/* ---------- Tokens ---------- */
:root {
  --primer: #2D3540;
  --primer-2: #3A4350;
  --primer-text: #C9D0D8;
  --steel: #ECEEF0;
  --panel: #FFFFFF;
  --line: #D7DBE0;
  --ink: #1B222A;
  --muted: #5F6B76;
  --accent: #1F5FA8;
  --accent-dark: #174A84;
  --plate: #F2CF4A;
  --ok: #2E7D4F;
  --danger: #B23A2E;
  --warn-bg: #FFF4D6;

  --font: 'Barlow', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-cond: 'Barlow Condensed', 'Arial Narrow', 'Segoe UI', sans-serif;

  --r-sm: 4px;
  --r-md: 6px;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--steel); }
h1, h2, h3 { font-family: var(--font-cond); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: 0.01em; }
a { color: var(--accent); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Buttons ---------- */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
       padding: 7px 14px; border-radius: var(--r-sm); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #B9C0C8; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { border-color: var(--line); }
.btn-sm { padding: 3px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--primer); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); padding: 32px 28px; border-radius: var(--r-md); }
.login-brand { font-size: 30px; }
.login-sub { color: var(--muted); margin: 4px 0 22px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100%; }
.sidebar { width: var(--sidebar-w); flex: none; background: var(--primer); color: var(--primer-text); padding: 18px 0;
           position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 0 20px 18px; border-bottom: 1px solid var(--primer-2); margin-bottom: 10px; }
