/* ============================================================
   House Design System — "Double-Entry" (v1.0, 2026-06-24)
   Red & black ledger ink on warm paper. Card-based, mobile-first.
   Plain CSS, no framework, no build step. Every site includes this.
   Approved direction A — see ~/docs/decisions-log.md D-007.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,700&display=swap');

/* ---- Design tokens ---------------------------------------- */
:root {
  --paper:     #FAF8F3;  /* warm near-white canvas            */
  --paper-2:   #FFFFFF;  /* raised surfaces (cards, inputs)   */
  --ink:       #1A1A18;  /* primary text, headings            */
  --ink-soft:  #6B6A63;  /* secondary text, labels            */
  --rule:      #E4DFD4;  /* hairlines, borders, ledger rules  */
  --rule-2:    #D8D2C5;  /* slightly stronger rule            */
  --red:       #A6261D;  /* ledger red ink — the one accent   */
  --red-tint:  #F4E6E3;  /* red wash for fills                */
  --green:     #2C6E49;  /* paid / positive                   */
  --amber:     #B8791B;  /* warning / due                     */

  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 1px 2px rgba(26,26,24,.05), 0 8px 24px rgba(26,26,24,.06);
  --maxw:      1040px;

  --display:   "Bricolage Grotesque", system-ui, sans-serif;
  --body:      system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:      ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, monospace;
}

/* ---- Reset / base ----------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}
h1, h2, h3 {
  font-family: var(--display);
  line-height: 1.12;
  margin: 0 0 .4em;
  font-weight: 700;
  letter-spacing: -.01em;
}
h1 { font-size: clamp(1.6rem, 1.15rem + 2.1vw, 2.3rem); }
h2 { font-size: clamp(1.2rem, 1rem + 1vw, 1.55rem); }
h3 { font-size: 1.02rem; font-weight: 600; }
p  { color: var(--ink-soft); margin: 0 0 1rem; }
a  { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code {
  font-family: var(--mono); font-size: .86em;
  background: var(--paper-2); border: 1px solid var(--rule);
  padding: 1px 6px; border-radius: 5px;
}

/* ---- Layout ----------------------------------------------- */
/* page gutter — comfortable space on the left/right edges at every width
   (min ~card padding, scales up on wider screens) */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(24px, 5vw, 44px); }
.section   { padding: clamp(20px, 4vw, 34px) 0; }
.stack > * + * { margin-top: 1.1rem; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.muted { color: var(--ink-soft); }

/* ---- Top bar ---------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar .inner { display: flex; align-items: center; gap: 16px; height: 62px; }
.brand {
  font-family: var(--display); font-weight: 700; font-size: 1.12rem;
  letter-spacing: -.02em; display: inline-flex; align-items: baseline; gap: 10px;
}
/* ledger-rule under the wordmark — the small house mark */
.brand .rule { flex: 0 0 26px; height: 0; border-top: 2px solid var(--red); align-self: center; }
.nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 7px 12px; border-radius: var(--radius-sm); color: var(--ink-soft);
  font-weight: 600; font-size: .92rem;
}
.nav a:hover { color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--red); border-radius: 0; }

/* ---- Cards (the index-card) ------------------------------- */
.card {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
/* index tab — a small folder tab clipped to the card's top edge */
.card .tab {
  position: absolute; top: -11px; left: 20px;
  font-family: var(--mono); font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--paper-2); background: var(--red);
  padding: 3px 11px 4px; border-radius: 6px 6px 0 0;
  box-shadow: 0 -1px 0 var(--red);
}
.card .tab.ink  { background: var(--ink);   }
.card .tab.gray { background: var(--ink-soft); }

.kpi { font-family: var(--mono); font-size: 2rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.card h3.muted { font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 .55rem; }

/* stat card — KPI cards in a row; uniform number size, badges bottom-aligned */
.card.stat { display: flex; flex-direction: column; }
.card.stat .kpi { font-size: 1.55rem; margin: 0 0 .7rem; }
.card.stat .badge { margin-top: auto; align-self: flex-start; }

/* ---- Status: pills + the rubber-stamp ---------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; overflow-wrap: normal;
  border: 1px solid var(--rule-2); color: var(--ink-soft); background: var(--paper);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok   { color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, var(--rule)); background: color-mix(in srgb, var(--green) 7%, var(--paper)); }
.badge.warn { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, var(--rule)); background: color-mix(in srgb, var(--amber) 8%, var(--paper)); }
.badge.bad  { color: var(--red);   border-color: color-mix(in srgb, var(--red)   35%, var(--rule)); background: var(--red-tint); }

/* the stamp — bold status marker, used ONCE on a record header */
.stamp {
  display: inline-block; transform: rotate(-3deg);
  font-family: var(--mono); font-weight: 700; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--red); border: 2px solid var(--red); border-radius: 6px;
  padding: 4px 12px; background: color-mix(in srgb, var(--red) 5%, transparent);
}
.stamp.ok { color: var(--green); border-color: var(--green); background: color-mix(in srgb, var(--green) 6%, transparent); }

