:root {
  --bg: #0b0f14; --bg-1: #11161d; --bg-2: #161c25; --bg-3: #1c2430;
  --border: #232c39; --border-2: #2c3747;
  --text: #e8edf4; --muted: #8a97a8; --faint: #5d6b7d;
  --accent: #34d399; --accent-2: #22d3ee;
  --grad: linear-gradient(135deg, #34d399, #22d3ee);
  --income: #34d399; --expense: #fb7185;
  --danger: #f4607a; --warn: #fbbf24;
  --shadow: 0 18px 50px -12px rgba(0,0,0,.6);
  --radius: 16px;
}
[data-theme="light"] {
  --bg: #f3f6fa; --bg-1: #ffffff; --bg-2: #ffffff; --bg-3: #eef2f7;
  --border: #e3e9f0; --border-2: #d6deea;
  --text: #16202c; --muted: #5d6b7d; --faint: #94a3b4;
  --shadow: 0 18px 44px -16px rgba(20,40,70,.22);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; } /* no pull-to-refresh / rubber-band in standalone */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
  font-size: 14.5px; line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: 11px; padding: 11px 13px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52,211,153,.16); }
::placeholder { color: var(--faint); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary { background: var(--grad); color: #05231b; font-weight: 700; border-radius: 12px; padding: 11px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .12s, filter .15s; }
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary.lg { width: 100%; padding: 13px; font-size: 15px; }
.btn-ghost { background: var(--bg-3); border: 1px solid var(--border-2); border-radius: 11px; padding: 10px 14px; color: var(--text); font-weight: 600; }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: rgba(244,96,122,.12); color: var(--danger); border: 1px solid rgba(244,96,122,.3); border-radius: 11px; padding: 10px 14px; font-weight: 600; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); }
.login::before { content: ""; position: fixed; inset: 0; background: radial-gradient(900px 500px at 50% -10%, rgba(52,211,153,.18), transparent 60%), radial-gradient(700px 500px at 90% 110%, rgba(34,211,238,.14), transparent 55%); pointer-events: none; }
.login-card { position: relative; width: 100%; max-width: 380px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 22px; padding: 34px 28px; box-shadow: var(--shadow); text-align: center; }
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 2px; font-size: 24px; letter-spacing: -.02em; }
.login-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 11px; }
.login-error { background: rgba(244,96,122,.12); color: var(--danger); border-radius: 10px; padding: 9px; font-size: 13px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.sidebar { background: var(--bg-1); border-right: 1px solid var(--border); padding: 20px 16px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.brand-logo { font-size: 22px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--bg-3); color: var(--text); }
.nav-item.active .ic { color: var(--accent); }
.add-side { margin-top: auto; }

.content { min-width: 0; padding: 26px 30px 40px; max-width: 1080px; width: 100%; margin: 0 auto; }
.bottom-nav { display: none; }

/* ---------- View header ---------- */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.month-picker { display: flex; align-items: center; gap: 4px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.month-picker button { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.month-picker button:hover { background: var(--bg-3); color: var(--text); }
.month-picker .mp-label { min-width: 116px; text-align: center; font-weight: 700; font-size: 14px; }
.mp-prev .ic { transform: rotate(180deg); }

/* ---------- Cards & grid ---------- */
.card { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px; }
.card-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 14px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, 1fr); }
.stat { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 25px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.stat .chip { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.pos { color: var(--income); } .neg { color: var(--expense); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }

/* ---------- Donut ---------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { flex-shrink: 0; }
.donut-center { font-size: 12px; }
.legend { display: flex; flex-direction: column; gap: 9px; flex: 1; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.legend-pct { color: var(--faint); width: 38px; text-align: right; font-size: 12px; }
.empty-mini { color: var(--faint); font-size: 13.5px; text-align: center; padding: 26px 0; }

/* ---------- Trend bars ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 6px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.bar { width: 12px; border-radius: 5px 5px 0 0; min-height: 3px; transition: height .4s ease; }
.bar.inc { background: linear-gradient(var(--income), #2bb98a); }
.bar.exp { background: linear-gradient(var(--expense), #e04766); }
.bar-label { font-size: 11px; color: var(--muted); }
.bars-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.bars-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Budget rows ---------- */
.budget-row { margin-bottom: 15px; }
.budget-row:last-child { margin-bottom: 0; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; margin-bottom: 6px; }
.budget-top .bt-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.budget-top .bt-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; background: var(--bg-3); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .5s ease; }
.bar-fill.over { background: var(--danger) !important; }

/* ---------- Transactions list ---------- */
.tx-day { margin-top: 18px; }
.tx-day:first-child { margin-top: 0; }
.tx-day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 0 4px 8px; }
.tx { display: flex; align-items: center; gap: 13px; padding: 12px 14px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 13px; margin-bottom: 8px; transition: border-color .15s, transform .1s; }
.tx:hover { border-color: var(--border-2); }
.tx-icon { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-weight: 600; }
.tx-note { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.tx:hover .tx-actions { opacity: 1; }
.tx-actions button { width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--faint); }
.tx-actions button:hover { background: var(--bg-3); color: var(--text); }
.tx-actions .ic { width: 16px; height: 16px; }
.rec-badge { font-size: 11px; opacity: .65; }
/* Touch devices have no hover — keep edit/delete reachable. */
@media (hover: none) { .tx-actions, .cat-card .tx-actions { opacity: 1; } }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.repeat-toggle { display: flex; align-items: center; gap: 11px; padding: 12px 14px; background: var(--bg-3); border: 1px solid var(--border-2); border-radius: 12px; margin-bottom: 14px; cursor: pointer; font-weight: 600; font-size: 13.5px; user-select: none; }
.repeat-toggle input { width: 18px; height: 18px; }
.repeat-hint { font-size: 12px; color: var(--muted); margin: -8px 0 14px; }
.month-summary { display: flex; gap: 22px; padding: 14px 16px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 13px; margin-bottom: 16px; }
.month-summary div span { display: block; font-size: 12px; color: var(--muted); }
.month-summary div b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* ---------- Categories ---------- */
.cat-section { margin-bottom: 26px; }
.cat-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 12px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 11px; }
.cat-card { display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 14px; }
.cat-ic { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-weight: 700; }
.cat-budget { font-size: 12.5px; color: var(--muted); }
.cat-card .tx-actions { opacity: .55; }
.cat-card:hover .tx-actions { opacity: 1; }

