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

:root {
  /* Paleta de marca Trisma (ver trisma-web-kit/colores.css) */
  --income:  #6A54A8; --income-bg:  #F0ECF8; --income-text:  #5A4596;
  --needs:   #2B5C9E; --needs-bg:   #E8EEF7; --needs-text:   #2B5C9E;
  --wants:   #2E9C85; --wants-bg:   #E4F3EF; --wants-text:   #217A68;
  --savings: #D4A843; --savings-bg: #FAF3E1; --savings-text: #8A6516;
  --brand: #14284A; --brand-accent: #2B5C9E; --brand-soft: #E8EEF7;
  --cream: #F5F0E4;
  --danger: #C2414B; --danger-bg: #FBECEE;
  --success: #1F8A5B; --success-bg: #E8F5EE;
  --ink: #14284A; --dark: #14284A;
  --gray-50: #F6F7F9; --gray-100: #EEF1F5; --gray-200: #E1E6ED;
  --gray-300: #CDD4DF; --gray-400: #929DB0; --gray-500: #5B6B84; --gray-700: #33415C;
  --radius: 14px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,40,74,.05), 0 1px 3px rgba(20,40,74,.05);
  --shadow-lg: 0 24px 48px -12px rgba(20,40,74,.25);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Lora', Georgia, 'Times New Roman', serif;
  --sidebar-w: 256px;

  /* Superficies y tokens semánticos (cambian con el tema) */
  --surface: #fff; --surface-raised: #fff; --row-hover: #FAFBFC;
  --on-brand: #fff; --brand-hover: #0C1A33; --seg-active: #fff;
  --focus-ring: rgba(43,92,158,.16);
  --danger-text: #9B2C35; --danger-border: #F2C4C8;
  --success-text: #17643F; --success-border: #BFE3CF;
  --backdrop: rgba(20,40,74,.45);
  --chart-grid: #EDF0F4; --balance-line: #14284A; --tooltip-bg: #14284A;
  --hero-bg: radial-gradient(120% 140% at 100% 0%, #24457A 0%, transparent 55%), #14284A;
  --hero-border: transparent;
  color-scheme: light;
}

/* ── Modo oscuro (fondos marino de la marca, acentos en sus versiones claras) ── */
:root[data-theme="dark"] {
  --income:  #A895E6; --income-bg:  rgba(168,149,230,.14); --income-text:  #A895E6;
  --needs:   #7FA6DD; --needs-bg:   rgba(127,166,221,.14); --needs-text:   #7FA6DD;
  --wants:   #4FC1A8; --wants-bg:   rgba(79,193,168,.13);  --wants-text:   #4FC1A8;
  --savings: #E6BE5A; --savings-bg: rgba(230,190,90,.13);  --savings-text: #E6BE5A;
  --brand: #F5F0E4; --brand-accent: #7FA6DD; --brand-soft: rgba(127,166,221,.14);
  --danger: #FF7A88; --danger-bg: rgba(255,122,136,.12);
  --success: #4ADE9B; --success-bg: rgba(74,222,155,.12);
  --ink: #F2F4F8; --dark: #F2F4F8;
  --gray-50: #0A1220; --gray-100: #16223A; --gray-200: #1F2C46;
  --gray-300: #2D3C5A; --gray-400: #6A7A98; --gray-500: #98A6BF; --gray-700: #CBD3E1;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.01);
  --shadow-lg: 0 30px 60px -16px rgba(0,0,0,.7);

  --surface: #0F1A2E; --surface-raised: #14223A; --row-hover: rgba(255,255,255,.025);
  --on-brand: #14284A; --brand-hover: #FFFFFF; --seg-active: #22314F;
  --focus-ring: rgba(127,166,221,.24);
  --danger-text: #FFB3BB; --danger-border: rgba(255,122,136,.3);
  --success-text: #9BF0C4; --success-border: rgba(74,222,155,.3);
  --backdrop: rgba(3,8,18,.72);
  --chart-grid: #1A2740; --balance-line: #F5F0E4; --tooltip-bg: #1F2C46;
  --hero-bg: radial-gradient(110% 130% at 100% 0%, rgba(127,166,221,.28) 0%, transparent 55%),
             radial-gradient(80% 100% at 0% 100%, rgba(79,193,168,.14) 0%, transparent 60%), #14284A;
  --hero-border: rgba(255,255,255,.08);
  color-scheme: dark;
}

