/* =========================================================================
   MQS — sistema de diseño
   Marca: negro grafito + amarillo MQS (el amarillo sólo como fondo/acento con
   texto oscuro encima: el amarillo como texto no cumple contraste AA).
   ========================================================================= */

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

  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f3f3f0;
  --surface-3: #e9e8e3;
  --border: #e2e1db;
  --border-strong: #c9c8c0;
  --text: #121211;
  --text-2: #4d4c48;
  --muted: #6e6c66;

  --nav-bg: #141413;
  --nav-text: #e9e8e3;
  --nav-muted: #a9a7a0;
  --nav-hover: #26261f;

  --brand: #f2b705;
  --brand-ink: #141413;
  --brand-soft: #fff6d6;

  --primary: #1b1b1a;
  --primary-hover: #33332f;
  --primary-ink: #ffffff;

  --focus: #2a78d6;
  --link: #1c5cab;

  --ok: #0a6b0a;        --ok-bg: #e6f4e4;
  --warn: #7a4f00;      --warn-bg: #fff3d0;
  --danger: #b42323;    --danger-bg: #fde9e7;
  --info: #1c5cab;      --info-bg: #e5effc;

  --ingreso: #0a6b0a;
  --egreso: #b42323;

  --row-hover: #f7f6f2;
  --row-selected: #fff6d6;
  --row-highlight: #e5effc;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(17, 17, 15, 0.06);
  --shadow: 0 1px 2px rgba(17, 17, 15, 0.06), 0 4px 12px rgba(17, 17, 15, 0.06);
  --shadow-lg: 0 12px 40px rgba(17, 17, 15, 0.18);

  /* Gráficas (paleta validada para daltonismo y contraste, modo claro) */
  --serie-1: #2a78d6; --serie-2: #eb6834;
  --chart-grid: #e1e0d9; --chart-axis: #c3c2b7; --chart-muted: #6e6c66;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --nav-h: 52px;
}

/* Modo oscuro: valores elegidos (no invertidos) y validados contra su superficie. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0e0e0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
    --border: #2f2f2c; --border-strong: #45453f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a988f;
    --nav-bg: #0a0a09; --nav-hover: #1f1f1c;
    --brand-soft: #3a3110;
    --primary: #f0efec; --primary-hover: #d9d8d2; --primary-ink: #121211;
    --focus: #5598e7; --link: #86b6ef;
    --ok: #4cc24c; --ok-bg: #12301a; --warn: #f5c451; --warn-bg: #3a2e0c;
    --danger: #f08a8a; --danger-bg: #3d1716; --info: #86b6ef; --info-bg: #142a47;
    --ingreso: #4cc24c; --egreso: #f08a8a;
    --row-hover: #20201e; --row-selected: #3a3110; --row-highlight: #142a47;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
    --serie-1: #3987e5; --serie-2: #d95926; --chart-grid: #2c2c2a; --chart-axis: #383835; --chart-muted: #9a988f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --border: #2f2f2c; --border-strong: #45453f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a988f;
  --nav-bg: #0a0a09; --nav-hover: #1f1f1c;
  --brand-soft: #3a3110;
  --primary: #f0efec; --primary-hover: #d9d8d2; --primary-ink: #121211;
  --focus: #5598e7; --link: #86b6ef;
  --ok: #4cc24c; --ok-bg: #12301a; --warn: #f5c451; --warn-bg: #3a2e0c;
  --danger: #f08a8a; --danger-bg: #3d1716; --info: #86b6ef; --info-bg: #142a47;
  --ingreso: #4cc24c; --egreso: #f08a8a;
  --row-hover: #20201e; --row-selected: #3a3110; --row-highlight: #142a47;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
  --serie-1: #3987e5; --serie-2: #d95926; --chart-grid: #2c2c2a; --chart-axis: #383835; --chart-muted: #9a988f;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* Tamaño por defecto de los íconos SVG (especificidad 0: cualquier regla de componente lo sustituye). */
:where(svg[focusable="false"]) { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.archivos-lista li > svg { width: 20px; height: 20px; color: var(--muted); }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: 0.9375rem; }
p { margin: 0 0 .75rem; }
a { color: var(--link); text-underline-offset: 2px; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }
.nowrap { white-space: nowrap; }
.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;
}

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

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: var(--radius-sm);
  font-weight: 600; text-decoration: none; transition: transform 160ms var(--ease-out);
}
.skip-link:focus { transform: translateY(60px); }

