/* 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;
  --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;
}

* { 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: 70rem; 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; }

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); }
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; }

.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; }
.field { display: grid; gap: 0.25rem; }
.field > label, .stack > label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 550; }
.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; }

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

.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; }

.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: 70rem; 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; }
}
