*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f0f13; --surface: #18181f; --surface2: #1f1f29; --surface3: #26262f;
  --border: rgba(255,255,255,0.07); --border2: rgba(255,255,255,0.12);
  --text: #f0eff4; --muted: #7e7d8a;
  --accent: #7c6ff7; --accent2: #5ce0c8;
  --green: #4ade80; --amber: #fbbf24; --red: #f87171; --blue: #60a5fa; --grey: #7e7d8a;
  --fixed-color: #7c6ff7; --var-color: #5ce0c8; --once-color: #fbbf24;
  --income-color: #4ade80; --refund-color: #60a5fa; --transfer-color: #a78bfa;
  --font: 'DM Sans', sans-serif; --mono: 'DM Mono', monospace;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; padding-bottom: 40px; }
button, input, select, textarea { font-family: var(--font); }
a { color: var(--accent2); }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; align-items: center; height: 58px; position: sticky; top: 0; z-index: 100; gap: 20px; }
.topbar-logo { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tabbar { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.tab-btn { background: transparent; border: none; color: var(--muted); font-size: 13px; font-weight: 500; padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: all .15s; }
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--text); background: var(--surface2); box-shadow: inset 0 0 0 1px var(--border2); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.sync-pill { display: flex; align-items: center; gap: 6px; background: var(--surface2); border: 1px solid var(--border2); border-radius: 20px; padding: 5px 12px; font-size: 11px; color: var(--muted); cursor: pointer; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sync-dot.ok { background: var(--green); } .sync-dot.busy { background: var(--amber); animation: pulse 1s infinite; } .sync-dot.err { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.icon-btn { background: var(--surface2); border: 1px solid var(--border2); color: var(--text); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 16px; }

.dropdown-menu { position: fixed; top: 58px; right: 20px; background: var(--surface2); border: 1px solid var(--border2); border-radius: 12px; padding: 6px; z-index: 200; display: none; flex-direction: column; min-width: 220px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.dropdown-menu.open { display: flex; }
.dropdown-menu button { text-align: left; background: transparent; border: none; color: var(--text); padding: 9px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.dropdown-menu button:hover { background: var(--surface3); }
.dropdown-menu button.danger { color: var(--red); }

.main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }

.period-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.period-label { font-size: 14px; font-weight: 500; min-width: 170px; text-align: center; }
.nav-btn { background: var(--surface2); border: 1px solid var(--border2); color: var(--text); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 16px; }
.period-mode-toggle { display: flex; gap: 4px; margin-left: auto; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 3px; }
.pm-btn { background: transparent; border: none; color: var(--muted); font-size: 11px; padding: 5px 12px; border-radius: 16px; cursor: pointer; }
.pm-btn.active { background: var(--accent); color: #fff; }

.notice-banner { background: rgba(251,191,36,0.08); border: 1px solid rgba(251,191,36,0.2); border-radius: 12px; padding: 12px 18px; margin-bottom: 16px; font-size: 13px; color: var(--amber); display: flex; gap: 10px; }
.notice-banner.info { background: rgba(96,165,250,0.08); border-color: rgba(96,165,250,0.2); color: var(--blue); }
.notice-banner strong { display: block; margin-bottom: 2px; color: var(--text); }

/* Grids & panels */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.metric .m-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.metric .m-value { font-family: var(--mono); font-size: 20px; font-weight: 500; letter-spacing: -0.02em; }
.metric .m-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.metric .m-badge { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 20px; margin-top: 6px; font-weight: 500; }
.c-green{color:var(--green)} .c-red{color:var(--red)} .c-blue{color:var(--blue)} .c-amber{color:var(--amber)} .c-muted{color:var(--muted)}
.badge-green{background:rgba(74,222,128,.12);color:var(--green)} .badge-red{background:rgba(248,113,113,.12);color:var(--red)} .badge-amber{background:rgba(251,191,36,.12);color:var(--amber)} .badge-grey{background:rgba(126,125,138,.15);color:var(--muted)} .badge-blue{background:rgba(96,165,250,.12);color:var(--blue)}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.span2 { grid-column: span 2; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px 22px; }
.panel-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.panel-title .dot { width: 6px; height: 6px; border-radius: 50%; }
.panel-title .right { margin-left: auto; font-size: 11px; text-transform: none; letter-spacing: 0; }
.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; }

/* Health score */
.health-score-ring { display: flex; align-items: center; gap: 18px; }
.health-num { font-family: var(--mono); font-size: 36px; font-weight: 600; }
.health-breakdown { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.health-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.health-row .hb-track { flex: 1; height: 5px; background: rgba(255,255,255,.06); border-radius: 3px; overflow: hidden; }
.health-row .hb-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.health-row .hb-val { font-family: var(--mono); width: 56px; text-align: right; color: var(--text); }

/* Category bars / progress */
.cat-bars { display: flex; flex-direction: column; gap: 12px; }
.cat-bar { display: flex; flex-direction: column; gap: 5px; }
.cat-bar-header { display: flex; justify-content: space-between; align-items: center; }
.cat-bar-name { font-size: 12px; color: var(--muted); }
.cat-bar-val { font-family: var(--mono); font-size: 12.5px; font-weight: 500; }
.bar-track { height: 6px; background: rgba(255,255,255,0.06); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }
.bar-fill.green{background:var(--green)} .bar-fill.amber{background:var(--amber)} .bar-fill.red{background:var(--red)} .bar-fill.grey{background:var(--muted)}

.donut-legend { display: flex; flex-direction: column; gap: 9px; margin-top: 14px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-label { flex: 1; color: var(--muted); }
.legend-val { font-family: var(--mono); font-weight: 500; }
.legend-pct { font-size: 10.5px; color: var(--muted); min-width: 30px; text-align: right; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 11px; color: var(--muted); letter-spacing: 0.03em; }
.form-field input, .form-field select, .form-field textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 13px; padding: 9px 12px; outline: none; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--accent); }
.form-field textarea { resize: vertical; min-height: 50px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.checkbox-row input { width: auto; }
.btn { background: var(--accent); border: none; border-radius: 10px; color: #fff; font-size: 13px; font-weight: 600; padding: 10px 16px; cursor: pointer; }
.btn:hover { opacity: .9; }
.btn.secondary { background: var(--surface3); border: 1px solid var(--border2); color: var(--text); }
.btn.danger { background: rgba(248,113,113,.15); color: var(--red); border: 1px solid rgba(248,113,113,.3); }
.btn.small { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

.filter-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.ftab { font-size: 11px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 20px; cursor: pointer; background: transparent; color: var(--muted); }
.ftab:hover { border-color: var(--border2); color: var(--text); }
.ftab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.search-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search-row input[type=text], .search-row input[type=date], .search-row select { background: var(--surface2); border: 1px solid var(--border); border-radius: 9px; color: var(--text); font-size: 12.5px; padding: 7px 10px; }
.search-row input[type=text] { flex: 1; min-width: 140px; }

/* Lists */
.entry-list { display: flex; flex-direction: column; gap: 6px; }
.entry { display: flex; align-items: center; gap: 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.entry:hover { border-color: var(--border2); }
.entry-day { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 46px; white-space: nowrap; }
.entry-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.entry-desc { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { font-size: 10px; color: var(--muted); white-space: nowrap; }
.entry-cat { font-size: 10px; padding: 2px 8px; border-radius: 20px; flex-shrink: 0; }
.entry-amt { font-family: var(--mono); font-weight: 500; min-width: 84px; text-align: right; }
.entry-actions { display: flex; gap: 2px; flex-shrink: 0; }
.entry-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 3px 5px; border-radius: 5px; }
.entry-actions button:hover { color: var(--text); background: rgba(255,255,255,.08); }
.entry-actions button.del:hover { color: var(--red); background: rgba(248,113,113,.1); }
.empty-state { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 0; }

/* Commitment cards */
.commit-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.commit-top { display: flex; align-items: center; gap: 10px; }
.commit-name { font-weight: 500; flex: 1; }
.commit-amt { font-family: var(--mono); font-weight: 500; }
.commit-meta { font-size: 11px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.status-pill { font-size: 10px; padding: 2px 9px; border-radius: 20px; font-weight: 600; letter-spacing: .02em; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: flex-start; justify-content: center; z-index: 500; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border2); border-radius: 16px; padding: 22px 24px; width: 100%; max-width: 520px; }
.modal h3 { font-size: 15px; margin-bottom: 14px; }
.modal-close { float: right; background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }

.toast-stack { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 600; }
.toast { background: var(--surface2); border: 1px solid var(--border2); border-radius: 10px; padding: 10px 16px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.err { border-color: rgba(248,113,113,.4); color: var(--red); }
.toast.ok { border-color: rgba(74,222,128,.4); color: var(--green); }

.footer { text-align: center; padding: 20px; font-size: 11px; color: rgba(255,255,255,0.15); letter-spacing: 0.06em; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 60px; }
  .topbar { padding: 0 12px; flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; }
  .tabbar { order: 3; width: 100%; }
}
