/* Tally - self-hosted styles (no CDN, CSP 'self' only) */
:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #dde1dc;
  --text: #1c2321;
  --muted: #64706b;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --green: #15803d;
  --green-bg: #e7f6ec;
  --red: #c2261d;
  --red-bg: #fdecea;
  --amber: #a15c07;
  --amber-bg: #fdf3e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 8px rgba(0, 0, 0, .04);
  --map-date: #2563eb;
  --map-details: #7c3aed;
  --map-amount: #0f766e;
  --map-debit: #c2261d;
  --map-credit: #15803d;
  --map-reference: #a15c07;
  --map-particulars: #be185d;
  --map-code: #0369a1;
  color-scheme: light;
}
/* Dark palette: follows the OS unless the user picked a theme (data-theme on <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121615;
    --surface: #1a201e;
    --surface-2: #222a27;
    --border: #2f3935;
    --text: #e6ebe8;
    --muted: #94a19b;
    --brand: #2dd4bf;
    --brand-ink: #062b27;
    --green: #4ade80;
    --green-bg: #12301f;
    --red: #f87171;
    --red-bg: #3a1714;
    --amber: #fbbf24;
    --amber-bg: #3a2a0c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121615;
  --surface: #1a201e;
  --surface-2: #222a27;
  --border: #2f3935;
  --text: #e6ebe8;
  --muted: #94a19b;
  --brand: #2dd4bf;
  --brand-ink: #062b27;
  --green: #4ade80;
  --green-bg: #12301f;
  --red: #f87171;
  --red-bg: #3a1714;
  --amber: #fbbf24;
  --amber-bg: #3a2a0c;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.muted { color: var(--muted); }
.big { font-size: 2.5rem; margin: 0; font-weight: 700; }
.center { text-align: center; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: .5rem; }
.brand-mark { width: 30px; height: 30px; display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.mainnav a { padding: .4rem .75rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.mainnav a:hover { background: var(--surface-2); color: var(--text); }
.mainnav a.active { background: var(--surface-2); color: var(--text); }
.container { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.crumbs { margin: 0; color: var(--muted); font-size: .9rem; }
.crumbs a { color: var(--muted); }
.actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
td.actions { justify-content: flex-end; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; border: 0; padding: 0; margin: 0; }
.row > .field { flex: 1 1 160px; }
.grow { flex: 1; }
fieldset.row legend { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; width: 100%; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.card.empty { text-align: center; padding: 2.5rem 1.25rem; }

/* ---------- flashes ---------- */
.flashes { margin-bottom: 1rem; }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .5rem; border: 1px solid var(--border); background: var(--surface); }
.flash-success { background: var(--green-bg); border-color: transparent; }
.flash-error { background: var(--red-bg); border-color: transparent; }
.flash-info { background: var(--surface-2); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.field label, .label { font-weight: 600; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=search], input:not([type]), select, textarea {
  font: inherit; color: inherit; background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.has-error input, .has-error select { border-color: var(--red); }
.hint { color: var(--muted); font-size: .85rem; }
.error { color: var(--red); font-size: .85rem; }
.req { color: var(--red); }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; align-items: center; }
.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; }
.inline-form input { flex: 1; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  padding: .55rem .95rem; border-radius: 8px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-block { width: 100%; margin-top: .5rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linklike {
  background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-align: left;
}
.linklike.danger { color: var(--red); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg { display: flex; align-items: center; cursor: pointer; font-weight: 500; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { padding: .5rem .9rem; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg:has(input:checked) { background: var(--surface-2); font-weight: 700; }
.seg-income:has(input:checked) { background: var(--green-bg); color: var(--green); }
.seg-expense:has(input:checked) { background: var(--red-bg); color: var(--red); }
.seg:has(input:focus-visible) { outline: 2px solid var(--brand); }

details.more { margin: 0 0 1rem; }
details.more > summary { cursor: pointer; color: var(--brand); font-weight: 500; font-size: .9rem; margin-bottom: .75rem; }

/* ---------- menus ---------- */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
.usermenu > summary { padding: .4rem .75rem; border-radius: 8px; font-weight: 500; }
.usermenu > summary:hover { background: var(--surface-2); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + .35rem); min-width: 220px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12); padding: .4rem; display: flex; flex-direction: column;
}
.menu-panel > a, .menu-panel > form > button, .menu-panel .linklike {
  display: block; width: 100%; padding: .5rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none;
}
.menu-panel > a:hover, .menu-panel .linklike:hover { background: var(--surface-2); }
.menu-panel .linklike.danger { color: var(--red); }

/* ---------- money & status ---------- */
.amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.zero { color: var(--muted); }
.pill {
  display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-amber { background: var(--amber-bg); color: var(--amber); }
.entry-name { font-weight: 500; }
.kind-label { font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
td > .kind-label { margin-left: .35rem; vertical-align: 1px; }
.kind-label.kind-income { color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.period {
  display: flex; flex-wrap: wrap; gap: .35rem .75rem; align-items: baseline;
  padding: .65rem 1rem; border-radius: 8px; background: var(--surface-2); margin-bottom: 1rem;
}
.period-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.period-len { color: var(--muted); font-size: .9rem; }
.period-wrap { margin-bottom: 1rem; }
.period-wrap .period { margin-bottom: .35rem; }
.income-hint { display: none; margin: 0; font-size: .88rem; color: var(--green); font-weight: 500; }
#entry-form:has(.seg-income input:checked) .period { background: var(--green-bg); outline: 2px solid var(--green); }
#entry-form:has(.seg-income input:checked) .income-hint { display: block; }
.normalised { color: var(--muted); font-size: .9rem; margin: -.5rem 0 1rem; min-height: 1.3em; }

.totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 1rem; border-left-width: 6px;
}
.totals.is-green { border-left-color: var(--green); }
.totals.is-red { border-left-color: var(--red); }
.total { background: var(--surface); padding: .85rem 1rem; display: flex; flex-direction: column; gap: .2rem; }
.total > span { color: var(--muted); font-size: .82rem; font-weight: 600; }
.total > strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.totals.small .total > strong { font-size: 1.05rem; }
.totals-actual .total > strong { font-size: 1.1rem; }
.is-green .total-net { background: var(--green-bg); }
.is-red .total-net { background: var(--red-bg); }
.is-green .total-net > strong { color: var(--green); }
.is-red .total-net > strong { color: var(--red); }
.total-net .pill { align-self: flex-start; }

.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.budget-card { display: block; text-decoration: none; color: inherit; border-top: 5px solid var(--green); transition: transform .1s; margin: 0; }
.budget-card.is-red { border-top-color: var(--red); }
.budget-card:hover { transform: translateY(-2px); }
.budget-card-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.budget-card h2 { margin: 0; }
.budget-card p { margin: .2rem 0 .75rem; font-size: .9rem; }
.mini-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 0 0 .75rem; }
.mini-totals dt { font-size: .75rem; color: var(--muted); }
.mini-totals dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

details.rename > summary { list-style: none; cursor: pointer; }
details.rename > summary::-webkit-details-marker { display: none; }
details.rename[open] > summary { display: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.table tfoot th { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }
.table-toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.tx-table tr.unassigned td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.tx-table td.assign { min-width: 260px; }
.tx-table td.assign select { padding: .35rem .5rem; font-size: .88rem; }
.suggest {
  margin-top: .3rem; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  border: 1px dashed var(--brand); color: var(--brand); background: transparent; border-radius: 999px; padding: .1rem .6rem;
}
.suggest:hover { background: var(--surface-2); }
tr.dupe td { opacity: .55; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .75rem; }
.filters input[type=search] { flex: 1 1 200px; width: auto; }
.filters select { width: auto; }
.filters .compact { display: flex; gap: .35rem; align-items: center; font-size: .85rem; color: var(--muted); }
.filters .compact input { width: auto; padding: .45rem .5rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; }

/* ---------- import ---------- */
.dropzone {
  display: flex; flex-direction: column; gap: .4rem; align-items: center; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem 1rem; cursor: pointer;
}
.dropzone:hover { border-color: var(--brand); }
.dropzone input[type=file] { max-width: 100%; }
.filename { font-weight: 600; }
.steps { padding-left: 1.2rem; color: var(--muted); }
.steps li { margin-bottom: .35rem; }
.warn { border-left: 5px solid var(--amber); }
.warn > summary { cursor: pointer; }

.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 1rem; }
.amount-mode { grid-column: 1 / -1; }
#map-form:has(input[name=amount_mode][value=single]:checked) .mode-split,
#map-form:has(input[name=amount_mode][value=split]:checked) .mode-single { display: none; }
.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.sw-date { background: var(--map-date); } .sw-details { background: var(--map-details); }
.sw-amount { background: var(--map-amount); } .sw-debit { background: var(--map-debit); }
.sw-credit { background: var(--map-credit); } .sw-reference { background: var(--map-reference); }
.sw-particulars { background: var(--map-particulars); } .sw-code { background: var(--map-code); }

.raw-table td, .raw-table th { white-space: nowrap; max-width: 30ch; overflow: hidden; text-overflow: ellipsis; }
.raw-table .rownum { color: var(--muted); width: 3rem; }
.raw-table tr.is-header td { font-weight: 700; background: var(--surface-2); }
.raw-table .tag { display: block; font-size: .68rem; min-height: 1em; color: #fff; }
.raw-table th[class*="map-"] .tag { padding: .1rem .35rem; border-radius: 4px; margin-bottom: .2rem; width: max-content; }
.map-date { --c: var(--map-date); } .map-details { --c: var(--map-details); }
.map-amount { --c: var(--map-amount); } .map-debit { --c: var(--map-debit); }
.map-credit { --c: var(--map-credit); } .map-reference { --c: var(--map-reference); }
.map-particulars { --c: var(--map-particulars); } .map-code { --c: var(--map-code); }
.raw-table [class*="map-"] { box-shadow: inset 3px 0 0 var(--c); background: color-mix(in srgb, var(--c) 9%, transparent); }
.raw-table th[class*="map-"] .tag { background: var(--c); }

@media (max-width: 640px) {
  .container { padding: 1rem .75rem 3rem; }
  .topbar { gap: .5rem 1rem; }
  .mainnav { order: 3; flex-basis: 100%; }
  .totals { border-left-width: 1px; border-top-width: 5px; }
  .totals.is-green { border-top-color: var(--green); }
  .totals.is-red { border-top-color: var(--red); }
}

/* ---------- entry shortcuts ---------- */
.tile-action { font-size: .82rem; font-weight: 600; text-decoration: none; margin-top: .15rem; }
.tile-action:hover { text-decoration: underline; }
.new-category { display: none; }
#entry-form:has(#category_id option[value="0"]:checked) .new-category { display: block; }
@supports not selector(:has(*)) { .new-category { display: block; } }
.empty .actions { justify-content: center; }

/* ---------- entry form: income vs expense ---------- */
.income-only { display: none; }
#entry-form:has(.seg-income input:checked) .income-only { display: block; }
#entry-form:has(.seg-income input:checked) .expense-only { display: none; }
.category-hint { margin: -.6rem 0 1rem; }
tr.not-counted td { color: var(--muted); }
tr.not-counted .neg { color: var(--muted); }

.toggle { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; font-weight: 600; margin-bottom: .35rem; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track {
  position: relative; width: 2.4rem; height: 1.35rem; border-radius: 999px; flex: none;
  background: var(--border); transition: background .15s;
}
.toggle-track::after {
  content: ""; position: absolute; top: .15rem; left: .15rem; width: 1.05rem; height: 1.05rem;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
.toggle input:checked + .toggle-track { background: var(--brand); }
.toggle input:checked + .toggle-track::after { transform: translateX(1.05rem); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- admin: registration ---------- */
.registration { border-left: 5px solid var(--green); }
.registration.is-open { border-left-color: var(--amber); }
.registration-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.registration-row p { margin: 0; }

/* ---------- theme toggle ---------- */
.theme-toggle {
  margin-left: auto; display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.mainnav ~ .theme-toggle { margin-left: 0; }
.theme-toggle:hover { background: var(--surface-2); }
.theme-icon { width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid currentColor; position: relative; overflow: hidden; }
/* system: half-filled circle; light: hollow (sun-ish); dark: filled crescent */
.theme-toggle[data-mode="system"] .theme-icon::after { content: ""; position: absolute; inset: 0 0 0 50%; background: currentColor; }
.theme-toggle[data-mode="dark"] .theme-icon { background: currentColor; }
.theme-toggle[data-mode="dark"] .theme-icon::after {
  content: ""; position: absolute; width: 100%; height: 100%; top: -30%; left: 35%; border-radius: 50%; background: var(--surface);
}
.theme-toggle[data-mode="light"] .theme-icon { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px currentColor; width: .7rem; height: .7rem; }

/* ---------- budget: income tile & collapsible categories ---------- */
.total-income { gap: .35rem; }
.income-list { list-style: none; margin: .25rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.income-list li {
  display: grid; grid-template-columns: 1fr auto; column-gap: .75rem; align-items: baseline;
  padding-top: .3rem; border-top: 1px solid var(--border); font-size: .9rem;
}
.income-list li a { color: var(--text); text-decoration: none; font-weight: 600; }
.income-list li a:hover { text-decoration: underline; }
.income-list li small { grid-column: 1; font-size: .78rem; }
.income-list .income-amt { grid-column: 2; grid-row: 1 / span 2; font-variant-numeric: tabular-nums; font-weight: 600; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 1.5rem 0 .5rem; }
.section-head h2 { margin: 0; }
details.category { padding: 0; }
details.category > summary.category-head {
  list-style: none; cursor: pointer; padding: .9rem 1.25rem; margin: 0;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
details.category > summary::-webkit-details-marker { display: none; }
details.category > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
details.category[open] > summary:hover { border-radius: var(--radius) var(--radius) 0 0; }
.category-head h3 { margin: 0; font-size: 1.05rem; }
.category-count { font-size: .82rem; }
.category-sum { margin-left: auto; display: flex; gap: .6rem; align-items: baseline; font-weight: 600; font-variant-numeric: tabular-nums; }
.category-sum small { font-weight: 400; }
.chevron { width: .55rem; height: .55rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; flex: none; margin-right: .1rem; }
details.category[open] > summary .chevron { transform: rotate(45deg); }
.category-body { padding: 0 1.25rem 1rem; }
.category-tools { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.category-tools details.rename { display: flex; gap: .35rem; align-items: center; }
.category-tools details.rename > summary { list-style: none; }
.category-tools details.rename > summary::-webkit-details-marker { display: none; }
.category-tools details.rename[open] > summary { display: none; }
.btn.danger { color: var(--red); }
.no-budget { font-size: .85rem; }
.outside-period > summary { cursor: pointer; }
.outside-period .table { margin-top: .75rem; }

/* ---------- transfers & accounts ---------- */
tr.is-transfer td { color: var(--muted); }
.transfer-check { margin-bottom: 1rem; }
#tx-form:has(.transfer-check input:checked) .not-transfer { display: none; }
.card-panel { border-left: 5px solid var(--green); }
.card-panel.is-red { border-left-color: var(--red); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem 1rem; margin: .5rem 0; }
.card-grid div { display: flex; flex-direction: column; }
.card-grid span { font-size: .8rem; color: var(--muted); font-weight: 600; }
.card-grid strong { font-variant-numeric: tabular-nums; }
.card-panel + .card-panel { margin-top: -.25rem; }
.credit-only { display: none; }
#account-form:has(.seg-credit input:checked) .credit-only { display: block; }
#account-form:has(.seg-credit input:checked) .bank-only { display: none; }
.category-head-plain { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; }
.category-head-plain h2 { margin: 0; }
.small-print { font-size: .85rem; margin: .25rem 0 0; }
.income-list li.extra-income > span:first-child { font-weight: 600; }
.roll-hint { margin: -.35rem 0 1rem 1.6rem; }

/* ---------- currency prefix on amount inputs ---------- */
.input-prefix { display: flex; align-items: stretch; }
.input-prefix .prefix {
  display: flex; align-items: center; padding: 0 .65rem; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-right: 0; border-radius: 8px 0 0 8px;
}
.input-prefix input { border-radius: 0 8px 8px 0; min-width: 0; }
.has-error .input-prefix .prefix { border-color: var(--red); }

/* ---------- searchable dropdown (combobox) ---------- */
.combo { position: relative; }
.combo-input { padding-right: 1.8rem !important; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-repeat: no-repeat;
  background-size: 5px 5px; background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; }
.tx-table .combo-input { padding: .35rem .5rem; font-size: .88rem; }
.combo-list {
  position: fixed; z-index: 50; margin: 0; padding: .3rem; list-style: none; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18); font-size: .9rem; max-width: min(460px, calc(100vw - 24px));
}
.combo-group { padding: .45rem .55rem .2rem; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); }
.combo-option { padding: .4rem .6rem; border-radius: 6px; cursor: pointer; }
.combo-option.is-active { background: var(--surface-2); }
.combo-option.is-selected { font-weight: 600; color: var(--brand); }
.combo-empty { padding: .5rem .6rem; color: var(--muted); }
.import-options { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
#period-form select { width: auto; max-width: 100%; }

/* ---------- selection, deletion, planned net with extra ---------- */
.select-col { width: 2rem; padding-right: 0 !important; }
.select-col input { width: 1rem; height: 1rem; margin: 0; cursor: pointer; }
.tx-table tr.unassigned td:first-child { box-shadow: none; }
.tx-table tr.unassigned td:nth-child(2) { box-shadow: inset 3px 0 0 var(--amber); }
.tx-table tr.is-selected td { background: color-mix(in srgb, var(--red) 7%, transparent); }
.row-actions { white-space: nowrap; text-align: right; }
.toolbar-spacer { flex: 1; }
.selected-count { font-size: .85rem; }
.delete-scope { padding-left: 1.2rem; }
.delete-scope li { margin-bottom: .25rem; }
.net-extra { display: flex; flex-direction: column; gap: .1rem; margin-top: .45rem; padding-top: .45rem;
  border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent); }
.net-extra > span { font-size: .78rem; font-weight: 600; color: var(--muted); }
.net-extra > strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.total-net .net-extra > strong { color: inherit; }

/* ---------- split transactions ---------- */
.split-summary { display: flex; flex-direction: column; gap: .2rem; min-width: 220px; }
.split-badge {
  align-self: flex-start; font-size: .75rem; font-weight: 700; text-decoration: none;
  padding: .1rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.split-badge:hover { border-color: var(--brand); color: var(--brand); }
.split-lines { list-style: none; margin: 0; padding: 0 0 0 .55rem; border-left: 2px solid var(--border); font-size: .85rem; }
.split-lines li { display: flex; justify-content: space-between; gap: .75rem; padding: .05rem 0; }
.split-lines li.is-scope { font-weight: 700; color: var(--brand); }
.split-amt { font-variant-numeric: tabular-nums; color: var(--muted); }
.split-lines li.is-scope .split-amt { color: inherit; }
.card.wide-narrow { max-width: 680px; }
.split-tx { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface-2); border-radius: 8px; margin-bottom: 1rem; }
.split-tx > div { display: flex; flex-direction: column; }
.split-total { font-size: 1.25rem; font-weight: 700; }
.split-table td { vertical-align: top; }
.split-table .split-amount { width: 10rem; }
.split-remaining { font-weight: 600; font-size: .9rem; }
details.category.is-builtin { border-style: dashed; }

/* ---------- in-place split editor & maths ---------- */
.tx-table tr.is-splitting td { background: var(--surface-2); }
.split-editor-row > td { padding: 0 .6rem .9rem !important; background: var(--surface-2); }
.split-editor { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: .85rem 1rem; }
.split-editor-head { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; margin-bottom: .6rem; }
.split-editor-head code { font-size: .82rem; background: var(--surface-2); padding: 0 .3rem; border-radius: 4px; }
.split-editor-lines { display: flex; flex-direction: column; gap: .45rem; }
.split-line { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(120px, 13rem) 2rem; gap: .5rem; align-items: start; }
.split-line-amount { position: relative; flex-wrap: wrap; }
.split-editor-foot { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .7rem; }
.math-result { flex-basis: 100%; font-size: .78rem; color: var(--muted); min-height: 1em; padding-left: .2rem; font-variant-numeric: tabular-nums; }
.math-result.is-error { color: var(--red); }
.split-amount .input-prefix { flex-wrap: wrap; }
@media (max-width: 640px) {
  .split-line { grid-template-columns: 1fr 2rem; }
  .split-line-amount { grid-column: 1; }
}

/* ---------- import: which account ---------- */
.account-pick { border-left: 5px solid var(--green); padding: .85rem 1.1rem; }
.account-pick.is-unsure { border-left-color: var(--amber); }
.account-pick-row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.account-pick-row label { font-weight: 600; }
.account-pick-row select { width: auto; min-width: 220px; }
.account-pick-why { margin: .4rem 0 0; font-size: .88rem; }

/* ---------- card used ---------- */
.card-chip { display: block; font-size: .78rem; color: var(--muted); letter-spacing: .01em; }
.sw-card { background: #6b7280; } .map-card { --c: #6b7280; }

/* ---------- double-click to edit ---------- */
[data-edit-url] { cursor: default; }
tr[data-edit-url]:hover td, .income-list li[data-edit-url]:hover { background: color-mix(in srgb, var(--brand) 5%, transparent); }

/* ---------- drag to reorder budget lines ---------- */
.grip-col { width: 1.6rem; padding-left: .2rem !important; padding-right: 0 !important; }
.drag-handle {
  border: 0; background: transparent; color: var(--muted); cursor: grab; padding: .2rem .25rem; border-radius: 4px;
  font-size: .9rem; line-height: 1; letter-spacing: -.12em; touch-action: none; opacity: .45;
}
tr:hover .drag-handle, .drag-handle:focus-visible { opacity: 1; }
.drag-handle:hover { background: var(--surface-2); color: var(--text); }
body.is-reordering, body.is-reordering * { cursor: grabbing !important; user-select: none; }
tr.is-dragging td { background: color-mix(in srgb, var(--brand) 12%, var(--surface)) !important;
  box-shadow: inset 0 1px 0 var(--brand), inset 0 -1px 0 var(--brand); }
tbody.entry-rows .empty-row { display: none; }
tbody.entry-rows:not(:has(tr[data-entry-id])) .empty-row { display: table-row; }
body.is-reordering details.category[data-drop-category] > summary { outline: 1px dashed var(--border); outline-offset: -4px; }
.reorder-status { font-size: .85rem; margin-left: auto; margin-right: .75rem; }
.reorder-status.is-error { color: var(--red); }

/* ---------- password reset links ---------- */
.reset-link-box { display: flex; gap: .5rem; margin: 1rem 0; }
.reset-link-box input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.reset-facts { padding-left: 1.1rem; }

/* ---------- profile pictures ---------- */
.avatar { border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); display: inline-block; vertical-align: middle; }
.avatar-sm { width: 26px; height: 26px; }
.avatar-xs { width: 22px; height: 22px; margin-right: .4rem; }
.avatar-lg { width: 72px; height: 72px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--border); }
.usermenu > summary { display: flex; align-items: center; gap: .5rem; }
.avatar-settings { display: flex; gap: 1.25rem; align-items: flex-start; flex-wrap: wrap; }
.avatar-options { flex: 1; display: flex; flex-direction: column; gap: 1rem; min-width: 240px; }
.avatar-grid { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .35rem; }
.avatar-choice { padding: 3px; border: 2px solid transparent; border-radius: 50%; background: none; cursor: pointer; line-height: 0; }
.avatar-choice:hover { border-color: var(--border); }
.avatar-choice.is-current { border-color: var(--brand); }
.avatar-choice img { border-radius: 50%; }
.avatar-upload input[type=file] { flex: 1; min-width: 0; }
.user-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.user-head h1 { margin: 0; }
.user-head p { margin: .2rem 0 0; font-size: .88rem; }

/* ---------- profile picture crop window ---------- */
dialog.cropper {
  border: 1px solid var(--border); border-radius: 14px; padding: 1.25rem; background: var(--surface); color: var(--text);
  width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.cropper::backdrop { background: rgba(10, 14, 13, .6); }
.cropper-head h2 { margin: 0 0 .25rem; }
.cropper-head p { margin: 0 0 1rem; font-size: .88rem; }
.cropper-body { display: flex; gap: 1.25rem; align-items: flex-start; flex-wrap: wrap; }
.cropper-stage { position: relative; display: inline-block; line-height: 0; user-select: none; touch-action: none;
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; border-radius: 6px; overflow: hidden; }
.cropper-stage img { display: block; max-width: min(560px, calc(100vw - 80px)); max-height: 60vh; width: auto; height: auto; }
.crop-box {
  position: absolute; box-sizing: border-box; border: 2px solid #fff; cursor: move; touch-action: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55), 0 0 0 1px rgba(0, 0, 0, .5);
  background-image: linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: calc(100% / 3) calc(100% / 3); background-position: -1px -1px;
}
.crop-box::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255,255,255,.7); pointer-events: none; }
.crop-box:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.crop-handle { position: absolute; width: 16px; height: 16px; background: #fff; border: 2px solid var(--brand); border-radius: 3px; }
.crop-handle.nw { left: -9px; top: -9px; cursor: nwse-resize; }
.crop-handle.se { right: -9px; bottom: -9px; cursor: nwse-resize; }
.crop-handle.ne { right: -9px; top: -9px; cursor: nesw-resize; }
.crop-handle.sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.cropper-side { flex: 1; min-width: 180px; }
.cropper-previews { display: flex; gap: 1rem; align-items: flex-end; margin: .4rem 0 .75rem; }
.cropper-previews canvas { border-radius: 50%; background: var(--surface-2); box-shadow: 0 0 0 1px var(--border); }
#cropper-preview-lg { width: 72px; height: 72px; }
#cropper-preview-sm { width: 26px; height: 26px; }

/* ---------------------------------------------------------------- which budget a transaction belongs to */
.notice { padding: .6rem .9rem; border-radius: 8px; border: 1px solid var(--border); border-left: 4px solid var(--amber);
          background: var(--surface); margin: .75rem 0; }
.tx-budget { font-size: .78rem; }
.bring-in-table td.from { white-space: nowrap; }
.memberships { list-style: none; margin: .2rem 0; padding: 0; }
.memberships li { padding: .15rem 0; }

/* ---------------------------------------------------------------- export / import Tally files */
.checklist, .export-options { border: 0; padding: 0; margin: 0 0 1rem; }
.checklist legend, .export-options legend { font-weight: 600; margin-bottom: .4rem; }
.checklist .check, .export-options .check { display: block; margin: .25rem 0; }
.export-pick { margin: .5rem 0 1rem; }
.plan-summary { border: 1px solid var(--border); border-left: 4px solid var(--green); border-radius: 8px;
                padding: .6rem 1rem; margin-bottom: 1rem; background: var(--surface); }
.plan-summary.is-red { border-left-color: var(--red); }
.plan-summary h2 { margin-top: 0; font-size: 1.05rem; }
.plan-summary ul { margin: .25rem 0 .5rem 1.1rem; padding: 0; }
.plan-note { margin: .3rem 0; padding: .3rem .6rem; border-radius: 6px; font-size: .9rem; }
.plan-error { background: var(--red-bg); }
.plan-warn { background: var(--amber-bg); }
.plan-info { color: var(--muted); }
.plan-budget { border-top: 1px solid var(--border); padding: .75rem 0; }
.plan-budget-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between; align-items: center; }
.plan-unmatched td:first-child { border-left: 3px solid var(--amber); }
