:root {
  --font-base: 14.667px;
  --font-xs: 12px;
  --font-sm: 13px;
  --font-md: 14.667px;
  --font-lg: 17px;
  --font-xl: 22px;
  --font-kpi: 23px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar: 226px;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #17202a;
  --muted: #6e7a86;
  --line: #dfe5ea;
  --line-soft: #ebeff2;
  --accent: #315f7b;
  --accent-strong: #214a64;
  --accent-soft: #e9f1f5;
  --positive: #1f7654;
  --negative: #a74b4b;
  --warning: #9a6b24;
  --warning-soft: #fff7e7;
  --shadow: 0 1px 2px rgb(20 32 43 / .04), 0 7px 24px rgb(20 32 43 / .035);
}
html[data-theme="dark"] {
  --bg: #0b0e11;
  --surface: #12171c;
  --surface-2: #171d23;
  --text: #e9eef2;
  --muted: #9ba8b4;
  --line: #2a333c;
  --line-soft: #202830;
  --accent: #77a9c6;
  --accent-strong: #96bfd6;
  --accent-soft: #172833;
  --positive: #67b892;
  --negative: #e08a8a;
  --warning: #ddb66e;
  --warning-soft: #2a2418;
  --shadow: none;
}
* { box-sizing: border-box; }
html { font-size: var(--font-base); background: var(--bg); }
body { margin: 0; font-family: "Aptos", "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg); line-height: 1.35; }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: var(--space-4) var(--space-3); border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: var(--space-4); z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 4px 6px 12px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--text); color: var(--surface); font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.05; }
.brand-copy strong { font-size: 15px; letter-spacing: -.01em; }
.brand-copy span { font-size: 13px; color: var(--muted); }
.nav-list { display: grid; gap: 3px; }
.nav-item { border: 0; background: transparent; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; width: 100%; min-height: 38px; padding: 7px 9px; border-radius: 9px; color: var(--muted); text-align: left; cursor: pointer; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.nav-icon { width: 22px; height: 22px; display: grid; place-items: center; font-size: 17px; }
.nav-badge { min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; border-radius: 99px; background: var(--warning-soft); color: var(--warning); font-size: 11px; font-weight: 700; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 10px 8px 2px; border-top: 1px solid var(--line-soft); min-width: 0; }
.avatar { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; }
.user-copy { min-width: 0; display: flex; flex-direction: column; }
.user-copy strong { font-size: 13px; }
.user-copy small { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 10.5px; }
.main { min-width: 0; padding: 0 clamp(18px, 2.5vw, 38px) 44px; }
.topbar { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); border-bottom: 1px solid var(--line); margin-bottom: var(--space-5); }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .055em; }
h1 { margin: 0; font-size: var(--font-xl); line-height: 1.1; letter-spacing: -.025em; }
h2 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
p { margin: 0; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.period-control { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.period-control select { height: 34px; border: 0; background: var(--surface); color: var(--text); padding: 0 26px 0 9px; min-width: 84px; }
.period-control select + select { border-left: 1px solid var(--line); min-width: 116px; }
.period-control select:focus-visible { outline-offset: -2px; }
.button, .icon-button, .text-button { cursor: pointer; }
.button { min-height: 36px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-weight: 650; }
.button:hover { background: var(--surface-2); }
.button-primary { background: var(--accent-strong); color: #fff; border-color: var(--accent-strong); }
.button-primary:hover { background: var(--accent); }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-size: 18px; }
.text-button { border: 0; background: transparent; color: var(--accent-strong); font-weight: 650; padding: 4px; }
.status-banner { margin: -8px 0 16px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted); }
.view { display: none; }
.view.is-active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 10px; margin-bottom: 12px; }
.kpi-card { min-width: 0; min-height: 104px; text-align: left; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; }
.kpi-card > span { color: var(--muted); font-size: 11.5px; font-weight: 650; }
.kpi-card strong { margin-top: 7px; font-size: var(--font-kpi); letter-spacing: -.035em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-card small { margin-top: auto; color: var(--muted); font-size: 10.5px; }
.kpi-warning strong { color: var(--warning); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,2fr) minmax(260px,.92fr); gap: 12px; margin-bottom: 12px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow); padding: 15px; min-width: 0; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.panel-head p { margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.chart-wrap { min-height: 215px; display: grid; place-items: stretch; overflow: hidden; }
.chart-large { min-height: 360px; }
.chart-svg { width: 100%; height: 100%; min-height: inherit; overflow: visible; }
.chart-grid { stroke: var(--line-soft); stroke-width: 1; }
.chart-income { fill: var(--accent); opacity: .8; }
.chart-expense { fill: var(--muted); opacity: .35; }
.chart-line { fill: none; stroke: var(--positive); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-dot { fill: var(--surface); stroke: var(--positive); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart-label { fill: var(--muted); font-size: 10px; }
.category-list { display: grid; gap: 11px; }
.category-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
.category-row .bar { grid-column: 1/-1; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.category-row .bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.category-row strong { font-variant-numeric: tabular-nums; font-size: 12px; }
.category-row span:first-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.table-wrap { overflow: auto; max-width: 100%; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 10.5px; font-weight: 700; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-positive { color: var(--positive); font-weight: 700; }
.amount-negative { color: var(--text); font-weight: 650; }
.status-pill { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; font-size: 9.5px; font-weight: 750; letter-spacing: .02em; white-space: nowrap; }
.status-REAL { color: var(--positive); background: color-mix(in srgb, var(--positive) 8%, var(--surface)); }
.status-PREVISTO { color: var(--accent-strong); background: var(--accent-soft); }
.status-PENDIENTE_REVISION, .status-POSIBLE_DUPLICADO, .status-ANOMALO { color: var(--warning); background: var(--warning-soft); }
.forecast-summary { min-height: 126px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.forecast-summary strong { font-size: 28px; letter-spacing: -.04em; }
.forecast-summary p { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.cashflow-filter { display: flex; align-items: flex-end; gap: 7px; flex-wrap: wrap; }
.cashflow-filter label { display: grid; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 650; }
.cashflow-filter input { height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0 8px; }
.search-field { flex: 1; }
.search-field input, .toolbar select { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 9px; padding: 0 11px; background: var(--surface); color: var(--text); }
.toolbar select { width: auto; min-width: 190px; }
.stack-list { display: grid; gap: 8px; }
.stack-item { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; padding: 11px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--surface-2); }
.stack-item h3 { margin: 0; font-size: 12.5px; }
.stack-item p { margin-top: 4px; color: var(--muted); font-size: 11.5px; }
.stack-item .meta { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: 10.5px; }
.stack-actions { display: flex; align-items: center; gap: 6px; }
.stack-actions .button { min-height: 31px; padding: 5px 9px; font-size: 11px; }
.empty-state { min-height: 110px; display: grid; place-items: center; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.settings-grid .panel > p { margin: 5px 0 15px; color: var(--muted); }
.inline-actions { display: flex; gap: 6px; }
.setting-row { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.dialog { width: min(560px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 16px; background: transparent; }
.dialog::backdrop { background: rgb(4 10 15 / .55); backdrop-filter: blur(2px); }
.dialog-card { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: 0 24px 70px rgb(0 0 0 / .25); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 18px; }
.dialog-copy { margin: 14px 0; color: var(--muted); font-size: 12px; }
.drop-zone { min-height: 116px; padding: 18px; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; text-align: center; cursor: pointer; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-title { font-weight: 700; }
.drop-zone small { color: var(--muted); margin-top: 4px; word-break: break-all; }
.import-progress { margin-top: 14px; }
.progress-line { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; }
.progress-track { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 7px 0 5px; }
.progress-track span { display: block; width: 0%; height: 100%; background: var(--accent); transition: width .2s ease; }
.import-progress small { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.transaction-detail-grid { margin: 15px 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.detail-metric { min-width: 0; padding: 9px 10px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface-2); }
.detail-metric span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 3px; }
.detail-metric strong { display: block; overflow-wrap: anywhere; font-size: 12px; }
.detail-section { margin-top: 14px; }
.detail-section h3 { margin: 0 0 5px; font-size: 11.5px; }
.detail-section > p { color: var(--muted); overflow-wrap: anywhere; }
.source-item { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 9px 10px; border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface-2); }
.source-item strong { display: block; font-size: 11.5px; }
.source-item small { display: block; margin-top: 3px; color: var(--muted); }
.data-table tbody tr[data-transaction-id] { cursor: pointer; }
.data-table tbody tr[data-transaction-id]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dialog-compact { width: min(380px, calc(100vw - 24px)); }
.mobile-more-list { display: grid; gap: 5px; margin-top: 14px; }
.mobile-more-list .nav-item { color: var(--text); border: 1px solid var(--line-soft); background: var(--surface-2); grid-template-columns: 28px 1fr; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; max-width: min(420px, calc(100vw - 36px)); padding: 10px 13px; border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: 0 10px 40px rgb(0 0 0 / .2); }
.mobile-nav { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .kpi-card { min-height: 92px; }
}
@media (max-width: 980px) {
  :root { --sidebar: 78px; }
  .brand-copy, .nav-item > span:not(.nav-icon):not(.nav-badge), .user-copy { display: none; }
  .sidebar { padding-inline: 10px; }
  .brand { justify-content: center; }
  .nav-item { grid-template-columns: 1fr; justify-items: center; padding-inline: 4px; }
  .nav-badge { position: absolute; margin-left: 24px; margin-top: -18px; }
  .user-chip { justify-content: center; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .panel-wide { grid-column: auto; }
}
@media (max-width: 720px) {
  html { font-size: 14px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 0 12px 84px; }
  .topbar { position: sticky; top: 0; z-index: 15; min-height: 66px; margin-bottom: 12px; padding: 8px 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); flex-wrap: wrap; }
  .top-actions { width: 100%; display: grid; grid-template-columns: minmax(0,1fr) auto; }
  .period-control { min-width: 0; }
  .period-control select { flex: 1; min-width: 0; width: 50%; }
  .period-control select + select { min-width: 0; }
  .eyebrow { display: none; }
  h1 { font-size: 19px; }
  .top-actions .icon-button { display: none; }
  .button-primary { min-height: 34px; }
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .kpi-card { min-height: 90px; padding: 11px 12px; }
  .kpi-card strong { font-size: 20px; }
  .dashboard-grid { gap: 8px; margin-bottom: 8px; }
  .panel { padding: 12px; border-radius: 10px; }
  .chart-wrap { min-height: 200px; }
  .chart-large { min-height: 300px; }
  .bottom-grid .panel-wide { order: 2; }
  .toolbar { flex-direction: column; }
  .cashflow-filter { width: 100%; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)) auto; }
  .cashflow-filter input { width: 100%; }
  .toolbar select { width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
  .movement-table th:nth-child(3), .movement-table td:nth-child(3), .movement-table th:nth-child(4), .movement-table td:nth-child(4), .movement-table th:nth-child(7), .movement-table td:nth-child(7) { display: none; }
  .data-table { min-width: 560px; }
  .movement-table, .recent-table { min-width: 0; }
  .recent-table th:nth-child(3), .recent-table td:nth-child(3), .recent-table th:nth-child(5), .recent-table td:nth-child(5) { display: none; }
  .recent-table th, .recent-table td { padding-inline: 6px; }
  .recent-table th:first-child, .recent-table td:first-child { width: 86px; }
  .recent-table th:nth-child(4), .recent-table td:nth-child(4) { width: 88px; }
  .recent-table td:nth-child(2) strong { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chart-label { font-size: 18px; }
  .mobile-nav { position: fixed; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 30; display: grid; grid-template-columns: repeat(5,1fr); min-height: 58px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: 0 10px 30px rgb(0 0 0 / .12); backdrop-filter: blur(14px); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); border-radius: 10px; display: grid; place-items: center; align-content: center; gap: 1px; }
  .mobile-nav button.is-active { color: var(--accent-strong); background: var(--accent-soft); }
  .mobile-nav span { font-size: 17px; line-height: 1; }
  .mobile-nav small { font-size: 9px; }
  .transaction-detail-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .source-item { grid-template-columns: 1fr; }
  .stack-item { grid-template-columns: 1fr; }
  .stack-actions { justify-content: flex-start; }
}
@media (max-width: 390px) {
  .transaction-detail-grid { grid-template-columns: 1fr; }
  .cashflow-filter { grid-template-columns: 1fr 1fr; }
  .cashflow-filter .button { grid-column: 1/-1; }
  .kpi-card { min-height: 78px; }
  .kpi-card strong { margin-top: 4px; }
}
