/* ============ Fuentes ============ */
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url('/fonts/plus-jakarta-sans-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url('/fonts/plus-jakarta-sans-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ============ Tokens ============ */
/* Colores de marca Regimax: verde #99CC46, morado #A44EA6, gris #9C9A9A.
   Los tonos "strong"/"ink" son variantes más oscuras para cumplir el contraste AA. */
:root {
  --bg: #f6f7f4;
  --bg-tint: #eef5e4;
  --surface: #ffffff;
  --surface-2: #f9faf7;
  --ink: #1f2420;
  --ink-2: #4b524c;
  --muted: #7a807b;
  --line: #e4e7e1;
  --line-strong: #d0d5cc;

  --brand-green: #99cc46;
  --brand-purple: #a44ea6;
  --brand-gray: #9c9a9a;

  --primary: #8b3f8e;
  --primary-hover: #74327a;
  --primary-ink: #ffffff;
  --primary-soft: #f5ebf5;
  --primary-soft-2: #ebd7ec;
  --focus: rgba(139, 63, 142, .28);

  --green: #5b8c1e;
  --green-ink: #3f6812;
  --green-soft: #eef6e2;
  --green-soft-2: #dcecc4;

  --down: var(--green-ink);
  --down-soft: var(--green-soft);
  --up: #a2531a;
  --up-soft: #f9ece0;
  --flat: #5c635d;
  --flat-soft: #eff1ed;

  --target: var(--primary);
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff7e6;
  --warn-line: #f2dfb5;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 36, 32, .04), 0 4px 16px rgba(31, 36, 32, .05);
  --shadow-lg: 0 24px 64px rgba(31, 36, 32, .18);
  --font: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 0;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
a { color: var(--primary); }
button, input, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
main:focus { outline: none; }

/* ============ Barra superior ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246, 247, 244, .88);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 12px var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-logo { height: 38px; width: auto; flex: none; }
.brand-divider { width: 1px; height: 26px; background: var(--line-strong); flex: none; }
.brand-clinic { font-size: .85rem; font-weight: 550; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) { .brand-divider, .brand > .brand-clinic { display: none; } .brand-logo { height: 34px; } }
.session { display: flex; align-items: center; gap: 10px; }
.session-user { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: .9rem; font-weight: 550; }
@media (max-width: 560px) { .session-user { display: none; } }

/* ============ Botones ============ */
.btn {
  --h: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--h); padding: 0 18px;
  border-radius: 12px; border: 1px solid transparent;
  font-weight: 650; font-size: .92rem; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-sm { --h: 34px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 1px 2px rgba(139, 63, 142, .28), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-soft { background: var(--primary-soft); color: var(--primary-hover); }
.btn-soft:hover { background: var(--primary-soft-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #971c13; }
.btn-text-danger { background: none; color: var(--danger); padding: 0 6px; }
.btn-text-danger:hover { background: var(--danger-soft); }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-ghost.is-loading::after { border-color: var(--line-strong); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 10px; border: 1px solid transparent; background: none; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.icon-btn-danger:hover { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

/* ============ Página ============ */
.page { max-width: 1240px; margin: 0 auto; padding: 28px var(--gutter) 64px; }
.page-narrow { max-width: 880px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 22px; }
.eyebrow { font-size: .78rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--green-ink); margin-bottom: 6px; }
.lead { color: var(--ink-2); margin-top: 6px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .9rem; margin: 0 0 14px -4px; padding: 4px; }
.back:hover { color: var(--ink); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(16px, 2.4vw, 26px); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { font-size: .84rem; color: var(--muted); margin-top: 2px; }

.badge {
  display: inline-flex; align-items: center; margin-left: 8px; padding: 2px 8px; vertical-align: middle;
  border-radius: 999px; background: var(--warn-soft); border: 1px solid var(--warn-line);
  color: #8a5a00; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--warn-soft); border: 1px solid var(--warn-line); color: #6b4a07;
  border-radius: 14px; padding: 12px 16px; margin-bottom: 18px; font-size: .9rem;
}
.banner .icon { margin-top: 2px; color: #a06c00; }

/* ============ Listado ============ */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.search {
  flex: 1 1 320px; max-width: 460px; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; padding: 0 14px; height: 48px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(139, 63, 142, .12); }
.search .icon { color: var(--muted); }
.search input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; height: 100%; font-size: .98rem; }
.count { color: var(--muted); font-size: .88rem; font-weight: 550; }

.patient-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-head, .patient-row {
  display: grid; grid-template-columns: minmax(240px, 2.2fr) 1fr 1fr minmax(170px, 1.1fr) 28px;
  align-items: center; gap: 16px; padding: 14px 20px;
}
.list-head { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); padding-block: 10px; }
.patient-row { text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); transition: background .12s; }
.patient-row:last-child { border-bottom: 0; }
.patient-row:hover { background: #fafcf6; }
.patient-row:hover .pr-go { color: var(--primary); transform: translateX(2px); }
.pr-person { display: flex; align-items: center; gap: 14px; min-width: 0; }
.avatar {
  flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: var(--green-soft); color: var(--green-ink); font-weight: 700; font-size: .85rem; letter-spacing: .02em;
}
.avatar-lg { width: 60px; height: 60px; font-size: 1.15rem; }
.pr-main { display: flex; flex-direction: column; min-width: 0; }
.pr-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.pr-sub { font-size: .82rem; color: var(--muted); }
.pr-label { display: none; }
.pr-value { font-weight: 550; font-variant-numeric: tabular-nums; }
.pr-trend { display: flex; align-items: center; gap: 12px; }
.pr-go { color: var(--line-strong); transition: transform .15s, color .15s; }
.sparkline path { fill: none; stroke: var(--green); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.sparkline circle { fill: var(--green); }

@media (max-width: 900px) {
  .list-head { display: none; }
  .patient-row { grid-template-columns: 1fr 1fr auto; grid-template-areas: 'person person go' 'last weight trend'; gap: 12px; padding: 16px; }
  .pr-person { grid-area: person; }
  .pr-go { grid-area: go; }
  .pr-last { grid-area: last; padding-left: 56px; }
  .pr-weight { grid-area: weight; }
  .pr-trend { grid-area: trend; justify-self: end; }
  .pr-trend .sparkline { display: none; }
  .pr-col { display: flex; flex-direction: column; }
  .pr-label { display: block; font-size: .7rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
}
@media (max-width: 480px) {
  .pr-last { padding-left: 0; }
}

/* ============ Estados vacíos y carga ============ */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 20px; color: var(--ink-2); }
.empty > .icon { width: 40px; height: 40px; color: var(--green-ink); background: var(--green-soft); border-radius: 50%; padding: 9px; margin-bottom: 6px; }
.empty-title { font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.empty .btn { margin-top: 10px; }
.empty-inline { padding: 18px 10px 6px; }
.skeleton-list { display: grid; gap: 12px; padding: 16px; }
.skeleton-list div { height: 56px; border-radius: 12px; background: linear-gradient(90deg, #eef0eb 0%, #f7f8f5 50%, #eef0eb 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============ Ficha del paciente ============ */
.patient-head { align-items: center; }
.patient-id { display: flex; align-items: center; gap: 16px; min-width: 0; }
.meta { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: .9rem; }
.meta li { display: inline-flex; align-items: center; gap: 6px; }
.meta .icon { width: 16px; height: 16px; color: var(--muted); }
.meta a { color: inherit; text-decoration: none; }
.meta a:hover { color: var(--primary); text-decoration: underline; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); min-width: 0;
}
.tile-label { font-size: .76rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tile-value { font-size: clamp(1.5rem, 1.1rem + 1.2vw, 2rem); font-weight: 720; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.25; margin-top: 4px; }
.tile-value small { font-size: .5em; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.tile-value-text { font-size: clamp(1.15rem, 1rem + .6vw, 1.4rem); padding-block: 4px 3px; }
.tile-sub { font-size: .82rem; color: var(--ink-2); }
.tile-accent.is-down { background: linear-gradient(160deg, #eef6e2 0%, #ffffff 70%); border-color: var(--green-soft-2); }
.tile-accent.is-down .tile-value { color: var(--down); }
.tile-accent.is-up { background: linear-gradient(160deg, #fbf0e6 0%, #ffffff 70%); border-color: #f1dcc8; }
.tile-accent.is-up .tile-value { color: var(--up); }
.tiles-large .tile { padding: 20px 22px; }
.tiles-large .tile-value { font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.5rem); }
@media (max-width: 960px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 380px) { .tile { padding: 14px; } }

.chart-card { margin-bottom: 16px; }
.chart-card .card-head { margin-bottom: 6px; }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--ink-2); flex-wrap: wrap; justify-content: flex-end; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-line { width: 18px; height: 3px; border-radius: 2px; background: var(--green); position: relative; }
.legend-line::after { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 2px solid var(--green); left: 50%; top: 50%; transform: translate(-50%, -50%); box-sizing: border-box; }
.legend-dash { width: 20px; height: 0; border-top: 2px dashed var(--target); }
.chart-wrap { position: relative; }
.chart-empty { position: absolute; inset: auto 0 44px; display: flex; justify-content: center; pointer-events: none; }
.chart-empty p { background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; font-size: .88rem; color: var(--ink-2); text-align: center; box-shadow: var(--shadow); }

/* Gráfica */
.chart { position: relative; width: 100%; }
.chart-svg { width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-svg:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 8px; }
.chart-grid line { stroke: #eef0eb; stroke-width: 1; }
.chart-grid .chart-baseline { stroke: var(--line-strong); }
.chart-grid .chart-tick { stroke: var(--line-strong); }
.chart-axis-label { font-size: 11.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-axis-unit { font-size: 11px; fill: var(--muted); font-weight: 700; }
.chart-line { fill: none; stroke: var(--green); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.area-stop-top { stop-color: var(--brand-green); stop-opacity: .28; }
.area-stop-bottom { stop-color: var(--brand-green); stop-opacity: 0; }
.chart-dot { fill: var(--surface); stroke: var(--green); stroke-width: 2; transition: r .12s; }
.chart-dot.is-last { fill: var(--green); stroke: var(--surface); stroke-width: 2.5; }
.chart-dot.is-first { stroke-dasharray: none; }
.chart-dot.is-active { r: 7; fill: var(--green); stroke: var(--surface); stroke-width: 3; }
.chart-target line { stroke: var(--target); stroke-width: 1.6; stroke-dasharray: 6 5; }
.chart-target-pill { fill: var(--primary-soft); stroke: var(--primary-soft-2); }
.chart-target-label { font-size: 11px; font-weight: 650; fill: var(--target); }
.chart-last-label { font-size: 13px; font-weight: 750; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.chart-first-label { font-size: 11.5px; font-weight: 600; fill: var(--ink-2); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.chart-guide { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: .5; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 132px;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 9px 12px; box-shadow: 0 10px 28px rgba(21,36,43,.25);
  font-size: .82rem; line-height: 1.35;
}
.tt-date { color: #b8c6cb; font-size: .76rem; }
.tt-weight { font-size: 1.1rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.tt-meta { color: #d5dfe2; }

/* Columnas inferiores */
.columns { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 960px) { .columns { grid-template-columns: 1fr; } }

/* Historial */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 12px; padding-bottom: 6px; }
.tl-item::before { content: ''; position: absolute; left: 10px; top: 22px; bottom: -4px; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--green); background: var(--surface); margin: 17px 0 0 5px; position: relative; z-index: 1; }
.tl-item:first-child .tl-dot { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.tl-initial .tl-dot { border-color: var(--muted); }
.tl-content { padding: 10px 0 14px; border-bottom: 1px solid var(--line); min-width: 0; }
.tl-item:last-child .tl-content { border-bottom: 0; }
.tl-head { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; }
.tl-date { font-weight: 650; }
.tl-when { font-size: .8rem; color: var(--muted); }
.tl-weight { display: flex; align-items: center; gap: 10px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-actions { display: flex; gap: 2px; }
.note { margin-top: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.note p { font-size: .92rem; color: var(--ink-2); overflow-wrap: anywhere; }
.note-label { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.note-adjust { background: #faf4fa; border-color: var(--primary-soft-2); }
.note-adjust .note-label { color: var(--target); }
@media (max-width: 560px) {
  .tl-head { grid-template-columns: 1fr auto; }
  .tl-weight { grid-column: 1; grid-row: 2; }
  .tl-actions { grid-column: 2; grid-row: 1 / 3; }
}

/* Chips de cambio */
.chip {
  display: inline-flex; align-items: center; gap: 3px; padding: 3px 10px; border-radius: 999px;
  font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip-sm { padding: 2px 8px; font-size: .76rem; }
.chip-icon { width: 11px; height: 11px; }
.chip.is-down { background: var(--down-soft); color: var(--down); }
.chip.is-up { background: var(--up-soft); color: var(--up); }
.chip.is-flat { background: var(--flat-soft); color: var(--flat); }

/* Ficha clínica */
.facts { margin: 0 0 8px; display: grid; gap: 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.clin-block { margin-top: 16px; }
.clin-block h3 { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.clin-block p { color: var(--ink-2); font-size: .92rem; overflow-wrap: anywhere; }

/* ============ Formularios ============ */
.form-card { padding: clamp(18px, 3vw, 32px); }
fieldset { border: 0; padding: 0; margin: 0 0 26px; min-width: 0; }
legend { font-weight: 700; font-size: 1rem; padding: 0; margin-bottom: 14px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; width: 100%; }
legend::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.grid-2, .grid-3 { display: grid; gap: 0 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :first-child:nth-last-child(3) { grid-column: 1 / -1; } }
@media (max-width: 480px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.field { margin-bottom: 16px; min-width: 0; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.optional { font-weight: 500; color: var(--muted); font-size: .8rem; }
.input-wrap { position: relative; }
.input-wrap input, .input-wrap textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.input-wrap input:hover, .input-wrap textarea:hover { border-color: #b8c4c0; }
.input-wrap input:focus, .input-wrap textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(139, 63, 142, .12); }
.has-unit input { padding-right: 52px; font-variant-numeric: tabular-nums; }
.unit { position: absolute; right: 6px; top: 6px; bottom: 6px; display: grid; place-items: center; min-width: 38px; padding: 0 8px; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); font-weight: 650; font-size: .85rem; pointer-events: none; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.field-error { font-size: .82rem; color: var(--danger); margin-top: 5px; font-weight: 550; }
.has-error input, .has-error textarea { border-color: var(--danger); background: #fffafa; }
.has-error input:focus, .has-error textarea:focus { box-shadow: 0 0 0 4px rgba(180, 35, 24, .12); border-color: var(--danger); }
.form-alert { background: var(--danger-soft); color: var(--danger); border: 1px solid #f7cfca; padding: 10px 14px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; font-size: .9rem; }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 20px; }
.form-actions-main { display: flex; gap: 10px; margin-left: auto; }
input[type='date'] { -webkit-appearance: none; appearance: none; }
input[type='date']::-webkit-date-and-time-value { text-align: left; }

/* ============ Diálogos ============ */
.dialog {
  border: 0; padding: 0; border-radius: 20px; width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: var(--shadow-lg); background: var(--surface); color: var(--ink);
}
.dialog-wide { width: min(600px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(21, 36, 43, .42); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dialog-body { padding: clamp(18px, 4vw, 28px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.dialog-title { font-size: 1.2rem; font-weight: 720; letter-spacing: -0.01em; }
.dialog-sub { color: var(--muted); font-size: .9rem; }
.dialog-text { color: var(--ink-2); margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.dialog-confirm .dialog-actions { margin-top: 24px; }
.delta-preview { margin: -4px 0 14px; font-size: .88rem; color: var(--ink-2); min-height: 1.4em; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
@media (max-width: 480px) {
  .dialog-actions .btn { flex: 1; }
}

/* ============ Avisos ============ */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: .9rem; box-shadow: 0 12px 32px rgba(21,36,43,.25); opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
.toast.is-visible { opacity: 1; transform: none; }
.toast-error { background: var(--danger); }

/* ============ Vista para el paciente ============ */
.present-mode .topbar { display: none; }
.present-mode { background: linear-gradient(180deg, var(--bg-tint) 0, var(--bg) 420px); }
.present { max-width: 1100px; margin: 0 auto; padding: 20px var(--gutter) 64px; }
.present-bar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 26px; }
.present-head { text-align: center; margin-bottom: 26px; }
.present-logo { height: 52px; width: auto; margin: 0 auto 18px; }
.present-head h1 { font-size: clamp(1.8rem, 1.2rem + 2.4vw, 2.8rem); }
.chart-card-large { padding: clamp(16px, 3vw, 32px); }
.measure-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.measure-table th { text-align: left; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.measure-table td { padding: 11px 10px; border-bottom: 1px solid var(--line); }
.measure-table tr:last-child td { border-bottom: 0; }
.measure-table .num { text-align: right; }
.measure-table th:nth-child(n+2) { text-align: right; }

/* ============ Acceso ============ */
.login-page { min-height: 100dvh; background: radial-gradient(1100px 600px at 100% 0%, #e8f3d8 0%, transparent 60%), radial-gradient(800px 500px at 0% 100%, #f6ecf6 0%, transparent 60%), var(--bg); }
.login { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); align-items: center; gap: 48px; max-width: 1120px; margin: 0 auto; padding: 32px var(--gutter); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: clamp(24px, 5vw, 44px); box-shadow: 0 2px 4px rgba(21,36,43,.03), 0 24px 60px rgba(21,36,43,.08); }
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 30px; }
.login-logo { width: min(220px, 70%); height: auto; }
.login-brand .brand-clinic { padding-left: 4px; }
.login-title { font-size: 1.6rem; }
.login-sub { color: var(--ink-2); margin: 6px 0 24px; }
.login-card .btn-block { --h: 48px; margin-top: 6px; }
.login-foot { margin-top: 20px; font-size: .82rem; color: var(--muted); text-align: center; }
.login-art { padding: 24px; }
.login-chart { width: 100%; height: auto; }
.la-grid { stroke: #dfe5d8; stroke-width: 1; fill: none; }
.la-target { stroke: var(--target); stroke-width: 1.6; stroke-dasharray: 6 5; fill: none; opacity: .7; }
.la-area { fill: var(--brand-green); opacity: .18; }
.la-line { fill: none; stroke: var(--green); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 600; stroke-dashoffset: 600; animation: draw 1.6s .2s ease-out forwards; }
.la-dots circle { fill: #fff; stroke: var(--green); stroke-width: 2.2; }
.la-dots circle:last-child { fill: var(--green); stroke: #fff; }
.login-art-caption { margin-top: 18px; font-size: 1.15rem; font-weight: 650; color: var(--ink-2); letter-spacing: -0.01em; max-width: 26ch; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; justify-items: center; }
  .login-card { width: 100%; max-width: 480px; }
  .login-art { display: none; }
}

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

/* ============ Impresión ============ */
@media print {
  body, .present-mode { background: #fff; font-size: 12px; }
  .no-print, .topbar, .toasts { display: none !important; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
  .present { padding: 0; max-width: none; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
}
.tiles-large .tile-value.tile-value-text { font-size: clamp(1.2rem, 1rem + .8vw, 1.6rem); }