/* ---------- Barra de navegación superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--nav-h); background: var(--nav-bg); color: var(--nav-text);
  display: flex; align-items: center; gap: 4px; padding: 0 16px;
  border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: -0.02em;
}
.brand-name { font-weight: 700; letter-spacing: .02em; font-size: 15px; }
.brand-name small { display: block; font-weight: 500; font-size: 10.5px; color: var(--nav-muted); letter-spacing: .08em; }

.nav { display: flex; align-items: stretch; height: 100%; gap: 2px; margin: 0; padding: 0; list-style: none; }
.nav > li { position: relative; display: flex; }
.nav-link {
  display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 100%;
  color: var(--nav-text); text-decoration: none; font-size: 14px; font-weight: 500;
  background: none; border: 0; font-family: inherit; cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -3px;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.nav-link:hover { background: var(--nav-hover); }
.nav-link[aria-current="page"], .nav-link.activo { border-bottom-color: var(--brand); color: #fff; }
.nav-link svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.nav-link .chev { width: 12px; height: 12px; transition: transform 150ms var(--ease-out); }
.nav-link[aria-expanded="true"] .chev { transform: rotate(180deg); }

.menu {
  position: absolute; top: calc(100% + 3px); left: 0; min-width: 240px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
  transform-origin: top left;
  opacity: 0; transform: scale(.97) translateY(-4px); visibility: hidden;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out), visibility 0s linear 140ms;
}
.menu.derecha { left: auto; right: 0; transform-origin: top right; }
.menu.abierto { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
.menu-cols { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 4px; min-width: 480px; }
.menu-titulo { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 10px 4px; font-weight: 600; }
.menu a, .menu button.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 14px; background: none; border: 0; font-family: inherit;
  cursor: pointer; text-align: left;
}
.menu a:hover, .menu button.menu-item:hover { background: var(--surface-2); }
.menu a[aria-current="page"] { background: var(--brand-soft); font-weight: 600; }
.menu a svg, .menu button svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.topbar-spacer { flex: 1; }
.user-btn { gap: 8px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.menu-toggle { display: none; }

@media (max-width: 1000px) {
  .menu-toggle { display: flex; }
  .nav {
    position: fixed; inset: var(--nav-h) 0 auto 0; flex-direction: column; height: auto; max-height: calc(100dvh - var(--nav-h));
    overflow: auto; background: var(--nav-bg); padding: 8px; gap: 2px; border-bottom: 3px solid var(--brand);
    display: none;
  }
  .nav.abierto { display: flex; }
  .nav > li { flex-direction: column; }
  .nav-link { height: 44px; border-bottom: 0; margin: 0; border-radius: var(--radius-sm); }
  .nav-link[aria-current="page"] { background: var(--nav-hover); box-shadow: inset 3px 0 0 var(--brand); }
  .menu { position: static; box-shadow: none; min-width: 0; margin: 2px 0 6px 12px; transform: none; }
  .menu:not(.abierto) { display: none; }
  .menu-cols { grid-template-columns: 1fr; min-width: 0; }
  .brand-name small { display: none; }
}

/* ---------- Página ---------- */
.page { padding: 16px 20px 32px; max-width: 100%; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.breadcrumb a { color: inherit; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 0; }
.card-body { padding: 14px 16px 16px; }
.card-head .hint { font-size: 12.5px; color: var(--muted); }

.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; } .page { padding: 12px; } }

