/* =====================================================================
   CLÍNICA NOE · Sistema de diseño
   Pensado primero para tableta (768–1366 px), fluido en móvil y escritorio.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  /* Marca: azul petróleo clínico + dorado suave */
  --brand-950: #042a30;
  --brand-900: #06343b;
  --brand-800: #0a4650;
  --brand-700: #0b5d68;
  --brand-600: #0b6e79;
  --brand-500: #138a96;
  --brand-400: #3fb0b9;
  --brand-200: #b4e3e6;
  --brand-100: #d8f1f2;
  --brand-50:  #eef9f9;
  --gold-600: #a8843f;
  --gold-500: #c9a45c;
  --gold-200: #ecdcb8;
  --gold-100: #f6eedc;

  /* Superficies */
  --bg: #f3f6f7;
  --bg-accent: radial-gradient(1200px 600px at 100% -10%, #e2f3f3 0%, transparent 60%),
               radial-gradient(900px 500px at -10% 110%, #f6efe0 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7fafb;
  --surface-3: #eef3f4;
  --glass: rgba(255, 255, 255, .72);
  --border: #e2e9eb;
  --border-strong: #cfdadd;

  /* Texto */
  --text: #0f2a30;
  --text-2: #466066;
  --muted: #6f878d;
  --on-brand: #ffffff;

  /* Estados (siempre acompañados de ícono + texto) */
  --ok: #188a5c;      --ok-bg: #e3f5ec;
  --warn: #b7700f;    --warn-bg: #fbf0dc;
  --alert: #c73a52;   --alert-bg: #fbe6ea;
  --info: var(--brand-600); --info-bg: var(--brand-50);

  /* Gráficas (validadas: CVD y contraste) */
  --chart-1: #008c99;
  --chart-2: #c0822a;
  --chart-3: #6b5bd2;
  --chart-grid: #e8eef0;
  --chart-axis: #7b9095;
  --chart-band: rgba(24, 138, 92, .08);

  /* Forma y profundidad */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --shadow-xs: 0 1px 2px rgba(15, 42, 48, .06);
  --shadow-sm: 0 2px 8px -2px rgba(15, 42, 48, .08), 0 1px 2px rgba(15, 42, 48, .04);
  --shadow: 0 12px 32px -12px rgba(15, 42, 48, .18), 0 2px 6px -2px rgba(15, 42, 48, .06);
  --shadow-lg: 0 30px 60px -20px rgba(6, 52, 59, .35), 0 8px 20px -8px rgba(6, 52, 59, .15);
  --ring: 0 0 0 4px rgba(19, 138, 150, .22);

  /* Tipografía */
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;

  /* Movimiento */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur: 240ms;

  /* Layout */
  --sidebar-w: 272px;
  --rail-w: 92px;
  --topbar-h: 76px;
  --tabbar-h: 72px;
  --gutter: clamp(16px, 2.6vw, 32px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1216;
  --bg-accent: radial-gradient(1200px 600px at 100% -10%, rgba(19, 138, 150, .16) 0%, transparent 60%),
               radial-gradient(900px 500px at -10% 110%, rgba(201, 164, 92, .08) 0%, transparent 55%);
  --surface: #131d24;
  --surface-2: #17232a;
  --surface-3: #1d2b33;
  --glass: rgba(19, 29, 36, .72);
  --border: #22343c;
  --border-strong: #2d434c;
  --text: #e6f0f1;
  --text-2: #a9bec2;
  --muted: #7f979c;
  --brand-50: #10272c;
  --brand-100: #143238;
  --gold-100: #2a2417;
  --ok: #3cc58c;      --ok-bg: rgba(60, 197, 140, .12);
  --warn: #e6a84a;    --warn-bg: rgba(230, 168, 74, .13);
  --alert: #f0788c;   --alert-bg: rgba(240, 120, 140, .13);
  --info: var(--brand-400); --info-bg: rgba(63, 176, 185, .12);
  --chart-1: #1fa7b1;
  --chart-2: #bf8628;
  --chart-3: #8878e6;
  --chart-grid: #1f3038;
  --chart-axis: #7f979c;
  --chart-band: rgba(60, 197, 140, .08);
  --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, .4);
  --shadow: 0 12px 32px -12px rgba(0, 0, 0, .55);
  --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .7);
  --ring: 0 0 0 4px rgba(63, 176, 185, .28);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-600); text-decoration: none; }
[data-theme="dark"] a { color: var(--brand-400); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0; }
::selection { background: var(--brand-200); color: var(--brand-950); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-xs); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.icon { display: inline-block; vertical-align: -0.2em; width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }

