/* Pennywise — clean personal finance app. Tokens first. */
:root {
  color-scheme: light;
  --bg: #f4f6f4;            /* page plane */
  --surface: #ffffff;       /* cards */
  --ink: #17201b;           /* primary text */
  --ink-2: #4d5a52;         /* secondary text */
  --ink-3: #7b8780;         /* muted */
  --hairline: #e3e8e4;
  --accent: #1f6f54;        /* deep green — money */
  --accent-strong: #17503d;
  --accent-soft: #e7f1ec;   /* tint for fills/tracks */
  --danger: #b3382e;
  --warn: #9a6b13;
  --focus: #1f6f54;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(23, 32, 27, .05), 0 6px 18px -8px rgba(23, 32, 27, .10);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, serif;
  /* chart series (categorical slots, light surface #ffffff) */
  --s1: #1f6f54;  /* green — accent series */
  --s2: #2a78d6;  /* blue */
  --s3: #eb6834;  /* orange */
  --s4: #1baf7a;
  --s5: #eda100;
  --s6: #4a3aa7;
  --s7: #e87ba4;
  --deemph: #c9d2cc; /* de-emphasis track / context series */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 36px);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--serif); font-size: 19px; font-weight: 600;
  color: var(--ink); text-decoration: none; letter-spacing: -0.01em;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: #eaf4ef;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 17px; height: 17px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------- buttons ---------------- */
.primary-btn {
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent-strong);
  padding: 10px 18px; border-radius: 10px;
  font-weight: 600; font-size: 14.5px;
  transition: background .15s ease, transform .06s ease;
}
.primary-btn:hover { background: var(--accent-strong); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.big { padding: 13px 24px; font-size: 15.5px; border-radius: 12px; }
.ghost-btn {
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--hairline);
  padding: 9px 16px; border-radius: 10px;
  font-weight: 500; font-size: 14px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s ease, border-color .15s ease;
}
.ghost-btn:hover { background: #fff; border-color: #cfd8d2; color: var(--ink); }
.ghost-btn.big { padding: 12px 22px; font-size: 15px; }
.small-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px;
}
.small-btn:hover { background: var(--accent-strong); }
.tiny-btn {
  background: transparent; border: 1px solid var(--hairline); color: var(--ink-2);
  padding: 4px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 500;
}
.tiny-btn:hover { background: #fff; color: var(--ink); }

/* ---------------- shell ---------------- */
.shell { max-width: 1120px; margin: 0 auto; padding: 26px clamp(16px, 4vw, 36px) 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-family: var(--serif); font-size: clamp(26px, 3.4vw, 32px); font-weight: 500; letter-spacing: -0.015em; }
.page-sub { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }

/* ---------------- KPI tiles ---------------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 18px 20px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.tile-label { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 7px; }
.tile-value {
  font-size: clamp(26px, 2.6vw, 31px); font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.1;
  font-variant-numeric: normal; /* proportional figures at display size */
}
.tile-value.is-negative { color: var(--danger); }
.tile-meta { margin-top: 7px; font-size: 12.5px; color: var(--ink-3); min-height: 18px; }

/* ---------------- filter row ---------------- */
.filter-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.segmented {
  display: inline-flex; background: #eceff0; padding: 3px;
  border-radius: 10px; border: 1px solid var(--hairline);
}
.seg-btn {
  border: none; background: transparent; color: var(--ink-2);
  padding: 7px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
}
.seg-btn.is-active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(23,32,27,.08); }
.budget-inline { display: flex; align-items: center; gap: 8px; }
.budget-inline label { font-size: 13.5px; color: var(--ink-2); }
.budget-inline input {
  width: 110px; padding: 8px 10px; border: 1px solid var(--hairline);
  border-radius: 9px; background: #fff; font-size: 14px;
}

/* ---------------- cards & grid ---------------- */
.grid-main {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow); min-width: 0;
  grid-column: span 12;
}
#trend-card { grid-column: span 7; }
#cat-card { grid-column: span 5; }
#budget-card { grid-column: span 5; }
#list-card { grid-column: span 7; }
@media (max-width: 880px) {
  #trend-card, #cat-card, #budget-card, #list-card { grid-column: span 12; }
}
@media (max-width: 640px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 16px 16px; }
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card-title { font-size: 15.5px; font-weight: 600; }
.card-sub { font-size: 12.5px; color: var(--ink-3); }

/* ---------------- charts ---------------- */
.chart { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 6px 0 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-line { width: 14px; height: 2px; border-radius: 1px; flex: none; }

/* tooltip */
.viz-tip {
  position: absolute; pointer-events: none; z-index: 30;
  background: #20302a; color: #fff;
  border-radius: 8px; padding: 8px 11px;
  font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 4px 14px rgba(23,32,27,.25);
  min-width: 120px; max-width: 240px;
}
.viz-tip .tt-label { color: #b8cdc3; font-size: 11.5px; margin-bottom: 2px; }
.viz-tip .tt-row { display: flex; align-items: center; gap: 8px; }
.viz-tip .tt-key { width: 12px; height: 2.5px; border-radius: 2px; flex: none; }
.viz-tip .tt-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.viz-tip .tt-name { color: #cfdad4; }

.chart-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13.5px; }
.chart-table th, .chart-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--hairline); }
.chart-table th:last-child, .chart-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table th { color: var(--ink-2); font-weight: 500; font-size: 12.5px; }
.hidden { display: none !important; }
.table-toggle-row { margin-top: 10px; }

