/* ==========================================================================
   CastleCRM design system. 3 of 5: COMPONENTS.
   Each block is shown, with its markup, on /styleguide/. Role tokens only: no hex, no stray px
   except 1px hairline offsets that are part of the rule language.
   ========================================================================== */

/* ---------- Icon ---------- */
.icon {
  width: var(--icon); height: var(--icon); flex: none; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: var(--icon-stroke); stroke-linecap: square; stroke-linejoin: miter;
}
.icon--sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon--lg { width: var(--icon-lg); height: var(--icon-lg); }

/* ---------- Buttons: square, 1.5 px ink border, verb-first labels ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--ctl-h); padding: 0 var(--sp-4); border: var(--rule-mid) solid var(--rule-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none;
  font: var(--fw-bold) var(--fs-1) / 1 var(--font); font-stretch: var(--wd-semi);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-sunk); color: var(--text); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn--secondary { /* the default look; kept as a named variant */ }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn--accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--accent:hover { background: var(--surface); border-color: var(--accent); color: var(--text); }
.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); border-color: var(--danger); color: var(--on-ink-danger); }
.btn--quiet { border-color: var(--rule); }
.btn--quiet:hover { border-color: var(--rule-strong); }
.btn--ghost, .btn--link {
  height: auto; min-height: var(--ctl-h-sm); padding: 0 var(--sp-1); border-color: transparent; background: none; color: var(--link);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px;
}
.btn--ghost:hover, .btn--link:hover { background: none; color: var(--link-hover); text-decoration-thickness: 2px; }
.btn--dashed { border-style: dashed; }
.btn--sm { height: var(--ctl-h-sm); padding: 0 var(--sp-3); font-size: var(--fs-0); gap: var(--sp-1); }
.btn--ghost.btn--sm, .btn--link.btn--sm { height: auto; padding: 0 var(--sp-1); }
.btn--icon { width: var(--ctl-h); padding: 0; }
.btn--icon.btn--sm { width: var(--ctl-h-sm); }
.btn--block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] {
  background: var(--surface-sunk); border-color: var(--rule); color: var(--text-faint); cursor: not-allowed; transform: none;
}
.btn--ghost[disabled], .btn--link[disabled] { background: none; border-color: transparent; }
/* Loading: htmx puts .htmx-request on the element that made the request */
.btn.htmx-request { cursor: progress; }
.btn.htmx-request::after {
  content: ""; position: absolute; left: -1px; right: -1px; bottom: -3px; height: 3px; background: var(--accent);
  transform-origin: left; animation: castle-load 900ms var(--ease-out) infinite;
}
@keyframes castle-load { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.page-actions, .btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.page-actions form, .btn-row form, .row-actions form { margin: 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; margin-bottom: var(--sp-4); }
.field__label { font: var(--fw-bold) var(--fs-0) / var(--lh-snug) var(--font); font-stretch: var(--wd-narrow); color: var(--text-muted); }
.field__help { margin: 0; font-size: var(--fs-0); color: var(--text-muted); max-width: 60ch; }
.field__error, .errorlist {
  display: flex; gap: var(--sp-1); align-items: flex-start; margin: 0; padding: 0; list-style: none;
  font-size: var(--fs-0); font-weight: var(--fw-bold); color: var(--danger);
}
.field__error::before { content: "!"; display: inline-grid; place-items: center; flex: none; width: 14px; height: 14px; background: var(--danger); color: var(--on-ink-danger); font-weight: var(--fw-max); font-size: 11px; line-height: 1; margin-top: 1px; }
.req { color: var(--danger); font-weight: var(--fw-heavy); }
/* .field :where(...) styles bare Django widgets too; :where keeps specificity at one class so components can override */
.input, .select, .textarea, .field :where(input:not([type=checkbox], [type=radio], [type=file]), select, textarea) {
  display: block; width: 100%; min-width: 0; height: var(--field-h); padding: 0 var(--sp-2);
  border: var(--rule-hair) solid var(--border-field); border-radius: var(--radius); background: var(--surface); color: var(--text);
  font-size: var(--fs-1);
}
.textarea, .field :where(textarea) { height: auto; min-height: 6.5rem; padding: 6px var(--sp-2); line-height: var(--lh-body); resize: vertical; }
.select, .field :where(select) {
  appearance: none; padding-right: 26px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2317154A' stroke-width='2.5'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 6px center / 14px;
}
.select[multiple], .field :where(select[multiple]) { height: auto; min-height: 6rem; padding: var(--sp-1); background-image: none; }
.input[type=file], .field :where(input[type=file]) { height: auto; padding: var(--sp-1) 0; border: 0; font-size: var(--fs-0); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); opacity: 1; }
.input:hover, .select:hover, .textarea:hover, .field :where(input, select, textarea):hover { border-color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus, .field :where(input, select, textarea):focus {
  outline: var(--focus-ring) solid var(--focus); outline-offset: -1px; border-color: var(--focus);
}
.field--error :where(.input, .select, .textarea, input:not([type=checkbox], [type=radio]), select, textarea),
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.field--error .field__label { color: var(--danger); }
.input[disabled], .select[disabled], .textarea[disabled], .field :where(input, select, textarea)[disabled] {
  background: var(--surface-sunk); color: var(--text-faint); border-color: var(--rule); cursor: not-allowed;
}
.input[readonly] { background: var(--surface-sunk); }
.input--num { text-align: right; font-variant-numeric: tabular-nums; }
.input-group { display: flex; gap: var(--sp-2); }
.input-group > .input, .input-group > .select { flex: 1; }
.input-affix { display: flex; align-items: center; border: var(--rule-hair) solid var(--border-field); background: var(--surface); height: var(--field-h); }
.input-affix > span { padding: 0 var(--sp-2); color: var(--text-muted); font-size: var(--fs-0); }
.input-affix .input { border: 0; height: calc(var(--field-h) - 2px); }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-1); font-weight: var(--fw-semibold); cursor: pointer; min-height: var(--ctl-h-sm); }
input[type=checkbox], input[type=radio] { accent-color: var(--text); width: 15px; height: 15px; margin: 0; flex: none; }
.check + .field__help { margin-left: 23px; }
.form-row { display: grid; gap: 0 var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.form-grid { display: grid; gap: 0 var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.form-checks { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-6); margin-bottom: var(--sp-3); }
.form-checks .field { margin: 0; }
.fieldset { border: 0; padding: 0; margin: 0 0 var(--sp-6); min-width: 0; }
.fieldset > legend {
  float: left; width: 100%; padding: 0 0 var(--sp-2); margin-bottom: var(--sp-4); border-bottom: var(--rule-heavy) solid var(--rule-strong);
  font: var(--fw-black) var(--fs-3) / 1 var(--font); font-stretch: var(--wd-wide); letter-spacing: -0.01em;
}
.fieldset > legend + * { clear: both; }
.form-actions {
  display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-top: var(--sp-2);
  padding-top: var(--sp-3); border-top: var(--rule-title) solid var(--rule-strong);
}

/* ---------- Tags (small flags: account type, roles, "Default") ---------- */
.badge {
  --tag: var(--text-muted); --tag-bg: var(--surface-sunk); --tag-rule: var(--rule);
  display: inline-flex; align-items: center; gap: var(--sp-1); padding: 1px 6px; vertical-align: 0.1em;
  border: var(--rule-hair) solid var(--tag-rule); background: var(--tag-bg); color: var(--tag);
  font: var(--fw-bold) var(--fs-0) / 1.3 var(--font); font-stretch: var(--wd-semi); white-space: nowrap;
}
.badge--neutral { --tag: var(--text-muted); }
.badge--ok      { --tag: var(--success); --tag-bg: var(--success-wash); --tag-rule: var(--success-wash); }
.badge--warn    { --tag: var(--warning); --tag-bg: var(--warning-wash); --tag-rule: var(--accent); }
.badge--danger  { --tag: var(--danger);  --tag-bg: var(--danger-wash);  --tag-rule: var(--danger-wash); }
.badge--info    { --tag: var(--info);    --tag-bg: var(--info-wash);    --tag-rule: var(--info-wash); }
.badge--primary { --tag: var(--primary); --tag-bg: var(--surface-selected); --tag-rule: var(--surface-selected); }
.badge--money   { --tag: var(--money);   --tag-bg: var(--money-wash);   --tag-rule: var(--money-wash); }
.badge--solid   { --tag: var(--on-primary); --tag-bg: var(--text); --tag-rule: var(--text); }

/* No-fail flag: a promised date that must not slip */
.nofail {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 5px 1px 3px; background: var(--danger-wash); color: var(--danger);
  font: var(--fw-heavy) var(--fs-0) / 1.3 var(--font); font-stretch: 85%; white-space: nowrap; vertical-align: 0.1em;
}
.nofail .icon { width: var(--icon-sm); height: var(--icon-sm); }
.is-today { font-weight: var(--fw-heavy); color: var(--danger); }

/* ---------- Status chips: a press-proof patch with its step number ---------- */
.status { display: inline-flex; align-items: center; gap: var(--sp-2); white-space: nowrap; font-weight: var(--fw-semibold); vertical-align: middle; }
.status__step {
  display: inline-grid; place-items: center; flex: none; width: var(--chip); height: var(--chip);
  background: var(--chip-ink, var(--ink-off)); color: var(--chip-on, var(--surface));
  font: var(--fw-heavy) 12px / 1 var(--font); font-stretch: var(--wd-tight); font-variant-numeric: tabular-nums;
}
.status__step .icon { width: 13px; height: 13px; stroke-width: 2.5; }
.status--ink-y { --chip-ink: var(--ink-y); --chip-on: var(--on-ink-y); }
.status--ink-k { --chip-ink: var(--ink-k); --chip-on: var(--on-ink-k); }
.status--ink-c { --chip-ink: var(--ink-c); --chip-on: var(--on-ink-c); }
.status--ink-m { --chip-ink: var(--ink-m); --chip-on: var(--on-ink-m); }
.status--ink-done { --chip-ink: var(--ink-done); --chip-on: var(--on-ink-done); }
.status--ink-danger { --chip-ink: var(--ink-danger); --chip-on: var(--on-ink-danger); }
.status--ink-danger .status__label { color: var(--danger); font-weight: var(--fw-heavy); }
.status--ink-off .status__step { background: transparent; color: var(--text-muted); box-shadow: inset 0 0 0 var(--rule-mid) var(--ink-off); }
.status--cancelled .status__label { color: var(--text-muted); text-decoration: line-through; }
.status--invoice-draft .status__label { color: var(--text-muted); }
.status--lg { font-size: var(--fs-2); font-weight: var(--fw-heavy); white-space: normal; }
.status--lg .status__step { width: var(--chip-lg); height: var(--chip-lg); font-size: 16px; }
/* Legacy class names from the first toolkit (no step number): same inks, square patch */
.badge[class*="badge--job-"], .badge[class*="badge--invoice-"] {
  --tag: var(--text); --tag-bg: transparent; --tag-rule: transparent; padding-left: 0; font-weight: var(--fw-semibold); font-size: var(--fs-1);
}
.badge[class*="badge--job-"]::before, .badge[class*="badge--invoice-"]::before { content: ""; width: 12px; height: 12px; background: var(--b, var(--ink-off)); }
.badge--job-new-order, .badge--job-awaiting-artwork, .badge--job-awaiting-supplier, .badge--job-awaiting-approval, .badge--invoice-partially-paid { --b: var(--ink-y); }
.badge--job-in-production { --b: var(--ink-k); }
.badge--job-dispatched-factory, .badge--job-dispatched-dpd { --b: var(--ink-c); }
.badge--job-awaiting-invoice, .badge--job-upload-novuna, .badge--job-invoiced, .badge--invoice-unpaid { --b: var(--ink-m); }
.badge--job-complete, .badge--invoice-paid { --b: var(--ink-done); }
.badge--invoice-overdue { --b: var(--ink-danger); }
.badge--job-cancelled, .badge--invoice-cancelled { --b: var(--ink-off); text-decoration: line-through; color: var(--text-muted); }
.badge--invoice-draft { --b: var(--ink-off); color: var(--text-muted); }

/* Artwork approval ticks: one square per line */
.art { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.art__ticks { display: inline-flex; gap: 2px; }
.art__ticks i { width: 9px; height: 9px; border: var(--rule-mid) solid var(--text); }
.art__ticks i.on { background: var(--text); }
.art--none { color: var(--text-muted); }
.art--none .art__ticks i { border-color: var(--ink-off); }

/* Initials monogram (people) */
.avatar {
  display: inline-grid; place-items: center; width: 26px; height: 22px; flex: none;
  border: var(--rule-hair) solid var(--rule); color: var(--text); background: var(--surface);
  font: var(--fw-heavy) 11px / 1 var(--font); font-stretch: 85%; letter-spacing: 0.02em;
}

/* ---------- Tabs (saved views, in-page section links) ---------- */
.tabs, .section-nav { display: flex; gap: 0; overflow-x: auto; border-bottom: var(--rule-hair) solid var(--rule); scrollbar-width: thin; }
.tabs a, .section-nav a, .tabs__tab {
  display: inline-flex; align-items: baseline; gap: 6px; flex: none; padding: 11px var(--sp-3) 9px; margin-bottom: -1px;
  border-bottom: var(--rule-title) solid transparent; color: var(--text-muted); text-decoration: none; white-space: nowrap;
  font-weight: var(--fw-semibold); font-stretch: var(--wd-semi);
}
.tabs a:hover, .section-nav a:hover { color: var(--text); border-bottom-color: var(--rule); }
.tabs a[aria-current], .section-nav a[aria-current] { color: var(--text); border-bottom-color: var(--rule-strong); font-weight: var(--fw-heavy); }
.tabs__n { font-size: var(--fs-0); font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: var(--fw-medium); }

/* ---------- Breadcrumbs ---------- */
.crumbs, .breadcrumb { display: flex; flex-wrap: wrap; gap: 0 6px; margin: 0 0 var(--sp-3); font-size: var(--fs-0); font-weight: var(--fw-semibold); font-stretch: var(--wd-narrow); color: var(--text-muted); }
.crumbs a, .breadcrumb a { color: var(--text-muted); }
.crumbs a:hover, .breadcrumb a:hover { color: var(--text); }
.crumbs__sep { color: var(--text-off); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; }
.table-wrap--scroll { max-height: 70vh; overflow: auto; }
.table-wrap--auto, .table-wrap--bare { /* kept for old templates: tables are bare and page-scrolled by default */ }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-1); font-stretch: var(--wd-table); }
.table th {
  text-align: left; vertical-align: bottom; white-space: nowrap; padding: 9px var(--sp-2) 7px;
  background: var(--surface-sunk); color: var(--text); border-top: var(--rule-heavy) solid var(--rule-strong); border-bottom: var(--rule-hair) solid var(--rule-strong);
  font: var(--fw-bold) var(--fs-0) / 1 var(--font); font-stretch: var(--wd-narrow);
}
.table-wrap--scroll .table thead th { position: sticky; top: 0; z-index: var(--z-sticky); }
.table td { height: var(--row-h); padding: 3px var(--sp-2); border-bottom: var(--rule-hair) solid var(--rule-soft); vertical-align: middle; line-height: var(--lh-snug); }
.table th:first-child, .table td:first-child { padding-left: var(--sp-3); }
.table th:last-child, .table td:last-child { padding-right: var(--sp-3); }
.table tbody tr:nth-child(5n):not(:last-child) td { border-bottom-color: var(--rule); }
.table tbody tr:last-child td { border-bottom: var(--rule-heavy) solid var(--rule-strong); }
.table tbody tr:hover td { background: var(--surface-hover); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.table td.num { font-weight: var(--fw-semibold); }
.table .col-check { width: 36px; padding-right: 0; }
.table a.row-link { color: var(--text); font-weight: var(--fw-heavy); text-decoration: none; white-space: nowrap; }
.table a.row-link:hover { color: var(--link); text-decoration: underline; }
.record-no { font-weight: var(--fw-heavy); font-stretch: 80%; font-size: var(--fs-2); color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; white-space: nowrap; }
a.record-no:hover { color: var(--link); text-decoration: underline; }
.cell-sub { display: block; color: var(--text-muted); font-size: var(--fs-0); }
.table th a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 3px; }
.table th a.sort:hover { text-decoration: underline; }
.table th a.sort::after { content: ""; width: 8px; height: 8px; opacity: 0; }
.table th a.sort:hover::after { opacity: .35; }
.table th[aria-sort] a.sort::after, .table th a.sort:hover::after {
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M0 2h8L4 7z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M0 2h8L4 7z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.table th[aria-sort] a.sort::after { opacity: 1; }
.table th[aria-sort="ascending"] a.sort::after { transform: rotate(180deg); }
.table tr.is-selected td, .table tr[aria-selected="true"] td { background: var(--surface-selected); }
.table tr.is-selected td:first-child, .table tr[aria-selected="true"] td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.table tr.is-closed td, .row-inactive td { color: var(--text-muted); }
.row-inactive a.row-link, .table tr.is-closed .record-no { color: var(--text-muted); font-weight: var(--fw-medium); }
.table--dense { /* the default is dense; kept as an alias */ }
.table--fixed { table-layout: fixed; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); justify-content: flex-end; align-items: center; }
.none { color: var(--text-faint); }

