:root {
  /* The reconciliation colour scheme, carried over from the Streamlit app. */
  --sel:        #bcd9ff;   /* selected */
  --sel-border: #4a90e2;
  --con:        #c8f0cf;   /* connected across files */
  --orphan:     #fff0e0;   /* unmatched */
  --partial:    #ffec99;   /* needs review / partial */
  --new:        #e3d4f7;   /* newly uploaded */
  --subscription:#cdeee9;  /* recurring, no invoice */
  --aging:      #e4e6e9;   /* open per the aging report — grey, expected */
  --payment-only:#d9e8fb;  /* paid in Sage, not yet tied to a bank deposit — blue, informational */
  --unmatched:  #f5c6c4;   /* no payment AND not aging — red, a real gap to investigate */
  --zebra:      #f7f9fc;

  --ink: #1c2733;
  --muted: #65758a;
  --line: #e3e8ef;
  --bg: #f4f6f9;
  --accent: #2f5dd0;
  --good: #1f8a4c;
  --warn: #b07d12;
  --bad: #c0392b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- shell ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: #fff;
  border-right: 1px solid var(--line); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.brand .sub { display:block; font-weight: 400; font-size: 11px; color: var(--muted); }
.nav { list-style: none; padding: 0; margin: 18px 0 0; }
.nav li { margin: 2px 0; }
.nav a {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--ink);
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--sel); font-weight: 600; }
.sidebar .foot { margin-top: 24px; font-size: 11px; color: var(--muted); }
.sidebar form { margin-top: 16px; }

