/* Fintavo — a Smallstacks product. Design tokens follow smallstacks.net:
   near-monochrome, one blue accent, Inter, pill buttons, 18px radii. The only
   additions are the two semantic money colours, which carry meaning and are
   validated for colour-vision deficiency (deutan ΔE 8.5, normal 25.4). */

:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --ink: #1d1d1f;
  --ink-soft: #6e6e73;
  --ink-faint: #86868b;
  --line: #e5e5e7;
  --line-strong: #d2d2d7;
  /* Teal, taken from the Fintavo mark, so the product and its logo agree.
     Deliberately distinct from Smallstacks' azure — Fintavo is a product with
     its own identity under the company, not a re-skin of the agency site. */
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, .16);

  /* money in / money out — semantic, never decorative */
  --in: #1a7f4b;
  --in-wash: #eaf5ee;
  --out: #c2410c;
  --out-wash: #fdefe7;
  --flag: #9a6700;
  --flag-wash: #fff8e6;

  --radius: 18px;
  --radius-sm: 11px;
  --radius-pill: 980px;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 8px 30px rgba(0,0,0,.05);

  /* Tokens that were previously hardcoded, pulled out so dark mode can swap
     them. --on-ink is text sitting on an --ink background (buttons, toast). */
  --on-ink: #ffffff;
  --ink-strong: #000000;
  --glass: rgba(255, 255, 255, .82);
  --row-hover: #fbfbfc;
  --error-border: #f6d3c2;
  --error-ink: #96320a;
  --flag-border: #f0e0b4;
  color-scheme: light;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg-alt);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

h1 { font-size: clamp(1.7rem, 1.3rem + 1.4vw, 2.3rem); font-weight: 600; letter-spacing: -.032em; line-height: 1.1; }
h2 { font-size: 1.02rem; font-weight: 600; letter-spacing: -.012em; }
.lead { color: var(--ink-soft); font-size: .94rem; }
.hint { color: var(--ink-faint); font-size: .8rem; font-weight: 400; }

/* Figures get fixed-width digits so columns line up and totals don't jitter. */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand__mark { flex: none; }
.brand__name { font-weight: 600; letter-spacing: -.018em; }
/* The byline is a credit, not a second brand — small caps-ish tracking keeps it
   subordinate to the product name it sits beside. */
.brand__by {
  color: var(--ink-faint); font-size: .7rem; font-weight: 500;
  letter-spacing: .04em; align-self: center;
  padding-left: 10px; border-left: 1px solid var(--line);
}
.brand--stacked { flex-direction: column; gap: 10px; margin-bottom: 30px; }
.brand--stacked .brand__name { font-size: 1.3rem; }
.brand--stacked .brand__by { padding-left: 0; border-left: 0; margin-top: -6px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.auth__card { width: 100%; max-width: 400px; text-align: center; }
.auth__card h1 { font-size: 1.75rem; }
.auth__card .lead { margin-top: 12px; }
.auth__card form { margin-top: 26px; text-align: left; }
.swap { margin-top: 20px; font-size: .89rem; color: var(--ink-soft); }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 24px;
  padding: 11px 22px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--ink-faint); font-size: .84rem; }
.tabs { display: flex; gap: 2px; }
.tab {
  border: 0; background: none; color: var(--ink-soft);
  font-size: .9rem; font-weight: 500; padding: 7px 14px; border-radius: var(--radius-pill);
  transition: background .18s ease, color .18s ease;
}
.tab:hover { background: var(--bg-alt); color: var(--ink); }
.tab.is-active { background: var(--ink); color: var(--on-ink); }

