/* momoney styles: ported from the zenmoney-importer editor, recolored with the C2 momo-iro tokens.
   The editor's review grid, drag states and inline fields live in the import section at the end. */

:root {
  color-scheme: light dark;

  /* sizing */
  --control-h:    44px;

  /* spacing scale */
  --sp-1:         4px;
  --sp-2:         8px;
  --sp-3:         12px;
  --sp-4:         16px;
  --sp-6:         24px;

  /* surfaces */
  --paper:        #F6F5F1;
  --surface:      #FFFFFF;
  --surface-sunk: #FBFAF8;
  --blush:        #FBE1E3;

  /* ink */
  --ink:          #1B1B22;
  --muted:        #6C6C7A;
  --ink-faint:    #9A9AA6;
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236C6C7A' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --label:        #8D5864;

  /* lines */
  --line:         #EBE6E2;
  --line-strong:  #DDD6D0;

  /* interactive */
  --accent:       #B53E5C;
  --accent-ink:   #FFFFFF;
  --accent-weak:  #FBE1E3;
  --focus-ring:   rgba(181, 62, 92, 0.18);

  /* money: expenses are drawn in ink, not red */
  --income:       #3D7A36;
  --expense:      var(--ink);

  /* warn */
  --warn:         #B7791F;
  --warn-line:    #ECB44A;
  --warn-tint:    #FDF7EA;

  /* peach add button */
  --peach:        #F4A08F;
  --peach-shade:  #E07C6E;
  --leaf:         #6E9F55;

  --topbar-bg:    rgba(246, 245, 241, .82);

  --shadow-sm: 0 1px 1px rgba(40,20,30,.04), 0 1px 2px rgba(40,20,30,.05);
  --shadow-md: 0 2px 5px -1px rgba(40,20,30,.10), 0 6px 16px -4px rgba(40,20,30,.10);
  --shadow-lg: 0 4px 12px -2px rgba(40,20,30,.14), 0 12px 32px -8px rgba(40,20,30,.16);

  --radius: 14px;
  --radius-sm: 9px;
  --tabbar-h: 64px;
  --sidebar-w: 232px;
  --sidebar-inset: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #161416;
    --surface:      #211D20;
    --surface-sunk: #1C181B;
    --blush:        #3A2128;
    --ink:          #EDE7E6;
    --muted:        #A39A9C;
    --ink-faint:    #7D7476;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23A39A9C' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    --label:        #C99AA5;
    --line:         #2F2A2D;
    --line-strong:  #3D3639;
    --accent:       #F08FA4;
    --accent-ink:   #161416;
    --accent-weak:  #3A2128;
    --focus-ring:   rgba(240, 143, 164, 0.22);
    --income:       #8CC67F;
    --warn:         #E2B260;
    --warn-line:    #A97C2E;
    --warn-tint:    #2E261A;
    --topbar-bg:    rgba(22, 20, 22, .82);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.30);
    --shadow-md: 0 4px 14px -4px rgba(0,0,0,.45);
    --shadow-lg: 0 12px 32px -8px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }

/* no scroll anchoring: an outerHTML swap inserts the new #content before removing the old one, and a scrolled
   page would otherwise jump down by the height of the new content to keep the old one in place */
/* text sizes are rem, so this one value scales the whole app (106.25% = 17px at the browser default) */
html { font-size: 106.25%; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-anchor: none; }

body {
  margin: 0;
  font-family: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  font-size: .9375rem;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}

a { color: var(--accent); }
code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .9em; }

