/* ─────────────────────────────────────────────────────────────
   Design tokens — Presupuesto
   Off-white cálido + azul Apple (#5e9eff) + SF Pro
   ───────────────────────────────────────────────────────────── */
:root {
  /* ── Surfaces (off-white cálido) ─────────────────────────── */
  --bg:           #f7f5ef;          /* canvas — un toque crema */
  --bg-elev:      #fdfcf8;          /* sidebar / topbar */
  --panel:        #ffffff;          /* cards */
  --panel-2:      #f3f0e8;          /* nested / hover row */
  --panel-3:      #ece8de;          /* deeper nested */

  /* ── Borders (hairlines, casi imperceptibles) ────────────── */
  --hairline:     rgba(20, 18, 12, 0.08);
  --hairline-2:   rgba(20, 18, 12, 0.05);
  --border:       rgba(20, 18, 12, 0.12);
  --border-strong: rgba(20, 18, 12, 0.22);

  /* ── Text ────────────────────────────────────────────────── */
  --text:         #1a1814;
  --text-2:       #3c3a33;
  --muted:        #76726a;
  --muted-2:      #a9a59b;
  --on-accent:    #ffffff;

  /* ── Accent (azul claro Apple-ish) ───────────────────────── */
  --accent:       #5e9eff;
  --accent-600:   #3d85ee;
  --accent-700:   #2a6ed1;
  --accent-soft:  rgba(94, 158, 255, 0.12);
  --accent-soft-2: rgba(94, 158, 255, 0.20);

  /* ── Semantics (calibrados para fondo claro) ─────────────── */
  --success:      #1f9f5a;
  --success-soft: rgba(31, 159, 90, 0.12);
  --warn:         #c98a16;
  --warn-soft:    rgba(201, 138, 22, 0.14);
  --danger:       #d4453a;
  --danger-soft:  rgba(212, 69, 58, 0.12);

  /* ── Espaciado (múltiplos de 4) ──────────────────────────── */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  32px;
  --space-8:  40px;
  --space-9:  56px;
  --space-10: 72px;

  /* ── Tipografía ──────────────────────────────────────────── */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Helvetica Neue", "Inter", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;

  --fs-micro:   11px;
  --fs-small:   12px;
  --fs-body:    13.5px;
  --fs-h3:      15px;
  --fs-h2:      19px;
  --fs-h1:      24px;
  --fs-display: 34px;

  --lh-tight:   1.15;
  --lh-base:    1.45;

  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semi:    600;
  --fw-bold:    700;

  /* ── Radii (suaves, Apple) ───────────────────────────────── */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* ── Shadows (muy sutiles) ───────────────────────────────── */
  --shadow-1: 0 1px 1px rgba(20, 18, 12, 0.04),
              0 1px 2px rgba(20, 18, 12, 0.04);
  --shadow-2: 0 1px 1px rgba(20, 18, 12, 0.04),
              0 4px 12px rgba(20, 18, 12, 0.06);
  --shadow-3: 0 8px 24px rgba(20, 18, 12, 0.10),
              0 2px 6px rgba(20, 18, 12, 0.06);
  --shadow-modal: 0 30px 80px rgba(20, 18, 12, 0.25),
                  0 8px 24px rgba(20, 18, 12, 0.12);
  --ring: 0 0 0 3px var(--accent-soft);

  /* ── Layout ──────────────────────────────────────────────── */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;

  /* ── Animation ───────────────────────────────────────────── */
  --ease: cubic-bezier(.32, .72, 0, 1);
  --t-fast: 120ms;
  --t-base: 180ms;
}

/* ── Density modifiers (driven by Tweaks) ───────────────────── */
[data-density="compact"] {
  --row-h: 32px;
  --pad-card: 14px;
  --pad-cell: 8px 10px;
  --fs-body: 13px;
}
[data-density="balanced"] {
  --row-h: 40px;
  --pad-card: 18px;
  --pad-cell: 10px 14px;
}
[data-density="comfy"] {
  --row-h: 48px;
  --pad-card: 24px;
  --pad-cell: 14px 16px;
  --fs-body: 14px;
}

