/* Fundación – sistema de diseño
   Tokens primero; todo lo demás se escribe contra los tokens (claro/oscuro en un solo lugar). */

:root {
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --page: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-sunken: #eef1f5;
  --border: #e2e6ec;
  --border-strong: #cdd3dc;

  --ink: #111a26;
  --ink-2: #4a5566;
  --ink-3: #7a8494;

  --brand: #13304f;
  --brand-2: #1d4673;
  --brand-ink: #ffffff;
  --accent: #2a6bc2;
  --accent-soft: #e8f0fb;
  --focus: #2a78d6;

  --good: #12784a;   --good-soft: #e5f4ec;
  --warn: #8a5a00;   --warn-soft: #fdf3dc;
  --bad: #b42318;    --bad-soft: #fde9e7;

  --serie-1: #2a78d6; --serie-2: #eb6834; --serie-3: #1baf7a; --serie-4: #eda100; --serie-5: #e87ba4;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(17, 26, 38, .06), 0 1px 3px rgba(17, 26, 38, .04);
  --shadow-lg: 0 8px 24px rgba(17, 26, 38, .12);
  --sidebar: 228px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d1117; --surface: #161b22; --surface-2: #1b2129; --surface-sunken: #11161c;
    --border: #2a313b; --border-strong: #39424e;
    --ink: #eef2f6; --ink-2: #b4bdc9; --ink-3: #8691a0;
    --brand: #0b1a2b; --brand-2: #16314f; --accent: #5b9be6; --accent-soft: #16263a; --focus: #5b9be6;
    --good: #3cc483; --good-soft: #0f2a1e; --warn: #f0b545; --warn-soft: #2d2410; --bad: #ff7b72; --bad-soft: #2f1414;
    --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500; --serie-5: #d55181;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d1117; --surface: #161b22; --surface-2: #1b2129; --surface-sunken: #11161c;
  --border: #2a313b; --border-strong: #39424e;
  --ink: #eef2f6; --ink-2: #b4bdc9; --ink-3: #8691a0;
  --brand: #0b1a2b; --brand-2: #16314f; --accent: #5b9be6; --accent-soft: #16263a; --focus: #5b9be6;
  --good: #3cc483; --good-soft: #0f2a1e; --warn: #f0b545; --warn-soft: #2d2410; --bad: #ff7b72; --bad-soft: #2f1414;
  --serie-1: #3987e5; --serie-2: #d95926; --serie-3: #199e70; --serie-4: #c98500; --serie-5: #d55181;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--brand); color: #c9d4e3; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: #fff; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3d7fd0, #1d4673); font-weight: 700; font-size: 15px; color: #fff;
}
.brand-name { font-weight: 650; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #8fa3bd; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f93ad; margin: 18px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: #c9d4e3; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 3px 0 0 #5b9be6; }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 14px; }
.user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: #2b507c; color: #fff; font-size: 12px; font-weight: 650;
}
.user-name { color: #fff; font-weight: 550; font-size: 13px; }
.user-role { font-size: 11.5px; color: #8fa3bd; }
.linkbtn { background: none; border: 0; padding: 0; color: #8fa3bd; cursor: pointer; font: inherit; font-size: 12px; }
.linkbtn:hover { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.crumbs { font-size: 12.5px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--ink-2); }
.topbar-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.content { padding: 24px 24px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; width: 100%; min-width: 0; }
.content > * { min-width: 0; }

/* ---------- Year switcher (segmented) ---------- */
.segmented { display: inline-flex; background: var(--surface-sunken); border: 1px solid var(--border);
             border-radius: 9px; padding: 3px; gap: 2px; }
.segmented a {
  padding: 5px 12px; border-radius: 6px; color: var(--ink-2); font-weight: 550; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.segmented a:hover { color: var(--ink); text-decoration: none; background: var(--surface); }
.segmented a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--ink); }
.btn-danger { color: var(--bad); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.input, select.input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; min-width: 0;
}
.input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.input-money { text-align: right; font-variant-numeric: tabular-nums; width: 150px; }
.input-money.compact { height: 28px; width: 112px; font-size: 12.5px; padding: 0 8px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); font-weight: 550; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head .desc { color: var(--ink-3); font-size: 12.5px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-title { font-size: 12.5px; color: var(--ink-2); font-weight: 550; }
.kpi-value { font-size: 22px; font-weight: 650; letter-spacing: -.02em; white-space: nowrap; }
.kpi-note { font-size: 12px; color: var(--ink-3); }
.kpi.highlight { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background:
  linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data th, .data td { padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 12px;
  white-space: nowrap; z-index: 1;
}
.data tbody tr:hover td { background: var(--surface-2); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data .neg { color: var(--bad); }
.data .cero { color: var(--ink-3); }
.data tfoot td { font-weight: 650; background: var(--surface-2); border-bottom: 0; }
.data .col-total { background: var(--surface-2); font-weight: 600; }
.data td.concepto { white-space: nowrap; color: var(--ink-2); }
.data tr.resta td.concepto::before { content: "− "; color: var(--ink-3); }
.data tr.suma td.concepto::before { content: "+ "; color: var(--ink-3); }
.data tr.base td { font-weight: 600; }
.data tr.subtotal td { font-weight: 650; background: var(--surface-sunken); color: var(--ink); }
.data tr.subtotal td.concepto, .data tr.resultado td.concepto { color: var(--ink); }
.data tr.subtotal td.concepto::before, .data tr.resultado td.concepto::before { content: "= "; color: var(--ink-3); }
.data tr.resultado td { font-weight: 700; background: var(--accent-soft); color: var(--ink); border-bottom: 0; }
.data tr.meta td { color: var(--ink-3); font-size: 12px; background: var(--surface-2); }
/* Cuadro ancho (muchas columnas): más compacto, encabezados que pueden partir en dos líneas */
.data.compact { font-size: 12.5px; }
.data.compact th, .data.compact td { padding: 8px 10px; }
.data.compact thead th { white-space: normal; max-width: 130px; line-height: 1.3; }
.data.compact td.concepto { white-space: normal; min-width: 180px; }
.card-foot { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 12px 18px;
             border-top: 1px solid var(--border); }
.data th a { color: inherit; }
.area-tipo { display: block; font-weight: 500; color: var(--ink-3); font-size: 11px; }
.data .ident { display: flex; flex-direction: column; white-space: nowrap; }
.data .ident small { color: var(--ink-3); font-size: 11.5px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-sunken); color: var(--ink-2); white-space: nowrap;
}
.badge.activo { background: var(--good-soft); color: var(--good); }
.badge.retirado, .badge.fundador { background: var(--accent-soft); color: var(--accent); }
.badge.contingente { background: var(--warn-soft); color: var(--warn); }
.badge.plan { background: transparent; border: 1px solid var(--border-strong); color: var(--ink-2); }
.badge.estado-ok { background: var(--good-soft); color: var(--good); }
.badge.estado-hist { background: var(--surface-sunken); color: var(--ink-2); }
.badge.estado-pend { background: var(--warn-soft); color: var(--warn); }
.delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---------- Alerts ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px;
  border: 1px solid transparent; font-size: 13px;
}
.alert strong { font-weight: 650; }
.alert.success { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.alert.warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert.error { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
details.avisos summary { cursor: pointer; font-weight: 600; }

/* ---------- Composition chart ---------- */
.chart { display: flex; flex-direction: column; gap: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 130px; gap: 12px; align-items: center; }
.bar-label { font-weight: 600; font-size: 13px; }
.bar-label small { display: block; color: var(--ink-3); font-weight: 500; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.bar { display: flex; gap: 2px; height: 22px; }
.seg { height: 100%; position: relative; min-width: 0; cursor: default; }
.seg:first-child { border-radius: 4px 0 0 4px; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg:hover { filter: brightness(1.08); }
.s1 { background: var(--serie-1); } .s2 { background: var(--serie-2); } .s3 { background: var(--serie-3); }
.s4 { background: var(--serie-4); } .s5 { background: var(--serie-5); }
.bar-side { text-align: right; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar-side strong { display: block; color: var(--ink); font-size: 12.5px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 8px 10px;
  font-size: 12px; min-width: 180px; display: none;
}
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- Checklist / empty state ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--border);
        border-radius: 8px; background: var(--surface-2); }
.step .dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none;
             background: var(--surface-sunken); color: var(--ink-3); font-size: 12px; font-weight: 700; }
.step.done .dot { background: var(--good-soft); color: var(--good); }
.step .step-text { display: flex; flex-direction: column; }
.step .step-text small { color: var(--ink-3); }
.step .btn { margin-left: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty .ic { width: 36px; height: 36px; color: var(--ink-3); margin-bottom: 8px; }

/* ---------- Detail header ---------- */
.profile { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.profile .avatar { width: 48px; height: 48px; font-size: 16px; background: var(--brand-2); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0; }
.fact { padding: 12px 18px; border-right: 1px solid var(--border); }
.fact:last-child { border-right: 0; }
.fact dt { font-size: 12px; color: var(--ink-3); margin-bottom: 3px; }
.fact dd { margin: 0; font-weight: 600; }

.cuotas { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.cuota { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--border);
         border-radius: 8px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.cuota span { font-size: 12px; color: var(--ink-3); }
.cuota strong { font-size: 13px; font-weight: 600; }
.data tr.subtotal td { font-weight: 650; }
details.importacion > summary { cursor: pointer; list-style: none; }
details.importacion > summary::-webkit-details-marker { display: none; }
details.importacion > summary { flex-wrap: nowrap; }
details.importacion > summary > div { flex: 1; min-width: 0; }
details.importacion > summary::after { content: "▸"; margin-left: 12px; color: var(--ink-3); font-size: 14px; }
details.importacion[open] > summary::after { content: "▾"; }
details.importacion:not([open]) > summary { border-bottom: 0; }
.input.archivo { height: auto; padding: 6px 8px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .input { min-width: 140px; }
.toolbar .search { flex: 1 1 240px; }
.note { font-size: 12px; color: var(--ink-3); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #1d4673 0%, transparent 60%), var(--brand); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
              padding: 32px; display: flex; flex-direction: column; gap: 18px; }
.login-card .brand { color: var(--ink); padding: 0; }
.login-card .brand-sub { color: var(--ink-3); }
.login-card .input { width: 100%; height: 40px; }
.login-card .btn { height: 40px; justify-content: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav a { white-space: nowrap; }
  .kpi-value { font-size: 20px; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px;
             overflow-x: auto; }
  .brand { padding: 0; }
  .brand-text, .nav-label, .sidebar-foot .user-meta { display: none; }
  .nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .topbar { padding: 12px 16px; position: static; }
  .content { padding: 16px 16px 40px; }
  .bar-row { grid-template-columns: 1fr; gap: 4px; }
  .bar-side { text-align: left; }
}

/* ---------- Print ---------- */
@media print {
  body.sin-impresion > * { display: none !important; }
  body.sin-impresion::before { content: "La impresión no está habilitada para este usuario."; display: block; padding: 40px; font-size: 14px; }
  :root { color-scheme: light; }
  body { background: #fff; font-size: 11px; }
  .app { display: block; }
  .sidebar, .topbar-actions, .no-print, .tooltip { display: none !important; }
  .topbar { position: static; border: 0; padding: 0 0 12px; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .data thead th { position: static; }
  a { color: inherit; }
}
