/* Zazen Accounting
 *
 * Design notes, so the next person changing this knows what is deliberate:
 *
 * - Every monetary figure and every document number is set in tabular
 *   monospace. Not a stylistic tic: in a ledger, digits have to align
 *   vertically to be compared at a glance, and a document reference is an
 *   identifier rather than prose.
 * - Amber (--sen) means money at risk -- outstanding, overdue, refused. It is
 *   never used decoratively, so its appearance always carries meaning.
 * - The settlement rail on an invoice shows paid / credited / outstanding as
 *   proportions of the total, because with partial payments the proportion is
 *   the information.
 */

:root {
  --paper: #fdfdfb;
  --card: #ffffff;
  --ink: #14261e;
  --ink-soft: #5a6b62;
  --ledger: #0f5132;
  --ledger-soft: #dcebe2;
  --sen: #b45309;
  --sen-soft: #fdf0dc;
  --flag-soft: #fff8d6;
  --rule: #dde3df;
  --wash: #edf2ef;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 4px;
  --gap: 1rem;

  /* How wide the page gets. Not removed altogether, though it nearly could
   * be: 118rem is past the width of any laptop, so on the machines this is
   * actually used on it is no constraint at all, and the recon sheet's twelve
   * columns get the room they were being denied at 70rem. What it still does
   * is stop a line of help text running the whole width of a 34" monitor,
   * which is a real cost and an invisible one -- prose past about 90
   * characters is measurably harder to read, and nobody attributes that to
   * the stylesheet. The content column and the flash messages above it both
   * read this, so they cannot drift out of line with each other; the header
   * is full-bleed and always was. */
  --page: 118rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper);
}

h1, h2, h3 { font-weight: 620; letter-spacing: -0.015em; line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.075rem; }
h3 { font-size: 0.95rem; }

a { color: var(--ledger); text-underline-offset: 2px; }

/* Money and references ---------------------------------------------------- */

.num,
.money,
.docref {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.money { text-align: right; white-space: nowrap; }
.money--due { color: var(--sen); }
.money--nil { color: var(--ink-soft); }

.docref { letter-spacing: 0.02em; }

/* The document number, as the hero of a detail page. */
.docref--hero {
  display: block;
  font-size: clamp(1.6rem, 4.5vw, 2.35rem);
  letter-spacing: 0.06em;
  font-weight: 500;
  color: var(--ledger);
}
.docref--draft { color: var(--ink-soft); }

/* Header ------------------------------------------------------------------ */

.app-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  padding: 0.7rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-weight: 680;
  letter-spacing: -0.02em;
  color: var(--ledger);
  text-decoration: none;
}

.app-nav { display: flex; gap: 1.1rem; }
.app-nav a { color: var(--ink-soft); text-decoration: none; }
.app-nav a:hover,
.app-nav a[aria-current="page"] { color: var(--ink); }
.app-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--ledger); }

.header-end { margin-inline-start: auto; display: flex; align-items: center; gap: 1rem; }

.app-main { max-width: var(--page); margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }

/* Page furniture ---------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head .actions { margin-inline-start: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 0 0 0.2rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card > h2 { margin-bottom: 0.75rem; }

.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); }

/* Status ------------------------------------------------------------------ */

