/* Autonomo Pilot — design tokens + layout.
   Brand: navy #0a2a4d + teal #1cbfc4 (from the AP logo).
   Themes: light (default) and dark via html[data-theme="dark"] — all colors are
   tokens; components must never hardcode a color that differs between themes.
   Desktop-first; single column ≤768px (stack-wide mobile rule). */

:root {
  --navy: #0a2a4d;
  --teal: #1cbfc4;
  --teal-dark: #12969b;

  --bg: #f2f5f8;
  --card: #ffffff;
  --line: #e2e9ef;
  --line-strong: #c9d5df;
  --hover-bg: #eef4f8;
  --row-hover: #f7fafc;

  --ink: #1e2b38;
  --ink-2: #52667a;
  --ink-3: #8595a6;
  --heading: var(--navy);
  --link: var(--teal-dark);

  --btn-bg: var(--navy);
  --btn-bg-hover: #123a66;
  --nav-active-bg: var(--navy);
  --nav-active-ink: #ffffff;

  --red: #b3261e;
  --green: #157a3c;
  --amber-bg: #fdf6ec;
  --amber-line: #eed9b1;
  --amber-ink: #7c5514;
  --flag-bg: #fdf3e7;
  --flag-hover: #faf0e0;
  --suggest-bg: #e9f7ee;
  --suggest-hover: #ddf1e5;

  --input-bg: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(10, 42, 77, .05), 0 1px 8px rgba(10, 42, 77, .04);
  --focus: 0 0 0 3px #1cbfc44d;
}

html[data-theme="dark"] {
  --bg: #0d1722;
  --card: #16242f;
  --line: #24343f;
  --line-strong: #37495a;
  --hover-bg: #1d2e3d;
  --row-hover: #1a2833;

  --ink: #dce6ee;
  --ink-2: #a3b4c2;
  --ink-3: #718496;
  --heading: #eef4f8;
  --link: #3fd2d8;

  --btn-bg: #1cbfc4;
  --btn-bg-hover: #3fd2d8;
  --nav-active-bg: #1cbfc4;
  --nav-active-ink: #06202b;

  --red: #ff8a80;
  --green: #6fd695;
  --amber-bg: #33290f;
  --amber-line: #57451c;
  --amber-ink: #e8c87a;
  --flag-bg: #2c2416;
  --flag-hover: #362c1a;
  --suggest-bg: #14301f;
  --suggest-hover: #1a3b27;

  --input-bg: #101d27;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 8px rgba(0, 0, 0, .2);
  --focus: 0 0 0 3px #1cbfc466;
}

* { box-sizing: border-box; }
/* The hidden attribute must always win, even over display:flex rules —
   this exact interaction shipped a stuck-open feedback panel once. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--link); }
a:hover { color: var(--heading); }

h1 { font-size: 24px; font-weight: 700; color: var(--heading); margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 700; color: var(--heading); margin: 0 0 14px; }

.demo-strip {
  background: var(--navy); color: #fff; text-align: center;
  padding: 7px 14px; font-size: 13px;
}
html[data-theme="dark"] .demo-strip { background: var(--teal); color: #06202b; }

/* ---------- layout ----------
   Desktop: the PAGE never scrolls — the sidebar is window-height and fixed in
   place; the content pane owns vertical scroll. Long/wide tables scroll inside
   their own container (never the window). Mobile reverts to normal flow. */
