/* CredVault components. Every colour/space/size comes from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-app);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--text-strong); line-height: 1.25; margin: 0; }
h1 { font-size: var(--text-xl); font-weight: 650; }
h2 { font-size: var(--text-lg); font-weight: 600; }
h3 { font-size: var(--text-md); font-weight: 600; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------ app shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100vh;
}
.sidebar {
  grid-area: side;
  background: var(--bg-sidebar);
  color: var(--fg-sidebar);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2); color: var(--fg-sidebar-strong); font-weight: 700; font-size: var(--text-lg); }
.brand-logo { height: 2em; width: auto; max-width: 8em; object-fit: contain; border-radius: var(--radius-sm); }
.brand-mark { display: grid; place-items: center; width: 2em; height: 2em; border-radius: var(--radius-sm); background: var(--primary-500); color: var(--text-on-primary); font-size: var(--text-sm); }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); padding: var(--space-2) var(--space-2) var(--space-1); }
.nav-link {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--fg-sidebar); font-size: var(--text-sm);
}
.nav-link:hover { background: var(--bg-sidebar-active); color: var(--fg-sidebar-strong); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--bg-sidebar-active); color: var(--fg-sidebar-strong); box-shadow: inset 3px 0 0 var(--primary-500); }
.nav-link.is-soon { opacity: 0.45; cursor: default; }
.nav-link.is-soon:hover { background: none; color: var(--fg-sidebar); }
.nav-link .soon { margin-left: auto; font-size: var(--text-xs); }
.nav-icon { width: 1.1em; height: 1.1em; flex: none; }

.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-search { flex: 1 1 auto; max-width: 32rem; position: relative; }
.search-results {
  list-style: none; margin: var(--space-1) 0 0; padding: var(--space-1);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  max-height: 60vh; overflow-y: auto;
}
.topbar-search .search-results { position: absolute; inset: 100% 0 auto 0; z-index: 30; }
.search-results a { display: flex; flex-direction: column; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--text); }
.search-results a:hover, .search-results a:focus { background: var(--bg-muted); text-decoration: none; }
.search-empty { padding: var(--space-2) var(--space-3); color: var(--text-muted); font-size: var(--text-sm); }
.topbar-user { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); }
.avatar { display: grid; place-items: center; width: 2.1em; height: 2.1em; border-radius: 50%; background: var(--primary-100); color: var(--primary-700); font-weight: 700; font-size: var(--text-sm); }
.menu-toggle { display: inline-flex; }
/* Wide screens: the menu button hides the sidebar (remembered per device). */
html.nav-collapsed .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
html.nav-collapsed .sidebar { display: none; }

.main { grid-area: main; padding: var(--space-5); min-width: 0; }
.page { width: 100%; max-width: var(--content-max); margin-inline: auto; display: flex; flex-direction: column; gap: var(--space-5); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.page-head p { margin: var(--space-1) 0 0; color: var(--text-muted); font-size: var(--text-sm); }

.breadcrumbs { display: flex; flex-wrap: wrap; gap: var(--space-1); font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-1); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs li { list-style: none; }
.breadcrumbs li + li::before { content: "/"; margin-right: var(--space-1); color: var(--text-faint); }
.breadcrumbs ol { display: contents; }

/* ------------------------------------------------------------- surfaces */
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) 0; }
.card-body { padding: var(--space-4); }
.card-body.flush { padding: var(--space-3) 0 0; }

