/* ============ Ledger — crisp, high-contrast expense tracker ============ */

:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --border: #e7e7e3;
  --border-strong: #d8d8d3;
  --text: #16161a;
  --muted: #76767c;
  --faint: #a0a0a4;
  --accent: oklch(0.56 0.13 150);
  --accent-soft: oklch(0.95 0.04 150);
  --income: oklch(0.56 0.13 150);
  --income-soft: oklch(0.95 0.04 150);
  --expense: oklch(0.58 0.15 25);
  --expense-soft: oklch(0.95 0.04 25);
  --radius: 14px;
  --radius-sm: 10px;
  --pad: 22px;
  --font-ui: "Manrope", system-ui, sans-serif;
  --font-num: "Space Grotesk", "Manrope", sans-serif;
  --shadow: 0 1px 2px rgba(16,16,26,0.04), 0 1px 1px rgba(16,16,26,0.03);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
.num { font-family: var(--font-num); font-feature-settings: "tnum" 1; letter-spacing: -0.01em; }

/* ---------- shell ---------- */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 28px 80px;
}

/* ---------- sync ---------- */
.sync-btn { position: relative; }
.sync-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 999px; background: var(--faint); border: 2px solid var(--surface); }
.sync-dot.online { background: var(--income); }
.sync-dot.connecting { background: oklch(0.72 0.15 70); }
.sync-dot.error { background: var(--expense); }
.conn-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.conn-chip.ok { color: var(--income); }
.conn-chip strong { color: var(--text); }
.sync-err { font-size: 12.5px; font-weight: 600; color: var(--expense); background: var(--expense-soft); border: 1px solid color-mix(in oklch, var(--expense) 25%, transparent); border-radius: 9px; padding: 9px 11px; line-height: 1.45; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; flex: none;
}
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: -2px; font-weight: 600; white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- month switcher ---------- */
.month-switch {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.month-switch button {
  width: 30px; height: 30px; border: none; background: transparent;
  border-radius: 999px; color: var(--muted);
  display: grid; place-items: center;
}
.month-switch button:hover { background: var(--surface-2); color: var(--text); }
.month-switch .label { padding: 0 10px; font-weight: 700; font-size: 14px; min-width: 116px; text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 14px; padding: 9px 14px;
  box-shadow: var(--shadow); transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-primary:hover { background: oklch(0.51 0.13 150); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-icon { padding: 9px; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: var(--pad); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 800; letter-spacing: -0.01em; }
.card-title small { color: var(--muted); font-weight: 600; margin-left: 8px; letter-spacing: 0; }

/* ---------- summary stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.stat {
  padding: 20px 22px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat.balance { background: var(--text); border-color: var(--text); color: #fff; }
.stat.balance .stat-label { color: rgba(255,255,255,0.7); }
.stat-label { font-size: 12.5px; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 7px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-dot { width: 8px; height: 8px; border-radius: 999px; flex: none; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 12px; letter-spacing: -0.025em; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; font-weight: 600; }
.stat.balance .stat-sub { color: rgba(255,255,255,0.6); }

/* ---------- main grid ---------- */
.main-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; margin-bottom: 16px; }
.col { display: flex; flex-direction: column; gap: 16px; }

/* ---------- trend chart ---------- */
.trend-wrap { width: 100%; }
.legend { display: flex; gap: 16px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.seg {
  display: inline-flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 3px;
}
.seg button {
  border: none; background: transparent; padding: 5px 12px; border-radius: 6px;
  font-weight: 700; font-size: 12.5px; color: var(--muted);
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- donut / categories ---------- */
.cat-list { display: flex; flex-direction: column; gap: 13px; margin-top: 4px; }
.cat-row { display: flex; align-items: center; gap: 11px; }
.cat-name { font-weight: 700; font-size: 13.5px; flex: 1; }
.cat-bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; flex: 1.4; }
.cat-bar > span { display: block; height: 100%; border-radius: 999px; }
.cat-amt { font-weight: 700; font-size: 13px; min-width: 78px; text-align: right; }
.cat-pct { font-size: 11.5px; color: var(--faint); min-width: 34px; text-align: right; font-weight: 700; }

/* ---------- transactions ---------- */
.tx-toolbar { display: flex; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px; color: var(--muted);
}
.search input { border: none; background: transparent; outline: none; padding: 10px 0; font-size: 14px; width: 100%; color: var(--text); font-weight: 600; }
.filter-select {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px;
  padding: 9px 12px; font-size: 13.5px; font-weight: 700; color: var(--text); outline: none;
}

.tx-list { display: flex; flex-direction: column; }
.tx-day-label { font-size: 11.5px; font-weight: 800; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; padding: 16px 2px 8px; }
.tx-day-label:first-child { padding-top: 4px; }
.tx {
  display: flex; align-items: center; gap: 13px; padding: 11px 8px; border-radius: 10px;
  transition: background .12s ease; position: relative;
}
.tx:hover { background: var(--surface-2); }
.tx-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff;
}
.tx-main { flex: 1; min-width: 0; }
.tx-note { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; display: flex; align-items: center; gap: 7px; }
.tx-pill { font-size: 10.5px; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tx-amt { font-weight: 700; font-size: 15px; white-space: nowrap; }
.tx-amt.in { color: var(--income); }
.tx-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s ease; }
.tx:hover .tx-actions { opacity: 1; }
.tx-actions button { width: 30px; height: 30px; border: none; background: transparent; border-radius: 8px; color: var(--faint); display: grid; place-items: center; }
.tx-actions button:hover { background: var(--border); color: var(--text); }

/* ---------- recurring ---------- */
.rec-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.rec-row:last-child { border-bottom: none; }
.rec-main { flex: 1; min-width: 0; }
.rec-note { font-weight: 700; font-size: 14px; }
.rec-meta { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.rec-amt { font-weight: 700; font-size: 14px; }
.switch { width: 38px; height: 22px; border-radius: 999px; border: none; background: var(--border-strong); position: relative; transition: background .15s ease; flex: none; }
.switch.on { background: var(--accent); }
.switch span { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 999px; background: #fff; transition: transform .15s ease; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on span { transform: translateX(16px); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; margin: 0 auto 14px; color: var(--faint); }
.empty h3 { margin: 0 0 4px; font-size: 15px; color: var(--text); }
.empty p { margin: 0 0 16px; font-size: 13.5px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16,16,26,0.32); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 200; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 18px; border: 1px solid var(--border); box-shadow: 0 24px 60px rgba(16,16,26,0.22); overflow: hidden; animation: pop .18s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 800; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.type-toggle button { border: none; background: transparent; padding: 10px; border-radius: 9px; font-weight: 800; font-size: 14px; color: var(--muted); }
.type-toggle button.active-exp { background: var(--expense); color: #fff; }
.type-toggle button.active-inc { background: var(--income); color: #fff; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; font-weight: 600; color: var(--text); outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--accent); background: var(--surface); }
.amount-input { display: flex; align-items: center; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 0 14px; }
.amount-input:focus-within { border-color: var(--accent); background: var(--surface); }
.amount-input .cur { font-weight: 800; color: var(--muted); font-size: 16px; }
.amount-input input { border: none; background: transparent; padding: 13px 8px; font-size: 26px; font-weight: 700; width: 100%; outline: none; }

.cat-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.cat-chip { display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 7px 12px; font-size: 12.5px; font-weight: 700; color: var(--text); }
.cat-chip.sel { border-color: var(--text); background: var(--text); color: #fff; }
.cat-chip .dot { width: 9px; height: 9px; border-radius: 999px; flex: none; }

.recur-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.recur-box .rb-text { font-size: 13.5px; font-weight: 700; }
.recur-box .rb-text small { display: block; color: var(--muted); font-weight: 600; font-size: 11.5px; margin-top: 2px; }
.recur-freq { display: flex; gap: 6px; margin-top: 4px; }
.recur-freq button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 11px; font-size: 12px; font-weight: 700; color: var(--muted); }
.recur-freq button.active { border-color: var(--text); background: var(--text); color: #fff; }

.modal-foot { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1; justify-content: center; padding: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat.balance { grid-column: 1 / -1; }
  .main-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .app { padding: 18px 14px 80px; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 28px; }
  .brand-sub { display: none; }
  .topbar { flex-wrap: wrap; }
  .cat-amt { min-width: 64px; }
}