/* ── Background variants ─────────────────────────────────────── */
[data-bg="warm"]    { --bg: #f7f5ef; --bg-elev: #fdfcf8; --panel-2: #f3f0e8; }
[data-bg="cool"]    { --bg: #f3f5f8; --bg-elev: #fbfcfd; --panel-2: #eaeef3; }
[data-bg="neutral"] { --bg: #f5f5f5; --bg-elev: #fcfcfc; --panel-2: #ededed; }
[data-bg="white"]   { --bg: #fbfaf6; --bg-elev: #ffffff; --panel-2: #f3f0e8; }
/* ─────────────────────────────────────────────────────────────
   Base + components
   ───────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
  letter-spacing: -0.005em;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }

::selection { background: var(--accent-soft-2); }

/* numeric tabular */
.tnum, .num { font-variant-numeric: tabular-nums; }

/* ───────────────── Layout shell ───────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  background: var(--bg);
  overflow: hidden;
}
.app[data-nav="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
.app[data-nav="topbar"]    { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) 1fr; }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ───────────────── Sidebar ───────────────── */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  display: grid; place-items: center;
  color: white; font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.04em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 1px 2px rgba(20,18,12,.15);
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.brand-sub {
  font-size: var(--fs-micro);
  color: var(--muted);
  margin-top: 1px;
}

.sidebar-section {
  padding: var(--space-3) var(--space-3);
  border-top: 1px solid var(--hairline-2);
}
.sidebar-section:first-of-type { border-top: 0; }
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  padding: var(--space-2) var(--space-3) var(--space-2);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 7px var(--space-3);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: var(--fs-body);
  font-weight: 450;
  user-select: none;
  position: relative;
  transition: background var(--t-fast) var(--ease);
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active {
  background: var(--panel);
  color: var(--text);
  font-weight: 550;
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
}
.nav-item svg { flex: 0 0 18px; color: var(--muted); }
.nav-item.active svg { color: var(--accent-600); }
.nav-item .nav-count {
  margin-left: auto;
  font-size: var(--fs-micro);
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.app[data-nav="collapsed"] .nav-label,
.app[data-nav="collapsed"] .brand-text,
.app[data-nav="collapsed"] .sidebar-label,
.app[data-nav="collapsed"] .nav-count,
.app[data-nav="collapsed"] .sidebar-period { display: none; }
.app[data-nav="collapsed"] .nav-item { justify-content: center; padding: 8px 0; }
.app[data-nav="collapsed"] .sidebar-brand { justify-content: center; padding: var(--space-5) 0 var(--space-4); }
.app[data-nav="collapsed"] .sidebar-period-card { display: none; }

.sidebar-foot {
  margin-top: auto;
  padding: var(--space-3);
  border-top: 1px solid var(--hairline-2);
}
.sidebar-period-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--r-md);
  background: var(--panel);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
}
.sidebar-period {
  flex: 1;
  min-width: 0;
}
.sidebar-period .label {
  font-size: var(--fs-micro);
  color: var(--muted);
}
.sidebar-period .value {
  font-size: var(--fs-body);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ───────────────── Topbar ───────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-5);
  position: relative;
  z-index: 10;
}
.topbar .brand-mark { width: 26px; height: 26px; font-size: 13px; }
.topbar-nav {
  display: flex;
  gap: 2px;
  align-items: center;
}
.topbar-nav .nav-item { padding: 6px var(--space-3); }
.topbar .spacer { flex: 1; }
.topbar-period {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-small);
  color: var(--muted);
}

/* ───────────────── Page header ───────────────── */
.page-head {
  padding: var(--space-7) var(--space-8) var(--space-5);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
}
.page-title {
  font-size: var(--fs-display);
  line-height: var(--lh-tight);
  letter-spacing: -0.025em;
  font-weight: 600;
  margin: 0 0 var(--space-1);
}
.page-sub {
  color: var(--muted);
  font-size: var(--fs-h3);
  letter-spacing: -0.01em;
  margin: 0;
}
.page-actions { display: flex; gap: var(--space-2); align-items: center; }

.page-body {
  padding: 0 var(--space-8) var(--space-8);
  overflow-y: auto;
  flex: 1;
  scroll-behavior: smooth;
}

/* ───────────────── Buttons ───────────────── */
.btn {
  appearance: none;
  border: 0;
  background: var(--text);
  color: var(--bg-elev);
  height: 34px;
  padding: 0 var(--space-4);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  font-weight: 550;
  letter-spacing: -0.005em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: filter var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { filter: brightness(0.95); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: white;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 1px 2px rgba(20,18,12,.08);
}
.btn.primary:hover { background: var(--accent-600); filter: none; }
.btn.secondary {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 0 0 0.5px var(--border), var(--shadow-1);
}
.btn.secondary:hover { background: var(--panel-2); filter: none; }
.btn.ghost {
  background: transparent;
  color: var(--text-2);
  box-shadow: none;
}
.btn.ghost:hover { background: var(--panel-2); filter: none; }
.btn.danger { background: var(--danger); color: white; }
.btn.danger:hover { background: #b53a31; filter: none; }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--fs-small); }
.btn.icon { width: 32px; padding: 0; }
.btn.icon.sm { width: 28px; }

/* ───────────────── Inputs ───────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: var(--fs-small);
  color: var(--muted);
  font-weight: 500;
}
.input, .select, .textarea {
  appearance: none;
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3);
  background: var(--panel);
  border: 0;
  border-radius: var(--r-md);
  box-shadow: 0 0 0 0.5px var(--border);
  color: var(--text);
  font-size: var(--fs-body);
  transition: box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.input:hover, .select:hover { box-shadow: 0 0 0 0.5px var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft);
  background: var(--bg-elev);
}
.input.saved {
  background: var(--success-soft);
  box-shadow: 0 0 0 1px var(--success);
  animation: savedFade 1.2s ease;
}
@keyframes savedFade {
  0% { background: var(--success-soft); }
  100% { background: var(--panel); box-shadow: 0 0 0 0.5px var(--border); }
}
.input.error {
  box-shadow: 0 0 0 1px var(--danger), 0 0 0 4px var(--danger-soft);
}
.textarea { height: auto; padding: var(--space-3); min-height: 80px; resize: vertical; }
.input-group { position: relative; }
.input-group .input { padding-left: 32px; }
.input-prefix { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='rgba(20,18,12,.5)' d='M0 0h10L5 6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

/* ───────────────── Card ───────────────── */
.card {
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  padding: var(--pad-card, 18px);
}
.card.flush { padding: 0; overflow: hidden; }
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--hairline-2);
}
.card-h h3 {
  margin: 0;
  font-size: var(--fs-h3);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.card-h .sub { color: var(--muted); font-size: var(--fs-small); margin-top: 2px;}

/* ───────────────── KPI ───────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: 1fr 1fr; } }

.kpi {
  background: var(--panel);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
}
.kpi.hero {
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  color: white;
  box-shadow: 0 0 0 0.5px rgba(0,0,0,.06), 0 12px 32px -8px var(--accent-soft-2);
}
.kpi-label {
  font-size: var(--fs-small);
  color: var(--muted);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.kpi.hero .kpi-label { color: rgba(255,255,255,.85); }
.kpi-value {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.kpi.hero .kpi-value { font-size: 38px; }
.kpi-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-small);
  color: var(--muted);
}
.kpi.hero .kpi-foot { color: rgba(255,255,255,.85); }

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: var(--r-pill);
  font-size: var(--fs-micro);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}
.kpi-trend.up { background: var(--success-soft); color: var(--success); }
.kpi-trend.down { background: var(--danger-soft); color: var(--danger); }
.kpi-trend.flat { background: var(--panel-2); color: var(--muted); }

/* hero KPI progress arc */
.kpi-bar {
  margin-top: var(--space-2);
  height: 6px;
  background: rgba(255,255,255,.25);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.kpi-bar > i { display: block; height: 100%; background: white; border-radius: inherit; }

/* ───────────────── Progress ───────────────── */
.progress {
  position: relative;
  height: 6px;
  width: 100%;
  background: var(--panel-2);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--t-base) var(--ease);
}
.progress.good > i { background: var(--success); }
.progress.warn > i { background: var(--warn); }
.progress.bad  > i { background: var(--danger); }
.progress.tall { height: 8px; }

/* ───────────────── Badge ───────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: var(--fs-micro);
  font-weight: 550;
  background: var(--panel-2);
  color: var(--text-2);
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent-700); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.dot::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.outline { background: transparent; box-shadow: 0 0 0 0.5px var(--border); }

/* ───────────────── Table ───────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
}
.table th {
  text-align: left;
  font-weight: 550;
  font-size: var(--fs-small);
  color: var(--muted);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  letter-spacing: -0.005em;
  background: var(--panel);
  position: sticky; top: 0; z-index: 1;
}
.table td {
  padding: var(--pad-cell, 10px 14px);
  border-bottom: 1px solid var(--hairline-2);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tr.row:hover td { background: var(--panel-2); }
.table tr.expanded td { background: var(--panel-2); }
.table .num { text-align: right; }
.table .right { text-align: right; }
.table .center { text-align: center; }

.expander {
  appearance: none;
  border: 0;
  background: transparent;
  width: 20px; height: 20px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--muted);
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.expander:hover { background: var(--panel-2); color: var(--text); }
.expander.open { transform: rotate(90deg); color: var(--text); }

.cat-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.cat-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--panel-2);
  color: var(--text-2);
  flex-shrink: 0;
}
.cat-icon.tinted { background: var(--accent-soft); color: var(--accent-700); }
.cat-name { font-weight: 500; }
.cat-sub { font-size: var(--fs-small); color: var(--muted); }

/* sub-rows */
.subrow td { padding-left: var(--space-7); background: var(--panel-2); }
.subrow td:first-child { padding-left: var(--space-9); }
.subrow .cat-name { font-weight: 450; color: var(--text-2); }

/* ───────────────── Modal ───────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: var(--space-6);
  animation: fadeIn .18s var(--ease);
}
.modal {
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: pop .22s var(--ease);
}
.modal.lg { max-width: 720px; }
.modal-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--hairline-2);
}
.modal-h h2 { margin: 0; font-size: var(--fs-h2); font-weight: 600; letter-spacing: -0.015em; }
.modal-h .sub { color: var(--muted); font-size: var(--fs-small); margin-top: 2px; }
.modal-body { padding: var(--space-5) var(--space-6); }
.modal-foot {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--hairline-2);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  background: var(--bg);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(8px); } to { opacity: 1; transform: scale(1); } }

.icon-btn {
  appearance: none;
  border: 0; background: transparent;
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ───────────────── Empty / loading / toast ───────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-9) var(--space-6);
  gap: var(--space-3);
  color: var(--muted);
}
.empty-art {
  width: 88px; height: 88px;
  border-radius: 22px;
  background: var(--panel-2);
  color: var(--muted);
  display: grid; place-items: center;
  margin-bottom: var(--space-2);
}
.empty h3 { margin: 0; font-size: var(--fs-h2); color: var(--text); font-weight: 600; letter-spacing: -0.015em; }
.empty p { margin: 0; max-width: 36ch; }

.skel { background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-3) 50%, var(--panel-2) 100%); background-size: 200% 100%; border-radius: var(--r-sm); animation: shimmer 1.6s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.toast-stack {
  position: fixed; right: var(--space-5); top: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 200;
}
.toast {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: 10px 12px 10px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-3);
  min-width: 280px; max-width: 360px;
  animation: slide .22s var(--ease);
  font-size: var(--fs-body);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.saving-pill {
  position: fixed; bottom: var(--space-6); left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 8px 14px 8px 12px;
  border-radius: var(--r-pill);
  font-size: var(--fs-small);
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-3);
  z-index: 90;
  animation: pop .18s var(--ease);
}

/* ───────────────── Spinner ───────────────── */
.spinner {
  width: 14px; height: 14px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .9s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────── Misc ───────────────── */
hr.div { border: 0; height: 1px; background: var(--hairline-2); margin: var(--space-4) 0; }
.row { display: flex; gap: var(--space-3); align-items: center; }
.col { display: flex; flex-direction: column; gap: var(--space-2); }
.grow { flex: 1; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.amount-pos { color: var(--success); }
.amount-neg { color: var(--text); }
.over { color: var(--danger); font-weight: 600; }

/* segment / tab control */
.seg {
  display: inline-flex;
  background: var(--panel-2);
  padding: 3px;
  border-radius: var(--r-md);
  gap: 2px;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 5px 12px;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
}
.seg button.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
}

/* category cards layout (alt mensual) */
.cat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-4);
}
.cat-card {
  background: var(--panel);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.cat-card:hover { transform: translateY(-1px); box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-2); }
.cat-card-h { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.cat-card-h .name { font-weight: 600; letter-spacing: -0.005em; flex: 1; }
.cat-card-h .pct { font-size: var(--fs-small); color: var(--muted); font-variant-numeric: tabular-nums; }
.cat-card-amounts { display: flex; align-items: baseline; justify-content: space-between; margin-top: var(--space-3); }
.cat-card-amounts .spent { font-size: var(--fs-h2); font-weight: 600; letter-spacing: -0.02em; }
.cat-card-amounts .total { font-size: var(--fs-small); color: var(--muted); }

/* split view */
.split {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--space-4);
  align-items: start;
}
.split-list {
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  overflow: hidden;
}
.split-list-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--hairline-2);
  transition: background var(--t-fast) var(--ease);
}
.split-list-item:last-child { border-bottom: 0; }
.split-list-item:hover { background: var(--panel-2); }
.split-list-item.active { background: var(--accent-soft); }
.split-list-item.active .name { color: var(--accent-700); font-weight: 600; }
.split-list-item .meta { font-size: var(--fs-small); color: var(--muted); margin-left: auto; }