/* Spreadsheet grid: quantity breaks, price tables. Every cell ruled; inputs fill the cell. */
.table--grid { width: auto; min-width: min(100%, 40rem); border: var(--rule-hair) solid var(--rule-strong); }
.table--grid td.cell-input { width: 7.5rem; min-width: 6rem; }
.table--grid th { border-top: 0; border-left: var(--rule-hair) solid var(--rule); padding: 7px var(--sp-2); }
.table--grid td { height: var(--row-h-grid); padding: 0 var(--sp-2); border-left: var(--rule-hair) solid var(--rule); }
.table--grid th:first-child, .table--grid td:first-child { border-left: 0; }
.table--grid tbody tr:last-child td { border-bottom: var(--rule-hair) solid var(--rule-soft); }
.table--grid tbody tr:nth-child(5n) td { border-bottom-color: var(--rule-soft); }
.table--grid td.cell-input { padding: 0; }
.table--grid .input, .table--grid .input-affix { border: 0; height: calc(var(--row-h-grid) - 1px); background: transparent; box-shadow: none; }
.table--grid .input:focus { outline: var(--focus-ring) solid var(--focus); outline-offset: -2px; }
.table--grid tr.is-chosen td { background: var(--surface-highlight); }
.table--grid tr.is-chosen td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.table--grid tr.is-sub td { border-top: var(--rule-hair) solid var(--rule-strong); }
.table--grid tbody tr:hover td { background: inherit; }
.table--grid tr.is-chosen:hover td { background: var(--surface-highlight); }
.pick { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-0); color: var(--text-muted); font-weight: var(--fw-semibold); }
.is-chosen .pick { color: var(--text); font-weight: var(--fw-black); }

