/* Dubai Ledger — the SCAL design language (design/oms-design-language.md) in plain CSS.
 *
 * No build step and no framework: the Tailwind class names the language is written in are
 * resolved here to their px/hex values once, as custom properties, and used by hand below.
 * Light only — there is no dark mode and no toggle (§2.1).
 *
 * The one axis that varies per app is the primary colour (§6.1); --primary keeps the ledger's
 * own blue. Everything else — slate neutrals, the type scale, table density, and colour earned
 * by state only — is the shared language and should not drift.
 */

:root {
  /* Neutrals: slate, never gray (§2.3) */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* State colours, one meaning each (§2.3): red = act now, amber = attention,
     emerald = done, blue = informational, slate = nothing notable. */
  --red-50: #fef2f2;
  --red-200: #fecaca;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;
  --amber-50: #fffbeb;
  --amber-200: #fde68a;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --emerald-50: #ecfdf5;
  --emerald-200: #a7f3d0;
  --emerald-700: #047857;
  --blue-50: #eff6ff;
  --blue-200: #bfdbfe;
  --blue-700: #1d4ed8;
  --violet-50: #f5f3ff;
  --violet-700: #6d28d9;

  /* The per-app exception (§6.1): dubai-ledger's own primary, kept from the first build. */
  --primary: #0b5fff;
  --primary-hover: #0a4fd6;
  --primary-ring: rgba(11, 95, 255, 0.35);

  /* Radii (§2.2): controls 8px, cards 12px, pills full, inline chips 4px. */
  --r-control: 8px;
  --r-card: 12px;
  --r-chip: 4px;

  --line: var(--slate-200);
  --row-line: var(--slate-100);

  --sans: "Sora", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* A list page caps at max-w-6xl; the ledger is a true wide matrix (§2.2, §5.5). */
  --page-max: 1152px;
  --page-max-wide: 1800px;
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 20px;
  color: var(--slate-900);
  background: var(--slate-50);
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Every control gets a visible focus ring; never a bare outline:none (§6.6). */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-radius: var(--r-chip);
}

/* ---------------------------------------------------------------- app bar */

/* Three destinations, so a top tab bar rather than the OMS sidebar (APP-UI §3.3).
   It stays on screen: this is a working screen, and the operator switches often. Short,
   so the ledger's table gets the height. */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 40px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.appbar .brand {
  font-size: 14px;
  font-weight: 600;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

.appbar nav {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
}

.appbar nav a {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--slate-500);
  border-bottom: 2px solid transparent;
  text-decoration: none;
}
.appbar nav a:hover {
  color: var(--slate-800);
  text-decoration: none;
}
/* The active tab is the one place besides the primary button that earns the primary colour. */
.appbar nav a[aria-current="page"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.appbar .spacer {
  flex: 1;
}
.appbar .operator {
  font-size: 12px;
  color: var(--slate-500);
}
.appbar .role-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--slate-500);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: 1px 6px;
}

/* A viewer reads everything and changes nothing: the server refuses every write
   (app/web/auth.py), and the write controls say so before they are pressed. Sign out
   is the one form a viewer posts. */
body.role-viewer main :is(button, input, select, textarea)[hx-post],
body.role-viewer main form[method="post"] :is(button, input, select, textarea),
body.role-viewer main form[hx-post] :is(button, input, select, textarea) {
  pointer-events: none;
  opacity: 0.45;
}

/* ------------------------------------------------------------- page shell */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.page-wide {
  max-width: var(--page-max-wide);
}
/* The ledger and tracking take the whole window: their tables are wider than any cap.
   Narrower than they fit, they scroll sideways inside their card, never the page. */
.page-full {
  max-width: none;
}
@media (min-width: 1024px) {
  .page.page-full {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Whitespace between groups, borders inside them (APP-UI §4). */
.stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (min-width: 1024px) {
  .page {
    padding: 32px;
  }
}

/* Title, one explanatory sentence, actions on the right with the primary last (§3.2). */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 18px;
  line-height: 28px;
  font-weight: 600;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

/* Not decoration: every page explains itself in one sentence under the title (§3.2). */
.page-sub {
  margin: 2px 0 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--slate-500);
}

/* -------------------------------------------------------------------- card */

/* A card is a border on white, never elevation (§2.2). */
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
}

.card-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  line-height: 16px;
}

.card-caption .caption-title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-600);
}

.card-caption .caption-note {
  color: var(--slate-400);
}

/* Row count, load context, the colour legend and the "show the rest" link of a table
   capped at 100 rows (§3.1) all live in the footer bar (§5.1.5). */
.card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 16px;
  color: var(--slate-500);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.legend .legend-amber {
  color: var(--amber-600);
}
.legend .legend-red {
  color: var(--red-600);
}
.legend .legend-emerald {
  color: var(--emerald-700);
}
.legend .legend-blue {
  color: var(--blue-700);
}

/* Caveats go at the bottom, findable and out of the way (§5.1.6). */
.footnote {
  margin: 0;
  font-size: 11px;
  line-height: 16px;
  color: var(--slate-400);
}

/* ------------------------------------------------------------------ tables */

/* Cap the body so the sticky total row stays on screen (§5.5.7). */
.scroll {
  overflow: auto;
  max-height: 60vh;
}

table.ledger {
  border-collapse: collapse;
  width: 100%;
  min-width: 1280px;
  font-size: 12px;
  line-height: 16px;
}

/* Horizontal padding always outruns vertical: rows stay tight, columns stay
   gutter'd so the eye tracks along one line (§2.2). */
table.ledger th,
table.ledger td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--row-line);
  text-align: left;
  white-space: nowrap;
}

/* Column headers: 12px, medium, uppercase, slate-500, sticky with an opaque fill (§3.1). */
table.ledger thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 12px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
}

table.ledger tbody td {
  height: 36px;
  padding: 7px 12px;
  color: var(--slate-600);
  vertical-align: middle;
}

