/* Budget App - the design system (step 5.1, briefing section 3).
   The one place values live outside config.py: colour, type, spacing, radius,
   elevation are tokens here, used everywhere below. Branding is deferred: a
   neutral palette, no logo, the app name as text. */

:root {
  /* colour */
  --canvas: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ee;
  --border-strong: #cdd5df;
  --ink: #1b2733;
  --ink-2: #364152;
  --muted: #5b6b7b;
  --faint: #8a97a6;
  --primary: #2457d6;
  --primary-hover: #1b45ad;
  --primary-soft: #eef3ff;
  --focus: #9db4ff;
  --danger: #b42318;   --danger-bg: #fee4e2;   --danger-line: #fecdca;
  --warning: #b54708;  --warning-bg: #fef0c7;  --warning-line: #fedf89;
  --success: #067647;  --success-bg: #d1fadf;  --success-line: #a6f4c5;
  --info: #175cd3;     --info-bg: #e0ecff;     --info-line: #c2d6ff;
  --neutral: #364152;  --neutral-bg: #eef2f6;  --neutral-line: #dde3ea;
  --violet: #5925dc;   --violet-bg: #ebe9fe;
  --log-bg: #101828;   --log-ink: #d0d5dd;
  /* type */
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;
  --fs-meta: 13px; --fs-body: 14px; --fs-lead: 16px; --fs-card: 20px; --fs-page: 28px;
  --lh: 1.45;
  /* space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* shape */
  --r-control: 8px; --r-card: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --shadow-lift: 0 4px 8px -2px rgba(16,24,40,.1), 0 2px 4px -2px rgba(16,24,40,.06);
  --shadow-float: 0 12px 24px -4px rgba(16,24,40,.12), 0 4px 8px -4px rgba(16,24,40,.06);
  --rail: 232px;
  --topbar: 76px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font: var(--fs-body)/var(--lh) var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); border-radius: var(--r-control); }
.mono { font-family: var(--mono); font-size: .95em; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-meta); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.break { word-break: break-all; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; display: inline-block; vertical-align: -0.2em; }

/* ---- the shell: the rail, the top bar, the content column ------------------ */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.tenant {
  display: flex; flex-direction: column; gap: 1px; margin: 0 4px 18px; padding: 9px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control);
}
.tenant-label { font-size: 11.5px; color: var(--faint); font-weight: 600; letter-spacing: .02em; }
.tenant-name { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 12px;
  border-radius: var(--r-control); color: var(--muted); font-weight: 500; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--canvas); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active .icon { color: var(--primary); }
.nav-label { flex: 1; }
.nav-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: 11.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.rail-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--faint); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar); display: flex; align-items: center;
  justify-content: space-between; gap: var(--s4); padding: 0 var(--s6);
  background: rgba(244,246,248,.88); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: var(--fs-page); font-weight: 650; letter-spacing: -.02em; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { width: 100%; max-width: 1264px; padding: var(--s5) var(--s6) 64px; display: flex; flex-direction: column; gap: var(--s5); }

/* loading: a thin bar under the top bar while htmx is talking to the server */
.loading-bar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; opacity: 0; transition: opacity .15s; }
.loading-bar::after { content: ""; position: absolute; top: 0; left: -40%; width: 40%; height: 100%; background: var(--primary); border-radius: 2px; animation: slide 1s ease-in-out infinite; }
.loading-bar.htmx-request { opacity: 1; }
@keyframes slide { from { left: -40%; } to { left: 100%; } }

/* the readiness pill */
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 14px 0 12px; flex: none;
  border-radius: 999px; font-weight: 600; font-size: 13.5px; border: 1px solid transparent; white-space: nowrap;
}
.pill:empty { display: none; }
.pill a { color: inherit; }
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-success { background: var(--success-bg); color: var(--success); border-color: var(--success-line); }
.pill-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.pill-muted { background: var(--neutral-bg); color: var(--muted); border-color: var(--neutral-line); }
.pill-muted .pill-dot { animation: blink 1.2s ease-in-out infinite; }
.pill-neutral { background: var(--surface); color: var(--muted); border-color: var(--border); }
@keyframes blink { 50% { opacity: .25; } }