/* Table toolbar: count + export above a list */
.table-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-4); margin: var(--sp-1) 0 var(--sp-2); min-height: var(--ctl-h-sm); }
.table-toolbar__count { margin: 0; color: var(--text-muted); font-size: var(--fs-1); }
.table-toolbar__count strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Bulk selection bar: appears above the table when rows are selected */
.bulkbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); min-height: 44px; padding: 0 var(--sp-3) 0 0; background: var(--strap-bg); color: var(--text-inverse); }
.bulkbar__count { align-self: stretch; display: flex; align-items: center; padding: 0 var(--sp-4); background: var(--accent); color: var(--on-accent); font-weight: var(--fw-semibold); }
.bulkbar__count strong { font-weight: var(--fw-black); margin-right: var(--sp-1); }
.bulkbar__label { color: var(--strap-text); font-weight: var(--fw-semibold); font-stretch: var(--wd-semi); }
.bulkbar .select { width: auto; min-width: 14rem; height: 30px; border: 0; }
.bulkbar .btn { height: 30px; }
.bulkbar .btn--link { color: var(--strap-text); }
.bulkbar .btn--link:hover { color: var(--text-inverse); }
.bulkbar :focus-visible { outline-color: var(--focus-on-dark); }

/* ---------- Filters (list toolbar): label sits inside the control's frame ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-3) 0 var(--sp-2); }
.filters__search { position: relative; flex: 0 1 22rem; margin: 0; }
.filters__search .icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.filters__search .input { padding-left: 30px; }
.filters__item {
  display: flex; align-items: center; height: var(--field-h); border: var(--rule-hair) solid var(--border-field); background: var(--surface); min-width: 0;
}
.filters__item:hover { border-color: var(--text-muted); }
.filters__item label { padding: 0 2px 0 9px; white-space: nowrap; font: var(--fw-bold) var(--fs-0) / 1 var(--font); font-stretch: var(--wd-narrow); color: var(--text-muted); }
.filters__item .select { border: 0; height: calc(var(--field-h) - 2px); width: auto; min-width: 7.5rem; font-weight: var(--fw-semibold); background-color: transparent; }
.filters__item.is-set { border-color: var(--rule-strong); }
.filters__actions { display: flex; gap: var(--sp-2); align-items: center; }

/* ---------- Pagination: joined squares ---------- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding-top: var(--sp-3); font-size: var(--fs-1); color: var(--text-muted); }
.pagination__info { margin: 0; }
.pagination__info strong { color: var(--text); font-variant-numeric: tabular-nums; }
.pagination__pages { list-style: none; margin: 0; padding: 0; display: flex; }
.pagination__link, .pagination__gap {
  display: inline-grid; place-items: center; min-width: 32px; height: 30px; padding: 0 6px; margin-left: -1px;
  border: var(--rule-hair) solid var(--rule); color: var(--text); text-decoration: none; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
}
.pagination li:first-child > * { margin-left: 0; }
a.pagination__link:hover { background: var(--surface-sunk); color: var(--text); position: relative; border-color: var(--rule-strong); }
.pagination__link[aria-current="page"] { background: var(--text); border-color: var(--text); color: var(--text-inverse); position: relative; }
.pagination__link[aria-disabled="true"] { color: var(--text-off); pointer-events: none; }
.pagination__gap { color: var(--text-muted); }

/* ---------- Alerts and messages: full frame, leading mark, no side stripe ---------- */
.messages { list-style: none; margin: 0 0 var(--sp-4); padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.alert {
  --a: var(--info); --a-wash: var(--info-wash);
  position: relative; display: block; padding: var(--sp-3) var(--sp-4) var(--sp-3) 42px;
  background: var(--a-wash); color: var(--text); border: var(--rule-hair) solid var(--a); font-size: var(--fs-1);
}
.alert::before {
  content: "i"; position: absolute; left: var(--sp-3); top: 11px; display: grid; place-items: center; width: 20px; height: 20px;
  background: var(--a); color: var(--surface); font: var(--fw-max) 13px / 1 var(--font); font-stretch: var(--wd-narrow);
}
.alert strong { color: var(--text); }
.alert > :last-child, .alert p { margin-bottom: 0; }
.alert--info, .alert--debug { --a: var(--info); --a-wash: var(--info-wash); }
.alert--success { --a: var(--success); --a-wash: var(--success-wash); }
.alert--success::before { content: "\2713"; font-family: var(--font-mono); font-size: 12px; }
.alert--warning { --a: var(--warning); --a-wash: var(--warning-wash); }
.alert--warning::before { content: "!"; background: var(--accent); color: var(--on-accent); }
.alert--error { --a: var(--danger); --a-wash: var(--danger-wash); }
.alert--error::before { content: "!"; }

/* ---------- Panels ("cards"): ruled sections, not boxes ---------- */
.card { min-width: 0; }
.card > h2:first-child, .card > h3:first-child, .card__header {
  margin: 0 0 var(--sp-2); padding-bottom: var(--sp-2); border-bottom: var(--rule-heavy) solid var(--rule-strong);
}
.card__header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-2) var(--sp-3); margin-bottom: 0; }
.card__header h2, .card__header h3 { margin: 0; }
.card__header .btn, .card__header form { flex: none; }
.card__meta { margin: 0; color: var(--text-muted); font-weight: var(--fw-semibold); font-size: var(--fs-0); }
.card__body { padding: var(--sp-3) 0; }
.card__body > :last-child { margin-bottom: 0; }
.card--flush > .table-wrap .table th { border-top: 0; }
.card--boxed { border: var(--rule-heavy) solid var(--rule-strong); padding: var(--sp-4); }
.empty-note { color: var(--text-muted); margin: 0; padding: var(--sp-3) 0; }
.placeholder > h2:first-child { border-bottom-style: dashed; border-bottom-width: var(--rule-mid); }
.placeholder p { margin: 0; padding: var(--sp-3) 0 0; color: var(--text-muted); font-size: var(--fs-0); }
.section { margin-top: var(--sp-7); }
.section > h2 { padding-bottom: var(--sp-2); border-bottom: var(--rule-heavy) solid var(--rule-strong); }