/* Tracking is thirteen fixed columns, not the ledger's operator-configured matrix, and it
   fits an ordinary 1280 laptop window without scrolling sideways (pinned by
   tests/web/test_tracking_browser.py). Nothing is hidden and nothing a reader scans down
   wraps - a date, a weight, a tracking number, a count, an amount holds one line - so the
   room comes from the free text (the two places, the invoice list) and the headers
   wrapping, a timestamp putting its time under its date, and tighter gutters. A narrower
   window scrolls inside the card, as before; it is never cut. */
table.ledger.tracking-table {
  min-width: 0;
}
table.ledger.tracking-table th,
table.ledger.tracking-table td {
  padding-left: 8px;
  padding-right: 8px;
  white-space: normal;
}
table.ledger.tracking-table thead th {
  padding: 8px;
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.03em;
  vertical-align: bottom;
}
table.ledger.tracking-table td.num,
table.ledger.tracking-table td[data-col="ship_date"],
table.ledger.tracking-table td[data-col="delivered_date"],
table.ledger.tracking-table td[data-col="tracking_number"] {
  white-space: nowrap;
}
/* Free text wraps, but never down to a word a line; a place with no spaces breaks
   where it must. */
table.ledger.tracking-table td[data-col="last_scan_location"],
table.ledger.tracking-table td[data-col="last_known_location"] {
  min-width: 104px;
  overflow-wrap: anywhere;
}
/* The invoice list breaks after a comma, never inside a number. */
table.ledger.tracking-table td[data-col="invoices"] {
  min-width: 104px;
}
/* A timestamp may put its time on the next line; the width keeps its date whole, or
   the line would break at the date's own hyphen. */
table.ledger.tracking-table td[data-col="last_scan_at"],
table.ledger.tracking-table td[data-col="checked"] {
  min-width: 88px;
}
/* The milestone is what a reader scans down, so its badge keeps one line: "Pre-transit"
   would otherwise break at its own hyphen. */

/* One primary value per row, everything else recedes (§2.2). */
table.ledger tbody td.mono {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--slate-800);
  font-weight: 500;
}

table.ledger tbody tr:hover {
  background: var(--slate-50);
}

/* A cargo parent's name is data, so its chip keeps the name's own case. Two classes,
   so it outranks the plain .chip rule further down. */
.chip.chip-cargo {
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  white-space: nowrap;
}

/* A total row is a sticky tfoot, labelled with what it totals (§3.1). */
table.ledger tfoot th {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--slate-100);
  border-top: 1px solid var(--line);
  border-bottom: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-800);
}

/* Only the grand total is pinned; the per-parent totals above it scroll with the table,
   or several sticky rows at bottom: 0 would stack over one another. */
table.ledger tfoot tr.parent-total th {
  position: static;
  font-weight: 500;
  color: var(--slate-600);
}

/* Text left, numbers right, always tabular (§3.1). */
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.editable {
  min-width: 150px;
}

/* The ledger's own matrix fits the window instead of scrolling sideways: at 1536 wide (a
   1920 laptop screen at 125%), with every column the seeded layout shows
   (scripts/seed_column_config.py); a narrower window, or more columns, scrolls the rest. Nothing is hidden and nothing an operator
   scans down wraps - dates, amounts and identifiers hold one line - so the room comes
   from the free text (a customer's name, where a scan was, the actions' notes) and the
   headers wrapping, and from tighter gutters. A layout wider still than the window
   scrolls inside its card, as before; it is never cut. */
table.ledger.ledger-lines {
  min-width: 0;
}
table.ledger.ledger-lines th,
table.ledger.ledger-lines td {
  padding-left: 2px;
  padding-right: 2px;
  white-space: normal;
}
table.ledger.ledger-lines thead th {
  padding: 8px 3px;
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.03em;
  vertical-align: bottom;
}
table.ledger.ledger-lines td.num,
table.ledger.ledger-lines td.mono,
table.ledger.ledger-lines td[data-col="invoice_date"],
table.ledger.ledger-lines td[data-col="due_date"],
table.ledger.ledger-lines td[data-col="delivered_date"],
table.ledger.ledger-lines td[data-col="paid_date"] {
  white-space: nowrap;
}
/* Free text wraps, but never down to a word a line. */
table.ledger.ledger-lines td[data-col="customer_display"],
table.ledger.ledger-lines td[data-col="customer_fqn"],
table.ledger.ledger-lines td[data-col="last_scan"] {
  min-width: 64px;
  overflow-wrap: anywhere;
}
table.ledger.ledger-lines td[data-col="last_checked"] {
  min-width: 80px;
}
/* Pieces (views.pieces_text) is words a count takes two lines for ("3/4 / Delivered")
   rather than widen its column, in the badges' size. */
table.ledger.ledger-lines td[data-col="pieces"] {
  font-size: 10px;
  line-height: 12px;
}
/* A status word may take two lines ("Out for / delivery") rather than widen its column. */
table.ledger.ledger-lines .chip.chip-cargo,
table.ledger.ledger-lines .badge {
  white-space: normal;
}
/* Tighter than the page's badge, so the longest status word ("Collections") and a FedEx
   number's tag leave the Delivered / ETA and Date paid columns their room. */
table.ledger.ledger-lines .badge {
  padding: 2px 5px;
  letter-spacing: 0.01em;
}
table.ledger.ledger-lines td.editable {
  min-width: 64px;
}
/* The carrier beside a tracking number (partials/ledger_row.html): a tag in that cell,
   in the carrier's own spelling and the page's sans, not a column of its own. */
table.ledger.ledger-lines .chip.chip-carrier {
  margin-left: 2px;
  padding: 0 4px;
  font-family: var(--sans);
  text-transform: none;
  letter-spacing: 0;
}
/* A timestamp may put its time on the next line; the width keeps its date whole, or
   the line would break at the date's own hyphen. */