.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em; font-optical-sizing: auto; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--gap, 16px); }
.row { display: flex; align-items: center; gap: var(--gap, 12px); }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* =====================================================================
   SHELL
   ===================================================================== */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 22px 16px;
  background: linear-gradient(180deg, var(--brand-900), var(--brand-950));
  color: #d7ecee;
  z-index: 30;
  overflow: hidden;
}
.sidebar::before {
  content: ""; position: absolute; inset: auto -40% -30% -40%; height: 60%;
  background: radial-gradient(closest-side, rgba(201, 164, 92, .18), transparent);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: #fff; }
.brand-mark { width: 46px; height: 46px; flex: none; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .3)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-kicker { font-size: .68rem; letter-spacing: .32em; text-transform: uppercase; color: var(--gold-500); font-weight: 700; }
.brand-name { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; letter-spacing: .02em; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 14px;
  min-height: 52px; padding: 0 16px; border-radius: 14px;
  color: #b9d6d9; font-weight: 600; font-size: .95rem;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link:active { transform: scale(.98); }
.nav-link[aria-current="page"] { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -16px; top: 12px; bottom: 12px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--gold-500);
  view-transition-name: nav-indicator;
}
.nav-link .icon { width: 22px; height: 22px; }
.nav-section { margin: 18px 16px 6px; font-size: .7rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: rgba(185, 214, 217, .5); }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08);
}
.user-chip .avatar { --size: 40px; }
.user-chip-name { color: #fff; font-weight: 700; font-size: .92rem; }
.user-chip-role { font-size: .76rem; color: #9fc2c6; }
.user-chip .icon-btn { color: #cfe5e7; margin-left: auto; }
.user-chip .icon-btn:hover { background: rgba(255, 255, 255, .1); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(1.6) blur(18px);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.topbar.is-scrolled { border-bottom-color: var(--border); box-shadow: var(--shadow-xs); }
.topbar-title { min-width: 0; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); font-weight: 600; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--brand-600); }
.topbar h1 { font-size: 1.3rem; font-weight: 800; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search-trigger {
  display: flex; align-items: center; gap: 10px; min-width: 260px; height: 46px; padding: 0 14px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  box-shadow: var(--shadow-xs); transition: border-color var(--dur), box-shadow var(--dur);
}
.search-trigger:hover { border-color: var(--brand-400); box-shadow: var(--shadow-sm); }
.search-trigger kbd { margin-left: auto; }
kbd { font: 600 .72rem var(--font); padding: 3px 7px; border-radius: 6px; background: var(--surface-3); border: 1px solid var(--border); color: var(--text-2); }

.view {
  flex: 1; width: 100%; max-width: 1480px; margin: 0 auto;
  padding: 8px var(--gutter) calc(40px + var(--safe-bottom));
}

.tabbar { display: none; }

/* Tableta: barra lateral en modo riel (íconos + etiqueta corta) */
@media (max-width: 1279px) {
  .shell { grid-template-columns: var(--rail-w) 1fr; }
  .sidebar { padding: 18px 10px; align-items: center; }
  .brand { padding: 0 0 18px; }
  .sidebar .brand-text, .nav-section, .user-chip-text { display: none; }
  .nav { width: 100%; }
  .nav-link { flex-direction: column; justify-content: center; gap: 4px; min-height: 66px; padding: 6px 4px; font-size: .68rem; text-align: center; border-radius: 16px; }
  .nav-link[aria-current="page"]::before { left: -10px; }
  .user-chip { flex-direction: column; padding: 8px; background: none; border: 0; }
  .user-chip .icon-btn { margin: 0; }
  .search-trigger { min-width: 0; }
  .search-trigger .search-label, .search-trigger kbd { display: none; }
}

/* Móvil: barra inferior */
@media (max-width: 767px) {
  :root { --topbar-h: 64px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar h1 { font-size: 1.1rem; }
  .view { padding-bottom: calc(var(--tabbar-h) + 32px + var(--safe-bottom)); }
  .tabbar {
    position: fixed; left: 12px; right: 12px; bottom: calc(10px + var(--safe-bottom)); z-index: 40;
    display: flex; justify-content: space-around; height: var(--tabbar-h); padding: 8px;
    border-radius: 24px; background: var(--glass); border: 1px solid var(--border);
    backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
    box-shadow: var(--shadow);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 16px; font-size: .68rem; font-weight: 700; color: var(--muted); }
  .tabbar a[aria-current="page"] { color: var(--brand-600); background: var(--brand-50); }
  .hide-mobile { display: none !important; }
}

/* =====================================================================
   COMPONENTES
   ===================================================================== */

/* ---------- Botones ---------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border);
  position: relative; overflow: hidden; isolation: isolate;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 20px; border-radius: 14px;
  border: 1px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 700; font-size: .95rem; white-space: nowrap; user-select: none;
  box-shadow: var(--shadow-xs);
  transition: transform 160ms var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur), opacity var(--dur);
}
.btn:hover { box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn-primary {
  --btn-fg: #fff; --btn-bd: transparent;
  --btn-bg: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  box-shadow: 0 10px 24px -10px rgba(11, 110, 121, .7), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn-primary:hover { box-shadow: 0 14px 30px -10px rgba(11, 110, 121, .8), inset 0 1px 0 rgba(255, 255, 255, .2); }
.btn-gold { --btn-fg: #2b1f06; --btn-bd: transparent; --btn-bg: linear-gradient(135deg, #e3c688, var(--gold-500)); }
.btn-soft { --btn-bg: var(--brand-50); --btn-fg: var(--brand-700); --btn-bd: transparent; box-shadow: none; }
[data-theme="dark"] .btn-soft { --btn-fg: var(--brand-400); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); box-shadow: none; }
.btn-danger { --btn-bg: var(--alert); --btn-fg: #fff; --btn-bd: transparent; }
.btn-danger-soft { --btn-bg: var(--alert-bg); --btn-fg: var(--alert); --btn-bd: transparent; box-shadow: none; }
.btn-sm { min-height: 38px; padding: 0 14px; border-radius: 11px; font-size: .85rem; gap: 7px; }
.btn-lg { min-height: 56px; padding: 0 26px; border-radius: 16px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn .spinner { display: none; }
.btn.is-loading { pointer-events: none; }
.btn.is-loading .spinner { display: block; }
.btn.is-loading > :not(.spinner) { opacity: .0; }
.btn.is-loading .spinner { position: absolute; }

.ripple {
  position: absolute; border-radius: 50%; pointer-events: none; z-index: -1;
  background: currentColor; opacity: .18; transform: scale(0);
  animation: ripple 600ms var(--ease) forwards;
}
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

.icon-btn {
  display: inline-grid; place-items: center; width: 46px; height: 46px; flex: none;
  border-radius: 14px; border: 0; background: transparent; color: var(--text-2);
  transition: background var(--dur), color var(--dur), transform 160ms var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.bordered { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-xs); }
.icon-btn.sm { width: 38px; height: 38px; border-radius: 11px; }

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tarjetas ---------- */
.card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  container-type: inline-size;
}
.card-pad { padding: clamp(18px, 2.2vw, 26px); }
.card-header { display: flex; align-items: center; gap: 12px; padding: 20px 24px 0; }
.card-header + .card-body { padding-top: 14px; }
.card-body { padding: 20px 24px 24px; }
.card-title { font-size: 1.05rem; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.card-title .icon { color: var(--brand-500); }
.card-sub { font-size: .85rem; color: var(--muted); }
.card-link { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur); cursor: pointer; }
.card-link:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand-200); }
[data-theme="dark"] .card-link:hover { border-color: var(--border-strong); }
.card-link:active { transform: translateY(-1px) scale(.995); }

.section-title { display: flex; align-items: center; gap: 10px; font-size: 1rem; font-weight: 800; margin: 0 0 14px; }
.section-title .icon { color: var(--brand-500); }
.section-title .num-badge { font-size: .75rem; }

/* ---------- Chips ---------- */
.chip {
  --chip-bg: var(--surface-3); --chip-fg: var(--text-2);
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px;
  border-radius: 999px; background: var(--chip-bg); color: var(--chip-fg);
  font-size: .78rem; font-weight: 700; white-space: nowrap;
}
.chip .icon { width: 14px; height: 14px; stroke-width: 2.2; }
.chip-ok { --chip-bg: var(--ok-bg); --chip-fg: var(--ok); }
.chip-warn { --chip-bg: var(--warn-bg); --chip-fg: var(--warn); }
.chip-alert { --chip-bg: var(--alert-bg); --chip-fg: var(--alert); }
.chip-info { --chip-bg: var(--info-bg); --chip-fg: var(--info); }
.chip-gold { --chip-bg: var(--gold-100); --chip-fg: var(--gold-600); }
[data-theme="dark"] .chip-gold { --chip-fg: var(--gold-500); }
.chip-lg { height: 34px; padding: 0 14px; font-size: .85rem; }
.num-badge { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; background: var(--brand-50); color: var(--brand-600); font-size: .75rem; font-weight: 800; }

/* ---------- Avatar ---------- */
.avatar {
  --size: 48px; --hue: 186;
  width: var(--size); height: var(--size); flex: none; border-radius: 30%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, hsl(var(--hue) 60% 46%), hsl(calc(var(--hue) + 28) 55% 34%));
  color: #fff; font-weight: 800; font-size: calc(var(--size) * .36); letter-spacing: .02em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 6px 14px -6px hsl(var(--hue) 60% 30% / .6);
}
.avatar-xl { --size: 92px; border-radius: 28px; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; gap: 16px 18px; grid-template-columns: repeat(12, 1fr); }
.form-grid > * { grid-column: span 12; }
.span-3 { grid-column: span 3 !important; } .span-4 { grid-column: span 4 !important; }
.span-5 { grid-column: span 5 !important; } .span-6 { grid-column: span 6 !important; }
.span-8 { grid-column: span 8 !important; }
@media (max-width: 767px) { .form-grid > [class*="span-"] { grid-column: span 12 !important; } }
@media (min-width: 768px) and (max-width: 1023px) { .span-3 { grid-column: span 6 !important; } }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-label { font-size: .82rem; font-weight: 700; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.field-label .req { color: var(--alert); }
.field-hint { font-size: .78rem; color: var(--muted); }
.field-error { font-size: .8rem; color: var(--alert); font-weight: 600; display: flex; gap: 6px; align-items: center; animation: fade-up 200ms var(--ease); }

.input {
  width: 100%; min-height: 52px; padding: 13px 16px;
  border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface-2);
  font-size: 16px; color: var(--text);
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
  appearance: none; -webkit-appearance: none;
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--brand-500); background: var(--surface); box-shadow: var(--ring); }
.input[aria-invalid="true"] { border-color: var(--alert); background: var(--alert-bg); }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.55; field-sizing: content; }
select.input {
  padding-right: 44px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%236f878d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 8 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
input[type="date"].input, input[type="datetime-local"].input, input[type="month"].input { min-height: 52px; }

.input-group { position: relative; display: flex; align-items: stretch; }
.input-group .input { padding-right: 64px; }
.input-addon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: .82rem; font-weight: 700; color: var(--muted); pointer-events: none; }
.input-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-group.has-icon .input { padding-left: 48px; }
.input-action { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

.search-input { height: 56px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-xs); font-size: 1rem; }

