/* per-salud — un registro que se lee como el visor del tensiómetro.
   Superficie fría y silenciosa; el único elemento con voz propia son los números. */

:root {
  color-scheme: light;
  --bg: #f2f4f6;
  --panel: #ffffff;
  --ink: #17202b;
  --ink-2: #4c5866;
  --ink-3: #7a8592;
  --line: #dde2e7;
  --line-strong: #c4ccd4;
  --accent: #23407a;          /* acción principal: azul tinta */
  --accent-ink: #ffffff;
  --accent-soft: #e3e9f5;
  --focus: #2a78d6;

  /* series (paleta validada: sistólica, diastólica, pulso) */
  --s-sys: #2a78d6;
  --s-dia: #eb6834;
  --s-pulse: #1baf7a;
  --s-other: #6250d6;

  /* estado (reservados; siempre con texto) */
  --good: #0a7d0a;
  --warning: #9a6a00;
  --serious: #c2561f;
  --critical: #c63434;
  --critical-soft: #fbe9e9;

  --grid: #e6e9ed;
  --radius-display: 22px;
  --radius-ctl: 10px;
  --num: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121417;
    --panel: #1b1f24;
    --ink: #e9edf1;
    --ink-2: #b2bcc7;
    --ink-3: #8592a0;
    --line: #2a3038;
    --line-strong: #3a424c;
    --accent: #8fb0ef;
    --accent-ink: #0f1830;
    --accent-soft: #233150;
    --s-sys: #3987e5;
    --s-dia: #d95926;
    --s-pulse: #199e70;
    --s-other: #9085e9;
    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #e66767;
    --critical-soft: #3a1f21;
    --grid: #252a31;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; margin-top: 1.25rem; }
p { margin: 0 0 1rem; max-width: 65ch; }
small, .small { font-size: .8125rem; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------- marca */
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; letter-spacing: -.01em; }
.brand-mark { width: 24px; height: 24px; border-radius: 7px; background: url("/static/icons/icon-192.png") center / cover; }

/* ------------------------------------------------------------- estructura */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(env(safe-area-inset-top, 0px) + .75rem) 1rem .75rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.sync { margin: 0; font-size: .8125rem; color: var(--warning); }
main { max-width: 640px; margin: 0 auto; padding: .25rem 1rem calc(88px + var(--safe-b)); }
.tab > h2 { margin-top: 1.5rem; }
.tab > h2:first-child { margin-top: .5rem; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: .375rem .5rem calc(.375rem + var(--safe-b));
  background: var(--panel); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .375rem 0; color: var(--ink-3); text-decoration: none; font-size: .75rem; font-weight: 550;
  border-radius: var(--radius-ctl);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* ------------------------------------------------------------- controles */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: 0 1rem; border-radius: var(--radius-ctl);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, var(--line)); }
.btn.block { width: 100%; min-height: 52px; font-size: 1.0625rem; }
.btn[disabled] { opacity: .55; cursor: progress; }

.field { display: grid; gap: .25rem; margin-bottom: 1rem; }
.field > span, .chips legend, .login-form label { font-size: .875rem; color: var(--ink-2); font-weight: 550; }
.field > span small { color: var(--ink-3); font-weight: 400; margin-left: .25rem; }
input, select {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: var(--radius-ctl);
  min-height: 44px; padding: .5rem .75rem; width: 100%;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--critical); font-weight: 550; }
.hint { font-size: .8125rem; color: var(--ink-3); margin: .5rem .25rem 1.25rem; }

