/* Worksheet, register, bills, income and setup.
   Adopted from the reviewed mockup rather than rewritten, so what was
   approved is what ships. */

body.app {
  display: block; padding: 0; margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
}
/* ─────────────────────────────────────────────────────────── chrome ── */

/* Wraps rather than overflowing. A single non-wrapping row silently pushed
   the first tabs off-screen as items were added - the nav was correct in
   the markup and simply not visible, which is a worse failure than being
   ugly. */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.5rem; border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; background: var(--paper); z-index: 20;
}
.brand {
  font: 700 .72rem/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .18em; text-transform: uppercase; color: var(--accent);
  /* The mark and the word read as one unit, aligned on their centres
     rather than their baselines - the mark has no baseline. */
  display: inline-flex; align-items: center; gap: .5rem;
}
.brand img {
  /* Fixed, because a logo that resizes with the text wobbles between
     views. Alt is empty: the word beside it already says the name, and a
     screen reader should not read it twice. */
  flex: none;
  display: block;
}
/* The tabs take the space they need and wrap together; the period controls
   are pushed to the far end so they stay findable at any width. */
.views { display: flex; gap: .25rem; flex-wrap: wrap; }

.topbar-right {
  display: flex; align-items: center; gap: .5rem;
  margin-left: auto;
}
.view-tab {
  font: 600 .85rem/1 "Segoe UI", system-ui, sans-serif;
  padding: .45rem .8rem; margin: 0; cursor: pointer;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted);
}
.view-tab.is-on { color: var(--ink); border-bottom-color: var(--accent); }
.who { margin-left: auto; font-size: .8rem; color: var(--muted); }

.page { max-width: 68rem; margin: 0 auto; padding: 1.75rem 1.5rem 5rem; }
/* The worksheet is a grid, not prose. A reading column wastes a wide
   monitor on the one view that can use every pixel. */
#page-worksheet { max-width: none; padding-left: 2rem; padding-right: 2rem; }
.topbar { max-width: none; }

/* ───────────────────────────────────────────────────────── position ── */

