/* =========================================================
   Sillar Finance — hoja de estilos
   Tokens de color validados (dataviz): superficie clara #fcfcfb / oscura #1a1a19
   ========================================================= */

/* ---------- Tokens: modo claro (base) ---------- */
:root {
  color-scheme: light;

  --surface-1: #fcfcfb;          /* tarjetas / superficie de graficos */
  --surface-2: #f4f3ef;          /* superficie hundida (inputs, filas alt.) */
  --plane:     #f9f9f7;          /* plano de pagina */
  --sidebar:   #ffffff;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --grid:     #e1e0d9;
  --axis:     #c3c2b7;
  --border:   rgba(11, 11, 11, .10);
  --border-strong: rgba(11, 11, 11, .18);
  --shadow:   0 1px 2px rgba(11,11,11,.04), 0 8px 24px rgba(11,11,11,.06);
  --ghost-wash: rgba(11, 11, 11, .045);

  /* Categoricos (identidad) — orden fijo, nunca ciclado */
  --series-1: #2a78d6;  /* azul     */
  --series-2: #eb6834;  /* naranja  */
  --series-3: #1baf7a;  /* aqua     */
  --series-4: #eda100;  /* amarillo */
  --series-5: #e87ba4;  /* magenta  */
  --series-6: #008300;  /* verde    */
  --series-7: #4a3aa7;  /* violeta  */
  --series-8: #e34948;  /* rojo     */
  --series-other: #898781;

  /* Estado (nunca reutilizados como serie) */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  /* Secuencial (azul, claro -> oscuro) */
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5; --seq-600: #184f95;

  --accent: var(--series-1);
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, .10);

  --radius:    14px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --sidebar-w: 244px;
  --tabbar-h:  62px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* ---------- Insets del sistema ----------
     Barra de estado, barra de gestos y muescas. Dentro de la app de
     Android, Capacitor inyecta --safe-area-inset-* en el elemento raíz
     con los valores reales; en el navegador esas variables no existen y
     se cae a env(), que en escritorio da cero.

     Los dos caminos hacen falta. En un WebView moderno la app dibuja de
     punta a punta y estos valores son lo único que impide que la hora y
     la batería queden encima de la barra superior. En un WebView viejo
     Capacitor achica la vista y entonces inyecta ceros: sumar el inset
     ahí duplicaría el margen, y por eso se prefiere el valor inyectado
     sobre env() cuando existe. */
  --inset-top:    var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --inset-right:  var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --inset-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --inset-left:   var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
}

/* ---------- Tokens: modo oscuro ---------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --plane:     #0d0d0d;
    --sidebar:   #131312;

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;

    --grid:   #2c2c2a;
    --axis:   #383835;
    --border: rgba(255,255,255,.10);
    --border-strong: rgba(255,255,255,.18);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
    --ghost-wash: rgba(255,255,255,.06);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --good-text: #0ca30c;
    --accent-wash: rgba(57, 135, 229, .16);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --plane:     #0d0d0d;
  --sidebar:   #131312;

  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;

  --grid:   #2c2c2a;
  --axis:   #383835;
  --border: rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.18);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --ghost-wash: rgba(255,255,255,.06);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --good-text: #0ca30c;
  --accent-wash: rgba(57, 135, 229, .16);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
a { color: inherit; text-decoration: none; }

.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-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; border-radius: var(--radius-xs);
}
.skip-link:focus { left: 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Layout ---------- */
.app { min-height: 100%; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
  padding: calc(18px + var(--inset-top)) 12px calc(18px + var(--inset-bottom)) calc(12px + var(--inset-left));
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 14.5px; font-weight: 500;
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; opacity: .8; }
.nav-item:hover { background: var(--ghost-wash); color: var(--text-primary); }
.nav-item.is-active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav-item.is-active svg { opacity: 1; }

.sidebar-foot { margin-top: auto; }