/* dashboard hero chart */
.hero-chart {
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-2);
  padding: var(--space-5);
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-5);
}
.hero-chart .stats { display: flex; flex-direction: column; gap: var(--space-3); }
.hero-chart .stat { padding: var(--space-3) 0; border-bottom: 1px solid var(--hairline-2); }
.hero-chart .stat:last-child { border-bottom: 0; }
.hero-chart .stat .label { font-size: var(--fs-small); color: var(--muted); }
.hero-chart .stat .value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.hero-chart canvas, .hero-chart .chart-area { min-height: 280px; }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.chart-card {
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  padding: var(--space-4) var(--space-5);
}
.chart-card h4 {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-h3);
  font-weight: 600;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.chart-card .sub { color: var(--muted); font-size: var(--fs-small); margin-left: auto; font-weight: 400; }
.chart-area { width: 100%; height: 220px; position: relative; }

/* tags row */
.tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* filter bar */
.filterbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--panel);
  border-radius: var(--r-md);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  margin-bottom: var(--space-4);
}
.filterbar .input { height: 30px; box-shadow: none; background: transparent; }
.filterbar .input:focus { background: var(--panel-2); box-shadow: none; }

/* upload dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-9) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  background: var(--panel);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .ico {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-700);
  display: grid; place-items: center;
}

/* ───────────────── Adiciones del proyecto ───────────────── */