table.ledger.ledger-lines td[data-col="balance_as_of"],
table.ledger.ledger-lines td[data-col="marked_paid_at"],
table.ledger.ledger-lines td[data-col="archived_at"] {
  min-width: 88px;
}
/* The row's buttons and their notes stack in the cell rather than stretch it; a name
   with no spaces (an operator's address) breaks where it must. */
/* Just wide enough that Mark paid and Archive, the usual pair, sit side by side on one
   line - narrower than the stacked buttons' column was - so the room goes to the free
   text; a longer pair or a note wraps inside it. */
table.ledger.ledger-lines td.actions {
  white-space: normal;
  overflow-wrap: anywhere;
  width: 136px;
  min-width: 136px;
}
table.ledger.ledger-lines td.actions [data-archive-warning] {
  max-width: 280px;
}
table.ledger.ledger-lines tbody tr.group-head th {
  white-space: nowrap;
}
/* A date in Delivered / ETA holds one line; its words ("Not picked up yet", "Held
   (exception)") wrap rather than widen the column. */
table.ledger.ledger-lines td[data-col="delivered_date"] .muted {
  white-space: normal;
}
/* The ledger's caption keeps Columns and Copy lines on its title row at any width the
   page fits: the note between them wraps instead. */
@media (min-width: 1024px) {
  #ledger-table .card-caption {
    flex-wrap: nowrap;
  }
}
#ledger-table .card-caption .caption-title,
#ledger-table .card-caption .copy-control {
  flex: none;
}
#ledger-table .card-caption .caption-note {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
}
/* Delivered / ETA (views.delivered_or_eta): a delivered date is the plain date in the
   row's own upright text, an estimate "ETA <date>" muted and italic. "ETA <date>" holds
   one line; our estimate's "(est.)" may take a second line rather than widen the
   column. A date never breaks. */
table.ledger.ledger-lines .eta {
  font-style: italic;
  color: var(--slate-500);
}
table.ledger.ledger-lines td[data-col="delivered_date"] .eta {
  white-space: normal;
}
table.ledger.ledger-lines .eta .eta-date {
  white-space: nowrap;
}
/* The carrier's own ETA, set apart from ours by the dotted underline its hover explains
   ("Estimated by FedEx"); ours says "(est.)". */
table.ledger.ledger-lines .carrier-eta {
  text-decoration: underline dotted var(--slate-400);
  text-underline-offset: 3px;
}
/* The tracking number is the carrier's own tracking page, in a new tab. */
table.ledger.ledger-lines a.track-link {
  color: var(--primary);
  text-decoration: none;
}
table.ledger.ledger-lines a.track-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}
/* A group heading's open total (views.group_rows). */
table.ledger.ledger-lines tr.group-head .group-open {
  font-weight: 500;
  color: var(--slate-700);
}
/* Both header rows stay pinned together: the labels that sort and the filters under
   them (app/static/ledger.js). */
table.ledger.ledger-lines thead {
  position: sticky;
  top: 0;
  z-index: 10;
}
table.ledger.ledger-lines thead th {
  position: static;
}
/* A header is a button that sorts; it reads as the header it always was, with an
   arrow once it orders the rows. */
table.ledger.ledger-lines button.th-sort {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
table.ledger.ledger-lines button.th-sort:hover {
  color: var(--slate-800);
}
table.ledger.ledger-lines th[aria-sort] button.th-sort {
  color: var(--primary);
}
table.ledger.ledger-lines th[aria-sort="ascending"] button.th-sort::after {
  content: " \25B2";
  font-size: 8px;
}
table.ledger.ledger-lines th[aria-sort="descending"] button.th-sort::after {
  content: " \25BC";
  font-size: 8px;
}
/* The filter row: its controls take the column's width and never widen it. */
table.ledger.ledger-lines tr.filter-row td {
  padding: 3px 5px 5px;
  height: auto;
  background: var(--slate-50);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.ledger.ledger-lines tr.filter-row input,
table.ledger.ledger-lines tr.filter-row select {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: 22px;
  padding: 1px 4px;
  font-size: 11px;
}
table.ledger.ledger-lines tr.filter-row .filter-range {
  display: flex;
  gap: 2px;
}
table.ledger.ledger-lines tr.filter-row .filter-range input {
  flex: 1 1 0;
}
/* Columns: this browser's show/hide (app/static/ledger.js), a small panel under its
   button. */
.columns-menu {
  position: relative;
  display: inline-block;
}
.columns-menu > summary {
  list-style: none;
  cursor: pointer;
}
.columns-menu > summary::-webkit-details-marker {
  display: none;
}
.columns-menu .columns-panel {
  position: absolute;
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  margin-top: 4px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--slate-700);
}
.columns-menu .columns-panel label {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.columns-menu .columns-panel button {
  align-self: flex-start;
  margin-top: 4px;
}
/* Full screen in height too: scrolled to, the table fills the window under the app bar,
   its header and total row still pinned. */
.page-full .scroll {
  max-height: calc(100vh - 150px);
}

/* The columns form is a page-shaped table, not the wide ledger matrix. */
table.ledger.columns-table {
  min-width: 720px;
}
table.ledger.columns-table td {
  padding: 6px 12px;
}
td.actions {
  white-space: nowrap;
  text-align: right;
}

/* Empty state inside a table: roomy, quiet, and it says which kind of empty (§3.7). */
table.ledger tbody td.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--slate-400);
  white-space: normal;
}

/* An invoice dated today, on the emails list: a quiet tint and a bar on the row's first
   cell, so today's rows are found without reading every date. Set on the cells, so it
   holds under the row hover. */
table.ledger tbody tr.today td {
  background: var(--blue-50);
}
table.ledger tbody tr.today td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
  color: var(--slate-800);
  font-weight: 500;
}