.status { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.status::before {
  content: "";
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}
.status--draft { color: var(--ink-soft); }
.status--issued { color: var(--ledger); }
.status--partially_paid { color: var(--sen); }
.status--paid { color: var(--ledger); }
.status--overdue { color: var(--sen); font-weight: 600; }
.status--cancelled { color: var(--ink-soft); text-decoration: line-through; }

/* The settlement rail: paid / credited / outstanding, to scale. */
.rail {
  display: flex;
  height: 0.5rem;
  border-radius: 99px;
  overflow: hidden;
  background: var(--wash);
  margin: 0.85rem 0 0.6rem;
}
.rail span { display: block; }
.rail .rail-paid { background: var(--ledger); }
.rail .rail-credited { background: var(--ledger-soft); }
.rail .rail-due { background: var(--sen); }

.rail-key {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.rail-key b { font-weight: 600; color: var(--ink); font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Tables ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }

/* Stored payloads and errors: wrap anywhere rather than widen the page, and
   let a giant body scroll inside its card. */
.code {
  font: 0.85rem/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 24rem;
  overflow-y: auto;
  background: var(--wash);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
}

table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  background: var(--wash);
  white-space: nowrap;
}
table.data td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data th.money, table.data td.money { text-align: right; }
table.data tbody tr:hover { background: var(--wash); }

/* The drafts panel: pending invoices waiting on a person, which live on the
   Decisions screen with the rest of the waiting queue. Padding is trimmed on
   the table side because the table draws its own. */
.drafts {
  border-inline-start: 3px solid var(--sen);
  margin-bottom: 1.25rem;
  padding-bottom: 0.35rem;
}
.drafts > h2 { margin-bottom: 0.15rem; }
.drafts > .eyebrow { text-transform: none; letter-spacing: normal; margin-bottom: 0.75rem; }
.drafts .table-wrap { margin-inline: -1.25rem; }
.drafts table.data td.actions { text-align: right; white-space: nowrap; }
table.data a { text-decoration: none; }
table.data a:hover { text-decoration: underline; }

table.totals { margin-inline-start: auto; font-size: 0.95rem; border-collapse: collapse; }
table.totals td { padding: 0.28rem 0 0.28rem 2rem; }
table.totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 680; padding-top: 0.5rem; }
table.totals tr.due td { color: var(--sen); font-weight: 620; }

/* Assumed by 40-odd templates and defined by none of them until now, so
   "muted small" has been rendering as ordinary body text everywhere. */
.muted { color: var(--ink-soft); }
.small { font-size: 0.85em; }

/* The income sheet's books, and its totals block. A section title is a
   heading inside the body, so it borrows the header's own treatment; a
   subtotal rules off the rows above it the way the sheet does. */
table.data tr.section th {
  background: var(--wash);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  padding: 0.55rem 0.6rem;
}
table.data tr.subtotal td { font-weight: 620; border-top: 1px solid var(--ink); }
/* A row waiting on a person -- money to match, a hold to decide, a remark
   nobody has answered -- is washed pale yellow, and its buttons sit in the
   last column so the eye finds them in one place. */
table.data tr.needs-action td { background: var(--flag-soft); }
table.data td.action { white-space: nowrap; text-align: right; }
table.data td.action .btn + .btn, table.data td.action form + .btn { margin-inline-start: 0.3rem; }
table.data tfoot tr.grand td { border-top: 2px solid var(--ink); font-weight: 680; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
}

/* Forms ------------------------------------------------------------------- */

.stack { display: grid; gap: 0.85rem; }
/* align-content matters: grid rows stretch by default, so in a field-row
   where one field carries help text, its shorter neighbours would stretch
   their label/control rows and every input would sit at a different height. */
.field { display: grid; gap: 0.25rem; align-content: start; }
.field > label, .field-head > label, .stack > label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 550; }
/* A label with an action beside it -- "Invoice   + Create new invoice" -- on
   the label's own baseline, so the pair reads as one heading for the field. */
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.field .help { font-size: 0.78rem; color: var(--ink-soft); }
.field .error { font-size: 0.8rem; color: var(--sen); }

.field-row { display: grid; gap: 0.85rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }

input, select, textarea {
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  width: 100%;
}
input[type="number"], input.money-input { font-family: var(--mono); text-align: right; }
textarea { min-height: 4.5rem; resize: vertical; }

/* A tick box is not a text box: the blanket width above stretched it across
   the column, which is what made every checkbox on a form sit oddly wide of
   its own label. */
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; }

/* A tick and the sentence it governs, on one line and vertically centred.
   Sits inside a `.field` so it lines up with the labelled controls around it,
   and so its help text lands under it like any other field's. */
.check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 400; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--ledger);
  outline-offset: 2px;
}

/* Tom Select pickers, restyled to sit beside the native controls. */
.ts-wrapper .ts-control {
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}
.ts-wrapper.focus .ts-control { outline: 2px solid var(--ledger); outline-offset: 2px; box-shadow: none; }
.ts-dropdown {
  font: inherit;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  /* Parented to <body> (see app.js), so it must sit above every card,
     sticky header and dialog backdrop on the page. */
  z-index: 1000;
}
.ts-dropdown .active { background: var(--wash); color: var(--ink); }
.ts-dropdown .optgroup-header { font-weight: 600; color: var(--ink-soft); }