/* Reset link */
a { color: inherit; text-decoration: none; }
a.nav-item { text-decoration: none; }
a.text-link { color: var(--accent-700); }
a.text-link:hover { text-decoration: underline; }

/* Form grid (transacción manual) */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}

/* Login layout */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: var(--space-6);
}
.auth-card {
  background: var(--panel);
  border-radius: var(--r-xl);
  padding: var(--space-7);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-2);
}
.auth-card h1 {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-h1);
  font-weight: 600;
  letter-spacing: -0.025em;
}
.auth-card .sub {
  color: var(--muted);
  font-size: var(--fs-body);
  margin: 0 0 var(--space-6);
}
.auth-card .field { margin-bottom: var(--space-4); }
.auth-card .btn { width: 100%; margin-top: var(--space-2); }

/* Period switcher (segmented + arrows) */
.period-switcher {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--panel);
  border-radius: var(--r-md);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  padding: 3px;
}
.period-switcher .icon-btn { width: 28px; height: 28px; border-radius: var(--r-sm); }
.period-switcher .select {
  height: 28px;
  background: transparent;
  box-shadow: none;
  padding-left: var(--space-3);
  font-size: var(--fs-body);
  font-weight: 550;
  text-transform: capitalize;
  min-width: 180px;
}
.period-switcher .select:hover, .period-switcher .select:focus { background: var(--panel-2); box-shadow: none; }

