/* ── Tokens ─────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #706f6a;   /* 4.9:1 sobre la superficie clara */
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --series-1-soft:  #cde2fb;
  --good:           #0ca30c;
  --warning:        #fab219;
  --critical:       #d03b3b;
  --good-ink:       #006300;
  --warn-ink:       #8a5b00;
  --crit-ink:       #a52222;
  --hover:          rgba(11,11,11,0.04);
  --shadow:         0 1px 2px rgba(11,11,11,.06), 0 4px 12px rgba(11,11,11,.04);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;   /* 4.9:1 sobre la superficie oscura */
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1:       #3987e5;
  --series-1-soft:  #184f95;
  --good-ink:       #4fce4f;
  --warn-ink:       #fab219;
  --crit-ink:       #ef7676;
  --hover:          rgba(255,255,255,0.06);
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1400px; margin: 0 auto; padding: 24px 20px 64px; }
.spacer { flex: 1 1 auto; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Encabezado ─────────────────────────────────────────────────────── */
header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
header h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
header .sub { color: var(--text-secondary); font-size: 13px; margin: 2px 0 0; }
.quien {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  color: var(--text-secondary); padding-right: 4px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--series-1); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.rol-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--series-1-soft); color: #1c5cab;
}
:root[data-theme="dark"] .rol-chip { color: #cde2fb; }

/* ── Botones ────────────────────────────────────────────────────────── */
button, .btn {
  font: inherit; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); border-radius: 8px; padding: 7px 13px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 500; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--crit-ink); }
button.danger:hover { background: rgba(208,59,59,.10); border-color: var(--critical); }
button.icon { padding: 5px 8px; font-size: 12px; border-radius: 6px; line-height: 1; }
a { color: var(--series-1); }

/* ── Tarjetas ───────────────────────────────────────────────────────── */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.seccion { font-size: 14px; font-weight: 600; margin: 0 0 14px; }

/* ── KPIs ───────────────────────────────────────────────────────────── */
.kpis { display: grid; gap: 12px; margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 7px; }
.kpi .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.kpi .value { font-size: 34px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; }
.kpi .foot { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { background: var(--hover); }
.kpi.active { outline: 2px solid var(--series-1); outline-offset: -1px; }

/* ── Gráficos ───────────────────────────────────────────────────────── */
.charts { display: grid; gap: 12px; margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.chart-box { padding: 16px 18px 12px; min-width: 0; }
.chart-box h2 { font-size: 13px; font-weight: 600; margin: 0 0 2px; }
.chart-box .cap { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }
.chart-scroll { overflow-x: auto; }
.chart-empty { color: var(--text-muted); font-size: 13px; height: 120px; display: flex; align-items: center; justify-content: center; }

/* ── Formularios ────────────────────────────────────────────────────── */
.form-card { padding: 18px; margin-bottom: 20px; }
.form-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.form-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.badge-edit { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--series-1-soft); color: #1c5cab; font-weight: 600; }
:root[data-theme="dark"] .badge-edit { color: #cde2fb; }
.grid-form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.field input, .field select {
  font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
  width: 100%; min-width: 0;
}
.field .hint { font-size: 11px; color: var(--text-muted); min-height: 14px; }
.field .hint.err { color: var(--crit-ink); }
.field input.bad, .field select.bad { border-color: var(--critical); }
.form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }

/* ── Barra de herramientas ──────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; margin-bottom: 12px; }
.toolbar input[type="search"], .toolbar select {
  font: inherit; font-size: 13px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
}
.toolbar input[type="search"] { min-width: 220px; flex: 1 1 220px; }
.count { font-size: 12px; color: var(--text-muted); }

/* ── Tablas ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-1);
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-secondary);
  padding: 10px 12px; white-space: nowrap; border-bottom: 1px solid var(--baseline);
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text-primary); }
thead th.noSort { cursor: default; }
th .arrow { color: var(--series-1); font-size: 10px; margin-left: 3px; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--gridline); vertical-align: middle; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.name { font-weight: 500; min-width: 150px; }
.placa { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .04em; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.status .ic { font-size: 11px; line-height: 1; }
.status.vigente { color: var(--good-ink); }
.status.porvencer { color: var(--warn-ink); }
.status.vencido { color: var(--crit-ink); }
.dias { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty strong { display: block; color: var(--text-secondary); margin-bottom: 4px; font-size: 14px; }

/* ── Avisos ─────────────────────────────────────────────────────────── */
.aviso {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 10px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface-1); margin-bottom: 16px;
}
.aviso .ic { flex: none; font-size: 13px; line-height: 1.4; }
.aviso.info { border-color: var(--series-1); }
.aviso.info .ic { color: var(--series-1); }
.aviso.error { border-color: var(--critical); color: var(--crit-ink); }
.aviso.exito { border-color: var(--good); color: var(--good-ink); }

#tip {
  position: fixed; pointer-events: none; z-index: 100;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  font-size: 12px; box-shadow: var(--shadow); opacity: 0; transition: opacity .1s; white-space: nowrap;
}
#tip.on { opacity: 1; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(8px);
  background: var(--text-primary); color: var(--page);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 200; max-width: 90vw;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Diálogo modal ──────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface-1); color: var(--text-primary);
  box-shadow: var(--shadow); max-width: 460px; width: calc(100vw - 32px);
}
dialog::backdrop { background: rgba(11,11,11,.45); }
dialog .dlg-body { padding: 20px; }
dialog h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
dialog .dlg-sub { margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); }
dialog .form-actions { margin-top: 16px; }

/* ── Autenticación ──────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-card h1 { font-size: 19px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
.auth-card .sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 22px; }
.auth-card .grid-form { grid-template-columns: 1fr; }
.auth-card button.primary { width: 100%; padding: 10px; margin-top: 6px; }
.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--page); padding: 4px; border-radius: 10px; }
.tabs button {
  flex: 1; border: none; background: transparent; border-radius: 7px; padding: 7px;
  color: var(--text-secondary); font-weight: 500;
}
.tabs button[aria-selected="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.auth-pie { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 18px; }

@media print {
  .form-card, .toolbar, .row-actions, header button, .charts, .aviso { display: none !important; }
}