.content { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: calc(16px + var(--inset-top)) calc(24px + var(--inset-right)) 16px calc(24px + var(--inset-left));
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title h1 { font-size: 20px; }
.topbar-title p { font-size: 13px; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.main { padding: 22px 24px 40px; flex: 1; }

/* ---------- Aviso de modo ----------
   Explica dónde viven los datos cuando eso cambia lo que se puede
   hacer en esta pantalla: modo local abierto en el escritorio, o
   sesión abierta sin conexión. Vive fuera de <main> porque las
   vistas reemplazan su contenido entero. */
.aviso-modo {
  margin: 18px 24px 0;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.5;
}
.aviso-modo p + p { margin-top: 8px; }
.aviso-modo strong { color: var(--text); }
.aviso-modo a { color: var(--accent); }

.tabbar { display: none; }

/* ---------- Tipografia auxiliar ---------- */
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 13px; border-radius: var(--radius-xs);
  border: 1px solid transparent; background: transparent;
  font-size: 14px; font-weight: 550; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; fill: currentColor; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { border-color: var(--border-strong); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--ghost-wash); color: var(--text-primary); }
.btn-quiet { color: var(--text-muted); padding: 6px 8px; }
.btn-quiet:hover { background: var(--ghost-wash); color: var(--text-primary); }
.btn-danger { color: var(--critical); }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.btn-block { width: 100%; }
.icon-only { padding: 8px 10px; min-width: 36px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* toggle de tema: mostrar el icono segun el modo activo */
.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .ico-sun { display: none; }
  :root:where(:not([data-theme="light"])) .ico-moon { display: block; }
}

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span:not(.sr-only) { font-size: 12.5px; color: var(--text-secondary); font-weight: 550; }
.field-inline { flex-direction: row; align-items: center; }
input, select, textarea {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  padding: 8px 11px;
  font-size: 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea { resize: vertical; min-height: 62px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
input[type="month"], input[type="date"] { min-width: 140px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.form-actions .spacer { margin-right: auto; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2, .card-head h3 { font-size: 15.5px; }
.card-head .card-sub { font-size: 12.5px; color: var(--text-muted); }
.card-head .card-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Stat tiles ---------- */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 550; }
.stat-value { font-size: 27px; font-weight: 660; letter-spacing: -.02em; line-height: 1.15; }
.stat-value.hero { font-size: 40px; }
.stat-delta { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.stat-delta strong { font-weight: 600; }
.stat-spark { margin-top: 4px; }

/* ---------- Graficos ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-empty {
  display: grid; place-items: center; min-height: 160px;
  color: var(--text-muted); font-size: 13.5px; text-align: center; padding: 20px;
}
.legend { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.legend-row {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 6px; border-radius: 6px; font-size: 13px;
}
.legend-row:hover { background: var(--ghost-wash); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 550; }
.legend-pct { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.legend-inline { flex-direction: row; flex-wrap: wrap; gap: 14px; }
.legend-inline .legend-row { padding: 0; }
.legend-inline .legend-row:hover { background: none; }

.chart-tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-xs);
  box-shadow: var(--shadow);
  padding: 8px 11px; font-size: 12.5px; max-width: 240px;
  transform: translate(-50%, calc(-100% - 12px));
}
.chart-tooltip .tt-title { font-weight: 620; margin-bottom: 3px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
.chart-tooltip .tt-row .legend-swatch { width: 8px; height: 8px; }
.chart-tooltip .tt-row span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 550; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; padding: 0 4px 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 14px; text-align: left; white-space: nowrap; }
.table th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--grid); position: sticky; top: 0; background: var(--surface-1);
}
.table td { border-bottom: 1px solid var(--grid); color: var(--text-secondary); }
.table tbody tr:hover td { background: var(--ghost-wash); }
.table .t-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 550; }
.table .t-main { color: var(--text-primary); font-weight: 550; white-space: normal; min-width: 160px; }
.table .t-actions { text-align: right; width: 1%; }
.table tfoot td { font-weight: 620; color: var(--text-primary); border-bottom: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary); white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 999px; flex: none; }
.chip-good { color: var(--good-text); background: color-mix(in srgb, var(--good) 12%, transparent); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.chip-bad  { color: var(--critical); background: color-mix(in srgb, var(--critical) 12%, transparent); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }

/* ---------- Barra de filtros ---------- */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px; margin-bottom: 16px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filters .field { min-width: 150px; flex: 1 1 150px; }
.filters .filters-end { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-xs); padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 6px;
  font-size: 13px; color: var(--text-secondary); cursor: pointer; font-weight: 550;
}
.segmented button.is-active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }

/* ---------- Estado vacio ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty h3 { color: var(--text-secondary); font-size: 15px; margin-bottom: 6px; }
.empty p { font-size: 13.5px; margin-bottom: 14px; }

/* ---------- Barras de progreso / rubros ---------- */
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13.5px; }
.bar-item .bar-name { color: var(--text-secondary); }
.bar-item .bar-val { font-variant-numeric: tabular-nums; font-weight: 550; }
.bar-track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(11,11,11,.45);
  display: grid; place-items: center;
  padding: calc(18px + var(--inset-top)) calc(18px + var(--inset-right)) calc(18px + var(--inset-bottom)) calc(18px + var(--inset-left));
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(620px, 100%); max-height: calc(100vh - 36px);
  display: flex; flex-direction: column;
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: 18px; overflow-y: auto; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; z-index: 70; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs); box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13.5px; max-width: 320px;
  display: flex; align-items: center; gap: 9px;
  animation: pop .14s ease-out;
}
.toast .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--good); flex: none; }
.toast.is-error .dot { background: var(--critical); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  :root { --sidebar-w: 78px; }
  .brand-text, .nav-item span, .theme-label { display: none; }
  .nav-item { justify-content: center; padding: 11px; }
  .brand { justify-content: center; padding: 4px 0 16px; }
}

