:root {
  color-scheme: light dark;
  --bg: #f2f2f6;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-2: #5a5a60;
  --hair: rgba(60, 60, 67, 0.14);
  --blue: #2a78d6;
  --track: #d6e5f8;
  --warn: #9a5b00;
  --warn-fill: #eda100;
  --crit: #c4302f;
  --crit-fill: #e34948;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", system-ui, "Helvetica Neue", Arial, sans-serif;
  --gap: 16px;
  --pad: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1b1b1e;
    --text: #f5f5f7;
    --text-2: #a6a6ae;
    --hair: rgba(235, 235, 245, 0.14);
    --blue: #3987e5;
    --track: #1f3556;
    --warn: #f0b13c;
    --warn-fill: #d99200;
    --crit: #ff7573;
    --crit-fill: #e66767;
    --shadow: none;
  }
}
@media (prefers-reduced-transparency: reduce) { .bar { backdrop-filter: none !important; background: var(--bg) !important; } }
@media (prefers-contrast: more) { :root { --hair: currentColor; } }
@media (max-width: 520px) {
  :root { --pad: 18px; --gap: 12px; }
  #s-chart .card-head { flex-wrap: wrap; }
  #s-chart .tools { flex-basis: 100%; justify-content: space-between; margin: 0 -6px 0 0; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 1rem/1.5 var(--font); font-optical-sizing: auto; -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
::selection { background: color-mix(in srgb, var(--blue) 30%, transparent); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 6px; }
button { font: inherit; color: inherit; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
h1, h2, h3, p, ul, dl, dd { margin: 0; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.plain { list-style: none; padding: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* barra superior */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 10px max(16px, calc((100vw - 880px) / 2)) 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
}
.bar h1 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; flex: 1; white-space: nowrap; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 0.8125rem; color: var(--text-2); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); }
.live[data-state="on"] i { background: #1baf7a; }
.live[data-state="on"] i.ping { animation: ping 700ms var(--ease-out); }
.live[data-state="off"] i { background: var(--crit-fill); }
@keyframes ping { from { box-shadow: 0 0 0 0 rgba(27, 175, 122, 0.55); } to { box-shadow: 0 0 0 9px rgba(27, 175, 122, 0); } }
.quiet {
  appearance: none; border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  font-size: 0.8125rem; padding: 8px 10px; min-height: 36px; border-radius: 10px;
}
.quiet:active { transform: scale(0.97); transition: transform 100ms ease-out; background: var(--hair); }
.bar .tabs { order: 3; flex-basis: 100%; }

/* selector segmentado (pestañas y rango) */
.seg { position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; border-radius: 11px; background: var(--hair); }
.seg button {
  position: relative; z-index: 1; appearance: none; border: 0; background: none; cursor: pointer;
  min-height: 34px; padding: 0 16px; font-size: 0.9375rem; font-weight: 500; border-radius: 9px; color: var(--text-2);
}
.seg button[aria-selected="true"], .seg button[aria-pressed="true"] { color: var(--text); }
.seg .thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 9px; background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
@media (prefers-color-scheme: dark) { .seg .thumb { background: #3a3a3f; } }
.tabs { display: grid; width: 100%; max-width: 460px; margin: 0 auto; }
@media (pointer: coarse) { .quiet, .seg button { min-height: 44px; } .quiet { padding: 10px 14px; } }

main { width: min(880px, 100% - 32px); margin: 0 auto; padding: 12px 0 56px; }
@media (max-width: 520px) { main { width: calc(100% - 24px); } }
.panel { display: grid; gap: var(--gap); }
.panel[hidden] { display: none; }
.cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); align-items: start; }
/* una tarjeta suelta en la última fila ocupa todo el ancho */
.cards > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
.group-h { padding: 14px 4px 0; display: grid; gap: 2px; }
.group-h h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.02em; }

/* tarjeta: una sola elevación, un solo radio */
.card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: var(--pad); display: grid; gap: 16px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head > div:first-child { min-width: 0; }
.card h2 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.012em; text-wrap: balance; }
.hint { color: var(--text-2); font-size: 0.8125rem; line-height: 1.45; margin-top: 2px; text-wrap: pretty; }
.tools { display: flex; align-items: center; gap: 4px; flex: none; margin: -6px -6px 0 0; }