/* ---- Buttons / forms -------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-2); background: var(--paper-2); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s, transform .05s;
}
.btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--paper-2); }
.btn.primary:hover { background: color-mix(in srgb, var(--red) 88%, #000); border-color: transparent; }
.btn.ghost { background: transparent; }
/* sizes & states — use these classes instead of inline padding/font overrides */
.btn { text-decoration: none; white-space: nowrap; line-height: 1.1; }
.btn.sm { padding: 5px 10px; font-size: .82rem; gap: 6px; }
.btn.icon { padding: 0; width: 36px; height: 36px; justify-content: center; gap: 0; font-size: 1.05rem; }
.btn.icon.sm { width: 30px; height: 30px; font-size: .95rem; }
.btn[disabled], .btn:disabled { opacity: .45; cursor: default; }
.btn[disabled]:active, .btn:disabled:active { transform: none; }

/* row action menu — the "⋯" kebab (pure <details>; ui.js adds close-on-outside) */
.rowmenu { position: relative; display: inline-block; }
.rowmenu > summary { list-style: none; cursor: pointer; }
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu > summary::marker { content: ''; }
.rowmenu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
  min-width: 184px; background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.rowmenu-list a, .rowmenu-list button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border: none; background: transparent; border-radius: 8px;
  font: inherit; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.rowmenu-list a:hover, .rowmenu-list button:hover { background: color-mix(in srgb, var(--red) 8%, var(--paper-2)); }
.rowmenu-list .danger { color: var(--red); }
.rowmenu-list form { margin: 0; }
.rowmenu-list hr { border: none; border-top: 1px solid var(--rule); margin: 4px 2px; }

label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-soft); margin: 0 0 6px; }
input, select, textarea {
  width: 100%; padding: 11px 13px; font: inherit; color: var(--ink);
  background: var(--paper-2); border: 1px solid var(--rule-2); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--red);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent);
}

/* ============================================================
   Responsive N×N table / master-detail
   Desktop: real table — sticky header, sticky first column,
            tabular figures, double-ruled ledger total.
   Mobile : each row reflows into a stacked label→value card
            via [data-label]. No squashing, no horizontal scroll.
   ============================================================ */
.table-wrap {
  overflow: visible; border-radius: var(--radius);
  border: 1px solid var(--rule); background: var(--paper-2);
}
/* Default: cells WRAP so the table always fits — never a horizontal scrollbar.
   Numbers stay on one line (.cell-num). A genuinely wide matrix can opt back in
   with <div class="table-wrap scroll"> + <table class="data wide">. */
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .94rem; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--rule); white-space: normal; vertical-align: top; overflow-wrap: anywhere; }
.table-wrap.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data.wide { min-width: 540px; }
table.data.wide th, table.data.wide td { white-space: nowrap; }
table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--paper); color: var(--ink-soft);
  font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  overflow-wrap: normal;
}
/* sticky first column — for wide N×N matrices */
table.data th[scope="row"], table.data td.rowhead {
  position: sticky; left: 0; z-index: 1;
  background: var(--paper-2); font-weight: 600;
}
table.data thead th:first-child { z-index: 3; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--red) 4%, var(--paper-2)); }
table.data tbody tr:hover td.rowhead { background: color-mix(in srgb, var(--red) 6%, var(--paper-2)); }
.cell-num { text-align: right; white-space: nowrap; font-family: var(--mono); font-variant-numeric: tabular-nums; }
/* ledger total — double rule above, like a hand-summed column */
table.data tfoot td { border-top: 3px double var(--ink); border-bottom: none; font-weight: 700; background: var(--paper); }

@media (max-width: 720px) {
  /* tables become stacked cards before columns get cramped (avoids mid-word breaks) */
  .table-wrap { overflow: visible; border: none; background: transparent; }
  table.data { min-width: 0; font-size: .95rem; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data, table.data tbody, table.data tfoot, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr {
    background: var(--paper-2); border: 1px solid var(--rule);
    border-radius: var(--radius); padding: 6px 14px; margin-bottom: 12px;
    box-shadow: var(--shadow);
  }
  table.data td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 1.2rem;
    padding: 7px 0; border-bottom: 1px solid var(--rule); white-space: normal;
  }
  table.data tr td:last-child { border-bottom: none; }
  table.data td::before {
    content: attr(data-label); color: var(--ink-soft);
    font-weight: 600; font-size: .8rem; text-align: left;
  }
  table.data td.rowhead { position: static; font-family: var(--display); font-size: 1.05rem; font-weight: 700; padding-bottom: 9px; }
  table.data td.rowhead::before { content: none; }
  table.data .cell-num { justify-content: space-between; }
  /* mobile total: one clean ruled line, not a broken half-width card */
  table.data tfoot tr {
    display: flex; align-items: baseline; justify-content: space-between;
    background: transparent; box-shadow: none; border: none;
    border-top: 3px double var(--ink); border-radius: 0;
    padding: 12px 2px 0; margin: 2px 0 0; gap: 1rem;
  }
  table.data tfoot td { display: block; width: auto; padding: 0; border: none; }
  table.data tfoot td.rowhead { font-family: var(--display); font-size: 1.05rem; padding: 0; }
  table.data tfoot td.rowhead::before { content: none; }
  table.data tfoot td.cell-num { white-space: nowrap; font-weight: 700; }
  table.data tfoot td.cell-num::before { content: none; }
  table.data tfoot td:empty { display: none; }
}

/* ---- Footer ----------------------------------------------- */
footer.site {
  border-top: 1px solid var(--rule); margin-top: 44px; padding: 26px 0;
  color: var(--ink-soft); font-size: .85rem;
}

/* ---- Quality floor ---------------------------------------- */
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 3px; }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media (max-width: 600px) {
  .card { padding: 18px; }
  .nav  { gap: 2px; }
}