/* ---------- layout ---------- */
.page { max-width: 1120px; margin-inline: auto; padding: 28px 22px 96px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.sectionhead { margin: 30px 0 12px; }

.card {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card + .card, .card--chart { margin-top: 18px; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.card__actions { display: flex; gap: 8px; align-items: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 14px; }

/* ---------- business / total cards ---------- */
.bcard { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.bcard--total { border-color: var(--line-strong); background: var(--bg); }
.bcard__name { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.012em; }
.swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.bcard__net { font-size: 1.85rem; font-weight: 600; letter-spacing: -.028em; margin-top: 10px; line-height: 1.1; }
.bcard__net.is-in { color: var(--in); }
.bcard__net.is-out { color: var(--out); }
.bcard__sub { color: var(--ink-faint); font-size: .8rem; margin-top: 3px; }
.bcard__rows { margin-top: 14px; display: grid; gap: 6px; font-size: .87rem; }
.bcard__row { display: flex; justify-content: space-between; gap: 12px; }
.bcard__row span:first-child { color: var(--ink-soft); }
.bcard__empty { color: var(--ink-faint); font-size: .85rem; margin-top: 10px; }

/* ---------- mixed-currency refusal ---------- */
.mixed { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); padding: 20px; box-shadow: var(--shadow); }
.mixed__why { color: var(--ink-soft); font-size: .9rem; margin-top: 6px; max-width: 62ch; }
.mixed__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 16px; }
.mixed__cell { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; }
.mixed__cell b { display: block; font-size: 1.3rem; font-weight: 600; letter-spacing: -.02em; }

/* ---------- chart ---------- */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; min-width: 100%; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--line-strong); stroke-width: 1; }
.chart text { font-family: var(--font); fill: var(--ink-faint); font-size: 11px; }
.chart .axis-value { font-variant-numeric: tabular-nums; }
.chart .bar { transition: opacity .15s ease; }
.chart .bar:hover { opacity: .82; }
.chart .datalabel { fill: var(--ink-soft); font-size: 10.5px; font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 16px; align-items: center; margin: 2px 0 12px; font-size: .84rem; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: block; }

.charttip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--ink); color: var(--on-ink); border-radius: 9px;
  padding: 8px 11px; font-size: .8rem; line-height: 1.45; box-shadow: 0 8px 24px rgba(0,0,0,.22);
}
.charttip b { font-variant-numeric: tabular-nums; }

