/* ============================================================================
   reconciliation-engine.css — the reusable bank reconciliation matcher.

   THEMING CONTRACT (ENGINES.md): every colour consumes a host design-system
   token with a neutral fallback — the SAME token names and the SAME neutral
   fallback values as invoice-engine.css, so the owner's engines read as one
   family when unthemed and both pick up a host's palette identically when
   themed. Semantic status colours (good/warn/danger) are the engine's own —
   they describe bank-transaction and match state, not brand, and are never
   host-overridable.
   ========================================================================= */

.rce { --rce-brand: var(--brand, #2F5D8A);
       --rce-on-brand: var(--on-brand, #fff);
       --rce-surface: var(--surface, #fff);
       --rce-surface-2: var(--surface-2, #F0F2F0);
       --rce-ground: var(--ground, #F4F5F3);
       --rce-ink: var(--ink, #1B1F1B);
       --rce-muted: var(--ink-muted, #62695F);
       --rce-line: var(--line, #D9DCD4);
       --rce-line-strong: var(--line-strong, #C2C6BC);
       --rce-danger: var(--danger, #B3261E);
       --rce-r: var(--r, 10px);
       --rce-mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
       --rce-body: var(--font-body, ui-sans-serif, system-ui, sans-serif);
       --rce-display: var(--font-display, var(--rce-body));

       /* Engine-owned semantic status colours — separate from the brand
          accent on purpose (design guidance: semantic color doesn't count
          as your accent). Muted, not primary-hue, so they read as state,
          not decoration. */
       --rce-good: #2E7D5B; --rce-good-bg: rgba(46,125,91,.12);
       --rce-warn: #9C6B08; --rce-warn-bg: rgba(156,107,8,.14);
       --rce-danger-bg: rgba(179,38,30,.10);
       --rce-brand-bg: color-mix(in srgb, var(--rce-brand) 10%, transparent);

       display: flex; flex-direction: column; gap: 14px;
       font-family: var(--rce-body); color: var(--rce-ink);
       font-variant-numeric: tabular-nums;
}
.rce * { box-sizing: border-box; }
.rce button { font-family: inherit; }
@media (prefers-reduced-motion: reduce) { .rce * { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------- toolbar */
.rce-toolbar { display: flex; flex-direction: column; gap: 10px; background: var(--rce-surface);
  border: 1px solid var(--rce-line); border-radius: var(--rce-r); padding: 12px 18px; }
.rce-toolbar-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rce-spacer { flex: 1 1 auto; }
/* This is the number the design brief asks to read in 10 seconds — design
   critique flagged the first version as reading like secondary toolbar
   text (13.5px, all-muted) despite being the page's single most important
   figure. Given its own quiet container and a larger mono figure so it
   holds its own next to the Import CSV button instead of losing to it. */
.rce-headline { display: flex; align-items: center; gap: 6px; font: 600 13px/1.3 var(--rce-body);
  color: var(--rce-muted); white-space: nowrap; background: var(--rce-ground);
  border: 1px solid var(--rce-line); border-radius: 999px; padding: 7px 14px 7px 6px; }
.rce-headline-num { font: 700 18px/1 var(--rce-mono); color: var(--rce-ink); background: var(--rce-surface);
  border-radius: 999px; padding: 3px 10px; }
.rce-headline-diff { font: 700 16px/1 var(--rce-mono); padding: 3px 10px; border-radius: 999px; margin-left: 2px; }
.rce-headline-diff.rce-zero { color: var(--rce-good); background: var(--rce-good-bg); }
.rce-headline-diff.rce-nonzero { color: var(--rce-danger); background: var(--rce-danger-bg); }

.rce-select, .rce-input {
  min-height: 36px; padding: 6px 10px; border: 1px solid var(--rce-line-strong);
  border-radius: calc(var(--rce-r) - 4px); background: var(--rce-surface); color: var(--rce-ink);
  font: 400 13.5px/1.3 var(--rce-body);
}
.rce-select:focus-visible, .rce-input:focus-visible { outline: 2px solid var(--rce-brand); outline-offset: 1px; }
.rce-label { font: 600 10.5px/1 var(--rce-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--rce-muted); }

.rce-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 7px 14px;
  border-radius: 999px; border: 1px solid var(--rce-line-strong); background: var(--rce-surface);
  color: var(--rce-ink); font: 600 13px/1 var(--rce-body); cursor: pointer; transition: filter .12s ease, transform .08s ease; }
.rce-btn:hover { filter: brightness(0.97); }
.rce-btn:active { transform: translateY(1px); }
.rce-btn:focus-visible { outline: 2px solid var(--rce-brand); outline-offset: 2px; }
.rce-btn[disabled] { opacity: .45; cursor: not-allowed; }
.rce-btn-primary { background: var(--rce-brand); border-color: var(--rce-brand); color: var(--rce-on-brand); }
.rce-btn-ghost { background: transparent; }
.rce-btn-danger { color: var(--rce-danger); border-color: var(--rce-danger); }
.rce-btn-sm { min-height: 28px; padding: 4px 10px; font-size: 12px; }

.rce-period-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding-top: 10px; border-top: 1px dashed var(--rce-line); }
.rce-period-bar .rce-input { width: 110px; }
.rce-computed { font: 600 12.5px/1 var(--rce-mono); color: var(--rce-muted); }
.rce-diff-chip { font: 700 12px/1 var(--rce-mono); padding: 4px 9px; border-radius: 999px; }
.rce-diff-chip.rce-ok { color: var(--rce-good); background: var(--rce-good-bg); }
.rce-diff-chip.rce-bad { color: var(--rce-danger); background: var(--rce-danger-bg); }
.rce-period-note { font-size: 12px; color: var(--rce-muted); }

/* ------------------------------------------------------------ import panel */
.rce-panel { background: var(--rce-surface); border: 1px solid var(--rce-line); border-radius: var(--rce-r);
  padding: 16px; display: grid; gap: 12px; }
.rce-panel[hidden] { display: none; }
.rce-panel h3 { margin: 0; font: 700 13px/1 var(--rce-body); }
.rce-dropzone { border: 2px dashed var(--rce-line-strong); border-radius: var(--rce-r); padding: 26px;
  text-align: center; color: var(--rce-muted); font-size: 13.5px; cursor: pointer; }
.rce-dropzone.rce-drag { border-color: var(--rce-brand); background: var(--rce-brand-bg); color: var(--rce-ink); }
.rce-format-line { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.rce-format-badge { font: 700 11px/1 var(--rce-mono); padding: 4px 8px; border-radius: 999px;
  background: var(--rce-brand-bg); color: var(--rce-brand); }
.rce-preview-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rce-preview-table th { text-align: left; font: 600 10px/1 var(--rce-mono); text-transform: uppercase;
  letter-spacing: .06em; color: var(--rce-muted); padding: 6px 8px; border-bottom: 2px solid var(--rce-line); }
.rce-preview-table td { padding: 6px 8px; border-bottom: 1px solid var(--rce-line); white-space: nowrap; }
.rce-preview-wrap { overflow-x: auto; }
.rce-money { font-family: var(--rce-mono); text-align: right; }
.rce-money.rce-out { color: var(--rce-danger); }
.rce-money.rce-in { color: var(--rce-good); }

/* ----------------------------------------------------------- rules drawer */
.rce-rule-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--rce-line); font-size: 12.5px; }
.rce-rule-row:last-child { border-bottom: none; }
.rce-rule-pattern { font-family: var(--rce-mono); }
.rce-rule-form { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; }

/* ---------------------------------------------------------- suggest strip */
.rce-suggest-strip { background: var(--rce-surface); border: 1px solid var(--rce-line); border-radius: var(--rce-r);
  padding: 12px 14px; display: grid; gap: 10px; }
.rce-suggest-strip[hidden] { display: none; }
.rce-suggest-title { font: 600 12.5px/1.3 var(--rce-body); color: var(--rce-muted); }
.rce-suggest-title b { color: var(--rce-ink); }
.rce-suggest-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.rce-suggest-card { flex: 0 0 auto; display: grid; gap: 4px; min-width: 200px; max-width: 280px;
  border: 1px solid var(--rce-line-strong); border-radius: calc(var(--rce-r) - 2px); padding: 8px 10px;
  cursor: pointer; background: var(--rce-ground); }
.rce-suggest-card:hover, .rce-suggest-card:focus-visible { border-color: var(--rce-brand); outline: none; }
.rce-suggest-card.rce-top { border-color: var(--rce-brand); background: var(--rce-brand-bg); }
.rce-tier { font: 700 9.5px/1 var(--rce-mono); text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 7px; border-radius: 999px; width: fit-content; }
.rce-tier-exact, .rce-tier-fee_netted { color: var(--rce-good); background: var(--rce-good-bg); }
.rce-tier-combination { color: var(--rce-brand); background: var(--rce-brand-bg); }
.rce-tier-fuzzy, .rce-tier-rule { color: var(--rce-warn); background: var(--rce-warn-bg); }
.rce-suggest-desc { font-size: 12.5px; line-height: 1.35; }
.rce-suggest-amount { font: 700 13px/1 var(--rce-mono); }
.rce-suggest-empty { color: var(--rce-muted); font-size: 13px; padding: 6px 0; }
.rce-action-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rce-fee-input { width: 90px; }

/* ------------------------------------------------------------- flow hint */
.rce-flow-hint { font: 600 12.5px/1.4 var(--rce-body); color: var(--rce-muted); background: var(--rce-ground);
  border: 1px solid var(--rce-line); border-radius: var(--rce-r); padding: 8px 14px; }
.rce-flow-hint b { color: var(--rce-ink); }

/* ------------------------------------------------------------- two panes */
.rce-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; min-height: 0; }
@media (max-width: 920px) { .rce-body { grid-template-columns: 1fr; } }

.rce-pane { background: var(--rce-surface); border: 1px solid var(--rce-line); border-radius: var(--rce-r);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.rce-pane-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px;
  border-bottom: 1px solid var(--rce-line); }
.rce-pane-head h3 { margin: 0; font: 700 12.5px/1 var(--rce-mono); text-transform: uppercase; letter-spacing: .06em; }
.rce-hint { font-size: 11px; color: var(--rce-muted); margin-left: auto; }

.rce-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.rce-chip { font: 600 11.5px/1 var(--rce-body); padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--rce-line-strong); background: var(--rce-surface); color: var(--rce-muted); cursor: pointer; }
.rce-chip.rce-on { background: var(--rce-brand); border-color: var(--rce-brand); color: var(--rce-on-brand); }

.rce-list { overflow-y: auto; max-height: 480px; }
.rce-row { display: grid; grid-template-columns: 78px 1fr auto auto 20px; gap: 10px; align-items: center;
  padding: 9px 12px; border-bottom: 1px solid var(--rce-line); cursor: pointer; position: relative; }
.rce-row:last-child { border-bottom: none; }
.rce-row:hover { background: var(--rce-ground); }
.rce-row.rce-selected { background: var(--rce-brand-bg); }
.rce-row.rce-selected::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--rce-brand); }
.rce-row-date { font: 600 11.5px/1.2 var(--rce-mono); color: var(--rce-muted); }
/* CSS Grid item default is min-width:auto, so a long description's
   intrinsic (unwrapped) width can force this 1fr column — and the whole
   row/list — wider than the pane, defeating .rce-row-desc's own
   ellipsis and producing a stray horizontal scrollbar. min-width:0 lets
   the grid track actually win the size fight, same standard fix as a
   flex item that needs to shrink below its content. */
.rce-row-main { min-width: 0; overflow: hidden; }
.rce-row-desc { font-size: 13px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rce-row-sub { font-size: 11px; color: var(--rce-muted); margin-top: 1px; }
.rce-row-amount { font: 700 13px/1 var(--rce-mono); text-align: right; white-space: nowrap; }
.rce-row-action { display: flex; justify-content: flex-end; }
.rce-row-action:empty { display: none; }
.rce-status-dot { width: 9px; height: 9px; border-radius: 50%; justify-self: center; }
.rce-status-unmatched .rce-status-dot { background: var(--rce-danger); }
.rce-status-matched .rce-status-dot { background: var(--rce-brand); }
.rce-status-reconciled .rce-status-dot { background: var(--rce-good); }
.rce-status-excluded .rce-status-dot { background: var(--rce-line-strong); }
.rce-flag { font-size: 11px; color: var(--rce-warn); }

.rce-book-row { grid-template-columns: 20px 78px 1fr auto; }
.rce-book-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--rce-brand); }
/* The book-row equivalent of the bank pane's top suggestion — set when
   this row is in the currently selected bank transaction's #1 candidate,
   so discoverability doesn't rely on reading the suggestion strip's text
   alone (RESEARCH.md "highlight the matching book row"). */
.rce-book-row.rce-suggested { background: var(--rce-brand-bg); box-shadow: inset 3px 0 0 var(--rce-brand); }

.rce-pane-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; border-top: 1px solid var(--rce-line); font-size: 12.5px; color: var(--rce-muted); }
.rce-selected-total { font: 700 13px/1 var(--rce-mono); color: var(--rce-ink); }

.rce-empty { padding: 32px 16px; text-align: center; color: var(--rce-muted); font-size: 13px; }

/* --------------------------------------------------------------- toasts */
.rce-toast { position: fixed; bottom: 18px; right: 18px; background: var(--rce-ink); color: var(--rce-surface);
  padding: 10px 16px; border-radius: calc(var(--rce-r) - 2px); font-size: 13px; z-index: 1000;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 360px; }
.rce-toast.rce-toast-error { background: var(--rce-danger); }