/* ---- layout helpers ----------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s4); }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.section { display: flex; flex-direction: column; gap: var(--s3); }
.section-title { font-size: var(--fs-lead); font-weight: 650; }
.lead { font-size: var(--fs-lead); color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.lead .icon { color: var(--success); }
.lead-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.inbox-line { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.inbox-line .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: var(--s2); }
.back-link { font-size: var(--fs-meta); }
.back-link a { color: var(--muted); }
.after-note { margin-top: calc(-1 * var(--s2)); }

/* ---- cards ---------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 20px 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-title { font-size: var(--fs-card); font-weight: 650; letter-spacing: -.01em; }
.link-arrow { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-meta); font-weight: 600; color: var(--primary); }
.table-card { padding: 0; overflow: clip; }

/* stat cards */
.stat { display: flex; flex-direction: column; gap: 4px; padding: 18px 22px; }
.stat-label { font-size: var(--fs-meta); color: var(--muted); font-weight: 500; }
.stat-value { font-size: var(--fs-page); font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-value-sm { font-size: var(--fs-card); line-height: 1.6; }
.stat-hint { font-size: var(--fs-meta); color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 2px 0 6px; }
.dot:first-child { margin-left: 0; }
.dot-success { background: var(--success); } .dot-danger { background: var(--danger); } .dot-neutral { background: var(--faint); }

/* "what needs you" */
.needs-group { display: flex; flex-direction: column; gap: var(--s2); }
.needs-group + .needs-group { margin-top: var(--s4); }
.needs-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.needs-list a { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 9px 12px; border-radius: var(--r-control); }
.needs-list a:hover { background: var(--surface-2); text-decoration: none; }
.count { min-width: 28px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.count-danger { background: var(--danger-bg); color: var(--danger); }
.count-warning { background: var(--warning-bg); color: var(--warning); }
.count-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* the three actions */
.actions-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s4); }
.action-tile-form { display: contents; }
.action-tile {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow);
  font: inherit; color: var(--ink); cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s;
}
.action-tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lift); text-decoration: none; transform: translateY(-1px); }
.action-tile > .icon { color: var(--faint); }
.action-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.action-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.action-title { font-weight: 650; }
.action-hint { font-size: var(--fs-meta); color: var(--muted); }

/* ---- tables ------------------------------------------------------------------------------ */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-body); }
.table th {
  text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 11px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th.num, .table td.num { text-align: right; }
.table-sticky thead th { position: sticky; top: var(--topbar); z-index: 2; }
.table-card .table-sticky { border-radius: var(--r-card); }
.table.compact td, .table.compact th { padding: 8px 12px; }
.table-empty { text-align: center; padding: 28px 16px !important; }
.key-cell { max-width: 280px; overflow-wrap: anywhere; }
.nominal { display: flex; flex-direction: column; line-height: 1.3; }
.nominal-code { font-size: 12.5px; color: var(--ink-2); }
.nominal-name { font-size: var(--fs-meta); color: var(--muted); }
.how-cell { white-space: nowrap; }
.how-cell .small { margin-left: 6px; }
.how-cell .pending { margin: 6px 0 0; display: flex; align-items: center; gap: 6px; color: var(--success); white-space: normal; }
.more-row td { background: var(--surface) !important; }
.more { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.report-link { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.report-link .icon { color: var(--faint); }

/* ---- badges --------------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap; line-height: 1; letter-spacing: .01em;
}
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 1.2s ease-in-out infinite; }

/* ---- buttons and inputs ----------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px;
  border-radius: var(--r-control); border: 1px solid transparent; font: 600 var(--fs-body)/1 var(--font);
  cursor: pointer; white-space: nowrap; text-decoration: none !important; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(16,24,40,.08); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(16,24,40,.05); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-soft { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
.btn-danger-soft:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled, .btn.htmx-request { opacity: .6; cursor: progress; }
.icon-btn { width: 34px; height: 34px; border-radius: var(--r-control); border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--canvas); color: var(--ink); }

.input {
  height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink); font: var(--fs-body)/1.3 var(--font); min-width: 0;
  transition: border-color .12s, box-shadow .12s; box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.input.mono { font-family: var(--mono); font-size: 13px; }
select.input { padding-right: 32px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235b6b7b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
.textarea { height: auto; min-height: 64px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.input-sm { height: 30px; font-size: 13px; padding: 0 9px; }
select.input-sm { padding-right: 28px; background-position: right 9px center; }
.num-input { width: 90px; }
.note-input { width: 150px; }
.check, .radio { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-body); }
.check input, .radio input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field-label { font-size: var(--fs-meta); font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: 12.5px; color: var(--muted); }
.field-hint.picked { color: var(--success); font-weight: 600; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: 14px; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.search { position: relative; flex: 1; min-width: 260px; max-width: 460px; display: flex; align-items: center; }
.search .icon { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }
.search-input { width: 100%; padding-left: 36px; }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

/* ---- banners, empty, error, done ------------------------------------------------------------- */
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 1px solid transparent; font-size: var(--fs-body); }
.banner .icon { margin-top: 1px; }
.banner-text { min-width: 0; overflow-wrap: anywhere; }
.banner-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.banner-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-line); }
.banner-success { background: var(--success-bg); color: var(--success); border-color: var(--success-line); }
.banner-info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }
.banner-muted { background: var(--neutral-bg); color: var(--ink-2); border-color: var(--neutral-line); }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 56px 24px; }
.empty-glyph { width: 56px; height: 56px; border-radius: 16px; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.empty-text { font-size: var(--fs-lead); font-weight: 600; max-width: 520px; }
.empty-note { font-size: var(--fs-meta); color: var(--muted); max-width: 520px; }
.empty .btn { margin-top: 6px; }
.error-card { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; max-width: 720px; }
.error-glyph { width: 52px; height: 52px; border-radius: 14px; background: var(--danger-bg); color: var(--danger); display: flex; align-items: center; justify-content: center; }
.error-line { font-family: var(--mono); font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control); padding: 10px 12px; width: 100%; overflow-wrap: anywhere; }
.done-state { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 10px; background: var(--success-bg); color: var(--success); border: 1px solid var(--success-line); }
.done-state p { flex: 1; font-weight: 600; }
.done-glyph { display: inline-flex; }
.hint-line { display: flex; align-items: center; gap: 6px; font-size: var(--fs-meta); color: var(--warning); margin: 8px 0 12px; }
.confidential { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-line); font-size: var(--fs-meta); font-weight: 500; }