/* Segmentado */
.segmented {
  position: relative; display: inline-flex; gap: 4px; padding: 5px;
  border-radius: 16px; background: var(--surface-3); border: 1px solid var(--border);
}
.segmented button {
  position: relative; z-index: 1; min-height: 40px; padding: 0 16px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text-2); font-weight: 700; font-size: .88rem;
  display: inline-flex; align-items: center; gap: 8px; transition: color var(--dur);
}
.segmented button[aria-pressed="true"] { color: var(--text); }
.segmented .seg-thumb {
  position: absolute; z-index: 0; top: 5px; bottom: 5px; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: left 320ms var(--ease-spring), width 320ms var(--ease-spring);
}

/* Pestañas */
.tabs { position: relative; display: flex; gap: 6px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 0 18px; border: 0; background: none;
  color: var(--muted); font-weight: 700; white-space: nowrap; transition: color var(--dur);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand-600); }
[data-theme="dark"] .tab[aria-selected="true"] { color: var(--brand-400); }
.tab-indicator { position: absolute; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--brand-500); transition: left 340ms var(--ease-spring), width 340ms var(--ease-spring); }
.tab-panel { animation: fade-up 320ms var(--ease); }

/* Interruptor */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--border-strong); transition: background var(--dur); pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 300ms var(--ease-spring); }
.switch input:checked + span { background: var(--brand-500); }
.switch input:checked + span::after { transform: translateX(22px); }

