:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-text: #006300;
  --good-wash: #e7f6e7;
  --warning: #fab219;
  --warning-wash: #fff4dc;
  --critical: #d03b3b;
  --critical-wash: #fbeaea;
  --neutral-mark: #c3c2b7;
  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #5598e7;
  --seq-4: #256abf;
  --seq-5: #104281;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --good-text: #0ca30c;
    --good-wash: #12301a;
    --warning-wash: #3a2c0c;
    --critical-wash: #3a1616;
    --neutral-mark: #4a4a46;
    --seq-0: #262624;
    --seq-1: #104281;
    --seq-2: #1c5cab;
    --seq-3: #2a78d6;
    --seq-4: #5598e7;
    --seq-5: #9ec5f4;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good-text: #0ca30c;
  --good-wash: #12301a;
  --warning-wash: #3a2c0c;
  --critical-wash: #3a1616;
  --neutral-mark: #4a4a46;
  --seq-0: #262624;
  --seq-1: #104281;
  --seq-2: #1c5cab;
  --seq-3: #2a78d6;
  --seq-4: #5598e7;
  --seq-5: #9ec5f4;
  --shadow: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); }

button, input, select {
  font: inherit;
  color: inherit;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ---------- barra superior ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; flex: none;
}

.brand h1 { font-size: 18px; margin: 0; line-height: 1.2; }
.brand p { margin: 0; color: var(--text-2); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- pastillas de estado ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral-mark); }
.pill.good .dot { background: var(--good); }
.pill.warning .dot { background: var(--warning); }
.pill.critical .dot { background: var(--critical); }
.pill.live .dot { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: none;
  min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.good { background: var(--good); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }

/* ---------- tarjetas ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.card h2 {
  font-size: 15px; margin: 0 0 2px;
}
.card .sub { color: var(--text-2); font-size: 13px; margin: 0 0 14px; }

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.card-head .sub { margin: 0; }

.grid { display: grid; gap: 16px; margin-top: 16px; }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

@media (max-width: 900px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.halves { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- estado principal ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 22px;
  border-left: 6px solid var(--neutral-mark);
}
.hero.good { border-left-color: var(--good); background: linear-gradient(90deg, var(--good-wash), var(--surface) 60%); }
.hero.critical { border-left-color: var(--critical); background: linear-gradient(90deg, var(--critical-wash), var(--surface) 60%); }
.hero.warning { border-left-color: var(--warning); background: linear-gradient(90deg, var(--warning-wash), var(--surface) 60%); }

.hero-eyebrow { font-size: 13px; color: var(--text-2); font-weight: 600; margin-bottom: 4px; }
.hero-title { font-size: 30px; font-weight: 750; line-height: 1.15; margin: 0; }
.hero-meta { color: var(--text-2); margin-top: 8px; display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 14px; }
.hero-meta b { color: var(--text); font-weight: 600; }
.hero-tramites { margin: 12px 0 0; padding-left: 18px; }
.hero-actions { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }

@media (max-width: 700px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-title { font-size: 24px; }
  .hero-actions { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  .hero-actions .btn { flex: 1 1 140px; }
}

/* ---------- KPIs ---------- */

.kpi .label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.15; }
.kpi .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ---------- línea de tiempo ---------- */

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--neutral-mark); display: inline-block; }
.swatch.good { background: var(--good); }
.swatch.warning { background: var(--warning); }
.swatch.critical { background: var(--critical); }