.mono, .amount { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.income { color: var(--income); }
.expense { color: var(--expense); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ───────────────────────── brand ───────────────────────── */
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; letter-spacing: -.01em; color: var(--accent); text-decoration: none;
}
.brand .peach-mark { width: 1.5em; height: 1.5em; flex: none; margin: -.25em 0; }
.peach-body { fill: var(--peach); stroke: none; }
.peach-cleft { fill: none; stroke: var(--peach-shade); stroke-width: 2.5; stroke-linecap: round; }
.peach-leaf { fill: var(--leaf); stroke: none; }

/* ───────────────────────── buttons ───────────────────────── */
.btn {
  font: inherit; font-weight: 600; font-size: .875rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; cursor: pointer;
  min-height: var(--control-h);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-ghost {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:hover { border-color: var(--muted); }
.btn-sm { padding: 6px 10px; font-size: .8125rem; min-height: 0; }
.btn-icon { width: 33px; height: 33px; padding: 0; } /* square at the computed height of .btn-sm */

/* ───────────────────────── shell ───────────────────────── */
.shell { min-height: 100vh; }

.main { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.month { font-weight: 600; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .78125rem; font-weight: 600;
  padding: 5px 10px; border-radius: 99px;
  background: var(--blush); color: var(--label); text-decoration: none;
  border: 1px solid transparent;
}
.chip:hover { border-color: var(--accent); }

.banner {
  margin: 12px 16px 0; padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-tint); border: 1px solid var(--warn-line); color: var(--ink);
  font-size: .875rem;
}

.wrap {
  max-width: 880px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}

.page-title { margin: 0 0 var(--sp-4); font-size: 1.5rem; letter-spacing: -.02em; }

/* sidebar: desktop only */
.sidebar { display: none; }

/* bottom tabs: mobile only */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px 4px env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0; font-size: .6875rem; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabbar a svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a.active { color: var(--accent); }

/* the peach-shaped add button sits raised in the middle of the tab bar */
.tabbar a.peach-add { flex: 0 0 68px; height: 64px; padding: 0; margin-top: -26px; align-self: flex-start; }
.tabbar a.peach-add svg { width: 64px; height: 64px; filter: drop-shadow(0 4px 8px rgba(181, 62, 92, .28)); }
.peach-add:active svg { transform: scale(.95); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .tabbar, .brand-mobile { display: none; }
  .sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 18px;
    padding: 22px 16px;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .sidebar .brand { padding: 0 var(--sidebar-inset) 6px; font-size: 1.125rem; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; }
  .side-nav a {
    padding: 9px var(--sidebar-inset); border-radius: var(--radius-sm);
    color: var(--ink); text-decoration: none; font-weight: 500;
  }
  .side-nav a:hover { background: var(--surface-sunk); }
  .side-nav a.active { background: var(--blush); color: var(--accent); font-weight: 600; }
  .side-add { margin: 0; }
  .side-logout {
    margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 0 0 0 var(--sidebar-inset); font-size: .8125rem;
  }
  .topbar { padding: 14px 28px; }
  .banner { margin: 14px 28px 0; }
  .wrap { padding: 24px 28px 48px; }
}

/* ───────────────────────── cards ───────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: var(--sp-4);
}
.card-blush { background: var(--blush); border-color: transparent; }
.card-title {
  margin: 0 0 12px; font-size: .75rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--label);
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

.list-links { list-style: none; margin: -8px 0; padding: 0; }
.list-links li + li { border-top: 1px solid var(--line); }
.list-links a { display: block; padding: 12px 2px; color: var(--ink); text-decoration: none; font-weight: 500; }
.list-links a::after { content: "›"; float: right; color: var(--ink-faint); }

/* ───────────────────────── day sections (transaction list) ───────────────────────── */
.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--sp-4);
  overflow: hidden;
}
.day-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(var(--surface-sunk), var(--surface));
  border-bottom: 1px solid var(--line);
}
.day-date { font-weight: 700; letter-spacing: -.01em; }
.day-date .wd { color: var(--ink-faint); font-weight: 500; margin-left: 8px; font-size: .78125rem; }
.day-sum { margin-left: auto; color: var(--muted); font-size: .8125rem; }
.day-sum .v { font-weight: 600; }