.stat-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
.stat { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.stat-label { font-size: var(--text-sm); color: var(--text-muted); }
.stat-value { font-size: var(--text-2xl); font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.stat-foot { font-size: var(--text-xs); color: var(--text-faint); }
/* Dashboard (v1 layout): breakdown on the left, card rows on the right. */
.dash-section { margin-bottom: var(--space-4); }
.dash-heading { font-size: var(--text-md); margin-bottom: var(--space-2); }
.dash-body { display: grid; gap: var(--space-4); grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr); align-items: start; }
.dash-cards { display: flex; flex-direction: column; gap: var(--space-4); }
.dash-row { display: grid; gap: var(--space-3); }
.dash-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dash-row.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dash-row.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.dash-row.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.dash-card { text-decoration: none; color: inherit; transition: border-color 0.15s, box-shadow 0.15s; }
a.dash-card:hover { border-color: var(--primary-500); box-shadow: var(--shadow-md); }
.dash-card.is-muted { opacity: 0.55; }
.dash-window { font-size: var(--text-sm); color: var(--text-muted); }
.dash-window .select { width: auto; }
.bd { margin: 0 0 var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.bd-title { font-size: var(--text-sm); font-weight: 600; color: var(--text-strong); }
.bd-bar { width: 100%; height: 0.9rem; display: block; border-radius: var(--radius-sm); overflow: hidden; }
.bd-seg.series-1, .bd-swatch.series-1 { fill: var(--series-1); background: var(--series-1); }
.bd-seg.series-2, .bd-swatch.series-2 { fill: var(--series-2); background: var(--series-2); }
.bd-seg.series-3, .bd-swatch.series-3 { fill: var(--series-3); background: var(--series-3); }
.bd-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); font-size: var(--text-sm); color: var(--text); }
.bd-legend li { display: inline-flex; align-items: center; gap: var(--space-1); }
.bd-swatch { width: 0.7rem; height: 0.7rem; border-radius: 2px; display: inline-block; }
@media (max-width: 80rem) { .dash-body { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 72rem) { .dash-row.cols-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 56rem) { .dash-row.cols-4, .dash-row.cols-5, .dash-row.cols-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dash-row.cols-3 { grid-template-columns: minmax(0, 1fr); } }
.stat.accent-primary { border-top: 3px solid var(--primary-500); }
.stat.accent-secondary { border-top: 3px solid var(--secondary-500); }
.stat.accent-tertiary { border-top: 3px solid var(--tertiary-500); }
.stat.accent-warning { border-top: 3px solid var(--warning-600); }

.kv { display: grid; grid-template-columns: minmax(6rem, max-content) minmax(0, 1fr); gap: var(--space-2) var(--space-4); margin: 0; font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-strong); display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); }
/* Side-by-side cards of a fixed height; each scrolls inside its own box (subscription Companies / Users). */
.card-fixed { display: flex; flex-direction: column; min-width: 0; }
.card-fixed > .card-head { padding-bottom: var(--space-3); border-bottom: 1px solid var(--border); }
.scroll-box { height: 22rem; overflow: auto; } /* the wheel scrolls the page; Shift/Ctrl + wheel this box (app.js) */
.scroll-box .table-wrap { overflow: visible; border-top: 0; }
.people-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
@media (min-width: 64rem) { .people-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); } }
.company-grid { list-style: none; margin: 0; padding: var(--space-3) var(--space-4); display: grid; gap: var(--space-2); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.company-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-width: 0;
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.company-item > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-3 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); }

/* --------------------------------------------------------------- tables */
/* One vertical scroll (the page's): the box only scrolls sideways when a table is wider than the screen. */
.table-wrap { overflow-x: auto; overflow-y: hidden; border-top: 1px solid var(--border); }
/* A row's small form (Renew, Merge...) opens inside the row, so the box never cuts it off. */
.table-wrap .inline-action[open] > .form { position: static; margin-top: var(--space-2); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); }
table.data th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-subtle); color: var(--text-muted);
  font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[aria-sort="ascending"]::after { content: " ▲"; }
table.data th[aria-sort="descending"]::after { content: " ▼"; }
table.data td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:hover { background: var(--bg-subtle); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-sub { display: block; color: var(--text-faint); font-size: var(--text-xs); }

.empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); }
.empty-icon { font-size: var(--text-2xl); color: var(--text-faint); }
.empty h3 { color: var(--text-strong); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); font-size: var(--text-sm); color: var(--text-muted); }

/* ---------------------------------------------------------- badges/pills */
.pill { display: inline-flex; align-items: center; gap: 0.35em; padding: 0.1em 0.65em; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; background: var(--bg-muted); color: var(--text-muted); }
.pill.success { background: var(--success-50); color: var(--success-600); }
.pill.warning { background: var(--warning-50); color: var(--warning-600); }
.pill.danger  { background: var(--danger-50);  color: var(--danger-600); }
.pill.info    { background: var(--info-50);    color: var(--info-600); }
.pill.primary { background: var(--primary-50); color: var(--primary-600); }
.pill.tertiary{ background: var(--tertiary-50); color: var(--tertiary-600); }
.pill.secondary { background: var(--secondary-50); color: var(--secondary-600); }
a.pill:hover { text-decoration: none; filter: brightness(0.96); }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0.55em 1.05em; border-radius: var(--radius-md); border: 1px solid transparent;
  font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary-500); color: var(--text-on-primary); }