/* Logos: cada imagen se muestra solo en el tema que le corresponde */
:root:not([data-theme="dark"]) .logo-on-dark,
:root[data-theme="dark"] .logo-on-light { display: none !important; }
/* Interruptor de tema */
.theme-toggle { border: 1px solid var(--gray-200); background: var(--surface); color: var(--gray-500); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; transition: color .15s, border-color .15s, background .15s; }
.theme-toggle:hover { color: var(--ink); border-color: var(--gray-300); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; color: #E6BE5A; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
body, .card, .sidebar, .btn, input, select { transition: background-color .25s, border-color .25s, color .25s; }

body { font-family: var(--font); background: var(--gray-50); color: var(--gray-700); -webkit-font-smoothing: antialiased; font-feature-settings: 'cv11', 'ss01'; }
.num, .card-value, .hero-amount, td, .donut-center b { font-variant-numeric: tabular-nums; }
svg.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; overflow-y: auto;
  padding: 24px 16px 16px;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 0 8px 26px; }
.brand-logo { display: block; height: 48px; width: auto; }
.brand-symbol { display: none; width: 40px; height: 40px; }
.sidebar .brand-tag { padding-left: 57px; margin-top: -6px; }
.brand-name { font-size: 1rem; font-weight: 600; color: var(--ink); letter-spacing: -.01em; line-height: 1.2; }
.brand-tag { font-size: .72rem; color: var(--gray-500); letter-spacing: .04em; }
.brand-tag i { font-style: normal; }
.brand-tag i + i::before { content: ' / '; color: var(--gray-300); }

.nav-label { font-size: .7rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: var(--gray-400); padding: 0 10px 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--gray-500); text-decoration: none;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { color: var(--ink); background: var(--gray-50); }
.sidebar nav a.active { color: var(--ink); background: var(--gray-100); }
.sidebar nav a.active .icon { color: var(--brand-accent); }
.sidebar-cta { margin-top: auto; padding-bottom: 14px; }
.sidebar-cta .btn { width: 100%; justify-content: center; padding: 10px; }

.user-box { display: flex; align-items: center; gap: 10px; padding: 14px 8px 2px; border-top: 1px solid var(--gray-200); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 600; font-size: .85rem; flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: .85rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: .75rem; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout { border: none; background: transparent; color: var(--gray-400); width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; transition: background .15s, color .15s; }
.logout:hover { background: var(--gray-100); color: var(--danger); }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.page { padding: clamp(22px, 3vw, 40px) clamp(16px, 3vw, 48px) 56px; max-width: 1680px; margin-inline: auto; display: none; animation: fadeIn .25s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin-bottom: 28px; }
.page-title { font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; color: var(--ink); letter-spacing: -.01em; line-height: 1.2; }
.page-sub { font-size: .875rem; color: var(--gray-500); margin-top: 4px; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; border: 1px solid var(--gray-200); min-width: 0; }
.card-title { font-size: .75rem; font-weight: 500; color: var(--gray-500); letter-spacing: .02em; margin-bottom: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-head h3 { font-size: .95rem; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }
.card-value { font-size: 1.6rem; font-weight: 600; letter-spacing: -.025em; color: var(--ink); }

.grid-4 { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.grid-hero { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(0,1fr); gap: 16px; margin-bottom: 16px; }
.grid-split { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr); gap: 16px; margin-bottom: 16px; }
.mb { margin-bottom: 16px; }
/* Rejilla que reparte columnas según el ancho disponible (sin huecos) */
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; align-items: start; }

/* Hero */
.hero {
  position: relative; overflow: hidden; color: #fff; border: none;
  background: var(--hero-bg); box-shadow: inset 0 0 0 1px var(--hero-border);
}
.hero::after { content: ''; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px); background-size: 32px 32px; mask-image: linear-gradient(120deg, transparent 40%, #000); pointer-events: none; }
.hero > * { position: relative; z-index: 1; }
.grid-hero .hero { display: flex; flex-direction: column; }
.grid-hero .hero .split-bar { margin-top: auto; }
.grid-hero .hero .hero-stats { margin-bottom: 24px; }
.hero .card-title { color: rgba(255,255,255,.6); }
.hero-amount { font-size: 2.5rem; font-weight: 600; letter-spacing: -.035em; margin: 4px 0 22px; }
.hero-stats { display: flex; gap: 32px; flex-wrap: wrap; }
.hero-stats div span { display: block; font-size: .75rem; color: rgba(255,255,255,.55); margin-bottom: 3px; }
.hero-stats div b { font-size: 1.05rem; font-weight: 600; }
.split-bar { display: flex; gap: 2px; height: 6px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.1); margin: 24px 0 12px; }
.split-bar i { display: block; height: 100%; transition: width .5s; }
.split-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .75rem; color: rgba(255,255,255,.7); }
.split-legend span::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--c); margin-right: 7px; vertical-align: middle; }
.hero-note { color: rgba(255,255,255,.7); font-size: .9rem; max-width: 420px; line-height: 1.6; }

