/* ==========================================================================
   Chequea · sistema de diseño del panel
   Tokens -> base -> layout -> componentes -> páginas.
   Tema oscuro por defecto; claro con prefers-color-scheme o con el interruptor
   (atributo data-theme en <html>, guardado por tema.js).
   Componentes reutilizables: .card .btn(.btn-primary/.btn-secondary/.btn-danger/.btn-ghost)
   .badge(.badge-ok/warn/bad/info/brand/neutral) .kpi .info-btn/.popover .table .banner
   .toast .modal .field/.input .switch .chip .empty .timeline .avatar
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: dark;
  /* espaciado (4/8/12/16/24/32/48) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px; --s12: 48px;
  /* radios */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-pill: 999px;
  /* tipografía */
  --f-body: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --t-xs: 12.5px; --t-sm: 13.5px; --t-base: 15px; --t-md: 16px; --t-lg: 18px; --t-xl: 22px; --t-2xl: 28px; --t-3xl: 34px; --t-kpi: 40px;
  /* superficies (oscuro) */
  --bg: #0A0E1F;
  --surface: #121832;
  --surface-2: #1A2145;
  --surface-3: #232B58;
  --line: #28315E;
  --line-strong: #3A4580;
  --ink: #EEF0FF;
  --ink-2: #C9CDEB;
  --muted: #A3AAD2;
  --faint: #7F87B5;
  --side-bg: #0D1229;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --shadow-lg: 0 24px 64px rgba(0,0,0,.55);
  /* marca y semánticos */
  --brand: #FF6B4A; --brand-hover: #FF7F61; --brand-ink: #1B0A05; --brand-soft: rgba(255,107,74,.15); --brand-text: #FF8A6E;
  --ok: #43D49A; --ok-soft: rgba(67,212,154,.14);
  --warn: #FFB547; --warn-soft: rgba(255,181,71,.14);
  --bad: #FF7A7A; --bad-soft: rgba(255,122,122,.15);
  --info: #9DB0FF; --info-soft: rgba(124,150,255,.17);
  --neutral: #A3AAD2; --neutral-soft: rgba(163,170,210,.14);
  --danger-bg: #D63A3E; --danger-ink: #fff;
  --focus: #8FA8FF;
  --glow: rgba(255,107,74,.16);
  /* chat */
  --chat-bg: #0E171C; --bubble-in: #1F2C34; --bubble-out: #0B5C47; --chat-ink: #E9EDEF; --chat-muted: #8EA0A9;
  /* gráfico */
  --c-rec: rgba(124,150,255,.4);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { /* claro por preferencia del sistema */
    color-scheme: light;
    --bg: #F3F4FA; --surface: #FFFFFF; --surface-2: #F6F7FC; --surface-3: #ECEEF8;
    --line: #E2E5F1; --line-strong: #C9CEE4; --ink: #131A3A; --ink-2: #333B63; --muted: #565D80; --faint: #7A81A3;
    --side-bg: #FFFFFF;
    --shadow: 0 1px 2px rgba(19,26,58,.06), 0 8px 24px rgba(19,26,58,.07);
    --shadow-lg: 0 24px 64px rgba(19,26,58,.22);
    --brand: #DB3F1B; --brand-hover: #C73512; --brand-ink: #FFFFFF; --brand-soft: #FFE9E2; --brand-text: #B8330F;
    --ok: #0A7A56; --ok-soft: #DDF5EA; --warn: #8F5500; --warn-soft: #FFF0D2; --bad: #C22E2E; --bad-soft: #FDE3E3;
    --info: #2F49D6; --info-soft: #E5EAFF; --neutral: #565D80; --neutral-soft: #E9EBF5;
    --danger-bg: #C9302F; --focus: #3450E6; --glow: rgba(255,90,54,.12);
    --chat-bg: #EAE4DA; --bubble-in: #FFFFFF; --bubble-out: #D7F5C4; --chat-ink: #111B21; --chat-muted: #667781;
    --c-rec: rgba(47,73,214,.28);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F3F4FA; --surface: #FFFFFF; --surface-2: #F6F7FC; --surface-3: #ECEEF8;
  --line: #E2E5F1; --line-strong: #C9CEE4; --ink: #131A3A; --ink-2: #333B63; --muted: #565D80; --faint: #7A81A3;
  --side-bg: #FFFFFF;
  --shadow: 0 1px 2px rgba(19,26,58,.06), 0 8px 24px rgba(19,26,58,.07);
  --shadow-lg: 0 24px 64px rgba(19,26,58,.22);
  --brand: #DB3F1B; --brand-hover: #C73512; --brand-ink: #FFFFFF; --brand-soft: #FFE9E2; --brand-text: #B8330F;
  --ok: #0A7A56; --ok-soft: #DDF5EA; --warn: #8F5500; --warn-soft: #FFF0D2; --bad: #C22E2E; --bad-soft: #FDE3E3;
  --info: #2F49D6; --info-soft: #E5EAFF; --neutral: #565D80; --neutral-soft: #E9EBF5;
  --danger-bg: #C9302F; --focus: #3450E6; --glow: rgba(255,90,54,.12);
  --chat-bg: #EAE4DA; --bubble-in: #FFFFFF; --bubble-out: #D7F5C4; --chat-ink: #111B21; --chat-muted: #667781;
  --c-rec: rgba(47,73,214,.28);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: var(--t-base); line-height: 1.55; -webkit-font-smoothing: antialiased; }