/* ---- the busy state --------------------------------------------------------------------------- */
.busy { display: flex; flex-direction: column; gap: var(--s4); border-color: var(--neutral-line); background: linear-gradient(180deg, #fbfcfd, var(--surface)); }
.busy-head { display: flex; gap: 14px; align-items: flex-start; }
.busy-title { font-weight: 650; font-size: var(--fs-lead); }
.busy-line { font-size: 13px; color: var(--ink-2); margin: 2px 0; overflow-wrap: anywhere; }
.busy-spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--neutral-bg); border-top-color: var(--primary); animation: spin .8s linear infinite; flex: none; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- the job panel ------------------------------------------------------------------------------ */
.job-panel { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--r-card); background: var(--surface); }
.card .job-panel, .busy .job-panel { box-shadow: none; }
#job-area > .job-panel, .content > .job-panel { box-shadow: var(--shadow); }
.job-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.job-title { display: flex; align-items: center; gap: 10px; }
.job-kind { font-weight: 650; font-size: var(--fs-lead); }
.job-id { font-size: 12px; color: var(--faint); }
.job-stage { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-body); }
.job-stage-name { font-weight: 600; color: var(--ink-2); }
.progress { height: 8px; border-radius: 999px; background: var(--neutral-bg); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .5s ease; min-width: 8px; }
.progress-success > span { background: var(--success); }
.progress-danger > span { background: var(--danger); }
.progress-warning > span { background: var(--warning); }
.progress-neutral > span { background: var(--faint); }
.progress-live > span { background-image: linear-gradient(90deg, rgba(255,255,255,0) 0, rgba(255,255,255,.35) 50%, rgba(255,255,255,0) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 6px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.chip-value { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.chip-label { font-size: var(--fs-meta); color: var(--muted); }
.chip-danger { background: var(--danger-bg); border-color: var(--danger-line); }
.chip-danger .chip-value, .chip-danger .chip-label { color: var(--danger); }
.chip-warning { background: var(--warning-bg); border-color: var(--warning-line); }
.chip-warning .chip-value, .chip-warning .chip-label { color: var(--warning); }
.chip-success { background: var(--success-bg); border-color: var(--success-line); }
.chip-success .chip-value, .chip-success .chip-label { color: var(--success); }
.log-box > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: var(--fs-meta); font-weight: 600; color: var(--primary); padding: 2px 0; }
.log-box > summary::-webkit-details-marker { display: none; }
.log { margin: 8px 0 0; padding: 14px 16px; border-radius: 10px; background: var(--log-bg); color: var(--log-ink); font: 12.5px/1.55 var(--mono); max-height: 340px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; display: flex; flex-direction: column-reverse; }
.log-lines { display: block; }
.log-lines > span { display: block; }
.failure-line { margin-top: 4px; color: var(--danger); opacity: .9; }
.log .log-err { color: #fda29b; }
.log .log-ok { color: #a6f4c5; }
.job-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.job-actions { display: flex; gap: var(--s2); }
.job-actions form { display: inline-flex; }
.job-none { padding: 6px 0; }
.job-link { display: flex; flex-direction: column; gap: 1px; }
.job-kind-sm { font-weight: 600; }
.job-data pre.json-tall { max-height: 520px; }

/* ---- import ------------------------------------------------------------------------------------ */
.upload { display: flex; flex-direction: column; gap: var(--s3); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 220px;
  padding: 32px; border: 2px dashed var(--border-strong); border-radius: var(--r-card); background: var(--surface-2);
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-glyph { width: 60px; height: 60px; border-radius: 18px; background: var(--surface); color: var(--primary); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); margin-bottom: 6px; }
.dropzone-title { font-size: var(--fs-lead); font-weight: 650; }
.dropzone-or { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: var(--fs-meta); }
.dropzone-hint { font-size: var(--fs-meta); color: var(--faint); }
.upload-busy { display: none; font-size: var(--fs-meta); color: var(--primary); font-weight: 600; }
.upload-busy.htmx-request { display: block; }
.upload-result { margin-top: var(--s3); display: flex; flex-direction: column; gap: 8px; }
.upload-summary { font-weight: 600; }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-control); background: var(--success-bg); color: var(--success); font-size: 13.5px; }
.file-refused { background: var(--danger-bg); color: var(--danger); }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.file-note { font-size: 12.5px; text-align: right; }
.file-icon { display: inline-flex; }
.dedup { margin-top: var(--s3); }
.run-card { display: flex; flex-direction: column; gap: var(--s3); }
.run-form { display: flex; flex-direction: column; gap: var(--s4); }
.run-option { display: flex; flex-direction: column; gap: 8px; padding-top: var(--s4); border-top: 1px solid var(--border); }

/* ---- review: groups, kinds, the drawer, the item --------------------------------------------- */
.queue { display: flex; flex-direction: column; gap: var(--s6); }
.group { display: flex; flex-direction: column; gap: var(--s3); }
.group-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.group-title { font-size: var(--fs-card); font-weight: 650; letter-spacing: -.01em; }
.group-danger .group-title::before, .group-warning .group-title::before, .group-neutral .group-title::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 10px; vertical-align: 2px; }
.group-danger .group-title::before { background: var(--danger); }
.group-warning .group-title::before { background: var(--warning); }
.group-neutral .group-title::before { background: var(--faint); }
.group-hint { color: var(--muted); font-size: var(--fs-meta); }
.group-empty { display: flex; align-items: center; gap: 8px; color: var(--success); font-weight: 600; padding: 14px 18px; border: 1px dashed var(--success-line); border-radius: var(--r-card); background: #f6fef9; }
.kind { padding: 0; overflow: clip; }
.kind-head { list-style: none; display: flex; align-items: center; gap: 14px; padding: 15px 20px; cursor: pointer; }
.kind-head::-webkit-details-marker { display: none; }
.kind-head:hover { background: var(--surface-2); }
.chevron { width: 8px; height: 8px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; flex: none; margin: 0 4px; }
.kind[open] .chevron { transform: rotate(45deg); }
.kind-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.kind-label { font-weight: 650; }
.kind-desc { font-size: var(--fs-meta); color: var(--muted); }
.kind-actions { font-size: 12.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.kind[open] .kind-head { border-bottom: 1px solid var(--border); }
.table-items td { padding: 10px 20px; }
.table-items .ident { width: 1%; white-space: nowrap; color: var(--muted); font-size: 12.5px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.item-link { display: block; color: var(--ink); }
.item-link:hover { color: var(--primary); }
.kind-fix, .kind-more { display: flex; gap: 8px; align-items: flex-start; padding: 12px 20px; font-size: var(--fs-meta); color: var(--muted); border-top: 1px solid var(--border); background: var(--surface-2); }
.kind-fix .icon { color: var(--warning); margin-top: 1px; }

.backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.32); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 94vw); background: var(--surface); z-index: 31;
  box-shadow: -16px 0 32px -8px rgba(16,24,40,.18); transform: translateX(104%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  overflow-y: auto; overscroll-behavior: contain;
}
.drawer:has(.item) { transform: none; }
body:has(.drawer .item) .backdrop { opacity: 1; pointer-events: auto; }
body:has(.drawer .item) { overflow: hidden; }
.drawer .item { padding: 22px 26px 40px; }
.item { display: flex; flex-direction: column; gap: var(--s5); }
.item-page .item { gap: var(--s5); }
.item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); }
.drawer .item-head { position: sticky; top: -22px; margin: -22px -26px 0; padding: 22px 26px 16px; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); z-index: 2; }
.item-head-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.item-head-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.eyebrow { font-size: 12.5px; font-weight: 650; color: var(--primary); letter-spacing: .01em; }
.item-title { font-size: 18px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.item-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: var(--fs-meta); }
.item-section { display: flex; flex-direction: column; gap: var(--s3); }
.item-section-title { font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.fix-hint { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-line); font-size: var(--fs-meta); }
.fix-hint strong { display: block; margin-bottom: 2px; }
.action-form { border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px 18px; background: var(--surface); box-shadow: var(--shadow); }
.action-head { margin-bottom: 14px; }
.action-title { font-size: 15px; font-weight: 650; }
.action-hint { font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; }
.kv { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr); gap: 0; margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.kv dt, .kv dd { margin: 0; padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv dt { color: var(--muted); font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); overflow-wrap: anywhere; }
.kv dd { overflow-wrap: anywhere; }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: 0; }
pre.json { margin: 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control); font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 300px; overflow: auto; }
.kv pre.json { border: 0; padding: 0; background: transparent; }