/* cuota */
.quota { gap: 20px; }
.card .headline, .headline { font-size: clamp(1.75rem, 5.2vw, 2.5rem); line-height: 1.08; letter-spacing: -0.025em; font-weight: 600; }
.headline .soft { color: var(--text-2); font-weight: 500; }
.meter { position: relative; height: 26px; border-radius: 13px; background: var(--track); overflow: hidden; }
.fill { position: absolute; inset: 0; background: var(--blue); clip-path: inset(0 100% 0 0 round 13px); }
.meter[data-level="warn"] .fill { background: var(--warn-fill); }
.meter[data-level="crit"] .fill { background: var(--crit-fill); }
.tick { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--text); opacity: 0.7; left: 0; }
.meter[data-empty] .tick { display: none; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 22px; color: var(--text-2); font-size: 0.9375rem; }
.facts b { color: var(--text); font-weight: 600; }
.key { display: inline-block; width: 2px; height: 0.9em; background: var(--text); opacity: 0.7; vertical-align: -0.1em; margin-right: 8px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.9375rem; }
.status svg { width: 18px; height: 18px; flex: none; }
.status[data-level="ok"] svg { color: #1baf7a; }
.status[data-level="warn"] { color: var(--warn); }
.status[data-level="crit"] { color: var(--crit); }
.notice { color: var(--text-2); font-size: 0.9375rem; }

/* tokens */
.total { font-size: 1.5rem; letter-spacing: -0.022em; line-height: 1.12; font-weight: 600; }
.total .soft { color: var(--text-2); font-weight: 500; }
dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
@media (min-width: 640px) { dl { grid-template-columns: repeat(3, 1fr); } }
dl > div { display: grid; gap: 2px; align-content: start; }
dt { color: var(--text-2); font-size: 0.8125rem; }
dd { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.012em; }
dd small { color: var(--text-2); font-weight: 400; font-size: 0.8125rem; margin-left: 6px; }

/* pistas */
.insight { display: grid; grid-template-columns: 22px 1fr; gap: 12px; }
.insights-list { display: grid; gap: 18px; }
.insight .ico svg { width: 20px; height: 20px; display: block; margin-top: 1px; }
.insight[data-level="ok"] .ico { color: var(--text-2); }
.insight[data-level="warn"] .ico { color: var(--warn); }
.insight-head { font-weight: 600; letter-spacing: -0.01em; text-wrap: pretty; }
.insight-body { margin-top: 2px; color: var(--text-2); font-size: 0.9375rem; text-wrap: pretty; }

/* gráficos */
.plot { position: relative; touch-action: pan-y; outline-offset: 6px; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.plot svg { display: block; width: 100%; overflow: visible; }
.plot .grid { stroke: var(--hair); stroke-width: 1; }
.plot text { fill: var(--text-2); font: 400 11px var(--font); }
.plot .bar-mark { fill: var(--blue); }
.plot .bar-mark[data-hot] { filter: brightness(1.12); }
.plot .cursor { fill: var(--text); opacity: 0.06; }
.tip {
  position: absolute; top: 0; left: 0; pointer-events: none; z-index: 3; opacity: 0;
  padding: 8px 12px; border-radius: 12px; background: var(--card); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 10px 28px rgba(0, 0, 0, 0.22);
  font-size: 0.8125rem; line-height: 1.35; white-space: nowrap; color: var(--text-2); transition: opacity 120ms ease-out;
}
.tip b { display: block; color: var(--text); font-size: 0.9375rem; font-weight: 600; }
.tip[data-on] { opacity: 1; }
.sum { color: var(--text-2); font-size: 0.8125rem; line-height: 1.45; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.data-table th, .data-table td { text-align: left; padding: 8px 0; border-bottom: 1px solid var(--hair); }
.data-table td:last-child, .data-table th:last-child { text-align: right; }
.data-table th { color: var(--text-2); font-weight: 500; }
.data-table-wrap { max-height: 300px; overflow: auto; }

/* listas con barra proporcional */
.rows { display: grid; gap: 14px; }
.row { display: grid; gap: 6px; }
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
.row-label { font-weight: 500; font-size: 0.9375rem; letter-spacing: -0.005em; min-width: 0; overflow-wrap: anywhere; }
.row-val { color: var(--text-2); font-size: 0.9375rem; white-space: nowrap; }
.row-sub { color: var(--text-2); font-size: 0.8125rem; line-height: 1.4; }
.hbar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.hbar i {
  display: block; height: 100%; background: var(--blue);
  clip-path: inset(0 calc(100% - var(--p, 0%)) 0 0 round 3px); transition: clip-path 600ms var(--ease-out);
}
.first .hbar i { transition-delay: calc(var(--i, 0) * 45ms); }

footer { color: var(--text-2); font-size: 0.8125rem; display: grid; gap: 4px; padding: 20px 4px 0; text-align: center; }

/* entrada: cada tarjeta llega (desenfoque + ascenso), una sola vez, al verse */
[data-enter] { opacity: 0; filter: blur(10px); transform: translateY(10px) scale(0.985); }
[data-enter].in {
  opacity: 1; filter: none; transform: none;
  transition: opacity 600ms var(--ease-out), filter 600ms var(--ease-out), transform 700ms var(--ease-out);
  transition-delay: var(--d, 0ms);
}
@media (prefers-reduced-motion: reduce) {
  [data-enter] { filter: none; transform: none; }
  [data-enter].in { transition: opacity 200ms ease; transition-delay: 0ms; }
  .live[data-state="on"] i.ping { animation: none; }
  .tip { transition: none; }
  .hbar i { transition: clip-path 200ms ease; }
  .first .hbar i { transition-delay: 0ms; }
}

/* acceso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); display: grid; gap: 18px; padding: 28px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); }
.login h1 { font-size: 1.75rem; letter-spacing: -0.025em; font-weight: 600; line-height: 1.1; flex: none; }
.login p { color: var(--text-2); }
.login label { display: grid; gap: 8px; font-size: 0.9375rem; font-weight: 500; }
.login input { font: inherit; font-size: 1rem; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--hair); background: var(--bg); color: var(--text); }
.login input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.primary { appearance: none; border: 0; cursor: pointer; min-height: 48px; border-radius: 12px; font-weight: 600; font-size: 1rem; background: #236cc2; color: #fff; }
.primary:active { transform: scale(0.97); transition: transform 100ms ease-out; }
.primary[disabled] { opacity: 0.6; cursor: default; }
.err { color: var(--crit); font-size: 0.9375rem; min-height: 1.4em; }

.more { justify-self: start; margin-left: -10px; }
