:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --panel-raised: #111113;
  --panel-raised-2: #17171a;
  --border: #1f1f22;
  --border-soft: #17171a;
  --border-strong: #2a2a2e;
  --text: #f4f4f5;
  --text-dim: #d4d4d8;
  --muted: #86868c;
  --muted-2: #55555b;
  --accent: #ffffff;
  --accent-text: #000000;
  --review: #eab308;
  --review-bg: rgba(234, 179, 8, 0.1);
  --want: #f5654a;
  --want-bg: rgba(245, 101, 74, 0.12);
  --need: #33c07f;
  --need-bg: rgba(51, 192, 127, 0.12);
  --credit: #33c07f;
  --debit: #f5654a;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::selection { background: rgba(244,244,245,0.16); color: var(--text); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: padding-box; }

/* ---------- header ---------- */
header {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--need); font-size: 0.6rem; }
header h1 { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.01em; }

.tabs {
  display: flex; gap: 2px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms var(--ease), color 180ms var(--ease);
}
.tab-btn.active { background: var(--accent); color: var(--accent-text); }
.tab-btn:not(.active):hover { color: var(--text); }

/* ---------- range bar (time-range control shared by both tabs) ---------- */
.range-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 53px);
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  z-index: 19;
}
.range-nav {
  display: flex; align-items: center; gap: 12px;
}
.range-nav button {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: transform 150ms var(--ease), background 150ms var(--ease), border-color 150ms var(--ease);
}
.range-nav button:hover { border-color: var(--muted); transform: translateY(-1px); }
.range-nav button:active { transform: scale(0.92); }
.range-nav h2 { margin: 0; font-size: 0.95rem; font-weight: 600; min-width: 150px; text-align: center; }
.today-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 160ms var(--ease);
  flex-shrink: 0;
}
.today-btn:hover { color: var(--text); border-color: var(--muted); }
.today-btn:active { transform: scale(0.95); }

/* ---------- stats bar ---------- */
.stats-bar {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  overflow-x: auto;
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 53px + 55px);
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(10px);
  z-index: 18;
}
.stat-block {
  padding: 14px 22px 14px 0;
  margin-right: 22px;
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 3px;
  animation: fadeSlideUp 320ms var(--ease) backwards;
  white-space: nowrap;
}
.stat-block:last-child { border-right: none; }
.stat-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; transition: color 200ms var(--ease); }
.stat-value.debit-text { color: var(--debit); }
.stat-value.credit-text { color: var(--credit); }
.stat-value.net-positive { color: var(--need); }
.stat-value.net-negative { color: var(--want); }

/* ---------- layout ---------- */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  width: 100%;
}
.view { animation: fadeSlideUp 260ms var(--ease); }
/* .hidden must always win over #view-calendar's own display:grid rule below —
   an id selector otherwise beats a two-class selector regardless of source
   order, which silently kept the calendar in the DOM flow on the Analytics
   tab. !important pins it. */
.view.hidden { display: none !important; }
.view.view-out { animation: viewOut 140ms var(--ease) forwards; }
.view.view-in { animation: viewIn 260ms var(--ease); }
@keyframes viewOut { to { opacity: 0; transform: translateY(4px); } }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.view#view-calendar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}
@media (min-width: 820px) {
  .view#view-calendar { grid-template-columns: 1.35fr 1fr; }
}

