:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6f6e69;
  --line: #e1e0d9;
  --line-2: #c3c2b7;
  --accent: #256abf;
  --accent-ink: #1c5cab;
  --accent-wash: #cde2fb;
  --bar: #2a78d6;
  --critical: #b52f2f;
  --critical-wash: #fbe9e7;
  --warning: #8a5f00;
  --warning-wash: #fdf3d9;
  --good: #006300;
  --good-wash: #e3f3e3;
  --info: #1c5cab;
  --info-wash: #e4eefb;
  --shadow: 0 8px 30px rgba(0, 0, 0, .16);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #a3a29a;
    --line: #2c2c2a;
    --line-2: #383835;
    --accent: #5598e7;
    --accent-ink: #86b6ef;
    --accent-wash: #184f95;
    --bar: #3987e5;
    --critical: #f08a8a;
    --critical-wash: #3a1d1d;
    --warning: #fab219;
    --warning-wash: #36290c;
    --good: #5cc75c;
    --good-wash: #16301a;
    --info: #86b6ef;
    --info-wash: #16283f;
    --shadow: 0 8px 30px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 14px; margin: 0 0 12px; font-weight: 650; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Estructura */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100%; }
.side {
  background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px;
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; padding: 4px 8px 14px; }
.brand img { width: 22px; height: 22px; }
.nav a {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px;
  color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-wash); color: var(--ink); }
.nav-sep { height: 1px; background: var(--line); margin: 8px 6px; }
.side-foot { margin-top: auto; padding: 10px 8px 2px; border-top: 1px solid var(--line); font-size: 12.5px; }
.side-foot .who { font-weight: 600; overflow-wrap: anywhere; }
.main { padding: 22px 26px 60px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head .sub { color: var(--ink-2); margin-top: 2px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }

/* Controles */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 6px 12px; border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; display: inline-block;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b0b0b; } }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn.link { border: 0; background: none; color: var(--accent-ink); padding: 2px 4px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 6px; padding: 6px 9px; min-width: 0; max-width: 100%;
}
textarea { width: 100%; min-height: 80px; resize: vertical; }
input[type=search] { width: 280px; }
label.field { display: block; font-weight: 500; font-size: 13px; }
label.field > input, label.field > select, label.field > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
label.field .hint { display: block; color: var(--ink-2); font-weight: 400; font-size: 12px; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

/* Tarjetas y mosaicos */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.card.flush { padding: 0; overflow: hidden; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; color: inherit; display: block; }
a.tile:hover { border-color: var(--line-2); text-decoration: none; background: var(--surface-2); }
.tile .value { font-size: 26px; font-weight: 650; line-height: 1.15; }
.tile .label { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

/* Barras */
.bars { display: grid; gap: 3px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr) 34px; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 5px; color: inherit; }
a.bar-row:hover { background: var(--surface-2); text-decoration: none; }
.bar-label { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.bar-track { height: 10px; position: relative; border-left: 1px solid var(--line-2); }
.bar-fill { display: block; height: 100%; min-width: 2px; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }

/* Medidor */
.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; min-width: 90px; }
.meter > span { display: block; height: 100%; background: var(--bar); border-radius: 4px; }
.meter.over > span { background: var(--critical); }

/* Etiquetas de estado */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.chip.critical { background: var(--critical-wash); color: var(--critical); }
.chip.warning { background: var(--warning-wash); color: var(--warning); }
.chip.good { background: var(--good-wash); color: var(--good); }
.chip.info { background: var(--info-wash); color: var(--info); }
.badge { background: var(--critical); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11.5px; font-weight: 650; }
@media (prefers-color-scheme: dark) { .badge { color: #0b0b0b; } }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; background: var(--surface); }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th a { color: inherit; }
.sorted::after { content: " ▲"; font-size: 9px; }
.sorted.desc::after { content: " ▼"; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-2); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); gap: 8px; flex-wrap: wrap; }

/* Detalle */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.on { color: var(--ink); border-color: var(--accent); }
dl.facts { display: grid; grid-template-columns: minmax(110px, 38%) minmax(0, 1fr); gap: 6px 12px; margin: 0; }
dl.facts dt { color: var(--ink-2); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border: 0; }
.timeline details { margin-top: 4px; color: var(--ink-2); font-size: 12.5px; }
.timeline details ul { margin: 4px 0 0; padding-left: 18px; }
.alert-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.alert-row:last-child { border: 0; }
.alert-row .what { min-width: 0; }
.alert-row .title { font-weight: 550; overflow-wrap: anywhere; }
.notice { padding: 10px 14px; border-radius: 6px; background: var(--warning-wash); color: var(--warning); font-size: 13px; }
.notice.error { background: var(--critical-wash); color: var(--critical); }
.notice.info { background: var(--info-wash); color: var(--info); }
.code-block { position: relative; background: var(--surface-2); border-radius: 6px; padding: 10px 76px 10px 12px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.code-block .btn { position: absolute; top: 6px; right: 6px; padding: 2px 9px; font-family: system-ui, sans-serif; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--bar); }

/* Diálogos */
dialog { border: 1px solid var(--line-2); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg-head { padding: 14px 18px 0; font-size: 16px; font-weight: 650; }
.dlg-body { padding: 14px 18px; }
.dlg-foot { padding: 0 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* Ingreso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(370px, 100%); display: grid; gap: 12px; }
.login .brand { padding: 0 0 4px; font-size: 18px; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 50; background: var(--ink); color: var(--page); padding: 9px 14px; border-radius: 7px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.error { background: var(--critical); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); align-items: center; padding: 8px 12px; }
  .brand { padding: 0 10px 0 0; width: 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-sep { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 16px; }
  .grid2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  input[type=search] { width: 100%; }
}

/* Utilidades */
.pad-h2 { padding: 14px 16px 2px; }
.pad { padding: 10px 12px 10px 16px; }
.flat { margin: 0; }
.nudge { margin-top: 10px; }
.grow { flex: 1; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
#filters { margin-bottom: 12px; }
.chip .btn.link { padding: 0 2px; color: inherit; font-size: 11px; }
[hidden] { display: none !important; }