@media (max-width: 760px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + var(--inset-bottom)); }

  .topbar {
    padding: calc(12px + var(--inset-top)) calc(14px + var(--inset-right)) 12px calc(14px + var(--inset-left));
    gap: 10px;
  }
  .topbar-title h1 { font-size: 18px; }
  .topbar-title p { display: none; }
  .topbar-tools { width: 100%; margin-left: 0; }
  .topbar-tools .field-inline { flex: 1; }
  .topbar-tools input[type="month"] { min-width: 0; width: 100%; }
  .hide-sm { display: none; }

  .main { padding: 14px calc(14px + var(--inset-right)) 26px calc(14px + var(--inset-left)); }
  .aviso-modo { margin: 12px calc(14px + var(--inset-right)) 0 calc(14px + var(--inset-left)); font-size: 13px; }
  .card { padding: 15px; border-radius: 12px; }
  .table-wrap { margin: 0 -15px -15px; }
  .form-grid { grid-template-columns: 1fr; }
  .grid { gap: 12px; }
  .stat-value { font-size: 24px; }
  .stat-value.hero { font-size: 32px; }
  .filters { padding: 12px; }
  .filters .field { flex-basis: 100%; min-width: 0; }
  .filters .filters-end { width: 100%; margin-left: 0; }

  /* La hoja sube desde abajo y ocupa todo el ancho: el inset de arriba se
     respeta para que su encabezado no quede bajo el reloj, y el de abajo
     va adentro del cuerpo para que el último botón no lo tape la barra de
     gestos. */
  .modal-backdrop { padding: var(--inset-top) 0 0; align-items: flex-end; }
  .modal {
    width: 100%; max-height: calc(92vh - var(--inset-top));
    border-radius: 16px 16px 0 0;
  }
  .modal-body { padding-bottom: calc(18px + var(--inset-bottom)); }

  .toast-stack {
    right: calc(12px + var(--inset-right)); left: calc(12px + var(--inset-left));
    bottom: calc(var(--tabbar-h) + var(--inset-bottom) + 12px);
    align-items: stretch;
  }
  .toast { max-width: none; }

  .tabbar {
    display: flex; position: fixed; z-index: 20;
    inset: auto 0 0 0; height: calc(var(--tabbar-h) + var(--inset-bottom));
    padding: 0 var(--inset-right) var(--inset-bottom) var(--inset-left);
    background: color-mix(in srgb, var(--sidebar) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }
  .tab-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 10.5px; color: var(--text-muted); font-weight: 550;
  }
  .tab-item svg { width: 21px; height: 21px; fill: currentColor; }
  .tab-item.is-active { color: var(--accent); }
}