/* ---------- Definition lists ---------- */
.dl { display: grid; grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr); margin: 0; }
.dl dt, .dl dd { padding: 7px 0; border-bottom: var(--rule-hair) solid var(--rule-soft); }
.dl dt { color: var(--text-muted); font-weight: var(--fw-semibold); font-size: var(--fs-0); font-stretch: var(--wd-narrow); padding-top: 8px; padding-right: var(--sp-3); }
.dl dd { margin: 0; overflow-wrap: anywhere; font-weight: var(--fw-medium); }
/* Facts: the key numbers of a record, in a ruled band */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); margin: 0; background: var(--surface-sunk); }
.facts > div, .fact { padding: 9px var(--sp-4) 10px; border-left: var(--rule-hair) solid var(--rule); min-width: 0; }
.facts > div:first-child { border-left: 0; }
.facts dt { margin-bottom: 5px; font: var(--fw-bold) var(--fs-0) / 1 var(--font); font-stretch: var(--wd-narrow); color: var(--text-muted); }
.facts dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.fact--key { background: var(--surface-key); }
.fact--key dd { font-weight: var(--fw-black); }
/* Money rows: sums down a column */
.money { margin: 0; }
.money__row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 5px 0; border-bottom: var(--rule-hair) solid var(--rule-soft); }
.money__row dt { color: var(--text-muted); font-weight: var(--fw-semibold); }
.money__row dd { margin: 0; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; text-align: right; }
.money__row--sub { border-top: var(--rule-hair) solid var(--rule-strong); }
.money__row--total { border-top: var(--rule-heavy) solid var(--rule-strong); border-bottom: var(--rule-heavy) solid var(--rule-strong); padding: var(--sp-2) 0; align-items: baseline; }
.money__row--total dt { color: var(--text); font-weight: var(--fw-black); }
.money__row--total dd { font-size: var(--fs-4); font-weight: var(--fw-black); letter-spacing: -0.01em; }