body.sin-scroll { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: var(--t-3xl); font-weight: 800; }
h2 { font-size: var(--t-lg); }
h3 { font-size: var(--t-md); }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
small { font-size: var(--t-sm); }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--brand); color: var(--brand-ink); padding: 10px 16px; border-radius: var(--r-sm); font-weight: 700; text-decoration: none; }
.skip:focus { top: 12px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- 3. Layout de aplicación ---------- */
.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.page { width: 100%; max-width: 1360px; margin: 0 auto; padding: var(--s8) 40px var(--s12); display: flex; flex-direction: column; gap: var(--s8); min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4) var(--s6); }
.page-head h1 { margin: 0; }
.page-sub { color: var(--muted); font-size: var(--t-md); margin-top: var(--s2); max-width: 70ch; }
.page-sub .info { vertical-align: middle; margin-left: var(--s1); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.back { display: inline-flex; align-items: center; gap: var(--s2); color: var(--muted); text-decoration: none; font-weight: 600; font-size: var(--t-sm); min-height: 36px; }
.back:hover { color: var(--ink); }
.stack { display: flex; flex-direction: column; gap: var(--s6); }

/* barra lateral */
.side { position: sticky; top: 0; height: 100vh; background: var(--side-bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 40; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: var(--s6) var(--s6) var(--s4); }
.side-top-actions { display: flex; gap: var(--s2); }
.side-menu { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: var(--s2) var(--s4) var(--s4); gap: var(--s4); }
.side-nav { display: flex; flex-direction: column; gap: var(--s1); }
.nav-item { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s4); min-height: 46px; border-radius: var(--r-md); color: var(--muted); text-decoration: none; font-weight: 600; font-size: var(--t-base); transition: background .15s, color .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }
.nav-text { flex: 1; min-width: 0; }
.nav-badge { min-width: 24px; height: 24px; padding: 0 7px; border-radius: var(--r-pill); background: var(--brand); color: var(--brand-ink); font-size: 12.5px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.side-user { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); min-width: 0; }
.side-user-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.side-user-txt b { font-size: var(--t-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-txt small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot-actions { display: flex; gap: var(--s2); }
.side-foot-actions .btn-block { flex: 1; }
.btn.side-toggle, .btn.mobile-only { display: none; }

/* marca */
.brand { display: inline-flex; align-items: center; gap: var(--s3); text-decoration: none; color: var(--ink); }
.brand .logo { width: 38px; height: 38px; flex: none; }
.brand strong { font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.brand strong span { color: var(--brand); }

/* ---------- 4. Componentes ---------- */
/* Tarjeta */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.card-pad { padding: var(--s6); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); }
.card-head h2 { font-size: var(--t-xl); }
.card-sub { color: var(--muted); font-size: var(--t-sm); margin-top: var(--s1); }
.card-section-title { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: var(--s4); }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s6); border-radius: var(--r-md); border: 1px solid transparent; font-size: var(--t-base); font-weight: 650; line-height: 1; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not([disabled]) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not([disabled]) { background: var(--surface-3); }
.btn-danger { background: var(--danger-bg); color: var(--danger-ink); }
.btn-danger:hover:not([disabled]) { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not([disabled]) { background: var(--surface-2); color: var(--ink); }
.btn-sm { min-height: 36px; padding: 0 var(--s4); font-size: var(--t-sm); }
.btn-icon { width: 44px; padding: 0; }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: var(--t-md); }

/* Insignias de estado */
.badge { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 700; line-height: 1.2; white-space: nowrap; background: var(--neutral-soft); color: var(--neutral); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }

/* Colores semánticos para íconos/KPI (--tone, --tone-soft) */
.t-ok { --tone: var(--ok); --tone-soft: var(--ok-soft); }
.t-bad { --tone: var(--bad); --tone-soft: var(--bad-soft); }
.t-warn, .t-sun { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.t-info { --tone: var(--info); --tone-soft: var(--info-soft); }
.t-brand { --tone: var(--brand-text); --tone-soft: var(--brand-soft); }
.t-neutral { --tone: var(--neutral); --tone-soft: var(--neutral-soft); }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s6); }
.kpi-grid.kpi-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--s6); display: flex; flex-direction: column; gap: var(--s3); min-height: 168px; text-decoration: none; color: inherit; }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.kpi-label { display: flex; align-items: center; gap: var(--s1); color: var(--muted); font-size: var(--t-sm); font-weight: 650; min-width: 0; }
.kpi-ico { width: 44px; height: 44px; border-radius: var(--r-md); background: var(--tone-soft); color: var(--tone); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.kpi-ico .ico { width: 22px; height: 22px; }
.kpi-val { font-size: var(--t-kpi); font-weight: 800; line-height: 1.05; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: auto; }
.kpi-sub { color: var(--muted); font-size: var(--t-sm); }
.kpi-link { transition: border-color .15s, transform .15s; }
.kpi-link:hover { border-color: var(--tone); transform: translateY(-2px); }
.kpi-wide { grid-column: span 2; }
.kpi::before { content: ""; position: absolute; left: var(--s6); right: var(--s6); top: 0; height: 3px; border-radius: 0 0 4px 4px; background: var(--tone, transparent); opacity: .85; }

/* Botón ⓘ + popover */
.info { position: relative; display: inline-flex; }
.info-btn { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--faint); display: inline-flex; align-items: center; justify-content: center; }
.info-btn .ico { width: 17px; height: 17px; }
.info-btn:hover, .info-btn[aria-expanded="true"] { color: var(--ink); background: var(--surface-3); }
.popover { position: absolute; top: calc(100% + 8px); left: 0; z-index: 30; width: min(360px, calc(100vw - 32px)); background: var(--surface-3); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: var(--s4) var(--s4) var(--s4); font-size: var(--t-sm); font-weight: 400; line-height: 1.5; letter-spacing: 0; text-align: left; }
.popover-title { font-weight: 700; margin-bottom: var(--s2); font-size: var(--t-base); }
.popover dl { margin: 0; display: grid; gap: var(--s1); }
.popover dt { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-top: var(--s3); }
.popover dt:first-child { margin-top: 0; }
.popover dd { margin: 0; color: var(--ink-2); }
.popover ul { margin: 0; padding-left: 18px; display: grid; gap: var(--s1); }
.popover-scroll { max-height: min(60vh, 420px); overflow: auto; }