/* horizontal category bars */
.hbar-row { display: grid; grid-template-columns: 110px 1fr 74px; gap: 10px; align-items: center; padding: 5.5px 0; }
.hbar-row .cat-name { font-size: 13.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { position: relative; height: 22px; }
.hbar-fill {
  height: 100%; border-radius: 4px;
  background: var(--s2, #2a78d6);
  min-width: 3px;
  transition: width .35s cubic-bezier(.2,.7,.3,1);
}
.hbar-row:hover .hbar-fill, .hbar-row:focus-within .hbar-fill { filter: brightness(1.08); }
.hbar-val { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }

/* trend chart (svg) */
#trend-chart svg { display: block; width: 100%; height: auto; }
.axis-text { font-size: 11px; fill: var(--ink-3); font-family: var(--font); font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--hairline); stroke-width: 1; }
.bar-hit { fill: transparent; cursor: pointer; }
.bar-hit:hover + .bar-mark, .bar-hit.is-hot + .bar-mark { filter: brightness(1.07); }

/* ---------------- meter ---------------- */
.meter-wrap { margin-top: 10px; }
.meter-track {
  height: 12px; border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .4s cubic-bezier(.2,.7,.3,1), background .3s ease;
}
.meter-fill.is-over { background: var(--danger); }
.meter-fill.is-warn { background: var(--warn); }
.meter-scale {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--ink-3); margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.meter-note { margin: 10px 0 0; font-size: 13.5px; color: var(--ink-2); }
.meter-note strong { color: var(--ink); font-weight: 600; }

/* goal */
.goal-block { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--hairline); }
.goal-title { font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.goal-fill { background: var(--s2); }
.goal-track { background: #e2ecf7; }
.goal-edit-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.goal-edit-row label { font-size: 13px; color: var(--ink-2); }
.goal-edit-row input {
  width: 96px; padding: 7px 10px; border: 1px solid var(--hairline);
  border-radius: 8px; background: #fff; font-size: 13.5px;
}

/* ---------------- entries table ---------------- */
.list-scroll { margin-top: 8px; }
.entries-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.entries-table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--ink-3);
  padding: 6px 8px; border-bottom: 1px solid var(--hairline);
}
.entries-table td { padding: 9px 8px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.entries-table tr:last-child td { border-bottom: none; }
.entries-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.entries-table .kind-pill {
  display: inline-block; font-size: 10.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px; letter-spacing: .02em;
}
.kind-income .kind-pill { background: #e7f1ec; color: var(--accent-strong); }
.kind-expense .kind-pill { background: #f0f1f2; color: var(--ink-2); }
.entries-table .date-cell { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.entries-table .title-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entries-table .cat-cell { color: var(--ink-2); font-size: 13px; }
.row-del {
  background: none; border: none; color: var(--ink-3);
  font-size: 15px; padding: 4px 8px; border-radius: 6px; line-height: 1;
}
.row-del:hover { color: var(--danger); background: #faf3f2; }
.income-amt { color: var(--accent-strong); }

.empty { text-align: center; padding: 34px 10px; }
.empty-title { font-weight: 600; margin: 0 0 4px; }
.empty-sub { color: var(--ink-3); font-size: 13.5px; margin: 0; }

/* ---------------- dialog ---------------- */
.dialog {
  border: none; border-radius: 16px;
  padding: 24px; width: min(430px, calc(100vw - 32px));
  box-shadow: 0 24px 60px -12px rgba(23,32,27,.35);
}
.dialog::backdrop { background: rgba(23, 32, 27, .45); backdrop-filter: blur(2px); }
.dialog-title { font-family: var(--serif); font-size: 21px; font-weight: 500; margin-bottom: 16px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
.field .opt { font-weight: 400; color: var(--ink-3); }
.field input, .field select {
  width: 100%; padding: 10px 12px;
  border: 1px solid #d4dad6; border-radius: 9px;
  background: #fff; font-size: 14.5px;
}
.field input:focus, .field select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row { display: flex; gap: 8px; margin-bottom: 15px; }
.toggle {
  flex: 1; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--hairline); background: #fff;
  color: var(--ink-2); font-weight: 500; font-size: 14px;
}
.toggle.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
.form-error { color: var(--danger); font-size: 13.5px; margin: 2px 0 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #20302a; color: #fff; padding: 11px 20px;
  border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(23,32,27,.3);
  z-index: 60; animation: toastIn .25s cubic-bezier(.2,.7,.3,1);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------- loading ---------------- */
.loading-veil { opacity: .55; transition: opacity .2s ease; pointer-events: none; }

/* ---------------- landing ---------------- */
.landing-body { background: var(--bg); }
.landing { max-width: 1060px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 36px) 80px; }
.landing-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 40px;
}
.hero { padding: clamp(24px, 6vw, 60px) 0 40px; max-width: 640px; }
.hero-eyebrow { font-size: 13px; font-weight: 600; color: var(--accent-strong); letter-spacing: .04em; text-transform: uppercase; margin: 0 0 14px; }
.hero-title { font-family: var(--serif); font-size: clamp(34px, 5.4vw, 52px); font-weight: 500; line-height: 1.12; letter-spacing: -0.02em; max-width: 15ch; }
.hero-sub { margin: 18px 0 0; font-size: clamp(15.5px, 1.8vw, 17px); line-height: 1.65; color: var(--ink-2); max-width: 52ch; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.landing-cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin-top: clamp(28px, 6vw, 64px);
}
.landing-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 22px 24px 20px; box-shadow: var(--shadow);
}
.lc-num { font-size: 12px; font-weight: 600; color: var(--ink-3); display: block; margin-bottom: 26px; }
.landing-card h2 { font-size: 16.5px; margin-bottom: 7px; }
.landing-card p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-2); }
@media (max-width: 760px) {
  .landing-cards { grid-template-columns: 1fr; }
  .hero-actions .big { width: 100%; }
}