/* Donut */
.donut-wrap { position: relative; height: 200px; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center b { font-size: 1.45rem; font-weight: 600; color: var(--ink); letter-spacing: -.02em; }
.donut-center span { font-size: .72rem; color: var(--gray-500); }

/* KPI tiles */
.kpi { display: flex; gap: 16px; align-items: center; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chip { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.chip .icon { width: 16px; height: 16px; }
.ring { --p: 0; --c: var(--brand); width: 68px; height: 68px; border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--gray-100) 0);
  display: grid; place-items: center; }
.ring::before { content: attr(data-label); width: 58px; height: 58px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: .78rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.kpi-meta { font-size: .78rem; color: var(--gray-500); margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 500; margin-top: 10px; }
.pill-ok { background: var(--success-bg); color: var(--success); }
.pill-over { background: var(--danger-bg); color: var(--danger); }

/* Top list */
.toplist { display: flex; flex-direction: column; gap: 16px; }
.toplist-row { display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: center; font-size: .85rem; }
.toplist-row .dot { width: 8px; height: 8px; border-radius: 50%; }
.toplist-row .name { font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toplist-row b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.toplist-row .bar { grid-column: 2 / 4; height: 4px; background: var(--gray-100); border-radius: 99px; overflow: hidden; margin-top: -6px; }
.toplist-row .bar i { display: block; height: 100%; border-radius: 99px; }
.empty { text-align: center; color: var(--gray-500); padding: 40px 12px; font-size: .875rem; }
.empty .icon { display: block; margin: 0 auto 10px; width: 28px; height: 28px; color: var(--gray-300); }

/* Progress */
.progress-wrap { background: var(--gray-100); border-radius: 99px; height: 6px; overflow: hidden; margin-top: 8px; }
.progress-bar  { height: 100%; border-radius: 99px; transition: width .4s; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 8px; border: 1px solid transparent; font-size: .85rem; font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; font-family: inherit; white-space: nowrap; line-height: 1.2; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: 0 1px 2px rgba(16,24,40,.12); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-danger  { background: var(--surface); color: var(--danger); border-color: var(--gray-200); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger-border); }
.btn-ghost   { background: var(--surface); color: var(--gray-700); border-color: var(--gray-200); }
.btn-ghost:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn-icon { width: 30px; height: 30px; padding: 0; justify-content: center; }
.btn-icon .icon { width: 15px; height: 15px; }
/* Tooltip propio: <button class="has-tip">… <span class="tip" role="tooltip">Texto <kbd>+</kbd></span></button>
   Aparece debajo, alineado a la derecha, al pasar el ratón o al llegar con el teclado (Tab) */
.has-tip { position: relative; }
.tip { position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--ink); color: var(--surface); font-size: .78rem; font-weight: 500; white-space: nowrap; box-shadow: 0 8px 20px -6px rgba(16,24,40,.35); pointer-events: none; opacity: 0; transform: translateY(-4px); transition: opacity .15s, transform .15s; }
.tip::before { content: ''; position: absolute; bottom: 100%; right: 16px; border: 5px solid transparent; border-bottom-color: var(--ink); }
.tip kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 4px; border: 1px solid currentColor; border-bottom-width: 2px; border-radius: 4px; font: 600 .72rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; opacity: .75; }
.has-tip:hover .tip, .has-tip:focus-visible .tip { opacity: 1; transform: none; transition-delay: .25s; }
/* En pantallas táctiles no hay teclado físico ni "pasar por encima": sin tooltip */
@media (hover: none) { .tip { display: none; } }

/* Segmented tabs (JS toggles btn-primary / btn-ghost) */
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--gray-100); border-radius: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.tabs .btn { box-shadow: none; border-color: transparent; padding: 7px 14px; }
.tabs .btn-ghost { background: transparent; color: var(--gray-500); }
.tabs .btn-ghost:hover { color: var(--ink); background: transparent; }
.tabs .btn-primary { background: var(--seg-active); color: var(--ink); box-shadow: 0 1px 3px rgba(16,24,40,.1); }
.tabs .btn-primary:hover { background: var(--seg-active); }

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; padding: 11px 16px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); font-size: .72rem; color: var(--gray-500); font-weight: 500; white-space: nowrap; }
th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; }
td { padding: 13px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; color: var(--gray-700); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--row-hover); }
.text-right { text-align: right; }
.cat-cell { display: flex; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); }
.date-cell { color: var(--gray-500); white-space: nowrap; }
.card.table-card { padding: 0; overflow: hidden; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
label { font-size: .8rem; font-weight: 500; color: var(--gray-700); }
input, select, textarea {
  padding: 10px 12px; border: 1px solid var(--gray-300); background: var(--surface); color: var(--ink);
  border-radius: 8px; font-size: .875rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s; width: 100%;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
input::placeholder { color: var(--gray-400); }
input:focus, select:focus { outline: none; border-color: var(--brand-accent); box-shadow: 0 0 0 4px var(--focus-ring); }
.select-inline { width: auto; padding: 8px 12px; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal-backdrop.hidden { display: none; }
.modal { background: var(--surface-raised); border: 1px solid var(--gray-200); border-radius: 16px; padding: 28px; width: 500px; max-width: 100%; box-shadow: var(--shadow-lg); animation: pop .2s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.98) translateY(6px); } to { opacity: 1; transform: none; } }
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 20px; color: var(--ink); letter-spacing: -.01em; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Diálogos generados por JS (dialog.js) */
.ui-dialog { z-index: 300; animation: fadeIn .15s ease; }
.ui-dialog.is-closing { opacity: 0; transition: opacity .15s; }
.ui-dialog-box { width: 420px; text-align: left; }
.ui-dialog-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 16px; }
.ui-dialog-icon .icon { width: 20px; height: 20px; }
.ui-dialog-icon.is-info    { background: var(--brand-soft); color: var(--brand-accent); }
.ui-dialog-icon.is-warning { background: var(--savings-bg); color: var(--savings); }
.ui-dialog-icon.is-danger  { background: var(--danger-bg); color: var(--danger); }
.ui-dialog-icon.is-success { background: var(--success-bg); color: var(--success); }
.ui-dialog .modal-title { margin-bottom: 8px; }
.ui-dialog-message { color: var(--gray-500); font-size: .9rem; line-height: 1.6; }
.btn-danger-solid { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger-solid { color: #1A0A0D; }
.btn-danger-solid:hover { filter: brightness(1.08); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px; font-size: .74rem; font-weight: 500; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.badge-income  { background: var(--income-bg);  color: var(--income-text); }
.badge-needs   { background: var(--needs-bg);   color: var(--needs-text); }
.badge-wants   { background: var(--wants-bg);   color: var(--wants-text); }
.badge-savings { background: var(--savings-bg); color: var(--savings-text); }

/* Month picker */
.month-picker { display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--gray-200); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); }
.month-picker .btn { background: transparent; border: none; width: 30px; height: 30px; padding: 0; justify-content: center; font-size: 1.05rem; color: var(--gray-500); }
.month-picker .btn:hover { background: var(--gray-100); color: var(--ink); }
.month-picker .btn .icon { width: 16px; height: 16px; }
.mp-label { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 160px; height: 30px; padding: 0 10px; border: none; border-radius: 7px; background: transparent; color: var(--ink); font: 500 .875rem var(--font); cursor: pointer; transition: background .15s; }
.mp-label.mp-year { min-width: 96px; }
.mp-label .icon { width: 15px; height: 15px; color: var(--gray-400); }
.mp-label:hover, .mp-label[aria-expanded="true"] { background: var(--gray-100); }
.mp-label:focus-visible, .date-field:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 1px; }