/* Banner */
.banner { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-md); border: 1px solid transparent; font-size: var(--t-sm); line-height: 1.5; background: var(--info-soft); color: var(--info); }
.banner .ico { margin-top: 1px; width: 18px; height: 18px; }
.banner-txt { color: var(--ink-2); flex: 1; min-width: 0; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-bad { background: var(--bad-soft); color: var(--bad); }
.banner-ok { background: var(--ok-soft); color: var(--ok); }

/* Toast */
.toasts { position: fixed; right: var(--s6); bottom: var(--s6); z-index: 90; display: flex; flex-direction: column; gap: var(--s3); max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: var(--s3); background: var(--surface-3); border: 1px solid var(--line-strong); border-left: 4px solid var(--info); border-radius: var(--r-md); padding: var(--s3) var(--s4); box-shadow: var(--shadow-lg); font-size: var(--t-sm); animation: entra .2s ease-out; }
.toast-ok { border-left-color: var(--ok); } .toast-bad { border-left-color: var(--bad); }
.toast.saliendo { opacity: 0; transition: opacity .25s; }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } }

/* Modal de confirmación */
.modal-back { position: fixed; inset: 0; z-index: 80; background: rgba(5,8,20,.62); display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.modal { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: var(--s8); width: min(480px, 100%); display: flex; flex-direction: column; gap: var(--s4); }
.modal h2 { font-size: var(--t-xl); }
.modal-txt { color: var(--muted); }
.modal-acciones { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s4); }