.position { display: flex; flex-wrap: wrap; gap: 3rem; align-items: flex-end; }
.headline .label {
  font: 700 .68rem/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 .4rem;
}
.figure {
  font: 700 clamp(2rem, 5vw, 2.9rem)/1 "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -.02em; margin: 0;
}
.figure.negative, .negative { color: #b3392f; }
@media (prefers-color-scheme: dark) { .figure.negative, .negative { color: #de7a6e; } }
.provisional { font-size: .78rem; color: var(--muted); margin: .4rem 0 0; }

.breakdown {
  display: flex; flex-wrap: wrap; gap: 1.75rem; margin: 0;
  font-size: .82rem;
}
.breakdown.standalone {
  padding-top: 1rem; border-top: 1px solid var(--rule); margin-top: .5rem;
}
.breakdown div { display: flex; flex-direction: column; gap: .1rem; }
.breakdown div.sub { opacity: .65; }
.breakdown dt {
  font-size: .64rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.breakdown dd { margin: 0; font-family: "Cascadia Mono", Consolas, monospace; }

.alert {
  margin: 1.5rem 0 0; padding: .9rem 1.1rem; border-radius: 3px;
  border: 1px solid #b3392f; background: rgba(179,57,47,.06);
}
.alert h2 { font-size: .92rem; margin: 0 0 .3rem; }
.alert p { font-size: .82rem; margin: 0; line-height: 1.5; }

/* ────────────────────────────────────────────────────── the sheet ── */

.rows-head {
  display: flex; align-items: center; gap: 1rem;
  margin: 2.25rem 0 .75rem;
}
.rows-head h2 { font: 700 1.05rem/1 "Helvetica Neue", Arial, sans-serif; margin: 0; }
.filters { display: flex; gap: .3rem; margin-left: auto; }
.filter, .ghost, .primary, .icon, .link, button.small {
  font: 600 .8rem/1 "Segoe UI", system-ui, sans-serif; cursor: pointer;
}
.filter {
  padding: .32rem .7rem; background: none; color: var(--muted);
  border: 1px solid var(--rule); border-radius: 999px;
}
.filter.is-on { border-color: var(--accent); color: var(--accent); }
.ghost {
  padding: .45rem .85rem; background: none; color: var(--ink);
  border: 1px solid var(--rule); border-radius: 3px;
}
.primary {
  padding: .45rem .95rem; background: var(--accent); color: var(--paper);
  border: 1px solid var(--accent); border-radius: 3px;
}
.primary.small { padding: .3rem .6rem; font-size: .75rem; }
.link { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 0; }
.icon { background: none; border: none; font-size: 1.3rem; color: var(--muted); line-height: 1; }
.inline { margin-left: auto; }
select.inline, .check.inline { font-size: .8rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); }

/* Bills stay put; periods scroll sideways. */
.sheet-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 3px; }
.sheet { border-collapse: collapse; font-size: .82rem; min-width: 100%; }
.sheet th, .sheet td { padding: .42rem .6rem; white-space: nowrap; }
.sheet thead th {
  font-size: .64rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; text-align: left;
  border-bottom: 1px solid var(--ink); background: var(--paper);
}
.period-head {
  text-align: center !important;
  font-size: .74rem !important; letter-spacing: .04em !important;
  text-transform: none !important; color: var(--ink) !important;
  padding-top: .6rem !important; padding-bottom: .6rem !important;
}
.period-head.current { color: var(--accent) !important; }
.period-head.dim { opacity: .55; }

/* Each period is three columns that must read as one block. A single
   hairline between them is not enough at this density, so every period
   gets a ground of its own and a boundary carried through head, body and
   foot as one continuous line. */
.sheet .p-start { border-left: 2px solid var(--rule); }
.sheet .p1 { background: rgba(127,127,127,.055); }
.sheet .p2 { background: transparent; }
.sheet .p0 { background: var(--accent-soft, rgba(15,107,99,.06)); }
tr.group .p0, tr.group .p1, tr.group .p2 { background: transparent; }
.sheet tfoot .p0 { background: var(--accent-soft, rgba(15,107,99,.09)); }
.badge {
  display: inline-block; margin-left: .35rem; padding: 0 .35rem;
  border: 1px solid var(--accent); border-radius: 3px;
  font-size: .6rem; letter-spacing: .08em; text-transform: uppercase;
}
.sheet tbody td, .sheet tbody th { border-bottom: 1px solid var(--rule); }
.sheet tbody th { font-weight: 600; text-align: left; }

/* Frozen name and account columns. */
.sticky-col, .sticky-col-2 {
  position: sticky; background: var(--paper); z-index: 2;
}
.sticky-col { left: 0; min-width: 16rem; }
.sticky-col-2 { left: 16rem; min-width: 7rem; color: var(--muted); font-size: .76rem;
  border-right: 2px solid var(--ink); }
thead .sticky-col, thead .sticky-col-2 { z-index: 3; }

.sheet .num { text-align: right; font-family: "Cascadia Mono", Consolas, monospace; }
.due { color: var(--muted); font-size: .76rem; }
.due.late { color: #b3392f; font-weight: 700; }
.paid { color: var(--accent); }
.paid.under { color: #7a4b12; }

/* Paid but not yet cleared: the money is committed, the bank has not taken
   it. Shown lighter than a cleared payment, so a glance down the column
   separates what is finished from what is still in flight - without
   relying on the difference between one tick and two. */
.paid:not(.cleared) { opacity: .82; }
.cleared { font-weight: 600; }
.verify { color: #7a4b12; }
.declined { color: #b3392f; }
.est-var { font-style: italic; }
.dim { opacity: .5; }

tr.group th {
  font: 700 .64rem/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .13em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-sunk, rgba(127,127,127,.07));
  padding: .5rem .6rem;
}
tr.is-overdue td, tr.is-overdue th { background: rgba(179,57,47,.05); }
tr.is-carried td, tr.is-carried th { background: rgba(122,75,18,.05); }
tr.is-paused { opacity: .55; }

.sheet tfoot th, .sheet tfoot td {
  border-top: 2px solid var(--ink); font-weight: 700; padding: .5rem .6rem;
}
.sheet tfoot .ending td { font-size: .95rem; }

.tag {
  display: inline-block; margin-left: .35rem; padding: 0 .4rem;
  border: 1px solid var(--rule); border-radius: 3px; color: var(--muted);
  font: 600 .62rem/1.5 "Segoe UI", system-ui, sans-serif; letter-spacing: .05em;
}
.tag.auto { border-color: var(--accent); color: var(--accent); }
.tag.warn { border-color: #b3392f; color: #b3392f; }
.tag.term { border-color: var(--muted); }

.portal {
  margin-left: .4rem; font-size: .74rem; color: var(--accent);
  text-decoration: none; opacity: .75;
}
.portal:hover { opacity: 1; text-decoration: underline; }

.hint { font-size: .78rem; color: var(--muted); line-height: 1.55; margin: .75rem 0 0; }

.close-period {
  margin-top: 2.5rem; padding: 1.1rem 1.3rem;
  border: 1px solid var(--rule); border-radius: 3px;
}
.close-period .rows-head { margin: 0 0 .4rem; }

/* ──────────────────────────────────────────────────────── register ── */

.register, .list, .mapping {
  width: 100%; border-collapse: collapse; font-size: .84rem; margin-top: 1rem;
}
.register th, .list th, .mapping th {
  text-align: left; font-size: .64rem; letter-spacing: .11em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: 0 .7rem .5rem 0;
  border-bottom: 1px solid var(--ink);
}
.register td, .list td, .mapping td {
  padding: .5rem .7rem .5rem 0; border-bottom: 1px solid var(--rule);
}
.register .num, .list .num, .num { text-align: right; font-family: "Cascadia Mono", Consolas, monospace; }
.register .mid { text-align: center; }
.register .name, .list .name { font-weight: 600; }
.right { text-align: right; }
tr.deposit td { color: var(--accent); }
tr.uncleared { color: var(--muted); }
tr.uncleared.stale td:first-child { border-left: 2px solid #b3392f; padding-left: .5rem; }
/* A button, not an indicator: reconciling a statement means ticking off a
   column of these, so the visible dot stays small while the clickable area
   is large enough to hit repeatedly without aiming. */
/* Cleared or not, in the register.
   Shape and colour together, never colour alone: a red/green pair is
   invisible to roughly one man in twelve and to any printed copy, so the
   circle/square distinction carries the meaning on its own. The legend
   above the table names both. */
.mark {
  display: inline-block; width: .6rem; height: .6rem;
  border: 1.5px solid var(--muted);
  padding: 0;
  background: none;
}
button.mark { cursor: pointer; box-shadow: 0 0 0 .5rem transparent; }

/* Cleared: a filled green circle. Done, settled, nothing outstanding. */
.mark.done {
  border-radius: 50%;
  background: #1E7A45;
  border-color: #1E7A45;
}
/* Not cleared: an open red square. Different SHAPE, not merely a different
   colour, and open rather than filled - the money is still to come out. */
.mark.todo {
  border-radius: 1px;
  background: none;
  border-color: #B3261E;
}
button.mark:hover { opacity: .7; }

/* The legend that makes the marks readable without being told. */
.legend {
  display: flex; flex-wrap: wrap; gap: 1.25rem;
  margin: .25rem 0 .75rem;
  font-size: .78rem; color: var(--soft);
}
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }

.subhead {
  font: 700 .68rem/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .13em; text-transform: uppercase; color: var(--muted);
  margin: 2.5rem 0 0;
}

/* ─────────────────────────────────────────────────────────── setup ── */

.setup-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: 2.5rem;
}
.setup-grid h2 { font: 700 1rem/1 "Helvetica Neue", Arial, sans-serif; margin: 0 0 .5rem; }
.setup-grid .ghost { margin-top: 1rem; }
.cat-list { list-style: none; margin: 1rem 0 0; padding: 0; font-size: .84rem; }
.cat-list li {
  display: flex; flex-direction: column; gap: .1rem;
  padding: .5rem 0; border-bottom: 1px solid var(--rule);
}
.cat-list span { color: var(--muted); font-size: .78rem; }

/* ─────────────────────────────────────────────────────────── modal ── */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4rem 1.5rem; z-index: 50; overflow-y: auto;
}
/* `display` beats the hidden attribute, so a display rule on an element
   that uses [hidden] has to say so explicitly or the element is never
   hidden at all. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--paper); border-radius: 4px; width: 100%; max-width: 34rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.modal.wide { max-width: 48rem; }
.modal-head {
  display: flex; align-items: center; gap: 1rem;
  padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--rule);
}
.modal-head h2 { font: 700 1.05rem/1 "Helvetica Neue", Arial, sans-serif; margin: 0; }
.modal-head .icon { margin-left: auto; }
.modal-body { padding: 1.4rem; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: .6rem;
  padding: 1rem 1.4rem; border-top: 1px solid var(--rule);
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-grid .span { grid-column: 1 / -1; }
.field-grid > div { display: flex; flex-direction: column; gap: .3rem; }
.field-grid label {
  font: 600 .68rem/1.3 "Segoe UI", system-ui, sans-serif;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.field-grid input, .field-grid select, select.inline {
  font: .88rem/1.4 "Segoe UI", system-ui, sans-serif; padding: .5rem .6rem;
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--paper); color: var(--ink);
}

/* ────────────────────────────────────────────────────────── import ── */

.steps { display: flex; gap: .5rem; margin-bottom: 1.1rem; }
.step {
  font: 600 .72rem/1 "Segoe UI", system-ui, sans-serif;
  padding: .35rem .7rem; border: 1px solid var(--rule); border-radius: 999px;
  color: var(--muted);
}
.step.on { border-color: var(--accent); color: var(--accent); }
.step.done { opacity: .55; }
.mapping .sample { color: var(--muted); font-size: .78rem; }
.mapping select { font-size: .82rem; padding: .35rem .5rem;
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--paper); color: var(--ink); width: 100%; }
tr.unmapped { opacity: .55; }
.notice {
  margin-top: 1.1rem; padding: .8rem 1rem; border-radius: 3px;
  border: 1px solid #7a4b12; background: rgba(122,75,18,.07);
  font-size: .82rem; line-height: 1.55;
}
.notice .sample { display: block; color: var(--muted); margin-top: .2rem; }

/* ──────────────────────────────────────────────────── app additions ── */

/* A cell the user can act on should look like one. */
.sheet td.editable { cursor: pointer; }
.sheet td.editable:hover { outline: 1px solid var(--accent); outline-offset: -1px; }

/* Actions appear beside the cell rather than in a dialogue: FUNC-6.31
   makes marking paid the most repeated action in the product. */
.row-menu {
  position: absolute; z-index: 60; min-width: 12rem;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.22); padding: .25rem;
}
.row-menu button {
  display: block; width: 100%; text-align: left;
  padding: .5rem .7rem; margin: 0; border: none; background: none;
  font: .85rem/1.3 "Segoe UI", system-ui, sans-serif; color: var(--ink);
  cursor: pointer; border-radius: 3px;
}
.row-menu button:hover { background: var(--accent); color: var(--paper); }

/* The status the row already has. Shown rather than omitted, so the menu
   reads as "this is what it is, here is what else it could be". */
.row-menu button.is-current {
  font-weight: 600;
  opacity: 0.75;
  cursor: default;
}
.row-menu button.is-current:hover { background: none; color: inherit; }

.row-menu hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 0.25rem 0;
}

/* The ? bubbles. Real buttons, so they focus and activate like anything
   else — hover alone excludes touch and keyboard users entirely. */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.05rem; height: 1.05rem; margin-left: .3rem; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%; background: none;
  color: var(--muted); cursor: pointer;
  font: 600 .68rem/1 "Segoe UI", system-ui, sans-serif;
}
.help:hover, .help:focus { border-color: var(--accent); color: var(--accent); }

