/**
 * SANATORIO LOAR — Sistema Único de Diseño Editorial y Clínico (Todos los Subdominios)
 *
 * Aplicado en:
 * - sanatorioloar.com (Landing, /privacy, /tyc, /articulos/*)
 * - shop.sanatorioloar.com (Tienda Oficial)
 * - portal.sanatorioloar.com (Portal de Pacientes)
 * - doctor.sanatorioloar.com (Panel de Doctores)
 * - Base oficial lista para admin.sanatorioloar.com (Panel Administrativo)
 *
 * Paleta estricta: Blancos (#FFFFFF, #FAFAFA), Grises editoriales (#F4F4F5, #E4E4E7,
 * #A1A1AA, #52525B, #18181B), acento verde oscuro clínico medido (#0F3D2E / #0A2B20),
 * alertas sobrias en rojo (#B91C1C / #FEF2F2). Cero celeste, cero degradados llamativos.
 */

:root {
  color-scheme: light;

  /* Superficies y escala de grises editoriales */
  --loar-white: #ffffff;
  --loar-bg: #fafafa;
  --loar-surface: #ffffff;
  --loar-surface-muted: #f4f4f5;
  --loar-border: #e4e4e7;
  --loar-border-strong: #d4d4d8;
  --loar-icon-muted: #a1a1aa;
  --loar-text-secondary: #52525b;
  --loar-text: #18181b;

  /* Acento verde oscuro clínico (uso sobrio y puntual) */
  --loar-accent: #0f3d2e;
  --loar-accent-hover: #0a2b20;
  --loar-accent-soft: #f2f6f4;
  --loar-accent-border: #cbd9d3;

  /* Alertas y validaciones */
  --loar-danger: #b91c1c;
  --loar-danger-bg: #fef2f2;
  --loar-danger-border: #fecaca;

  /* Tipografía de alto contraste */
  --loar-font-display: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, sans-serif;
  --loar-font-sans: "Inter", system-ui, -apple-system, sans-serif;

  /* Radios refinados y formales (prohibido 24px-32px tipo burbuja) */
  --loar-radius-sm: 6px;
  --loar-radius-md: 8px;
  --loar-radius-lg: 10px;

  /* Sombras arquitectónicas mínimas */
  --loar-shadow-xs: 0 1px 2px rgba(24, 24, 27, 0.04);
  --loar-shadow-sm: 0 4px 12px rgba(24, 24, 27, 0.06);
  --loar-shadow-md: 0 12px 28px rgba(24, 24, 27, 0.12);

  /* Compatibilidad con variables MD3 y portales existentes */
  --md-sys-color-primary: var(--loar-accent);
  --md-sys-color-primary-hover: var(--loar-accent-hover);
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: var(--loar-accent-soft);
  --md-sys-color-on-primary-container: var(--loar-accent);
  --md-sys-color-secondary: var(--loar-text-secondary);
  --md-sys-color-secondary-container: var(--loar-surface-muted);
  --md-sys-color-on-secondary-container: var(--loar-text);
  --md-sys-color-surface: var(--loar-bg);
  --md-sys-color-surface-container-lowest: var(--loar-surface);
  --md-sys-color-surface-container-low: #f7f7f8;
  --md-sys-color-surface-container: var(--loar-surface-muted);
  --md-sys-color-on-surface: var(--loar-text);
  --md-sys-color-on-surface-variant: var(--loar-text-secondary);
  --md-sys-color-outline: var(--loar-icon-muted);
  --md-sys-color-outline-variant: var(--loar-border);
  --md-sys-shape-corner-small: 6px;
  --md-sys-shape-corner-medium: 8px;
  --md-sys-shape-corner-large: 10px;
  --md-sys-shape-corner-extra-large: 10px;
  --md-sys-shape-corner-full: 6px;
}

html,
body {
  overflow-x: clip;
  background-color: var(--loar-bg);
  color: var(--loar-text);
  font-family: var(--loar-font-sans);
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* ============================================================================
 * MENÚ PERSISTENTE DE PERFIL DEL PACIENTE (Popover + Viewport-Aware Dropdown)
 * ============================================================================ */
.loar-profile-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  min-width: 40px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--loar-border);
  background: var(--loar-surface);
  color: var(--loar-text);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
  anchor-name: --loar-profile-anchor;
}

.loar-profile-trigger:hover {
  border-color: var(--loar-border-strong);
  background: var(--loar-surface-muted);
}

.loar-profile-avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  display: block;
}

.loar-profile-avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--loar-text);
  color: #ffffff;
  font-family: var(--loar-font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
}

/* Ocultar antes de polyfill si :popover-open no existe */
@supports not selector(:popover-open) {
  .loar-profile-popover[popover]:not(.\:popover-open) {
    display: none;
  }
}