.main { flex: 1 1 auto; padding: 28px 36px; max-width: 1500px; min-width: 0; }
h1 { font-size: 30px; margin: 0 0 18px; }
h2 { font-size: 19px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.pill { display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:600; }
.pill.good { background:#e3f3ea; color:var(--good); }
.pill.warn { background:#fdf3df; color:var(--warn); }

/* ---- KPI cards ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background:#fff; border:1px solid var(--line); border-radius:12px; padding:16px 18px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.kpi .delta.good { color: var(--good); }

/* dashboard time filter */
.dash-filter { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin:0 0 18px;
  background:#fff; border:1px solid var(--line); border-radius:12px; padding:10px 14px; }
.dash-filter-cur { font-weight:700; margin-right:6px; }
.dash-preset { display:inline-block; padding:6px 12px; border-radius:999px; font-size:13px;
  border:1px solid var(--line); color:var(--ink); }
.dash-preset:hover { border-color:var(--accent); text-decoration:none; }
.dash-preset.active { background:var(--sel); border-color:var(--sel-border); font-weight:600; }
.dash-filter .dash-range { font-size:12px; color:var(--muted); display:inline-flex; align-items:center; gap:5px; }
.dash-filter .dash-range input { width:auto; padding:6px 8px; font-size:13px; }
.dash-filter button { padding:6px 14px; font-size:13px; }

/* ---- progress bar ---- */
.bar { height: 14px; border-radius: 8px; background: var(--line); overflow: hidden; display:flex; margin: 8px 0; }
.bar > span { display:block; height:100%; }
.bar .reconciled { background: var(--good); }
.bar .review { background: var(--partial); }
.bar .waiting { background: var(--aging); }
.legend { font-size: 12px; color: var(--muted); display:flex; gap:18px; flex-wrap:wrap; }
.legend .dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:5px; vertical-align:middle; }

/* ---- channel cards ---- */
.channels { display:grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap:14px; }
.chan { background:#fff; border:1px solid var(--line); border-radius:12px; padding:14px 16px; }
.chan .name { font-weight:600; }
.chan .count { font-size: 26px; font-weight:700; }
.chan .amt { color: var(--muted); }
.chan .mix { font-size:12px; margin-top:8px; display:flex; gap:10px; }
.swatch { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:4px; vertical-align:middle; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; background:#fff; border:1px solid var(--line); border-radius:10px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td { padding: 6px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.grid th { background:#fbfcfe; position: sticky; top: 0; font-weight: 600; color: var(--muted); }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tr.zebra td { background: var(--zebra); }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { filter: brightness(0.97); }

/* selection / connection / status colours win over zebra */
tr.b-orphan       td { background: var(--orphan) !important; }
tr.b-partial      td { background: var(--partial) !important; }
tr.b-new          td { background: var(--new) !important; }
tr.b-subscription td { background: var(--subscription) !important; }
tr.b-aging        td { background: var(--aging) !important; }
tr.b-payment-only td { background: var(--payment-only) !important; }
tr.b-unmatched    td { background: var(--unmatched) !important; }
tr.connected      td { background: var(--con) !important; }
tr.selected       td { background: var(--sel) !important; box-shadow: inset 3px 0 0 var(--sel-border); }

.grid-card { margin-bottom: 22px; }
.grid-card h3 { margin: 0 0 8px; font-size: 15px; display:flex; align-items:center; gap:8px; }
.grid-card h3 .count { font-weight: 400; color: var(--muted); font-size: 12px; }

/* ---- explorer detail panel ---- */
.explorer { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
.detail { position: sticky; top: 20px; background:#fff; border:1px solid var(--line); border-radius:12px; padding:16px; }
.detail h3 { margin-top:0; }
.detail .empty { color: var(--muted); }
.detail dl { margin: 0; font-size: 13px; }
.detail dt { color: var(--muted); margin-top: 8px; }
.detail dd { margin: 0; font-weight: 500; }

/* ---- Explorer scoped mini-chat ("Ask Aaron about this transaction") — bubble style ----
   Used ONLY by _ask_answer.html + explorer.js (#ask-thread). The tab/side-bubble Aaron uses the
   avatar-row .ow-msg style further down — do not delete these as "old chat" rules. */
.msg { padding: 10px 14px; border-radius: 14px; max-width: 82%; }
.msg.user { align-self: flex-end; background: var(--sel); }
.msg.assistant { align-self: flex-start; background: #fff; border:1px solid var(--line); }
.msg.pending { opacity: .85; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; }

/* ---- forms / buttons ---- */
input[type=text], input[type=password] {
  padding: 9px 12px; border:1px solid var(--line); border-radius:9px; font-size:14px; width:100%;
}
button, .btn {
  padding: 9px 16px; border: none; border-radius: 9px; background: var(--accent);
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border:1px solid var(--line); }
button:hover { filter: brightness(1.05); }

/* ---- login ---- */
.login-wrap { display:flex; align-items:center; justify-content:center; min-height:100vh; }
.login-card { background:#fff; border:1px solid var(--line); border-radius:16px; padding:34px; width:360px; box-shadow: 0 8px 30px rgba(20,40,80,.06); }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.login-card label { display:block; font-size:12px; color:var(--muted); margin: 12px 0 4px; }
.login-card button { width: 100%; margin-top: 20px; }
.error { background:#fdeceb; color: var(--bad); padding:8px 12px; border-radius:8px; font-size:13px; margin-bottom:8px; }
.note { background:#fff8e6; color:var(--warn); padding:8px 12px; border-radius:8px; font-size:12px; }
.note.success-note { background:#e3f3ea; color:var(--good); }

/* login: "or" separator between password and magic-link forms */
.or-sep { display:flex; align-items:center; gap:10px; margin:18px 0 6px; color:var(--muted); font-size:12px; }
.or-sep::before, .or-sep::after { content:""; flex:1; height:1px; background:var(--line); }
.login-card form + .or-sep + form button { margin-top:6px; }

/* account / change-password */
.account-card { background:#fff; border:1px solid var(--line); border-radius:12px; padding:20px 22px;
  max-width:420px; margin-top:16px; }
.account-card h2 { margin:0 0 12px; font-size:18px; }
.account-form label { display:block; font-size:12px; color:var(--muted); margin:12px 0 4px; }
.account-form button { margin-top:18px; }
.account-card .okline { background:#e3f3ea; color:var(--good); padding:8px 12px; border-radius:8px;
  font-size:13px; margin-bottom:8px; }

/* htmx loading indicator */
.htmx-indicator { opacity: 0; transition: opacity 150ms; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }
.spinner { display:inline-block; font-size:12px; color: var(--muted); }

/* ---- ingest ---- */
.ingest-grid { display:flex; flex-wrap:wrap; gap:16px; margin:10px 0 18px; }
.ingest-slot { display:flex; flex-direction:column; gap:6px; background:#fff;
  border:1px solid var(--line); border-radius:10px; padding:12px 14px; min-width:260px; }
.slot-label { font-size:12px; font-weight:600; color:var(--ink); }
.supporting { margin:6px 0 14px; }
.supporting summary { cursor:pointer; color:var(--accent); font-size:13px; }
.actions { display:flex; align-items:center; gap:12px; margin-top:8px; }
.ingest-summary { background:#fff; border:1px solid var(--line); border-radius:12px;
  padding:16px 18px; margin-top:18px; }
.two-col { display:flex; gap:40px; flex-wrap:wrap; }
.success { color: var(--good); }
.warn { color: var(--warn); }

/* ---- audit cards ---- */
.cards { display:flex; flex-wrap:wrap; gap:14px; margin:14px 0; }
.card { background:#fff; border:1px solid var(--line); border-radius:12px; padding:14px 16px;
  min-width:150px; flex:1; }
.card .big { font-size:22px; font-weight:700; }
.card .sub { color:var(--muted); font-size:12px; }
.card.b-reconciled { background: var(--con); }
.card.b-partial { background: var(--partial); }
.card.b-orphan { background: var(--orphan); }
.card.b-subscription { background: var(--subscription); }
.finding { background:#fff; border-left:4px solid var(--line); padding:8px 12px; margin:6px 0;
  border-radius:6px; font-size:13px; }
.finding.error { border-left-color: var(--bad); background:#fdeceb; }
.finding.review { border-left-color: var(--warn); background:#fff8e6; }
.finding.info { border-left-color: var(--accent); }

/* ---- review table ---- */
table.review { width:100%; border-collapse:collapse; margin-top:10px; font-size:13px; }
table.review th, table.review td { text-align:left; padding:7px 10px; border-bottom:1px solid var(--line); }
table.review td.num { text-align:right; font-variant-numeric: tabular-nums; }
table.review td.actions { display:flex; gap:8px; }
table.review button { padding:4px 10px; font-size:12px; }

/* ====================================================================
   Explorer 2.0 — search / sort / resize / float-to-top, on the web app
   ==================================================================== */
.explorer-toolbar { display:flex; align-items:center; gap:16px; flex-wrap:wrap;
  margin:6px 0 18px; }
.explorer-toolbar .detail-toggle { font-size:13px; display:flex; align-items:center; gap:6px; cursor:pointer; }
.explorer-toolbar #clear-sel { padding:6px 12px; font-size:13px; }

.export-multi { position:relative; }
.export-multi > summary { display:inline-block; list-style:none; padding:6px 12px; font-size:13px;
  border-radius:9px; }
.export-multi > summary::-webkit-details-marker { display:none; }
.export-body { position:absolute; z-index:20; top:110%; left:0; background:#fff; border:1px solid var(--line);
  border-radius:10px; padding:12px 14px; box-shadow:0 8px 30px rgba(20,40,80,.12); min-width:230px; }
.export-cols { display:flex; flex-direction:column; gap:6px; font-size:13px; margin-bottom:10px; }
.export-cols label { display:flex; align-items:center; gap:7px; cursor:pointer; }
#export-multi-btn { padding:7px 12px; font-size:13px; width:100%; }

.section-h { font-size:14px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted);
  margin:4px 0 12px; }
.grid-2col { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:20px; align-items:start; }
@media (max-width:1100px) { .grid-2col { grid-template-columns:1fr; } }
/* a card must stay inside its column — never bleed a wide/selected table into the neighbor */
.grid-card { min-width:0; }
.grid-card .float-strip { max-width:100%; overflow-x:auto; }

.supporting-files { margin-top:18px; }
.supporting-files > summary { cursor:pointer; color:var(--accent); font-size:14px; font-weight:600;
  margin-bottom:12px; }

/* per-file head: title left, tools right */
.grid-card .grid-head { display:flex; align-items:center; justify-content:space-between;
  gap:10px; flex-wrap:wrap; margin-bottom:8px; }
.grid-card .grid-title { font-size:15px; font-weight:600; display:flex; align-items:center; gap:8px; }
.grid-card .grid-title .count { font-weight:400; color:var(--muted); font-size:12px; }
.grid-card .grid-title .hilite { font-weight:600; color:var(--good); font-size:12px; }
.grid-tools { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.grid-tools .grid-search { width:150px; padding:5px 9px; font-size:12px; }
.grid-tools .newonly { font-size:12px; color:var(--muted); display:flex; align-items:center; gap:5px; cursor:pointer; }
.grid-tools .grid-year { padding:5px 8px; font-size:12px; border:1px solid var(--line); border-radius:8px; background:#fff; }
.grid-tools .btn-export { padding:5px 10px; font-size:12px; }

/* the float-to-top "matches" strip */
.float-strip { border:1px solid var(--good); border-radius:10px; padding:8px; margin-bottom:8px;
  background:#f1faf3; }
.float-strip .float-cap { font-size:12px; font-weight:600; color:var(--good); margin-bottom:6px; }
table.grid.float { width:100%; }
table.grid.float .th-resize { display:none; }

/* sortable / resizable headers */
table.grid thead th { position:sticky; top:0; }
.th-label { user-select:none; }
.th-sort { font-size:10px; color:var(--accent); }
table.grid thead th[role=button]:hover .th-label,
.match-grid table.grid thead th:hover .th-label { color:var(--accent); text-decoration:underline; }
.th-resize { position:absolute; top:0; right:0; width:7px; height:100%; cursor:col-resize; }
.th-resize:hover { background:var(--sel-border); opacity:.4; }
body.col-resizing { cursor:col-resize; user-select:none; }

/* Each Explorer grid scrolls inside a TALL box (~65% of the viewport): contained (no giant page),
   shows many rows at once, and the page scrolls between grids. Wide tables scroll sideways too. */
.grid-scroll { max-height:65vh; overflow:auto; }

/* the detail / connections panel (full width, below the grids — the 2.0 arrangement) */
.detail-panel { background:#fff; border:1px solid var(--line); border-radius:12px; padding:18px 20px;
  margin-top:22px; }
.detail-panel .empty { margin:0; }
.detail-head h3 { margin:0 0 2px; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.detail-panel .badge { font-size:12px; font-weight:600; padding:2px 10px; border-radius:999px;
  background:var(--bg); color:var(--ink); }
.detail-panel .okline { background:#e3f3ea; color:var(--good); padding:8px 12px; border-radius:8px;
  font-size:13px; margin:10px 0; }
.detail-panel .story { margin:12px 0; }
.detail-panel .conn-h { margin:16px 0 8px; font-size:14px; }
.conn-block { margin:6px 0; }
.conn-block > summary { cursor:pointer; font-size:13px; font-weight:600; padding:4px 0; }
.conn-block .tablewrap { margin:6px 0 10px; max-height:280px; overflow:auto; }
.field-dl { display:grid; grid-template-columns:max-content 1fr; gap:2px 14px; font-size:13px; margin:8px 0; }
.field-dl dt { color:var(--muted); }
.field-dl dd { margin:0; }
.detail-hr { border:none; border-top:1px solid var(--line); margin:16px 0; }

/* resizable columns: pinned widths + fixed layout so a column can shrink as well as grow */
table.grid.sized { table-layout:fixed; }
table.grid.sized th, table.grid.sized td { overflow:hidden; text-overflow:ellipsis; }

/* keyboard focus for the mouse-free path */
#explorer-grids tbody tr:focus-visible { outline:2px solid var(--sel-border); outline-offset:-2px; }
.th-label:focus-visible { outline:2px solid var(--sel-border); border-radius:3px; }

/* per-chain ✓/✗ verification chips */
.chips-row { display:flex; flex-wrap:wrap; gap:6px; margin:10px 0; }
.chip { font-size:12px; font-weight:600; padding:2px 9px; border-radius:999px; }
.chip.ok  { background:#e3f3ea; color:var(--good); }
.chip.bad { background:#fdeceb; color:var(--bad); }

/* "Open the payment record" deep-links */
.pay-links { margin:12px 0; }
.pay-links .who-label { margin-bottom:6px; }
.pay-link { display:inline-block; margin:0 8px 8px 0; padding:6px 12px; font-size:13px; }

/* Pinned to the top of the detail panel: the selection's Sage record URLs, highlighted so they're
   the first thing seen (no scrolling). */
.pay-links.pinned { margin:12px 0; padding:10px 14px; background:#eef5ff;
  border:1px solid var(--sel); border-radius:10px; }
.pay-links.pinned + .pay-links.pinned { margin-top:-4px; }
.pay-links.pinned .who-label { font-weight:600; color:var(--accent); }

/* Review table: the small ↗ "jump to this invoice in the AR Report" link, and the per-row
   "view" expander holding the deposit's payment / invoice record URLs. */
.ar-jump { text-decoration:none; margin-left:1px; color:var(--accent); font-size:11px; vertical-align:super; }
.row-links > summary { cursor:pointer; color:var(--accent); font-size:13px; }
.row-links[open] > summary { margin-bottom:6px; }
.row-links .pay-links { margin:6px 0; }

.suggest-form { margin:10px 0 4px; }
.suggest-form button { padding:6px 12px; font-size:13px; }

/* scoped multi-turn chat thread */
.scoped-chat .who-label { font-size:12px; margin-bottom:8px; }
.ask-thread { display:flex; flex-direction:column; gap:10px; max-height:340px; overflow-y:auto;
  margin-bottom:10px; }
.ask-thread:empty { margin:0; }

/* Dashboard: clickable KPI / channel tiles that open a drill-down modal. */
.kpi.clickable, .chan.clickable { cursor:pointer; transition:border-color .12s, box-shadow .12s; }
.kpi.clickable:hover, .chan.clickable:hover,
.kpi.clickable:focus-visible, .chan.clickable:focus-visible {
  border-color:var(--accent); box-shadow:0 2px 10px rgba(47,93,208,.12); outline:none; }

/* The drill-down modal (built without any external library). */
.modal-backdrop { position:fixed; inset:0; background:rgba(20,30,45,.45); z-index:1000;
  display:flex; align-items:flex-start; justify-content:center; padding:6vh 16px; }
.modal-backdrop[hidden] { display:none; }
.modal { background:#fff; border-radius:14px; width:100%; max-width:920px; max-height:84vh;
  overflow:auto; padding:18px 22px; box-shadow:0 20px 60px rgba(0,0,0,.3); }
.modal-head { display:flex; align-items:center; justify-content:space-between; gap:12px;
  margin-bottom:10px; }
.modal-head h3 { margin:0; }
.modal-head .count { color:var(--muted); font-weight:400; font-size:13px; }
.modal-close { border:none; background:transparent; font-size:18px; line-height:1; cursor:pointer;
  color:var(--muted); padding:4px 8px; border-radius:8px; }
.modal-close:hover { background:var(--bg); color:var(--ink); }
body.modal-on { overflow:hidden; }

/* Dashboard charts — self-contained inline SVG / CSS (no charting library). */
.charts { display:grid; grid-template-columns:repeat(auto-fit, minmax(290px,1fr)); gap:16px;
  margin:8px 0 4px; align-items:start; }
.chart-card { background:#fff; border:1px solid var(--line); border-radius:12px; padding:16px 18px; }
.chart-card h3 { margin:0 0 12px; font-size:14px; }
.donut-wrap { display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.donut { width:128px; height:128px; flex:none; }
.donut-num { font-size:7px; font-weight:700; fill:var(--ink); }
.donut-sub { font-size:3px; fill:var(--muted); }
.donut-legend { display:flex; flex-direction:column; gap:6px; font-size:12px; min-width:150px; }
.donut-legend .dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-right:6px; }
.bar-chart { display:flex; flex-direction:column; gap:10px; }
.bar-row { display:grid; grid-template-columns:110px 1fr auto; align-items:center; gap:10px; font-size:12px; }
.bar-label { color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.bar-track { background:var(--bg); border-radius:6px; height:14px; overflow:hidden; }
.bar-fill { height:100%; display:flex; border-radius:6px; overflow:hidden; min-width:2px; background:var(--aging); }
.bar-fill .seg { height:100%; display:inline-block; }
.bar-fill .seg.rec { background:var(--good); }
.bar-fill .seg.rev { background:var(--partial); }
.bar-fill .seg.wait { background:var(--aging); }
.bar-val { font-variant-numeric:tabular-nums; }
.col-chart { display:flex; align-items:flex-end; gap:6px; height:150px; padding-top:8px; overflow-x:auto; }
.col { flex:1 0 26px; display:flex; flex-direction:column; align-items:center; justify-content:flex-end;
  height:100%; gap:4px; }
.col-bar { width:72%; background:var(--accent); border-radius:4px 4px 0 0; min-height:2px; }
.col-x { font-size:10px; color:var(--muted); }

/* Folded subscriptions block on the dashboard. */
.subs-fold { margin-top:18px; }
.subs-fold > summary { cursor:pointer; font-size:18px; font-weight:700; list-style:revert; }
.subs-fold > summary .muted { font-size:13px; font-weight:400; }
.subs-fold[open] > summary { margin-bottom:10px; }

/* ════════════════════ Aaron — Open-WebUI-style chat (tab) ════════════════════ */
.page-aaron .main { height:100vh; padding:0; max-width:none; overflow:hidden; }
.aaron-shell { display:flex; height:100vh; min-height:0; }

/* conversation-history sidebar */
.aaron-convs { width:248px; flex:0 0 248px; border-right:1px solid var(--line); background:#fbfcfe;
  display:flex; flex-direction:column; padding:14px 12px; overflow-y:auto; }
.aaron-newchat { width:100%; text-align:left; background:#fff; color:var(--ink);
  border:1px solid var(--line); border-radius:10px; padding:10px 12px; font-weight:600; }
.aaron-newchat:hover { border-color:var(--accent); filter:none; }
.aaron-conv-items { margin-top:12px; display:flex; flex-direction:column; gap:2px; }
.aaron-conv { display:flex; align-items:center; border-radius:9px; }
.aaron-conv:hover { background:var(--bg); }
.aaron-conv.active { background:var(--sel); }
.aaron-conv-pick { flex:1; min-width:0; margin:0; }
.aaron-conv-title { width:100%; text-align:left; background:none; color:var(--ink); font-weight:500;
  border:none; border-radius:9px; padding:9px 10px; font-size:13px; white-space:nowrap;
  overflow:hidden; text-overflow:ellipsis; }
.aaron-conv-title:hover { filter:none; }
.aaron-conv.active .aaron-conv-title { font-weight:600; }
.aaron-conv-del { margin:0; }
.aaron-conv-x { background:none; color:var(--muted); border:none; padding:6px 9px; font-size:12px; opacity:0; }
.aaron-conv:hover .aaron-conv-x { opacity:1; }
.aaron-conv-x:hover { color:var(--bad); filter:none; }
.aaron-conv-empty { font-size:12px; padding:8px 10px; }

/* thread column */
.aaron-main { flex:1; min-width:0; display:flex; flex-direction:column; }
.aaron-chat { flex:1; display:flex; flex-direction:column; min-height:0; }
.aaron-msgs { flex:1; overflow-y:auto; padding:24px 16px; display:flex; flex-direction:column; }
.aaron-chat .aaron-msgs > * { width:100%; max-width:760px; margin-left:auto; margin-right:auto; }

/* a message row: avatar + body, NO bubble (Open WebUI style) */
.ow-msg { display:flex; gap:14px; padding:14px 4px; }
.ow-avatar { flex:0 0 30px; width:30px; height:30px; border-radius:50%; display:flex;
  align-items:center; justify-content:center; font-size:13px; font-weight:700; color:#fff;
  background:var(--accent); }
.ow-user .ow-avatar { background:#5b6b80; }
.ow-body { flex:1; min-width:0; }
.ow-name { font-size:12px; font-weight:700; color:var(--muted); margin-bottom:3px; }
.ow-text { white-space:pre-wrap; }
.ow-msg.pending { opacity:.7; }

/* composer — rounded pill pinned at the bottom, centered */
.aaron-composer { display:flex; align-items:flex-end; gap:8px; width:100%; max-width:760px;
  margin:0 auto; padding:10px 16px 18px; }
.aaron-composer textarea { flex:1; resize:none; max-height:160px; padding:12px 14px;
  border:1px solid var(--line); border-radius:16px; font-size:15px; font-family:inherit;
  line-height:1.4; box-shadow:0 2px 10px rgba(20,40,80,.05); }
.aaron-composer textarea:focus { outline:none; border-color:var(--sel-border); }
.composer-send { flex:0 0 auto; width:40px; height:40px; border-radius:50%; padding:0; font-size:18px; line-height:1; }
.aaron-note { max-width:760px; margin:0 auto 4px; }

/* empty-state hero */
.aaron-empty { margin:auto; text-align:center; padding:24px; }
.aaron-empty-logo { width:54px; height:54px; border-radius:50%; background:var(--accent); color:#fff;
  font-size:24px; font-weight:700; display:flex; align-items:center; justify-content:center; margin:0 auto 14px; }
.aaron-empty-title { font-size:20px; font-weight:600; margin:0 0 4px; }
.aaron-empty-sub { color:var(--muted); margin:0 0 18px; }
.aaron-chips { display:flex; gap:8px; flex-wrap:wrap; justify-content:center; }
.aaron-chips form { margin:0; }
.aaron-chip { background:#fff; color:var(--ink); border:1px solid var(--line); border-radius:999px;
  padding:8px 14px; font-size:13px; font-weight:500; }
.aaron-chip:hover { border-color:var(--accent); filter:none; }

/* the Aaron tab IS the conversation sidebar + thread — hide the app's main nav rail so it isn't a
   second sidebar; the conv sidebar header carries a brand link + mini nav instead. */
.page-aaron .sidebar { display:none; }

/* conv-sidebar header: brand + compact nav back into the app */
.aaron-convs-head { margin-bottom:12px; }
.aaron-convs-brand { display:block; font-weight:700; font-size:15px; color:var(--ink); }
.aaron-convs-brand:hover { text-decoration:none; color:var(--accent); }
.aaron-convs-nav { display:flex; flex-wrap:wrap; gap:6px 10px; margin-top:8px; font-size:12px; }
.aaron-convs-nav a { color:var(--muted); }
.aaron-conv.active { box-shadow:inset 3px 0 0 var(--sel-border); }   /* non-color active cue */

/* the typing row must COLLAPSE when idle (opacity alone leaves a ~50px gap + offsets centering);
   .show keeps it visible while a question is pending (Aaron still thinking after you switched back) */
.aaron-typing { display:none; }
.aaron-typing.show, .htmx-request.aaron-typing, .htmx-request .aaron-typing { display:flex; }
.aaron-poll { display:none; }

/* keep the empty-state hero a compact centered card, not the full 760px column width */
.aaron-chat .aaron-msgs > .aaron-empty { width:auto; max-width:520px; }

/* narrow screens: shrink the history rail and let the thread use the full width */
@media (max-width:900px) {
  .aaron-convs { width:200px; flex-basis:200px; }
  .aaron-chat .aaron-msgs > *, .aaron-composer, .aaron-note { max-width:100%; }
}

/* animated "Aaron is typing" indicator */
.typing-dots { display:inline-flex; gap:5px; padding:2px 0; }
.typing-dots span { width:7px; height:7px; border-radius:50%; background:var(--muted);
  display:inline-block; animation: aaron-typing 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay:.18s; }
.typing-dots span:nth-child(3) { animation-delay:.36s; }
@keyframes aaron-typing { 0%,70%,100% { opacity:.25; transform:translateY(0); }
  35% { opacity:1; transform:translateY(-4px); } }

/* rendered markdown inside an assistant bubble */
.md-body { white-space: normal; }
.md-body > :first-child { margin-top:0; }
.md-body > :last-child { margin-bottom:0; }
.md-body p { margin:8px 0; }
.md-body ul, .md-body ol { margin:8px 0; padding-left:22px; }
.md-body li { margin:2px 0; }
.md-body h3, .md-body h4, .md-body h5 { margin:12px 0 6px; }
.md-body code { background:var(--bg); padding:1px 5px; border-radius:5px; font-size:.92em; }
.md-body pre.md-code { background:#0f1b2d; color:#e7eef7; padding:12px 14px; border-radius:10px; overflow-x:auto; }
.md-body pre.md-code code { background:none; padding:0; color:inherit; }
.md-body a { color:var(--accent); }
.md-tablewrap { overflow-x:auto; }
.md-table { border-collapse:collapse; margin:8px 0; font-size:13px; }
.md-table th, .md-table td { border:1px solid var(--line); padding:5px 10px; text-align:left; }
.md-table th { background:var(--bg); }

/* a chart Aaron drew inside an answer — interactive inline SVG (charts.js) */
.aaron-chart { margin:12px 0; padding:12px 14px; background:#fff; border:1px solid var(--line); border-radius:12px; }
.aaron-chart-title { font-weight:600; font-size:13px; margin-bottom:10px; }
.aaron-chart-area-wrap { width:100%; }
.aaron-chart-svg { display:block; max-width:100%; overflow:visible; }
.aaron-chart-lab { font-size:11px; fill:var(--muted); }
.aaron-chart-val { font-size:11px; fill:var(--ink); font-variant-numeric:tabular-nums; }
.aaron-chart-track { fill:var(--bg); }
.aaron-chart-axis { stroke:var(--line); stroke-width:1; }
.aaron-chart-area { fill:rgba(47,93,208,.10); }
.aaron-chart-svg rect[fill]:hover, .aaron-chart-svg path[fill]:not(.aaron-chart-area):hover,
.aaron-chart-svg circle:hover { opacity:.82; }
.aaron-pie-wrap { display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.aaron-pie-legend { display:flex; flex-direction:column; gap:5px; font-size:12px; }
.aaron-pie-item { white-space:nowrap; }
.aaron-pie-dot { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:6px; vertical-align:middle; }
.aaron-chart-fallback { font-size:12px; color:var(--muted); }
.aaron-chart-tip { position:fixed; z-index:3000; background:#0f1b2d; color:#fff; font-size:12px;
  padding:6px 10px; border-radius:8px; pointer-events:none; box-shadow:0 6px 20px rgba(0,0,0,.3); max-width:240px; }
.aaron-chart-tip[hidden] { display:none; }

/* Aaron action proposals (propose -> click Confirm) */
.aaron-action { margin:12px 0; padding:12px 14px; border:1px solid var(--sel-border);
  background:#eef5ff; border-radius:12px; }
.aaron-action-summary { font-size:13px; font-weight:600; margin-bottom:10px; }
.aaron-action-form { display:flex; gap:8px; }
.aaron-action-form button { padding:7px 16px; font-size:13px; }
.aaron-action-go.danger { background:var(--bad); }
.aaron-action.done { border-color:var(--good); background:#e3f3ea; font-size:13px; font-weight:600;
  display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

/* the global "Ask Aaron" bubble + popup (every page except the Aaron tab) */
.aaron-bubble { position:fixed; right:22px; bottom:22px; z-index:1200; }
.aaron-bubble-btn { width:56px; height:56px; border-radius:50%; padding:0; font-size:24px;
  box-shadow:0 8px 24px rgba(20,40,80,.28); display:flex; align-items:center; justify-content:center; }
.aaron-bubble.open .aaron-bubble-btn { transform:scale(.94); }
.aaron-pop { position:absolute; right:0; bottom:70px; width:380px; max-width:calc(100vw - 32px);
  height:560px; max-height:calc(100vh - 120px); background:#fff; border:1px solid var(--line);
  border-radius:16px; box-shadow:0 18px 50px rgba(20,40,80,.28); display:flex; flex-direction:column; overflow:hidden; }
.aaron-pop[hidden] { display:none; }
.aaron-pop-head { display:flex; align-items:center; gap:8px; padding:12px 14px; border-bottom:1px solid var(--line); }
.aaron-pop-title { font-weight:700; flex:1; }
.aaron-pop-expand, .aaron-pop-close { color:var(--muted); font-size:15px; text-decoration:none;
  background:none; border:none; cursor:pointer; padding:4px 8px; border-radius:8px; }
.aaron-pop-expand:hover, .aaron-pop-close:hover { background:var(--bg); color:var(--ink); text-decoration:none; }
.aaron-pop-body { flex:1; min-height:0; display:flex; }
.aaron-pop-loading { margin:auto; padding:20px; }
.aaron-pop .aaron-chat { flex:1; min-width:0; min-height:0; }
.aaron-pop .aaron-msgs { padding:14px 12px; }
.aaron-pop .aaron-chat .aaron-msgs > * { max-width:100%; }
.aaron-pop .aaron-composer { padding:8px 10px 12px; }
.aaron-pop .aaron-composer textarea { font-size:14px; padding:9px 12px; }
.aaron-pop .ow-msg { padding:10px 2px; gap:10px; }
.aaron-pop .aaron-empty { padding:14px; }
@media (max-width:480px) { .aaron-pop { width:calc(100vw - 24px); height:calc(100vh - 110px); } }

/* Bubble text must WRAP, not get clipped by the popup's overflow:hidden. Long unbroken tokens
   break; wide tables / code / charts stay inside the popup and scroll internally. */
.ow-text, .md-body { overflow-wrap:anywhere; }
.aaron-pop .ow-body { min-width:0; overflow:hidden; }
.aaron-pop .md-body pre.md-code,
.aaron-pop .md-tablewrap { max-width:100%; overflow-x:auto; }
.aaron-pop .md-table { max-width:100%; }
.aaron-pop .aaron-chart { max-width:100%; overflow-x:auto; }
.aaron-pop .aaron-chart-svg { max-width:100%; }

/* Review — manual-match baskets (bank orphans, then open invoices); stacked full-width so the
   invoice detail columns (date / status / aging / paid) have room. */
.match-baskets { display:flex; flex-direction:column; gap:16px; align-items:stretch; }
.basket { border:1px solid var(--line); border-radius:12px; background:#fff; overflow:hidden; }
/* colour-coded days-aging pill: green <=30, yellow 31-60, red >60 */
.age-pill { display:inline-block; min-width:34px; padding:1px 7px; border-radius:999px; font-size:12px;
  font-weight:600; text-align:center; }
.age-pill.age-green  { background:#e3f3ea; color:var(--good); }
.age-pill.age-yellow { background:#fdf3df; color:var(--warn); }
.age-pill.age-red    { background:#fdeceb; color:var(--bad); }
.basket-head { padding:10px 14px; font-weight:600; background:var(--bg); border-bottom:1px solid var(--line); }
.basket-list { max-height:340px; overflow-y:auto; border:none; border-radius:0; }
.pick-table th, .pick-table td { padding:5px 10px; }
.pick-table .pick-radio { width:30px; text-align:center; }
.pick-row { cursor:pointer; }
.pick-row.picked td { background:var(--sel) !important; box-shadow:inset 3px 0 0 var(--sel-border); }
.match-bar { margin-top:12px; display:flex; align-items:center; gap:10px; }
.match-bar #match-hint { font-size:12px; }
button:disabled { opacity:.45; cursor:not-allowed; filter:none; }

/* Review manual-match: Explorer-style grids (bank orphans / open invoices), scoped + capped height. */
.match-grid { margin-bottom:16px; }
.match-grid .grid-scroll { max-height:340px; overflow:auto; }
.match-grid .th-label { cursor:pointer; }
.match-grid .pick-radio { width:30px; text-align:center; }

/* ── Excel-style per-column sort + filter (gridfilter.js) ─────────────────────────── */
.gf-btn { background:none; border:none; color:var(--muted); cursor:pointer; font-size:10px;
  padding:0 3px; margin-left:3px; line-height:1; vertical-align:middle; }
.gf-btn:hover { color:var(--accent); }
.gf-btn.gf-active { color:var(--accent); }
.gf-cols-btn { padding:6px 10px; font-size:12px; }

.gf-menu { position:fixed; z-index:2000; width:250px; max-width:calc(100vw - 16px); background:#fff;
  border:1px solid var(--line); border-radius:10px; box-shadow:0 14px 44px rgba(20,40,80,.28);
  padding:10px; font-size:13px; }
.gf-menu .gf-title { font-weight:600; margin-bottom:6px; }
.gf-sep { height:1px; background:var(--line); margin:8px 0; }
.gf-sort { display:flex; gap:6px; }
.gf-menu button { padding:6px 8px; font-size:12px; }
.gf-sort .gf-mini { flex:1; background:#fff; color:var(--ink); border:1px solid var(--line); }
.gf-sort .gf-mini:hover { border-color:var(--accent); color:var(--accent); }
.gf-cond { display:flex; flex-direction:column; gap:6px; }
.gf-menu .gf-op, .gf-menu .gf-in, .gf-menu .gf-vsearch { width:100%; padding:6px 8px; font-size:13px;
  border:1px solid var(--line); border-radius:8px; }
.gf-vsearch { margin-bottom:4px; }
.gf-list { max-height:180px; overflow-y:auto; overscroll-behavior:contain; border:1px solid var(--line); border-radius:8px; margin-top:2px; }
.gf-item { display:flex; align-items:center; gap:7px; padding:4px 8px; cursor:pointer;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.gf-item:hover { background:var(--zebra); }
.gf-item input { flex:none; }
.gf-all { font-weight:600; border-bottom:1px solid var(--line); }
.gf-foot { display:flex; gap:6px; margin-top:10px; }
.gf-foot button { flex:1; }
.gf-cols .gf-item { border:none; }

/* ── Match-freshness banner + re-run button (Dashboard + Ingest) ─────────────────── */
.match-status { display:flex; align-items:center; gap:12px; flex-wrap:wrap;
  padding:10px 14px; margin:14px 0; border:1px solid var(--line); border-radius:10px;
  background:#f7f9fc; font-size:13px; }
.match-status.stale { background:#fff8e6; border-color:#f0d48a; }
.match-status .ms-msg { flex:1; min-width:180px; color:var(--muted); }
.match-status.stale .ms-msg { color:#8a6d00; font-weight:500; }
.match-status .ms-btn { padding:7px 12px; font-size:13px; white-space:nowrap; }
.match-status .ms-spin { color:var(--muted); font-size:12px; }
.rematch-summary { margin-top:12px; }
.rematch-list { margin:6px 0 12px; padding-left:20px; }
.rematch-list li { margin:3px 0; }
.rematch-counts { list-style:none; padding:0; margin:8px 0; display:flex; gap:18px; flex-wrap:wrap; }
.rematch-counts li { color:var(--muted); }

/* ---- single upload portal (Ingest) ---- */
.dropzone { display:block; border:2px dashed #b9c3cf; border-radius:12px; background:#fff;
  padding:34px 20px; text-align:center; cursor:pointer; transition:border-color .15s, background .15s; }
.dropzone:hover, .dropzone.dz-hover { border-color:var(--accent, #2563eb); background:#f4f8ff; }
.dropzone input[type="file"] { display:none; }
.dz-icon { font-size:30px; margin-bottom:6px; }
.dz-text { font-size:15px; }
.dz-sub { font-size:12px; margin-top:6px; }
.dz-picked { font-size:12px; margin-top:8px; font-weight:600; }
/* Accumulated file chips below the dropzone (multi-file upload). */
.file-list { list-style:none; padding:0; margin:12px 0; display:flex; flex-wrap:wrap; gap:8px; }
.file-chip { display:inline-flex; align-items:center; gap:8px; background:#eef3fb; border:1px solid var(--line);
  border-radius:20px; padding:5px 6px 5px 12px; font-size:12px; }
.file-chip .file-name { color:var(--ink); }
.file-chip .file-x { border:none; background:#d7e0ee; color:#334; cursor:pointer; font-size:14px; line-height:1;
  width:20px; height:20px; border-radius:50%; padding:0; display:flex; align-items:center; justify-content:center; }
.file-chip .file-x:hover { background:#f0c0c0; color:#900; }
.ingest-files { border-collapse:collapse; margin:8px 0 14px; font-size:13px; }
.ingest-files th, .ingest-files td { text-align:left; padding:5px 12px 5px 0; border-bottom:1px solid #eef1f4; }
.ingest-files tr.ingest-unknown td, .ingest-files tr.ingest-error td { background:#fdf6ec; }
.ingest-files tr.ingest-replaced td { color:var(--muted); text-decoration:line-through; }

/* ---- aging (customer aging report) ---- */
.aging-table td.aging-overdue { color:var(--bad, #c0392b); font-weight:600; }
.aging-table tr.aging-totals td { border-top:2px solid #d5dbe2; }
.kpis.aging-strip .kpi-warn .value { color:var(--bad, #c0392b); }
.proof-strip { margin-top:18px; font-size:13px; }
.findings-box { margin-top:20px; }
.findings-box summary { cursor:pointer; font-weight:600; }

/* ---- per-file freshness chips (Explorer grid headers + Review strip) ---- */
.fresh-strip { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:6px 0 14px; }
.fresh-strip .fresh-chip { font-size:12px; background:#f1f4f8; border-radius:999px; padding:3px 10px; color:var(--muted); }
.fresh-chip.amber { background:#fdf3e0; color:#9a6b00; font-weight:600; }
.fresh-chip.red { background:#fdeceb; color:var(--bad, #c0392b); font-weight:600; }
.crumb { margin: 0 0 4px; font-size: 13px; }
.bucket-cust { margin: 10px 0; }
.bucket-cust summary { cursor: pointer; }
.aging-actions { white-space: nowrap; }
.aging-actions .btn { font-size: 12px; padding: 3px 8px; }

/* ---- top-right profile menu ---- */
.profile-menu { position: fixed; top: 14px; right: 20px; z-index: 3000; }
.profile-menu > summary { list-style: none; cursor: pointer; background: #fff;
  border: 1px solid var(--line, #dde3ea); border-radius: 999px; padding: 6px 14px;
  font-size: 13px; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.profile-menu > summary::-webkit-details-marker { display: none; }
.profile-menu[open] > summary { background: #f4f6f9; }
.menu-panel { position: absolute; right: 0; margin-top: 6px; background: #fff;
  border: 1px solid var(--line, #dde3ea); border-radius: 10px; min-width: 210px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 6px; }
.menu-head { padding: 8px 10px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid #eef1f4; margin-bottom: 4px; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px;
  border-radius: 7px; font-size: 13px; color: inherit; text-decoration: none;
  background: none; border: none; cursor: pointer; }
.menu-item:hover { background: #f2f5f9; }
.menu-sep { border-top: 1px solid #eef1f4; margin: 4px 0; }

/* ---- Dashboard upload box + admin create form ---- */
details.upload-box { background: #fff; border: 1px solid var(--line, #dde3ea);
  border-radius: 12px; padding: 10px 16px; margin: 10px 0 18px; }
details.upload-box > summary { cursor: pointer; font-size: 14px; }
details.upload-box[open] { padding-bottom: 16px; }
.admin-create { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: #fff; border: 1px solid var(--line, #dde3ea); border-radius: 12px;
  padding: 14px 16px; max-width: 900px; }
.admin-create label { display: flex; flex-direction: column; gap: 4px; font-size: 12px;
  color: var(--muted); }
.admin-create input, .admin-create select { padding: 6px 8px; }
.admin-create .admin-invite { flex-direction: row; align-items: center; gap: 6px;
  flex-basis: 100%; }

/* ---- per-column filter row (Excel-style) ---- */
.gf-filter-row td { padding: 2px 4px 6px; background: #fbfcfe; }
.gf-colsearch { width: 100%; min-width: 52px; box-sizing: border-box; font-size: 11px;
  padding: 3px 6px; border: 1px solid #dfe5ec; border-radius: 6px; background: #fff; }
.gf-colsearch:focus { outline: none; border-color: var(--accent, #2563eb); }

/* colour legend chips on the Explorer header */
.legend-row .lg { display:inline-block; padding:0 7px; border-radius:4px; margin-right:2px;
  border:1px solid rgba(0,0,0,.08); font-size:12px; }

/* ---- Excel-style cell selection + Count/Sum/Average bar (cellstats.js) ---- */
table.grid tbody td.cell-sel { background:#cfe3ff !important; box-shadow: inset 0 0 0 2px #2f5dd0; }
#cell-stats { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 10px; background: #1c2733; color: #fff;
  padding: 8px 16px; border-radius: 999px; font-size: 13px; z-index: 4000;
  box-shadow: 0 4px 18px rgba(0,0,0,.28); font-variant-numeric: tabular-nums; }
#cell-stats .cs-k { color: #9fb3cc; margin-right: 4px; }
#cell-stats .cs-sep { color: #52627a; }
#cell-stats #cs-clear { background: transparent; border: none; color: #9fb3cc; cursor: pointer;
  font-size: 14px; padding: 0 2px; margin-left: 4px; }
#cell-stats #cs-clear:hover { color: #fff; }

/* deposit-resolution control in the detail panel */
.resolve-box { margin: 8px 0; font-size: 13px; }
.resolve-box summary { cursor: pointer; color: var(--accent); }
.resolve-box form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0 4px; font-size: 12px; text-decoration: underline; }
