/*
 * Greenbar accounting paper: the material this work has always been done on.
 * Banding is functional (row tracking across a wide table), the stamp red is
 * reserved for things that need an adviser's eye, and every figure is
 * monospaced and tabular so columns align the way a statement's do.
 */

:root {
  --paper: #fbfaf6;
  --band: #edf1e9;
  --ink: #1c2321;
  --ink-soft: #5c665f;
  --rule: #c9cfc6;
  --stamp: #a63a22;
  --confirm: #2f5d50;
  --focus: #1c5f8a;

  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;

  --gutter: clamp(1rem, 4vw, 3rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14171a;
    --band: #1b2024;
    --ink: #e8eae4;
    --ink-soft: #97a29b;
    --rule: #333c40;
    --stamp: #e07a5f;
    --confirm: #7fb2a1;
    --focus: #6cb6e8;
  }
}
:root[data-theme="dark"] {
  --paper: #14171a; --band: #1b2024; --ink: #e8eae4; --ink-soft: #97a29b;
  --rule: #333c40; --stamp: #e07a5f; --confirm: #7fb2a1; --focus: #6cb6e8;
}
:root[data-theme="light"] {
  --paper: #fbfaf6; --band: #edf1e9; --ink: #1c2321; --ink-soft: #5c665f;
  --rule: #c9cfc6; --stamp: #a63a22; --confirm: #2f5d50; --focus: #1c5f8a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

/* ---- masthead ------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.25rem var(--gutter) 1rem;
  border-bottom: 2px solid var(--ink);
}

.masthead h1 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.masthead .locality {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.masthead .locality b { color: var(--confirm); font-weight: 600; }

/* ---- dropzone ------------------------------------------------------- */

main { padding: 0 var(--gutter) 4rem; }

.dropzone {
  margin: 2rem 0;
  padding: clamp(2rem, 8vw, 4.5rem) 1.5rem;
  border: 1px dashed var(--rule);
  text-align: center;
  cursor: pointer;
  background: transparent;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color 120ms, background 120ms;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone[data-over="true"] {
  border-color: var(--ink);
  background: var(--band);
}
.dropzone strong { display: block; font-size: 1.05rem; margin-bottom: 0.35rem; }
.dropzone span { color: var(--ink-soft); font-size: 0.85rem; }

/* ---- the trust bar -------------------------------------------------- */

.ledger-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0 2.5rem;
  align-items: flex-end;
  padding: 1rem 0 0.85rem;
  border-bottom: 1px solid var(--ink);
}

.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat dt {
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stat dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}
.stat[data-tone="good"] dd { color: var(--confirm); }
.stat[data-tone="alert"] dd { color: var(--stamp); }

/* ---- ledger --------------------------------------------------------- */

.section-rule {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  width: 100%;
  margin: 2rem 0 0;
  padding: 0.5rem 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.section-rule h2 {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
}
.section-rule .count { font-family: var(--mono); color: var(--ink-soft); font-size: 0.8rem; }
.section-rule .chevron { margin-left: auto; color: var(--ink-soft); font-size: 0.75rem; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

thead th {
  padding: 0.6rem 0.5rem;
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
th.num, td.num { text-align: right; font-family: var(--mono); white-space: nowrap; }

tbody tr { border-bottom: 1px solid color-mix(in srgb, var(--rule) 45%, transparent); }
tbody tr:nth-child(even) { background: var(--band); }
tbody tr:focus-within { outline: 2px solid var(--focus); outline-offset: -2px; }

td { padding: 0.5rem; vertical-align: top; }
td.date { font-family: var(--mono); color: var(--ink-soft); white-space: nowrap; font-size: 0.85rem; }
td.detail { width: 45%; }
td.detail .desc { display: block; word-break: break-word; }
td.credit { color: var(--confirm); }

/* The reconciliation spine: a continuous rule down the balance column that
   breaks exactly where the bank's own arithmetic stops chaining. */
td.balance {
  border-left: 2px solid var(--confirm);
  position: relative;
}
tr[data-break="true"] td.balance {
  border-left-color: var(--stamp);
  border-left-style: dashed;
}
tr[data-break="true"] td.balance::before {
  content: "chain breaks here";
  position: absolute;
  left: 0.5rem;
  bottom: -0.55rem;
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--stamp);
  background: var(--paper);
  padding: 0 0.3rem;
}

/* ---- flags and controls --------------------------------------------- */

.flag {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--stamp);
  color: var(--stamp);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.flag[data-kind="transfer"] { border-color: var(--ink-soft); color: var(--ink-soft); }

select {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.3rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  max-width: 100%;
}
select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Rule-scope prompt: appears only after a correction, because that is the only
   moment the question means anything. */
.scope {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.scope button {
  font: inherit;
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.scope button:hover { border-color: var(--ink); }
.scope button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.scope code { font-family: var(--mono); color: var(--ink); }

/* When a rule is created, every row it touches flashes once - the point of the
   feature made visible. */
@keyframes applied {
  from { background: color-mix(in srgb, var(--confirm) 28%, transparent); }
  to { background: transparent; }
}
tr[data-applied="true"] { animation: applied 900ms ease-out; }

@media (prefers-reduced-motion: reduce) {
  tr[data-applied="true"] { animation: none; box-shadow: inset 3px 0 0 var(--confirm); }
  * { transition: none !important; }
}

/* ---- facilities and footer ------------------------------------------ */

.facilities { margin-top: 2.5rem; }
.facilities td.rate { color: var(--stamp); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 2rem; }
.toolbar button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.toolbar button:hover { background: var(--ink); color: var(--paper); }
.toolbar button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.note {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  color: var(--ink-soft);
  max-width: 62ch;
}

/* ---- client bar ------------------------------------------------------ */

/* Rules scope to the selected client, so this is what stops one borrower's
   categorisation carrying onto the next borrower's statements. */
.client-bar {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 1rem 0 0;
}
.client-bar label {
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.push-right { margin-left: auto; }

/* A suggestion is a proposal, not a decision: dashed rather than solid, and
   the row stays in the queue until it is confirmed. */
.badge-suggested {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.35rem;
  border: 1px dashed var(--ink-soft);
  color: var(--ink-soft);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  vertical-align: 1px;
}

tr.merchant-group td {
  background: var(--band);
  border-top: 1px solid var(--rule);
}
tr.merchant-group .merchant-count {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.scope label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

/* ---- account strip -------------------------------------------------- */

/* One chip per loaded account: the single place an account is switched on,
   named, and reported on. A dot means its balance chain does not close. */
.account-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 0 0;
}

.chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--paper);
}
.chip[data-shown="false"] { opacity: 0.45; }
.chip[data-shown="false"] .chip-toggle { text-decoration: line-through; }

.chip-toggle {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* The account's purpose is a standing decision about everything on it, so it
   reads as a state rather than an action. */
.linklike.purpose {
  text-decoration: none;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.linklike.purpose[data-purpose="rental"] {
  border-color: var(--confirm);
  color: var(--confirm);
}
.linklike.purpose[data-purpose="business"] {
  border-color: var(--focus);
  color: var(--focus);
}

/* The row picker carries the same colour coding as the chip, so a glance down
   the column shows which rows belong to which venture. */
select.purpose { font-size: 0.75rem; padding: 0.1rem 0.2rem; }
select.purpose[data-purpose="rental"] { color: var(--confirm); }
select.purpose[data-purpose="business"] { color: var(--focus); }

.chip-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--stamp);
  flex: none;
}

.linklike {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.7rem;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
}
.linklike:hover { color: var(--ink); }
.linklike:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- ledger tabs ----------------------------------------------------- */

/* The tabs and the header stay put while the ledger scrolls: with hundreds of
   rows, a column heading or a filter box you have to scroll back for is a
   filter box you stop using. Offsets are measured at render, not guessed -
   the heights move with the font and with whether balance is showing. */
/* Tabs and the tools that act on the shown tab travel together, so the whole
   block is one sticky unit rather than two that can separate. */
.ledger-controls {
  position: sticky;
  top: 0;
  z-index: 4;
  margin-top: 2rem;
  background: var(--paper);
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  padding-top: 0.5rem;
  border-bottom: 1px solid var(--ink);
}

.tab-tools {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.45rem 0.1rem 0.35rem;
}

.tabs [role="tab"] {
  border: 1px solid transparent;
  border-bottom: 0;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  margin-bottom: -1px;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--paper);
}
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tabs [role="tab"] .count {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-soft);
  margin-left: 0.35rem;
}
.tabs .linklike { align-self: center; }

/* Sticky header rows sit below the tabs. They need an opaque background or
   the rows scroll through them. */
#ledger thead tr:first-child th {
  position: sticky;
  top: var(--tabs-h, 2.6rem);
  z-index: 3;
  background: var(--paper);
}
#ledger thead tr.filters th {
  position: sticky;
  top: calc(var(--tabs-h, 2.6rem) + var(--head-h, 2rem));
  z-index: 3;
  background: var(--paper);
}

