:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #fff;
  --surface-soft: #f8faf9;
  --text: #1d2925;
  --muted: #7b8882;
  --line: #e7ece9;
  --primary: #138b68;
  --primary-strong: #087653;
  --primary-soft: #e9f6f1;
  --danger: #cf5e58;
  --warning: #c98831;
  --blue: #507eb4;
  --violet: #8067b3;
  --shadow: 0 12px 32px rgba(35, 62, 51, .055);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
:root[data-theme="blue"] { --primary:#3979c4; --primary-strong:#245f9f; --primary-soft:#edf4fc; }
:root[data-theme="violet"] { --primary:#7958b7; --primary-strong:#61419e; --primary-soft:#f2eef9; }
:root[data-theme="dark"] { color-scheme:dark; --bg:#111a18; --surface:#1b2723; --surface-soft:#202e29; --text:#edf4f0; --muted:#9caea5; --line:#30413a; --primary:#57c39a; --primary-strong:#75d4ac; --primary-soft:#223c32; --danger:#fa8179; --warning:#e8b25d; --blue:#83b4e7; --violet:#b19ce4; --shadow:0 12px 32px rgba(0,0,0,.18); }
* { box-sizing:border-box; }
body { margin:0; min-width:320px; min-height:100vh; background:var(--bg); color:var(--text); font-size:14px; }
button,input,select { font:inherit; }
button { color:inherit; }
.hidden { display:none!important; }
.muted,.helper { color:var(--muted); line-height:1.6; }
.eyebrow { margin:0 0 8px; color:var(--primary); font-size:10px; font-weight:800; letter-spacing:.14em; }
.auth-shell { min-height:100vh; display:grid; place-items:center; padding:24px; background:radial-gradient(ellipse at top left,var(--primary-soft),transparent 54%),var(--bg); }
.auth-card { width:min(100%,430px); padding:38px; background:var(--surface); border:1px solid var(--line); border-radius:22px; box-shadow:var(--shadow); }
.brand-mark { display:grid; place-items:center; width:46px; height:46px; margin-bottom:24px; border-radius:15px; background:var(--primary); color:white; font-size:23px; font-weight:800; }
.brand-mark.small { width:36px; height:36px; margin:0; border-radius:12px; font-size:19px; flex:none; }
.brand-logo { display:block; width:46px; height:46px; object-fit:contain; border-radius:12px; background:var(--surface); }
.brand-logo.small { width:36px; height:36px; flex:none; }
.auth-card h1 { margin:0 0 10px; font-size:27px; letter-spacing:-.04em; }
.form-stack { display:grid; gap:16px; margin-top:25px; }
label { display:grid; gap:7px; color:var(--text); font-size:12px; font-weight:650; }
input,select { min-width:0; width:100%; min-height:42px; padding:10px 12px; border:1px solid var(--line); border-radius:9px; outline:0; background:var(--surface-soft); color:var(--text); }
input:focus,select:focus { border-color:var(--primary); box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 16%,transparent); }
input::placeholder { color:var(--muted); }
.button { display:inline-flex; justify-content:center; align-items:center; gap:8px; min-height:39px; padding:9px 15px; border:0; border-radius:9px; font-size:12px; font-weight:700; cursor:pointer; transition:transform .15s,background .15s; }
.button:hover { transform:translateY(-1px); }
.button.primary { background:var(--primary); color:#fff; }
.button.primary:hover { background:var(--primary-strong); }
.button.subtle { background:var(--primary-soft); color:var(--primary-strong); }
.button.danger { background:#fff1f0; color:var(--danger); }
:root[data-theme="dark"] .button.danger { background:#482c2b; }
.helper { margin:18px 0 0; font-size:11px; }
.helper strong { color:var(--text); }
.form-message { min-height:18px; margin:0; font-size:12px; }
.error { color:var(--danger); }
.app-shell { min-height:100vh; }
.sidebar { position:fixed; inset:0 auto 0 0; z-index:3; display:flex; flex-direction:column; width:246px; padding:24px 16px 16px; border-right:1px solid var(--line); background:var(--surface); }
.brand { display:flex; align-items:center; gap:11px; padding:0 9px 25px; color:var(--text); text-decoration:none; font-size:14px; font-weight:800; letter-spacing:-.02em; }
.brand small { display:block; margin-top:4px; color:var(--muted); font-size:8px; font-weight:700; letter-spacing:.12em; }
.main-nav { display:grid; gap:5px; }
.nav-link { display:flex; align-items:center; gap:13px; width:100%; padding:11px 13px; border:0; border-radius:9px; background:transparent; color:var(--muted); text-align:left; font-size:12px; font-weight:650; cursor:pointer; }
.nav-link span { width:18px; font-size:17px; text-align:center; }
.nav-link:hover,.nav-link.active { background:var(--primary-soft); color:var(--primary-strong); }
.sidebar-foot { display:grid; gap:12px; margin-top:auto; padding:14px 5px 3px; border-top:1px solid var(--line); }
.sidebar-user { display:flex; align-items:center; gap:10px; min-width:0; }
.avatar { display:grid; place-items:center; width:32px; height:32px; flex:none; border-radius:50%; background:var(--primary-soft); color:var(--primary-strong); font-size:12px; font-weight:800; }
.sidebar-foot strong,.sidebar-foot small { display:block; max-width:122px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sidebar-foot strong { font-size:11px; }
.sidebar-foot small { margin-top:4px; color:var(--muted); font-size:10px; }
.logout-link,.icon-button { border:0; background:transparent; color:var(--muted); cursor:pointer; }
.logout-link { display:flex; align-items:center; justify-content:center; gap:9px; width:100%; min-height:38px; padding:8px 11px; border-radius:9px; color:var(--danger); text-align:left; font-size:12px; font-weight:700; }
.logout-link:hover { background:color-mix(in srgb,var(--danger) 9%,var(--surface)); }
.logout-link span:first-child { font-size:18px; }
.main-area { width:min(1500px,calc(100% - 246px)); margin-left:246px; padding:0 40px 28px; }
.topbar { display:flex; align-items:center; justify-content:space-between; min-height:91px; border-bottom:1px solid var(--line); }
.topbar h1 { margin:0; font-size:19px; letter-spacing:-.03em; }
.topbar .eyebrow { margin-bottom:4px; }
.topbar-right { display:flex; align-items:center; gap:10px; color:var(--muted); font-size:11px; }
.topbar-right .avatar { margin-left:11px; }
.today-label { font-size:11px; }
.page { display:grid; gap:20px; padding-top:24px; }
.welcome-row { display:flex; align-items:center; justify-content:space-between; gap:18px; }
.welcome-row h2 { margin:0 0 5px; font-size:20px; letter-spacing:-.03em; }
.welcome-row p { margin:0; font-size:12px; }
.stats-grid { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:13px; }
.stats-grid.compact { grid-template-columns:repeat(3,minmax(0,1fr)); }
.stat-card,.panel { min-width:0; padding:18px; border:1px solid var(--line); border-radius:13px; background:var(--surface); box-shadow:var(--shadow); }
.stat-card { min-height:122px; }
.stat-top { display:flex; align-items:center; justify-content:space-between; gap:5px; color:var(--muted); font-size:11px; }
.stat-card strong { display:block; margin-top:15px; overflow-wrap:anywhere; font-size:clamp(17px,1.8vw,23px); letter-spacing:-.04em; }
.stat-card small { display:block; margin-top:6px; color:var(--muted); font-size:9px; }
.stat-icon { display:grid; place-items:center; width:28px; height:28px; flex:none; border-radius:9px; background:var(--primary-soft); color:var(--primary); font-size:15px; font-weight:800; }
.stat-icon.red { background:#fff0ef; color:var(--danger); }
.stat-icon.orange { background:#fff5e9; color:var(--warning); }
.stat-icon.blue { background:#edf4fd; color:var(--blue); }
.stat-icon.violet { background:#f1edfa; color:var(--violet); }
:root[data-theme="dark"] .stat-icon.red,:root[data-theme="dark"] .stat-icon.orange,:root[data-theme="dark"] .stat-icon.blue,:root[data-theme="dark"] .stat-icon.violet { background:var(--surface-soft); }
.balance-card { border-color:color-mix(in srgb,var(--primary) 35%,var(--line)); }
.panel h2 { margin:0; font-size:14px; letter-spacing:-.02em; }
.chart-panel { padding-bottom:13px; }
.panel-heading { display:flex; align-items:center; justify-content:space-between; gap:15px; margin-bottom:17px; }
.panel-heading h2 { margin-bottom:5px; }
.panel-heading .muted { margin:0; font-size:11px; }
.chart-heading { align-items:flex-start; }
.chart-controls { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:8px; }
.chart-controls label,.transaction-filters label { display:grid; gap:4px; min-width:100px; color:var(--muted); font-size:10px; }
.chart-controls select,.transaction-filters select { width:100%; min-width:100px; min-height:34px; padding:6px 9px; font-size:11px; }
.transaction-filters { display:grid; grid-template-columns:repeat(3,minmax(130px,1fr)); gap:10px; margin:-3px 0 14px; }
.checkbox-row { display:flex; align-items:center; gap:8px; }
.checkbox-row input { width:16px; min-height:16px; margin:0; }
.table-subtitle { display:block; margin-top:3px; color:var(--muted); font-size:10px; }
.filter-label { display:flex; align-items:center; gap:8px; color:var(--muted); font-size:10px; white-space:nowrap; }
.filter-label select { width:auto; min-width:140px; min-height:34px; padding:6px 9px; font-size:10px; }
.chart-period { padding:6px 9px; border-radius:7px; background:var(--surface-soft); color:var(--muted); font-size:9px; font-weight:800; letter-spacing:.08em; }
.chart-wrap { height:255px; width:100%; }
#financeChart { display:block; width:100%; height:100%; }
.chart-legend { display:flex; flex-wrap:wrap; justify-content:center; gap:8px 18px; padding:7px 0 2px; }
.legend-item { display:flex; align-items:center; gap:7px; color:var(--muted); font-size:10px; }
.legend-swatch { width:8px; height:8px; border-radius:50%; }
.legend-color-0 { background:#138b68; }
.legend-color-1 { background:#cf5e58; }
.legend-color-2 { background:#c98831; }
.legend-color-3 { background:#507eb4; }
.legend-color-4 { background:#8067b3; }
.activity-list { display:grid; }
.activity-row { display:flex; align-items:center; gap:12px; padding:12px 0; border-top:1px solid var(--line); }
.activity-dot { width:9px; height:9px; flex:none; border-radius:50%; background:var(--primary); }
.activity-dot.expense { background:var(--danger); }
.activity-dot.debt { background:var(--warning); }
.activity-dot.receivable { background:var(--blue); }
.activity-main { min-width:0; flex:1; }
.activity-main strong,.activity-main small { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.activity-main strong { font-size:11px; }
.activity-main small { margin-top:4px; color:var(--muted); font-size:10px; }
.activity-amount { font-size:11px; font-weight:750; white-space:nowrap; }
.text-button { padding:5px 0; border:0; background:transparent; color:var(--primary); font-size:11px; font-weight:700; cursor:pointer; }
.transaction-form { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px; margin-top:17px; }
.transaction-form .wide { grid-column:span 2; }
.transaction-form>.button { align-self:end; }
.panel>h2+.transaction-form { margin-top:18px; }
.panel>.panel-heading+.table-scroll { margin-top:5px; }
.table-scroll { width:100%; overflow:auto; }
table { width:100%; border-collapse:collapse; text-align:left; }
th,td { padding:12px 10px; border-bottom:1px solid var(--line); font-size:11px; white-space:nowrap; }
th { color:var(--muted); font-size:9px; font-weight:750; letter-spacing:.04em; text-transform:uppercase; }
td { color:var(--text); }
td.note-cell { max-width:230px; overflow:hidden; text-overflow:ellipsis; }
td.number,th.number { text-align:right; }
td.actions { text-align:right; }
.table-action { padding:5px 8px; border:0; border-radius:6px; background:var(--surface-soft); color:var(--muted); font-size:10px; cursor:pointer; }
.table-action:hover { color:var(--primary); }
.table-action.delete:hover { background:#fff0ef; color:var(--danger); }
.empty-state { padding:22px 10px; color:var(--muted); font-size:11px; text-align:center; }
.record-list { display:grid; gap:12px; }
.record-card { padding:17px 18px; border:1px solid var(--line); border-radius:13px; background:var(--surface); box-shadow:var(--shadow); }
.record-header { display:flex; align-items:flex-start; justify-content:space-between; gap:15px; }
.record-header h3 { margin:0 0 5px; font-size:14px; }
.record-header p { margin:0; color:var(--muted); font-size:10px; }
.record-amount { text-align:right; }
.record-amount strong { display:block; font-size:16px; }
.record-amount small { display:block; margin-top:4px; color:var(--muted); font-size:10px; }
.record-progress { height:6px; margin:15px 0 11px; overflow:hidden; border-radius:10px; background:var(--surface-soft); }
.record-progress span { display:block; height:100%; border-radius:inherit; background:var(--primary); }
.progress-0 span { width:0%; }
.progress-10 span { width:10%; }
.progress-20 span { width:20%; }
.progress-30 span { width:30%; }
.progress-40 span { width:40%; }
.progress-50 span { width:50%; }
.progress-60 span { width:60%; }
.progress-70 span { width:70%; }
.progress-80 span { width:80%; }
.progress-90 span { width:90%; }
.progress-100 span { width:100%; }
.record-meta { display:flex; align-items:center; justify-content:space-between; gap:12px; color:var(--muted); font-size:10px; }
.record-actions { display:flex; gap:8px; }
.master-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:start; gap:18px; }
.compact-form { gap:11px; margin:17px 0 18px; }
.button-row { display:flex; gap:8px; }
.type-pills { display:flex; align-items:center; flex-wrap:wrap; gap:9px; margin-top:17px; }
.type-pill { padding:9px 11px; border-radius:8px; background:var(--primary-soft); color:var(--primary-strong); font-size:11px; font-weight:700; }
.type-pill.expense { background:#fff0ef; color:var(--danger); }
.type-pills p { flex-basis:100%; margin:2px 0 0; font-size:11px; }
.theme-options { display:flex; flex-wrap:wrap; gap:10px; margin-top:17px; }
.theme-choice { display:flex; align-items:center; gap:8px; padding:9px 12px; border:1px solid var(--line); border-radius:8px; background:var(--surface); font-size:11px; cursor:pointer; }
.theme-choice i { width:13px; height:13px; border-radius:50%; background:#138b68; }
.theme-choice[data-theme="blue"] i { background:#3979c4; }
.theme-choice[data-theme="violet"] i { background:#7958b7; }
.theme-choice[data-theme="dark"] i { background:#26332e; }
.theme-choice.active { border-color:var(--primary); box-shadow:0 0 0 2px var(--primary-soft); }
.settings-form { max-width:520px; }
.app-footer { padding:9px 2px; color:var(--muted); font-size:9px; text-align:center; }
.ledger-dialog { width:min(680px,calc(100% - 26px)); max-height:min(90vh,760px); padding:24px; border:1px solid var(--line); border-radius:17px; background:var(--surface); color:var(--text); box-shadow:0 22px 70px rgba(0,0,0,.2); }
.ledger-dialog::backdrop { background:rgba(12,24,18,.52); backdrop-filter:blur(3px); }
.dialog-heading { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:12px; }
.dialog-heading h2 { margin:0; font-size:20px; }
.icon-button { font-size:27px; line-height:1; }
.ledger-summary { display:flex; flex-wrap:wrap; gap:8px 20px; margin:12px 0; color:var(--muted); font-size:11px; }
.ledger-summary strong { color:var(--text); }
.payment-form { grid-template-columns:repeat(2,minmax(0,1fr)); padding:15px; border-radius:11px; background:var(--surface-soft); }
.toast { position:fixed; z-index:10; right:25px; bottom:25px; max-width:min(390px,calc(100% - 32px)); padding:12px 16px; border-radius:10px; background:#263a32; color:white; box-shadow:var(--shadow); font-size:12px; opacity:0; pointer-events:none; transform:translateY(8px); transition:opacity .18s,transform .18s; }
.toast.visible { opacity:1; transform:translateY(0); }
@media(max-width:1150px) {
  .main-area { padding-right:25px; padding-left:25px; }
  .stats-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
}
@media(max-width:760px) {
  .sidebar { position:fixed; inset:0 auto 0 0; width:66px; height:100vh; padding:14px 7px 10px; border-right:1px solid var(--line); border-bottom:0; }
  .brand { justify-content:center; padding:0 0 20px; }
  .brand-copy,.sidebar-user>div,.nav-label,.logout-label { display:none; }
  .brand-mark.small { width:34px; height:34px; }
  .main-nav { display:grid; gap:7px; overflow:visible; padding:0; }
  .nav-link { justify-content:center; width:100%; min-width:0; min-height:42px; gap:0; padding:8px 4px; font-size:0; }
  .nav-link span:first-child { width:auto; font-size:18px; }
  .sidebar-foot { display:grid; justify-items:center; gap:12px; padding:12px 0 2px; }
  .sidebar-user { justify-content:center; }
  .sidebar-foot .avatar { width:30px; height:30px; }
  .logout-link { min-height:38px; padding:7px 4px; }
  .app-shell { display:block; }
  .main-area { width:calc(100% - 66px); margin-left:66px; padding:0 16px 20px; }
  .topbar { min-height:73px; }
  .today-label { display:none; }
  .topbar-right .avatar { margin-left:0; }
  .page { padding-top:18px; gap:14px; }
  .stats-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:9px; }
  .stat-card { min-height:108px; padding:14px; }
  .stats-grid.compact { grid-template-columns:repeat(3,minmax(0,1fr)); }
  .stats-grid.compact .stat-card { padding:12px 10px; }
  .stats-grid.compact .stat-top { align-items:flex-start; font-size:9px; }
  .stats-grid.compact .stat-icon { width:23px; height:23px; }
  .stats-grid.compact .stat-card strong { font-size:14px; }
  .master-grid { grid-template-columns:1fr; }
  .transaction-form { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .transaction-form .wide { grid-column:span 2; }
  .transaction-form>.button { grid-column:span 2; }
  .chart-wrap { height:220px; }
  .chart-heading { display:grid; }
  .chart-controls { justify-content:flex-start; }
  .chart-controls label { min-width:calc(50% - 6px); }
  .transaction-filters { grid-template-columns:1fr; }
}
@media(max-width:430px) {
  .auth-card { padding:27px 22px; }
  .welcome-row { align-items:flex-start; }
  .welcome-row .button { flex:none; padding:8px 10px; font-size:10px; }
  .welcome-row h2 { font-size:18px; }
  .stats-grid.compact { grid-template-columns:1fr; }
  .stats-grid.compact .stat-card { min-height:90px; }
  .transaction-form { grid-template-columns:1fr; }
  .transaction-form .wide,.transaction-form>.button { grid-column:span 1; }
  .record-header { flex-direction:column; }
  .record-amount { text-align:left; }
  .record-meta { align-items:flex-start; flex-direction:column; }
  .payment-form { grid-template-columns:1fr; }
  .payment-form .wide,.payment-form>.button { grid-column:auto; }
  th,td { padding:10px 8px; }
}