/* A grouped ledger's shipment heading: its tracking number and how many lines. Not a
   total row, so it is quiet and scrolls with the lines. */
table.ledger tbody tr.group-head th {
  padding: 8px 12px;
  background: var(--slate-50);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-800);
}
table.ledger tbody tr.group-head th > * + * {
  margin-left: 12px;
}
table.ledger tbody tr.group-head .mono {
  font-family: var(--mono);
  font-size: 11px;
}
table.ledger tbody tr.group-head:hover {
  background: none;
}
/* A group's two Copy buttons, side by side in its heading. */
.copy-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.copy-control .copy-status {
  margin-left: 4px;
  font-weight: 400;
  color: var(--slate-500);
}
.copy-control .copy-status:empty {
  display: none;
}

table.ledger tbody tr.status-removed td,
table.ledger tbody tr.status-voided td {
  color: var(--slate-400);
}
table.ledger tbody tr.status-archived td {
  color: var(--slate-400);
}
/* A delivered line still owing more than three days after its delivery
   (views.delivered_unpaid_late): amber, attention, as a quiet tint on its cells, so it
   holds under the row hover. The text keeps its own colours. */
table.ledger tbody tr.delivered-unpaid-late td {
  background: var(--amber-50);
}

/* ------------------------------------------------------------------ badges */

/* One shape, one badge per row: pill, 11px, uppercase, a 50-level tint with
   700-level text from the same family (§3.3). */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--slate-100);
  color: var(--slate-600);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* Done, confirmed, matched. */
.badge-paid,
.badge-delivered,
.badge-file-present {
  background: var(--emerald-50);
  color: var(--emerald-700);
}

/* Attention, not failure: waiting on someone else. A file nobody could say
   about (unknown) is here, never red: red says it is missing. */
.badge-freight_delivered,
.badge-file-unknown {
  background: var(--amber-50);
  color: var(--amber-700);
}

/* Something is wrong and a human must act: overdue or a carrier exception. */
.badge-exception,
.badge-returned,
.badge-collections,
.badge-file-missing {
  background: var(--red-50);
  color: var(--red-700);
}

/* Moving normally, nothing to do. */
.badge-in_transit,
.badge-shipped,
.badge-out_for_delivery {
  background: var(--blue-50);
  color: var(--blue-700);
}

/* Not yet real. */
.badge-pre_transit {
  background: var(--violet-50);
  color: var(--violet-700);
}

.badge-archived,
.badge-unknown,
.badge-not_scanned,
.badge-invoiced {
  background: var(--slate-100);
  color: var(--slate-500);
}

.badge-removed,
.badge-voided {
  background: var(--slate-100);
  color: var(--slate-500);
  text-decoration: line-through;
}

/* A tracking email's two files, side by side (partials/attachments.html). */
.attachment-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* The emails list's two files, one above the other in one cell. */
.ready-files {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

/* Why a file on the emails list reads as it does, beneath its badge. */
.attachment-why {
  margin-top: 2px;
  max-width: 44ch;
  white-space: normal;
  color: var(--slate-600);
  font-size: 11px;
  line-height: 14px;
}

/* A category is a grey chip; colour stays for state (§6.3). */
.chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--r-chip);
  background: var(--slate-100);
  color: var(--slate-600);
  font-size: 10px;
  line-height: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ----------------------------------------------------------------- buttons */

/* Secondary: everything that is not the one action the page exists for (§3.4). */
button {
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: #fff;
  color: var(--slate-600);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
button:hover {
  background: var(--slate-50);
  color: var(--slate-800);
}

/* Primary: one per view. */
button.primary {
  padding: 8px 16px;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
}
button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

button[disabled],
button[disabled]:hover {
  opacity: 0.5;
  cursor: default;
  background: var(--primary);
  color: #fff;
}
button:not(.primary)[disabled],
button:not(.primary)[disabled]:hover {
  background: #fff;
  color: var(--slate-600);
}

/* Quiet / text button (§3.4). */
button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--slate-500);
  font-size: 12px;
}
button.link:hover {
  background: none;
  color: var(--slate-800);
  text-decoration: underline;
}

.inline {
  display: inline;
}

/* Compact: every action on /ledger and /tracking - the row's, the toolbar's, a group's
   Copy, and a link that does what a button does (a.btn) - is a small bordered button,
   outlined, with the view's one primary filled (§3.4). Smaller than the default button
   in both directions, so a row holding two sits on one line of its own height. The
   border is slate-300, a shade darker than a card's, so an outlined button reads as a
   control against white and not as text. */
a.btn,
summary.btn,
button.btn-sm,
td.actions button {
  display: inline-flex;
  align-items: center;
  padding: 2px 5px;
  border: 1px solid var(--slate-300);
  border-radius: 6px;
  background: #fff;
  color: var(--slate-700);
  font-family: var(--sans);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
a.btn:hover,
summary.btn:hover,
button.btn-sm:hover,
td.actions button:hover {
  border-color: var(--slate-400);
  background: var(--slate-50);
  color: var(--slate-900);
  text-decoration: none;
}
button.btn-sm.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  padding: 3px 8px;
}
button.btn-sm.primary:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
  color: #fff;
}
button.btn-sm:not(.primary)[disabled],
button.btn-sm:not(.primary)[disabled]:hover {
  border-color: var(--slate-300);
  background: #fff;
  color: var(--slate-600);
}
/* One of a set that is on: the grouping the page is in, a filter that is applied. */
a.btn[aria-current] {
  border-color: var(--primary);
  background: var(--blue-50);
  color: var(--primary);
}

/* A row's actions sit side by side, right-aligned, and wrap only when they must; a
   note (who paid it, the archive record) is a quiet item among them. */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 2px 3px;
}
.row-actions > [data-archive-warning] {
  flex-basis: 100%;
}

/* Archive's confirmation: the sentence wraps above its two buttons instead of widening
   the row, and reads as a warning, not an error (partials/ledger_row.html). */