/* Totals row in budget editor */
.totals-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
@media (max-width: 800px) { .totals-bar { grid-template-columns: 1fr; } }

/* Budget cell input */
.budget-cell {
  width: 100%;
  max-width: 140px;
  height: 32px;
  background: transparent;
  border: 0;
  box-shadow: 0 0 0 0.5px transparent;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 0 var(--space-2);
  transition: box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.budget-cell:hover { box-shadow: 0 0 0 0.5px var(--border); background: var(--bg-elev); }
.budget-cell:focus { outline: none; box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft); background: var(--bg-elev); }
.budget-cell.saved { background: var(--success-soft); box-shadow: 0 0 0 1px var(--success); animation: savedFade 1.2s ease; }
.budget-cell.error { box-shadow: 0 0 0 1px var(--danger), 0 0 0 4px var(--danger-soft); }

/* Tx-count chip */
.tx-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  background: var(--panel-2);
  color: var(--muted);
  border-radius: var(--r-pill);
  font-size: 10px;
  font-weight: 600;
}

/* Inline tx table inside expanded row */
.tx-inline {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
.tx-inline th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 6px var(--space-3);
  background: var(--panel-3);
}
.tx-inline th.num { text-align: right; }
.tx-inline td { padding: 6px var(--space-3); border-bottom: 1px solid var(--hairline-2); }
.tx-inline tr:last-child td { border-bottom: 0; }
.tx-inline .num { text-align: right; }

