/* Components for the three themes (tokens.css). Class names are shared by every page;
   the look (sidebar vs top bar, density, type) comes from the active theme. Tokens only —
   no raw colours here. */

/* ---------------------------------------------------------------- base */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  color: var(--link-hover);
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
[x-cloak] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
h1,
h2,
h3 {
  text-wrap: balance;
}

/* ---------------------------------------------------------------- app shell
   Markup (js/shell.js): .page > header.top#top (brand, upload, nav, account) + main.
   Ledger and Evergreen: the header is a left sidebar. Graphite: a top bar.
   Phones (all themes): compact top bar + bottom navigation. */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page > :not(.top) {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 32px 48px;
}
.top {
  background: var(--nav-bg);
  color: var(--nav-fg);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--nav-fg-active);
  white-space: nowrap;
}
.brand:hover {
  color: var(--nav-fg-active);
}
.logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--brand-mark);
  color: var(--brand-mark-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.nav {
  display: flex;
  gap: 2px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--nav-fg);
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--r-ctl);
}
.nav a:hover {
  color: var(--nav-fg-active);
  background: var(--nav-bg-active);
}
.nav a[aria-current="page"] {
  color: var(--nav-fg-active);
  background: var(--nav-bg-active);
  font-weight: 600;
}
.nav svg {
  flex: none;
}
.nav .nav-upload {
  display: none;
}
.upload-btn {
  flex: none;
}
.top-end {
  display: flex;
  align-items: center;
  gap: 8px;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.account-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--nav-fg-active);
  font: inherit;
  text-align: left;
  padding: 6px;
  border-radius: var(--r-ctl);
  cursor: pointer;
  min-width: 0;
}
.account-btn:hover {
  background: var(--nav-bg-active);
}
.account-btn .who {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.account-btn .who b {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-btn .who small {
  font-size: 12px;
  color: var(--nav-muted);
}
.menu-wrap {
  position: relative;
}
.menu {
  position: absolute;
  z-index: 40;
  min-width: 240px;
  padding: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu .menu-head {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu .menu-sep {
  height: 1px;
  background: var(--border-soft);
  margin: 6px 0;
}
.menu a,
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-ctl);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu a:hover,
.menu button:hover {
  background: var(--hover);
  color: var(--text);
}
.menu .theme-opt[aria-checked="true"] {
  font-weight: 600;
}
.menu .theme-opt .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  flex: none;
}
.menu .theme-opt .dot.ledger {
  background: var(--swatch-ledger);
}
.menu .theme-opt .dot.graphite {
  background: var(--swatch-graphite);
}
.menu .theme-opt .dot.evergreen {
  background: var(--swatch-evergreen);
}
.menu .theme-opt .check-mark {
  margin-left: auto;
  visibility: hidden;
}
.menu .theme-opt[aria-checked="true"] .check-mark {
  visibility: visible;
}
.menu .phone-only {
  display: none;
}

/* desktop: sidebar themes */
@media (min-width: 1024px) {
  :root:not([data-theme="graphite"]) .page {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-auto-rows: min-content;
  }
  :root:not([data-theme="graphite"]) .page > :not(.top) {
    grid-column: 2;
  }
  :root:not([data-theme="graphite"]) .top {
    grid-column: 1;
    grid-row: 1 / span 40;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    align-items: stretch;
    gap: 20px;
    padding: 20px 14px 14px;
    border-right: 1px solid var(--nav-border);
    overflow-y: auto;
  }
  :root:not([data-theme="graphite"]) .brand {
    padding: 0 8px;
  }
  :root:not([data-theme="graphite"]) .nav {
    flex-direction: column;
  }
  :root:not([data-theme="graphite"]) .nav a {
    height: 38px;
    padding: 0 10px;
  }
  :root:not([data-theme="graphite"]) .top-end {
    margin-top: auto;
    flex-direction: column;
    align-items: stretch;
    border-top: 1px solid var(--nav-border);
    padding-top: 10px;
  }
  :root[data-theme="evergreen"] .top-end {
    border-top-color: rgb(255 255 255 / 0.12);
  }
  :root:not([data-theme="graphite"]) .menu {
    left: 0;
    bottom: calc(100% + 6px);
  }
  :root:not([data-theme="graphite"]) .avatar-only {
    display: none;
  }
}

/* Evergreen sidebar: upload sits at the bottom, as in the mockup */
@media (min-width: 1024px) {
  :root[data-theme="evergreen"] .top .nav {
    order: 1;
  }
  :root[data-theme="evergreen"] .top .upload-btn {
    order: 2;
    margin-top: auto;
  }
  :root[data-theme="evergreen"] .top .top-end {
    order: 3;
    margin-top: 0;
  }
}

/* desktop: Graphite top bar with underlined tabs */
@media (min-width: 1024px) {
  :root[data-theme="graphite"] .top {
    position: sticky;
    top: 0;
    height: 56px;
    padding: 0 24px;
    border-bottom: 1px solid var(--nav-border);
  }
  :root[data-theme="graphite"] .nav {
    height: 56px;
    order: 1;
    margin-right: auto;
  }
  :root[data-theme="graphite"] .nav a {
    padding: 0 12px;
    border-radius: 0;
    border-bottom: 2px solid transparent;
  }
  :root[data-theme="graphite"] .nav a:hover {
    background: transparent;
  }
  :root[data-theme="graphite"] .nav a[aria-current="page"] {
    background: transparent;
    border-bottom-color: var(--accent);
  }
  :root[data-theme="graphite"] .nav svg {
    display: none;
  }
  :root[data-theme="graphite"] .brand {
    order: 0;
    margin-right: 8px;
  }
  :root[data-theme="graphite"] .upload-btn {
    order: 2;
  }
  :root[data-theme="graphite"] .top-end {
    order: 3;
  }
  :root[data-theme="graphite"] .account-btn .who {
    display: none;
  }
  :root[data-theme="graphite"] .menu {
    right: 0;
    top: calc(100% + 8px);
  }
}

/* tablets and phones: compact top bar, bottom navigation */
@media (max-width: 1023px) {
  .page > :not(.top) {
    padding: 16px 16px 104px;
  }
  .top {
    position: sticky;
    top: 0;
    height: 56px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--nav-border);
  }
  .top .brand {
    margin-right: auto;
  }
  .upload-btn {
    display: none !important;
  }
  .account-btn .who {
    display: none;
  }
  .menu {
    right: 0;
    top: calc(100% + 8px);
  }
  .menu .phone-only {
    display: flex;
  }
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: 76px;
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
  }
  .nav a {
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border-radius: 0;
  }
  .nav a:hover {
    background: transparent;
    color: var(--text);
  }
  .nav a[aria-current="page"] {
    background: transparent;
    color: var(--text);
  }
  .nav a .ico {
    width: 56px;
    height: 30px;
    border-radius: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .nav a[aria-current="page"] .ico {
    background: var(--accent-soft);
    color: var(--accent-soft-fg);
  }
  .nav .nav-upload {
    display: flex;
  }
  .nav .nav-upload .ico {
    background: var(--accent);
    color: var(--accent-on);
  }
  .nav [data-nav="income"],
  .nav [data-nav="accounts"],
  .nav [data-nav="settings"] {
    display: none;
  }
}

/* ---------------------------------------------------------------- page header */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 20px;
}
.page-head .eyebrow {
  font-size: 13px;
  color: var(--text-muted);
}
.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ---------------------------------------------------------------- grid + cards */
.bento {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  align-items: start;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--pad-card);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.tile-wide {
  padding: var(--pad-card);
}
.tile.flush {
  padding: 0;
  gap: 0;
}
.tile.flush > .tile-head {
  padding: 16px var(--pad-card);
  border-bottom: 1px solid var(--border-soft);
}
.span-2 {
  grid-column: span 2;
}
.span-3 {
  grid-column: span 3;
}
.span-4 {
  grid-column: 1 / -1;
}
.row-2 {
  grid-row: span 2;
}
.tile h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.label-light {
  font-weight: 500;
}
.big {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.note {
  font-size: 13px;
}
.note-sm {
  font-size: 12px;
}
.muted {
  color: var(--text-muted);
}
.muted-15 {
  font-size: 14px;
}
.hero {
  gap: 14px;
}
.hero-num {
  font-family: var(--font-num);
  font-size: clamp(34px, 3.4vw, 48px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.ccy-prefix {
  font-size: 16px;
  font-weight: 500;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}
.chip.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}
.chip.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: transparent;
}

/* tinted tiles from the old design are plain cards now; the tint survives in figures */
.t-mint .big {
  color: var(--in);
}
.t-lemon .count,
.count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* KPI strip: one card split into cells */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
}
.kpis > div {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  margin: 0 -1px -1px 0;
}
.kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
}
.kpi-row > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.in-text,
.ok-text {
  color: var(--in);
}
.warn-text {
  color: var(--warn);
}
.danger-text {
  color: var(--danger);
}

/* legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend i {
  width: 14px;
  height: 2px;
  background: var(--chart-accent);
}
.legend i.compare {
  height: 0;
  border-top: 2px dashed var(--chart-compare);
  background: none;
}

/* category list with share bars */
.cat-list {
  display: flex;
  flex-direction: column;
}
.cat-list > a,
.cat-list > div {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 48px;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
.cat-list > a:hover {
  color: var(--text);
  background: var(--hover);
}
.cat-list .amt {
  font-family: var(--font-num);
  font-weight: 500;
}
.share-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;
  background: var(--surface-sunken);
}

/* ---------------------------------------------------------------- lists */
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}
.row b {
  font-family: var(--font-num);
  font-weight: 600;
}
.row-sm {
  font-size: 14px;
}
.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: var(--r-ctl);
  min-width: 96px;
  flex: 1 1 96px;
}
.cats.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.cat-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  margin-left: -8px;
}
.cat-actions .pill {
  min-height: 32px;
  min-width: 32px;
}
.cat .n {
  font-size: 13px;
  font-weight: 600;
}
.cat .p {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-num);
}
.c-peach {
  background: var(--peach-bg);
  color: var(--peach-fg);
}
.c-sky {
  background: var(--sky-bg);
  color: var(--sky-fg);
}
.c-mint {
  background: var(--mint-bg);
  color: var(--mint-fg);
}
.c-lilac {
  background: var(--lilac-bg);
  color: var(--lilac-fg);
}
.c-lemon {
  background: var(--lemon-bg);
  color: var(--lemon-fg);
}
.c-neutral {
  background: var(--neutral-bg);
  color: var(--neutral-fg);
}
.latest {
  display: flex;
  flex-direction: column;
}
.txn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
a.txn:hover {
  color: var(--text);
  background: var(--hover);
}
.txn .who {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.txn .who b {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.txn .who small {
  font-size: 12px;
  color: var(--text-muted);
}
.txn .amt {
  font-family: var(--font-num);
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
}
.txn .amt .side {
  font-family: var(--font);
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
}
.ic {
  width: 34px;
  height: 34px;
  border-radius: var(--r-ctl);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex: none;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: none;
  display: inline-block;
}

/* ---------------------------------------------------------------- buttons ("pill") */
.pill,
.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.pill:hover,
.pill-btn:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--border-strong);
}
.pill-btn {
  align-self: flex-start;
}
.pill.sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}
.pill[aria-pressed="true"],
.pill.active {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  border-color: transparent;
  font-weight: 600;
}
.pill.primary {
  background: var(--accent);
  color: var(--accent-on);
  border-color: transparent;
  font-weight: 600;
}
.pill.primary:hover {
  color: var(--accent-on);
  filter: brightness(1.08);
}
.pill.ghost {
  background: transparent;
  border-color: transparent;
}
.pill.ghost:hover {
  background: var(--hover);
}
.pill.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}
.pill.lemon {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}
.pill:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
:root[data-theme="evergreen"] .top .pill.primary {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
}
.link-strong {
  font-size: 13px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}