td.actions [data-archive-warning] {
  display: block;
  max-width: 360px;
  margin: 0 0 2px auto;
  color: var(--amber-700);
  white-space: normal;
  text-align: left;
}
td.actions [data-archive-record],
td.actions [data-undo-hint] {
  font-size: 11px;
}

/* ------------------------------------------------------------------ inputs */

input[type="text"],
input[type="password"],
input[type="number"] {
  font-family: inherit;
  font-size: 12px;
  line-height: 16px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: #fff;
  color: var(--slate-800);
  width: 100%;
}
input[type="text"]:hover,
input[type="password"]:hover,
input[type="number"]:hover {
  border-color: var(--slate-300);
}
input[type="text"]:focus-visible,
input[type="password"]:focus-visible,
input[type="number"]:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
  border-radius: var(--r-control);
}

input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

input.pos {
  width: 76px;
}

/* --------------------------------------------------------------- toolbars */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

/* The ledger's grouping sits in its one toolbar line (partials/ledger_toolbar.html). */
.toolbar .view-switch {
  gap: 4px 8px;
}
/* The ledger's toolbar buttons are a size up from the table's (partials/ledger_toolbar.html). */
#ledger-toolbar a.btn,
#ledger-toolbar button.btn-sm {
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 18px;
}
#ledger-toolbar button.btn-sm.primary {
  padding: 5px 12px;
}
/* Group: one joined control, the grouping the page is in filled. */
.view-switch .seg {
  display: inline-flex;
  border: 1px solid var(--slate-300);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.view-switch .seg a {
  padding: 5px 12px;
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  color: var(--slate-700);
  text-decoration: none;
  white-space: nowrap;
}
.view-switch .seg a + a {
  border-left: 1px solid var(--slate-300);
}
.view-switch .seg a:hover {
  background: var(--slate-50);
  color: var(--slate-900);
}
.view-switch .seg a[aria-current="page"] {
  background: var(--slate-900);
  color: #fff;
  font-weight: 500;
}

/* The grouping links, and the ledger's two totals at the row's end. */
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-top: 12px;
}

/* Flat or by tracking number: plain links, the current one marked. */
.view-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 13px;
}
.view-switch a[aria-current="page"] {
  color: var(--slate-900);
  font-weight: 600;
}
.view-switch .toolbar-note {
  font-size: 12px;
  color: var(--slate-400);
}

.toolbar .toolbar-note {
  font-size: 12px;
  color: var(--slate-400);
}

/* The ledger's two totals, one line at the end of the grouping row
   (partials/ledger_totals.html): each a link that is its filter, the one that is on
   marked. */
.ledger-totals {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin-left: auto;
  font-size: 13px;
}
.ledger-totals-sep {
  color: var(--slate-400);
}
a.total-filter {
  color: var(--slate-500);
  text-decoration: none;
}
a.total-filter .total-value {
  font-weight: 600;
  color: var(--slate-900);
  font-variant-numeric: tabular-nums;
}
a.total-filter:hover .total-value {
  text-decoration: underline;
}
a.total-filter.total-active,
a.total-filter.total-active .total-value {
  color: var(--primary);
}

/* The manual tracking refresh: its label says what it is doing while htmx waits
   (htmx puts `htmx-request` on the form it is sending). */
.refresh-form .refresh-busy,
.refresh-form.htmx-request .refresh-idle {
  display: none;
}
.refresh-form.htmx-request .refresh-busy {
  display: inline;
}
.refresh-summary {
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  font-size: 12px;
  line-height: 18px;
}
.refresh-summary p {
  margin: 0;
}
.refresh-summary .refresh-problem {
  color: var(--red-800);
}
.refresh-detail {
  margin-top: 6px;
}
.refresh-detail p {
  margin: 4px 0;
}
.refresh-reason {
  display: block;
  color: var(--slate-500);
}
.refresh-detail summary {
  cursor: pointer;
  color: var(--slate-600);
}
.refresh-results td {
  padding: 2px 12px 2px 0;
  vertical-align: top;
}

/* ------------------------------------------------------------------ states */

/* Errors are inline, above the content, and announced (§3.7, §6.7). */
.error {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--red-200);
  border-radius: var(--r-control);
  background: var(--red-50);
  color: var(--red-800);
  font-size: 12px;
  line-height: 16px;
}

.flash {
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 1px solid var(--emerald-200);
  border-radius: var(--r-control);
  background: var(--emerald-50);
  color: var(--emerald-700);
  font-size: 12px;
  line-height: 16px;
}

/* A conflict tints the container, not the sentence (§2.3 gate 3). */
tr.conflict td {
  background: var(--red-50);
  white-space: normal;
}
.error-inline {
  color: var(--slate-900);
  font-weight: 500;
}

/* A judgement about one row is a bare coloured word next to the action it asks for,
   not a second pill — one badge per row is the rule (§3.3). */
.hint {
  margin-right: 8px;
  color: var(--amber-700);
  font-size: 11px;
  font-weight: 500;
}

.muted {
  color: var(--slate-400);
}
.mono {
  font-family: var(--mono);
}

/* ------------------------------------------------------------------- login */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 24px;
}

.login h1 {
  margin: 0;
  font-size: 18px;
  line-height: 28px;
  font-weight: 600;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

.login .page-sub {
  margin: 4px 0 20px;
}

.login label {
  display: block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-500);
}

.login .field + .field {
  margin-top: 14px;
}

.login input[type="text"],
.login input[type="password"] {
  font-size: 14px;
  padding: 8px 10px;
}

.login button,
.login .login-google {
  width: 100%;
  margin-top: 20px;
  justify-content: center;
}

.login .error {
  margin-bottom: 16px;
}

.login-foot {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 16px;
  color: var(--slate-400);
}

/* ---------------------------------------------------------- tracking email */

