/* Sistema de diseño de STALD (openspec: ingles-pro).
   Tokens, modo claro/oscuro y componentes de bajo nivel. Sin frameworks ni build: se enlaza con <link>.
   Modo oscuro: sigue al sistema (prefers-color-scheme) salvo que <html data-theme="light|dark"> lo fije. */

:root {
  color-scheme: light;
  /* Color */
  --bg: #f6f6fb;
  --card: #ffffff;
  --card-2: #f7f7fc;
  --text: #1b1a2e;
  --muted: #5d5b70;
  --border: #e3e2ee;
  --accent: #4f46e5;        /* texto y bordes de acento (índigo de Inglés) */
  --accent-bg: #4f46e5;     /* relleno de botones: texto blanco con contraste AA en ambos modos */
  --accent-2: #7c3aed;
  --accent-soft: #eef2ff;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #c81e1e;
  --bad-soft: #fee2e2;
  --focus: #7c3aed;
  /* Forma */
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 24px;
  --shadow-1: 0 1px 2px rgba(27, 26, 46, .06);
  --shadow-2: 0 1px 2px rgba(27, 26, 46, .06), 0 10px 28px rgba(27, 26, 46, .08);
  /* Espacio: escala de 4 px */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  /* Tipografía */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12111c; --card: #1d1b2c; --card-2: #24223a; --text: #f3f2fa; --muted: #aeabc4; --border: #34314d;
    --accent: #a5b4fc; --accent-bg: #4f46e5; --accent-2: #c4b5fd; --accent-soft: #272552;
    --ok: #4ade80; --ok-soft: #12351f; --warn: #fbbf24; --warn-soft: #3a2a08; --bad: #f87171; --bad-soft: #3b1414; --focus: #c4b5fd;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12111c; --card: #1d1b2c; --card-2: #24223a; --text: #f3f2fa; --muted: #aeabc4; --border: #34314d;
  --accent: #a5b4fc; --accent-bg: #4f46e5; --accent-2: #c4b5fd; --accent-soft: #272552;
  --ok: #4ade80; --ok-soft: #12351f; --warn: #fbbf24; --warn-soft: #3a2a08; --bad: #f87171; --bad-soft: #3b1414; --focus: #c4b5fd;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.45;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
[hidden] { display: none !important; }
.num, .tabular { font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.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; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 2000; background: var(--card); color: var(--text); padding: 8px 12px; border-radius: 10px; }
.skip:focus { left: 8px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Tarjeta ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-1); padding: var(--s4); }
.card + .card { margin-top: var(--s3); }
.card-titulo { margin: 0 0 var(--s2); font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  font: inherit; font-weight: 700; font-size: .88rem; padding: 10px 16px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: var(--accent-bg); color: var(--on-accent); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.btn:hover { box-shadow: 0 6px 16px rgba(79, 70, 229, .25); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--card); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { box-shadow: none; border-color: var(--accent); }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: .8rem; }
.btn.icono { min-width: 44px; padding: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; border-radius: 999px; padding: 3px 10px; background: var(--accent-soft); color: var(--accent); max-width: 100%; overflow-wrap: anywhere; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.gris { background: var(--card-2); color: var(--muted); border: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 4px; overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1 0 auto; font: inherit; font-weight: 700; font-size: .86rem; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: none; background: none; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"], .tab[aria-current="page"] { background: var(--accent-bg); color: var(--on-accent); }

/* ---------- Anillo de progreso (SVG) ---------- */
.anillo { position: relative; width: 84px; height: 84px; flex-shrink: 0; }
.anillo svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.anillo .pista { stroke: var(--border); }
.anillo .valor { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.anillo .centro { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-weight: 800; font-size: 1.05rem; line-height: 1.05; font-variant-numeric: tabular-nums; }
.anillo .centro small { display: block; font-size: .62rem; font-weight: 700; color: var(--muted); }

/* ---------- Barra ---------- */
.barra { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.barra > span { display: block; height: 100%; border-radius: 999px; background: var(--ok); transition: width .4s ease; }
.barra.warn > span { background: var(--warn); }
.barra.bad > span { background: var(--bad); }
.barra.accent > span { background: linear-gradient(90deg, var(--accent-bg), var(--accent-2)); }

/* ---------- Tabla ---------- */
.tabla-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--card); }
.tabla { width: 100%; border-collapse: collapse; font-size: .84rem; }
.tabla th, .tabla td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tabla thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--card-2); position: sticky; top: 0; }

/* ---------- Indicadores (KPI) ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s3); box-shadow: var(--shadow-1); }
.kpi b { display: block; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kpi.ok b { color: var(--ok); } .kpi.warn b { color: var(--warn); } .kpi.bad b { color: var(--bad); }

/* ---------- Cajón lateral (<dialog>) ---------- */
dialog.cajon {
  margin: 0 0 0 auto; height: 100%; max-height: 100dvh; width: min(440px, 100vw); max-width: 100vw; padding: 0; border: none;
  background: var(--bg); color: var(--text); box-shadow: var(--shadow-2); border-radius: var(--r-lg) 0 0 var(--r-lg);
}
dialog.cajon[open] { animation: entraCajon .22s ease; }
dialog.cajon::backdrop { background: rgba(10, 9, 20, .45); }
@keyframes entraCajon { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.cajon-cab { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: var(--s3); padding: var(--s4); background: var(--card); border-bottom: 1px solid var(--border); }
.cajon-cuerpo { padding: var(--s4); display: grid; gap: var(--s3); }

/* ---------- Esqueleto de carga y estado vacío ---------- */
.esqueleto { display: grid; gap: var(--s3); }
.esqueleto i { display: block; height: 72px; border-radius: var(--r-md); background: linear-gradient(90deg, var(--card) 25%, var(--card-2) 50%, var(--card) 75%); background-size: 200% 100%; animation: brillo 1.2s infinite linear; border: 1px solid var(--border); }
.esqueleto i:first-child { height: 120px; }
@keyframes brillo { to { background-position: -200% 0; } }
.vacio { text-align: center; color: var(--muted); padding: var(--s6) var(--s4); font-size: .9rem; }
.vacio .grande { font-size: 2rem; display: block; margin-bottom: 4px; }

/* ---------- Navegación con emojis ---------- */
.nav-item {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border-radius: var(--r-sm);
  font: inherit; font-weight: 700; font-size: .9rem; color: var(--muted); text-decoration: none; background: none; border: none; cursor: pointer; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--card-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-emoji { font-size: 1.2rem; line-height: 1; width: 1.5em; text-align: center; }

/* Barra inferior fija en celular */
@media (max-width: 719.98px) {
  .nav-barra {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; display: flex; justify-content: space-around;
    background: var(--card); border-top: 1px solid var(--border); box-shadow: 0 -6px 18px rgba(0, 0, 0, .06);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
  }
  .nav-barra .nav-item { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; min-height: 56px; padding: 6px 2px; font-size: .68rem; justify-content: center; text-align: center; border-radius: 14px; }
  .nav-barra .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .nav-barra .solo-escritorio { display: none; }
  .btn.sm { min-height: 44px; } /* en pantallas táctiles todo botón mide al menos 44 px */
  .con-barra { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom, 0px)); }
}
@media (min-width: 720px) {
  .nav-barra .solo-celular { display: none; }
}
@media (pointer: coarse) { .btn.sm { min-height: 44px; } } /* tablets: también 44 px (openspec: navegacion-dispositivos) */