/* The quick-create dialog on the invoice screen. */
.quick-dialog {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  padding: 1.25rem;
  width: min(26rem, 90vw);
}
.quick-dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.quick-dialog h2 { margin-top: 0; }

/* The decision dialog on the recon sheet. Wider than the quick-create one
 * because it holds a list of invoices to choose between, and capped in height
 * so a customer with thirty unpaid invoices scrolls inside the dialog rather
 * than pushing the Confirm button off the screen. */
.decide {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  padding: 1.25rem;
  width: min(46rem, 92vw);
  max-height: 85vh;
}
.decide::backdrop { background: rgb(0 0 0 / 0.35); }
.decide__close { display: flex; justify-content: flex-end; margin-bottom: 0.4rem; }

/* Small enough to sit under a name in a table cell without stretching the row. */
.btn--tiny { padding: 0.15rem 0.5rem; font-size: 0.78rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 550;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--ledger);
  background: var(--ledger);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  width: auto;
}
.btn:hover { background: #0c4229; }
.btn--quiet { background: var(--card); color: var(--ink); border-color: var(--rule); }
.btn--quiet:hover { background: var(--wash); }
.btn--danger { background: var(--card); color: var(--sen); border-color: var(--sen); }
.btn--danger:hover { background: var(--sen-soft); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.link-button {
  background: none; border: none; padding: 0; width: auto;
  color: var(--ink-soft); cursor: pointer; font: inherit;
}
.link-button:hover { color: var(--ink); }

/* Filters ----------------------------------------------------------------- */

.filters { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.filters .field { gap: 0.2rem; }
.filters input, .filters select { width: auto; min-width: 9rem; }

/* Tabs are sections of a page, pills are filters within one. The two must
   not look alike: a tab is flat text over a shared baseline with the active
   one underlined in ledger green; a pill is a rounded chip that toggles. */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--rule);
  margin-bottom: 1rem;
  overflow-x: auto;
}
.tab {
  padding: 0.5rem 0.85rem;
  margin-bottom: -2px;
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ledger); }
.tab-count {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.72rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  background: var(--wash);
  color: var(--ink-soft);
  border-radius: 99px;
  padding: 0.05rem 0.45rem;
}
.tab[aria-selected="true"] .tab-count { background: var(--ledger-soft); color: var(--ledger); }

/* A badge is a queue, not a word. `.tab-count` above sits inside a heading and
   stays quiet; this one has to read across the header as work waiting, so it
   is a filled disc set apart from the label rather than a number trailing it
   -- otherwise "Decisions 16" scans as the name of the page.
   Amber because these are things to settle, which is what amber means here. */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.3rem;
  height: 1.3rem;
  /* min-width == height, so one digit is a circle and more grow into a pill
     rather than squashing. */
  padding: 0 0.35rem;
  margin-inline-start: 0.4rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  vertical-align: middle;
  background: var(--wash);
  color: var(--ink-soft);
}
.badge--alert { background: var(--sen); color: #fff; }

.pills { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.pill {
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 99px;
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: none;
  width: auto;
}
.pill[aria-pressed="true"] { background: var(--ledger); border-color: var(--ledger); color: #fff; }

/* Messages and notices ---------------------------------------------------- */

.messages { list-style: none; margin: 0 auto; padding: 0.75rem 1.5rem 0; max-width: var(--page); display: grid; gap: 0.4rem; }
.message { padding: 0.5rem 0.75rem; border-radius: var(--radius); background: var(--ledger-soft); }
.message--error { background: var(--sen-soft); color: var(--sen); }

.notice {
  border: 1px solid var(--rule);
  border-inline-start: 3px solid var(--ink-soft);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  font-size: 0.88rem;
  background: var(--card);
}
.notice--warn { border-inline-start-color: var(--sen); background: var(--sen-soft); }
.notice--credit { border-inline-start-color: var(--ledger); background: var(--ledger-soft); }

/* Definition lists -------------------------------------------------------- */

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1.25rem; margin: 0; font-size: 0.92rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; }

.auth { max-width: 21rem; margin: 5rem auto; }
.auth h1 { margin-bottom: 0.35rem; }
.auth .eyebrow { margin-bottom: 1.5rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.htmx-request { opacity: 0.55; transition: opacity 120ms ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media print {
  .app-header, .actions, .filters, .messages { display: none !important; }
  body { background: #fff; }
}