/* ---------- Workflow strip: the job's press steps ---------- */
.wf { list-style: none; margin: var(--sp-3) 0 var(--sp-5); padding: 0; display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); border: var(--rule-mid) solid var(--rule-strong); }
.wf__step { display: flex; align-items: center; gap: 6px; padding: 7px var(--sp-2); min-height: 40px; border-left: var(--rule-hair) solid var(--rule); font-size: var(--fs-0); font-stretch: 88%; line-height: 1.1; }
.wf__step:first-child { border-left: 0; }
.wf__n { font-weight: var(--fw-max); font-size: var(--fs-2); font-stretch: 70%; font-variant-numeric: tabular-nums; color: var(--text-faint); }
.wf__label { color: var(--text-muted); font-weight: var(--fw-semibold); }
.wf__step.is-done { background: var(--strap-bg); border-left-color: var(--strap-field-border); }
.wf__step.is-done .wf__n, .wf__step.is-done .wf__label { color: var(--strap-text); }
.wf__step.is-current { background: var(--accent); }
.wf__step.is-current .wf__n, .wf__step.is-current .wf__label { color: var(--on-accent); font-weight: var(--fw-black); }

/* ---------- Empty state: the castle ---------- */
.empty-state { display: grid; justify-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-7) var(--sp-5) var(--sp-8); border-top: var(--rule-heavy) solid var(--rule-strong); border-bottom: var(--rule-hair) solid var(--rule); }
.empty-state__art { width: 11rem; max-width: 60%; height: auto; margin-bottom: var(--sp-2); }
.empty-state__art--dark { display: none; }
.empty-state h2, .empty-state h3 { margin: 0; font: var(--fw-black) var(--fs-4) / 1.05 var(--font); font-stretch: var(--wd-wide); letter-spacing: -0.015em; }
.empty-state p { color: var(--text-muted); max-width: 34rem; margin: 0 0 var(--sp-2); }
.empty-state--plain { padding-block: var(--sp-6); }