/* ---------- Botones ---------- */
.btn {
  --b-bg: var(--surface); --b-fg: var(--text); --b-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--b-bd);
  background: var(--b-bg); color: var(--b-fg); font: 500 14px/1 var(--font); cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none;
  transition: transform 140ms var(--ease-out), background-color 150ms ease, border-color 150ms ease;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { --b-bg: var(--primary); --b-fg: var(--primary-ink); --b-bd: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-brand { --b-bg: var(--brand); --b-fg: var(--brand-ink); --b-bd: var(--brand); font-weight: 600; }
.btn-brand:hover { background: #e0a900; }
.btn-danger { --b-bg: var(--surface); --b-fg: var(--danger); --b-bd: var(--border-strong); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { --b-bg: transparent; --b-bd: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; height: 32px; }
.btn-group { display: inline-flex; }
.btn-group .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.btn-group .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .req { color: var(--danger); margin-left: 2px; }
.input, select.input, textarea.input {
  height: 36px; width: 100%; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 14px var(--font); transition: border-color 150ms ease, box-shadow 150ms ease;
}
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
select.input { padding-right: 28px; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input[aria-invalid="true"], .input.input-validation-error { border-color: var(--danger); }
.input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.field-error, .field-validation-error { color: var(--danger); font-size: 12.5px; }
.field-hint { color: var(--muted); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; min-height: 32px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.form-grid > * { grid-column: span 12; }
.span-2 { grid-column: span 2 !important; } .span-3 { grid-column: span 3 !important; }
.span-4 { grid-column: span 4 !important; } .span-5 { grid-column: span 5 !important; }
.span-6 { grid-column: span 6 !important; } .span-8 { grid-column: span 8 !important; }
@media (max-width: 720px) { .form-grid > * { grid-column: span 12 !important; } }
fieldset.grupo { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; }
fieldset.grupo > legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }

/* ---------- Barra de filtros (una fila, encima de tablas/gráficas) ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.toolbar .field { min-width: 150px; }
.toolbar .field.w-lg { min-width: 260px; flex: 1 1 260px; }
.toolbar .grow { flex: 1; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 32px; }

/* Selector múltiple (checklist en popover) */
.multi { position: relative; }
.multi > button.input svg { width: 16px; height: 16px; flex: none; color: var(--muted); transition: transform 140ms var(--ease-out); }
.multi > button.input[aria-expanded="true"] svg { transform: rotate(180deg); }
.multi > button.input { text-align: left; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.multi > button.input span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; width: max(100%, 300px); max-height: 340px;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); transform-origin: top left;
  opacity: 0; transform: scale(.97); visibility: hidden;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out), visibility 0s linear 140ms;
}
.multi-panel.abierto { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
.multi-panel .multi-buscar { padding: 8px; border-bottom: 1px solid var(--border); }
.multi-panel .multi-lista { overflow: auto; padding: 4px; }
.multi-panel label { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border-radius: var(--radius-sm); font-size: 13.5px; cursor: pointer; }
.multi-panel label:hover { background: var(--surface-2); }
.multi-panel input { margin-top: 2px; accent-color: var(--primary); }
.multi-pie { display: flex; justify-content: space-between; padding: 6px 8px; border-top: 1px solid var(--border); }

/* Chips de filtros activos */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 10px; border-radius: 999px;
  background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent);
  font-size: 12.5px; color: var(--text);
}
.chip button { border: 0; background: none; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; color: var(--text-2); display: grid; place-items: center; }
.chip button:hover { background: rgba(0,0,0,.08); }

/* ---------- Tablas de datos ---------- */
.table-card { overflow: hidden; }
.table-wrap { overflow: auto; max-height: calc(100dvh - 300px); min-height: 200px; }
.table-wrap.alto-libre { max-height: none; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.data caption { text-align: left; padding: 0 0 8px; font-weight: 600; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-2);
  font-size: 12px; font-weight: 650; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border-strong);
}
table.data thead th.num { text-align: right; }
table.data th a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
table.data th a.sort:hover { color: var(--text); }
table.data th a.sort svg { width: 12px; height: 12px; opacity: .35; }
table.data th[aria-sort] a.sort svg { opacity: 1; color: var(--text); }
table.data tbody tr { transition: background-color 120ms ease; }
table.data tbody tr:hover { background: var(--row-hover); }
table.data tbody tr.seleccionada { background: var(--row-selected); }
table.data tbody tr.resaltada { background: var(--row-highlight); box-shadow: inset 3px 0 0 var(--focus); }
table.data tbody tr.inactiva > td:not(.col-acciones) { color: var(--muted); }
.archivos-lista { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.archivos-lista li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.archivos-lista li > div { flex: 1; min-width: 0; }
.archivos-lista .nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.permisos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
@media (max-width: 720px) { .permisos { grid-template-columns: 1fr; } }
.permisos label { align-items: flex-start; }
.permisos small { display: block; color: var(--muted); font-weight: 400; }
table.data td.desc { min-width: 260px; max-width: 520px; }
table.data td.desc .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
table.data .col-check { width: 36px; text-align: center; position: sticky; left: 0; background: inherit; }
table.data thead .col-check { z-index: 3; background: var(--surface-2); }
table.data .col-acciones { width: 1%; white-space: nowrap; text-align: right; }
table.data tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 650; border-top: 1px solid var(--border-strong); }
table.data input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
table.data th .th { display: inline-flex; align-items: center; gap: 2px; }
table.data th.num .th { justify-content: flex-end; width: 100%; }
.th-filtro {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 4px;
  background: none; color: var(--muted); cursor: pointer; opacity: .55; transition: opacity 120ms ease, background-color 120ms ease;
}
.th-filtro svg { width: 13px; height: 13px; }
th:hover .th-filtro, .th-filtro:focus-visible, .th-filtro[aria-expanded="true"] { opacity: 1; }
.th-filtro:hover { background: var(--surface-3); color: var(--text); }
.th-filtro.activo { opacity: 1; color: var(--brand-ink); background: var(--brand); }
@media (hover: none) { .th-filtro { opacity: 1; } }
.col-pop {
  position: absolute; z-index: 80; width: 300px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; max-height: 420px; font-size: 13.5px;
  animation: pop-in 140ms var(--ease-out);
}
@keyframes pop-in { from { opacity: 0; transform: scale(.97) translateY(-4px); } }
.col-pop .cp-head { padding: 10px 12px 0; }
.col-pop .cp-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: hidden; }
.col-pop .cp-lista { overflow: auto; max-height: 240px; margin: 0 -4px; }
.col-pop .cp-lista label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer; }
.col-pop .cp-lista label:hover { background: var(--surface-2); }
.col-pop .cp-lista input, .col-pop .check input { accent-color: var(--primary); margin-top: 2px; }
.col-pop .cp-pie { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.row-actions { display: inline-flex; gap: 2px; opacity: .55; transition: opacity 120ms ease; }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

.table-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2);
}
.pager { display: flex; align-items: center; gap: 4px; }
.pager .btn { min-width: 32px; }
.pager .actual { font-weight: 650; padding: 0 8px; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* Barra de acciones en lote (aparece al seleccionar filas) */
.bulkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--brand-soft); border-bottom: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  font-size: 13.5px;
}
.bulkbar strong { margin-right: 6px; }