.field > span {
  color: var(--text-muted);
}
.input,
select.input,
textarea.input {
  min-height: 38px;
  padding: 7px 11px;
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  width: 100%;
}
.input::placeholder {
  color: var(--text-muted);
}
.input:hover {
  border-color: var(--border-strong);
}
textarea.input {
  min-height: 88px;
  resize: vertical;
}
.input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: transparent;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.check input,
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* review confidence: field outlines + badges */
.conf-high {
  border-color: var(--ok);
}
.conf-mid {
  border-color: var(--warn);
  background: var(--warn-bg);
}
.conf-low {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.conf-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.conf-badge.high {
  background: var(--ok-bg);
  color: var(--ok);
}
.conf-badge.mid {
  background: var(--warn-bg);
  color: var(--warn);
}
.conf-badge.low {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---------------------------------------------------------------- tables */
.table-wrap {
  overflow-x: auto;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tbl th {
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.tbl th button {
  all: unset;
  cursor: pointer;
}
.tbl th button:focus-visible {
  outline: 2px solid var(--focus);
}
.tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.tbl td.num,
.tbl th.num {
  text-align: right;
  white-space: nowrap;
}
.tbl td.num {
  font-family: var(--font-num);
  font-weight: 500;
}
.tbl tr.clickable td {
  cursor: pointer;
}
.tbl tr.clickable:hover td {
  background: var(--hover);
}
.tbl tr.flagged td {
  background: var(--warn-bg);
}
.tbl tr.done td {
  color: var(--text-muted);
}
/* payee groups: question + one-click choices above the category picker */
.tbl.groups .ask {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
}
.tbl.groups td .block {
  display: block;
  margin-top: 2px;
}
.tbl.groups select.input {
  min-width: 180px;
}
.tbl .input {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}
.tile > .table-wrap:first-child,
.tile.flush .table-wrap {
  margin: 0;
}
.tbl .in-text {
  color: var(--in);
  font-weight: 600;
}

/* tags */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--neutral-bg);
  color: var(--neutral-fg);
  white-space: nowrap;
}

/* progress */
.progress,
.track {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress > span,
.track > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.2s ease;
}

/* drop zone */
.drop {
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  gap: 6px;
}
.drop:hover,
.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-title {
  font-weight: 600;
  font-size: 15px;
}
.drop-icon {
  color: var(--accent);
}

/* ---------------------------------------------------------------- overlays */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-pop);
}
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 10px 16px;
  border-radius: var(--r-ctl);
  background: var(--text);
  color: var(--surface);
  font-weight: 500;
  box-shadow: var(--shadow-pop);
}
.toast.error {
  background: var(--danger);
  color: var(--surface);
}
@media (max-width: 1023px) {
  .toast {
    bottom: 92px;
  }
}
kbd {
  font-family: var(--font-num);
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ---------------------------------------------------------------- login */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.auth-tile {
  width: 100%;
  max-width: 420px;
  padding: 28px;
}
.auth-tile h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.error-msg {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--r-ctl);
  padding: 10px 12px;
  font-size: 14px;
}

