/* TesoreriApp — sistema de diseño "Confianza clara" (definido con el skill ui-ux-pro-max)
   Estructura en pizarra, verde = pagado / acción principal, ámbar = pendiente, rojo = vencido.
   Tema claro por defecto; oscuro con prefers-color-scheme o el selector de la cuenta (data-theme).
   Tipografía IBM Plex Sans servida localmente (CSP 'self' y uso sin conexión). Íconos SVG, nunca emoji.
   Reglas: contraste ≥ 4.5:1, foco visible, objetivos táctiles ≥ 44 px, respeta prefers-reduced-motion. */

@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url("/fonts/plex-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap; src: url("/fonts/plex-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url("/fonts/plex-600.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 700; font-display: swap; src: url("/fonts/plex-700.woff2") format("woff2"); }

:root {
  /* Primitivos */
  --slate-950: #020617; --slate-900: #0f172a; --slate-800: #1e293b; --slate-700: #334155; --slate-600: #475569;
  --slate-500: #64748b; --slate-400: #94a3b8; --slate-300: #cbd5e1; --slate-200: #e2e8f0; --slate-100: #f1f5f9; --slate-50: #f8fafc;
  --green-700: #15803d; --green-600: #16a34a; --green-100: #dcfce7; --green-50: #f0fdf4;
  --amber-700: #b45309; --amber-500: #f59e0b; --amber-100: #fef3c7;
  --red-700: #b91c1c; --red-600: #dc2626; --red-100: #fee2e2;
  --blue-700: #1d4ed8; --blue-100: #dbeafe;

  /* Semánticos */
  --bg: var(--slate-50);
  --surface: #ffffff;
  --surface-2: var(--slate-100);
  --line: var(--slate-200);
  --line-strong: var(--slate-300);
  --text: var(--slate-900);
  --muted: var(--slate-600);
  --chrome: var(--slate-900);
  --chrome-2: var(--slate-800);
  --chrome-text: var(--slate-300);
  --primary: var(--green-700);
  --primary-hover: #166534;
  --on-primary: #ffffff;
  --ok: var(--green-700);   --ok-bg: var(--green-100);
  --warn: var(--amber-700); --warn-bg: var(--amber-100);
  --bad: var(--red-700);    --bad-bg: var(--red-100);
  --info: var(--blue-700);  --info-bg: var(--blue-100);
  --chart-in: var(--green-600);
  --chart-out: var(--slate-400);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 1px 3px rgb(15 23 42 / 0.08);
  --focus: 0 0 0 3px color-mix(in srgb, var(--green-600) 45%, transparent);
  --t-fast: 150ms;
  --t: 220ms;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--slate-950); --surface: #0e1424; --surface-2: #151c2f; --line: #243045; --line-strong: var(--slate-700);
    --text: var(--slate-50); --muted: var(--slate-400); --chrome: #060b18; --chrome-2: #111a2d;
    --primary: var(--green-600); --primary-hover: #22c55e; --on-primary: #04130a;
    --ok: #4ade80; --ok-bg: #0f2a1a; --warn: #fbbf24; --warn-bg: #2d2208; --bad: #f87171; --bad-bg: #3a1414;
    --info: #93c5fd; --info-bg: #172554; --chart-out: var(--slate-600);
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--slate-950); --surface: #0e1424; --surface-2: #151c2f; --line: #243045; --line-strong: var(--slate-700);
  --text: var(--slate-50); --muted: var(--slate-400); --chrome: #060b18; --chrome-2: #111a2d;
  --primary: var(--green-600); --primary-hover: #22c55e; --on-primary: #04130a;
  --ok: #4ade80; --ok-bg: #0f2a1a; --warn: #fbbf24; --warn-bg: #2d2208; --bad: #f87171; --bad-bg: #3a1414;
  --info: #93c5fd; --info-bg: #172554; --chart-out: var(--slate-600);
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-variant-numeric: tabular-nums; overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.12rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-underline-offset: 2px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: grid; gap: 16px; }
.stack.tight { gap: 8px; }

