:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --accent: #f6821f;          /* naranja Cloudflare, solo marca */
  --series: #2a78d6;          /* serie única de las gráficas */
  --series-soft: #cde2fb;
  --grid: #e7e5df;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --info: #2a78d6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8d86;
    --series: #3987e5;
    --series-soft: #184f95;
    --grid: #2a2a27;
    --info: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8d86; --series: #3987e5;
  --series-soft: #184f95; --grid: #2a2a27; --info: #3987e5; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; min-height: 38px; }
.btn:hover { border-color: var(--text-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--text); color: var(--surface); border-color: var(--text); justify-content: center; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.login-card label { font-size: 13px; color: var(--text-2); margin-top: 8px; }
.login-card input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); }
.error { color: var(--critical); font-size: 13px; min-height: 18px; margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand div { display: grid; line-height: 1.2; }
.brand .muted { font-weight: 400; font-size: 12.5px; }
.brand-mark { width: 34px; height: 34px; padding: 7px; border-radius: 10px; background: #111; color: var(--accent); }

/* Estructura */
#app { max-width: 1180px; margin: 0 auto; padding: 16px 16px 48px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 4px; margin: 18px 0 16px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 14px; padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
.tab { display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.g-hero { grid-template-columns: 1.4fr 1fr 1fr; }
.g-tiles { grid-template-columns: repeat(2, 1fr); }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-services { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
@media (max-width: 860px) { .g-hero, .g-2 { grid-template-columns: 1fr; } }

/* Héroe y tiles */
.hero-label { color: var(--text-2); font-size: 13px; }
.hero-num { font-size: 44px; font-weight: 650; letter-spacing: -.03em; line-height: 1.05; margin: 6px 0 10px; }
.tile-num { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.tile .muted { font-size: 12.5px; }
.period { font-size: 13px; color: var(--text-2); }

/* Estado */
.chip { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px 3px 7px; border-radius: 999px; border: 1px solid currentColor; }
.chip svg { width: 15px; height: 15px; }
.lv-critica { color: var(--critical); }
.lv-alta { color: var(--serious); }
.lv-media { color: #b98000; }
.lv-info { color: var(--info); }
.lv-ok { color: var(--good); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lv-media { color: var(--warning); } }
:root[data-theme="dark"] .lv-media { color: var(--warning); }

/* Medidor */
.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter > span { position: absolute; inset: 0 auto 0 0; background: var(--series); border-radius: 99px; }
.meter.warn > span { background: var(--warning); }
.meter.over > span { background: var(--critical); }
.meter-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-2); margin-top: 6px; gap: 8px; }
.budget-line { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }

/* Alertas */
.alerts { display: grid; gap: 8px; }
.alert { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: start; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.alert svg { width: 20px; height: 20px; margin-top: 1px; }
.alert .t { font-weight: 600; font-size: 14px; }
.alert .d { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.alert .lvl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.alert.reviewed { opacity: .55; }
.empty { display: flex; gap: 10px; align-items: center; color: var(--text-2); font-size: 14px; padding: 6px 0; }
.empty svg { color: var(--good); }

/* Servicios */
.svc { display: grid; gap: 8px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.svc:hover { border-color: var(--text-2); }
.svc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.svc-name { font-weight: 600; }
.svc-cost { font-size: 13px; color: var(--text-2); }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.r, th.r { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--surface-2); }
.svc-tag { font-size: 12px; color: var(--muted); display: block; }
td .meter { width: 90px; display: inline-block; vertical-align: middle; }

/* Gráfica */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--series); }
.chart .bar.hl { fill: var(--text); }
.chart .zero { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .limit { stroke: var(--critical); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .limit-label { fill: var(--critical); font-size: 11px; }
.tooltip { position: fixed; z-index: 30; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.tooltip b { display: block; font-size: 13px; }

/* Listas */
.list { display: grid; }
.list-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }
.list-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.badge { font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 0 6px; margin-left: 6px; }

/* Auditorías */
.audit { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.audit > button { width: 100%; display: grid; grid-template-columns: 1fr auto auto 18px; gap: 14px; align-items: center; padding: 14px 16px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.audit > button svg.chev { transition: transform .15s; color: var(--muted); }
.audit.open > button svg.chev { transform: rotate(90deg); }
.audit-body { padding: 0 16px 16px; display: grid; gap: 14px; }
.audit-date { font-weight: 600; }

.note { font-size: 13px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.note strong { color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-word; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 40; max-width: calc(100% - 32px); }
.credit { text-align: right; margin-top: 28px; font-size: 10.5px; color: var(--muted); opacity: .8; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 560px) {
  .hero-num { font-size: 36px; }
  .top-actions .btn span { display: none; }
  #updated { display: none; }
  .audit > button { grid-template-columns: 1fr auto 18px; }
  .audit > button .hide-sm { display: none; }
}

.mt { margin-top: 16px; }
.meter-wrap { margin-top: 16px; }