.loar-profile-popover {
  position-anchor: --loar-profile-anchor;
  width: min(280px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--loar-border);
  border-radius: var(--loar-radius-lg);
  background: var(--loar-surface);
  color: var(--loar-text);
  box-shadow: var(--loar-shadow-md);
  overflow: hidden;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 180ms;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  .loar-profile-popover {
    transform: translateY(-6px);
  }
}

.loar-profile-popover:is(:popover-open, .\:popover-open) {
  display: block;
  opacity: 1;
}

@starting-style {
  .loar-profile-popover:is(:popover-open, .\:popover-open) {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .loar-profile-popover:is(:popover-open, .\:popover-open) {
    transform: translateY(0);
  }
  @starting-style {
    .loar-profile-popover:is(:popover-open, .\:popover-open) {
      transform: translateY(-6px);
    }
  }
}

@supports (position-area: block-end) {
  .loar-profile-popover {
    inset: auto;
    margin: 8px 0 0 0;
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  }
}

@supports not (position-area: block-end) {
  .loar-profile-popover {
    position: fixed;
    top: 64px;
    right: 12px;
    left: auto;
    bottom: auto;
    margin: 0;
  }
}

.loar-profile-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--loar-bg);
  border-bottom: 1px solid var(--loar-border);
}

.loar-profile-head-meta {
  min-width: 0;
  flex: 1;
}

.loar-profile-name {
  display: block;
  font-family: var(--loar-font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--loar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loar-profile-email {
  display: block;
  font-size: 11.5px;
  color: var(--loar-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loar-profile-list {
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
}

.loar-profile-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--loar-radius-sm);
  background: transparent;
  color: var(--loar-text);
  font-family: var(--loar-font-sans);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.loar-profile-item:hover {
  background: var(--loar-surface-muted);
}

.loar-profile-item .material-symbols-rounded {
  font-size: 19px;
  color: var(--loar-text-secondary);
  flex-shrink: 0;
}

.loar-profile-item--primary {
  font-weight: 600;
  color: var(--loar-accent);
}

.loar-profile-item--primary .material-symbols-rounded {
  color: var(--loar-accent);
}

.loar-profile-divider {
  height: 1px;
  background: var(--loar-border);
  margin: 4px 6px;
}

.loar-profile-item--danger {
  color: var(--loar-danger);
}

.loar-profile-item--danger .material-symbols-rounded {
  color: var(--loar-danger);
}

.loar-profile-item--danger:hover {
  background: var(--loar-danger-bg);
}

/* ============================================================================
 * MODAL UNIFICADO DE CONFIGURACIÓN DE CUENTA (<dialog> con validación moderna)
 * ============================================================================ */
dialog.loar-settings-dialog {
  width: min(490px, calc(100vw - 20px));
  max-width: 490px;
  max-height: min(90dvh, 720px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--loar-border);
  border-radius: var(--loar-radius-lg);
  background: var(--loar-surface);
  color: var(--loar-text);
  box-shadow: var(--loar-shadow-md);
  overflow: hidden;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 200ms;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.loar-settings-dialog {
    transform: translateY(10px);
  }
}

dialog.loar-settings-dialog[open] {
  opacity: 1;
}

@starting-style {
  dialog.loar-settings-dialog[open] {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.loar-settings-dialog[open] {
    transform: translateY(0);
  }
  @starting-style {
    dialog.loar-settings-dialog[open] {
      transform: translateY(10px);
    }
  }
}

dialog.loar-settings-dialog:modal {
  overscroll-behavior: contain;
}

dialog.loar-settings-dialog::backdrop {
  background: rgba(24, 24, 27, 0.48);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
  transition-property: background-color, display, overlay;
  transition-duration: 200ms;
  transition-behavior: allow-discrete;
}

.loar-settings-shell {
  display: flex;
  flex-direction: column;
  max-height: min(90dvh, 720px);
}

.loar-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--loar-bg);
  border-bottom: 1px solid var(--loar-border);
}

.loar-settings-title {
  margin: 0;
  font-family: var(--loar-font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--loar-text);
}

.loar-settings-close {
  width: 36px;
  height: 36px;
  border-radius: var(--loar-radius-sm);
  border: 1px solid var(--loar-border);
  background: var(--loar-surface);
  color: var(--loar-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.loar-settings-close:hover {
  background: var(--loar-surface-muted);
}

.loar-settings-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--loar-border);
  background: var(--loar-surface);
}

.loar-settings-tab {
  min-height: 44px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--loar-text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}

.loar-settings-tab[aria-selected="true"] {
  color: var(--loar-accent);
  border-bottom-color: var(--loar-accent);
}

.loar-settings-body {
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.loar-settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.loar-settings-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--loar-text);
}

.loar-settings-rules {
  margin: 0 0 2px;
  padding-left: 16px;
  font-size: 11.5px;
  color: var(--loar-text-secondary);
  line-height: 1.5;
}

.loar-settings-rules li.is-met {
  color: var(--loar-accent);
  font-weight: 600;
}

.loar-settings-input,
.loar-settings-select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--loar-radius-sm);
  border: 1px solid var(--loar-border-strong);
  background: var(--loar-surface);
  color: var(--loar-text);
  font-size: 14px;
  font-family: var(--loar-font-sans);
}

