:root {
  --bg:#f0f5f7;
  --ink:#15283c;
  --muted:#506477;
  --line:#d9e4ec;
  --surface-subtle:#f4f8fb;
  --scene-grid:rgb(24 91 102 / .075);
  --scene-glow:rgb(50 146 132 / .13);
}

html[data-theme="dark"] {
  color-scheme:dark;
  --bg:#0a1420;
  --panel:#122132;
  --ink:#e8f3fb;
  --muted:#b2c5d5;
  --line:#32485d;
  --surface-subtle:#172a3d;
  --accordion-highlight:#1b3044;
  --donut-empty:#32485d;
  --teal:#85d6bf;
  --green:#84ddb1;
  --red:#ff9d9d;
  --blue:#92bbff;
  --scene-grid:rgb(124 186 205 / .105);
  --scene-glow:rgb(32 129 119 / .3);
  --shadow:0 10px 24px rgb(0 0 0 / .2);
}

.main {
  align-self:start;
  margin:0 auto;
  padding-top:clamp(18px,3vw,36px);
}

#topbar {
  isolation:isolate;
  position:relative;
  margin-bottom:16px;
  padding:clamp(14px,2.5vw,25px);
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:
    radial-gradient(ellipse at 94% 4%,var(--scene-glow),transparent 66%),
    linear-gradient(var(--scene-grid) 1px,transparent 1px) 100% 0 / 24px 24px,
    linear-gradient(90deg,var(--scene-grid) 1px,transparent 1px) 100% 0 / 24px 24px,
    var(--panel);
}

#topbar .topbar { margin:0; }
#topbar .topbar > * { min-width:0; }
#topbar .eyebrow { color:var(--teal); }

@media (min-width:761px) {
  .sidebar { overflow-y:auto; scrollbar-width:thin; }
}

main[data-page="home"] #content,
main[data-page="transactions"] #content {
  display:grid;
  grid-template-columns:minmax(0,1fr);
  gap:clamp(12px,2vw,17px);
}

main:is([data-page="home"],[data-page="transactions"]) #content > * {
  min-width:0;
  max-width:100%;
  margin-block:0;
}

main[data-page="home"] :is(.cash-grid,.metric-panels,.two-col,.kpis) { align-items:stretch; }
main[data-page="home"] :is(.cash-tile,.metric-panel,.kpi) { overflow-wrap:anywhere; }
main[data-page="home"] .due-item > strong { overflow-wrap:anywhere; }

main[data-page="transactions"] .split-summary {
  grid-template-columns:repeat(auto-fit,minmax(min(100%,175px),1fr));
  align-items:stretch;
}

main[data-page="transactions"] .summary-stat { min-width:0; overflow-wrap:anywhere; }
#transactionsTable .transactions-table :is(th,td) { line-height:1.42; }
#transactionsTable .transactions-table td:nth-child(11) .action-btn { margin:2px 4px 2px 0; }

.workspace-actions,.savings-actions {
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:8px;
}

.savings-heading {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:16px;
}

.savings-heading strong,.savings-box > strong {
  display:block;
  font-size:clamp(1.4rem,3vw,2rem);
  font-variant-numeric:tabular-nums;
  letter-spacing:-.035em;
  margin-top:7px;
  overflow-wrap:anywhere;
}

.savings-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(min(100%,270px),1fr));
  gap:14px;
}

.savings-box { display:flex; flex-direction:column; gap:8px; overflow-wrap:anywhere; }
.savings-box :is(p,h2) { margin:0; }
.savings-goal { padding-block:10px; }
.savings-goal div { display:flex; justify-content:space-between; flex-wrap:wrap; gap:4px 12px; }
.savings-goal progress { width:100%; height:11px; accent-color:var(--teal); }
.savings-goal p { margin-top:5px; color:var(--muted); font-size:.86rem; }
.savings-actions { margin-top:auto; }

.finance-chat-output { display:grid; gap:8px; }
.finance-chat-output p {
  background:var(--surface-subtle);
  border:1px solid var(--line);
  border-radius:10px;
  padding:10px 12px;
  margin:0;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  line-height:1.5;
}
.finance-chat-output p:nth-child(odd) { background:var(--panel); }
.finance-chat-output strong { display:block; }
#finance-chat { margin-top:14px; }
.finance-chat-input { display:flex; gap:8px; }
.finance-chat-input input { flex:1; min-width:0; }

#monthly-report { color:var(--ink); }
#monthly-report h2 { margin:0 0 8px; }
#monthly-report dl { display:grid; gap:6px; margin-bottom:20px; }
#monthly-report dl div { display:flex; justify-content:space-between; gap:8px; }
#monthly-report dd { margin:0; font-weight:750; }
#monthly-report table { width:100%; border-collapse:collapse; font-size:.9em; }
#monthly-report :is(th,td) { padding:7px 5px; border-bottom:1px solid var(--line); text-align:right; }
#monthly-report :is(th,td):first-child { text-align:left; overflow-wrap:anywhere; }

html[data-theme="dark"] :is(.sidebar,.auth-box,.modal,.modal-top,.modal-footer,.date-pill,.month-picker-panel,
  .btn:not(.btn-primary),.input,.field input,.field select,.field textarea,.summary-stat,.metric-panel,
  .cash-tile,.data-table th,.data-table tr,.invoice-kpis > div,.forecast-cell,.starter-welcome,.settings-layout > *,
  .stat-list-row,.review-batch,.tx-compact-sort,.v7-kpi,.notice,.alert) {
  color:var(--ink);
  border-color:var(--line);
  background:var(--panel);
}