/* ---- table controls -------------------------------------------------- */

th button.sort {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
th button.sort:hover { color: var(--ink); }
th button.sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

tr.filters th { padding: 0 0.5rem 0.5rem; border-bottom: 1px solid var(--rule); }
.filter { display: flex; gap: 0.25rem; }
.filter input, .filter select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 0.75rem;
  padding: 0.15rem 0.3rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
}
.filter input:focus-visible, .filter select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

td.tick, th.tick { width: 2rem; text-align: center; padding-left: 0; padding-right: 0; }

/* Bulk marking acts on whatever the filters left on screen. */
.bulk {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0.1rem 0.3rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.bulk .linklike[disabled] { opacity: 0.4; cursor: default; text-decoration: none; }

/* An empty result keeps the header and filter row above it, so the filter that
   emptied the table is still there to be undone. */
tbody tr.empty td {
  padding: 1rem 0.5rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* A figure is a button because it is correctable, but it must still read as a
   figure - so it inherits the monospaced tabular column and shows its
   affordance on hover rather than by looking like a control. */
button.figure {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: right;
}
button.figure:hover { text-decoration: underline dotted; }
button.figure:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

td[data-edited="true"] button.figure { color: var(--stamp); font-weight: 600; }
td[data-edited="true"] button.figure::after {
  content: "✎";
  margin-left: 0.3rem;
  font-size: 0.7rem;
}

/* ---- summary --------------------------------------------------------- */

/* Two halves of the content width: the left is the control surface, the right
   is the artefact that gets screenshotted or pasted. They collapse to one
   column when there is not room for two readable ones. */
.summary-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .summary-columns { grid-template-columns: minmax(0, 1fr); }
}

.summary-pane { min-width: 0; }
.pane-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0.9rem 0 0.3rem;
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.pane-title .linklike { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* Transfers sit outside the totals by design; this makes that visible rather
   than something the adviser has to know. */
.transfer-note {
  margin: 0.9rem 0 0;
  padding: 0.5rem 0.7rem;
  border-left: 3px solid var(--ink-soft);
  background: var(--band);
  font-size: 0.78rem;
  color: var(--ink-soft);
  max-width: 76ch;
}

.share-scope {
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
}

/* Condensed: this table is read as a block, not scanned row by row.
   The checkbox column is a gutter: headings, totals and the Net line all
   start at --summary-edge, and only the categories indent past it. Stated
   once here so the three cannot drift apart. */
table.summary {
  font-size: 0.8rem;
  --summary-edge: 0.4rem;
  --summary-indent: 1.15rem;
}
table.summary td, table.summary th { padding: 0.2rem 0.4rem; }
/* INCOME and EXPENSES: the two things being read. Larger than everything
   under them, and flush left. */
table.summary tr.section th {
  padding: 0.8rem 0.4rem 0.25rem var(--summary-edge);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

/* Expense subheadings: smaller than the section, flush left, and the
   categories beneath them are what get indented. */
table.summary tr.group th {
  padding-top: 0.55rem;
  padding-left: var(--summary-edge);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: left;
  border-bottom: 0;
}

table.summary td.cat { padding-left: var(--summary-indent); }
table.summary tr.spacer td { padding: 0; height: 0.8rem; border: 0; }
table.summary tr.net td { border-top-width: 2px; }
/* Net and the below-the-line notes sit at the shared edge, not indented with
   the categories - they summarise the block rather than belonging to it. */
table.summary tr.net td.cat,
table.summary tr.aside td.cat,
table.summary tr.pending td.cat { padding-left: var(--summary-edge); }
table.summary tr.pending td,
table.summary tr.aside td {
  border-top: 0;
  color: var(--ink-soft);
  font-weight: 400;
}
table.summary tbody tr:nth-child(even) { background: none; }
table.summary tbody tr.total td {
  border-top: 1px solid var(--ink);
  font-weight: 600;
}
table.summary tbody tr.total:last-child td { border-top-width: 2px; }

/* Every figure in the picker is a way into the rows behind it. */
button.drill {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
button.drill:hover { text-decoration: underline; }
button.drill:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* An excluded row stays put so its checkbox can be found again - the only way
   back is the box that removed it. It reads as struck out rather than gone. */
table.summary tbody tr[data-excluded="true"] td { color: var(--ink-soft); }
table.summary tbody tr[data-excluded="true"] td:nth-child(2) { text-decoration: line-through; }

table.summary.share { border-collapse: collapse; }
table.summary.share tbody tr.group th { padding-top: 0.6rem; }

/* ---- payment tracing -------------------------------------------------- */

/* A facility payment with no matching outgoing means a statement the adviser
   was not given. Stamp red is reserved for exactly that kind of finding. */
.tracing { margin-top: 2.5rem; }
.trace-line { margin: 0.35rem 0; font-size: 0.82rem; color: var(--ink-soft); }
.trace-line strong { color: var(--ink); font-weight: 600; }
.trace-line[data-tone="alert"] { color: var(--stamp); }
.trace-line[data-tone="alert"] strong { color: var(--stamp); }
.trace-line .figures { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.flag[data-kind="internal"] { border-color: var(--ink-soft); color: var(--ink-soft); }
.flag[data-kind="loan-payment"] { border-color: var(--confirm); color: var(--confirm); }
.flag[data-kind="redraw"] { border-color: var(--stamp); color: var(--stamp); }

/* ---- reconciliation -------------------------------------------------- */

.banner {
  margin: 1.25rem 0 0;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--stamp);
  background: color-mix(in srgb, var(--stamp) 8%, transparent);
  font-size: 0.82rem;
}
.banner p { margin: 0.25rem 0; }

.adjustments { margin-top: 2.5rem; }
.residual {
  margin: 0.5rem 0 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--stamp);
}

.hidden { display: none !important; }