/* ---------- Activity log ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity__item { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 7px 0; border-bottom: var(--rule-hair) solid var(--rule-soft); font-size: var(--fs-0); }
.activity__msg { overflow-wrap: anywhere; font-size: var(--fs-1); }
.activity__meta { display: flex; flex-wrap: wrap; gap: 0 var(--sp-2); color: var(--text-muted); }
.activity__meta time { font-weight: var(--fw-semibold); }
.activity__who { font-weight: var(--fw-bold); color: var(--text); }

/* ---------- Attachments ---------- */
.attachments { list-style: none; margin: 0; padding: 0; }
.attachments li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--sp-2); padding: 7px 0; border-bottom: var(--rule-hair) solid var(--rule-soft); }
.attachments a { font-weight: var(--fw-bold); overflow-wrap: anywhere; }
.attachments form { margin: 0; }
.upload-form { display: grid; gap: var(--sp-2); padding: var(--sp-3); margin-top: var(--sp-3); background: var(--surface-sunk); }
.upload-form .field { margin: 0; }

/* ---------- Addresses ---------- */
.addresses { display: grid; gap: 0 var(--sp-6); grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); }
.address { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3) 0; border-bottom: var(--rule-hair) solid var(--rule-soft); min-width: 0; }
.address--inactive { color: var(--text-muted); }
.address__head { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); align-items: center; font-weight: var(--fw-heavy); }
.address__body { margin: 0; flex: 1; overflow-wrap: anywhere; }
.address .row-actions { justify-content: flex-start; }