/* Formularios */
.field { display: flex; flex-direction: column; gap: var(--s2); }
.label { font-size: var(--t-sm); font-weight: 650; color: var(--ink-2); }
.help { font-size: var(--t-xs); color: var(--muted); }
.field-error { font-size: var(--t-xs); color: var(--bad); font-weight: 600; }
.input, .select, .textarea { width: 100%; min-height: 48px; padding: 0 var(--s4); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-md); color: var(--ink); font-size: var(--t-md); transition: border-color .15s, box-shadow .15s; }
.textarea { padding: var(--s3) var(--s4); min-height: 96px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.search { position: relative; flex: 1; min-width: 220px; }
.search .ico { position: absolute; left: var(--s4); top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .input { padding-left: 46px; }
/* Interruptor: <label class="switch"><input type="checkbox" role="switch"><span class="switch-track"></span>Texto</label> */
.switch { display: inline-flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 48px; height: 28px; border-radius: var(--r-pill); background: var(--surface-3); border: 1px solid var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--ok); border-color: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Chips (filtros) */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { min-height: 40px; padding: 0 var(--s4); border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-size: var(--t-sm); font-weight: 650; white-space: nowrap; transition: background .15s, color .15s, border-color .15s; }
.chip:hover { color: var(--ink); background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); }

/* Tabla */
.table-wrap { overflow-x: auto; margin: 0 calc(var(--s6) * -1); padding: 0 var(--s6); }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th { text-align: left; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--s4); border-bottom: 1px solid var(--line); height: 60px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td:first-child, .table th:first-child { padding-left: var(--s2); min-width: 150px; }
.table-name { font-weight: 650; }
.rate { display: inline-flex; align-items: center; justify-content: flex-end; gap: var(--s3); min-width: 140px; }
.rate-bar { width: 80px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.rate-bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

/* Avatar */
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; letter-spacing: .02em; background: var(--brand-soft); color: var(--brand-text); }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.av-1 { background: var(--ok-soft); color: var(--ok); }
.av-2 { background: var(--info-soft); color: var(--info); }
.av-3 { background: var(--warn-soft); color: var(--warn); }
.av-4 { background: rgba(190,120,255,.16); color: #C58BFF; }
:root[data-theme="light"] .av-4 { background: #F3E3FF; color: #7A2BB0; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .av-4 { background: #F3E3FF; color: #7A2BB0; } }

/* Estado vacío */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s2); padding: var(--s12) var(--s6); }
.empty h3 { font-size: var(--t-lg); margin-top: var(--s2); }
.empty p { color: var(--muted); max-width: 44ch; margin-bottom: var(--s2); }
.ilus { width: 148px; height: auto; }
.il-sombra { fill: var(--surface-3); }
.il-hoja { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 2; }
.il-linea { fill: var(--line-strong); }
.il-lupa { fill: var(--surface); stroke: var(--brand); stroke-width: 4; }
.il-mango { stroke: var(--brand); stroke-width: 5; stroke-linecap: round; }
.il-signo { stroke: var(--brand); stroke-width: 3.5; stroke-linecap: round; }

/* Línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 var(--s6) 40px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: 11px; top: 26px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.tl-dot { position: absolute; left: 0; top: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--tone-soft, var(--neutral-soft)); display: flex; align-items: center; justify-content: center; }
.tl-dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--tone, var(--neutral)); }
.tl-title { font-weight: 700; }
.tl-time { display: block; color: var(--muted); font-size: var(--t-sm); margin-top: 2px; }
.tl-det { display: block; color: var(--ink-2); font-size: var(--t-sm); margin-top: var(--s2); }
.tl-quote { display: block; margin-top: var(--s2); padding: var(--s2) var(--s3); background: var(--surface-2); border-left: 3px solid var(--line-strong); border-radius: 0 var(--r-sm) var(--r-sm) 0; font-size: var(--t-sm); color: var(--ink-2); }

/* Lista de datos (dl) */
.facts { margin: 0; display: grid; gap: 0; }
.fact { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: 0; padding-bottom: 0; }
.fact dt { color: var(--muted); font-size: var(--t-sm); font-weight: 600; }
.fact dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- 5. Páginas ---------- */
/* Tablero: lista de pedidos */
.list-tools { display: flex; flex-direction: column; gap: var(--s4); padding: var(--s6); border-bottom: 1px solid var(--line); }
.list-search { display: flex; flex-wrap: wrap; gap: var(--s3); }
.list-head, .row { display: grid; grid-template-columns: minmax(230px, 1.4fr) minmax(0, 1.5fr) 140px 210px 24px; gap: var(--s4); align-items: center; padding: 0 var(--s6); }
.list-head { min-height: 44px; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.row { min-height: 76px; padding-top: var(--s3); padding-bottom: var(--s3); border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; transition: background .12s; }
.row:hover { background: var(--surface-2); }
.row:focus-visible { outline-offset: -3px; border-radius: 0; }
.row .go { color: var(--faint); justify-self: end; }
.row:hover .go { color: var(--ink); }
.who { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.who > div, .r-prod { display: flex; flex-direction: column; min-width: 0; }
.who b, .r-prod span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 650; }
.who small, .r-prod small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-tot { font-weight: 700; text-align: right; }
.r-est { display: flex; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s4) var(--s6); }

/* Detalle de pedido */
.dhead { display: flex; align-items: center; gap: var(--s6); flex-wrap: wrap; }
.dhead-txt { flex: 1; min-width: 220px; }
.dhead-txt h1 { font-size: var(--t-2xl); }
.dhead-txt p { color: var(--muted); margin-top: var(--s1); }
.dcols { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: var(--s6); align-items: start; }
.product-line { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.product-line:last-of-type { border-bottom: 0; }
.product-qty { color: var(--muted); font-variant-numeric: tabular-nums; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line-strong); font-weight: 700; }
.total-line b { font-size: var(--t-xl); font-variant-numeric: tabular-nums; }
.chat { display: flex; flex-direction: column; gap: var(--s2); background: var(--chat-bg); border-radius: var(--r-md); padding: var(--s4); max-height: 420px; overflow: auto; }
.msg { max-width: 82%; padding: var(--s2) var(--s3); border-radius: 12px; font-size: var(--t-sm); line-height: 1.45; color: var(--chat-ink); background: var(--bubble-in); overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0,0,0,.12); }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .meta { display: block; margin-top: 2px; text-align: right; font-size: 11.5px; color: var(--chat-muted); }