.day-cont { margin-top: calc(-1 * var(--sp-4)); border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
/* the part of a day above its continuation keeps square bottom corners, so the two read as one card */
.day:has(+ .day-cont) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

/* ───────────────────────── transactions list ───────────────────────── */
.month-nav { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.month-nav .page-title { margin: 0; flex: 1; text-align: center; }

.tx-summary { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.summary-cell { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; }
.summary-cell .card-title { margin: 0; }
.summary-value { font-size: 1.375rem; font-weight: 600; letter-spacing: -.02em; }
.summary-note { flex-basis: 100%; margin: 0; font-size: .8125rem; }

.tx-filters { margin-bottom: 14px; gap: 8px; }
.tx-filters label { flex: 1 1 140px; font-size: .78125rem; }
.tx-filters label.grow { flex: 2 1 200px; }

.tx-rows { list-style: none; margin: 0; padding: 0; }
.tx-rows li + li { border-top: 1px solid var(--line); }
.tx-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 16px; color: var(--ink); text-decoration: none;
}
.tx-row:hover { background: var(--surface-sunk); }
.tx-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.tx-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { display: flex; gap: 8px; color: var(--muted); font-size: .8125rem; }
.tx-sub .tx-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub .tx-acct { margin-left: auto; white-space: nowrap; }
.tx-amounts { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; max-width: 50%; }
/* the account sits under the amount, flush with the row's right edge; long names are cut rather than squeezing the title */
.tx-amounts .tx-acct { color: var(--muted); font-size: .8125rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tx-approx { color: var(--muted); font-size: .78125rem; }
.tx-transfer, .tx-transfer .amount { color: var(--muted); }
.tx-more { display: flex; justify-content: center; padding: 8px 0 16px; }
.empty { text-align: center; padding: 32px 0; }

/* ───────────────────────── forms ───────────────────────── */
.form { display: flex; flex-direction: column; gap: var(--sp-3); }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form label { display: flex; flex-direction: column; gap: 4px; color: var(--label); font-size: .875rem; }
.form input, .form select, .form textarea {
  font: inherit; font-size: 1rem; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.form input:not([type=checkbox]):not([type=radio]):not([type=file]), .form select { height: var(--control-h); }
/* native menulist puts the chevron flush against the border; draw our own, inset like the text */
.form select {
  appearance: none; -webkit-appearance: none;
  padding-right: 36px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 12px;
}
.form select:disabled { opacity: .6; }
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring);
}
.form-inline .form-error { flex-basis: 100%; }
.form-error {
  margin: 0; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--blush); color: var(--accent);
}
.field-error { color: var(--accent); font-size: .8125rem; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 140px; }
.field-hint { font-size: .8125rem; }
.form [aria-invalid="true"], .form input.invalid { border-color: var(--accent); }
.input-cur { position: relative; display: flex; }
.input-cur input { flex: 1; min-width: 0; padding-right: 56px; }
.input-cur .cur {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .8125rem; color: var(--muted); pointer-events: none;
}
.btn-danger { color: var(--accent); }

/* segmented control: radio buttons styled as one bar */
.segmented {
  display: flex; padding: 3px; gap: 3px;
  background: var(--surface-sunk); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.form .segmented label { flex: 1; display: block; color: var(--ink); font-size: .875rem; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 8px 6px; border-radius: 7px; font-weight: 600; cursor: pointer;
}
.segmented input:checked + span { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus-ring); }

/* a transfer has accounts on both sides and no category; expense and income have no to-side */
.tx-form:has([name=type][value=transfer]:checked) .only-ei { display: none; }
.tx-form:not(:has([name=type][value=transfer]:checked)) .only-transfer { display: none; }
.tx-form .only-transfer { display: flex; flex-direction: column; gap: 12px; }
.tx-form label > .only-ei, .tx-form label > .only-transfer { display: inline; }
.tx-more-fields summary { cursor: pointer; color: var(--label); font-weight: 600; padding: 4px 0; }
.tx-more-fields[open] summary { margin-bottom: 8px; }

/* ───────────────────────── sheets ───────────────────────── */
/* full screen on mobile, a side panel on desktop; opened as a page without JS */
.sheet-page { max-width: 560px; margin: 0 auto; }
.sheet-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.sheet-head .page-title { flex: 1; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-host .sheet-head .page-title { font-size: 1.25rem; }
.sheet-foot { margin-top: var(--sp-6); display: flex; justify-content: center; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(20, 10, 15, .35); }
.sheet-host .sheet {
  position: fixed; inset: 0; z-index: 70; overflow-y: auto;
  background: var(--paper);
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 900px) {
  .sheet-host .sheet {
    left: auto; width: 460px; padding: 22px 24px 32px;
    border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
    animation-name: sheet-left;
  }
  @keyframes sheet-left { from { transform: translateX(24px); opacity: 0; } }
}

.details-amount { margin: 0 0 12px; font-size: 1.625rem; font-weight: 600; letter-spacing: -.02em; }
.details-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.details-list dt { color: var(--label); font-size: .875rem; }
.details-list dd { margin: 0; overflow-wrap: anywhere; }
.conversions { list-style: none; margin: 0; padding: 0; }
.conversions li { display: flex; justify-content: space-between; padding: 6px 0; }
.conversions li + li { border-top: 1px solid var(--line); }
.details-meta { font-size: .8125rem; text-align: center; }
.banner-inline { margin: 0 0 12px; }

.trash-row { display: flex; align-items: center; }
.trash-row .tx-row { flex: 1; min-width: 0; }
.trash-row form { padding-right: var(--sp-4); }

/* ───────────────────────── category combobox panel ───────────────────────── */
#cat-panel {
  position: fixed; z-index: 500;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 280px; overflow-y: auto; padding: 4px 0; min-width: 180px;
}
.cat-opt {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  cursor: pointer; font-size: .90625rem; color: var(--ink); user-select: none;
}
.cat-opt:hover { background: var(--surface-sunk); }
.cat-opt.active { background: var(--accent-weak); color: var(--accent); }
.cat-check { color: var(--income); font-size: .6875rem; width: 14px; flex-shrink: 0; visibility: hidden; }
.cat-opt.cat-checked .cat-check { visibility: visible; }

/* ───────────────────────── toasts ───────────────────────── */
.toasts {
  position: fixed; z-index: 100; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 99px;
  background: var(--ink); color: var(--paper);
  font-weight: 600; font-size: .875rem; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
  transition: opacity .3s, transform .3s;
}
.toast-error { background: var(--accent); color: var(--accent-ink); }
.toast:has(.toast-action) { display: flex; align-items: center; gap: var(--sp-3); padding: 6px 6px 6px var(--sp-4); }
/* only the action takes taps; the toast itself lets them through to the list below */
.toast .toast-action {
  pointer-events: auto; cursor: pointer;
  padding: 6px 10px; font-size: .8125rem; border-radius: 99px;
  border: 0; background: var(--paper); color: var(--ink); font-weight: 600; font-family: inherit;
}
.toast-out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@media (min-width: 900px) {
  .toasts { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); }
}