/* ---------- Insignias de estado (siempre con texto, nunca sólo color) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge svg { width: 12px; height: 12px; }
.badge-ingreso { background: var(--ok-bg); color: var(--ingreso); }
.badge-egreso { background: var(--danger-bg); color: var(--egreso); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* Interruptor de estado revisado/autorizado dentro de la tabla */
.estado-toggle {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
  font: 600 12px var(--font); cursor: pointer; transition: transform 120ms var(--ease-out), background-color 150ms ease;
}
.estado-toggle svg { width: 12px; height: 12px; }
.estado-toggle:active { transform: scale(.95); }
.estado-toggle[aria-pressed="true"].rev { background: var(--info-bg); color: var(--info); border-color: transparent; }
.estado-toggle[aria-pressed="true"].aut { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.estado-toggle:disabled { cursor: default; }
.estado-toggle:disabled:active { transform: none; }

/* ---------- Indicadores (KPIs) ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 14px; box-shadow: var(--shadow-sm); min-width: 0; }
.kpi .kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .kpi-label .dot { width: 8px; height: 8px; border-radius: 50%; }
.kpi .kpi-value { font-size: 1.375rem; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { background: var(--nav-bg); color: #f0efec; border-color: var(--nav-bg); position: relative; overflow: hidden; }
.kpi.hero::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--brand); }
.kpi.hero .kpi-label { color: #c3c2b7; }
.kpi.hero .kpi-value { font-size: 2rem; }
.kpi.hero .kpi-sub { color: #a9a7a0; }
.delta { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); }
.kpi.hero .delta.up { color: #6fd36f; } .kpi.hero .delta.down { color: #f59a9a; }
.text-ingreso { color: var(--ingreso); } .text-egreso { color: var(--egreso); }

/* Medidor de presupuesto ejercido */
.meter { position: relative; height: 8px; border-radius: 999px; background: #dbe8fa; overflow: hidden; min-width: 80px; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: #2a78d6; }
.meter.warn > span { background: #fab219; } .meter.warn { background: #fdecc4; }
.meter.over > span { background: #d03b3b; } .meter.over { background: #f6d4d4; }
:root[data-theme="dark"] .meter { background: #1c3556; }

/* ---------- Diálogos ---------- */
dialog.modal {
  border: 0; padding: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); width: min(960px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  opacity: 1; transform: none;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out), overlay 180ms allow-discrete, display 180ms allow-discrete;
}
dialog.modal.sm { width: min(480px, calc(100vw - 24px)); }
dialog.modal[open] { display: flex; flex-direction: column; }
@starting-style { dialog.modal[open] { opacity: 0; transform: scale(.97) translateY(6px); } }
dialog.modal::backdrop { background: rgba(10, 10, 9, .45); transition: opacity 180ms ease; }
@starting-style { dialog.modal[open]::backdrop { opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ---------- Avisos ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; margin-bottom: 12px; border: 1px solid transparent; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-info { background: var(--info-bg); color: var(--info); }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; min-width: 280px; max-width: 420px;
  padding: 12px 14px; border-radius: var(--radius); background: var(--nav-bg); color: #f0efec; box-shadow: var(--shadow-lg);
  font-size: 14px; opacity: 1; transform: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
@starting-style { .toast { opacity: 0; transform: translateY(12px); } }
.toast.saliendo { opacity: 0; transform: translateY(8px); transition-duration: 150ms; }
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast.ok svg { color: #6fd36f; } .toast.error svg { color: #f59a9a; } .toast.warn svg { color: var(--brand); }

/* Indicador de carga de HTMX: barra fina bajo la navegación */
.carga {
  position: fixed; top: var(--nav-h); left: 0; right: 0; height: 2px; z-index: 60; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--brand), transparent); background-size: 40% 100%;
  background-repeat: no-repeat; opacity: 0; transition: opacity 150ms ease;
}
.htmx-request.carga, .htmx-request .carga { opacity: 1; animation: carga 900ms linear infinite; }
@keyframes carga { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.htmx-request .table-wrap, .htmx-request.table-wrap { opacity: .6; transition: opacity 120ms ease 150ms; }

/* ---------- Login ---------- */
.login-page { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.login-arte {
  background: var(--nav-bg); color: #f0efec; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-arte::before {
  content: ""; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(135deg, transparent 0 22px, rgba(242,183,5,.05) 22px 23px),
    radial-gradient(circle at 80% 20%, rgba(242,183,5,.18), transparent 45%);
}
.login-arte > * { position: relative; }
.login-arte h2 { font-size: 2rem; font-weight: 700; max-width: 14ch; line-height: 1.15; }
.login-arte p { color: #c3c2b7; max-width: 42ch; }
.login-arte .lema { letter-spacing: .3em; font-size: 12px; color: var(--brand); font-weight: 600; }
.login-form { display: grid; place-items: center; padding: 32px; }
.login-form form { width: min(380px, 100%); display: grid; gap: 14px; }
.login-form .logo { height: 64px; width: auto; margin-bottom: 8px; }
:root[data-theme="dark"] .login-form .logo { filter: invert(1) hue-rotate(180deg); }
.login-form .input { height: 42px; font-size: 15px; }
.login-form .btn { height: 42px; font-size: 15px; }
@media (max-width: 860px) { .login-page { grid-template-columns: 1fr; } .login-arte { display: none; } }

/* ---------- Dashboard ---------- */
.chart { width: 100%; height: 300px; }
.chart.alto { height: 360px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.vista-tabla table.data { font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); font: 500 12.5px var(--font); padding: 5px 10px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }
.seg button + button { border-left: 1px solid var(--border-strong); }
.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.sort-local { border: 0; background: none; font: inherit; color: inherit; cursor: pointer; padding: 0; }
.sort-local:hover { color: var(--text); text-decoration: underline; }
th[aria-sort="ascending"] .sort-local::after { content: " ▲"; font-size: 9px; }
th[aria-sort="descending"] .sort-local::after { content: " ▼"; font-size: 9px; }
@media (max-width: 1000px) { .nombre-usuario { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
  .htmx-request.carga, .htmx-request .carga { animation: none; }
}

@media print {
  .topbar, .toolbar, .page-actions, .table-foot, .bulkbar, .no-print, .col-check, .col-acciones { display: none !important; }
  .table-wrap { max-height: none; overflow: visible; }
  body { background: #fff; font-size: 11px; }
  .card { border: 0; box-shadow: none; }
}
@media (forced-colors: active) {
  .badge, .estado-toggle, .chip { border: 1px solid CanvasText; }
}

/* ---------- Dashboard: filtros en panel izquierdo + secciones ---------- */
.dash-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px; align-items: start; }
.panel-filtros {
  display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.panel-filtros .panel-titulo { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0 0 4px; }
.panel-filtros .presets { flex-wrap: wrap; }
.panel-filtros .fechas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel-filtros .fechas .input { padding-left: 8px; padding-right: 4px; }
.panel-filtros .multi-panel { width: max(100%, 320px); }
/* Fijo al desplazarse sólo si cabe en la pantalla (si no, el panel se recortaría). */
@media (min-height: 760px) { .panel-filtros { position: sticky; top: calc(var(--nav-h) + 12px); } }
@media (max-width: 1000px) { .dash-layout { grid-template-columns: 1fr; } .panel-filtros { position: static; } }
.seccion-titulo { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 10px; }
@media print { .panel-filtros { display: none; } .dash-layout { display: block; } }