/* ---------- Botones y campos ---------- */
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; text-decoration: none;
  transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, transform var(--t-fast) ease;
}
.icon { width: 20px; height: 20px; flex: none; }
.list-row .row .icon { color: var(--primary); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn.icon { padding: 8px; min-width: 44px; }
.btn.block { width: 100%; }
.btn.lg { min-height: 54px; font-size: 1.05rem; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.field small { color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.error-text { color: var(--bad); font-weight: 600; font-size: 0.92rem; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; margin-top: 1px; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); min-height: 38px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; background: var(--chrome); color: var(--chrome-text);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 2px; z-index: 5; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; font-size: 1.1rem; padding: 4px 8px 14px; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.course-switch {
  width: 100%; text-align: left; background: var(--chrome-2); color: #fff; border: 1px solid #ffffff1f; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px; cursor: pointer; display: grid; gap: 1px; min-height: 52px;
}
.course-switch small { color: var(--slate-400); font-size: 0.8rem; }
.course-switch strong { font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--chrome-text);
  text-decoration: none; font-weight: 500; min-height: 44px; transition: background-color var(--t-fast) ease;
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
.nav-link:hover { background: var(--chrome-2); color: #fff; }
.nav-link[aria-current="page"] { background: var(--green-700); color: #fff; }
.nav-link .count { margin-left: auto; background: var(--amber-500); color: var(--slate-900); border-radius: 999px; padding: 0 8px; font-size: 0.78rem; font-weight: 700; }
.sidebar .sep { height: 1px; background: #ffffff1a; margin: 8px 6px; }
.sidebar .user { margin-top: auto; padding: 12px; border-top: 1px solid #ffffff1a; font-size: 0.875rem; color: var(--slate-400); }
.sidebar .user strong { display: block; color: #fff; font-weight: 600; }

.main { margin-left: 248px; padding: 28px 32px 64px; max-width: 1240px; }
.topbar { display: none; }
.bottom-nav { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card > h2, .card > .card-head { margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 16px 18px 0; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 4; background: var(--chrome); color: #fff;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px; min-height: 56px;
  }
  .topbar .brand { padding: 0; font-size: 1rem; }
  .topbar .course-switch { margin: 0 0 0 auto; width: auto; max-width: 58vw; min-height: 44px; padding: 6px 10px; }
  .topbar .course-switch strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 6;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button {
    position: relative; display: grid; justify-items: center; align-content: center; gap: 2px; padding: 6px 2px; min-height: var(--nav-h);
    border: 0; background: transparent; color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600; cursor: pointer;
  }
  .bottom-nav svg { width: 24px; height: 24px; }
  .bottom-nav [aria-current="page"] { color: var(--primary); }
  .bottom-nav [aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
  .bottom-nav .count { position: absolute; top: 6px; left: 54%; background: var(--amber-500); color: var(--slate-900); border-radius: 999px; padding: 0 6px; font-size: 0.7rem; font-weight: 700; }
  .form-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
}

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-weight: 500; font-size: 0.875rem; }
.kpi .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0; }
.kpi .hint { color: var(--muted); font-size: 0.85rem; }
.kpi.hero { background: var(--chrome); color: #fff; border-color: var(--chrome); }
.kpi.hero .label, .kpi.hero .hint { color: var(--slate-300); }
.kpi.alert .value { color: var(--bad); }
.kpi.good .value { color: var(--ok); }
a.kpi { text-decoration: none; color: inherit; display: block; transition: border-color var(--t-fast) ease; }
a.kpi:hover { border-color: var(--line-strong); }

.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--chart-in); border-radius: 999px; }
.kpi.hero .progress { background: #ffffff26; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 899px) { .grid-2, .grid-2.even { grid-template-columns: 1fr; } }

/* ---------- Avisos dentro de la página ---------- */
.callout { display: flex; gap: 12px; align-items: flex-start; border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); }
.callout svg { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.callout.warn { background: var(--warn-bg); border-color: transparent; }
.callout.warn svg { color: var(--warn); }
.callout.info { background: var(--info-bg); border-color: transparent; }
.callout.info svg { color: var(--info); }
.callout.ok { background: var(--ok-bg); border-color: transparent; }
.callout.ok svg { color: var(--ok); }
.callout.bad { background: var(--bad-bg); border-color: transparent; }
.callout.bad svg { color: var(--bad); }
.callout .grow > strong { display: block; }

/* ---------- Gráficos ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .in { fill: var(--chart-in); }
.chart .out { fill: var(--chart-out); }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 12px; font-family: inherit; }
.legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbars { display: grid; gap: 12px; }
.hbar .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 0.92rem; margin-bottom: 4px; }
.hbar .meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--chart-in); border-radius: 4px; }
.hbar .fill.out { background: var(--chart-out); }

/* ---------- Listas ---------- */
.list { display: grid; }
.list-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 13px 18px;
  border: 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: transparent; color: inherit;
  text-decoration: none; min-height: 56px;
}
.list-row:last-child { border-bottom: 0; }
button.list-row, a.list-row { cursor: pointer; transition: background-color var(--t-fast) ease; }
button.list-row:hover, a.list-row:hover { background: var(--surface-2); }
.list-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list-row .sub { color: var(--muted); font-size: 0.875rem; }
.list-row .end { text-align: right; display: grid; justify-items: end; gap: 4px; }
.card:not(.flush) .list-row { padding-left: 2px; padding-right: 2px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; line-height: 1.6;
}
.badge svg { width: 14px; height: 14px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.strike { text-decoration: line-through; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar .input { width: auto; flex: 1 1 200px; }
.toolbar select.input { flex: 0 1 200px; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; display: grid; justify-items: center; gap: 6px; }
.empty svg { width: 40px; height: 40px; color: var(--slate-400); }
.empty strong { color: var(--text); font-size: 1.05rem; }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 0.95rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- Matriz de cuotas ---------- */
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.9rem; }
.matrix th, .matrix td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.matrix th { font-weight: 600; color: var(--muted); font-size: 0.8rem; position: sticky; top: 0; background: var(--surface); }
.matrix .name { text-align: left; position: sticky; left: 0; background: var(--surface); font-weight: 600; min-width: 150px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.matrix tfoot td { font-weight: 600; color: var(--muted); font-size: 0.8rem; }
.cell { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 0; cursor: pointer; font-weight: 700; font-size: 0.75rem; }
.cell svg { width: 18px; height: 18px; }
.cell.paid { background: var(--ok-bg); color: var(--ok); }
.cell.partial { background: var(--warn-bg); color: var(--warn); }
.cell.pending { background: var(--surface-2); color: var(--muted); }
.cell.overdue { background: var(--bad-bg); color: var(--bad); }
.cell.none { background: transparent; cursor: default; }

/* ---------- Estado de cuenta (apoderado) ---------- */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.month { border-radius: 10px; padding: 10px; border: 1px solid var(--line); display: grid; gap: 2px; font-size: 0.85rem; }
.month strong { font-size: 0.95rem; }
.month.paid { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.month.partial { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.month.overdue { background: var(--bad-bg); border-color: transparent; color: var(--bad); }
.month.pending { color: var(--muted); }

/* ---------- Subida de comprobantes ---------- */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 16px; text-align: center; display: grid; gap: 10px;
  justify-items: center; background: var(--surface); transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.dropzone.over { border-color: var(--primary); background: var(--ok-bg); }
.dropzone svg { width: 44px; height: 44px; color: var(--primary); }
.upload-item { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.upload-item:last-child { border-bottom: 0; }
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 0.75rem; font-weight: 700; }

/* ---------- Revisión ---------- */
.review { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 18px; }
@media (max-width: 899px) { .review { grid-template-columns: 1fr; } }
.receipt-view { background: var(--surface-2); border-radius: 10px; min-height: 220px; display: grid; place-items: center; overflow: hidden; }
.receipt-view img { max-width: 100%; max-height: 70dvh; display: block; }
.receipt-view iframe { width: 100%; height: 60dvh; border: 0; background: #fff; }
.confidence { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.alloc-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 120px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.alloc-row .input { min-height: 40px; text-align: right; }
/* Comprobantes anteriores del apoderado */
.history { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.history-item { display: grid; gap: 4px; justify-items: start; text-align: left; padding: 8px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: inherit; font: inherit; cursor: pointer; }
.history-item:hover { border-color: var(--primary); }
.history-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.history-item:disabled { cursor: default; opacity: .7; }
.history-img { width: 100%; aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.history-img img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.history-img svg { width: 28px; height: 28px; }

/* ---------- Modal / hoja inferior ---------- */
dialog {
  border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text);
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 24px 64px rgb(2 6 23 / 0.35);
}
dialog::backdrop { background: rgb(2 6 23 / 0.55); }
dialog[open] { display: flex; flex-direction: column; animation: dlg-in var(--t) ease-out; }
dialog.wide { width: min(980px, calc(100vw - 24px)); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(12px); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 10px; }
.dlg-body { padding: 4px 18px 18px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 899px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 94dvh; }
  dialog.wide { width: 100vw; }
  .dlg-foot .btn { flex: 1 1 auto; }
}

/* ---------- Toasts ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast { background: var(--slate-900); color: #fff; padding: 12px 16px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgb(2 6 23 / 0.3); border-left: 5px solid var(--slate-400); animation: toast-in var(--t) ease-out; }
.toast.error { border-left-color: #f87171; }
.toast.ok { border-left-color: #4ade80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Acceso ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--chrome);
  background-image: radial-gradient(circle at 20% 10%, rgb(22 163 74 / 0.18), transparent 45%), radial-gradient(circle at 90% 90%, rgb(148 163 184 / 0.12), transparent 40%); }
.login-card { width: min(420px, 100%); background: var(--surface); border-radius: 16px; padding: 28px 24px; display: grid; gap: 16px; box-shadow: 0 24px 64px rgb(2 6 23 / 0.4); }
.login-card .brand { color: var(--text); padding: 0; font-size: 1.3rem; }
.login-card .brand-mark { width: 42px; height: 42px; }

/* ---------- Rendición imprimible ---------- */
.report-head { display: grid; gap: 2px; }
.ledger { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.ledger th, .ledger td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.ledger th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.ledger td.num, .ledger th.num { text-align: right; }
.ledger tfoot td { font-weight: 700; border-bottom: 0; }
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --line: #ccc; --shadow: none; color-scheme: light; }
  body { background: #fff; font-size: 11pt; }
  .sidebar, .topbar, .bottom-nav, #toasts, .no-print, .page-head .actions { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  .card { border: 0; padding: 0; break-inside: avoid; margin-bottom: 14px; }
  .print-only { display: block; }
  a { color: #000; text-decoration: none; }
}

/* ---------- Varios ---------- */
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-box { display: flex; gap: 8px; }
.link-box .input { font-size: 0.85rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; min-height: 44px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); }

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