@media print {
  .sidebar, .tabbar, .topbar-tools, .t-actions { display: none !important; }
  .content { margin: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* ---------- Gemelo tabular de los graficos ---------- */
.chart-table { margin-top: 14px; }
.chart-table > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
}
.chart-table > summary::-webkit-details-marker { display: none; }
.chart-table > summary::before { content: "▸"; font-size: 10px; }
.chart-table[open] > summary::before { content: "▾"; }
.chart-table .table-wrap { margin: 8px 0 0; max-height: 260px; overflow-y: auto; }
.chart-table .table th, .chart-table .table td { padding: 7px 10px; }

/* ---------- Detalles varios ---------- */
.card button.card { background: var(--surface-1); box-shadow: none; }
.card button.card:hover { background: var(--ghost-wash); }
.table .t-actions .btn + .btn { margin-left: 2px; }

/* =========================================================
   Sesión: pantalla de acceso, estado de sincronización y cuenta
   ========================================================= */

body.sin-sesion .app { display: none; }
body.sin-sesion { overflow: hidden; }

.gate {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  padding: calc(24px + var(--inset-top)) calc(24px + var(--inset-right)) calc(24px + var(--inset-bottom)) calc(24px + var(--inset-left));
  background: var(--plane);
  overflow-y: auto;
}
.gate[hidden] { display: none; }

.gate-panel {
  width: min(420px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px;
}
.gate-marca { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.gate-marca strong { display: block; font-size: 15.5px; font-weight: 650; }
.gate-marca span { font-size: 12.5px; color: var(--text-muted); }

.gate-tabs { width: 100%; margin-bottom: 18px; }
.gate-tabs button { flex: 1; }

.gate-campos { display: flex; flex-direction: column; gap: 14px; }
.gate-enviar { margin-top: 18px; padding: 10px 16px; }
.gate-error {
  margin-top: 14px; font-size: 13px; color: var(--critical);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--critical) 28%, transparent);
  border-radius: var(--radius-xs); padding: 8px 11px;
}
.gate-pie { margin-top: 14px; font-size: 12.5px; color: var(--text-muted); text-align: center; }
.gate-nota {
  width: min(420px, 100%); text-align: center;
  font-size: 12.5px; color: var(--text-muted); line-height: 1.5;
}
.enlace {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent); font-weight: 550; text-decoration: underline;
}

/* ---------- selector de plan ---------- */
.planes { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.planes legend { font-size: 12.5px; color: var(--text-secondary); font-weight: 550; padding: 0 0 6px; }
.plan-opcion {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px;
  padding: 11px 13px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s ease, background .12s ease;
}
.plan-opcion input { width: auto; margin: 3px 0 0; grid-row: span 2; align-self: start; }
.plan-nombre { font-size: 14px; font-weight: 600; }
.plan-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }
.plan-opcion:hover { background: var(--ghost-wash); }
.plan-opcion.is-active { border-color: var(--accent); background: var(--accent-wash); }

/* ---------- estado de sincronización ---------- */
.sync {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-muted);
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.sync .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--good); flex: none; }
.sync-trabajando .dot { background: var(--warning); }
.sync-aviso .dot { background: var(--serious); }
.sync-error { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.sync-error .dot { background: var(--critical); }
.sync:empty { display: none; }

/* ---------- chip de usuario ---------- */
.user-chip {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 4px 11px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border-strong);
}
.user-chip:hover { background: var(--ghost-wash); }
.user-ini {
  width: 28px; height: 28px; border-radius: 999px; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 650;
}
.user-txt { display: flex; flex-direction: column; line-height: 1.2; }
.user-txt strong { font-size: 13px; font-weight: 600; }
.user-txt span { font-size: 11.5px; color: var(--text-muted); }