.compose {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.compose label {
  display: block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-500);
}

.compose textarea {
  font-family: inherit;
  font-size: 12px;
  line-height: 18px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: #fff;
  color: var(--slate-800);
  width: 100%;
  resize: vertical;
}

.compose textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.compose input[type="tel"] {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  width: 100%;
  max-width: 280px;
}

/* One role on the card: where its addresses come from, and nothing else. */
.compose .role {
  margin: 0;
  padding: 0;
  border: 0;
}
.compose .role legend {
  margin: 0 0 6px;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-500);
}
.compose .role-note {
  margin: 0 0 6px;
  font-size: 12px;
  line-height: 18px;
  color: var(--slate-500);
}
.compose .check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--slate-800);
}
.compose .actions {
  display: flex;
  gap: 8px;
}

.email-subject {
  margin: 0;
  padding: 12px 16px 0;
  font-weight: 600;
  color: var(--slate-900);
}

.email-body {
  margin: 0;
  padding: 12px 16px 16px;
  font-family: inherit;
  font-size: 13px;
  line-height: 20px;
  white-space: pre-wrap;
  color: var(--slate-800);
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0;
  padding: 12px 16px 16px;
  font-size: 13px;
}

.facts dt {
  color: var(--slate-500);
}

.facts dd {
  margin: 0;
  color: var(--slate-800);
}

/* ---------------------------------------------------- tracking typed by hand */

/* The number itself, large enough to read digit by digit against the carrier's
   paperwork before it is emailed: a mistyped one is a stranger's parcel. */
.typed-number {
  margin: 0;
  padding: 16px 16px 4px;
  font-size: 24px;
  line-height: 32px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--slate-900);
  word-break: break-all;
}

.card-body {
  margin: 0;
  padding: 12px 16px 16px;
  font-size: 13px;
  line-height: 20px;
  color: var(--slate-700);
}

.compose input.typed-input {
  max-width: 360px;
  font-size: 14px;
  line-height: 20px;
  padding: 6px 8px;
  letter-spacing: 0.06em;
}

.compose select {
  font-family: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: #fff;
  color: var(--slate-800);
  max-width: 360px;
  width: 100%;
}

.compose .role-note + .role-note,
.compose select + .role-note {
  margin-top: 6px;
}

td a.chip {
  text-decoration: none;
}

/* Prose in a mono cell is still prose (§2.1): only the number is mono. */
td a[data-add-tracking] {
  font-family: var(--sans);
  font-size: 12px;
}

/* Attention, not done (§2.3 amber): a number a person typed, to be checked. */
.notice {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--amber-200);
  border-radius: var(--r-control);
  background: var(--amber-50);
  color: var(--amber-700);
  font-size: 12px;
  line-height: 16px;
}

/* ------------------------------------------------------ bulk tracking email */

table.bulk td {
  vertical-align: top;
  white-space: normal;
}
table.bulk .bulk-off td {
  color: var(--slate-400);
}
table.bulk .bulk-detail td {
  padding-top: 0;
  border-top: 0;
}
table.bulk .bulk-detail summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--slate-600);
}
.bulk-to,
.bulk-phone {
  font-family: inherit;
  font-size: 12px;
  line-height: 18px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  width: 100%;
  min-width: 170px;
  resize: vertical;
}
.bulk-phone {
  margin-top: 4px;
}
table.bulk td[data-col="status"] {
  min-width: 200px;
}
.bulk-sends-to {
  margin-top: 4px;
  font-size: 12px;
  color: var(--slate-800);
}
.bulk-reason {
  margin-top: 4px;
  font-size: 11px;
  line-height: 16px;
}
.bulk-sendbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.bulk-summary {
  margin: 0;
  flex: 1 1 320px;
  font-size: 12px;
}
.bulk-testbar {
  justify-content: flex-start;
}
.bulk-test-to {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--slate-800);
}
.bulk-test-to input {
  width: 240px;
}
.bulk-test-note {
  margin: 0;
  flex: 1 1 320px;
}
table.bulk td.nowrap {
  white-space: nowrap;
}
table.bulk td[data-col="attachments"] div + div {
  margin-top: 4px;
}
table.bulk td[data-col="attachments"] .mono {
  word-break: break-all;
}
.bulk-cc {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- templates */

.template-note {
  margin: 0;
  padding: 12px 16px 0;
  font-size: 12px;
  line-height: 18px;
  color: var(--slate-500);
}

.compose textarea.wording {
  font-family: var(--mono);
}

.template-errors {
  margin: 0;
  padding: 12px 16px 16px 32px;
  font-size: 13px;
  line-height: 20px;
  color: var(--slate-800);
}

.rendering + .rendering {
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------ template editor: fields */

/* The fields sit beside the two boxes, outside the text, so they are there
   whatever the boxes hold - an emptied body included. */
.wording-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 860px) {
  .wording-editor {
    grid-template-columns: minmax(0, 1fr);
  }
}
.wording-boxes {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field-list {
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: 12px;
  background: var(--slate-50);
}
.field-list .field-list-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-500);
}
.field-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field-list li[data-absent] {
  padding-left: 8px;
  border-left: 2px solid var(--amber-200);
}
.field-list .field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}
.field-list button.field-token,
.field-list button.field-guard {
  padding: 3px 8px;
  font-size: 11px;
  color: var(--primary);
  text-align: left;
  word-break: break-all;
}
.field-list button.field-guard {
  margin: 2px 0;
}
.field-list .field-label {
  font-size: 12px;
  color: var(--slate-800);
}
.field-list .field-example,
.field-list .field-absent {
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 16px;
  color: var(--slate-500);
  word-break: break-word;
}
.field-list .field-absent {
  color: var(--amber-700);
}