.btn-primary:hover { background: var(--primary-600); }
.btn-secondary { background: var(--secondary-50); color: var(--secondary-600); border-color: color-mix(in srgb, var(--secondary-500) 30%, transparent); }
.btn-secondary:hover { background: color-mix(in srgb, var(--secondary-500) 16%, var(--bg-surface)); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-muted); color: var(--text); }
.btn-danger { background: var(--danger-600); color: var(--text-on-danger); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading::after { content: ""; position: absolute; width: 1em; height: 1em; border-radius: 50%; border: 2px solid currentColor; border-color: var(--text-on-primary) transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.field .hint { font-size: var(--text-xs); color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; font: inherit; font-size: var(--text-md); color: var(--text-strong);
  background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: 0.55em 0.8em; transition: border-color 0.12s, box-shadow 0.12s;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--neutral-500); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary-500); box-shadow: 0 0 0 3px var(--focus-ring); }
.input[aria-invalid="true"] { border-color: var(--danger-600); }
/* date/time fields with a picker button */
.picker-field { position: relative; display: block; }
.picker-field .input { padding-right: 2.6em; }
.picker-btn {
  position: absolute; right: 0.3em; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; padding: 0.3em; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer;
}
.picker-btn:hover { background: var(--bg-muted); color: var(--primary-600); }
.picker-btn:focus-visible { outline: 3px solid var(--focus-ring); }
.picker-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.eye-btn[aria-pressed="true"] { color: var(--primary-600); }
/* A password field that is read-only only to block autofill looks normal. */
.input[data-unlock-on-focus] { background: var(--bg-surface); cursor: text; }
/* The native input only exists to host the browser's picker popup. */
.picker-native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
/* subscription form: fields + sticky summary side by side, stacking on narrow screens */
.form-split { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem); align-items: start; }
.summary-card { position: sticky; top: calc(var(--space-6) + 3rem); }
@media (max-width: 64rem) { .form-split { grid-template-columns: minmax(0, 1fr); } .summary-card { position: static; } }
/* Approvals: one card-like row per request, before/after table, note + decision. */
.request-list { list-style: none; margin: 0; padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.request { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.request-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.request-head input[type="checkbox"] { width: 1.05em; height: 1.05em; accent-color: var(--primary-500); }
.request-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.request-actions .input { flex: 1 1 16rem; }
.diff-table th[scope="row"] { font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.diff-before { color: var(--text-muted); text-decoration: line-through; text-decoration-color: var(--border-strong); }
.diff-after { color: var(--text-strong); font-weight: 600; }
/* "Support call not saved" prompt on the Connecting page, pinned over the content. */
.unsaved { position: fixed; inset: auto var(--space-4) var(--space-4) auto; max-width: min(28rem, calc(100vw - 2 * var(--space-4))); z-index: 50; box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: var(--space-3); }
.reason { border-top: 1px solid var(--border); padding-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.reason summary { cursor: pointer; }
.pending-box form { display: inline-flex; gap: var(--space-2); margin-left: var(--space-2); }

/* Company rows sit two to a line (v1), one on phones. */
/* Company fields: three per line (two on mid-size screens, one on phones); code + a square remove button. */
.company-rows { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2) var(--space-4); }
.company-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: stretch; }
.company-row [data-remove-company] {
  aspect-ratio: 1 / 1; height: 100%; min-height: 2.25rem; width: auto; padding: 0;
  display: inline-grid; place-items: center; font-size: var(--text-lg); line-height: 1;
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-muted);
}
.company-row [data-remove-company]:hover { color: var(--danger-600); border-color: var(--danger-600); background: var(--danger-50); }
@media (max-width: 64rem) { .company-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 40rem) { .company-rows { grid-template-columns: minmax(0, 1fr); } }
.company-picks-empty { font-size: var(--text-xs); color: var(--text-muted); }
.input-sm { padding: 0.35em 0.6em; font-size: var(--text-sm); max-width: 12rem; }

/* transactions */
.billing-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.tx-actions { border-top: 1px solid var(--border); }
.tx-action { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); background: var(--bg-subtle); }
.tx-action > summary { cursor: pointer; font-weight: 600; color: var(--text-strong); padding: var(--space-1) 0; }
.tx-action[open] > summary { margin-bottom: var(--space-3); }
.inline-action { display: inline-block; text-align: left; position: relative; }
.inline-action > summary { list-style: none; }
.inline-action > summary::-webkit-details-marker { display: none; }
.inline-action[open] > .form { position: absolute; right: 0; top: 100%; z-index: 10; width: min(22rem, 90vw); margin-top: var(--space-1);
  padding: var(--space-3); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); }