html[data-theme="dark"] .btn:not(.btn-primary):hover,
html[data-theme="dark"] .data-table tr:hover>td,
html[data-theme="dark"] .date-pill button:hover { background:var(--surface-subtle); }
html[data-theme="dark"] .btn-primary { background:#286965; border-color:#387f78; color:#fff; }
html[data-theme="dark"] .btn-primary:hover { background:#327c73; }
html[data-theme="dark"] :is(.sidebar-label,.brand-sub,.nav-btn,.subtitle,.due-marker,.section-hint,.cash-tile p) { color:var(--muted); }
html[data-theme="dark"] :is(.brand-main,.text-button,.cash-action,.chart text,.action-btn) { color:var(--teal); }
html[data-theme="dark"] .chart text { fill:var(--muted); }
html[data-theme="dark"] .gridline { stroke:var(--line); }
html[data-theme="dark"] :is(.nav-btn.active,.nav-btn:hover,.sidebar-toggle,.cash-icon) { background:#19394a; color:#a7e3d0; }
html[data-theme="dark"] :is(.metric-panel.good,.notice.success) { background:#153a32; }
html[data-theme="dark"] :is(.metric-panel.attention,.notice.warn) { background:#352a29; }
html[data-theme="dark"] .due-marker-late { color:var(--red); }
html[data-theme="dark"] #transactionsTable .transactions-table td::before { color:var(--muted); }
html[data-theme="dark"] #transactionsTable .transactions-table tr { background:var(--panel); border-color:var(--line); }
html[data-theme="dark"] .acc-body { color:var(--ink); }
html[data-theme="dark"] .mf73-donut-center { background:var(--panel); color:var(--ink); }
html[data-theme="dark"] .mf73-legend-name { color:var(--muted); }
html[data-theme="dark"] .mf73-legend-amount { color:var(--ink); }
html[data-theme="dark"] .mf73-legend-row:focus-visible { outline:2px solid var(--blue); outline-offset:3px; }
html[data-theme="dark"] :is(.mf73-notif-btn,.mf73-notif-header,.mf73-notif-panel,.mf73-mobile-more-menu) {
  background:var(--panel); color:var(--ink); border-color:var(--line);
}
html[data-theme="dark"] :is(.mf73-notif-btn:hover,.mf73-notif-btn[aria-expanded="true"],.mf73-notif-close,
  .mf73-notif-item,.mf73-notif-item .notice button,.mf73-mobile-more-menu .mf73-mobile-link) {
  background:var(--surface-subtle); color:var(--ink); border-color:var(--line);
}
html[data-theme="dark"] .mf73-notif-item.warn { background:#352a29; }
html[data-theme="dark"] .mf73-notif-item .notice { background:transparent; color:var(--ink); }
html[data-theme="dark"] :is(.mf73-notif-date,.mf73-notif-section h3) { color:var(--muted); }
html[data-theme="dark"] .mf73-notif-count { border-color:var(--panel); }

html[data-theme="dark"] .field label { color:var(--muted); }
html[data-theme="dark"] :is(.week-closed,.invoice-alert) {
  background:#262a32;
  color:var(--ink);
  border-color:#626247;
}
html[data-theme="dark"] .week-closed .tiny { color:var(--muted); }
html[data-theme="dark"] :is(.state-pending,.pill.warn),
html[data-theme="dark"] .acc-title .state-pending {
  background:#3c2b19;
  border-color:#7c5a2e;
  color:#ffdc9b;
}
html[data-theme="dark"] :is(.state-cleared,.pill.success),
html[data-theme="dark"] .acc-title .state-cleared {
  background:#17382e;
  border-color:#356655;
  color:#a2e7bd;
}
html[data-theme="dark"] :is(.state-card,.state-info),
html[data-theme="dark"] .acc-title :is(.state-card,.state-info) {
  background:#20364b;
  border-color:#45607c;
  color:#c6e0ff;
}

@media(max-width:520px) {
  #topbar .controls { justify-content:flex-start; gap:7px; }
  #topbar .controls > .btn { min-height:40px; }
  main[data-page="transactions"] .split-summary { grid-template-columns:repeat(2,minmax(0,1fr)); }
  main[data-page="home"] .due-item { grid-template-columns:minmax(0,1fr) auto; }
  main[data-page="home"] .due-item button { grid-column:2; justify-self:end; }
}

@media print {
  @page { size:A4; margin:16mm; }
  body:has(#monthly-report) { background:white!important; color:black!important; }
  body:has(#monthly-report) > :not(#modal),
  body:has(#monthly-report) :is(.modal-top,.modal-footer) { display:none!important; }
  body:has(#monthly-report) :is(#modal,.modal,.modal-body) {
    background:none!important;
    border:0!important;
    box-shadow:none!important;
    display:block!important;
    height:auto!important;
    inset:auto!important;
    margin:0!important;
    max-height:none!important;
    max-width:none!important;
    overflow:visible!important;
    padding:0!important;
    position:static!important;
    width:auto!important;
  }
  #monthly-report { color:#122637!important; font:11pt/1.45 system-ui,sans-serif; }
  #monthly-report table tr { break-inside:avoid; }
}