/* ---- settings, backups ---------------------------------------------------------------------- */
.settings, .backups { display: flex; flex-direction: column; gap: var(--s4); }
.setting-key { font-weight: 600; color: var(--ink); }
.setting-note { color: var(--ink-2); margin-top: 2px; }
.setting-value { margin-right: 8px; }
.value-cell { white-space: nowrap; }
.change-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.change-cell .inline-form { flex-wrap: nowrap; }
.change-cell input.input-sm[type=text]:not(.note-input) { width: 150px; }
.change-cell .note-input { width: 130px; }
.settings-table td { vertical-align: top; }
.tables-cell { display: flex; flex-wrap: wrap; gap: 4px; max-width: 420px; }
.table-chip { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.workbook-card { display: flex; flex-direction: column; gap: 8px; align-self: start; }
.workbook-name { font-weight: 600; overflow-wrap: anywhere; }

/* ---- a rendered report ---------------------------------------------------------------------- */
.prose { padding: 32px 40px; line-height: 1.6; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 16px; line-height: 1.25; }
.prose h2 { font-size: 19px; margin: 32px 0 12px; padding-top: 20px; border-top: 1px solid var(--border); }
.prose h3 { font-size: 16px; margin: 24px 0 8px; }
.prose h4 { font-size: 14px; margin: 18px 0 6px; }
.prose p, .prose ul, .prose ol { margin: 0 0 12px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose a { color: var(--primary); }
.prose code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
.prose pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow: auto; margin: 0 0 14px; }
.prose pre code { border: 0; padding: 0; background: transparent; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 6px 0 18px; font-size: 13px; }
.prose th, .prose td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.prose tr:nth-child(even) td { background: #fbfcfd; }
.prose blockquote { margin: 0 0 14px; padding: 8px 14px; border-left: 3px solid var(--info-line); background: var(--info-bg); color: var(--ink-2); border-radius: 0 8px 8px 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

/* ---- toasts ------------------------------------------------------------------------------------ */
#toasts { position: fixed; right: 24px; bottom: 24px; z-index: 60; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; min-width: 300px; max-width: 440px;
  padding: 13px 14px 13px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--success); box-shadow: var(--shadow-float); font-size: 13.5px; color: var(--ink-2);
  animation: toast-in .22s cubic-bezier(.2,.8,.2,1);
}
.toast-danger { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-body { flex: 1; min-width: 0; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 2px; }
.toast-first { font-weight: 650; color: var(--ink); }
.toast-close { border: 0; background: transparent; color: var(--faint); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
.toast-close:hover { color: var(--ink); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* =================================================================================================
   step 5.2 - the figures, the drill-down, the statement page. Extends the system above; no new
   colours: the primary for links and the highlight, success / danger / muted for the checks.
   ================================================================================================= */
.nowrap { white-space: nowrap; }
.actions-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.banner-link { margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 4px; font-weight: 650; color: inherit; white-space: nowrap; }
.banner-pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; }
.btn.disabled { opacity: .45; pointer-events: none; }
.section-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }

/* the toolbar and the tabs */
.figures-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; padding: 16px 20px; }
.figures-toolbar input[type=date] { width: 158px; }
.figures-toolbar .field-sub select { width: 230px; }
.toolbar-check { height: 36px; }
.toolbar-buttons { display: flex; gap: var(--s2); margin-left: auto; }
.tabs-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 2px; }
.tab { padding: 10px 14px 11px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.excel-card { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); min-width: 0; }
.excel-icon { color: var(--success); display: inline-flex; }
.excel-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.excel-label { font-size: 11.5px; font-weight: 650; color: var(--faint); letter-spacing: .02em; }
.excel-name { font-size: 12.5px; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }

/* the headline */
.headline { display: flex; flex-direction: column; gap: var(--s3); }
.headline-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.headline .stat-value { font-size: 26px; }
.bridge { max-width: 1000px; }
.filtered-line { font-size: 13.5px; color: var(--ink-2); font-weight: 600; }

/* a statement: indent by level, the kind's weight and border, the first column sticky */
.statement-scroll { overflow-x: auto; }
.statement { font-size: 13.5px; }
.statement th, .statement td { padding: 7px 14px; white-space: nowrap; }
.statement th.st-label, .statement td.st-label { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 300px; max-width: 460px; white-space: normal; box-shadow: 1px 0 0 var(--border); }
.statement th.st-label { background: var(--surface-2); z-index: 2; }
.statement tbody tr:hover td.st-label { background: var(--surface-2); }
.statement .st-code { color: var(--faint); font-size: 11.5px; }
.statement td.st-total-col, .statement th.st-total-col { box-shadow: inset 1px 0 0 var(--border); font-weight: 600; }
.lvl-0 { padding-left: 14px !important; } .lvl-1 { padding-left: 30px !important; } .lvl-2 { padding-left: 46px !important; }
.lvl-3 { padding-left: 62px !important; } .lvl-4 { padding-left: 78px !important; } .lvl-5 { padding-left: 94px !important; }
.lvl-6 { padding-left: 110px !important; } .lvl-7 { padding-left: 126px !important; }
.st-heading td { color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .03em; padding-top: 14px; }
.st-top td, .st-subtotal td, .bva-section td, .bva-subtotal td { font-weight: 650; }
.st-subtotal td, .bva-subtotal td { border-top: 1px solid var(--border-strong); }
.statement tbody tr.st-total td, .statement tbody tr.bva-total td { border-top: 1px solid var(--ink-2); border-bottom: 3px double var(--ink-2); font-weight: 700; }
.st-check td { color: var(--muted); font-style: italic; }
.st-blank td { padding: 3px; border-bottom: 0; }
.bva-heading td { color: var(--muted); font-style: italic; }
/* not .group-head / .sub-head: the review queue owns .group-head (display: flex) */
.bva th.period-head { text-align: center; border-bottom: 0; padding-bottom: 2px; }
.bva .measure-head { font-size: 11.5px; padding-top: 2px; }
.no-budget { color: var(--faint); font-style: italic; font-size: 12px; }
.mark-cell { text-align: center; }
.fig-link { color: var(--primary); font-weight: 500; }
.fig-link:hover { text-decoration: underline; }
.meta-line { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-meta); color: var(--muted); }
.window-note { max-width: 1000px; }