/* ---------- Página ---------- */
.page-header { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 16px; margin: 8px 0 24px; }
.page-title { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.page-subtitle { color: var(--muted); margin-top: 4px; }
.page-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

.grid { display: grid; gap: var(--gap, 20px); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(var(--min, 300px), 1fr)); }
@media (max-width: 1023px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .grid-4 { grid-template-columns: 1fr 1fr; --gap: 12px; } }

/* ---------- KPI ---------- */
.kpi { padding: 20px 22px; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.kpi-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); }
[data-theme="dark"] .kpi-icon { color: var(--brand-400); }
.kpi-icon.gold { background: var(--gold-100); color: var(--gold-600); }
.kpi-value { font-family: var(--font-display); font-size: clamp(1.9rem, 3.4vw, 2.5rem); font-weight: 600; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.kpi-foot { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi::after { content: ""; position: absolute; right: -40px; top: -40px; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(closest-side, var(--brand-50), transparent); pointer-events: none; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; font-size: .78rem; }
.delta .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.delta.good { color: var(--ok); } .delta.bad { color: var(--alert); } .delta.flat { color: var(--muted); }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: var(--radius-xl);
  padding: clamp(24px, 3.6vw, 40px);
  background: linear-gradient(125deg, var(--brand-700) 0%, var(--brand-900) 60%, #05262c 100%);
  color: #fff; box-shadow: var(--shadow-lg);
}
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; filter: blur(40px); opacity: .55; pointer-events: none; }
.hero::before { width: 380px; height: 380px; right: -80px; top: -140px; background: #1fb1bb; animation: float 14s ease-in-out infinite; }
.hero::after { width: 300px; height: 300px; right: 22%; bottom: -200px; background: var(--gold-500); opacity: .35; animation: float 18s ease-in-out infinite reverse; }
.hero > * { position: relative; z-index: 1; }
.hero-kicker { font-size: .78rem; letter-spacing: .22em; text-transform: uppercase; color: var(--gold-200); font-weight: 700; }
.hero-title { font-family: var(--font-display); font-size: clamp(1.8rem, 3.6vw, 2.7rem); font-weight: 600; margin-top: 8px; }
.hero-sub { color: #bfe0e3; margin-top: 6px; }
.hero .btn-glass { --btn-bg: rgba(255, 255, 255, .12); --btn-fg: #fff; --btn-bd: rgba(255, 255, 255, .18); backdrop-filter: blur(10px); box-shadow: none; }
.hero .btn-glass:hover { --btn-bg: rgba(255, 255, 255, .2); }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-30px, 20px) scale(1.08); } }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 12px; margin: 0 -12px;
  border-radius: 16px; color: inherit; min-height: 64px;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
a.list-item:hover, button.list-item:hover { background: var(--surface-2); }
a.list-item:active { transform: scale(.99); }
.list-item + .list-item { border-top: 1px solid var(--border); }
a.list-item:hover + .list-item, .list-item:hover { border-color: transparent; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; }
.list-item-sub { font-size: .82rem; color: var(--muted); }
button.list-item { width: calc(100% + 24px); border: 0; background: none; text-align: left; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { position: sticky; top: 0; text-align: left; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 800; background: var(--surface-2); padding: 12px 14px; white-space: nowrap; }
.table td { padding: 12px 14px; border-top: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; }

/* ---------- Diálogos ---------- */
dialog.modal {
  width: min(760px, calc(100vw - 32px)); max-height: min(92dvh, 960px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  overflow: hidden; display: flex; flex-direction: column;
}
dialog.modal:not([open]) { display: none; }
dialog.modal.modal-sm { width: min(460px, calc(100vw - 32px)); }
dialog.modal.modal-lg { width: min(1040px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(4, 28, 33, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
dialog.modal[open] { animation: modal-in 380ms var(--ease-spring); }
dialog.modal[open]::backdrop { animation: fade-in 260ms var(--ease); }
dialog.modal.is-closing { animation: modal-out 200ms var(--ease) forwards; }
dialog.modal.is-closing::backdrop { animation: fade-out 200ms var(--ease) forwards; }
.modal-header { display: flex; align-items: center; gap: 14px; padding: 22px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 1.2rem; font-weight: 800; }
.modal-body { padding: 22px 24px; overflow-y: auto; overscroll-behavior: contain; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); flex: none; }
.modal-icon.danger { background: var(--alert-bg); color: var(--alert); }
.modal-icon.warn { background: var(--warn-bg); color: var(--warn); }
@media (max-width: 767px) {
  dialog.modal, dialog.modal.modal-sm, dialog.modal.modal-lg {
    width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 28px 28px 0 0;
  }
  dialog.modal[open] { animation: sheet-in 420ms var(--ease-spring); }
  .modal-footer { padding-bottom: calc(16px + var(--safe-bottom)); }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(24px) scale(.96); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes sheet-in { from { transform: translateY(100%); } }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; z-index: 1000; top: calc(var(--topbar-h) + 8px); right: 18px; display: flex; flex-direction: column; gap: 10px; width: min(400px, calc(100vw - 36px)); pointer-events: none; }
@media (max-width: 767px) { .toast-stack { top: auto; bottom: calc(var(--tabbar-h) + 22px + var(--safe-bottom)); right: 18px; } }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  border-radius: 18px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in 420ms var(--ease-spring);
}
.toast.is-leaving { animation: toast-out 240ms var(--ease) forwards; }
.toast-icon { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--info-bg); color: var(--info); }
.toast.success .toast-icon { background: var(--ok-bg); color: var(--ok); }
.toast.error .toast-icon { background: var(--alert-bg); color: var(--alert); }
.toast.warning .toast-icon { background: var(--warn-bg); color: var(--warn); }
.toast-title { font-weight: 800; font-size: .92rem; }
.toast-msg { font-size: .85rem; color: var(--text-2); }
.toast-progress { position: absolute; left: 16px; right: 16px; bottom: 6px; height: 3px; border-radius: 3px; background: var(--border); overflow: hidden; }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(40px) scale(.95); } }

/* ---------- Esqueletos y vacíos ---------- */
.skeleton {
  position: relative; overflow: hidden; border-radius: var(--radius); background: var(--surface-3);
  min-height: var(--h, 120px);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 48px 20px; }
.empty-art { width: 140px; height: 140px; margin-bottom: 6px; animation: float-soft 6s ease-in-out infinite; }
.empty-title { font-size: 1.15rem; font-weight: 800; }
.empty-text { color: var(--muted); max-width: 420px; }
@keyframes float-soft { 50% { transform: translateY(-8px); } }

/* ---------- Banners ---------- */
.banner { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 16px; background: var(--info-bg); color: var(--info); font-size: .9rem; font-weight: 600; }
.banner.alert { background: var(--alert-bg); color: var(--alert); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.offline-banner { position: fixed; z-index: 999; left: 50%; top: 12px; transform: translateX(-50%); box-shadow: var(--shadow); animation: fade-up 300ms var(--ease); }

/* =====================================================================
   LOGIN
   ===================================================================== */
.login { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--bg); }
@media (min-width: 761px) and (max-width: 1023px) { .login { grid-template-columns: 1fr 1fr; } .login-headline { font-size: 2.1rem; } }
.login-art {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
  padding: clamp(28px, 5vw, 64px); color: #fff;
  background: linear-gradient(150deg, var(--brand-700), var(--brand-950) 70%);
}
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .6; will-change: transform; }
.blob-1 { width: 520px; height: 520px; background: #16a3ad; top: -160px; right: -120px; animation: float 16s ease-in-out infinite; }
.blob-2 { width: 380px; height: 380px; background: var(--gold-500); bottom: -140px; left: -80px; opacity: .35; animation: float 20s ease-in-out infinite reverse; }
.blob-3 { width: 260px; height: 260px; background: #6fd6c6; bottom: 25%; right: 18%; opacity: .25; animation: float 12s ease-in-out infinite; }
.login-grid { position: absolute; inset: 0; opacity: .08; background-image: linear-gradient(rgba(255,255,255,.6) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.6) 1px, transparent 1px); background-size: 48px 48px; mask-image: radial-gradient(circle at 30% 40%, #000, transparent 70%); -webkit-mask-image: radial-gradient(circle at 30% 40%, #000, transparent 70%); }
.login-art > :not(.blob):not(.login-grid) { position: relative; z-index: 1; }
.login-brand { display: flex; align-items: center; gap: 16px; }
.login-brand .brand-mark { width: 64px; height: 64px; }
.login-brand .brand-name { font-size: 2.2rem; }
.login-headline { font-family: var(--font-display); font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.08; font-weight: 600; max-width: 560px; }
.login-headline em { font-style: italic; color: var(--gold-200); }
.login-features { display: flex; flex-direction: column; gap: 14px; margin-top: 28px; }
.login-feature { display: flex; align-items: center; gap: 14px; color: #cfe7ea; font-weight: 600; }
.login-feature .icon-wrap { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .14); backdrop-filter: blur(8px); }
.login-foot { font-size: .8rem; color: rgba(207, 231, 234, .7); }
.login-pulse { width: 100%; max-width: 520px; height: 70px; color: var(--gold-500); }
.login-pulse path { stroke-dasharray: 600; stroke-dashoffset: 600; animation: draw 3.2s var(--ease) infinite; }
@keyframes draw { 60% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -600; } }

.login-panel { display: grid; place-items: center; padding: 32px var(--gutter); }
.login-card { width: min(440px, 100%); animation: fade-up 600ms var(--ease) both; }
.login-card h2 { font-family: var(--font-display); font-size: 2.1rem; font-weight: 600; }
.login-card .lead { color: var(--muted); margin: 8px 0 28px; }
.login-card form { display: flex; flex-direction: column; gap: 18px; }
.login-card.shake { animation: shake 480ms var(--ease); }
.login-secure { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 22px; color: var(--muted); font-size: .8rem; }
.caps-warning { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--warn); }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-art { min-height: 0; justify-content: flex-start; gap: 36px; padding: 32px 28px 76px; }
  .login-headline { font-size: clamp(1.7rem, 5vw, 2.4rem); }
  .login-features, .login-pulse, .login-foot { display: none; }
  .login-panel { place-items: start center; padding-top: 40px; margin-top: -40px; border-radius: 32px 32px 0 0; background: var(--bg); position: relative; z-index: 2; }
}