/* receipt preview */
.preview {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--r-ctl);
  background: var(--surface-sunken);
}
.preview-frame {
  width: 100%;
  height: 70vh;
  border: 0;
  border-radius: var(--r-ctl);
  background: var(--surface-sunken);
}
pre.ocr {
  white-space: pre-wrap;
  font-family: var(--font-num);
  font-size: 12px;
  max-height: 320px;
  overflow: auto;
  background: var(--surface-sunken);
  padding: 12px;
  border-radius: var(--r-ctl);
  margin: 0;
}

/* charts */
.chart-box {
  position: relative;
  height: 260px;
}
.empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 12px 0;
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}
.sw-peach {
  background: var(--chart-peach);
}
.sw-sky {
  background: var(--chart-sky);
}
.sw-lemon {
  background: var(--chart-lemon);
}
.sw-lilac {
  background: var(--chart-lilac);
}
.sw-mint {
  background: var(--chart-mint);
}
.sw-neutral {
  background: var(--chart-neutral);
}

/* upload type picker */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}
.type-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  min-height: 88px;
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  font: inherit;
  cursor: pointer;
}
.type-card .type-title {
  font-weight: 600;
  font-size: 15px;
}
.type-card .type-note {
  font-size: 13px;
}
.type-card:hover {
  border-color: var(--border-strong);
}
.type-card[aria-checked="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------------------------------------------------------------- helpers */
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.grow {
  flex: 1;
  min-width: 0;
}
.right {
  text-align: right;
}
.push-down {
  margin-top: auto;
}
.push-right {
  margin-left: auto;
}
.self-start {
  align-self: start;
}
.needs-text {
  font-size: 14px;
}
.num-font {
  font-family: var(--font-num);
}
a.tile {
  color: inherit;
}
a.tile:hover {
  border-color: var(--border-strong);
}
.bento-sub {
  display: contents;
}
.spacer {
  flex: 1;
}

/* ---------------------------------------------------------------- report tables */
.tbl.report tr.group-head td {
  background: var(--surface-2);
  font-weight: 600;
}
.group-toggle {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  gap: 10px;
  align-items: baseline;
}
.group-toggle:focus-visible {
  outline: 2px solid var(--focus);
}
.tbl.report tfoot td {
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
}

/* ---------------------------------------------------------------- responsive grid */
@media (max-width: 1280px) {
  .bento {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .span-3,
  .span-4 {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .bento {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2,
  .span-3,
  .span-4 {
    grid-column: auto;
  }
  .row-2 {
    grid-row: auto;
  }
  .pill,
  .pill-btn,
  .input {
    min-height: 44px;
  }
  .pill.sm {
    min-height: 40px;
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpis > div {
    padding: 14px;
  }
  .big {
    font-size: 20px;
  }
}

/* phones: ledger rows become two-line rows (who + amount / date + category) */
@media (max-width: 640px) {
  .tbl.ledger thead {
    display: none;
  }
  .tbl.ledger,
  .tbl.ledger tbody {
    display: block;
  }
  .tbl.ledger tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "sel who amt"
      "sel date cat";
    align-items: center;
    gap: 4px 12px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border-soft);
  }
  .tbl.ledger tr.clickable:hover {
    background: var(--hover);
  }
  .tbl.ledger td,
  .tbl.ledger tr.clickable:hover td {
    display: block;
    padding: 0;
    background: none;
    border: 0;
  }
  .tbl.ledger .c-sel {
    grid-area: sel;
  }
  .tbl.ledger .c-who {
    grid-area: who;
    min-width: 0;
  }
  .tbl.ledger .c-who b {
    overflow-wrap: anywhere;
  }
  .tbl.ledger .c-amt {
    grid-area: amt;
  }
  .tbl.ledger .c-date {
    grid-area: date;
    font-size: 12px;
    color: var(--text-muted);
  }
  .tbl.ledger .c-cat {
    grid-area: cat;
    justify-self: end;
  }
  .tbl.ledger .c-ccy,
  .tbl.ledger .c-base,
  .tbl.ledger .c-src {
    display: none;
  }
}

/* phones: report rows become two-line rows (payee + amount / date + category) */
@media (max-width: 640px) {
  .tbl.report thead {
    display: none;
  }
  .tbl.report,
  .tbl.report tbody,
  .tbl.report tfoot {
    display: block;
  }
  .tbl.report tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "payee amt"
      "meta cat";
    gap: 4px 12px;
    align-items: center;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border-soft);
  }
  .tbl.report tr.group-head,
  .tbl.report tr.grand-total {
    grid-template-areas: "label amt";
    background: var(--surface-2);
    padding: 10px 8px;
  }
  .tbl.report td,
  .tbl.report tr.clickable:hover td,
  .tbl.report tr.group-head td,
  .tbl.report tfoot td {
    display: block;
    padding: 0;
    background: none;
    border: 0;
  }
  .tbl.report .r-payee {
    grid-area: payee;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .tbl.report .r-label {
    grid-area: label;
  }
  .tbl.report .r-amt {
    grid-area: amt;
  }
  .tbl.report .r-amt:empty,
  .tbl.report .r-acct {
    display: none;
  }
  .tbl.report .r-in:not(:empty) + .r-out:not(:empty) {
    grid-area: auto;
    grid-column: 2;
  }
  .tbl.report .r-date {
    grid-area: meta;
    font-size: 12px;
    color: var(--text-muted);
  }
  .tbl.report .r-cat {
    grid-area: cat;
    justify-self: end;
  }
  .tbl.report .r-in:not(:empty)::before,
  .tbl.report .r-out:not(:empty)::before {
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    margin-right: 6px;
  }
  .tbl.report .r-in:not(:empty)::before {
    content: "in";
  }
  .tbl.report .r-out:not(:empty)::before {
    content: "out";
  }
}

@media (prefers-reduced-motion: no-preference) {
  .nav a,
  .pill,
  .tile,
  .txn {
    transition:
      background-color 0.15s ease,
      color 0.15s ease,
      border-color 0.15s ease;
  }
}
@media (prefers-reduced-motion: reduce) {
  .progress > span,
  .track > span {
    transition: none;
  }
}

/* ---------------------------------------------------------------- Home */
.kpis + .home-grid {
  margin-top: var(--gap);
  align-items: stretch;
}
.home-grid > .tile {
  align-self: stretch;
}
.home-grid .chart-box {
  flex: 1;
  min-height: 260px;
}
.home-side {
  gap: var(--gap);
  min-width: 0;
}
.home-grid > .stack {
  gap: var(--gap);
  min-width: 0;
}
.chart-box.tall {
  min-height: 300px;
}
.legend i.sw-in,
.legend i.sw-out {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.legend i.sw-in {
  background: var(--chart-in);
}
.legend i.sw-out {
  background: var(--chart-out);
}
.legend i.sw-net {
  background: var(--text-muted);
}
.clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.block {
  display: block;
}
.rec-row {
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
}
.rec-row .grow {
  min-width: 0;
}
.rec-row .clip {
  display: block;
}

/* top categories: label, bar, amount, share, change vs last month */
.hbars {
  display: flex;
  flex-direction: column;
}
.hbar {
  display: grid;
  grid-template-columns: minmax(80px, 1.1fr) minmax(60px, 2fr) auto 64px 64px;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
a.hbar:hover {
  color: var(--text);
  background: var(--hover);
}
.hbar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-sunken);
  overflow: hidden;
}
.hbar-track > span {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--chart-neutral);
}
.hbar.flag .hbar-track > span {
  background: var(--warn);
}
.hbar-amt {
  font-family: var(--font-num);
  font-weight: 500;
  text-align: right;
}
.hbar-share,
.hbar-change {
  font-size: 12px;
  text-align: right;
}
.good {
  color: var(--ok);
}
.bad {
  color: var(--danger);
}
@media (max-width: 640px) {
  .hbar {
    grid-template-columns: minmax(0, 1fr) auto 56px;
  }
  .hbar-track,
  .hbar-share {
    display: none;
  }
}
.tile.flush .tbl th:first-child,
.tile.flush .tbl td:first-child {
  padding-left: var(--pad-card);
}
.tile.flush .tbl th:last-child,
.tile.flush .tbl td:last-child {
  padding-right: var(--pad-card);
}
.tile.flush .tbl tr:last-child td {
  border-bottom: 0;
}
.tile.flush .empty.pad {
  padding: 16px var(--pad-card);
}
.latest-tbl .r-payee a {
  color: var(--text);
  font-weight: 500;
}
.latest-tbl .r-acct {
  white-space: nowrap;
}
a.tile.needs:hover {
  color: inherit;
  background: var(--hover);
}
@media (max-width: 640px) {
  .tile.flush .tbl.report tr {
    padding-left: var(--pad-card);
    padding-right: var(--pad-card);
  }
}

/* ---------------------------------------------------------------- Report statements */
.stmt-tabs {
  padding-block: 10px;
}
.stmt-tabs .pill.active {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}
.stmt-period {
  align-items: flex-end;
  gap: 12px;
}
.stmt-table {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stmt-table th[scope="row"] {
  text-align: left;
  font-weight: 400;
  position: sticky;
  left: 0;
  background: var(--surface);
  min-width: 180px;
}
.stmt-table tr.sec th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-top: 18px;
  border-bottom: 1px solid var(--border-strong);
}
.stmt-table .total-col {
  font-weight: 600;
  border-left: 1px solid var(--border);
}
.stmt-table tr.tot th,
.stmt-table tr.tot td {
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
}
.stmt-table tr.grand th,
.stmt-table tr.grand td {
  font-weight: 700;
  border-top: 3px double var(--border-strong);
}
.stmt-table tr.bal th,
.stmt-table tr.bal td {
  background: var(--surface-2);
}
.stmt-table tr.memo th,
.stmt-table tr.memo td {
  color: var(--text-muted);
  font-style: italic;
}
.stmt-table tr.flag th {
  color: var(--warn);
}
@media print {
  #top,
  .stmt-tabs,
  .stmt-actions,
  .stmt-period,
  .bottom-nav {
    display: none !important;
  }
  .stmt {
    box-shadow: none;
    border: 0;
  }
  .stmt-table th[scope="row"] {
    position: static;
  }
}

/* ---------------------------------------------------------------- Report: Categories view */
.cat-report {
  display: grid;
  gap: 14px;
}
.cat-report .pill.active {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}
.cat-period {
  flex-wrap: wrap;
  gap: 10px;
}
.cat-period-label {
  min-width: 9em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.cat-kpis {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
}
.cat-kpis > div {
  display: grid;
  gap: 2px;
}
.cat-kpis strong {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}
.cat-charts {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}
.cat-charts h3 {
  margin: 0 0 6px;
  font-weight: 500;
}
.cat-charts .chart-box {
  min-height: 220px;
}
.cat-report .stmt-table th[scope="row"] .dot {
  margin-right: 8px;
  vertical-align: middle;
}
.cat-period select.input {
  width: auto;
}
.cat-report .stmt-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (max-width: 1023px) {
  .cat-charts {
    grid-template-columns: minmax(0, 1fr);
  }
}
