/* ─── Reset & Variables ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #22262f;
  --border: #2c313c;
  --text: #eef0f4;
  --text-dim: #9aa1ad;
  --accent: #5b8cff;
  --warn: #e0a63c;
  --danger: #e2554f;
}

@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f7; --surface: #fff; --surface-2: #f0f1f4; --border: #e2e4e9; --text: #191b1f; --text-dim: #5c626e; }
}
:root[data-theme="light"] { --bg: #f4f5f7; --surface: #fff; --surface-2: #f0f1f4; --border: #e2e4e9; --text: #191b1f; --text-dim: #5c626e; }
:root[data-theme="dark"] { --bg: #0f1115; --surface: #1a1d24; --surface-2: #22262f; --border: #2c313c; --text: #eef0f4; --text-dim: #9aa1ad; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; }

/* ─── Header ────────────────────────────────────────────────────────── */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { font-size: 22px; font-weight: 700; }
.top .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #3ecf6a; margin-right: 4px; }
.sync-dot.offline { background: var(--danger); }

.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 16px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ─── Hero ──────────────────────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.hero-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-align: center; }
.hero-val { font-size: 22px; font-weight: 700; }
.hero-label { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* ─── Panels ────────────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.week-tag { font-size: 11px; font-weight: 600; color: var(--accent); background: rgba(91,140,255,0.12); padding: 3px 8px; border-radius: 20px; }
.hint { color: var(--text-dim); font-size: 13px; }

/* ─── Savings ─────────────────────────────────────────────────────────── */
.savings-headline { margin-bottom: 14px; }
.savings-amt { font-size: 20px; font-weight: 700; }
.savings-msg { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.goal-list { display: flex; flex-direction: column; gap: 14px; }

/* ─── Category rows ─────────────────────────────────────────────────── */
.cat-list { display: flex; flex-direction: column; gap: 14px; }
.cat-row-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.cat-name { font-weight: 600; }
.cat-amt { color: var(--text-dim); }
.bar-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.cat-row-bottom { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.cat-row.other { padding-top: 6px; border-top: 1px dashed var(--border); }

/* ─── History strip ─────────────────────────────────────────────────── */
.history-strip { display: flex; gap: 10px; align-items: flex-end; height: 140px; overflow-x: auto; }
.history-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1 0 40px; height: 100%; }
.history-bar-wrap { flex: 1; display: flex; align-items: flex-end; width: 100%; }
.history-bar { width: 100%; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.history-income { font-size: 10px; color: #3ecf6a; margin-top: 4px; }
.history-date { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ─── Settings modal ─────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal h3 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 0 10px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; color: var(--text); font-size: 13px; }

.cat-edit-list { display: flex; flex-direction: column; gap: 8px; }
.cat-edit-row { display: flex; align-items: center; gap: 8px; }
.cat-edit-name { flex: 1; font-size: 13px; }
.cat-edit-limit { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; color: var(--text); }

.dollar-input { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 0 8px; width: 110px; }
.dollar-input span { color: var(--text-dim); font-size: 13px; }
.dollar-input input { background: transparent; border: none; padding: 8px 4px; color: var(--text); width: 100%; font-size: 13px; }
.dollar-input input:focus { outline: none; }

.add-cat-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.add-cat-row select { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; color: var(--text); font-size: 13px; }

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 18px; font-size: 13px; opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .hero { grid-template-columns: repeat(2, 1fr); }
}