.panel, .calendar-panel, .day-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  transition: border-color 220ms var(--ease);
}
.panel h3 {
  margin: 0 0 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- calendar ---------- */
.cal-grid-wrapper { overflow: hidden; position: relative; }
.cal-grid-wrapper.slide-out-left .cal-grid { animation: outLeft 150ms var(--ease) forwards; }
.cal-grid-wrapper.slide-out-right .cal-grid { animation: outRight 150ms var(--ease) forwards; }
.cal-grid-wrapper.slide-in-right .cal-grid { animation: inRight 220ms var(--ease) backwards; }
.cal-grid-wrapper.slide-in-left .cal-grid { animation: inLeft 220ms var(--ease) backwards; }
@keyframes outLeft { to { transform: translateX(-20px); opacity: 0; } }
@keyframes outRight { to { transform: translateX(20px); opacity: 0; } }
@keyframes inRight { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes inLeft { from { transform: translateX(-20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 0.65rem; color: var(--muted-2); padding-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.cal-cell {
  min-height: 64px;
  border-radius: 9px;
  border: 1px solid var(--border-soft);
  padding: 6px;
  cursor: pointer;
  background: var(--panel-raised);
  position: relative;
  overflow: hidden;
  transition: border-color 160ms var(--ease), transform 160ms var(--ease);
  animation: cellIn 240ms var(--ease) backwards;
}
@keyframes cellIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.cal-cell.empty { background: transparent; border-color: transparent; cursor: default; animation: none; }
.cal-cell:hover:not(.empty) { border-color: var(--muted); transform: translateY(-2px); }
.cal-cell.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cal-cell.today .daynum { color: var(--text); font-weight: 700; }
.cal-cell.today::before {
  content: ""; position: absolute; top: 5px; left: 5px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--accent);
}
.cal-cell .daynum { font-size: 0.7rem; color: var(--muted); }
.cal-cell .daytotal { font-family: var(--font-mono); font-size: 0.74rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

.split-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; display: flex; overflow: hidden; }
.split-bar .seg { height: 100%; transition: width 300ms var(--ease); }
.split-bar .need { background: var(--need); }
.split-bar .want { background: var(--want); }
.split-bar .unset { background: #2a2a2d; }

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.review { background: var(--review); }
.dot.corner { position: absolute; top: 6px; right: 6px; box-shadow: 0 0 0 3px rgba(234,179,8,0.12); }

.legend { display: flex; gap: 16px; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--border-soft); font-size: 0.72rem; color: var(--muted); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }

/* ---------- day panel ---------- */
.day-panel { display: flex; flex-direction: column; min-height: 0; }
.day-panel-inner { display: flex; flex-direction: column; min-height: 0; }
.day-panel h3 { margin: 0 0 12px; font-size: 0.9rem; font-weight: 600; flex-shrink: 0; }
.day-panel.panel-enter { animation: fadeSlideUp 240ms var(--ease); }
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.empty-hint { color: var(--muted); font-size: 0.85rem; }

.txn-list {
  overflow-y: auto;
  min-height: 0;
  max-height: calc(100dvh - 260px);
  padding-right: 4px;
  margin-right: -4px;
}
@media (min-width: 820px) {
  .txn-list { max-height: calc(100dvh - 300px); }
}
.txn-list::-webkit-scrollbar { width: 6px; }
.txn-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.txn-list::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

.txn-card {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--panel-raised);
  animation: fadeSlideUp 280ms var(--ease) backwards;
  transition: border-color 200ms var(--ease);
}
.txn-card.needs-review { border-color: var(--review); background: color-mix(in srgb, var(--review) 7%, var(--panel-raised)); }
.txn-card.st-need { border-color: var(--need); background: color-mix(in srgb, var(--need) 7%, var(--panel-raised)); }
.txn-card.st-want { border-color: var(--want); background: color-mix(in srgb, var(--want) 7%, var(--panel-raised)); }

.txn-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; gap: 10px; }
.txn-merchant { font-weight: 600; font-size: 0.88rem; }
.txn-amount { font-family: var(--font-mono); font-size: 0.88rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.txn-amount.debit { color: var(--debit); }
.txn-amount.credit { color: var(--credit); }
.txn-meta { font-size: 0.7rem; color: var(--muted); margin-bottom: 10px; }

.spend-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.st-btn {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  padding: 6px 8px; border-radius: 7px; font-size: 0.74rem; cursor: pointer;
  transition: all 160ms var(--ease);
}
.st-btn:hover { border-color: var(--muted); color: var(--text); }
.st-btn:active { transform: scale(0.96); }
.st-btn.need.active { background: rgba(62,207,142,0.12); border-color: var(--need); color: var(--need); }
.st-btn.want.active { background: rgba(240,71,71,0.12); border-color: var(--want); color: var(--want); }

.txn-edit { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.txn-edit select, .txn-edit input[type=text] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 0.76rem;
  transition: border-color 160ms var(--ease);
}
.txn-edit select:focus, .txn-edit input[type=text]:focus { outline: none; border-color: var(--muted); }
.txn-edit select { flex: 1; min-width: 118px; }
.txn-edit input[type=text] { flex: 2; min-width: 130px; }
.txn-edit button {
  background: var(--accent); border: none; color: var(--accent-text);
  padding: 6px 13px; border-radius: 6px; font-size: 0.76rem; font-weight: 600; cursor: pointer;
  transition: transform 150ms var(--ease), opacity 150ms var(--ease);
}
.txn-edit button:hover { transform: translateY(-1px); }
.txn-edit button:active { transform: scale(0.94); }
.txn-edit button.saving { opacity: 0.5; cursor: default; }
.saved-tick { color: var(--need); font-size: 0.72rem; margin-left: 2px; }
.saved-tick.pulse { animation: tickPulse 420ms var(--ease); }
@keyframes tickPulse { 0% { opacity: 0; transform: scale(0.7); } 60% { opacity: 1; transform: scale(1.15); } 100% { transform: scale(1); } }

/* ---------- analytics ---------- */
.analytics-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 820px) { .analytics-grid { grid-template-columns: 1fr 1fr; } }
.chart-panel { grid-column: 1 / -1; }

.scroll-region { max-height: 320px; overflow-y: auto; padding-right: 4px; margin-right: -4px; }
.scroll-region::-webkit-scrollbar { width: 6px; }
.scroll-region::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .bar-label { width: 130px; font-size: 0.76rem; color: var(--muted); flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; height: 20px; background: var(--panel-raised); border-radius: 5px; overflow: hidden; position: relative; }
.bar-row .bar-fill { height: 100%; border-radius: 5px; background: var(--text); transition: width 500ms var(--ease); animation: barGrow 500ms var(--ease) backwards; }
@keyframes barGrow { from { width: 0 !important; } }
.bar-row .bar-value { width: 74px; text-align: right; font-family: var(--font-mono); font-size: 0.76rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.daily-chart-svg { width: 100%; height: auto; display: block; }
.daily-chart-svg rect { transition: opacity 150ms var(--ease); }
.daily-chart-svg rect:hover { opacity: 0.7; }

.merchant-row {
  display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid var(--border-soft); font-size: 0.8rem;
}
.merchant-row:last-child { border-bottom: none; }
.merchant-row .m-name { color: var(--text); }
.merchant-row .m-meta { color: var(--muted); font-size: 0.7rem; }
.merchant-row .m-amt { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; }

.trend-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 0.8rem; }
.trend-row:last-child { border-bottom: none; }
.trend-row span:first-child, .trend-row span:last-child { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.trend-row .t-bar { flex: 1; height: 6px; background: var(--panel-raised); border-radius: 3px; margin: 0 12px; overflow: hidden; }
.trend-row .t-fill { height: 100%; background: var(--text); border-radius: 3px; transition: width 500ms var(--ease); }
.empty-chart { color: var(--muted); font-size: 0.8rem; padding: 20px 0; text-align: center; }

/* ---------- overview metrics ---------- */
.overview-panel { grid-column: 1 / -1; }
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.overview-card {
  background: var(--panel-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 5px;
  animation: fadeSlideUp 320ms var(--ease) backwards;
  transition: border-color 200ms var(--ease);
}
.overview-card:hover { border-color: var(--border-strong); }
.overview-card .ov-label { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.overview-card .ov-value { font-family: var(--font-mono); font-size: 1.02rem; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overview-card .ov-sub { font-size: 0.68rem; color: var(--muted-2); }

/* ---------- need vs want donut ---------- */
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; justify-content: center; padding: 4px 0; }
.donut {
  position: relative;
  width: 132px; height: 132px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: fadeSlideUp 380ms var(--ease) backwards;
  transition: background 500ms var(--ease);
}
.donut-hole {
  position: absolute; inset: 16px;
  border-radius: 50%;
  background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
}
.donut-hole .donut-total { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 700; color: var(--text); }
.donut-hole .donut-sub { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.donut-legend { display: flex; flex-direction: column; gap: 10px; font-size: 0.8rem; min-width: 150px; flex: 1; }
.donut-legend .leg-row { display: flex; align-items: center; gap: 8px; }
.donut-legend .leg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.donut-legend .leg-name { color: var(--text-dim); }
.donut-legend .leg-pct { color: var(--muted); font-size: 0.72rem; }
.donut-legend .leg-amt { margin-left: auto; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------- responsive ---------- */
@media (max-width: 479px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 0.95rem; }
  .range-bar { padding: 10px 16px; top: calc(env(safe-area-inset-top, 0px) + 49px); }
  .range-nav h2 { min-width: 120px; font-size: 0.85rem; }
  .stats-bar { padding: 0 16px; top: calc(env(safe-area-inset-top, 0px) + 49px + 49px); }
  .stat-block { padding: 12px 16px 12px 0; margin-right: 16px; }
  .stat-value { font-size: 1rem; }
  main { padding: 16px 12px 40px; }
  .cal-cell { min-height: 50px; }
  .today-btn { padding: 6px 10px; font-size: 0.7rem; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .donut-wrap { gap: 16px; justify-content: flex-start; }
  .donut { width: 108px; height: 108px; }
  .donut-hole { inset: 13px; }
  .donut-legend { min-width: 0; }
}

@media (min-width: 1400px) {
  main { max-width: 1320px; }
}
