:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --neutral-bar: #52514e;
  --good: #006300;
  --good-fill: #0ca30c;
  --bad: #b3261e;
  --critical-fill: #d03b3b;
  --warning-fill: #fab219;
  --focus: #2a78d6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --neutral-bar: #c3c2b7;
    --good: #0ca30c;
    --bad: #e66767;
    --focus: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a988f;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --neutral-bar: #c3c2b7;
  --good: #0ca30c;
  --bad: #e66767;
  --focus: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--text-muted); }

.wordmark {
  font-family: "Jost", var(--font);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.02em;
}

/* Botones */
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 9px 16px; background: none; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--text-primary); color: var(--surface); font-weight: 600; }
.ghost { border-color: var(--border); background: var(--surface); }
.ghost:hover { background: var(--surface-2); }
.small { padding: 5px 10px; font-size: 13px; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px 28px;
}
.login-card h1 { font-size: 22px; margin: 20px 0 8px; }
.login-card form { display: grid; gap: 8px; margin-top: 20px; }
.login-card label { font-size: 13px; color: var(--text-secondary); }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--baseline); background: var(--page);
}
.login-card button.primary { margin-top: 6px; }
.login-msg { min-height: 1em; color: var(--text-secondary); font-size: 14px; }
.login-sent { margin-top: 20px; }

/* Barra superior */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-sub { color: var(--text-muted); font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--text-secondary); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Página */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 4px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters select {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); max-width: 100%;
}
.segmented { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { padding: 6px 12px; font-size: 14px; border-radius: 7px; color: var(--text-secondary); }
.segmented button:hover { color: var(--text-primary); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text-primary); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.range { margin: 0; font-size: 14px; }

.content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; transition: opacity .15s; }
.content > *, .block > *, .page-head > *, .chart-grid > * { min-width: 0; }
.content.loading { opacity: .5; }

/* Titular */
.hero {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
}
.hero-value { font-size: 52px; font-weight: 600; line-height: 1.05; margin: 6px 0 8px; letter-spacing: -0.02em; }

.status { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 10px; background: var(--surface-2); }
.status div { display: grid; }
.status strong { font-size: 15px; }
.status span:not(.status-icon) { font-size: 13px; color: var(--text-secondary); }
.status-icon {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.status.good .status-icon { background: var(--good-fill); }
.status.critical .status-icon, .status-inline.critical .status-icon { background: var(--critical-fill); }
.status-inline { display: inline-flex; gap: 6px; align-items: center; }
.status-inline .status-icon { width: 18px; height: 18px; font-size: 11px; }

/* Nivel de medición */
.level { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.level-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.level-steps { display: grid; grid-template-columns: repeat(4, minmax(64px, 1fr)); gap: 4px; list-style: none; margin: 0; padding: 0; flex: 1; max-width: 520px; }
.level-steps li { display: grid; gap: 6px; font-size: 12px; color: var(--text-muted); }
.level-bar { height: 6px; border-radius: 3px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.level-steps li.done { color: var(--text-primary); }
.level-steps li.done .level-bar { background: var(--text-primary); box-shadow: none; }
.level-next { margin: 12px 0 0; font-size: 14px; color: var(--text-secondary); }

/* Bloques */
.block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.block-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.block-head h2 { font-size: 19px; }
.block-meta { font-size: 13px; color: var(--text-muted); }
.sub-head { font-size: 15px; margin-bottom: 10px; }
.empty { color: var(--text-secondary); margin: 0; }
.footnote { font-size: 13px; color: var(--text-muted); margin: 0; }
.error { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--critical-fill); padding: 14px 16px; border-radius: 8px; }

/* Indicadores */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tiles-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; }
.tile { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; display: grid; gap: 2px; align-content: start; }
.tile-label { font-size: 13px; color: var(--text-secondary); }
.tile-value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 2px 0; }
.tile-note { font-size: 12px; color: var(--text-muted); }
.delta { font-size: 12px; color: var(--text-muted); }
.delta-num { font-weight: 600; }
.delta.good .delta-num { color: var(--good); }
.delta.bad .delta-num { color: var(--bad); }
.delta.neutral .delta-num { color: var(--text-secondary); }

/* Gráficos */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.chart-card { border: 1px solid var(--border); border-radius: 9px; padding: 14px 14px 10px; min-width: 0; }
.chart-card h3 { font-size: 15px; }
.chart-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.chart-host { position: relative; margin-top: 10px; min-height: 240px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .reference { stroke: var(--text-secondary); stroke-width: 1.5; }
.chart .ref-label { fill: var(--text-secondary); font-size: 12px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; }
.chart .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart .col { transition: opacity .1s; }
.chart:has(.col.hover) .col:not(.hover) { opacity: .55; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; color: var(--text-secondary); }
.legend-item, .plat { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.tip {
  position: absolute; pointer-events: none; z-index: 3;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12); padding: 8px 10px; font-size: 13px; min-width: 150px;
}
.tip-title { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--text-secondary); }
.tip-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.tip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.chart-data summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.chart-data .table-wrap { max-height: 280px; margin-top: 8px; }

/* Tablas */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-secondary); }
tbody th { font-weight: 400; }
.n { text-align: right; font-variant-numeric: tabular-nums; }
tfoot th, tfoot td { font-weight: 600; border-bottom: 0; background: var(--surface-2); }
.campaigns tr.group th, .campaigns tr.group td { font-weight: 600; background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.campaigns tr.camp th { padding-left: 30px; color: var(--text-secondary); }

/* Embudo */
.split { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; }
.funnel { display: grid; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 56px; grid-template-areas: "name track val" ". step step"; column-gap: 10px; align-items: center; }
.funnel-name { grid-area: name; font-size: 14px; }
.funnel-track { grid-area: track; height: 14px; }
.funnel-bar { display: block; height: 100%; background: var(--neutral-bar); border-radius: 0 4px 4px 0; }
.funnel-val { grid-area: val; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.funnel-step { grid-area: step; font-size: 12px; }

/* Pie y notas */
.data-foot { font-size: 13px; color: var(--text-secondary); padding: 0 4px; }
.notes-block { border-style: dashed; }
.note-form { display: grid; gap: 8px; justify-items: start; }
.note-form textarea { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--baseline); background: var(--page); resize: vertical; }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.notes li { border-top: 1px solid var(--grid); padding-top: 10px; }
.notes p { margin: 4px 0 6px; white-space: pre-wrap; }
.note-meta { font-size: 12px; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .who { display: none; }
  .page { padding: 20px 16px 48px; }
  .page-head h1 { font-size: 22px; }
  .hero { padding: 18px; }
  .hero-value { font-size: 44px; }
  .block { padding: 16px; }
  .split { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .level-top { flex-direction: column; align-items: stretch; }
  .level-steps { max-width: none; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .level-steps li { font-size: 11px; }
}