.loar-settings-input:focus,
.loar-settings-select:focus {
  outline: none;
  border-color: var(--loar-accent);
}

.loar-settings-input:is(:user-invalid, .is-invalid),
.loar-settings-select:is(:user-invalid, .is-invalid) {
  border-color: var(--loar-danger);
  background: var(--loar-danger-bg);
}

.loar-settings-error {
  font-size: 12px;
  color: var(--loar-danger);
  font-weight: 500;
}

.loar-settings-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--loar-radius-sm);
  font-size: 12.5px;
  line-height: 1.45;
  border: 1px solid var(--loar-border);
}

.loar-settings-alert--error {
  background: var(--loar-danger-bg);
  border-color: var(--loar-danger-border);
  color: var(--loar-danger);
}

.loar-settings-alert--success {
  background: var(--loar-accent-soft);
  border-color: var(--loar-accent-border);
  color: var(--loar-accent);
}

.loar-settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--loar-radius-md);
  border: 1px solid var(--loar-accent);
  background: var(--loar-accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background-color 150ms ease;
}

.loar-settings-btn:hover {
  background: var(--loar-accent-hover);
}

.loar-settings-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.loar-settings-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 440px) {
  .loar-settings-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.loar-settings-avatar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--loar-radius-md);
  background: var(--loar-bg);
  border: 1px solid var(--loar-border);
}

.loar-settings-avatar-preview {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--loar-border);
  flex-shrink: 0;
}

.loar-settings-pwd-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.loar-settings-pwd-wrap .loar-settings-input {
  padding-right: 44px;
}

.loar-settings-eye {
  position: absolute;
  right: 6px;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--loar-text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* ============================================================================
 * BOTÓN FLOTANTE AUTOMÁTICO DE TIKTOK LIVE (Solo público/paciente; NUNCA doctor/admin)
 * Regla estricta: fondo negro puro + overflow:hidden para contener la onda roja
 * ============================================================================ */
.loar-live-fab {
  position: fixed;
  left: 14px;
  bottom: var(--loar-live-bottom, calc(16px + env(safe-area-inset-bottom, 0px)));
  z-index: 85;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 15px 0 8px;
  border-radius: 10px;
  background: #09090b;
  border: 1px solid #27272a;
  color: #ffffff;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  isolation: isolate;
  transition: transform 180ms ease, background-color 180ms ease;
}

.loar-live-fab:hover {
  background: #000000;
}

@media (prefers-reduced-motion: no-preference) {
  .loar-live-fab {
    animation: loar-live-enter 260ms ease-out both;
  }
  .loar-live-fab:hover {
    transform: translateY(-2px);
  }
}

@keyframes loar-live-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.loar-live-avatar-wrap {
  position: relative;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

/* Onda roja pulsante sutil y estrictamente contenida dentro del recuadro del botón */
.loar-live-avatar-wrap::before,
.loar-live-avatar-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 1.5px solid #ef4444;
  background: rgba(239, 68, 68, 0.14);
  pointer-events: none;
  z-index: -1;
}

@media (prefers-reduced-motion: no-preference) {
  .loar-live-avatar-wrap::before {
    animation: loar-live-pulse-ring 2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
  }
  .loar-live-avatar-wrap::after {
    animation: loar-live-pulse-ring 2s cubic-bezier(0.22, 1, 0.36, 1) 0.9s infinite;
  }
}

@keyframes loar-live-pulse-ring {
  0% {
    transform: scale(0.98);
    opacity: 0.72;
  }
  100% {
    transform: scale(1.34);
    opacity: 0;
  }
}

.loar-live-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
  object-position: center top;
  border: 1.5px solid #ef4444;
  display: block;
  background: #18181b;
}

.loar-live-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.loar-live-badge {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f87171;
}

.loar-live-label {
  font-family: var(--loar-font-display);
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
}

.loar-live-tiktok-ico {
  width: 17px;
  height: 17px;
  color: #ffffff;
  flex-shrink: 0;
  opacity: 0.95;
}

@media (prefers-reduced-motion: reduce) {
  dialog.loar-settings-dialog,
  .loar-profile-popover {
    transition-duration: 80ms;
  }
}