/* Campo de fecha (sustituye al input nativo) */
.date-field { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: 8px; background: var(--surface); color: var(--ink); font: .875rem var(--font); text-align: left; cursor: pointer; box-shadow: 0 1px 2px rgba(16,24,40,.04); transition: border-color .15s, box-shadow .15s; }
.date-field span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date-field span::first-letter { text-transform: uppercase; }
.date-field .icon { width: 16px; height: 16px; color: var(--gray-400); }
.date-field:hover { border-color: var(--gray-400); }
.date-field[aria-expanded="true"] { border-color: var(--brand-accent); box-shadow: 0 0 0 4px var(--focus-ring); }

/* Calendario emergente (datepicker.js) */
.dp-pop { position: fixed; z-index: 400; width: 296px; padding: 12px; border-radius: 14px; background: var(--surface-raised); border: 1px solid var(--gray-200); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top center; transition: opacity .14s ease, transform .14s ease; }
.dp-pop.is-open { opacity: 1; transform: none; }
.dp-head { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.dp-nav, .dp-title, .dp-day, .dp-cell, .dp-today { border: none; background: transparent; font-family: var(--font); color: var(--ink); cursor: pointer; transition: background .12s, color .12s; }
.dp-nav { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--gray-500); }
.dp-nav .icon { width: 16px; height: 16px; }
.dp-nav:hover { background: var(--gray-100); color: var(--ink); }
.dp-title { flex: 1; height: 32px; border-radius: 8px; font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; justify-content: center; gap: 4px; letter-spacing: -.01em; }
.dp-title .icon { width: 14px; height: 14px; color: var(--gray-400); }
.dp-title:hover:not(:disabled) { background: var(--gray-100); }
.dp-title:disabled { cursor: default; }
.dp-week, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-week span { text-align: center; font-size: .7rem; font-weight: 600; color: var(--gray-400); padding: 4px 0 6px; }
.dp-day { height: 36px; border-radius: 9px; font-size: .84rem; font-variant-numeric: tabular-nums; display: grid; place-items: center; position: relative; }
.dp-day.is-out { color: var(--gray-300); cursor: default; }
:root[data-theme="dark"] .dp-day.is-out { color: var(--gray-400); opacity: .45; }
button.dp-day:hover, .dp-cell:hover { background: var(--gray-100); }
.dp-day.is-today::after, .dp-cell.is-today::after { content: ''; position: absolute; bottom: 5px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--brand-accent); }
.dp-day.is-selected, .dp-cell.is-selected { background: var(--brand) !important; color: var(--on-brand); font-weight: 600; }
.dp-day.is-selected::after, .dp-cell.is-selected::after { background: var(--on-brand); }
.dp-day:focus-visible, .dp-cell:focus-visible, .dp-nav:focus-visible, .dp-title:focus-visible, .dp-today:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 1px; }
.dp-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px 0; }
.dp-cell { height: 44px; border-radius: 10px; font-size: .86rem; font-weight: 500; position: relative; }
.dp-foot { display: flex; justify-content: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--gray-100); }
.dp-today { padding: 6px 14px; border-radius: 8px; font-size: .82rem; font-weight: 500; color: var(--brand-accent); }
.dp-today:hover { background: var(--brand-soft); }