.brand-name { font-family: var(--font-cond); font-weight: 700; font-size: 21px; color: #fff; }
.nav-group { padding: 12px 20px 4px; font-size: 12px; color: #8E99A5; }
.nav-link { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 20px; color: var(--primer-text);
            text-decoration: none; border-left: 3px solid transparent; }
.nav-link:hover { background: var(--primer-2); color: #fff; }
.nav-link.active { background: var(--primer-2); color: #fff; border-left-color: var(--plate); }
.nav-link.planned { color: #8E99A5; }
.nav-phase { font-size: 11px; color: #8E99A5; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 28px; background: var(--panel); border-bottom: 1px solid var(--line); }
.page-title { font-size: 24px; flex: 1; }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user-name { font-weight: 600; }
.user-role { color: var(--muted); margin-right: 8px; }
.menu-toggle { display: none; }
.page { padding: 24px 28px 48px; outline: none; }

/* ---------- Panels & layout ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 19px; }
.panel-body { padding: 16px; }
.panel-note { color: var(--muted); padding: 16px; margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=search] { min-width: 280px; }

/* Record header (customer / vehicle detail) */
.record-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.record-head .titles { flex: 1; min-width: 220px; }
.record-head h2 { font-size: 30px; }
.record-meta { color: var(--muted); margin-top: 2px; }
.back { display: inline-block; margin-bottom: 10px; font-size: 14px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; }
.stat-value { font-family: var(--font-cond); font-size: 34px; font-weight: 600; line-height: 1; }
.stat-label { color: var(--muted); font-size: 14px; margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; font-weight: 600; color: var(--muted); background: #F6F7F8; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #F4F7FB; }
td.num, th.num { text-align: right; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.docno { font-family: var(--font-cond); font-weight: 600; font-size: 16px; letter-spacing: 0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.pager-buttons { display: flex; gap: 6px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #E4E8EC; color: var(--ink); }
.badge-ok { background: #DCEFE3; color: var(--ok); }
.badge-off { background: #F6DEDB; color: var(--danger); }
.badge-blue { background: #DDE8F5; color: var(--accent-dark); }

/* ---------- Number plate: the signature element ---------- */
.plate { display: inline-block; font-family: var(--font-cond); font-weight: 700; font-size: 16px; letter-spacing: 0.08em;
         background: var(--plate); color: #111; border: 2px solid #1B222A; border-radius: 4px; padding: 0 9px; line-height: 1.5;
         white-space: nowrap; }
.plate-lg { font-size: 34px; padding: 2px 18px; border-width: 3px; border-radius: 6px; }

/* ---------- Definition lists ---------- */
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 14px; }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Lists inside panels ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.comm { display: block !important; }
.comm-meta { font-size: 13px; color: var(--muted); }
.comm-body { margin-top: 4px; white-space: pre-wrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 14px; }
.field > span { font-weight: 500; }
.field .hint { color: var(--muted); font-size: 13px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #C3C9D0; border-radius: var(--r-sm); padding: 7px 10px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,95,168,.18); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: #F6DEDB; color: var(--danger); padding: 8px 12px; border-radius: var(--r-sm); font-size: 14px; margin: 0 0 14px; }
.form-warn { background: var(--warn-bg); color: #6B4E00; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }

/* Lookup (search-as-you-type picker) */
.lookup { position: relative; }
.lookup-results { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid #C3C9D0;
                  border-radius: var(--r-sm); max-height: 220px; overflow-y: auto; margin: 2px 0 0; padding: 0; list-style: none; }
.lookup-results li { padding: 7px 10px; cursor: pointer; }
.lookup-results li:hover, .lookup-results li.active { background: #EEF3FA; }
.lookup-picked { font-size: 13px; color: var(--ok); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(27, 34, 42, .5); display: grid; place-items: start center;
                  padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--panel); border-radius: var(--r-md); width: 100%; max-width: 640px; }
.modal-sm { max-width: 420px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 21px; }
.modal-body { padding: 18px 20px 20px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r-sm); font-size: 14px; max-width: 360px; }
.toast-error { background: var(--danger); }

/* ---------- Planned module page ---------- */
.planned-intro { max-width: 70ch; margin: 0 0 16px; }
.feature-cols { columns: 2 260px; column-gap: 32px; padding: 16px 16px 16px 36px; margin: 0; }
.feature-cols li { margin-bottom: 6px; break-inside: avoid; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-block; }
  .user-role, .user-name { display: none; }
  .page, .topbar { padding-left: 16px; padding-right: 16px; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .toolbar input[type=search] { min-width: 0; flex: 1; }
}

/* ================= Phase 2: workshop ================= */
.pre { white-space: pre-wrap; }
.overdue { color: var(--danger); font-weight: 600; }
.docno-xl { font-family: var(--font-cond); font-size: 32px; letter-spacing: 0.02em; }
.record-head .record-meta + .record-meta { margin-top: 6px; }
.sub { font-size: 16px; margin-bottom: 8px; }
.plain { margin: 0; padding-left: 18px; }
.field.check.inline { margin: 0; }

/* Stage badges, grouped by part of the process */
.stage { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.stage-intake    { background: #E4E8EC; color: #36404B; }
.stage-approved  { background: #DDE8F5; color: var(--accent-dark); }
.stage-work      { background: #FBEBC5; color: #6B4E00; }
.stage-finish    { background: #DCEFE3; color: var(--ok); }
.stage-closed    { background: #2D3540; color: #fff; }
.stage-cancelled { background: #F6DEDB; color: var(--danger); }

/* Callouts */
.callout { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: var(--warn-bg); color: #5A4300;
           border: 1px solid #EBD390; border-radius: var(--r-md); padding: 10px 16px; margin-bottom: 20px; }
.callout-off { background: #F6DEDB; color: var(--danger); border-color: #E9B9B3; }

/* Progress stepper: the stages are a true sequence, so numbering carries meaning */
.stepper { display: flex; list-style: none; margin: 0; padding: 14px 16px; gap: 4px; overflow-x: auto; counter-reset: step; }
.stepper li { flex: 1 0 92px; position: relative; padding-top: 30px; font-size: 12.5px; text-align: center; color: var(--muted); counter-increment: step; }
.stepper li::before { content: counter(step); position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 24px; height: 24px; border-radius: 50%;
                      display: grid; place-items: center; font-weight: 600; background: #E4E8EC; color: var(--muted); }
.stepper li::after { content: ''; position: absolute; top: 11px; left: calc(50% + 15px); right: calc(-50% + 15px); height: 2px; background: #E4E8EC; }
.stepper li:last-child::after { display: none; }
.stepper li.done { color: var(--ink); }
.stepper li.done::before { background: var(--ok); color: #fff; content: '\2713'; }
.stepper li.done::after { background: var(--ok); }
.stepper li.current { color: var(--ink); font-weight: 600; }
.stepper li.current::before { background: var(--plate); color: #111; box-shadow: 0 0 0 2px #1B222A; }

/* Reception form */
.fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 14px 4px; margin: 0 0 16px; }
.fieldset legend { font-weight: 600; padding: 0 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); column-gap: 12px; }
.check-grid .field { margin-bottom: 8px; }
.checklist { margin-bottom: 8px; }
.checklist td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
.checklist td:first-child { width: 40%; }
.checklist input, .checklist select { width: 100%; }

/* Photos */
.photo-add { display: flex; gap: 6px; align-items: center; }
.photo-add select { padding: 3px 6px; font-size: 13px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; padding: 14px 16px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--line); display: block; background: #F6F7F8; }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; justify-content: space-between; gap: 6px; text-transform: capitalize; }

/* Signatures */
.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px 16px; }
.sig { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.sig-label { font-weight: 600; font-size: 14px; }
.sig img { width: 100%; max-height: 90px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; }
.sig-empty { width: 100%; height: 70px; display: grid; place-items: center; border: 1px dashed #B9C0C8; border-radius: var(--r-sm); color: var(--muted); font-size: 13px; }
.sig-pad { width: 100%; height: 200px; border: 1px solid #C3C9D0; border-radius: var(--r-sm); background: #fff; touch-action: none; cursor: crosshair; display: block; margin-bottom: 12px; }
.note-form textarea { width: 100%; min-height: 60px; }
.note-form { padding-bottom: 6px; }

/* Workshop board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(236px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.board-col { background: #E1E5E9; border-radius: var(--r-md); padding: 10px; min-height: 160px; }
.board-col-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; padding: 0 2px; }
.board-col-head h2 { font-size: 16px; }
.count { font-family: var(--font-cond); font-weight: 600; color: var(--muted); }
.board-empty { color: var(--muted); font-size: 13px; text-align: center; margin: 18px 0; }
.job-card { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid #B9C0C8; border-radius: var(--r-sm); padding: 9px 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 3px; }
.job-card.urgent { border-left-color: var(--plate); }
.job-card.is-overdue { border-left-color: var(--danger); }
.job-card-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.job-card-top .docno { text-decoration: none; color: var(--muted); }
.job-card-veh { font-weight: 600; }
.job-card-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
.job-card-actions { display: flex; gap: 6px; margin-top: 6px; }

/* Dashboard additions */
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { border-color: var(--accent); }
.stat-alert .stat-value { color: var(--danger); }
.bars { list-style: none; margin: 0; padding: 12px 16px; }
.bars li { display: grid; grid-template-columns: 150px 1fr 32px; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }
.bar-track { height: 10px; background: #EEF0F2; border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 5px; }
.bar-n { text-align: right; font-family: var(--font-cond); font-weight: 600; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 18px; border-bottom: 1px solid var(--line); }
@media (max-width: 900px) { .sigs { grid-template-columns: 1fr; } .bars li { grid-template-columns: 110px 1fr 28px; } }
/* Printing any screen: no menus or buttons, full width, with the company letterhead */
.print-head { display: none; }
@media print {
  .sidebar, .topbar, .toolbar, .btn, .back, .tabs, .toasts, #modal-root, .pager, form.toolbar { display: none !important; }
  body { background: #fff; }
  .main, #page, main { margin: 0 !important; padding: 0 !important; width: 100% !important; max-width: none !important; }
  .panel, .stat { box-shadow: none !important; border: 1px solid #ccc; break-inside: avoid; }
  .print-head { display: flex !important; align-items: center; gap: 14px; border-bottom: 2px solid #1F2630; padding-bottom: 8px; margin-bottom: 12px; }
  .print-head img { max-height: 48px; max-width: 180px; }
  .print-head span { margin-left: auto; font-size: 11px; color: #555; }
  a[href]:after { content: none !important; }
  table { font-size: 11px; }
}

/* ================= Phase 3: quotations, labour, QC ================= */
.btn-row { display: flex; gap: 6px; }
.add-line { display: flex; gap: 6px; align-items: center; }
.add-line select { padding: 3px 6px; font-size: 13px; }
.qlines td { padding: 6px 8px; }
.qlines.editing input, .qlines.editing select { padding: 5px 7px; font-size: 14px; }
.qlines .w-desc { width: 100%; min-width: 220px; }
.qlines .w-part { width: 110px; }
.qlines .w-num { width: 90px; text-align: right; }
.qlines .w-pct { width: 64px; text-align: right; }
.qlines td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; margin: 0; font-variant-numeric: tabular-nums; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }
.totals .grand { font-family: var(--font-cond); font-size: 22px; font-weight: 600; color: var(--ink); border-top: 2px solid var(--ink); padding-top: 6px; }
td.num, .costing td { font-variant-numeric: tabular-nums; }
.clock-running { color: var(--ok); font-weight: 600; }
.inline-field { flex-direction: row; align-items: center; gap: 6px; margin: 0; }

/* ================= Phase 5: inventory and purchasing ================= */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .tabs { margin-bottom: 0; border-bottom: 0; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.modal-wide { max-width: 1100px; }
.qlines .w-item { width: 190px; }
.form-actions.start { justify-content: flex-start; padding: 8px 0 12px; }
td.neg { color: var(--danger); }
.compare td.best { background: #DCEFE3; font-weight: 600; }
.compare .total-row td { border-top: 2px solid var(--ink); font-weight: 600; }
.callout-ok { background: #DCEFE3; color: var(--ok); border-color: #B8DCC5; }
.toolbar.inline { margin: 0; gap: 6px; }

/* ================= Phase 6: finance ================= */
.ok-text { color: var(--ok); }
table.fin tr.grp th { text-align: left; padding-top: 14px; font-family: var(--font-cond); font-size: 15px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); border-bottom: 0; }
tr.sub-total td { font-weight: 600; border-top: 1px solid var(--line); }
tr.grand-row td { font-family: var(--font-cond); font-size: 17px; font-weight: 600; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
table.fin td:first-child { padding-left: 14px; }
table.fin tr.sub-total td:first-child, table.fin tr.grand-row td:first-child { padding-left: 8px; }
.budget-grid .w-num { width: 82px; }
.budget-grid td, .budget-grid th { white-space: nowrap; }
a.btn, a.btn:hover { text-decoration: none; }
pre.code { background: #F4F6F8; border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; font-size: 12.5px; white-space: pre; }

/* ================= Phase 9: reporting ================= */
.chart { margin: 0; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .c1, .legend .sw.c1 { fill: var(--accent); background: var(--accent); }
.chart .c2, .legend .sw.c2 { fill: #8FB3DA; background: #8FB3DA; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.hbars { margin-top: 12px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 36px; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.hb-track { background: #EEF1F4; border-radius: 3px; height: 10px; overflow: hidden; }
.hb-fill { display: block; height: 100%; background: var(--accent); }
.hb-val { text-align: right; font-variant-numeric: tabular-nums; }
.gauges { display: flex; gap: 24px; margin-bottom: 10px; }
.gauge { margin: 0; text-align: center; width: 96px; }
.gauge svg { width: 80px; height: 80px; }
.gauge .g-bg { fill: none; stroke: #EEF1F4; stroke-width: 8; }
.gauge .g-fg { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }
.gauge .g-fg.hi { stroke: var(--ok); } .gauge .g-fg.lo { stroke: #C27C0E; }
.gauge .g-txt { font: 600 16px var(--font); fill: var(--ink); }
.gauge figcaption { font-size: 12px; color: var(--muted); }
.alerts { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; }
.alert { padding: 6px 10px; border-radius: 6px; font-size: 13px; text-decoration: none; color: var(--ink); background: #EEF4FB; }
.alert-warn { background: #FFF3DC; }
table.report tr.grp-row td { font-weight: 600; background: #F7F8FA; }
.report-list li { gap: 16px; }
.hb-fill.w0 { width: 0%; }
.hb-fill.w5 { width: 5%; }
.hb-fill.w10 { width: 10%; }
.hb-fill.w15 { width: 15%; }
.hb-fill.w20 { width: 20%; }
.hb-fill.w25 { width: 25%; }
.hb-fill.w30 { width: 30%; }
.hb-fill.w35 { width: 35%; }
.hb-fill.w40 { width: 40%; }
.hb-fill.w45 { width: 45%; }
.hb-fill.w50 { width: 50%; }
.hb-fill.w55 { width: 55%; }
.hb-fill.w60 { width: 60%; }
.hb-fill.w65 { width: 65%; }
.hb-fill.w70 { width: 70%; }
.hb-fill.w75 { width: 75%; }
.hb-fill.w80 { width: 80%; }
.hb-fill.w85 { width: 85%; }
.hb-fill.w90 { width: 90%; }
.hb-fill.w95 { width: 95%; }
.hb-fill.w100 { width: 100%; }

/* ================= Phase 10: security ================= */
.qr { text-align: center; margin: 8px 0; }
.qr img { border: 1px solid var(--line); border-radius: 6px; }
.center { text-align: center; }
pre.codes { font-size: 15px; letter-spacing: 1px; line-height: 1.8; text-align: center; }
ol.steps { padding-left: 18px; margin: 0 0 6px; }
.turnstile { margin: 6px 0; min-height: 0; }

/* ================= Platform administration ================= */
.pa-top { display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: var(--sidebar, #1F2630); color: #fff; flex-wrap: wrap; }
.pa-top .tabs { margin: 0; }
.pa-top .tab { color: #C9D1DA; }
.pa-top .tab.active { color: #fff; }
.pa-main { max-width: 1200px; margin: 0 auto; padding: 20px; }
dl.secret code { font-size: 15px; user-select: all; }

/* ================= Branding ================= */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { max-height: 34px; max-width: 120px; background: #fff; border-radius: 4px; padding: 2px; }
.login-logo { display: block; max-height: 64px; max-width: 220px; margin: 0 auto 10px; }
.logo-preview img { max-height: 80px; max-width: 260px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.file-btn { cursor: pointer; }
.toolbar .export { margin-right: 6px; }

/* ================= Phones and tablets ================= */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.nav-backdrop, .side-account { display: none; }
.menu-toggle .menu-icon { display: block; }
.menu-toggle { color: var(--ink); background: transparent; }
@media (max-width: 900px) {
  .topbar { position: sticky; top: 0; z-index: 30; gap: 6px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .page-title { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .userbox { gap: 2px; }
  .userbox [data-action="me:password"], .userbox [data-action="auth:logout"] { display: none; }   /* in the menu instead */
  .menu-toggle { padding: 0 12px; }
  .sidebar { top: 0; bottom: 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain; width: min(84vw, 300px); z-index: 40;
    padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom)); box-shadow: 4px 0 24px rgba(0, 0, 0, .25); }
  .nav-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(20, 26, 33, .45); z-index: 35; }
  body.menu-open { overflow: hidden; }
  .side-account { display: grid; gap: 6px; margin: 14px 12px 0; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .14); }
  .side-account .btn { justify-content: flex-start; color: inherit; border-color: rgba(255, 255, 255, .2); }
  .side-user { display: grid; padding: 0 4px 6px; font-size: 14px; }
  .side-user span { opacity: .75; font-size: 13px; }
  .page { padding: 12px 12px calc(28px + env(safe-area-inset-bottom)); }
  .record-head { gap: 8px; margin-bottom: 14px; }
  .record-head h2 { font-size: 22px; }
  .record-head .titles { min-width: 100%; }
  .record-head > .btn, .record-head > a.btn { flex: 1 1 auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 24px; }
  .toolbar { gap: 8px; }
  .toolbar input[type=search] { flex: 1 1 100%; }
  .tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: none; }
  .board { grid-auto-columns: 86vw; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; }
  .board-col { scroll-snap-align: start; }
  /* Dialogs open as a sheet from the bottom, with the title and buttons always in reach */
  .modal-backdrop { place-items: end center; padding: 0 !important; }
  .modal, .modal-sm, .modal-wide { max-width: none !important; border-radius: 14px 14px 0 0; max-height: 92dvh; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
  .modal-head { position: sticky; top: 0; background: var(--panel); z-index: 2; }
  .modal .form-actions { position: sticky; bottom: 0; background: var(--panel); padding: 10px 0 4px; margin-bottom: 0; z-index: 2; }
  .panel-head { flex-wrap: wrap; gap: 8px; }
  .pa-top { padding: 8px 12px; gap: 8px; }
  .pa-top .tabs { order: 3; width: 100%; }
  .pa-main { padding: 12px; }
}
/* Fingers need bigger targets than a mouse pointer */
@media (pointer: coarse), (max-width: 900px) {
  .btn, a.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }   /* links styled as buttons too */
  .btn-sm { min-height: 40px; padding: 6px 12px; font-size: 14px; }
  .btn-link { min-height: 40px; }
  .tab { min-height: 44px; display: inline-flex; align-items: center; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea { min-height: 44px; font-size: 16px; }   /* 16 px: iPhones do not zoom in */
  .qlines.editing input, .qlines.editing select, .photo-add select, .add-line select { font-size: 16px; }   /* small inline controls too */
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  #nav a { min-height: 46px; display: flex; align-items: center; }
  /* Text links inside tables and lists get a finger-sized tap area; so do checkbox labels */
  td a:not(.btn), .list a:not(.btn), .record-meta a { display: inline-block; padding: 10px 0; }
  .field.check, label:has(> input[type=checkbox]), label:has(> input[type=radio]) { min-height: 44px; display: flex; align-items: center; gap: 10px; }
  input[type=checkbox], input[type=radio] { width: 24px; height: 24px; flex: none; }
  .clickable { cursor: pointer; }
}
/* Lists: each row becomes a card on phones (cells carry their column name) */
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel); margin: 0 0 10px; padding: 6px 0; }
  table.stack tr.clickable:active { background: #F1F4F7; }
  table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; padding: 5px 12px; border: 0; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 500; text-align: left; flex: none; max-width: 45%; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td[data-empty] { display: none; }
  table.stack td:first-child { font-weight: 600; font-size: 16px; }
  table.stack tr.grand-row, table.stack tr.sub-total { background: #F7F8FA; }
  .table-wrap:has(> table.stack) { overflow: visible; border: 0; }
  .panel:has(table.stack) { background: transparent; border: 0; box-shadow: none; }
  .panel:has(table.stack) > .panel-head { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 10px; }
  .dl { grid-template-columns: 1fr; }
  .gauges { justify-content: space-around; }
  .hbar { grid-template-columns: 96px 1fr 30px; }
}

/* Platform site: sign-in centred like the firm sign-in, and the top bar lined up with the centred page */
.platform .login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--primer, #1F2630); }
.platform .login-wrap.hidden { display: none; }
.platform .login-wrap .login-card { box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.pa-top { padding-left: max(20px, calc((100% - 1200px) / 2 + 20px)); padding-right: max(20px, calc((100% - 1200px) / 2 + 20px)); }
.pa-top .grow { flex: 1; }
.pa-top .tabs { border-bottom: 0; }