/* ---------- Inline (in-page) forms ---------- */
.inline-slot:empty { display: none; }
.inline-form { margin: var(--sp-3) 0; padding: var(--sp-4); border: var(--rule-heavy) solid var(--rule-strong); background: var(--surface); }
.inline-form h3 { margin-bottom: var(--sp-3); }
.inline-form .form-actions { border-top-width: var(--rule-heavy); }

/* ---------- Thumbnails ---------- */
.thumb { display: block; width: 44px; height: 44px; object-fit: contain; background: var(--surface-sunk); border: var(--rule-hair) solid var(--rule); }
.thumb--empty { background: var(--surface-sunk) linear-gradient(to top right, transparent calc(50% - 1px), var(--rule) calc(50% - 1px), var(--rule) calc(50% + 1px), transparent calc(50% + 1px)); }
.thumb--lg { width: 100%; max-width: 20rem; height: auto; aspect-ratio: 1; padding: var(--sp-2); }

/* ---------- Links list (paperwork on a record) ---------- */
.links { list-style: none; margin: 0; padding: 0; }
.links__item { display: grid; grid-template-columns: 82px auto minmax(0, 1fr); gap: var(--sp-2); align-items: baseline; padding: 6px 0; border-bottom: var(--rule-hair) solid var(--rule-soft); }
.links__kind { display: inline-flex; gap: 5px; align-items: center; color: var(--text-muted); font-weight: var(--fw-semibold); }
.links__item a { font-weight: var(--fw-heavy); font-variant-numeric: tabular-nums; }
.links__state { color: var(--text-muted); font-size: var(--fs-0); text-align: right; }