/* the states: not ready, refused, failed checks */
.notready, .refusal-card { display: flex; flex-direction: column; gap: var(--s4); }
.notready-head { display: flex; gap: var(--s4); align-items: center; }
.notready-head .empty-glyph { margin: 0; flex: none; }
.notready-form { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }

/* checks & notes, the commentary */
.checks-table .check-id { width: 1%; white-space: nowrap; font-weight: 650; }
.checks-table .check-result { white-space: nowrap; }
.fail-line { color: var(--danger); margin-top: 4px; white-space: normal; }
.notes-list { display: grid; grid-template-columns: minmax(150px, 210px) minmax(0, 1fr); gap: 10px 22px; margin: 0; }
.notes-list dt { font-weight: 650; }
.notes-list dd { margin: 0; color: var(--ink-2); }
.comment { display: flex; flex-direction: column; gap: 10px; }
.comment .card-head { margin-bottom: 0; }
.comment-title { font-size: 15px; font-weight: 650; }

/* the drill-down */
.drill-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s4); flex-wrap: wrap; }
.drill-title { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.drill-what { font-size: var(--fs-lead); font-weight: 650; overflow-wrap: anywhere; }
.drill-tools { display: flex; gap: 10px; align-items: center; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-control); overflow: hidden; background: var(--surface); }
.seg { padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg + .seg { border-left: 1px solid var(--border-strong); }
.seg:hover { text-decoration: none; color: var(--ink); }
.seg.active { background: var(--primary-soft); color: var(--primary); }
.drill-table td { padding: 9px 14px; }
.d-desc { min-width: 220px; }
.page-link { color: var(--primary); display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.unverified { color: var(--warning); }
.more-actions { display: flex; gap: var(--s2); }
.drill-totals { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--ink-2); }
/* the CLI's own lines, its spacing kept */
.drill-title p, .drill-totals p { white-space: pre-wrap; }
.drill-figure { font-weight: 650; color: var(--ink); }

/* the statement page */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.page-head-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-name { font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.page-nav { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.page-count { padding: 0 4px; }
.row-card { display: flex; flex-direction: column; gap: 10px; border-left: 4px solid var(--primary); }
.row-data { display: flex; flex-wrap: wrap; gap: 8px 32px; margin: 0; }
.row-data dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.row-data dd { margin: 0; font-size: 15px; font-weight: 600; }
.row-desc { min-width: 240px; }
.original-note { display: flex; align-items: center; gap: 6px; font-size: var(--fs-meta); color: var(--warning); font-weight: 600; }
.page-viewer { padding: 18px; overflow: auto; background: var(--neutral-bg); }
.page-image { display: block; margin: 0 auto; max-width: none; height: auto; background: var(--surface); box-shadow: var(--shadow-lift); }
.page-foot { display: flex; justify-content: flex-end; }

/* ---- narrow windows ------------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .span-3, .span-4 { grid-column: span 6; }
  .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .actions-row { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .span-3, .span-4 { grid-column: span 12; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =================================================================================================
   step 5.3 - the firm console (the matters) and a matter's way back to it. Extends the system
   above; no new colours, no new tokens.
   ================================================================================================= */
.matters { display: flex; flex-direction: column; gap: var(--s4); }
.matters-new { padding: 18px 24px; }
.matters-new-form { display: flex; align-items: flex-start; gap: var(--s4); flex-wrap: wrap; }
.matters-new-field { flex: 1; min-width: 260px; max-width: 560px; }
.matters-new-form > .btn { margin-top: 26px; }
.matter-number { font-weight: 700; font-size: 15px; color: var(--ink); }
.matter-ref { flex-wrap: nowrap; }
.matter-ref .input { width: 200px; }
.matter-data { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.matter-port { margin-left: 6px; }
.matter-actions { white-space: nowrap; text-align: right; }
.matter-actions form { display: inline-flex; margin-left: 6px; }
.matters-tail .log { margin-top: 6px; max-height: 180px; }
/* the matter's rail: "Matters", back to the console, above Home - a line under it */
.nav-back { position: relative; margin-bottom: 9px; }
.nav-back::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -6px; border-top: 1px solid var(--border); }

/* =================================================================================================
   step 5.5a - the Accounts page: the coverage grid (one square per account per month,
   review/coverage.py) and one card per account with its decisions. Extends the system above; the
   squares take the status tones - solid for what a statement says (verified, accepted, read not
   proven, failed), outlined for what no statement says (missing, partly covered, outside).
   ================================================================================================= */
.coverage-card { padding: 20px 0 16px; }
.coverage-card .card-head { padding: 0 24px; flex-wrap: wrap; }
.cov-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-meta); color: var(--muted); }
.cov-legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cov-scroll { overflow-x: auto; margin-bottom: var(--s3); }
.cov-grid { border-collapse: separate; border-spacing: 0; font-size: var(--fs-meta); }
.cov-grid th, .cov-grid td { padding: 4px 3px; text-align: center; white-space: nowrap; }
.cov-grid thead th { font-size: 11.5px; font-weight: 600; color: var(--faint); padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.cov-grid thead .cov-month-year { color: var(--ink-2); }
.cov-grid .cov-account {
  position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 500;
  padding: 4px 16px 4px 24px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border);
}
.cov-grid tbody .cov-account a { color: var(--ink); }
.cov-grid tbody .cov-account .badge { margin-left: 6px; height: 18px; font-size: 11px; }
.cov-grid tbody tr:hover th, .cov-grid tbody tr:hover td { background: var(--surface-2); }
.cov-grid .cov-note { text-align: left; padding-left: 12px; }
.cov { display: inline-block; width: 16px; height: 16px; border-radius: 3px; vertical-align: middle; flex: none; }
a.cov:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--focus); }
.cov-verified { background: var(--success); }
.cov-accepted { background: var(--muted); }
.cov-unverified { background: var(--warning); }
.cov-failed { background: var(--danger); }
.cov-partial { background: linear-gradient(135deg, var(--warning) 50%, var(--surface) 50%); box-shadow: inset 0 0 0 1.5px var(--warning); }
a.cov-partial:hover { box-shadow: inset 0 0 0 1.5px var(--warning), 0 0 0 2px var(--focus); }
.cov-missing { background: var(--danger-bg); box-shadow: inset 0 0 0 1.5px var(--danger); }
a.cov-missing:hover { box-shadow: inset 0 0 0 1.5px var(--danger), 0 0 0 2px var(--focus); }
.cov-outside { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.cov-foot { padding: 0 24px; }
.cov-foot + .cov-foot { margin-top: 4px; }
/* the cards */
.account-cards { display: flex; flex-direction: column; gap: var(--s4); }
.account-card { display: flex; flex-direction: column; gap: var(--s4); scroll-margin-top: calc(var(--topbar) + 12px); }
.account-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.account-title { font-size: var(--fs-card); font-weight: 650; letter-spacing: -.01em; }
.account-subtitle { font-size: var(--fs-body); font-weight: 500; }
.account-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.account-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--s4); align-items: start; }
.decision { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.decision-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 2px; }
.decision-note { color: var(--ink-2); overflow-wrap: anywhere; }
.account-facts a { color: var(--primary); font-weight: 500; }
.account-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--s3); }
.account-form { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.account-form .action-head { margin-bottom: 0; }
.account-form .form-actions { margin-top: auto; }
/* Home: the Accounts card opens the page */
.stat-link { color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.stat-link:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-lift); }
@media (max-width: 1100px) { .account-body { grid-template-columns: 1fr; } }