/* ---------- listas clave/valor ---------- */
.lista-datos { display: flex; flex-direction: column; gap: 1px; }
.lista-datos > div {
  display: flex; align-items: baseline; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--grid);
  font-size: 13.5px;
}
.lista-datos > div:last-child { border-bottom: 0; }
.lista-datos span { color: var(--text-secondary); }
.lista-datos strong { margin-left: auto; font-weight: 600; }

@media (max-width: 760px) {
  .gate { padding: 0; justify-content: flex-start; }
  .gate-panel {
    width: 100%; min-height: 100vh; border: 0; border-radius: 0;
    box-shadow: none; padding: 32px 20px;
    display: flex; flex-direction: column; justify-content: center;
  }
  .gate-nota { padding: 0 20px 28px; }
  .topbar-tools .sync span { display: none; }
  .topbar-tools .sync { padding: 5px; }
  .user-txt { display: none; }
  .user-chip { padding: 3px; border: 0; }
  .tab-item span { font-size: 10px; }
}

/* ---------- Recuperación de contraseña ---------- */
.gate-titulo { font-size: 17px; margin-bottom: 8px; }
.gate-texto { font-size: 14px; line-height: 1.55; color: var(--text-secondary); margin-bottom: 4px; }
.gate-texto + .gate-campos { margin-top: 16px; }
.gate-texto.muted { color: var(--text-muted); font-size: 13px; }

.gate-olvide { margin-top: 12px; text-align: right; font-size: 12.5px; }

.gate-coincide { font-size: 12.5px; margin-top: -6px; display: flex; align-items: center; gap: 6px; }
.gate-coincide.es-ok { color: var(--good-text); }
.gate-coincide.es-error { color: var(--critical); }
.gate-coincide::before { content: "•"; font-size: 14px; line-height: 1; }
.gate-coincide.es-ok::before { content: "✓"; }
.gate-coincide.es-error::before { content: "✕"; }

.gate-aviso { text-align: center; padding: 6px 0 4px; }
.gate-aviso .gate-titulo,
.gate-aviso .gate-texto { text-align: center; }
.gate-icono {
  width: 46px; height: 46px; margin: 0 auto 14px;
  border-radius: 999px; display: grid; place-items: center;
  font-size: 21px; line-height: 1;
}
.gate-aviso.es-ok .gate-icono {
  background: color-mix(in srgb, var(--good) 14%, transparent);
  color: var(--good-text);
}
.gate-aviso.es-alerta .gate-icono {
  background: color-mix(in srgb, var(--warning) 20%, transparent);
  color: var(--serious);
  font-weight: 700;
}

/* ---------- Modulos habilitados por el plan ---------- */
.plan-modulos {
  grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px 10px;
  margin-top: 6px;
}
.plan-modulo { font-size: 11.5px; color: var(--good-text); white-space: nowrap; }
.plan-modulo.es-fuera { color: var(--text-muted); text-decoration: line-through; }

.modulos-lista { display: flex; flex-direction: column; gap: 1px; }
.modulo {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid var(--grid);
  font-size: 13.5px; color: var(--text-muted);
}
.modulo:last-child { border-bottom: 0; }
.modulo strong { display: block; font-weight: 600; color: var(--text-secondary); }
.modulo.es-activo strong { color: var(--text-primary); }
.modulo-desc { display: block; font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.modulo-marca {
  width: 20px; height: 20px; flex: none; border-radius: 999px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted);
}
.modulo.es-activo .modulo-marca {
  background: color-mix(in srgb, var(--good) 15%, transparent);
  color: var(--good-text);
}
.modulo-estado {
  margin-left: auto; font-size: 11.5px; white-space: nowrap;
  padding-top: 2px;
}
.modulo.es-activo .modulo-estado { color: var(--good-text); }