/* ---------- Settings ---------- */
.settings-card { max-width: 520px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row .set-label b { display: block; }
.set-row .set-label span { font-size: 12.5px; color: var(--muted); }
.set-row input, .set-row select { width: auto; min-width: 90px; }
.theme-toggle { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(4,7,11,.66); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 18px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-card { width: 100%; max-width: 440px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 20px; padding: 22px; box-shadow: var(--shadow); animation: pop .2s ease; max-height: 92vh; overflow-y: auto; }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-head button { color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }
.seg { display: flex; background: var(--bg-3); border-radius: 11px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 9px; border-radius: 8px; font-weight: 700; color: var(--muted); transition: .15s; }
.seg button.on[data-v="expense"] { background: rgba(251,113,133,.16); color: var(--expense); }
.seg button.on[data-v="income"] { background: rgba(52,211,153,.16); color: var(--income); }
.amount-input { position: relative; }
.amount-input .cur { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.amount-input input { padding-left: 30px; font-size: 22px; font-weight: 800; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-row button { width: 38px; height: 38px; border-radius: 10px; font-size: 19px; background: var(--bg-3); border: 1px solid transparent; }
.emoji-row button.on { border-color: var(--accent); background: var(--bg-2); }
.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-row button { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; }
.color-row button.on { border-color: var(--text); transform: scale(1.12); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn-primary { flex: 1; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--bg-2); border: 1px solid var(--border-2); color: var(--text); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px; animation: pop .2s ease; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state .big { font-size: 44px; margin-bottom: 10px; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: calc(18px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
  .stats { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .view-head h2 { font-size: 21px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--bg-1); border-top: 1px solid var(--border);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); justify-content: space-around; align-items: center;
  }
  .bottom-nav .nav-item { flex-direction: column; gap: 0; padding: 8px 14px; color: var(--muted); }
  .bottom-nav .nav-item.active { background: none; color: var(--accent); }
  .add-fab { width: 52px; height: 52px; border-radius: 16px; background: var(--grad); color: #05231b; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px -6px rgba(52,211,153,.5); margin-top: -22px; }
  .add-fab .ic { width: 24px; height: 24px; stroke-width: 2.4; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-card { max-width: 100%; border-radius: 22px 22px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); animation: slideup .22s ease; }
  @keyframes slideup { from { transform: translateY(100%); } }
}