/* Avisos */
.alist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s4); }
.aviso { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: var(--s4); align-items: flex-start; padding: var(--s6); }
.aviso-ico { width: 48px; height: 48px; border-radius: var(--r-md); background: var(--tone-soft); color: var(--tone); display: flex; align-items: center; justify-content: center; }
.aviso-ico .ico { width: 24px; height: 24px; }
.aviso-body { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.aviso-body h3 { font-size: var(--t-lg); }
.aviso-body p { color: var(--ink-2); }
.aviso-meta { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); color: var(--muted); font-size: var(--t-sm); }
.aviso-side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s3); }

/* Métricas */
.funnel { display: flex; flex-direction: column; gap: var(--s6); }
.fr { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr) 150px; gap: var(--s4) var(--s6); align-items: center; }
.fr-label { font-weight: 650; }
.fr-track { height: 18px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.fr-bar { height: 100%; min-width: 4px; border-radius: 9px; background: var(--info); }
.fr-bar.ok { background: var(--ok); } .fr-bar.bad { background: var(--bad); } .fr-bar.warn { background: var(--warn); } .fr-bar.brand { background: var(--brand); }
.fr-val { text-align: right; display: flex; align-items: baseline; justify-content: flex-end; gap: var(--s3); }
.fr-val b { font-size: var(--t-lg); font-variant-numeric: tabular-nums; }
.fr-val span { color: var(--muted); font-size: var(--t-sm); min-width: 52px; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6); margin-bottom: var(--s4); color: var(--muted); font-size: var(--t-sm); }
.legend span { display: inline-flex; align-items: center; gap: var(--s2); }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 12px; font-family: var(--f-body); }
.chart .eje { stroke: var(--line); stroke-width: 1; }
.chart .b-rec { fill: var(--c-rec); }
.chart .l-ok { fill: none; stroke: var(--ok); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .l-bad { fill: none; stroke: var(--bad); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .d-ok { fill: var(--surface); stroke: var(--ok); stroke-width: 2.5; }
.chart .d-bad { fill: var(--surface); stroke: var(--bad); stroke-width: 2.5; }
.metric-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s6); }