.aviso-plan {
  padding: 12px 15px; margin-bottom: 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--series-4);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  font-size: 13px; line-height: 1.55; color: var(--text-secondary);
}
.aviso-plan a { color: var(--accent); text-decoration: underline; }

/* ---------- Lo que el plan no incluye ----------
   Se muestra, no se esconde. Tiene que leerse como «esto existe y todavía
   no es tuyo», no como «esto está roto»: de ahí el candado en vez de un
   gris de deshabilitado, y de ahí que siga respondiendo al toque —lo que
   devuelve es la explicación—. Nada lleva `disabled`, porque un control
   deshabilitado no dispara eventos y entonces no habría forma de contar
   por qué está así. */
.es-bloqueado { position: relative; opacity: .62; }
.es-bloqueado:hover { opacity: .78; }

.nav-item.es-bloqueado::after,
.tab-item.es-bloqueado::after,
.btn.es-bloqueado::after {
  content: "🔒";
  font-size: .82em;
  margin-left: 6px;
  line-height: 1;
  filter: grayscale(1);
}
.tab-item.es-bloqueado::after { position: absolute; top: 6px; right: 50%; margin: 0; transform: translateX(220%); }
.nav-item.es-bloqueado { font-weight: 500; }

/* Etiqueta para las tarjetas de alta rápida */
.etiqueta-plan {
  display: inline-block; margin-left: 8px;
  padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  color: var(--text-muted); text-transform: uppercase;
  vertical-align: middle;
}
.opcion-alta { text-align: left; cursor: pointer; border-color: var(--border-strong); }
.opcion-alta-nombre { font-weight: 620; margin-bottom: 4px; }

/* Panel que ocupa el lugar de una sección bloqueada */
.panel-bloqueo { text-align: center; padding: 34px 22px; }
.panel-bloqueo-candado {
  width: 54px; height: 54px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
}
.panel-bloqueo-candado svg { width: 26px; height: 26px; fill: var(--text-muted); }
.panel-bloqueo h2 { font-size: 17px; margin-bottom: 8px; }
.panel-bloqueo p { max-width: 46ch; margin: 0 auto; font-size: 14px; }

/* ---------- Aviso legal ---------- */
.descargo {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 15px 16px; margin-bottom: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--series-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.descargo-cuerpo { flex: 1; min-width: 0; }
.descargo-titulo {
  display: block; font-size: 13px; font-weight: 650;
  color: var(--text-primary); margin-bottom: 6px;
}
.descargo-cerrar { flex: none; margin: -4px -4px 0 0; }
.legal-texto {
  font-size: 12.5px; line-height: 1.6;
  color: var(--text-secondary); text-align: justify;
  hyphens: auto;
}

@media (max-width: 760px) {
  .legal-texto { text-align: left; }
}

/* ---------- Cuenta compartida ---------- */
.compartir-estado {
  display: flex; align-items: flex-start; gap: 13px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.compartir-icono { font-size: 22px; line-height: 1; }

.compartir-enlace {
  margin-top: 16px; padding: 15px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.compartir-enlace input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.btn-whatsapp { background: #25d366; color: #08260f; font-weight: 600; }
.btn-whatsapp:hover { filter: brightness(1.06); }
.btn-whatsapp svg { fill: currentColor; }

.lista-miembros { display: flex; flex-direction: column; gap: 1px; }
.miembro {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 0; border-bottom: 1px solid var(--grid);
}
.miembro:last-child { border-bottom: 0; }
.miembro-ini {
  width: 32px; height: 32px; border-radius: 999px; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 650;
}
.miembro.es-pendiente .miembro-ini { background: var(--surface-2); color: var(--text-muted); }
.miembro-datos { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.miembro-datos strong { font-size: 13.5px; font-weight: 600; }
.miembro-datos span { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

.chip-titular {
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
  border-color: color-mix(in srgb, var(--series-1) 32%, transparent);
  color: var(--series-1);
}
.chip-hija {
  background: color-mix(in srgb, var(--series-7) 14%, transparent);
  border-color: color-mix(in srgb, var(--series-7) 32%, transparent);
  color: var(--series-7);
}