/* ---------- Meter (margin against median) ---------- */
.meter { position: relative; height: 12px; margin: var(--sp-3) 0 6px; border: var(--rule-hair) solid var(--rule-strong); background: linear-gradient(90deg, var(--rule) 1px, transparent 1px) 0 0 / 10% 100%; }
.meter__fill { position: absolute; inset: 0 auto 0 0; width: var(--v); background: var(--primary); }
.meter__mark { position: absolute; left: var(--v); top: -5px; bottom: -5px; width: 2px; background: var(--rule-strong); }
.meter__note { margin: 0; font-size: var(--fs-0); color: var(--text-muted); }

/* ---------- HTMX in-flight regions ---------- */
#list-results, [data-swap-region] { transition: opacity var(--dur) var(--ease-out); }
#list-results.htmx-request, [data-swap-region].htmx-request { opacity: .55; }
.htmx-indicator { visibility: hidden; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { visibility: visible; }

@media (max-width: 40rem) {
  .table .col-secondary { display: none; }
  .filters__search { flex: 1 1 100%; }
  .filters__item { flex: 1 1 calc(50% - var(--sp-2)); }
  .filters__item .select { flex: 1; min-width: 0; width: 100%; }
  .dl { grid-template-columns: minmax(0, 1fr); }
  .dl dt { border-bottom: 0; padding-bottom: 0; }
  .dl dd { padding-top: 2px; }
  .wf { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .wf__step { border-top: var(--rule-hair) solid var(--rule); }
  .btn { min-height: var(--ctl-h); }
  .pagination { justify-content: center; }
  .pagination__info { width: 100%; text-align: center; }
  .pagination__link, .pagination__gap { min-width: 40px; height: 40px; }
}
.filters__item:focus-within { border-color: var(--focus); }