/* Category list (settings) */
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 4px; border: 1px solid var(--gray-100); border-radius: 8px; background: var(--surface); transition: background .15s, box-shadow .15s, border-color .15s; }
.cat-row:hover { background: var(--gray-50); }
.cat-row .cat-name { flex: 1; min-width: 0; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-row.inactive .cat-name { opacity: .4; }
.cat-row .btn { opacity: .55; transition: opacity .15s; }
.cat-row:hover .btn { opacity: 1; }

/* Arrastrar para ordenar */
.grip { border: none; background: transparent; color: var(--gray-400); width: 24px; height: 28px; border-radius: 6px; display: grid; place-items: center; cursor: grab; touch-action: none; flex-shrink: 0; }
.grip .icon { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.grip:hover { color: var(--ink); background: var(--gray-100); }
.grip:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 1px; }
.dragging { position: relative; z-index: 5; border-color: var(--brand-accent) !important; box-shadow: 0 12px 28px -8px rgba(16,24,40,.25), 0 0 0 3px var(--focus-ring) !important; }
.cat-row.dragging { background: var(--surface-raised); }
.is-sorting, .is-sorting * { cursor: grabbing !important; user-select: none; }

/* ── Gastos fijos ───────────────────────────────────────────────────────── */
/* Aviso en Movimientos con los pendientes del mes */
.rec-banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--gray-200); border-left: 3px solid var(--brand-accent); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); animation: fadeIn .2s ease; }
.rec-banner-icon { background: var(--brand-soft); color: var(--brand-accent); }
.rec-banner-text { flex: 1; min-width: 0; font-size: .875rem; color: var(--gray-700); }
.rec-banner-text b { color: var(--ink); font-weight: 600; }
.rec-banner-text span { display: block; font-size: .78rem; color: var(--gray-500); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-banner-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.rec-banner-close { border-color: transparent; background: transparent; color: var(--gray-400); }
.rec-banner-close:hover { color: var(--ink); }

/* Marca en la tabla de Movimientos: movimiento creado desde un gasto fijo */
.rec-mark { display: inline-grid; place-items: center; color: var(--gray-400); }
.rec-mark .icon { width: 14px; height: 14px; }

/* Página: filas en pausa */
.rec-paused td { opacity: .5; }
.rec-paused td:last-child { opacity: 1; }
.rec-paused-badge { background: var(--gray-100); color: var(--gray-500); }

/* Ventana para elegir cuáles añadir */
.rec-check { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; font-size: .85rem; font-weight: 500; color: var(--gray-700); }
.rec-check input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; margin: 0; padding: 0; box-shadow: none; accent-color: var(--brand-accent); cursor: pointer; }
.rec-check-all { padding: 0 12px 10px; border-bottom: 1px solid var(--gray-100); margin-bottom: 6px; }
.rec-apply-list { display: flex; flex-direction: column; gap: 4px; max-height: min(52vh, 420px); overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.rec-apply-row { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; transition: background .12s; }
.rec-apply-row:hover { background: var(--gray-50); }
.rec-apply-row:has(.rec-apply-check:not(:checked)) .rec-apply-info,
.rec-apply-row:has(.rec-apply-check:not(:checked)) .chip,
.rec-apply-row:has(.rec-apply-check:not(:checked)) .rec-apply-amount { opacity: .45; }
.rec-apply-info { display: flex; flex-direction: column; min-width: 0; }
.rec-apply-info b { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-apply-info small { font-size: .76rem; color: var(--gray-500); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-apply-amount { display: flex; align-items: center; gap: 6px; flex-shrink: 0; color: var(--gray-500); font-size: .85rem; }
.rec-apply-amount input { width: 110px; padding: 7px 10px; text-align: right; font-variant-numeric: tabular-nums; }
.rec-apply-footer { align-items: center; }
.rec-apply-footer > span { margin-right: auto; }

/* Nombres de bloques */
.label-row { display: flex; align-items: flex-end; gap: 12px; }
.label-row .chip { width: 40px; height: 40px; margin-bottom: 16px; }
.label-row .form-group { flex: 1; min-width: 0; }

/* Ratio preview */
.ratio-bar { display: flex; gap: 2px; height: 8px; border-radius: 99px; overflow: hidden; background: var(--gray-100); margin: 4px 0 22px; }
.ratio-bar i { display: block; height: 100%; transition: width .3s; }
.label-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* ── Auth ───────────────────────────────────────────────────────────────── */
.auth { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); min-height: 100vh; background: var(--surface); }
.auth-side { position: relative; overflow: hidden; color: #fff; padding: 40px 48px; display: flex; flex-direction: column;
  background: var(--hero-bg); }
.auth-side::after { content: ''; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px); background-size: 40px 40px; mask-image: linear-gradient(160deg, transparent 30%, #000); pointer-events: none; }
.auth-side > * { position: relative; z-index: 1; }
.auth-side .brand { padding: 0; }
.auth-side .brand-logo { height: 56px; }
.auth-pitch h2, .modal-title { font-family: var(--font-display); }
.auth-side .brand-name { color: #fff; }
.auth-side .brand-tag { color: rgba(255,255,255,.55); }
.auth-side .brand-tag i + i::before { color: rgba(255,255,255,.3); }
.auth-pitch { margin: auto 0; max-width: 440px; }
.auth-pitch h2 { font-size: 2.2rem; font-weight: 600; letter-spacing: -.035em; line-height: 1.15; margin-bottom: 16px; }
.auth-pitch p { color: rgba(255,255,255,.65); line-height: 1.65; font-size: .95rem; }
.auth-demo { margin-top: 36px; display: flex; flex-direction: column; gap: 16px; padding: 22px; border: 1px solid rgba(255,255,255,.1); border-radius: 14px; background: rgba(255,255,255,.03); backdrop-filter: blur(4px); }
.auth-demo div { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: .82rem; color: rgba(255,255,255,.75); }
.auth-demo b { font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }
.auth-demo i { grid-column: 1 / 3; height: 4px; border-radius: 99px; display: block; }
.auth-foot { font-size: .78rem; color: rgba(255,255,255,.45); }
.auth-theme { position: absolute; top: 20px; right: 20px; }
.auth-main { position: relative; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .tabs { width: 100%; }
.auth-logo-mobile { display: none; margin-bottom: 20px; }
.auth-symbol { width: 48px; height: 48px; }

/* ── Utilities ──────────────────────────────────────────────────────────── */
.mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.flex { display: flex; } .items-center { align-items: center; }
.justify-between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.text-sm { font-size: .875rem; } .text-xs { font-size: .75rem; }
.font-bold { font-weight: 600; } .gap-2 { gap: 8px; }
.hidden { display: none !important; }
.c-danger { color: var(--danger); } .c-success { color: var(--success); }
.c-income { color: var(--income); } .c-needs { color: var(--needs); }
.c-wants  { color: var(--wants-text); } .c-savings { color: var(--savings-text); }
.muted { color: var(--gray-400); }

.alert { padding: 11px 14px; border-radius: 8px; font-size: .85rem; font-weight: 500; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error   { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }

/* ── Responsive ─────────────────────────────────────────────────────────── */
/* Pantallas grandes: más aire en tarjetas y gráficos más altos */
@media (min-width: 1600px) {
  .card { padding: 26px; }
  .donut-wrap { height: 230px; }
}
@media (max-width: 1240px) {
  .grid-3 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  /* La tarjeta impar sobrante ocupa toda la fila en vez de dejar un hueco */
  .grid-3 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 1040px) {
  .grid-split { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 72px; }
  .sidebar { padding: 20px 12px 12px; }
  .sidebar .brand { align-items: center; padding: 0 0 24px; }
  .sidebar .brand-logo, .sidebar .brand-tag, .nav-label, .sidebar nav a span, .sidebar-cta .label, .user-info { display: none; }
  .sidebar .brand-symbol { display: block; }
  .sidebar nav a { justify-content: center; }
  .sidebar-cta .btn { padding: 10px 0; }
  .user-box { flex-direction: column; padding: 12px 0 0; }
  .grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .auth { grid-template-columns: minmax(0,1fr); }
  .auth-side { display: none; }
  .auth-logo-mobile { display: block; }
}
@media (max-width: 760px) {
  .grid-hero { grid-template-columns: minmax(0,1fr); }
  .donut-wrap { height: 180px; }
}
@media (max-width: 640px) {
  /* Menú inferior + botón flotante para añadir */
  .sidebar { top: auto; bottom: 0; height: auto; width: 100%; flex-direction: row; align-items: center; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); border-right: none; border-top: 1px solid var(--gray-200); }
  .sidebar .brand { display: none; }
  .sidebar nav { flex-direction: row; flex: 1; justify-content: space-around; gap: 0; }
  .sidebar nav a { padding: 10px; }
  .sidebar-cta { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); margin: 0; padding: 0; z-index: 90; }
  .sidebar-cta .btn { width: 52px; height: 52px; padding: 0; border-radius: 16px; box-shadow: 0 10px 24px -6px rgba(16,24,40,.45); }
  .sidebar-cta .btn .icon { width: 22px; height: 22px; }
  .user-box { border-top: none; padding: 0; flex-direction: row; gap: 2px; }
  .user-box .avatar { display: none; }
  .theme-toggle, .logout { width: 32px; height: 32px; border: none; background: transparent; }
  .main { margin-left: 0; padding-bottom: 88px; }
  .page-header { margin-bottom: 20px; align-items: flex-start; }
  .page-header > div:last-child:not(:first-child) { width: 100%; }
  .page-title { font-size: 1.4rem; }
  .grid-3, .grid-2 { grid-template-columns: minmax(0,1fr); }
  .grid-3 > :last-child:nth-child(odd) { grid-column: auto; }
  .card { padding: 18px; }
  .hero-amount { font-size: 2rem; margin-bottom: 16px; }
  .hero-stats { gap: 18px; }
  .mp-label { min-width: 0; flex: 1; }
  .month-picker { flex: 1; }
  #dash-picker, #ent-picker { flex: 1 1 100%; }
  .modal { padding: 22px; border-radius: 16px 16px 0 0; align-self: flex-end; }
  .modal-backdrop { padding: 0; }
  .modal .grid-2 { grid-template-columns: minmax(0,1fr); gap: 0; }
  .tabs { display: flex; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tabs .btn { flex: 1 0 auto; justify-content: center; }

  /* Movimientos: la tabla se convierte en tarjetas */
  .entries-table thead { display: none; }
  .entries-table, .entries-table tbody { display: block; }
  .entries-table tr { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "cat cat amount" "date type actions" "note note note"; align-items: center; gap: 4px 10px; padding: 14px 16px; border-bottom: 1px solid var(--gray-100); }
  .entries-table tr:last-child { border-bottom: none; }
  .entries-table td { padding: 0; border: none; background: none !important; }
  .entries-table .td-cat { grid-area: cat; min-width: 0; }
  .entries-table .td-cat .cat-cell { min-width: 0; }
  .entries-table .td-amount { grid-area: amount; font-size: .95rem; }
  .entries-table .td-date { grid-area: date; font-size: .78rem; padding-left: 38px; }
  .entries-table .td-type { grid-area: type; }
  .entries-table .td-actions { grid-area: actions; }
  .entries-table .td-note { grid-area: note; padding-left: 38px; font-size: .8rem; }
  .entries-table .no-note, .entries-table .td-budget { display: none; }
  .entries-table .cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .entries-table tr td[colspan] { grid-column: 1 / -1; }

  /* Gastos fijos: aviso y ventana de selección en vertical */
  .rec-banner { flex-wrap: wrap; }
  .rec-banner-text { flex: 1 1 calc(100% - 60px); }
  .rec-banner-actions { width: 100%; }
  .rec-banner-actions .btn:not(.btn-icon) { flex: 1; justify-content: center; }
  .rec-apply-amount input { width: 90px; }
  .rec-apply-footer { flex-wrap: wrap; }
  .rec-apply-footer > span { width: 100%; }
}