.chips { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.chips legend { padding: 0; margin-bottom: .375rem; float: left; width: 100%; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; inset: 0; margin: 0; min-height: 0; cursor: pointer; }
.chips span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 .875rem;
  border: 1px solid var(--line-strong); border-radius: 999px; font-size: .9375rem; font-weight: 550;
  color: var(--ink-2); background: var(--panel);
}
.chips input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.chips input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------- el visor (elemento protagonista) */
.display {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "sys sys" "dia dia" "cat cat";
  background: var(--panel);
  border-radius: var(--radius-display);
  padding: .75rem 1.25rem 1rem;
  border: 1px solid var(--line);
}
.readout { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.readout-sys { grid-area: sys; border-bottom: 1px solid var(--line); }
.readout-dia { grid-area: dia; }
.readout-label { font-size: .9375rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.readout-label small { display: block; font-weight: 500; color: var(--ink-3); font-size: .75rem; }
.readout-sys .readout-label { border-left: 4px solid var(--s-sys); padding-left: .5rem; }
.readout-dia .readout-label { border-left: 4px solid var(--s-dia); padding-left: .5rem; }
.readout input {
  border: 0; background: transparent; padding: 0; min-height: 0; border-radius: 6px;
  text-align: right; width: 3.2ch;
  font-family: var(--num); font-variant-numeric: tabular-nums; font-weight: 600;
  letter-spacing: -.03em; color: var(--ink); caret-color: var(--accent);
}
.readout-sys input { font-size: clamp(4rem, 21vw, 6rem); line-height: 1.05; }
.readout-dia input { font-size: clamp(3.25rem, 16vw, 4.5rem); line-height: 1.1; }
.readout input::placeholder { color: var(--line-strong); }
.readout input:focus-visible { outline: none; background: var(--accent-soft); }
.live-category {
  grid-area: cat; margin: .25rem 0 0; padding-top: .5rem; border-top: 1px solid var(--line);
  font-size: .9375rem; font-weight: 600; text-align: right; min-height: 2rem;
}
.more { margin-top: 1.5rem; }
.more[open] summary { margin-bottom: 1rem; }
.switch { margin: 1rem 0 0; text-align: center; color: var(--ink-2); font-size: .9375rem; }
.login-form label small { color: var(--ink-3); font-weight: 400; margin-left: .25rem; }
.password-form { max-width: 28rem; }

/* categorías: color de estado + texto, nunca solo color */
.cat { display: inline-flex; align-items: center; gap: .375rem; font-weight: 600; }
.cat::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.cat-normal { color: var(--good); }
.cat-elevada { color: var(--warning); }
.cat-hta1 { color: var(--serious); }
.cat-hta2, .cat-crisis { color: var(--critical); }
.cat-crisis::before { border-radius: 2px; transform: rotate(45deg); }

.alert-crisis {
  margin: 1rem 0; padding: 1rem; border-radius: 14px;
  background: var(--critical-soft); border-left: 4px solid var(--critical); color: var(--ink);
}

/* ------------------------------------------------------------- vistazo 7 días */
.glance { margin-top: 2rem; }
.glance-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 0; }
.glance-grid div { min-width: 0; }
.glance-grid dt { font-size: .8125rem; color: var(--ink-3); }
.glance-grid dd { margin: 0; font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 1.625rem; font-weight: 600; }
.glance-grid dd small { font-family: var(--ui); font-size: .75rem; color: var(--ink-3); font-weight: 500; }

/* ------------------------------------------------------------- gráfico */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .5rem 0 1rem; }
.select select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
.chart-figure { position: relative; margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: .875rem .5rem .5rem; }
.chart-title { padding: 0 .5rem .25rem; font-weight: 650; }
.chart-title small { display: block; font-weight: 500; color: var(--ink-3); }
.chart { width: 100%; height: 280px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart text { font: 11px var(--ui); fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .center { stroke: var(--ink-2); stroke-width: 1.25; }
.chart .limit { stroke: var(--ink-2); stroke-width: 1.25; stroke-dasharray: 6 4; }
.chart .ref { stroke: var(--warning); stroke-width: 1.5; stroke-dasharray: 2 4; stroke-linecap: round; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { stroke: var(--panel); stroke-width: 2; }
.chart .pt-signal { fill: var(--panel); stroke: var(--critical); stroke-width: 2.5; }
.chart .label-line, .chart .label-ref { font-weight: 600; fill: var(--ink-2); paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.chart .label-ref { fill: var(--warning); }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.chart-tip {
  position: absolute; z-index: 3; pointer-events: none; min-width: 9rem;
  padding: .5rem .625rem; border-radius: 10px; background: var(--ink); color: var(--bg);
  font-size: .8125rem; line-height: 1.35; box-shadow: 0 6px 20px rgb(0 0 0 / .18);
}
.chart-tip b { font-family: var(--num); font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem 1rem; margin: 1.25rem .25rem; }
.stats dt { font-size: .75rem; color: var(--ink-3); }
.stats dd { margin: 0; font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 1.25rem; font-weight: 600; }

.signals ul { list-style: none; margin: 0; padding: 0; }
.signals li { padding: .625rem 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: .75rem; }
.signals .rule { font-weight: 700; color: var(--critical); font-variant-numeric: tabular-nums; }
.signals li.none { display: block; color: var(--ink-2); }

details { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: .75rem; }
summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.explain p, .explain ul { color: var(--ink-2); font-size: .9375rem; }
.table-wrap { overflow-x: auto; margin-top: .5rem; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .375rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--ink-3); font-weight: 600; }

/* ------------------------------------------------------------- historial */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: .5rem 0 .25rem; }
.list-head h2 { margin: 0; }
.day { margin-top: 1.25rem; }
.day h3 { font-size: .875rem; color: var(--ink-3); font-weight: 600; margin: 0 0 .25rem; }
.reading {
  display: grid; grid-template-columns: 3.25rem 1fr auto; align-items: center; gap: .75rem;
  width: 100%; padding: .625rem .25rem; border: 0; border-bottom: 1px solid var(--line);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.reading time { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: .9375rem; }
.reading .val { font-family: var(--num); font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.reading .val small { font-family: var(--ui); font-size: .8125rem; color: var(--ink-3); font-weight: 500; margin-left: .375rem; }
.reading .notes { display: block; font-size: .8125rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading .cat { font-size: .8125rem; }
.reading.pending { opacity: .7; }

/* ------------------------------------------------------------- ajustes */
.copy-row { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.copy-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: .625rem .75rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-ctl); font-size: .875rem; }
.connections { list-style: none; padding: 0; margin: 0 0 1rem; }
.connections li { padding: .5rem 0; border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------- diálogos y avisos */
.sheet {
  width: min(560px, 100%); margin: auto auto 0; max-height: 92vh;
  border: 0; border-radius: 20px 20px 0 0; padding: 1.25rem 1rem calc(1rem + var(--safe-b));
  background: var(--bg); color: var(--ink);
}
.sheet::backdrop { background: rgb(10 14 20 / .45); }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.edit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.row-actions { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }
.row-actions .spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); z-index: 20; transform: translateX(-50%);
  max-width: calc(100% - 2rem); padding: .75rem 1rem; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 550; box-shadow: 0 8px 24px rgb(0 0 0 / .2);
}
@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: toast-in .22s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* ------------------------------------------------------------- login y OAuth */
.login, .oauth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-form, .oauth-card {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-display); padding: 1.5rem;
}
.login-form h1, .oauth-card h1 { margin: 1rem 0 1.25rem; font-size: 1.375rem; }
.login-form input, .oauth-card input { margin: .25rem 0 1rem; }
.oauth-brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; }
.oauth-card label { font-size: .875rem; color: var(--ink-2); font-weight: 550; }
.oauth-card code { font-size: .9em; }
.oauth-card .row-actions .btn { flex: 1; }