.tip {
  position: absolute; z-index: 70; max-width: 22rem;
  background: var(--paper); border: 1px solid var(--accent); border-radius: 4px;
  padding: .8rem 1rem; box-shadow: 0 8px 24px rgba(0,0,0,.22);
  font: .82rem/1.55 "Segoe UI", system-ui, sans-serif;
}
.tip p { margin: 0 0 .5rem; }
.tip .link { font-size: .78rem; }

/* Help is two panes: topics on the left, the chosen one on the right. */
.help-body { display: grid; grid-template-columns: 14rem 1fr; gap: 1.5rem; }
.help-nav { display: flex; flex-direction: column; gap: .1rem; }
.help-nav button {
  text-align: left; padding: .5rem .7rem; margin: 0;
  background: none; border: none; border-left: 2px solid transparent;
  color: var(--muted); cursor: pointer;
  font: 600 .82rem/1.3 "Segoe UI", system-ui, sans-serif;
}
.help-nav button.is-on { color: var(--ink); border-left-color: var(--accent); }
.help-content h3 {
  font: 700 1.05rem/1.3 "Helvetica Neue", Arial, sans-serif; margin: 0 0 .75rem;
}
.help-content p {
  font: .88rem/1.65 "Segoe UI", system-ui, sans-serif; margin: 0 0 .8rem;
  color: var(--soft); max-width: 38rem;
}
.help-content a { color: var(--accent); }

@media (max-width: 46rem) {
  .help-body { grid-template-columns: 1fr; }
  .help-nav { flex-direction: row; flex-wrap: wrap; }
  .help-nav button { border-left: none; border-bottom: 2px solid transparent; }
  .help-nav button.is-on { border-bottom-color: var(--accent); }
}

/* Modals are display:flex, which beats the hidden attribute unless this
   says otherwise — the element would never actually hide. */
.modal-backdrop[hidden] { display: none; }

/* The one setting whose absence cannot be undone.
 *
 * Marked rather than merely present: a user will not go looking for a
 * recovery phrase, and by the time they want one it is too late to make
 * one. Removed as soon as a phrase exists. */
.needs-attention {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}