/* Below 1536 wide the ledger's matrix tightens instead of scrolling sideways, so every
   seeded column stays whole down to a 1200 window (pinned by
   tests/web/test_ledger_copy_browser.py): smaller body text and gutters, the row's
   buttons stacked, and a tracking number's carrier tag and the free text allowed onto
   a second line. A date, an amount or a number still never breaks. A 1536 window and
   wider keeps the layout above. */
@media (max-width: 1535px) {
  table.ledger.ledger-lines th,
  table.ledger.ledger-lines td {
    padding-left: 1.5px;
    padding-right: 1.5px;
  }
  table.ledger.ledger-lines thead th {
    padding: 6px 1.5px;
    font-size: 10px;
    letter-spacing: 0;
  }
  table.ledger.ledger-lines tbody td {
    font-size: 11px;
  }
  table.ledger.ledger-lines tbody td.mono {
    font-size: 10px;
  }
  table.ledger.ledger-lines .badge {
    padding: 1px 3px;
    font-size: 10px;
    letter-spacing: 0;
  }
  table.ledger.ledger-lines .chip.chip-cargo {
    font-size: 10px;
  }
  table.ledger.ledger-lines td[data-col="tracking_number"] {
    white-space: normal;
  }
  table.ledger.ledger-lines td[data-col="tracking_number"] a.track-link {
    white-space: nowrap;
  }
  table.ledger.ledger-lines td a[data-add-tracking] {
    white-space: normal;
  }
  table.ledger.ledger-lines td[data-col="customer_display"],
  table.ledger.ledger-lines td[data-col="customer_fqn"],
  table.ledger.ledger-lines td[data-col="last_scan"] {
    min-width: 48px;
  }
  table.ledger.ledger-lines td[data-col="last_checked"] {
    min-width: 56px;
  }
  table.ledger.ledger-lines td.editable {
    min-width: 32px;
  }
  table.ledger.ledger-lines td.actions {
    width: 72px;
    min-width: 72px;
  }
  table.ledger.ledger-lines td.actions .row-actions {
    flex-direction: column;
    align-items: flex-end;
  }
  /* the toolbar keeps its one line */
  #ledger-toolbar .toolbar {
    gap: 8px;
  }
  #ledger-toolbar a.btn,
  #ledger-toolbar button.btn-sm,
  #ledger-toolbar button.btn-sm.primary,
  .view-switch .seg a {
    padding: 4px 9px;
    font-size: 12px;
  }
  #ledger-toolbar .ledger-totals {
    font-size: 12px;
  }
  /* a long label ("Undo Mark paid") takes two lines rather than widen the column */
  table.ledger.ledger-lines td.actions button {
    white-space: normal;
    text-align: center;
  }
}

/* ------------------------------------------------------------ cargo houses */

/* /cargo-houses: one row per house, its details a row beneath it shown by its chevron
   (app/static/houses.js). Below 720px the rows become blocks, so nothing scrolls sideways. */
.houses-page {
  gap: 12px;
}
@media (min-width: 1024px) {
  .page.houses-page {
    padding-top: 16px;
  }
}
.houses-alert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.houses-alert > span {
  flex: 1;
  min-width: 200px;
}
table.houses {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 16px;
}
table.houses th {
  background: var(--slate-50);
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--slate-500);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.houses td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--row-line);
  color: var(--slate-600);
  vertical-align: middle;
}
table.houses td.nw {
  white-space: nowrap;
}
table.houses tbody tr.house:hover > td {
  background: var(--slate-50);
}
table.houses td.num,
table.houses th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.houses td.name {
  color: var(--slate-900);
  font-weight: 500;
}
table.houses td.chev {
  width: 28px;
  padding-right: 0;
}
.houses-page .chev-btn {
  border: 0;
  background: none;
  padding: 2px;
  color: var(--slate-400);
  border-radius: var(--r-chip);
}
.houses-page .chev-btn svg {
  width: 14px;
  height: 14px;
  transition: transform 0.12s;
}
.houses-page .chev-btn:hover,
.houses-page .chev-btn[aria-expanded="true"] {
  color: var(--slate-700);
  background: var(--slate-100);
}
.houses-page .chev-btn[aria-expanded="true"] svg {
  transform: rotate(90deg);
}
.qbname {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--slate-800);
  background: var(--slate-100);
  border-radius: var(--r-chip);
  padding: 1px 5px;
  white-space: pre-wrap;
}
table.houses tr.inactive td {
  color: var(--slate-400);
}
table.houses tr.inactive td.name {
  color: var(--slate-500);
  font-weight: 400;
}
.houses-page .switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--slate-700);
  white-space: nowrap;
  opacity: 0.7;
}
.houses-page .switch .track {
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: var(--slate-300);
  position: relative;
  flex: none;
}
.houses-page .switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
}
.houses-page .switch[aria-checked="true"] .track {
  background: var(--primary);
}
.houses-page .switch[aria-checked="true"] .track::after {
  left: 14px;
}
table.houses tr[hidden] {
  display: none !important;
}
table.houses tr.detail > td {
  background: #fcfdfe;
  padding: 0;
}
.houses-page .detail-inner {
  padding: 10px 12px 12px 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  align-items: flex-start;
}
.houses-page .detail-inner .facts {
  padding: 0;
  font-size: 12px;
  gap: 4px 14px;
}
.houses-page .detail-inner .error {
  flex-basis: 100%;
}
.houses-page .detail-note {
  margin: 0;
  font-size: 12px;
  max-width: 80ch;
}
table.houses .empty-row td {
  padding: 44px 16px;
  text-align: center;
  color: var(--slate-400);
  font-size: 13px;
}
@media (max-width: 719px) {
  table.houses thead {
    display: none;
  }
  table.houses,
  table.houses tbody,
  table.houses tr,
  table.houses td {
    display: block;
    width: 100%;
  }
  table.houses tr.house {
    position: relative;
    padding: 10px 14px 10px 36px;
    border-bottom: 1px solid var(--row-line);
  }
  table.houses tr.house > td {
    padding: 0;
    border: 0;
  }
  table.houses td.chev {
    position: absolute;
    left: 12px;
    top: 11px;
    width: auto;
  }
  table.houses td.name {
    font-size: 13px;
  }
  table.houses td[data-k] {
    display: inline;
    font-size: 11px;
    color: var(--slate-500);
  }
  table.houses td[data-k]::before {
    content: attr(data-k) " ";
    color: var(--slate-400);
  }
  table.houses td.sep::after {
    content: "  ·  ";
    color: var(--slate-300);
  }
  table.houses td.qb {
    margin: 3px 0;
  }
  table.houses td.nw {
    white-space: normal;
  }
  table.houses td.status {
    margin-top: 6px;
  }
  table.houses td.changed {
    margin-top: 2px;
  }
  table.houses td.acts:empty {
    display: none;
  }
  .houses-page .detail-inner {
    padding: 8px 14px 12px 36px;
  }
}
.houses-page .switch {
  border: 0;
  background: none;
  padding: 0;
}
.houses-page button.switch {
  cursor: pointer;
  opacity: 1;
}
.houses-page form.inline {
  display: inline;
}
.houses-footnote {
  margin: 0;
  font-size: 11px;
  line-height: 16px;
  color: var(--slate-400);
  max-width: 120ch;
}
.houses-dialog {
  width: calc(100% - 32px);
  max-width: 460px;
  border: 0;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}
