/* Finanzas personales — hoja de estilos */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e4e7ec;
  --primary: #4338ca;
  --primary-2: #3730a3;
  --primary-weak: #eef0ff;
  --on-primary: #ffffff;
  --income: #059669;
  --expense: #e11d48;
  --transfer: #2563eb;
  --warn: #d97706;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, .28);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e1a; --surface: #111627; --surface-2: #151b2e; --surface-3: #1c2339;
    --text: #e8ebf3; --text-2: #c3c9d8; --muted: #8b94ab; --border: #232a40;
    --primary: #818cf8; --primary-2: #a5b4fc; --primary-weak: rgba(129, 140, 248, .14); --on-primary: #0b1020;
    --income: #34d399; --expense: #fb7185; --transfer: #60a5fa; --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0e1a; --surface: #111627; --surface-2: #151b2e; --surface-3: #1c2339;
  --text: #e8ebf3; --text-2: #c3c9d8; --muted: #8b94ab; --border: #232a40;
  --primary: #818cf8; --primary-2: #a5b4fc; --primary-weak: rgba(129, 140, 248, .14); --on-primary: #0b1020;
  --income: #34d399; --expense: #fb7185; --transfer: #60a5fa; --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14.5px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1, "cv11" 1; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
a { color: inherit; text-decoration: none; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; word-break: break-word; }
.icon { flex: none; display: block; }
.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: 12.5px; }
.grow { flex: 1 1 auto; min-width: 0; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.neutral { color: var(--transfer); }
.mono { font-family: var(--mono); letter-spacing: .08em; }
.link { color: var(--primary); font-weight: 550; font-size: 13px; }
.link:hover { text-decoration: underline; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 16px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 6px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand small, .auth-brand small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 520; transition: background .15s, color .15s; }
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.is-active { background: var(--primary-weak); color: var(--primary); font-weight: 620; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-weight: 700; flex: none; }
.user-meta { min-width: 0; line-height: 1.3; }
.user-meta strong, .user-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--muted); font-size: 12px; }
.sidebar-tools { display: flex; gap: 6px; padding: 0 2px; }
.sidebar-tools form { margin: 0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid transparent; }
.topbar h1 { font-size: 21px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
.content { padding: 8px 28px 28px; display: flex; flex-direction: column; gap: 18px; max-width: 1360px; width: 100%; }
.foot { padding: 0 28px 28px; color: var(--muted); font-size: 12px; }
.scrim { display: none; }
.bottomnav { display: none; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-flush .card-head { margin: 0; }
.pad { padding: 16px 20px; }
.card-foot { border-top: 1px solid var(--border); }
.card-foot .hint { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.empty { text-align: center; padding: 48px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty p { margin: 0 0 6px; }
.empty-mini { color: var(--muted); margin: 0; padding: 8px 0; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.empty-mini p { margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 1px 2px rgba(67, 56, 202, .3); }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--expense); }
.btn-danger:hover { background: color-mix(in srgb, var(--expense) 10%, var(--surface)); color: var(--expense); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn-lg { height: 46px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn-sm { width: 30px; height: 30px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.only-dark { display: none; }
[data-theme="dark"] .only-dark { display: block; }
[data-theme="dark"] .only-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-dark { display: block; }
  :root:not([data-theme="light"]) .only-light { display: none; }
}

.alert { display: flex; align-items: flex-start; gap: 10px; margin: 0 28px 4px; padding: 11px 12px 11px 16px; border-radius: var(--radius-sm); border: 1px solid; font-weight: 520; }
.alert-x { margin-left: auto; background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 2px; }
.alert-success { background: color-mix(in srgb, var(--income) 10%, var(--surface)); border-color: color-mix(in srgb, var(--income) 30%, transparent); color: color-mix(in srgb, var(--income) 70%, var(--text)); }
.alert-error { background: color-mix(in srgb, var(--expense) 9%, var(--surface)); border-color: color-mix(in srgb, var(--expense) 30%, transparent); color: color-mix(in srgb, var(--expense) 75%, var(--text)); }
.alert-info { background: var(--primary-weak); border-color: color-mix(in srgb, var(--primary) 25%, transparent); color: var(--text-2); }
.auth-card .alert { margin: 0 0 14px; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input[type=number], select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s; min-width: 0;
}
textarea { height: auto; padding: 9px 12px; resize: vertical; }
select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
input[type=color] { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
input[type=file] { font: inherit; font-size: 13px; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; margin-right: 10px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; margin-bottom: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
section.grid-2 { gap: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form-card h2 { margin-bottom: 14px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input[type=text] { flex: 1; min-width: 140px; height: 34px; }
.radio-cards { border: 0; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.radio-cards label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.radio-cards label:has(input:checked) { border-color: var(--primary); background: var(--primary-weak); }
.radio-cards input { margin-top: 3px; accent-color: var(--primary); }
.radio-cards small { display: block; color: var(--muted); font-size: 12.5px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 25px; font-weight: 720; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-delta { font-size: 12.5px; color: var(--muted); }
.kpi-delta.up-good { color: var(--income); }
.kpi-delta.down-bad { color: var(--expense); }
.kpi-accent { background: linear-gradient(135deg, #4338ca, #6d28d9); border-color: transparent; color: #fff; }
.kpi-accent .kpi-label, .kpi-accent .kpi-delta { color: rgba(255, 255, 255, .78); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; margin-right: 2px; vertical-align: 1px; }
.dot-lg { width: 12px; height: 12px; margin: 0; }

.grid-main { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.span-2 { grid-column: span 2; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.form-card { position: sticky; top: 84px; }

.legend { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); display: inline-block; margin-left: 8px; }

/* Gráficos */
.chart { width: 100%; min-height: 120px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart rect.bar-r { transition: opacity .15s; }
.chart:hover rect.bar-r { opacity: .55; }
.chart rect.bar-r:hover { opacity: 1; }
.chart .donut-total { fill: var(--text); font-size: 16px; font-weight: 700; }
.chart .donut-label { fill: var(--muted); font-size: 11px; }
.chart-tip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 600; padding: 6px 9px; border-radius: 7px; box-shadow: var(--shadow-lg); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }
.donut-wrap { display: grid; place-items: center; margin-bottom: 10px; }
.donut-wrap .chart { width: 190px; min-height: 190px; }

/* Listas */
.cat-list, .acc-list, .budget-list, .up-list, .rank-list, .row-list, .tx-list { list-style: none; margin: 0; padding: 0; }
.cat-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; }
.cat-list strong { font-weight: 620; }
.acc-list li, .up-list li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.acc-list li:first-child, .up-list li:first-child { border-top: 0; }
.acc-list small, .up-list small, .row-list small { display: block; color: var(--muted); font-size: 12px; }
.acc-dot { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); flex: none; }
.date-chip { width: 42px; flex: none; text-align: center; line-height: 1.1; font-size: 10.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 5px 0; border-radius: 9px; background: var(--surface-3); }
.date-chip b { display: block; font-size: 16px; color: var(--text); }
.date-chip.is-due { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.budget-list li, .rank-list li { padding: 8px 0; }
.budget-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 6px; flex-wrap: wrap; }
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: visible; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--c); transition: width .4s ease; }
.bar > span.warn { background: var(--warn); }
.bar > span.over { background: var(--expense); }
.bar .pace { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-2); opacity: .45; border-radius: 2px; }

.row-list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); }
.row-list li.is-archived, .is-archived { opacity: .55; }
.row-actions { display: flex; align-items: center; gap: 2px; }
.row-actions form { margin: 0; }

.tx-list li.tx { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.card-flush .tx-list li.tx { padding: 10px 20px; }
.tx-list li.tx:first-child { border-top: 0; }
.tx-icon { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.tx-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.tx-main strong { display: flex; align-items: center; gap: 5px; font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-main small { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-main:hover strong { color: var(--primary); }
.tx-flag { color: var(--muted); display: inline-flex; }
.tx-amount { font-weight: 680; white-space: nowrap; }
.tx-del { margin: 0; opacity: 0; transition: opacity .15s; }
.tx:hover .tx-del, .tx-del:focus-within { opacity: 1; }
.day-head { display: flex; justify-content: space-between; padding: 9px 20px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.day-head:first-child { border-top: 0; }

/* Filtros */
.filters { padding: 14px 16px; }
.filters-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters-row .field { margin: 0; flex: 1 1 140px; }
.filters-row .search-field { flex: 2 1 220px; position: relative; }
.search-field .icon { position: absolute; left: 12px; bottom: 12px; color: var(--muted); }
.search-field input { padding-left: 36px; }
.filters-btns { display: flex; gap: 8px; }
.filters-btns .btn { height: 40px; }
.filters-toggle { display: none !important; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { padding: 5px 12px; border-radius: 99px; border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-2); background: var(--surface); }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.year-chips { margin: 0; }
.period-form h2 { align-self: center; }
.period-form p { margin: 10px 0 0; }

.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.summary-strip > div { padding: 13px 18px; border-left: 1px solid var(--border); min-width: 0; }
.summary-strip > div:first-child { border-left: 0; }
.summary-strip span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.summary-strip strong { font-size: 18px; font-weight: 700; white-space: nowrap; }

.pager { display: flex; justify-content: center; align-items: center; gap: 14px; }

.month-nav { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.month-nav span { min-width: 128px; text-align: center; font-weight: 650; font-size: 14px; }
.month-nav .icon-btn { width: 32px; height: 32px; }

/* Cuentas */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.acc-card { display: flex; flex-direction: column; gap: 6px; border-top: 3px solid var(--c); }
.acc-card header { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.acc-card .acc-dot { background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.acc-balance { font-size: 24px; font-weight: 720; letter-spacing: -.02em; }
.acc-actions { display: flex; align-items: center; gap: 2px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.acc-actions .btn { margin-right: auto; }
.acc-actions form { margin: 0; }
.adjust summary { cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 600; margin-top: 4px; }
.adjust form { margin-top: 8px; }
.adjust .hint { margin: 6px 0 0; }

/* Presupuestos */
.budget-table li { align-items: center; }
.budget-input { display: flex; align-items: center; gap: 6px; width: 170px; flex: none; }
.budget-input b { color: var(--muted); font-weight: 600; }
.budget-input input { text-align: right; height: 36px; }

/* Tabla */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 20px; text-align: left; border-top: 1px solid var(--border); white-space: nowrap; }
.table thead th { border-top: 0; font-size: 12px; color: var(--muted); font-weight: 650; background: var(--surface-2); }
.table tfoot th { background: var(--surface-2); font-weight: 700; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.is-future td { color: var(--muted); opacity: .6; }

/* Ajustes */
.settings { display: grid; gap: 18px; max-width: 920px; }
.settings h2 { margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 8px; }
.stats div { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.stats dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.stats dd { margin: 2px 0 0; font-weight: 700; }
.undo-import { margin-top: 14px; }

/* ---------- Modal de movimiento ---------- */
.modal { border: 0; padding: 0; background: transparent; max-width: 520px; width: calc(100% - 24px); color: var(--text); }
.modal::backdrop { background: rgba(10, 14, 26, .55); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 18px 20px 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }
.modal-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--border); }
.modal-foot .check { margin: 0; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 12px; margin-bottom: 14px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px; border-radius: 9px; font-weight: 620; font-size: 13.5px; color: var(--muted); transition: background .15s, color .15s; }
.segmented input:checked + span { background: var(--surface); box-shadow: var(--shadow); }
.seg-egreso input:checked + span { color: var(--expense); }
.seg-ingreso input:checked + span { color: var(--income); }
.seg-transferencia input:checked + span { color: var(--transfer); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }
.amount-input { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; transition: border-color .15s, box-shadow .15s; }
.amount-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.amount-input b { font-size: 22px; color: var(--muted); font-weight: 600; }
.amount-input input { border: 0 !important; box-shadow: none !important; height: 56px; padding: 0; font-size: 28px; font-weight: 720; letter-spacing: -.02em; background: transparent; }
.more-fields { margin-bottom: 8px; }
.more-fields summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: 13px; margin-bottom: 10px; }
.current-attachment { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.current-attachment a { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 600; font-size: 13px; }
.current-attachment .check { margin: 0; }

/* ---------- Acceso ---------- */
.auth-body { background: var(--bg); }
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 44px; color: #fff; background: radial-gradient(1200px 600px at 10% 0%, #6d28d9 0%, transparent 60%), radial-gradient(900px 700px at 100% 100%, #0e7490 0%, transparent 55%), #1e1b4b; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.auth-brand small { color: rgba(255, 255, 255, .7); }
.auth-pitch h2 { font-size: 36px; font-weight: 750; letter-spacing: -.03em; max-width: 420px; margin-bottom: 12px; }
.auth-pitch p { color: rgba(255, 255, 255, .78); font-size: 16px; max-width: 420px; margin: 0 0 22px; }
.auth-pitch ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.auth-pitch li { display: flex; align-items: center; gap: 10px; color: rgba(255, 255, 255, .9); }
.auth-pitch li .icon { color: #a7f3d0; }
.auth-foot { display: flex; align-items: center; gap: 6px; color: rgba(255, 255, 255, .65); }
.auth-main { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 32px 20px; }
.auth-main > .alert { width: 100%; max-width: 420px; margin: 0 0 14px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin-bottom: 4px; }
.auth-card > .muted { margin: 0 0 22px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .grid-main .span-2 { grid-column: 1 / -1; }
  .grid-main > .stack { order: 1; }
  .grid-main > .span-2:not(:first-child) { order: 2; }
  .grid-side { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; inset: 0 auto 0 0; width: 280px; transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10, 14, 26, .45); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 19px; }
  .content { padding: 6px 16px 96px; gap: 14px; }
  .foot { display: none; }
  .alert { margin: 0 16px 4px; }
  .grid-main, .grid-side { grid-template-columns: minmax(0, 1fr); }
  .form-card { position: static; }
  .grid-side > .form-card { order: -1; }
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
  .bottomnav a, .bottomnav button:not(.fab) { display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit; font-size: 10.5px; font-weight: 600; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; }
  .bottomnav a.is-active { color: var(--primary); }
  .fab { justify-self: center; width: 54px; height: 54px; margin-top: -26px; border-radius: 50%; border: 4px solid var(--bg); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; box-shadow: 0 8px 20px -6px rgba(67, 56, 202, .6); cursor: pointer; }
  .sidebar-new { display: none; }
  .hide-sm { display: none; }
  .tx-del { opacity: 1; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 24px 20px; gap: 18px; }
  .auth-pitch h2 { font-size: 24px; }
  .auth-pitch p, .auth-pitch ul, .auth-foot { display: none; }
  .modal { width: 100%; max-width: none; margin: auto 0 0; }
  .modal-card { border-radius: 20px 20px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .kpis, .kpis-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 19px; }
  .kpi-delta { font-size: 11.5px; }
  .kpis-3 .kpi:last-child { grid-column: 1 / -1; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-2.modal-grid { grid-template-columns: 1fr 1fr; }
  .card:not(.card-flush) { padding: 14px 16px; }
  .filters:not(.is-open) .filters-row > .field:not(.search-field), .filters:not(.is-open) .filters-btns .btn-primary, .filters:not(.is-open) .filters-btns .btn-ghost { display: none; }
  .filters-toggle { display: inline-flex !important; }
  .filters .filters-row { flex-wrap: wrap; }
  .tx-del { display: none; }
  .pad, .row-list li, .card-flush .tx-list li.tx, .day-head { padding-left: 16px; padding-right: 16px; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-strip > div:nth-child(3) { border-left: 0; }
  .summary-strip > div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .summary-strip strong { font-size: 16px; }
  .month-nav span { min-width: 104px; font-size: 13px; }
  .row-list li { flex-wrap: wrap; }
  .row-actions { width: 100%; justify-content: flex-end; margin-top: -4px; }
  .budget-table li { flex-wrap: wrap; }
  .budget-input { width: 100%; }
  .filters-row .field { flex: 1 1 45%; }
  .filters-row .search-field { flex-basis: 100%; }
  .filters.is-open .filters-btns { width: 100%; }
  .filters-btns .btn { flex: 1; }
  .topbar-actions .btn-ghost span { display: none; }
}

/* ---------- Impresión ---------- */
.print-head { display: none; }
@media print {
  :root { --bg: #fff; --surface: #fff; --shadow: none; }
  .sidebar, .topbar, .bottomnav, .foot, .alert, .period-form .btn, .year-chips, dialog { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .print-head { display: block; margin-bottom: 8px; }
  .print-head p { color: #64748b; margin: 2px 0 0; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
  .kpi-accent { background: #fff; color: var(--text); border: 1px solid var(--border); }
  .kpi-accent .kpi-label, .kpi-accent .kpi-delta { color: var(--muted); }
}