/* =====================================================================
   PACIENTES
   ===================================================================== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 22px; }
.toolbar .grow { flex: 1 1 320px; }

.patient-card { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.patient-card-top { display: flex; align-items: center; gap: 14px; min-width: 0; }
.patient-card-name { font-weight: 800; font-size: 1.05rem; line-height: 1.25; }
.patient-card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .84rem; color: var(--text-2); }
.patient-card-meta span { display: inline-flex; align-items: center; gap: 6px; }
.patient-card-meta .icon { width: 15px; height: 15px; color: var(--muted); }
.patient-card-foot { display: flex; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: .8rem; color: var(--muted); }

/* Perfil */
.profile { overflow: hidden; }
.profile-banner { height: 116px; background: linear-gradient(120deg, var(--brand-600), var(--brand-900)); position: relative; overflow: hidden; }
.profile-banner::after { content: ""; position: absolute; width: 300px; height: 300px; right: -60px; top: -150px; border-radius: 50%; background: radial-gradient(closest-side, rgba(201, 164, 92, .5), transparent); }
.profile-body { padding: 0 clamp(18px, 2.4vw, 28px) 24px; display: flex; flex-wrap: wrap; gap: 18px 24px; align-items: flex-end; margin-top: -46px; position: relative; }
.profile-body .avatar-xl { border: 5px solid var(--surface); box-shadow: var(--shadow); }
.profile-info { flex: 1 1 280px; min-width: 0; padding-top: 52px; }
.profile-name { font-family: var(--font-display); font-size: clamp(1.6rem, 3vw, 2.1rem); font-weight: 600; }
.profile-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.stat-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--border); }
.stat-strip > div { padding: 16px 20px; border-left: 1px solid var(--border); }
.stat-strip > div:first-child { border-left: 0; }
.stat-label { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.25rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .78rem; color: var(--muted); font-weight: 700; }
@media (max-width: 1023px) { .stat-strip { grid-template-columns: repeat(3, 1fr); } .stat-strip > div:nth-child(4) { border-left: 0; } .stat-strip > div:nth-child(n+4) { border-top: 1px solid var(--border); } }
@media (max-width: 560px) { .stat-strip { grid-template-columns: repeat(2, 1fr); } .stat-strip > div { border-left: 0 !important; border-top: 1px solid var(--border); } .stat-strip > div:nth-child(odd) { border-right: 1px solid var(--border); } }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.info-block { padding: 18px 20px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.info-block h4 { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.info-block h4 .icon { width: 16px; height: 16px; color: var(--brand-500); }
.info-block p { white-space: pre-wrap; }
.info-block.alert { background: var(--alert-bg); border-color: transparent; }
.info-block.alert h4, .info-block.alert h4 .icon { color: var(--alert); }

/* Línea de tiempo */
.timeline { position: relative; display: flex; flex-direction: column; gap: 14px; padding-left: 34px; }
.timeline::before { content: ""; position: absolute; left: 11px; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: linear-gradient(var(--brand-400), var(--border)); }
.tl-item { position: relative; }
.tl-dot { position: absolute; left: -34px; top: 22px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand-500); box-shadow: 0 0 0 5px var(--bg); }
.tl-item:first-child .tl-dot { background: var(--brand-500); box-shadow: 0 0 0 5px var(--bg), 0 0 0 9px rgba(19, 138, 150, .18); animation: pulse-ring 2.4s infinite; }
.tl-card { display: flex; gap: 18px; padding: 18px 20px; }
.tl-date { flex: none; width: 64px; text-align: center; padding: 8px 0; border-radius: 14px; background: var(--brand-50); color: var(--brand-700); }
[data-theme="dark"] .tl-date { color: var(--brand-400); }
.tl-day { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; line-height: 1; }
.tl-month { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.tl-year { font-size: .68rem; opacity: .7; font-weight: 700; }
.tl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.tl-title { font-weight: 800; }
.tl-metrics { display: flex; flex-wrap: wrap; gap: 8px; }
.metric-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-pill .icon { width: 15px; height: 15px; color: var(--brand-500); }
.metric-pill small { color: var(--muted); font-weight: 600; }
@keyframes pulse-ring { 50% { box-shadow: 0 0 0 5px var(--bg), 0 0 0 13px rgba(19, 138, 150, 0); } }
@media (max-width: 560px) { .tl-card { flex-direction: column; gap: 12px; } .tl-date { width: auto; display: flex; gap: 8px; align-items: baseline; justify-content: flex-start; padding: 6px 12px; } .tl-day { font-size: 1.2rem; } }

/* =====================================================================
   CONSULTA
   ===================================================================== */
.consult-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.consult-aside { position: sticky; top: calc(var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: 16px; max-height: calc(100dvh - var(--topbar-h) - 24px); overflow-y: auto; padding-bottom: 8px; }
@media (max-width: 1100px) { .consult-layout { grid-template-columns: 1fr; } .consult-aside { position: static; max-height: none; order: -1; } }

.form-section { padding: clamp(18px, 2.4vw, 28px); }
.form-section + .form-section { margin-top: 18px; }
.form-section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.form-section-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); flex: none; }
[data-theme="dark"] .form-section-icon { color: var(--brand-400); }
.form-section-icon.gold { background: var(--gold-100); color: var(--gold-600); }
.form-section-title { font-size: 1.08rem; font-weight: 800; }
.form-section-sub { font-size: .82rem; color: var(--muted); }

.vitals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.vital {
  position: relative; padding: 16px; border-radius: 18px; background: var(--surface-2); border: 1.5px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; transition: border-color var(--dur), background var(--dur), transform var(--dur) var(--ease);
}
.vital:focus-within { border-color: var(--brand-500); background: var(--surface); box-shadow: var(--ring); }
.vital-head { display: flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 700; color: var(--text-2); }
.vital-head .icon { width: 18px; height: 18px; color: var(--brand-500); }
.vital-inputs { display: flex; align-items: baseline; gap: 6px; }
.vital-input {
  width: 100%; min-width: 0; border: 0; background: transparent; padding: 0; outline: none;
  font-family: var(--font-display); font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  -moz-appearance: textfield; appearance: textfield;
}
.vital-input::-webkit-outer-spin-button, .vital-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.vital-input::placeholder { color: var(--border-strong); }
.vital-sep { font-size: 1.6rem; color: var(--muted); }
.vital-unit { font-size: .78rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.vital-foot { display: flex; align-items: center; gap: 8px; min-height: 28px; flex-wrap: wrap; }
.vital-range { font-size: .72rem; color: var(--muted); }
.vital.wide { grid-column: span 2; }
@media (max-width: 480px) { .vital.wide { grid-column: auto; } }
.vital.static { background: var(--surface); }
.vital.static .vital-value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }

/* Medidor de IMC */
.bmi-card { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: center; }
@media (max-width: 640px) { .bmi-card { grid-template-columns: 1fr; } }
.gauge { position: relative; width: 100%; max-width: 260px; margin: 0 auto; }
.gauge svg { width: 100%; height: auto; overflow: visible; }
.gauge-needle { transform-origin: 130px 130px; transition: transform 900ms var(--ease-spring); }
.gauge-value { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; }
.gauge-number { font-family: var(--font-display); font-size: 2.4rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.gauge-label { font-size: .8rem; font-weight: 700; color: var(--muted); margin-top: 4px; }

/* Carbohidratos */
.range { width: 100%; height: 36px; appearance: none; -webkit-appearance: none; background: transparent; }
.range::-webkit-slider-runnable-track { height: 10px; border-radius: 10px; background: linear-gradient(90deg, var(--brand-400) var(--p, 0%), var(--surface-3) var(--p, 0%)); }
.range::-moz-range-track { height: 10px; border-radius: 10px; background: var(--surface-3); }
.range::-moz-range-progress { height: 10px; border-radius: 10px; background: var(--brand-400); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; margin-top: -10px; border-radius: 50%; background: #fff; border: 3px solid var(--brand-500); box-shadow: var(--shadow); transition: transform 200ms var(--ease-spring); }
.range::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 3px solid var(--brand-500); box-shadow: var(--shadow); }
.range:active::-webkit-slider-thumb { transform: scale(1.15); }
.carbs-display { display: flex; align-items: baseline; gap: 8px; }
.carbs-display .vital-input { width: 5ch; font-size: 2.6rem; }

/* Medicamentos */
.med-list { display: flex; flex-direction: column; gap: 12px; }
.med-row {
  position: relative; display: grid; gap: 12px; padding: 16px 56px 16px 16px; border-radius: 18px;
  grid-template-columns: 2fr 1fr 1.4fr 1fr; background: var(--surface-2); border: 1px solid var(--border);
  animation: pop-in 360ms var(--ease-spring);
}
.med-row .med-extra { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 12px; }
.med-row .remove { position: absolute; top: 12px; right: 8px; }
.med-row .input { min-height: 48px; background: var(--surface); }
.med-index { position: absolute; left: -10px; top: -10px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-600); color: #fff; font-size: .75rem; font-weight: 800; box-shadow: var(--shadow-sm); }
.med-row.is-removing { animation: pop-out 240ms var(--ease) forwards; }
@media (max-width: 900px) { .med-row { grid-template-columns: 1fr 1fr; } .med-row .med-extra { grid-template-columns: 1fr 1fr; } .med-row .med-extra > :last-child { grid-column: 1 / -1; } }
@media (max-width: 520px) { .med-row, .med-row .med-extra { grid-template-columns: 1fr; } }

.med-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: 18px; background: var(--surface-2); border: 1px solid var(--border); }
.med-card-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--gold-100); color: var(--gold-600); flex: none; }
.med-card-name { font-weight: 800; }
.med-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Documentos */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 32px 20px; border-radius: 22px; border: 2px dashed var(--border-strong); background: var(--surface-2);
  text-align: center; transition: border-color var(--dur), background var(--dur), transform var(--dur) var(--ease);
}
.dropzone.is-over { border-color: var(--brand-500); background: var(--brand-50); transform: scale(1.01); }
.dropzone-icon { width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center; background: var(--surface); color: var(--brand-500); box-shadow: var(--shadow-sm); }
.dropzone-title { font-weight: 800; }
.dropzone-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.doc-card {
  position: relative; display: flex; flex-direction: column; overflow: hidden; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur); animation: pop-in 360ms var(--ease-spring) both;
  text-align: left; padding: 0; color: inherit;
}
.doc-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.doc-thumb { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--surface-3); overflow: hidden; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb .icon { width: 40px; height: 40px; stroke-width: 1.4; color: var(--brand-500); }
.doc-thumb.pdf .icon { color: var(--alert); }
.doc-thumb.word .icon { color: #2f6fd6; }
.doc-thumb.excel .icon { color: var(--ok); }
.doc-info { padding: 10px 12px; min-width: 0; }
.doc-name { font-weight: 700; font-size: .84rem; }
.doc-meta { font-size: .74rem; color: var(--muted); }
.doc-card .doc-remove { position: absolute; top: 8px; right: 8px; background: var(--glass); backdrop-filter: blur(8px); }
.doc-progress { height: 4px; background: var(--surface-3); }
.doc-progress > span { display: block; height: 100%; width: var(--p, 0%); background: var(--brand-500); transition: width 200ms; }

.viewer { width: min(1100px, calc(100vw - 32px)); height: min(88dvh, 900px); }
.viewer .modal-body { padding: 0; flex: 1; display: grid; place-items: center; background: var(--surface-3); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* Barra de acciones fija */
.sticky-actions {
  position: sticky; bottom: calc(12px + var(--safe-bottom)); z-index: 15; margin-top: 22px;
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 20px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
}
@media (max-width: 767px) { .sticky-actions { bottom: calc(var(--tabbar-h) + 20px + var(--safe-bottom)); } }
.save-state { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* Historial lateral */
.history-mini { display: flex; flex-direction: column; gap: 8px; }
.history-mini button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); text-align: left; transition: background var(--dur), border-color var(--dur), transform var(--dur) var(--ease); }
.history-mini button:hover { background: var(--surface); border-color: var(--brand-200); transform: translateX(3px); }
.history-mini .tl-date { width: 50px; padding: 6px 0; }
.history-mini .tl-day { font-size: 1.2rem; }

/* =====================================================================
   REPORTES / GRÁFICAS
   ===================================================================== */
.chart-card { padding: 20px 22px 16px; display: flex; flex-direction: column; gap: 12px; }
.chart-head { display: flex; align-items: flex-start; gap: 12px; }
.chart-title { font-weight: 800; }
.chart-sub { font-size: .8rem; color: var(--muted); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .8rem; font-weight: 700; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 18px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; }
.chart-legend i.dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.chart-box { position: relative; height: 260px; }
.chart-last { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; line-height: 1; margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.chart-last small { display: block; font-family: var(--font); font-size: .72rem; color: var(--muted); font-weight: 700; margin-top: 4px; }

.summary-tile { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.summary-tile .kpi-value { font-size: 1.9rem; }

.report-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* Paleta de comandos */
.palette { width: min(640px, calc(100vw - 32px)); margin-top: 10vh; }
.palette .modal-body { padding: 8px; max-height: 60dvh; }
.palette-input { border: 0; background: transparent; font-size: 1.15rem; min-height: 64px; padding: 0 20px 0 56px; width: 100%; outline: none; }
.palette-input:focus-visible { box-shadow: none; }
.palette-head { position: relative; border-bottom: 1px solid var(--border); }
.palette-head .icon { position: absolute; left: 20px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.palette-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 14px; border-radius: 14px; border: 0; background: none; text-align: left; color: inherit; }
.palette-item[aria-selected="true"], .palette-item:hover { background: var(--brand-50); }
.palette-group { padding: 10px 14px 4px; font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

/* Contraseña */
.strength { display: flex; gap: 6px; }
.strength i { flex: 1; height: 6px; border-radius: 6px; background: var(--surface-3); transition: background var(--dur); }
.strength[data-level="1"] i:nth-child(-n+1) { background: var(--alert); }
.strength[data-level="2"] i:nth-child(-n+2) { background: var(--warn); }
.strength[data-level="3"] i:nth-child(-n+3) { background: var(--brand-400); }
.strength[data-level="4"] i { background: var(--ok); }

/* Bitácora */
.audit-icon { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; flex: none; background: var(--surface-3); color: var(--text-2); }
.audit-icon.ok { background: var(--ok-bg); color: var(--ok); }
.audit-icon.alert { background: var(--alert-bg); color: var(--alert); }
.audit-icon.info { background: var(--info-bg); color: var(--info); }
.audit-icon.gold { background: var(--gold-100); color: var(--gold-600); }

/* Dictado por voz */
.dictate.is-listening { background: var(--alert-bg); color: var(--alert); animation: pulse-mic 1.2s infinite; }
@keyframes pulse-mic { 50% { box-shadow: 0 0 0 8px rgba(199, 58, 82, .12); } }

/* Barras simples (distribución de IMC) */
.hbar { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 12px; font-size: .85rem; }
.hbar + .hbar { margin-top: 12px; }
.hbar-track { height: 12px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.hbar-fill { height: 100%; width: 0; border-radius: 6px; background: var(--chart-1); transition: width 1s var(--ease); }
.hbar-label { font-weight: 700; color: var(--text-2); }
.hbar-value { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

/* =====================================================================
   ANIMACIONES
   ===================================================================== */
.reveal { animation: fade-up 560ms var(--ease) both; animation-delay: calc(var(--i, 0) * 55ms); }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.94); } }
@keyframes pop-out { to { opacity: 0; transform: scale(.94); height: 0; margin: 0; padding: 0; } }

/* La capa de transición no debe bloquear toques mientras se anima */
::view-transition { pointer-events: none; }
::view-transition-old(root) { animation: 180ms var(--ease) both vt-out; }
::view-transition-new(root) { animation: 320ms var(--ease) both vt-in; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* =====================================================================
   IMPRESIÓN
   ===================================================================== */
.print-header { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff !important; color: #000; }
  .sidebar, .topbar, .tabbar, .sticky-actions, .no-print, .toast-stack, .page-actions { display: none !important; }
  .shell { display: block; }
  .view { padding: 0; max-width: none; }
  .card { box-shadow: none !important; border-color: #ddd !important; break-inside: avoid; }
  .print-header { display: flex; align-items: center; gap: 14px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 2px solid var(--brand-600); }
  .print-header .brand-mark { width: 48px; height: 48px; }
  .reveal { animation: none !important; }
}