/* customer contacts */
.contact-list { display: flex; flex-direction: column; gap: var(--space-4); }
.contact-card { margin: 0; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-subtle); display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.contact-card.is-invalid { border-color: var(--danger-600); }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.multi-row { display: flex; gap: var(--space-2); align-items: center; }
.multi-row .input { flex: 1 1 auto; min-width: 0; }
.tag-picks { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tag-check { position: relative; }
.tag-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tag-check span { display: inline-block; padding: 0.2em 0.8em; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); cursor: pointer; user-select: none; }
.tag-check input:checked + span { background: var(--tertiary-50); border-color: var(--tertiary-500); color: var(--tertiary-600); }
.tag-check input:focus-visible + span { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.contact-view { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); }
.contact-view article { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); }
.contact-view ul { list-style: none; margin: 0; padding: 0; }

.username-status.ok { color: var(--success-600); }
.username-status.bad { color: var(--danger-600); }
.gst-status.ok { color: var(--success-600); }
.gst-status.bad { color: var(--danger-600); }

.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; padding: var(--space-4); }
.filters .field { flex: 1 1 10rem; }
.filters.flush { padding: 0; }
.row-start { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); font-size: var(--text-sm); }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.check input { width: 1.05em; height: 1.05em; accent-color: var(--primary-500); }

.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); border: 1px solid transparent; }
.alert.danger  { background: var(--danger-50);  color: var(--danger-600);  border-color: color-mix(in srgb, var(--danger-600) 25%, transparent); }
.alert.success { background: var(--success-50); color: var(--success-600); border-color: color-mix(in srgb, var(--success-600) 25%, transparent); }
.alert.info    { background: var(--info-50);    color: var(--info-600);    border-color: color-mix(in srgb, var(--info-600) 25%, transparent); }
.alert.warning { background: var(--warning-50); color: var(--warning-600); border-color: color-mix(in srgb, var(--warning-600) 25%, transparent); }

/* --------------------------------------------------------- auth screens */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.auth-aside {
  background: linear-gradient(160deg, var(--primary-700), var(--neutral-900));
  color: var(--fg-hero); padding: var(--space-6); display: flex; flex-direction: column; justify-content: space-between; gap: var(--space-5);
}
.auth-aside h2 { color: var(--fg-hero-strong); font-size: var(--text-2xl); max-width: 18ch; }
.auth-aside p { max-width: 42ch; color: var(--fg-hero-muted); }
.auth-aside .brand { color: var(--fg-hero-strong); }
.auth-aside .cell-sub { color: var(--fg-hero-muted); }
.auth-main { display: grid; place-items: center; padding: var(--space-6) var(--space-4); }
.auth-card { width: min(100%, 26rem); display: flex; flex-direction: column; gap: var(--space-4); }
.auth-card .sub { color: var(--text-muted); font-size: var(--text-sm); margin: var(--space-1) 0 0; }
.otp-input { letter-spacing: 0.5em; font-size: var(--text-xl); text-align: center; font-variant-numeric: tabular-nums; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; font-size: var(--text-sm); }

/* ------------------------------------------------ authenticator setup */
.enrol { display: grid; gap: var(--space-5); grid-template-columns: auto minmax(0, 1fr); align-items: start; }
.qr { width: clamp(9rem, 8rem + 5vw, 13rem); height: auto; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--neutral-0); padding: var(--space-2); }
.steps { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: var(--space-2); }
.code-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); gap: var(--space-2); margin: 0; padding-left: 1.4em; font-size: var(--text-lg); }
.code-list code { letter-spacing: 0.05em; }
@media (max-width: 40rem) { .enrol { grid-template-columns: minmax(0, 1fr); } }