.timeline {
  position: relative;
  height: 44px;
  border-bottom: 1px solid var(--axis);
  margin-top: 6px;
}
.timeline .tick {
  position: absolute; bottom: 0; width: 3px; height: 18px;
  border-radius: 2px 2px 0 0;
  background: var(--neutral-mark);
  transform: translateX(-1px);
}
.timeline .tick.available { background: var(--good); height: 40px; }
.timeline .tick.error { background: var(--critical); height: 30px; }
.timeline .tick.unknown { background: var(--warning); height: 34px; }
.timeline .hit {
  position: absolute; top: 0; bottom: 0; width: 10px; transform: translateX(-5px);
  cursor: crosshair;
}
.axis-labels { position: relative; height: 18px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.axis-labels span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

/* ---------- mapa de calor ---------- */

.heat-scroll { overflow-x: auto; }
.heatmap {
  display: grid;
  grid-template-columns: 30px repeat(24, minmax(8px, 1fr));
  gap: 2px;
  min-width: 260px;
  font-size: 11px;
  color: var(--muted);
}
@media (max-width: 520px) {
  .heatmap { font-size: 10px; gap: 1px; }
  .heatmap .cell { border-radius: 2px; }
}
.heatmap .rowlabel { display: flex; align-items: center; font-size: 12px; color: var(--text-2); }
.heatmap .collabel { text-align: center; font-variant-numeric: tabular-nums; }
.heatmap .cell {
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  background: var(--seq-0);
  min-width: 0;
}
.heatmap .cell.empty { background: transparent; outline: 1px dashed var(--grid); outline-offset: -1px; }
.heatmap .cell.l1 { background: var(--seq-1); }
.heatmap .cell.l2 { background: var(--seq-2); }
.heatmap .cell.l3 { background: var(--seq-3); }
.heatmap .cell.l4 { background: var(--seq-4); }
.heatmap .cell.l5 { background: var(--seq-5); }
.heat-legend { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.heat-legend .cell { width: 14px; height: 14px; border-radius: 3px; display: inline-block; background: var(--seq-0); }
.heat-legend .cell.l1 { background: var(--seq-1); }
.heat-legend .cell.l3 { background: var(--seq-3); }
.heat-legend .cell.l5 { background: var(--seq-5); }
.heat-legend .cell.empty { background: transparent; outline: 1px dashed var(--grid); outline-offset: -1px; }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--text); color: var(--page);
  padding: 6px 10px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  max-width: 280px; display: none;
}
.tooltip b { font-weight: 650; }

/* ---------- listas ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--grid); display: flex; gap: 10px; align-items: flex-start; }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .body { min-width: 0; flex: 1; }
.list .msg { white-space: pre-wrap; word-break: break-word; font-size: 13px; color: var(--text-2); margin-top: 2px; }
.empty-note { color: var(--muted); font-size: 14px; padding: 8px 0; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.good { color: var(--good-text); background: var(--good-wash); }
.badge.critical { color: var(--critical); background: var(--critical-wash); }
.badge.warning { color: var(--text); background: var(--warning-wash); }

/* ---------- tabla ---------- */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.time { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.detail { color: var(--text-2); word-break: break-word; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text-2); }
.segmented button.on { background: var(--surface-2); color: var(--text); }

/* ---------- captura ---------- */

.shot {
  display: block; width: 100%; max-height: 420px; object-fit: cover; object-position: top;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
}

/* ---------- formulario ---------- */

.form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
@media (max-width: 900px) { .form { grid-template-columns: minmax(0, 1fr); } }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field input[type="number"], .field input[type="text"], .field input[type="password"], .field select {
  width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--axis);
  background: var(--surface);
  min-height: 38px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check label { margin: 0; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.form-msg { font-size: 13px; color: var(--text-2); }
.form-msg.err { color: var(--critical); }

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- modal ---------- */

.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 40; overflow-y: auto;
}
.modal-back.open { display: flex; }
.modal { width: min(860px, 100%); }
.modal pre {
  background: var(--surface-2); border-radius: 10px; padding: 12px; overflow: auto;
  font-size: 12px; max-height: 320px; white-space: pre-wrap; word-break: break-word;
}

/* ---------- aviso flotante ---------- */

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--page);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60;
  display: none; max-width: calc(100% - 32px);
}
.toast.show { display: block; }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); }
.login-card h1 { font-size: 20px; margin: 12px 0 4px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mt { margin-top: 16px; }