/* Hide-empty toggle */
.row-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  font-size: var(--fs-small);
}
.toggle-label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; color: var(--muted); }
.toggle-label input { accent-color: var(--accent); }

.empty-row { display: none; }
.empty-row.show { display: table-row; }

/* Sticky col helper for annual budget */
.sticky-col {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 1;
}
.scroll-x { overflow-x: auto; }

/* Helpers */
.flex { display: flex; }
.flex.gap-2 { gap: var(--space-2); }
.flex.gap-3 { gap: var(--space-3); }
.flex.center { align-items: center; }
.flex.between { justify-content: space-between; }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--muted); }

/* Apply-to-all mini button (budget) */
.btn-mini {
  appearance: none;
  border: 0;
  background: var(--panel-2);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  font-size: var(--fs-micro);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn-mini:hover { background: var(--bg); color: var(--text); }
.btn-mini.applied { background: var(--success-soft); color: var(--success); }

/* Status badge for subcategories */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: var(--fs-micro);
  font-weight: 600;
}
.status-pill.good { background: var(--success-soft); color: var(--success); }
.status-pill.warn { background: var(--warn-soft); color: var(--warn); }
.status-pill.bad { background: var(--danger-soft); color: var(--danger); }
.status-pill.muted { background: var(--panel-2); color: var(--muted); }