html, body { height: 100%; }
body { overflow: hidden; }
.layout { display: flex; height: 100vh; }
.demo-strip + .layout { height: calc(100vh - 34px); }
.sidebar {
  width: 216px; flex: 0 0 216px;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px 16px;
  gap: 2px;
}
.brand { display: block; padding: 0 8px 16px; text-align: center; }
.brand img {
  display: block; margin: 0 auto;
  width: 128px; max-width: 100%; height: auto;
}
.brand .logo-dark { display: none; }
html[data-theme="dark"] .brand .logo-light { display: none; }
html[data-theme="dark"] .brand .logo-dark { display: block; }
.brand .demo-pill { margin-top: 8px; display: inline-block; }
.sidebar a {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  padding: 9px 12px; border-radius: 8px; font-size: 14px;
}
.sidebar a:hover { background: var(--hover-bg); color: var(--heading); }
.sidebar a.active {
  background: var(--nav-active-bg); color: var(--nav-active-ink);
  box-shadow: inset 3px 0 0 var(--teal);
}
.sidebar .badge {
  margin-left: auto;
  background: var(--teal); color: #fff;
  border-radius: 99px; padding: 1px 8px; font-size: 12px; font-weight: 700;
}
html[data-theme="dark"] .sidebar .badge { color: #06202b; }
.sidebar a.active .badge { background: var(--card); color: var(--heading); }
.theme-toggle {
  margin-top: auto;
  background: none; border: 1px solid var(--line); color: var(--ink-2);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 0;
}
.theme-toggle:hover { background: var(--hover-bg); color: var(--heading); }
.sidebar-foot { padding: 12px 8px 0; font-size: 12px; color: var(--ink-3); word-break: break-all; }
.lock-note { color: var(--green); font-weight: 600; margin-bottom: 4px; cursor: help;
  word-break: normal; overflow-wrap: normal; white-space: nowrap; font-size: 11px; }
.demo-pill {
  background: var(--teal); color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 4px; padding: 2px 6px; letter-spacing: .06em; vertical-align: middle;
}
html[data-theme="dark"] .demo-pill { color: #06202b; }
.sidebar { overflow-y: auto; }
.content { flex: 1; padding: 28px 36px 48px; min-width: 0; max-width: 1240px;
           overflow-y: auto; height: 100%; display: flex; flex-direction: column; }
.content > * { flex-shrink: 0; }

/* Full-height list pages (ledger/review): the table card fills the remaining
   viewport and the TABLE scrolls inside it, header row sticky. */
.page-fill { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.page-fill > .card.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; }
.card.fill .table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }
.card.fill table tr:first-child th {
  position: sticky; top: 0; z-index: 3; background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

/* page header row: title + period selector / actions (right padding clears the
   fixed account chip) */
.page-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 22px; padding-right: 52px;
}

/* top-right account menu */
.account-chip-wrap { position: fixed; top: 14px; right: 20px; z-index: 880; }
.account-chip {
  width: 36px; height: 36px; min-height: 0; padding: 0;
  border-radius: 50%; font-weight: 700; font-size: 15px;
  background: var(--navy); color: #fff; border: 2px solid var(--card);
  box-shadow: var(--shadow); cursor: pointer;
}
html[data-theme="dark"] .account-chip { background: var(--teal); color: #06202b; }
.account-menu {
  position: absolute; right: 0; top: 44px; min-width: 230px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); overflow: hidden; padding: 4px 0;
}
.account-menu .account-email {
  padding: 10px 14px; font-size: 12.5px; color: var(--ink-3);
  border-bottom: 1px solid var(--line); word-break: break-all;
}
.account-menu a {
  display: block; padding: 9px 14px; text-decoration: none;
  color: var(--ink); font-size: 14px;
}
.account-menu a:hover { background: var(--hover-bg); color: var(--heading); }
@media (max-width: 768px) {
  .account-chip-wrap { position: absolute; top: 12px; right: 12px; }
  .page-head { padding-right: 0; }
}
.page-head h1 { margin: 0; flex: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px;
}
.stat .value { font-size: 24px; font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.stat .value.neg { color: var(--red); }
.stat .value.pos { color: var(--green); }
.stat .muted { margin-top: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
tbody tr:hover td, table tr:hover td { background: var(--row-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num.neg, .amount-neg { color: var(--red); }
td.num.pos, .amount-pos { color: var(--green); }
tr.flagged td { background: var(--flag-bg); }
tr.flagged:hover td { background: var(--flag-hover); }
tr.total td { font-weight: 700; color: var(--heading); border-top: 2px solid var(--line-strong); background: none; }
.muted { color: var(--ink-3); font-size: 13px; }

/* Sticky action column: in wide editable tables (Settings), the Save/Delete
   cell pins to the right edge of the scroll container so the primary action
   is never pushed out of view by a narrow window — the data scrolls under it. */
td.actions, th.actions {
  position: sticky; right: 0; z-index: 1;
  background: var(--card);
  box-shadow: -10px 0 10px -10px rgba(10, 42, 77, .25);
}
td.actions { white-space: nowrap; }
tbody tr:hover td.actions, table tr:hover td.actions { background: var(--row-hover); }
tr.flagged td.actions { background: var(--flag-bg); }
html[data-theme="dark"] td.actions, html[data-theme="dark"] th.actions {
  box-shadow: -10px 0 10px -10px rgba(0, 0, 0, .6);
}

/* ---------- notices ---------- */
.warn {
  background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink);
  border-radius: 8px; padding: 10px 14px; margin: 8px 0; font-size: 13.5px;
}
.warn a { color: inherit; font-weight: 600; }
.error { background: #fbeaea; border-color: #e3b0ac; color: #7c1f1a; }
html[data-theme="dark"] .error { background: #351b19; border-color: #6b2f2a; color: #f5b5af; }
.ok { color: var(--green); }
.empty-state { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty-state .big { font-size: 15px; font-weight: 600; color: var(--heading); margin-bottom: 6px; }
.disclaimer {
  font-size: 12.5px; color: var(--amber-ink); background: var(--amber-bg);
  border: 1px solid var(--amber-line); border-radius: 8px;
  padding: 10px 14px; margin-top: 20px;
}

.warn.attn { display: flex; align-items: center; gap: 12px; }
/* high specificity on purpose: .warn a { color: inherit } and .btn both try to
   restyle this link — this rule must own both background and text color */
.warn.attn a.attn-fix {
  margin-left: auto; flex: 0 0 auto;
  padding: 5px 14px; min-height: 0; font-size: 13px; font-weight: 600;
  background: var(--card); color: var(--amber-ink);
  border: 1px solid var(--amber-ink); border-radius: 8px;
}
.warn.attn a.attn-fix:hover { background: var(--amber-ink); color: var(--card); }

/* ---------- forms & controls ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=email],
select, textarea {
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 10px; background: var(--input-bg); color: var(--ink); min-height: 38px;
}
/* type=search must match the text inputs exactly — kill native search chrome
   (this regressed once: the search box rendered as an unstyled dark square) */
input[type=search] { -webkit-appearance: none; appearance: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: none; box-shadow: var(--focus); border-color: var(--teal);
}
input.small { width: 104px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input[type=checkbox] {
  width: 16px; height: 16px; margin: 0;
  vertical-align: middle;
  accent-color: var(--teal);
}

button, .btn {
  background: var(--btn-bg); color: var(--nav-active-ink); border: 0; border-radius: 8px;
  padding: 9px 16px; min-height: 38px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
  transition: background .12s ease;
}
button:hover, .btn:hover { background: var(--btn-bg-hover); color: var(--nav-active-ink); }
button.secondary, .btn.secondary {
  background: var(--card); color: var(--heading); border: 1px solid var(--line-strong);
}
button.secondary:hover, .btn.secondary:hover { background: var(--hover-bg); color: var(--heading); }
button.danger { background: var(--red); color: #fff; }
button.danger:hover { background: #8f1e17; color: #fff; }

form.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.controls label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ledger: one line per row; forms never wrap */
.ledger-table td { white-space: nowrap; }
.ledger-table td.desc .desc-text {
  display: inline-block; max-width: 260px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
.ledger-table form.inline { flex-wrap: nowrap; }
.ledger-table select { max-width: 220px; }

/* settings rules: dirty-state saves */
tr.dirty-row td { background: var(--flag-bg); }
tr.dirty-row:hover td { background: var(--flag-hover); }

/* Bulk-action header rows reserve the control height so showing/hiding the
   "Update all selected" controls never shifts the layout. */
.bulk-head { min-height: 42px; align-items: center; }
/* rules tab: bulk controls live inline in the toolbar row (no reserved row) */
#rules-bulk-form { margin-left: auto; }

/* review queue: toolbar, suggested rows, pagination */
.review-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.review-search { flex: 1; min-width: 200px; }
/* scoped override: the global .tabs bottom margin is declared LATER in this
   file and would win on equal specificity, knocking the row off-centre */
.review-toolbar .tabs { margin-bottom: 0; align-items: center; }
.review-toolbar .tabs a { padding-top: 9px; padding-bottom: 9px; }
tr.suggested td { background: var(--suggest-bg); }
tr.suggested:hover td { background: var(--suggest-hover); }
.btn-confirm, .btn-confirm-all { background: var(--green); color: #fff; }
.btn-confirm:hover, .btn-confirm-all:hover { background: #0f6330; color: #fff; }
html[data-theme="dark"] .btn-confirm, html[data-theme="dark"] .btn-confirm-all { color: #04170b; }
html[data-theme="dark"] .btn-confirm:hover, html[data-theme="dark"] .btn-confirm-all:hover { background: #8ee5ac; color: #04170b; }
.btn-confirm { padding: 5px 12px; min-height: 0; font-size: 13px; }
.ok-banner { background: var(--suggest-bg); border-color: var(--green); color: var(--green); }
.pagination { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }
.table-footer { display: flex; gap: 14px; align-items: center; margin-top: 8px; min-height: 42px; }
.table-footer .pagination { margin-top: 0; }

/* description text reads slightly larger than table chrome */
td.desc .desc-text { font-size: 15px; }

/* Condensed density: one line per row — description truncates, account tucks
   inline, and the whole assign form (select + Assign + create-rule) sits on
   a single row. Toggled per user, persisted in localStorage ('ap-density'). */
.review-table.condensed td { padding: 5px 8px; }
.review-table.condensed td.desc { white-space: nowrap; }
.review-table.condensed td.desc .desc-text {
  font-size: 14px; display: inline-block; max-width: 210px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
.review-table.condensed td.desc .acct { display: inline; margin-left: 6px; font-size: 12px; }
.review-table.condensed .income-edit { display: inline-flex; margin-top: 0; margin-left: 8px; flex-wrap: nowrap; }
.review-table.condensed .income-edit input.small { width: 84px; }
.review-table.condensed .suggested-name { display: inline; margin-right: 8px; font-size: 13px; }
.review-table.condensed .confirm-form { display: inline; }
.review-table.condensed .btn-confirm { padding: 3px 9px; }
.review-table.condensed .assign-cell {
  flex-direction: row; align-items: center; flex-wrap: nowrap; gap: 8px; min-width: 0;
}
.review-table.condensed .assign-cell .field-row { flex-wrap: nowrap; }
.review-table.condensed .assign-cell select { min-width: 150px; }
.review-table.condensed .rule-row { white-space: nowrap; flex-wrap: nowrap; }
.review-table.condensed .rule-row input[type=text] { width: 130px; min-width: 0; flex: none; }
.review-table.condensed input[type=text], .review-table.condensed select,
.review-table.condensed button { min-height: 30px; padding-top: 4px; padding-bottom: 4px; }

/* review queue: stacked assign cell */
.assign-cell { display: flex; flex-direction: column; gap: 8px; min-width: 300px; }
.assign-cell .field-row select { flex: 1; min-width: 170px; }
.rule-row { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.rule-row input[type=text] { flex: 1; min-width: 120px; }
.income-edit { margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- upload ---------- */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.dz-icon { width: 40px; height: 40px; color: var(--teal-dark); margin: 4px auto 6px; display: block; }
.dz-title { font-size: 16px; margin: 0; }
.file-btn {
  background: #e2f7f8; color: var(--teal-dark); border: 0;
  font-weight: 700; cursor: pointer;
}
.file-btn:hover { background: #cdf0f1; color: var(--teal-dark); }
html[data-theme="dark"] .file-btn { background: #10393c; color: var(--teal); }
html[data-theme="dark"] .file-btn:hover { background: #14484c; color: var(--teal); }
input#file-input:focus-visible + .file-btn { box-shadow: var(--focus); }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 12px; padding: 8px 12px;
  background: var(--suggest-bg); color: var(--green);
  border: 1px solid var(--green); border-radius: 999px;
  font-weight: 600; font-size: 13.5px;
}
.file-chip .fb-x { font-size: 18px; color: inherit; }

.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius);
  padding: 36px 24px; text-align: center; background: var(--card);
  transition: border-color .12s ease, background .12s ease;
  margin-bottom: 20px;
}
.dropzone.drag { border-color: var(--teal); background: var(--hover-bg); }
.dropzone p { margin: 8px 0; }

/* ---------- mapping wizard ---------- */
.map-table th { vertical-align: bottom; }
.map-table .role-select { width: 100%; min-width: 130px; font-size: 13px; }
.map-table .map-header {
  margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--heading);
  text-transform: none; letter-spacing: 0;
}
.map-table td { white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- calc tables & tabs ---------- */
.calc-table td:first-child { color: var(--ink-2); }
.calc-table td { padding: 11px 12px; }
.calc-table tr[title] { cursor: help; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs a {
  padding: 8px 15px; border-radius: 8px; background: transparent;
  text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 14px;
  border: 1px solid transparent;
}
.tabs a:hover { background: var(--hover-bg); color: var(--heading); }
.tabs a.active { background: var(--card); border-color: var(--line); color: var(--heading); box-shadow: var(--shadow); }

/* ---------- confirmation modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 950;
  background: rgba(6, 18, 30, .5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-panel {
  background: var(--card); color: var(--ink);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  padding: 22px 24px; max-width: 520px; width: 100%;
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.modal-panel h2 { margin-top: 0; font-size: 17px; }

/* category drag-and-drop reorder */
.drag-handle { cursor: grab; color: var(--ink-3); font-size: 16px; user-select: none; width: 30px; }
tr.cat-row.dragging td { opacity: .4; background: var(--hover-bg); }

/* ---------- feedback widget (Keystone pattern) ---------- */
.fb-launcher {
  position: fixed; bottom: 18px; right: 18px; z-index: 890;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; min-height: 0;
  border: 0; border-radius: 999px;
  background: var(--navy); color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(10, 42, 77, .3);
  transition: transform .12s ease, background .12s ease;
}
.fb-launcher:hover { background: #123a66; color: #fff; transform: translateY(-1px); }
html[data-theme="dark"] .fb-launcher { background: var(--teal); color: #06202b; }
html[data-theme="dark"] .fb-launcher:hover { background: #3fd2d8; color: #06202b; }
.fb-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(6, 18, 30, .45);
  display: flex; align-items: flex-end; justify-content: flex-end; padding: 18px;
}
.fb-panel {
  width: 340px; max-width: 100%; max-height: calc(100vh - 36px); overflow-y: auto;
  background: var(--card); color: var(--ink);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; font-size: 14px;
}
.fb-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; color: var(--heading); }
.fb-x {
  border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer;
  color: var(--ink-3); padding: 0 2px; min-height: 0;
}
.fb-x:hover { color: var(--heading); background: none; }
.fb-types { display: flex; gap: 8px; }
.fb-type {
  flex: 1; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--input-bg); color: var(--ink-2); font-size: 13px; font-weight: 600; cursor: pointer; min-height: 0;
}
.fb-type:hover { background: var(--hover-bg); color: var(--heading); }
.fb-type.active { border-color: var(--btn-bg); background: var(--btn-bg); color: var(--nav-active-ink); }
.fb-panel textarea, .fb-panel input[type=email] { width: 100%; resize: vertical; }
.fb-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.fb-error { color: var(--red); font-size: 12.5px; }
.fb-sent { padding: 18px 4px; text-align: center; font-weight: 600; color: var(--green); }
.fb-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- mobile: single column (stack-wide rule) ---------- */
@media (max-width: 768px) {
  html, body { height: auto; }
  body { overflow: auto; overflow-x: clip; }
  .layout { flex-direction: column; height: auto; }
  .content { overflow-y: visible; height: auto; display: block; }
  .sidebar { overflow-y: visible; }
  .page-fill, .page-fill > .card.fill, .card.fill .table-wrap { display: block; min-height: auto; overflow: visible; }
  .card.fill .table-wrap { overflow-x: auto; }
  .ledger-table td { white-space: normal; }
  .sidebar {
    width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--line);
    padding: 10px 12px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px;
  }
  .brand { width: 100%; padding: 2px 4px 8px; text-align: left; }
  .brand img { width: 72px; margin: 0; }
  .sidebar a { padding: 7px 11px; font-size: 13.5px; }
  .theme-toggle { margin-top: 0; margin-left: auto; padding: 6px 10px; }
  .sidebar-foot { display: none; }
  .content { padding: 18px 14px 90px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 16px; }
  .cards { grid-template-columns: 1fr; }
  .controls { flex-direction: column; align-items: stretch; }
  .controls label, .controls select, .controls input, .controls button { width: 100%; }
  form.inline { display: flex; flex-direction: column; align-items: stretch; }
  form.inline select, form.inline input, form.inline button { width: 100%; }
  .assign-cell { min-width: 0; }
  .fb-overlay { padding: 10px; }
  .fb-panel { width: 100%; }
  .fb-launcher { bottom: 14px; right: 14px; }
}

/* ---------- app footer (legal links on every app page) ---------- */
.app-footer {
  margin-top: 36px; padding: 14px 2px 0; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  font-size: 12px; color: var(--ink-3);
}
.app-footer a { color: var(--ink-3); text-decoration: none; }
.app-footer a:hover { color: var(--link); text-decoration: underline; }
.app-footer nav { white-space: nowrap; }

/* ---------- legal pages (standalone documents, no app shell) ---------- */
/* base.html locks the window scroll (the content pane scrolls instead);
   legal pages are normal documents, so restore page scrolling here. */
body.legal-body { overflow: auto; height: auto; }
.legal-wrap { max-width: 780px; margin: 0 auto; padding: 28px 20px 60px; }
.legal-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 18px; margin-bottom: 18px; }
.legal-brand img { width: 150px; display: block; }
.legal-brand .logo-dark { display: none; }
html[data-theme="dark"] .legal-brand .logo-light { display: none; }
html[data-theme="dark"] .legal-brand .logo-dark { display: block; }
.legal-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13.5px; }
.legal-nav a { text-decoration: none; color: var(--ink-2); }
.legal-nav a:hover { color: var(--link); }
.legal-nav a.active { color: var(--heading); font-weight: 700; }
.legal-lang { margin-left: auto; font-size: 13.5px; color: var(--ink-3); }
.legal-lang a { text-decoration: none; color: var(--ink-2); padding: 2px 4px; }
.legal-lang a.active { color: var(--heading); font-weight: 700; }
.legal-doc {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 34px 38px 40px; line-height: 1.65;
}
.legal-doc h1 { font-size: 26px; margin: 0 0 14px; }
.legal-doc h2 { font-size: 17px; margin: 26px 0 8px; }
.legal-doc p, .legal-doc li { font-size: 14.5px; }
.legal-doc ul { padding-left: 22px; }
.legal-doc table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.legal-doc th, .legal-doc td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.legal-doc th { background: var(--hover-bg); color: var(--heading); }
.legal-doc code { background: var(--hover-bg); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.legal-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; font-size: 12.5px; color: var(--ink-3); }
@media (max-width: 768px) {
  .legal-doc { padding: 22px 16px 28px; }
  .legal-lang { margin-left: 0; }
  .app-footer { flex-direction: column; gap: 6px; }
  .app-footer nav { white-space: normal; }
}