/* ───────────────────────── auth and error pages ───────────────────────── */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; box-shadow: var(--shadow-md);
}
.auth-card .brand { margin: 0 0 16px; font-size: 1.75rem; }

/* accounts and categories */
.page-head { margin-bottom: var(--sp-4); }
.page-head .page-title { margin: 0; }
.accounts-total { display: flex; flex-direction: column; gap: 4px; }
.accounts-total .card-title { margin: 0; }
.item-row { display: flex; align-items: center; gap: 6px; padding-right: var(--sp-4); }
.item-row .tx-row { flex: 1; min-width: 0; }
.cat-child .tx-row { padding-left: 32px; }
.cat-child .tx-title { font-weight: 400; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.form label.check input { width: auto; }

/* ───────────────────────── stats ───────────────────────── */
.stats-period { font-size: .875rem; }
.stats-tabs {
  display: flex; gap: 4px; padding: 3px; margin-bottom: 12px;
  background: var(--surface-sunk); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.stats-tabs a {
  flex: 1; text-align: center; padding: 7px 8px; border-radius: 7px;
  color: var(--muted); text-decoration: none; font-weight: 500; font-size: .875rem;
}
.stats-tabs a.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.stats-controls { margin-bottom: 14px; gap: 8px; }
.stats-controls > label { flex: 1 1 130px; font-size: .78125rem; }
.stats-controls:not(:has([name=period] option[value=custom]:checked)) .stats-month input { color: var(--muted); }
/* account picker: a disclosure row with a chevron, opening into toggle chips (the checkbox is the chip) */
.stats-accts { flex-basis: 100%; font-size: .875rem; }
.stats-accts summary {
  display: inline-flex; align-items: center; gap: var(--sp-1); max-width: 100%;
  cursor: pointer; user-select: none; color: var(--label); font-weight: 600; font-size: .78125rem;
  padding: 6px 0; border-radius: var(--radius-sm); list-style: none;
}
.stats-accts summary::-webkit-details-marker { display: none; }
.stats-accts summary::after {
  content: ""; width: 12px; height: 12px; flex: none;
  background: var(--select-chevron) center / 12px 12px no-repeat;
  transition: transform .15s;
}
.stats-accts[open] summary::after { transform: rotate(180deg); }
.stats-accts summary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.stats-accts-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 4px; }
.form .stats-accts-list label.check {
  position: relative; gap: 6px; padding: 5px 12px; border-radius: 99px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  font-size: .8125rem; font-weight: 500; line-height: 1.3; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.form .stats-accts-list label.check::before {
  content: ""; width: 10px; height: 10px; flex: none; border-radius: 50%;
  border: 1.5px solid var(--line-strong); transition: background .12s, border-color .12s;
}
.form .stats-accts-list label.check:hover { border-color: var(--accent); }
.form .stats-accts-list label.check:has(input:checked) {
  background: var(--blush); border-color: transparent; color: var(--label); font-weight: 600;
}
.form .stats-accts-list label.check:has(input:checked)::before { background: var(--accent); border-color: var(--accent); }
.form .stats-accts-list label.check:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--focus-ring); }
.form .stats-accts-list label.check input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
}
.stats-unconverted { margin: 0 0 12px; }
.stats-totals .summary-cell { gap: 2px; }
.stats-note { font-size: .8125rem; }