/* Categories management page */
.cat-block {
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 0.5px var(--hairline), var(--shadow-1);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.cat-block-h { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.sub-edit-table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
.sub-edit-table td { padding: 4px 8px; border-bottom: 1px solid var(--hairline-2); }
.sub-edit-table td:first-child { padding-left: 0; }
.sub-edit-table input { height: 30px; }


/* ───────────────── Fixes de alineación y UX ───────────────── */

/* Hide native number spinners — feos y comen espacio */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* Fixed table layout — fuerza anchos del colgroup/thead */
.table.fixed { table-layout: fixed; }

/* Section row: encabezado de categoría (NO clickeable) */
.row-section td {
  background: linear-gradient(to bottom, var(--bg-elev), var(--panel)) !important;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}
.row-section + .row-section td { border-top: 0; }
.row-section td:first-child {
  position: relative;
}
.row-section td:first-child::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.row-section .cat-name {
  font-weight: 600;
  font-size: var(--fs-body);
  letter-spacing: -0.005em;
}
.row-section .cat-icon {
  width: 32px; height: 32px;
}
.row-section:hover td {
  background: linear-gradient(to bottom, var(--bg-elev), var(--panel)) !important;
}
.row-section { cursor: default; }

/* Data row clickeable */
.data-row { cursor: pointer; }
.data-row:hover td { background: var(--accent-soft) !important; }
.data-row.is-expanded td { background: var(--accent-soft-2) !important; }
.data-row td { transition: background var(--t-fast) var(--ease); }

/* Indent del nombre en subcategorías para mostrar jerarquía */
.data-row .sub-name-cell {
  padding-left: var(--space-7) !important;
}
.data-row.no-indent .sub-name-cell {
  padding-left: var(--space-3) !important;
}

/* Budget cell input — más ancho, sin spinners */
.budget-cell {
  width: 100%;
  min-width: 90px;
  max-width: none;
  height: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 0 var(--space-2);
  color: var(--text);
  font-size: var(--fs-body);
  transition: all var(--t-fast) var(--ease);
}
.budget-cell:hover {
  border-color: var(--border);
  background: var(--bg-elev);
}
.budget-cell:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.budget-cell.saved { background: var(--success-soft); border-color: var(--success); animation: savedFade 1.2s ease; }
.budget-cell.error { border-color: var(--danger); background: var(--danger-soft); }

/* Expander chevron — más visible */
.expander {
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
}
.data-row:hover .expander { background: var(--panel); color: var(--text); }
.data-row.is-expanded .expander {
  background: var(--accent);
  color: white;
  transform: rotate(90deg);
}

/* Tx detail (transacciones expandidas) sin padding en TD */
tr.tx-detail > td {
  padding: 0 !important;
  background: var(--panel-3) !important;
}
tr.tx-detail .tx-inline {
  background: transparent;
}
tr.tx-detail .tx-inline th { background: var(--panel-2); }

/* Sub-name con indentación visual */
.data-row .sub-leaf {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-left: var(--space-5);
}
.data-row .sub-leaf .leaf-marker {
  width: 8px;
  height: 1px;
  background: var(--border);
}

/* Apply-to-all button más legible */
.btn-mini {
  padding: 5px 10px;
  font-size: var(--fs-micro);
  font-weight: 500;
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--hairline);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.btn-mini:hover { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-mini.applied { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.btn-mini[disabled] { opacity: .5; cursor: not-allowed; }

/* Status pills sin background tan fuerte (más sutiles) */
.status-pill {
  font-size: var(--fs-micro);
  padding: 2px 8px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Card flush con tablas: bordes redondeados respetados */
.card.flush table.table thead th:first-child { border-top-left-radius: var(--r-lg); }
.card.flush table.table thead th:last-child { border-top-right-radius: var(--r-lg); }

/* Period switcher mejor centrado */
.period-switcher .icon-btn {
  width: 30px;
  height: 30px;
}
.period-switcher .select {
  height: 30px;
  text-align: center;
  text-align-last: center;
}