/* -------------------------------------------------------- fixed forms */
body.fullscreen-form-page { height: 100vh; overflow: hidden; }
body.fullscreen-form-page .shell { height: 100vh; }
body.fullscreen-form-page .main { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
body.fullscreen-form-page .page { flex: 1 1 auto; min-height: 0; overflow: auto; }

/* ----------------------------------------------------------- responsive */
@media (max-width: 64rem) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(80vw, 18rem); z-index: 20; transform: translateX(-100%); transition: transform 0.2s; }
  /* Narrow screens: the sidebar slides over the page instead; the wide-screen choice doesn't apply. */
  html.nav-collapsed .sidebar { display: flex; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-md); }
  .main { padding: var(--space-4); }
}
@media (max-width: 48rem) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .topbar-search { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
/* Settings -> Branding: the live preview sits on a sidebar-coloured strip, as it will be shown. */
.brand-preview { background: var(--bg-sidebar); border-radius: var(--radius-md); padding: var(--space-3); }

/* Record "⋯" menu in a page title: rarely-used, destructive actions (deactivate, delete).
   Each item opens its own dialog, so the action is done in a focused window. */
.record-menu { position: relative; display: inline-flex; }
.record-menu-toggle { min-width: 2.5rem; font-size: var(--text-lg); line-height: 1; letter-spacing: 0.05em; }
.record-menu-list {
  position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: 30; min-width: 14rem;
  display: flex; flex-direction: column; padding: var(--space-1);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
}
.record-menu-list[hidden] { display: none; }
.record-menu-item {
  display: block; width: 100%; text-align: left; padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: inherit; font-size: var(--text-sm); cursor: pointer;
}
.record-menu-item:hover, .record-menu-item:focus-visible { background: var(--bg-muted); }
a.record-menu-item { text-decoration: none; }
.record-menu-item.danger { color: var(--danger-600); }
.record-menu-item.danger:hover, .record-menu-item.danger:focus-visible { background: var(--danger-50); }

.modal {
  width: min(30rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: var(--scrim); }
.modal > form { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); }
.modal h2 { margin: 0; font-size: var(--text-lg); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }

/* List filter bars: search stays in the bar; the other filters sit in a floating
   panel behind a "Filters" button (app.js enhanceFilters). */
.filters.filters-compact { align-items: flex-end; }
.filters.filters-compact > .field { flex: 1 1 18rem; max-width: 36rem; }
.filter-toggle { position: relative; display: inline-flex; }
.filter-count {
  display: inline-grid; place-items: center; min-width: 1.35rem; height: 1.35rem; margin-left: var(--space-2); padding: 0 0.3rem;
  border-radius: var(--radius-pill); background: var(--primary-600); color: var(--text-on-primary); font-size: var(--text-xs); font-weight: 700;
}
.filter-panel {
  position: absolute; top: calc(100% + var(--space-2)); left: 0; z-index: 40; width: min(34rem, calc(100vw - 2rem));
  display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.filter-panel[hidden] { display: none; }
.filter-panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: var(--space-3); }
.filter-panel .modal-actions { margin-top: 0; }
@media (max-width: 40rem) {
  .filter-panel { position: fixed; top: auto; bottom: var(--space-3); left: var(--space-3); right: var(--space-3); width: auto; max-height: 75vh; overflow: auto; }
}

/* List pages: title, then search + Filters, then the page's own buttons - one row. */
.page-head.list-head { align-items: center; flex-wrap: wrap; justify-content: flex-start; }
.page-head.list-head > h1 { margin: 0; }
.page-head.list-head > .filters { flex: 1 1 22rem; padding: 0; align-items: center; flex-wrap: nowrap; min-width: 0; }
.page-head.list-head > .filters > .field { flex: 1 1 auto; max-width: 30rem; }
.page-head.list-head > .filters > .field > label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.page-head.list-head > .row-start { margin-left: auto; }
.page-head.list-head .filter-panel { left: auto; right: 0; }
@media (max-width: 40rem) {
  .page-head.list-head > .filters { flex-basis: 100%; order: 3; }
}

/* Long notes in a table: two lines, the whole note on hover/focus (title) - keeps rows short. */
.clamp-2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.clamp-2:focus { -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }
table.data td.notes-cell { min-width: 14rem; max-width: 30rem; color: var(--text-muted); }
/* Billing controls on one line: bill no., Billed, Received, Save. */
table.data td.billing-cell { white-space: nowrap; }
table.data td.billing-cell .billing-form { flex-wrap: nowrap; }
table.data td.billing-cell .input-sm { width: 8rem; }
table.data td.billing-cell [data-billing-error]:empty { display: none; }
table.data td.billing-cell [data-billing-error] { white-space: normal; }

/* Transaction details window: a bit wider, notes keep their line breaks. */
.modal.modal-wide { width: min(38rem, calc(100vw - 2rem)); }
/* Big windows (record a transaction, log a support call): a title row with ✕, then the forms. */
.modal.modal-xl { width: min(56rem, calc(100vw - 2rem)); }
.modal > .modal-body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); }
.modal .modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.modal .tx-actions { border-top: 0; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Sortable list headers are links (the server sorts the whole list); they look like headers. */
table.data th .th-sort { color: inherit; text-decoration: none; display: inline-flex; gap: 0.2em; }
table.data th .th-sort:hover { color: var(--text-strong); text-decoration: underline; }
table.data th[aria-sort] .th-sort { color: var(--text-strong); }