.stats-list { list-style: none; padding: 0; overflow: hidden; }
.stats-list > li + li, .stats-children li + li { border-top: 1px solid var(--line); }
.stats-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px;
  color: var(--ink); text-decoration: none; cursor: pointer;
}
.stats-row:hover { background: var(--surface-sunk); }
summary.stats-row { list-style: none; }
summary.stats-row::-webkit-details-marker { display: none; }
.stats-group[open] > summary { background: var(--surface-sunk); }
.stats-group > summary .stats-name::after { content: " ▾"; color: var(--ink-faint); font-size: .6875rem; }
.stats-children { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.stats-children .stats-row { padding-left: 32px; }
.stats-children .stats-name { font-weight: 400; }
.stats-all { color: var(--accent); font-size: .8125rem; padding-top: 8px; padding-bottom: 8px; }
.stats-row-main { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.stats-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-row-note { font-size: .78125rem; font-weight: 400; }
.stats-bar { display: block; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.stats-bar span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.stats-row-figs { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; }
.stats-share { font-size: .78125rem; }
.stats-delta.up { color: var(--accent); }
.stats-delta.down { color: var(--income); }

.stats-trend { padding: 12px; }
.chart-scroll, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.trend-chart { display: block; width: 100%; height: auto; }
.trend-zero { stroke: var(--line-strong); stroke-width: 1; }
.trend-bar.expense { fill: var(--ink); opacity: .82; }
.trend-bar.income { fill: var(--income); }
.trend-chart a:hover .trend-bar { opacity: 1; fill: var(--accent); }
.trend-net { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.trend-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.trend-label { fill: var(--muted); font-size: .6875rem; font-family: "Hanken Grotesk", system-ui, sans-serif; }
.trend-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; font-size: .8125rem; }
.trend-legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.trend-legend .key:first-child { margin-left: 0; }
.trend-legend .key.expense { background: var(--ink); }
.trend-legend .key.income { background: var(--income); }
.trend-legend .key.net { background: var(--accent); height: 3px; }

.table-scroll { padding: 0; }
.stats-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .84375rem; }
.stats-table th, .stats-table td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.stats-table thead th { color: var(--label); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stats-table tbody th, .stats-table tfoot th, .stats-table thead th:first-child { text-align: left; }
.stats-table tbody tr:last-child > * { border-bottom: 0; }
.stats-table tfoot > tr > * { border-top: 1px solid var(--line-strong); border-bottom: 0; font-weight: 600; }
.stats-table a { color: inherit; text-decoration: none; }
.stats-table a:hover { color: var(--accent); }
.stats-table .total { font-weight: 600; }
/* the year table keeps the category column in view while the months scroll */
.year-table th:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; box-shadow: 1px 0 0 var(--line);
}
/* on wide screens the total column stays in view too; phones keep plain scrolling */
@media (min-width: 900px) {
  .year-table .total { position: sticky; right: 0; z-index: 1; background: var(--surface); box-shadow: -1px 0 0 var(--line); }
}

/* ───────────────────────── imports ───────────────────────── */
.back-link { font-size: .84375rem; text-decoration: none; }
.upload-form { gap: 12px; }
.upload-form .field { flex: 1 1 180px; }
.upload-form .field.grow { flex: 2 1 240px; }
.upload-form input[type=file] { padding: 7px 8px; }
.imp-list-card { padding: 0; overflow: hidden; }
.imp-list { list-style: none; margin: 0; padding: 0; }
.imp-list li + li { border-top: 1px solid var(--line); }
.imp-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--ink); text-decoration: none; }
.imp-item:hover { background: var(--surface-sunk); }
.imp-item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .8125rem; white-space: nowrap; }
.status {
  display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600;
  background: var(--surface-sunk); color: var(--muted); border: 1px solid var(--line);
}
.status-review { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.status-committed { color: var(--income); }
.status-failed { background: var(--warn-tint); color: var(--warn); border-color: var(--warn-line); }
.status-processing { color: var(--label); }
.imp-info { margin: -4px 0 12px; font-size: .84375rem; }

.imp-status { display: flex; align-items: center; gap: 12px; }
.imp-status.imp-failed { display: block; }
.imp-failed .form-error { margin-top: 0; }
.spinner {
  width: 18px; height: 18px; flex-shrink: 0; border-radius: 50%;
  border: 2.5px solid var(--accent-weak); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.imp-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.imp-counts { font-weight: 600; }
.imp-discard { position: relative; }
.imp-discard summary { list-style: none; }
.imp-discard summary::-webkit-details-marker { display: none; }
.imp-discard[open] form {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 260px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
}
.imp-discard form p { margin: 0 0 10px; font-size: .8125rem; }

/* the review grid: grip, date, description, category or account, amount, confidence/skip/delete */
.imp-table { --imp-grid: 16px 136px minmax(0, 1fr) minmax(0, 250px) 130px 210px; }
.imp-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.imp-colhead {
  display: none; grid-template-columns: var(--imp-grid); gap: 0 10px; padding: 0 16px 8px;
  font-size: .6875rem; letter-spacing: .055em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600;
}
.imp-colhead .r { text-align: right; }
.imp-rows { padding: 4px 0; min-height: 8px; }

.imp-row {
  display: grid; gap: 4px 8px; align-items: center; padding: 8px 12px 8px 6px; margin: 0;
  grid-template-columns: 16px minmax(0, 1fr) 128px;
  grid-template-areas: "grip desc amount" "grip cat cat" "grip date meta" "grip err err";
  border-left: 2px solid transparent; transition: background .12s ease;
}
.imp-row + .imp-row { border-top: 1px solid var(--line); }
.imp-row > .grip { grid-area: grip; }
.imp-row > .f-date { grid-area: date; }
.imp-row > .f-desc { grid-area: desc; }
.imp-row > .imp-cat { grid-area: cat; }
.imp-row > .f-amount { grid-area: amount; }
.imp-row > .imp-meta { grid-area: meta; }
.imp-row > .imp-errors { grid-area: err; }
.imp-row:hover { background: var(--surface-sunk); }
.imp-row.low { border-left-color: var(--warn-line); background: var(--warn-tint); }
.imp-row.skipped .f { color: var(--ink-faint); text-decoration: line-through; }
.imp-row.skipped .f-cat, .imp-row.skipped .f-date { text-decoration: none; }
.imp-row.has-error { border-left-color: var(--accent); }
@keyframes saved-flash {
  0%   { border-left-color: var(--income); background-color: color-mix(in srgb, var(--income) 10%, transparent); }
  100% { border-left-color: transparent; background-color: transparent; }
}
.imp-row.saved { animation: saved-flash .6s ease-out; }

.grip {
  color: var(--ink-faint); cursor: grab; user-select: none; align-self: stretch;
  display: flex; align-items: center; justify-content: center; touch-action: none;
}
.grip:hover { color: var(--muted); }
.grip:active { cursor: grabbing; }
.imp-fieldset[disabled] .grip, .imp-fieldset[disabled] .imp-add { display: none; }

/* inline-editable fields: borderless until hover or focus */
.f {
  font: inherit; color: var(--ink); width: 100%; min-width: 0;
  border: 1px solid transparent; border-radius: 6px; background: transparent; padding: 6px 8px;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.f:hover { background: var(--surface); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.f:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.f:disabled { color: var(--ink); opacity: 1; }
.f:disabled:hover { background: transparent; border-color: transparent; box-shadow: none; }
.f[aria-invalid="true"], .f.invalid { border-color: var(--warn-line); background: var(--warn-tint); color: var(--warn); }
.f-date { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .8125rem; }
.f-desc { font-weight: 500; }
.f-amount, .f-counter {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums;
  text-align: right; font-weight: 600;
}
.f-amount.pos { color: var(--income); }
.f-amount.neg { color: var(--expense); }
.imp-cat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.imp-counter .f { padding-right: 48px; }
.imp-counter .cur { font-size: .75rem; }

.imp-meta { display: flex; align-items: center; gap: 10px; justify-content: flex-end; font-size: .78125rem; min-width: 0; }
.conf { display: flex; align-items: center; gap: 6px; width: 72px; }
.conf-bar { flex: 1; height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; }
.conf-bar > i { display: block; height: 100%; border-radius: 99px; background: var(--income); }
.conf.mid .conf-bar > i { background: var(--warn-line); }
.conf.low .conf-bar > i { background: var(--accent); }
.conf-n { font-size: .71875rem; color: var(--muted); }
.conf-none { color: var(--ink-faint); font-size: .75rem; }
.badge {
  display: inline-block; padding: 2px 7px; border-radius: 99px; font-size: .71875rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.badge-dup { background: var(--warn-tint); color: var(--warn); border: 1px solid var(--warn-line); }
.imp-skip { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.del {
  border: none; background: transparent; cursor: pointer; color: var(--ink-faint);
  border-radius: 6px; padding: 5px; display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.del:hover { background: var(--accent-weak); color: var(--accent); }
.imp-errors { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }

.imp-add { border-top: 1px dashed var(--line); padding: 6px 16px 10px; }
.imp-add summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .8125rem; padding: 4px 0; list-style: none; }
.imp-add summary::-webkit-details-marker { display: none; }
.imp-add .form-inline { gap: 8px; margin-top: 6px; }
.imp-add .form-inline label { flex: 1 1 130px; font-size: .78125rem; }
.imp-add .form-inline label.grow { flex: 2 1 200px; }

.sortable-ghost { opacity: .35; }
.sortable-chosen { background: var(--surface) !important; }
.sortable-drag { background: var(--surface); border-radius: 8px; box-shadow: var(--shadow-lg); border-left: 2px solid var(--accent); }

.hint { text-align: center; color: var(--ink-faint); font-size: .75rem; margin-top: 18px; }
.hint kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .6875rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px;
}

.undo-panel .tx-rows { margin-bottom: 12px; }
.undo-refs { margin: 0 0 12px; padding-left: 18px; font-size: .875rem; }
.undo-actions { margin-top: 12px; }

@media (min-width: 900px) {
  .imp-colhead { display: grid; }
  .imp-row {
    grid-template-columns: var(--imp-grid); grid-template-areas: none; gap: 0 10px; padding: 3px 16px;
  }
  .imp-row + .imp-row { border-top: 0; }
  .imp-row > .grip, .imp-row > .f-date, .imp-row > .f-desc, .imp-row > .imp-cat,
  .imp-row > .f-amount, .imp-row > .imp-meta, .imp-row > .imp-errors { grid-area: auto; }
  .imp-row > .imp-errors { grid-column: 2 / -1; padding-bottom: 4px; }
  .grip { opacity: 0; transition: opacity .12s; }
  .imp-row:hover .grip { opacity: 1; }
  .del { opacity: 0; }
  .imp-row:hover .del, .del:focus-visible { opacity: 1; }
}