.houses-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.houses-dialog h2 {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
}
.houses-dialog .lead {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--slate-600);
}
.houses-dialog .lbl {
  display: block;
  margin: 12px 0 4px;
  font-size: 12px;
  color: var(--slate-600);
}
.houses-dialog .txt {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
}
.houses-dialog .txt.mono {
  font-family: var(--mono);
  font-size: 12px;
}
.houses-dialog .hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--slate-500);
}
.houses-dialog .foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
/* The held invoices beside the parent picker: read-only, wrapping, scrolled down not across. */
.houses-dialog:has(table.held) {
  max-width: 680px;
}
.houses-dialog .held-wrap {
  margin-top: 12px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
}
.houses-dialog table.held {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
}
.houses-dialog table.held th,
.houses-dialog table.held td {
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  border-bottom: 1px solid var(--line);
}
.houses-dialog table.held th {
  position: sticky;
  top: 0;
  background: #fff;
  font-weight: 600;
  color: var(--slate-600);
}

/* /ledger's pieces dialog (partials/pieces_dialog.html): one row per box, every cell on one
   line, as wide and tall as the window allows; only the list scrolls, down and never across,
   under a header that stays. Too narrow for the row, each box is a card of its own cells, each
   under its column's words (`data-label`). Its opener is the Pieces cell's own words, a
   compact bordered button. */
table.ledger.ledger-lines td[data-col="pieces"] .pieces-btn {
  padding: 2px 5px;
  font-size: 10px;
  line-height: 12px;
  white-space: normal;
  text-align: left;
}
.houses-dialog.pieces-dialog {
  width: min(1100px, 90vw);
  max-width: none;
  max-height: 85vh;
  box-sizing: border-box;
}
/* A closed dialog keeps the browser's display: none. The list's box, inside the swapped-in
   body, takes what the title and Close leave. */
.houses-dialog.pieces-dialog[open],
.pieces-dialog .pieces-body {
  display: flex;
  flex-direction: column;
}
.pieces-dialog .pieces-body {
  flex: 1 1 auto;
  min-height: 0;
}
.pieces-dialog .pieces-wrap {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  container-type: inline-size;
}
.pieces-dialog table.pieces-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.pieces-dialog table.pieces-table th,
.pieces-dialog table.pieces-table td {
  padding: 6px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.pieces-dialog table.pieces-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  font-weight: 600;
  color: var(--slate-600);
}
.pieces-dialog table.pieces-table td.num {
  width: 1%;
}
.pieces-dialog .code {
  margin-left: 6px;
  font-size: 11px;
}
@container (max-width: 860px) {
  .pieces-dialog table.pieces-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .pieces-dialog table.pieces-table,
  .pieces-dialog table.pieces-table tbody {
    display: block;
  }
  .pieces-dialog table.pieces-table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 10px;
    row-gap: 2px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
  }
  .pieces-dialog table.pieces-table td {
    display: block;
    grid-column: 1 / -1;
    padding: 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .pieces-dialog table.pieces-table td.num {
    grid-column: 1;
    width: auto;
    color: var(--slate-500);
  }
  .pieces-dialog table.pieces-table td.mono {
    grid-column: 2;
    font-weight: 600;
  }
  /* Each cell under its column's words, a wrapped value kept beside them, not under them. */
  .pieces-dialog table.pieces-table td[data-label]:not(.num, .mono) {
    padding-left: 76px;
    text-indent: -76px;
  }
  .pieces-dialog table.pieces-table td[data-label]:not(.num, .mono) > * {
    text-indent: 0;
  }
  .pieces-dialog table.pieces-table td[data-label]:not(.num, .mono)::before {
    content: attr(data-label);
    display: inline-block;
    width: 70px;
    margin-right: 6px;
    text-indent: 0;
    color: var(--slate-500);
  }
  .pieces-dialog table.pieces-table td:empty {
    display: none;
  }
}

/* ------------------------------------------------------------------ access */

.access-grant-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}
.access-grant-fields label {
  font-size: 12px;
  color: var(--slate-500);
}
.access-grant-fields input[type="email"] {
  width: 280px;
}
/* A short list, not the ledger: it fits its card at any width, actions right-aligned. */
table.ledger.access-table {
  min-width: 0;
}
table.ledger.access-table td:last-child {
  width: 1%;
}
table.ledger.access-table .row-actions {
  flex-wrap: nowrap;
}
table.ledger.access-table .row-actions form.inline {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