/* Login */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--s6) var(--s4); position: relative; background: radial-gradient(900px 500px at 15% -10%, var(--glow), transparent 60%), radial-gradient(700px 420px at 100% 110%, var(--info-soft), transparent 60%), var(--bg); }
.auth-theme { position: absolute; top: var(--s4); right: var(--s4); }
.auth-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: var(--s12) var(--s8) var(--s8); display: flex; flex-direction: column; gap: var(--s6); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; }
.auth-brand .logo { width: 60px; height: 60px; }
.auth-brand .brand strong { font-size: 30px; }
.auth-brand p { color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: var(--s4); }
.auth-foot { text-align: center; color: var(--faint); font-size: var(--t-xs); }

/* ---------- 6. Responsive ---------- */
@media (max-width: 1180px) {
  .kpi-grid.kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-wide { grid-column: span 2; }
  .dcols, .metric-cols { grid-template-columns: minmax(0, 1fr); }
  .page { padding-left: var(--s8); padding-right: var(--s8); }
}
@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-top { padding: var(--s3) var(--s4); min-height: 64px; }
  .btn.side-toggle, .btn.mobile-only { display: inline-flex; }
  .btn.desktop-only { display: none; }
  .brand .logo { width: 34px; height: 34px; }
  .side-menu { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--side-bg); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: var(--s3) var(--s4) var(--s4); max-height: calc(100vh - 64px); overflow: auto; }
  .side.open .side-menu { display: flex; }
  .side-foot { margin-top: var(--s2); }
  .page { padding: var(--s6) var(--s6) var(--s12); gap: var(--s6); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
}
@media (max-width: 760px) {
  :root { --t-3xl: 28px; --t-kpi: 34px; --t-xl: 20px; }
  .page { padding: var(--s6) var(--s4) var(--s12); }
  .kpi { padding: var(--s4); min-height: 140px; }
  .kpi::before { left: var(--s4); right: var(--s4); }
  .kpi-ico { width: 38px; height: 38px; }
  .kpi-val { font-size: var(--t-kpi); }
  .kpi-wide { grid-column: span 2; }
  .card-pad { padding: var(--s4); }
  .list-tools { padding: var(--s4); }
  .chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(var(--s4) * -1); padding: 0 var(--s4) var(--s1); scrollbar-width: none; }
  .chips.scroll::-webkit-scrollbar { display: none; }
  .chip { min-height: 44px; }
  .list-head { display: none; }
  .row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "who who" "prod tot" "est est"; gap: var(--s2) var(--s3); padding: var(--s4); min-height: 96px; gap: var(--s3); }
  .row .who { grid-area: who; } .row .r-est { grid-area: est; } .row .r-prod { grid-area: prod; } .row .r-tot { grid-area: tot; align-self: end; } .row .go { display: none; }
  .pager { padding: var(--s4); }
  .pager .btn { flex: 1; }
  .fact { grid-template-columns: 1fr; gap: var(--s1); }
  .fr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "l v" "t t"; gap: var(--s2) var(--s3); }
  .fr-label { grid-area: l; } .fr-val { grid-area: v; } .fr-track { grid-area: t; }
  .aviso { grid-template-columns: 40px minmax(0, 1fr); padding: var(--s4); }
  .aviso-ico { width: 40px; height: 40px; }
  .aviso-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .table-wrap { margin: 0 calc(var(--s4) * -1); padding: 0 var(--s4); }
  .btn { min-height: 48px; }
  .btn-sm { min-height: 44px; }
  .btn-icon { width: 48px; }
  .info-btn { width: 36px; height: 36px; }
  .modal { padding: var(--s6); }
  .modal-acciones .btn { flex: 1; }
  .auth-card { padding: var(--s8) var(--s6) var(--s6); }
  .toasts { left: var(--s4); right: var(--s4); bottom: var(--s4); }
  .dhead .badge { order: 3; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}