/* ---------- breakdown ---------- */
.bd { margin-top: 6px; }
.bd + .bd { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.bd__name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .95rem; margin-bottom: 10px; }
.bd__row { display: grid; grid-template-columns: minmax(120px, 1.4fr) 3fr auto; gap: 12px; align-items: center; padding: 5px 0; font-size: .88rem; }
.bd__label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Both must be block-level — width and height do nothing on an inline span. */
.bd__track { display: block; background: var(--bg-alt); border-radius: 4px; height: 8px; overflow: hidden; }
.bd__fill { display: block; height: 100%; border-radius: 4px; }
.bd__value { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.bd__group { color: var(--ink-faint); font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; margin: 12px 0 4px; }

/* ---------- transactions table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: .89rem; }
th { color: var(--ink-faint); font-weight: 500; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; background: var(--row-hover); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
td.amount, th.amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.amount.is-in { color: var(--in); }
td.amount.is-out { color: var(--out); }
td.actions { text-align: right; white-space: nowrap; }
.rowbtn { border: 0; background: none; color: var(--ink-faint); padding: 4px 7px; border-radius: 7px; font-size: .82rem; }
.rowbtn:hover { background: var(--bg-alt); color: var(--ink); }
.rowbtn--danger:hover { background: var(--out-wash); color: var(--out); }
.pill { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--bg-alt); color: var(--ink-soft); }
.pill--flag { background: var(--flag-wash); color: var(--flag); }
/* nowrap keeps a two-word business name from splitting and making rows uneven */
.bizdot { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }

.empty { padding: 46px 22px; text-align: center; color: var(--ink-faint); font-size: .92rem; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field--wide { grid-column: 1 / -1; }
label { display: block; font-size: .84rem; font-weight: 500; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: .94rem; color: inherit;
  padding: 10px 13px; background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
input[type="color"] { padding: 4px; height: 42px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[aria-invalid="true"] { border-color: var(--out); }
.formgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.formactions { display: flex; gap: 10px; margin-top: 6px; }
.card--form { margin-bottom: 18px; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters--row { margin-bottom: 14px; }
.filters select, .filters input { width: auto; min-width: 130px; font-size: .88rem; padding: 8px 11px; }
.customrange { display: inline-flex; align-items: center; gap: 8px; }
.sep { color: var(--ink-faint); font-size: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: .92rem; font-weight: 500; white-space: nowrap;
  padding: 10px 20px; border-radius: var(--radius-pill); border: 1px solid transparent;
  transition: background .2s ease, border-color .2s ease, opacity .2s ease;
}
.btn--primary { background: var(--ink); color: var(--on-ink); }
.btn--primary:hover { background: var(--ink-strong); }
.btn--ghost { background: var(--bg); color: var(--ink); border-color: var(--line-strong); }
.btn--ghost:hover { border-color: var(--ink); }
.btn--sm { padding: 7px 14px; font-size: .85rem; }
.btn--block { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { border: 0; background: none; color: var(--ink-faint); font-size: 1.5rem; line-height: 1; padding: 0 6px; }
.iconbtn:hover { color: var(--ink); }

.notice { border-radius: var(--radius-sm); padding: 11px 14px; font-size: .87rem; margin-bottom: 14px; }
.notice--error { background: var(--out-wash); border: 1px solid var(--error-border); color: var(--error-ink); }
.notice--flag { background: var(--flag-wash); border: 1px solid var(--flag-border); color: var(--flag); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--on-ink); padding: 11px 18px; border-radius: var(--radius-pill);
  font-size: .88rem; z-index: 80; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

@media (max-width: 860px) {
  .formgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; gap: 12px; }
  .tabs { order: 3; width: 100%; }
  .brand__by { display: none; }
}
@media (max-width: 560px) {
  .formgrid { grid-template-columns: 1fr; }
  .page { padding: 22px 14px 90px; }
  th, td { padding: 10px 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- personal finance ---------- */
.sectionhead--first { margin-top: 0; }
.pagehead--sub { margin: 30px 0 12px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; margin-top: 18px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.kindpill {
  display: inline-block; font-size: .7rem; font-weight: 500; letter-spacing: .03em;
  padding: 2px 9px; border-radius: var(--radius-pill);
  background: var(--bg-alt); color: var(--ink-soft); text-transform: capitalize;
}
.kindpill--debt { background: var(--out-wash); color: var(--out); }
.kindpill--investment { background: var(--accent-soft); color: var(--accent); }

.acct__asof { color: var(--ink-faint); font-size: .76rem; }
.acct__quick { display: flex; gap: 8px; margin-top: 12px; }
.acct__quick input { flex: 1; min-width: 0; font-size: .88rem; padding: 8px 11px; }

.commit { display: grid; gap: 4px; }
.commit__row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: .9rem; border-bottom: 1px solid var(--line); }
.commit__row:last-child { border-bottom: 0; }
.commit__row.is-total { font-weight: 600; border-top: 1px solid var(--line-strong); margin-top: 4px; }
.commit__label { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); }
.commit__row.is-total .commit__label { color: var(--ink); }

.field--check label { display: flex; align-items: center; gap: 9px; font-weight: 400; margin-top: 26px; }
.field--check input { width: auto; }

/* net worth line chart */
.chart .nw-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .nw-area { fill: var(--accent-soft); }
.chart .nw-dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.chart .nw-dot--hover { opacity: 0; }
.chart .nw-hit:hover .nw-dot--hover { opacity: 1; }

/* ---------- dark mode ----------
   Tokens only; every rule above paints from them. The block appears
   twice because CSS cannot alias a selector into a media query:
   once for the explicit toggle, once for the OS preference. */
:root[data-theme="dark"] {
  --bg: #16191d;
  --bg-alt: #0e1114;
  --ink: #e7e9ec;
  --ink-soft: #a3a9b4;
  --ink-faint: #7c828e;
  --line: #262b31;
  --line-strong: #3a414a;
  --accent: #12a596;
  --accent-soft: rgba(18, 165, 150, .22);
  --in: #27a86e;
  --in-wash: rgba(39, 168, 110, .14);
  --out: #dd6234;
  --out-wash: rgba(221, 98, 52, .15);
  --flag: #d9a514;
  --flag-wash: rgba(217, 165, 20, .13);
  --on-ink: #101317;
  --ink-strong: #ffffff;
  --glass: rgba(14, 17, 20, .82);
  --row-hover: #1b2026;
  --error-border: rgba(221, 98, 52, .4);
  --error-ink: #f0916b;
  --flag-border: rgba(217, 165, 20, .35);
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #16191d;
  --bg-alt: #0e1114;
  --ink: #e7e9ec;
  --ink-soft: #a3a9b4;
  --ink-faint: #7c828e;
  --line: #262b31;
  --line-strong: #3a414a;
  --accent: #12a596;
  --accent-soft: rgba(18, 165, 150, .22);
  --in: #27a86e;
  --in-wash: rgba(39, 168, 110, .14);
  --out: #dd6234;
  --out-wash: rgba(221, 98, 52, .15);
  --flag: #d9a514;
  --flag-wash: rgba(217, 165, 20, .13);
  --on-ink: #101317;
  --ink-strong: #ffffff;
  --glass: rgba(14, 17, 20, .82);
  --row-hover: #1b2026;
  --error-border: rgba(221, 98, 52, .4);
  --error-ink: #f0916b;
  --flag-border: rgba(217, 165, 20, .35);
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
  }
}

.pagehead__actions { display: flex; gap: 10px; align-items: center; }