/* =================================================================================================
   step 5.5b - the Outputs page: four cards in a 2x2 grid (one column below 1100px, as every
   .span-6), each with what it is, its newest file and one action; the budget card re-rendered
   whole by htmx. Extends the system above; no new colours, no new tokens.
   ================================================================================================= */
.outputs-grid { align-items: stretch; }
.output-card { display: flex; flex-direction: column; gap: var(--s3); }
.output-head { display: flex; align-items: center; gap: 10px; color: var(--primary); }
.output-head .card-title { color: var(--ink); }
.output-lead { margin-top: -4px; }
.output-block { display: flex; flex-direction: column; gap: 8px; }
.output-label { font-size: 11.5px; font-weight: 650; color: var(--faint); letter-spacing: .02em; text-transform: uppercase; }
.output-file { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.output-file + .output-file { margin-top: 6px; }
.output-file-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.output-name { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; color: var(--ink); }
.pack-summary { color: var(--ink-2); }
.pack-gaps ul { margin: 2px 0 0; padding-left: 18px; }
.pack-foreign { color: var(--warning); font-weight: 600; }
.output-older summary { cursor: pointer; font-size: var(--fs-meta); color: var(--muted); margin: 4px 0; }
.output-form { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; border-top: 1px solid var(--border); }
.output-form .fields { margin-top: 10px; }
.output-card > .form-actions { margin-top: auto; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row .input { flex: 1; min-width: 0; }
.key-note { display: flex; align-items: flex-start; gap: 8px; margin-top: auto; padding: 10px 12px; border-radius: 10px; background: var(--warning-bg); border: 1px solid var(--warning-line); color: var(--ink-2); }
.key-note .icon { color: var(--warning); flex: none; margin-top: 1px; }
.key-command { white-space: nowrap; font-size: 12px; }
.budget-versions { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.budget-versions li { display: flex; flex-direction: column; gap: 1px; }
.budget-version { font-weight: 600; font-size: 13.5px; }
.budget-upload, .proposal-form { display: flex; flex-direction: column; gap: 8px; }
.proposal-form { flex-direction: row; align-items: flex-end; gap: var(--s3); flex-wrap: wrap; }
.proposal-form .field { min-width: 140px; }
@media (max-width: 760px) { .output-file { flex-direction: column; } }

/* step 5.6 - the private address (the firm console's rows) and what arrived by mail (Import) */
.address-note { display: flex; flex-direction: column; gap: 2px; margin: 0 0 var(--s3); }
.address-note p { margin: 0; }
.address-line { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.address-text { font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; user-select: all; }
.by-mail-files { display: flex; flex-direction: column; gap: 2px; }
.by-mail-files .hint-line { margin: 4px 0 0; }
.matters-table tr:has(+ .matter-address-row) td { border-bottom: 0; padding-bottom: 2px; }
.matter-address-row td { padding-top: 0; }
.matters-table tr:hover + .matter-address-row td, .matters-table tr:has(+ .matter-address-row:hover) td { background: var(--surface-2); }

/* ---- step 4b.8a: the budget folder's workbooks ("Use this workbook"); an unreadable database ---- */
.budget-candidates { margin-top: 12px; }
.budget-candidate-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.budget-candidate { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.budget-candidate-name { font-weight: 600; overflow-wrap: anywhere; }
.budget-candidate form { margin-left: auto; }
.busy-unreadable { border-color: var(--danger-line); }
.busy-unreadable .busy-title { color: var(--danger); }

/* step 5.4a - the firm console's Licence and Mailbox cards, above the clients */
.firm-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); margin-bottom: var(--s4); align-items: start; }
.firm-cards .card-head { margin-bottom: var(--s3); }
.licence-lines { display: flex; flex-direction: column; gap: 8px; }
.licence-lines p { margin: 0; }
.licence-firm { font-weight: 600; }
.licence-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.licence-unreachable { color: var(--warning); font-weight: 600; }
.licence-downloaded { color: var(--success); }
.licence-install-success { color: var(--success); font-weight: 600; }   /* step 5.4b */
.licence-install-danger { color: var(--danger); font-weight: 600; }    /* step 5.4b */
.licence-key-change, .mailbox-settings { margin-top: var(--s3); }
.licence-key-change summary, .mailbox-settings summary { cursor: pointer; color: var(--muted); }
.licence-key-form { display: flex; align-items: flex-start; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s3); }
.licence-key-field { flex: 1; min-width: 220px; }
.licence-key-form > .btn { margin-top: 26px; }
.mailbox-card p { margin: 0 0 6px; }
.mailbox-form { margin-top: var(--s3); display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
.mailbox-form .fields { width: 100%; }
.delivery-state { margin: var(--s2) 0; }                                  /* step 5.4c */
.delivery-on { color: var(--success); font-weight: 600; }
.delivery-off { color: var(--warning); font-weight: 600; }
.mailbox-instead { margin-top: var(--s3); }
.mailbox-instead > summary { cursor: pointer; color: var(--muted); }
.mailbox-pull { margin-top: var(--s2); }
@media (max-width: 1100px) { .firm-cards { grid-template-columns: minmax(0, 1fr); } }

/* step 5.4d - the firm portal on our side (vendor/templates): the console's shell and tokens;
   the logged-out pages are one card in the middle of the page */
.portal-auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s4); padding: var(--s6) var(--s4); }
.portal-auth-brand { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.portal-auth-brand .brand-name { font-size: 20px; }
.portal-auth-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: var(--s4); padding: 28px 32px; }
.portal-auth-title { font-size: var(--fs-card); font-weight: 650; letter-spacing: -.01em; }
.portal-auth-lead { margin-top: calc(-1 * var(--s2)); }
.portal-auth-links { display: flex; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.portal-auth-links a { color: var(--primary); }
.portal-auth-foot { max-width: 440px; text-align: center; }
.portal-form { display: flex; flex-direction: column; gap: 14px; }
.portal-form .form-actions { margin-top: 2px; }
.portal-terms { display: flex; align-items: center; gap: 8px; }
.portal-terms a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.portal-message { display: flex; flex-direction: column; gap: 10px; color: var(--ink-2); }
.portal-user { color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-logout { margin: 4px 0; }
.portal-logout .btn { padding-left: 0; }
.portal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); align-items: start; }
.portal-grid > .card .card-head { margin-bottom: var(--s3); }
.portal-grid > .card > p + p, .portal-grid > .card > p + .portal-facts { margin-top: 8px; }
.portal-wide { grid-column: 1 / -1; }
.portal-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; margin: 0; }
.portal-facts dt { color: var(--muted); font-size: var(--fs-meta); }
.portal-facts dd { margin: 0; min-width: 0; }
.portal-sha { overflow-wrap: anywhere; }
.portal-trial { margin-top: var(--s3); font-weight: 600; color: var(--info); }
.portal-trial-ended { color: var(--danger); }
.portal-state-note { margin-top: var(--s2); padding: 10px 12px; border-radius: 10px; background: var(--warning-bg); border: 1px solid var(--warning-line); color: var(--ink-2); }
.portal-steps { margin: var(--s3) 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); }
.portal-steps-title { margin-top: var(--s4); }
.portal-key-card, .portal-confirm { max-width: 720px; display: flex; flex-direction: column; gap: var(--s3); }
.portal-key-card .card-head, .portal-confirm .card-head { margin-bottom: 0; }
.portal-key { font-size: 17px; padding: 12px 14px; border-radius: var(--r-control); background: var(--surface-2); border: 1px dashed var(--border-strong); user-select: all; overflow-wrap: anywhere; }
.portal-key-warn { color: var(--warning); font-weight: 600; }
.portal-search { justify-content: flex-start; }
.portal-search .search { min-width: 320px; }
.portal-search .search-input { padding-left: 12px; }
.portal-firm-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s4); }
.portal-firm-actions form { display: inline-flex; }
@media (max-width: 1100px) { .portal-grid { grid-template-columns: minmax(0, 1fr); } }