@media (max-width: 400px) {
  .kpi-val { font-size: 30px; }
}
.legend .lg-rec { background: var(--c-rec); border: 1px solid var(--info); }
.legend .lg-ok { background: var(--ok); }
.legend .lg-bad { background: var(--bad); }
@media (max-width: 560px) {
  .kpi-grid.kpi-4 { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid.kpi-4 .kpi { min-height: 132px; }
  .kpi-grid.kpi-4 .kpi-wide { grid-column: auto; }
}
.page-actions:empty { display: none; }

/* ---------- 7. Bandeja "Requieren acción", configuración y modales con formulario ---------- */
.stack-sm { display: flex; flex-direction: column; gap: var(--s4); }
.banner a { color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.banner-modo { border-color: var(--warn); }
.arows { list-style: none; margin: 0; padding: 0; }
.arow { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); gap: var(--s4) var(--s6); padding: var(--s6); border-bottom: 1px solid var(--line); align-items: start; }
.arow:last-child { border-bottom: 0; }
.arow:hover { background: var(--surface-2); }
.arow-quien { display: flex; gap: var(--s4); align-items: flex-start; min-width: 0; }
.arow-quien-txt { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.arow-num { font-weight: 700; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.arow-num:hover { text-decoration: underline; text-underline-offset: 3px; }
.tel-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); color: var(--ink-2); font-size: var(--t-sm); }
.mini-link { display: inline-flex; align-items: center; gap: var(--s1); min-height: 32px; color: var(--info); font-weight: 650; text-decoration: none; font-size: var(--t-sm); }
.mini-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.arow-prod, .arow-est { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; align-items: flex-start; }
.arow-prod small, .arow-est small { color: var(--muted); font-size: var(--t-sm); }
.arow-est .badge { margin-bottom: var(--s1); }
.arow-acc { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--s3); padding-top: var(--s4); border-top: 1px dashed var(--line); }
.arow-acc:empty { display: none; }
.btn-cancelar { color: var(--bad); }
.nota-pie { padding: var(--s4) var(--s6); font-size: var(--t-sm); border-top: 1px solid var(--line); }
.dropi-card { border-color: var(--bad); }
.dropi-fila { padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
.dropi-fila:last-child { border-bottom: 0; padding-bottom: 0; }
.dropi-cab { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.dropi-cab small { color: var(--muted); }
.dropi-nota { margin-top: var(--s2); color: var(--ink-2); font-size: var(--t-sm); overflow-wrap: anywhere; }
.cfg-cab { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); }
.cfg-cab h2 { font-size: var(--t-xl); }
.cfg-cab .card-sub { max-width: 62ch; }
.cfg-switch { padding-top: var(--s4); border-top: 1px solid var(--line); }
.cfg-pie { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s4); margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--line); }
.tel-lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-md); }
.tel-item, .tel-vacio { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s3) var(--s4); min-height: 60px; border-bottom: 1px solid var(--line); }
.tel-item:last-child, .tel-vacio:last-child { border-bottom: 0; }
.tel-vacio { color: var(--muted); }
.tel-agregar { margin-top: var(--s6); }
.tel-agregar-fila { display: flex; gap: var(--s3); }
.tel-agregar-fila .input { flex: 1; min-width: 0; }
.modal { max-height: calc(100vh - 32px); overflow-y: auto; }
.modal .banner { align-items: flex-start; }
@media (max-width: 980px) {
  .arow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .arow-quien { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .arow { grid-template-columns: minmax(0, 1fr); padding: var(--s4); gap: var(--s4); }
  .arow-acc .btn { flex: 1 1 100%; }
  .tel-agregar-fila { flex-direction: column; }
  .cfg-pie .btn { width: 100%; }
  .tel-item .btn { min-height: 44px; }
}
@media (max-width: 560px) {
  #kpis.kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  #kpis.kpi-4 .kpi { min-height: 112px; padding: var(--s3) var(--s4); }
  #kpis.kpi-4 .kpi-sub { display: none; }
  #kpis.kpi-4 .kpi-ico { width: 32px; height: 32px; }
  #kpis.kpi-4 .kpi-val { font-size: 30px; }
}
