:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #a3b1c6;
  --line: #e4e9f0;
  --line-strong: #cbd5e1;

  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #eef4ff;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --ok-bar: #10b981;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --info: #0369a1;
  --info-soft: #f0f9ff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-line: #fecaca;
  --danger-bar: #fca5a5;
  --mark-bad: #dc2626;
  --mark-ok: #059669;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 21, 31, .05), 0 8px 24px -14px rgba(16, 21, 31, .16);
  --shadow-lg: 0 24px 60px -18px rgba(15, 23, 42, .34);
  --ring: 0 0 0 3px color-mix(in srgb, var(--brand) 24%, transparent);
  --nav-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1220;
    --panel: #131b2c;
    --panel-2: #172134;
    --ink: #e8eefb;
    --muted: #94a4bd;
    --faint: #5b6b85;
    --line: #24304a;
    --line-strong: #33415e;

    --brand: #5b9bff;
    --brand-ink: #06152e;
    --brand-soft: #1a2846;
    --ok: #34d399;
    --ok-soft: #10261f;
    --ok-bar: #34d399;
    --warn: #fbbf24;
    --warn-soft: #2a2010;
    --info: #7dd3fc;
    --info-soft: #10222f;
    --danger: #fca5a5;
    --danger-soft: #2a1414;
    --danger-line: #5b2020;
    --danger-bar: #b91c1c;
    --mark-bad: #ef4444;
    --mark-ok: #10b981;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -16px rgba(0, 0, 0, .7);
    --shadow-lg: 0 26px 70px -20px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html[dir="rtl"] body {
  font-family: "SF Arabic", "Geeza Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", "Dubai", system-ui, sans-serif;
}
/* Money and counts line up column-wise wherever they appear. */
.num, .value, .plate, .stat .value, .tot strong, .totals span { font-variant-numeric: tabular-nums; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--brand); }

/* ------------------------------- shell -------------------------------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--brand), #4f46e5);
  color: var(--brand-ink); display: grid; place-items: center; font-size: 18px;
}
.brand strong { display: block; font-size: 15px; line-height: 1.25; }
.brand span { font-size: 12px; color: var(--muted); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-weight: 500;
  border: 0; background: none; width: 100%; cursor: pointer;
  font-size: 14.5px; text-align: start; font-family: inherit;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item .ico { width: 20px; text-align: center; }
.nav-spacer { flex: 1; }

.main { padding: 24px 28px 64px; min-width: 0; }
.page-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.spacer { flex: 1; }

/* ------------------------------ controls ------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, black); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-soft); border-color: var(--brand); outline-offset: 0;
}
textarea { resize: vertical; min-height: 72px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* -------------------------------- cards ------------------------------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card > header {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.card > header h2 { font-size: 15px; }
.card .body { padding: 18px; }

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow); }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.stat .value { font-size: 25px; font-weight: 680; margin-top: 5px; letter-spacing: -.02em; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--brand); }

/* ------------------------------- tables ------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel-2); font-weight: 620; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.linked { cursor: pointer; }
tbody tr.linked:hover { background: var(--brand-soft); }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.plate {
  display: inline-block; font-weight: 700; letter-spacing: .06em;
  border: 1.5px solid var(--faint); border-radius: 6px; padding: 2px 9px;
  background: var(--panel); font-variant-numeric: tabular-nums; direction: ltr;
}
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px;
}
.icon-sm { width: 14px; height: 14px; vertical-align: -2px; }
.btn.sm .icon { width: 14px; height: 14px; }
.nav-item .ico { display: inline-flex; }
.nav-item .icon { width: 19px; height: 19px; }
.brand .logo .icon { width: 19px; height: 19px; stroke-width: 2; vertical-align: 0; }
.empty .big .icon { width: 34px; height: 34px; stroke-width: 1.3; opacity: .4; }
.pill .icon { vertical-align: -2px; }
html[dir="rtl"] .icon-flip { transform: scaleX(-1); }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill.received { background: var(--info-soft); color: var(--info); }
.pill.in_progress { background: var(--warn-soft); color: var(--warn); }
.pill.done { background: var(--brand-soft); color: var(--brand); }
.pill.delivered { background: var(--ok-soft); color: var(--ok); }
.pill.unpaid { background: var(--danger-soft); color: var(--danger); }
.pill.paid { background: var(--ok-soft); color: var(--ok); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }

/* ------------------------------- modal -------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 14, 26, .55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--panel); border-radius: 14px; width: min(720px, 100%);
  max-height: 90vh; overflow: auto; box-shadow: 0 24px 60px -12px rgba(0, 0, 0, .35);
}
.modal > header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal > header h2 { font-size: 16px; }
.modal .body { padding: 20px; display: grid; gap: 14px; }
.modal > footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.err { background: var(--danger-soft); color: var(--danger); padding: 9px 12px; border-radius: 9px; font-size: 13.5px; }

.toast {
  position: fixed; inset-block-end: 22px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  z-index: 100; box-shadow: var(--shadow); font-size: 14px;
}

/* ------------------------- job detail / invoice ------------------------ */
.two-col { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }
.totals { display: grid; gap: 9px; }
.totals .line { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.totals .line.grand { border-top: 1px solid var(--line); padding-top: 10px; font-size: 18px; font-weight: 700; }
.totals .line.balance { color: var(--danger); font-weight: 650; }
.status-flow { display: flex; gap: 6px; flex-wrap: wrap; }
.picker { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.picker button {
  display: flex; width: 100%; gap: 10px; align-items: center; padding: 9px 13px;
  background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer;
  font: inherit; text-align: start; color: inherit;
}
.picker button:hover { background: var(--brand-soft); }
.picker button:last-child { border-bottom: 0; }

.print-only { display: none !important; }
@media print {
  .print-only { display: block !important; }
  .invoice-head.print-only { display: flex !important; }
  .app { display: block; }
  .sidebar, .page-head, .no-print, .modal-backdrop { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; font-size: 13px; }
  .two-col { grid-template-columns: 1fr; }
}

.invoice-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.invoice-head h2 { font-size: 20px; }

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ============================ auth & shell ============================== */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.auth { width: min(400px, 100%); padding: 28px; display: grid; gap: 14px; }
.auth h1 { font-size: 20px; }
.auth-brand { display: flex; align-items: center; gap: 9px; font-size: 16px; color: var(--brand); }
.auth-brand .icon { width: 22px; height: 22px; }
.auth .btn { width: 100%; justify-content: center; }

.center-switch {
  display: grid; gap: 4px; padding: 4px; margin-bottom: 10px;
  background: var(--bg); border-radius: 11px;
}
.center-tab {
  display: flex; align-items: center; gap: 8px; padding: 8px 11px;
  border-radius: 8px; text-decoration: none; color: var(--muted);
  font-weight: 600; font-size: 13.5px;
}
.center-tab.on { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); }
.center-tab .icon { width: 17px; height: 17px; }
.nav-group { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }

.perm { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; }
.perm.on { background: var(--ok-soft); color: var(--ok); }
.perm.off { background: var(--bg); color: var(--faint); }

.field-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  font-size: 13.5px; font-weight: 550; background: var(--panel);
}
.chip:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.chip input { width: auto; margin: 0; accent-color: var(--brand); }
.chip.static { cursor: default; gap: 4px; padding-inline-end: 4px; }
.modal.wide { width: min(860px, 100%); }
.flex1 { flex: 1; }

/* ========================= inspection form ============================== */
.insp-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.insp-image { box-shadow: none; }
.insp-image > header { padding: 10px 14px; }
.insp-image > header h2 { font-size: 14px; }
.insp-image .body { padding: 12px 14px 14px; }

.canvas {
  position: relative; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); overflow: hidden; color: var(--faint); line-height: 0;
}
.canvas.markable { cursor: crosshair; }
.canvas img { width: 100%; display: block; }
.car-diagram { width: 100%; display: block; padding: 6px; }

.mark {
  position: absolute; transform: translate(50%, -50%);
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--panel);
  font: 700 12px/1 system-ui; color: #fff; cursor: pointer; padding: 0;
  display: grid; place-items: center; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
html[dir="ltr"] .mark { transform: translate(-50%, -50%); }
.mark.bad { background: var(--mark-bad); }
.mark.ok { background: var(--mark-ok); }

.mark-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.mark-list li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.mark-badge { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; flex: none; }
.mark-badge.bad { background: var(--danger-soft); color: var(--danger); }
.mark-badge.ok { background: var(--ok-soft); color: var(--ok); }
.hint { margin-top: 7px; }
.comment { margin: 10px 0 0; font-size: 13.5px; background: var(--bg); padding: 9px 12px; border-radius: 9px; }
.fixed-notes { white-space: pre-wrap; font-size: 13.5px; color: var(--muted); line-height: 1.7; }

table.points td { padding: 7px 10px; }
.btn.ok-on { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.btn.bad-on { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* damage grid */
.grid-table { font-size: 13px; }
.grid-table th, .grid-table td { border: 1px solid var(--line); text-align: center; padding: 6px 8px; }
.grid-table thead th { background: var(--panel-2); font-size: 11.5px; text-transform: none; letter-spacing: 0; }
.grid-table th.corner { background: var(--bg); font-size: 11px; white-space: nowrap; }
.grid-table th.rowhead { text-align: start; white-space: nowrap; background: var(--panel-2); font-weight: 600; color: var(--ink); }
.grid-table th span { display: inline-block; }
.grid-table .col-del { padding: 0 3px; opacity: 0; }
.grid-table th:hover .col-del { opacity: 1; }
.grid-table td.cell { cursor: pointer; width: 44px; height: 34px; color: var(--brand); }
.grid-table td.cell:hover { background: var(--brand-soft); }
.grid-table td.cell.on { background: var(--brand-soft); }

/* signatures */
.sig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sig { text-align: center; }
.sig-label { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.sig-img, .sig-empty {
  height: 96px; border: 1px dashed var(--line); border-radius: 9px;
  display: grid; place-items: center; width: 100%; object-fit: contain;
  color: var(--faint); font-size: 13px; background: var(--panel); margin-bottom: 8px;
}
.sigpad { width: 100%; height: 240px; border: 1px solid var(--line); border-radius: 10px; touch-action: none; background: var(--panel); }

/* templates */
.tpl-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tpl { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tpl img { width: 100%; display: block; }
.tpl-none { height: 110px; display: grid; place-items: center; color: var(--faint); background: var(--bg); }
.tpl figcaption { display: flex; align-items: center; gap: 6px; padding: 7px 10px; font-size: 13px; border-top: 1px solid var(--line); }
.tpl figcaption .btn { margin-inline-start: auto; }
.tpl-preview { max-width: 100%; border-radius: 9px; margin-top: 10px; }
.tpl-points { margin-top: 12px; }

.page-break { break-after: page; }
.form-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 16px; }

@media print {
  .form-head.print-only { display: flex !important; }
  .insp-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .canvas { break-inside: avoid; }
  .insp-image { break-inside: avoid; border: 1px solid var(--line); }
  .card { break-inside: avoid; margin-bottom: 10px; }
  .card + .card { margin-top: 10px; }
  .sig-empty { border-style: solid; }
  .grid-table td.cell { height: 26px; }
  .auth-wrap { display: none; }
}

@media (max-width: 700px) {
  .sig-row, .insp-grid { grid-template-columns: 1fr; }
}

/* ============================== finance ================================= */
.ok-text { color: var(--ok); }
.bad-text { color: var(--danger); }

.fin-head { flex-wrap: wrap; gap: 10px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  border: 0; background: none; font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 7px 14px; border-radius: 7px; cursor: pointer; color: var(--muted);
}
.tab.on { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); }
.range-row input[type="date"] { width: auto; padding: 6px 9px; font-size: 13px; }

.totals-row { display: flex; flex-wrap: wrap; gap: 10px; }
.tot {
  flex: 1 1 140px; background: var(--bg); border-radius: 10px; padding: 12px 14px;
  display: grid; gap: 4px;
}
.tot span { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.tot strong { font-size: 18px; letter-spacing: -.01em; }
.tot.big { background: var(--brand-soft); }
.tot.big strong { color: var(--brand); font-size: 21px; }

h3.sec { font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 620; }
.bars { display: grid; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 8px; font-size: 12.5px; }
.bar-day { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 9px; border-radius: 999px; display: block; min-width: 2px; }
.bar.in { background: var(--ok); grid-column: 2; }
.bar.out { background: var(--danger-bar); grid-column: 2; margin-top: 2px; }
.bar-val { grid-column: 3; font-variant-numeric: tabular-nums; color: var(--muted); }

.pay-block .totals { margin-bottom: 10px; }
.pay-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pay-list li {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px;
  background: var(--bg); border-radius: 8px; padding: 6px 10px;
}
.statement table { font-size: 13.5px; }
.statement tfoot th { background: var(--bg); }

tfoot th { background: var(--panel-2); border-top: 2px solid var(--line); font-size: 13px; text-transform: none; color: var(--ink); }

@media print {
  .tabs, .range-row, .stats { display: none !important; }
  .statement .modal { box-shadow: none; max-height: none; }
}

/* ======================= interaction & accessibility ==================== */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}
.btn, .nav-item, .tab, .center-tab, .chip, tbody tr.linked { transition: background-color .13s ease, border-color .13s ease, color .13s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Visible only to screen readers. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; inset-inline-start: -9999px; top: 8px; z-index: 200;
  background: var(--panel); padding: 9px 15px; border-radius: 9px; box-shadow: var(--shadow);
}
.skip-link:focus { inset-inline-start: 8px; }

/* ============================ loading state ============================= */
#progress {
  position: fixed; inset-block-start: 0; inset-inline: 0; height: 2.5px; z-index: 300;
  background: var(--brand); transform: scaleX(0); transform-origin: var(--pg-origin, left);
  opacity: 0; pointer-events: none;
}
html[dir="rtl"] #progress { --pg-origin: right; }
html.loading #progress { opacity: 1; animation: pg 1.4s ease-out infinite; }
@keyframes pg {
  0% { transform: scaleX(0); }
  60% { transform: scaleX(.75); }
  100% { transform: scaleX(1); opacity: .25; }
}

/* ========================== mobile app bar / drawer ===================== */
.appbar { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  /* The drawer sits outside the viewport; without this it widens the page. */
  html, body { overflow-x: hidden; }
  .app { display: block; }

  .appbar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 40;
    background: var(--panel); border-bottom: 1px solid var(--line);
    padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  }
  .appbar strong { font-size: 15px; }
  .appbar .sub { font-size: 12px; color: var(--muted); }
  .menu-btn {
    border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
    padding: 7px 9px; cursor: pointer; color: var(--ink); display: grid; place-items: center;
  }

  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 60;
    width: min(280px, 82vw); height: 100dvh; flex-direction: column; overflow-y: auto;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg); border-inline-end: 1px solid var(--line);
  }
  html[dir="rtl"] .sidebar { transform: translateX(102%); }
  .app.nav-open .sidebar { transform: translateX(0); }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(8, 14, 26, .5); opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }

  .nav-item { width: 100%; padding: 11px 12px; }
  .main { padding: 16px 14px 56px; }
  .page-head h1 { font-size: 19px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat .value { font-size: 21px; }
  .modal { max-height: 92dvh; }
  .modal .body { padding: 16px; }
  .btn { padding: 10px 14px; }
  .page-head { gap: 10px; }
  .page-head .btn { flex: 1 1 auto; justify-content: center; }
}

/* ============================ tables polish ============================= */
.table-wrap { max-height: none; }
thead th { position: sticky; top: 0; z-index: 2; }
@media (max-width: 900px) { thead th { position: static; } }
tbody tr:nth-child(even) > td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
tbody tr.linked:hover > td { background: var(--brand-soft); }

/* ============================== stepper ================================= */
.stepper { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.step {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  font: inherit; font-weight: 570; font-size: 13.5px; cursor: pointer; color: var(--muted);
}
.step:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.step .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.step.done { color: var(--ink); }
.step.done .dot { background: var(--ok); }
.step.current { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.step.current .dot { background: var(--brand-ink); }
.step:disabled { cursor: default; opacity: .75; }
.step-sep { width: 14px; height: 1px; background: var(--line-strong); flex: none; }
@media (max-width: 640px) { .step-sep { display: none; } }

/* ============================== toasts ================================== */
.toast {
  display: flex; align-items: center; gap: 9px;
  animation: toast-in .18s ease-out;
  inset-block-end: max(22px, env(safe-area-inset-bottom));
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ============================ confirm dialog ============================ */
.confirm { width: min(420px, 100%); }
.confirm .body { text-align: center; padding: 26px 22px 6px; }
.confirm .warn-ico {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--danger-soft); color: var(--danger);
}
.confirm .warn-ico .icon { width: 24px; height: 24px; }
.confirm p { margin: 0; font-size: 15px; font-weight: 550; }
.confirm footer { justify-content: center; }

/* ============================ small refinements ========================= */
.card > header h2 { letter-spacing: -.006em; }
.stat { transition: border-color .13s ease, transform .13s ease; }
.stat.clickable:hover { transform: translateY(-1px); }
.brand .logo { box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--brand) 55%, transparent); }
.empty .big .icon { opacity: .35; }
.pill { line-height: 1.5; }

/* ========================= the printed paper form ======================== */
.printed-form { color: #111; font-size: 11.5px; line-height: 1.35; }

.pf-head {
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
  border: 1.5px solid #111; border-radius: 8px; padding: 9px 12px; margin-bottom: 8px;
}
.pf-brand { display: flex; align-items: center; gap: 11px; }
.pf-logo { height: 54px; width: auto; max-width: 150px; object-fit: contain; }
.pf-logo-blank { width: 46px; height: 46px; display: grid; place-items: center; border: 1.5px solid #111; border-radius: 8px; }
.pf-logo-blank .icon { width: 24px; height: 24px; }
.pf-head h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.pf-tag { font-size: 10.5px; color: #444; margin-top: 2px; }
.pf-meta { text-align: end; font-size: 10.5px; color: #333; }
.pf-title { font-size: 13px; font-weight: 700; color: #111; margin-bottom: 3px; }
.pf-no { font-weight: 600; }

.pf-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 8px; }
.pf-field { border: 1px solid #111; border-radius: 5px; display: flex; overflow: hidden; min-height: 22px; }
.pf-label {
  background: #111; color: #fff; padding: 3px 8px; font-size: 10px; font-weight: 600;
  white-space: nowrap; display: flex; align-items: center;
}
.pf-value { padding: 3px 8px; flex: 1; font-weight: 600; align-self: center; }

.pf-diagrams { display: grid; gap: 5px; margin-bottom: 8px; }
.pf-row { display: flex; gap: 6px; justify-content: center; }
.pf-row-wide .pf-view { width: 58%; }
.pf-row-three .pf-view { flex: 1; }
.pf-view { margin: 0; border: 1px solid #999; border-radius: 6px; padding: 3px; }
.pf-canvas { position: relative; line-height: 0; }
.pf-canvas .car-diagram, .pf-canvas img { width: 100%; display: block; color: #333; }
.pf-view figcaption { font-size: 9.5px; text-align: center; color: #444; margin-top: 1px; }

.pf-mark {
  position: absolute; transform: translate(50%, -50%);
  width: 15px; height: 15px; border-radius: 50%; border: 1px solid #fff;
  font: 700 9px/15px system-ui; color: #fff; text-align: center;
}
html[dir="ltr"] .pf-mark { transform: translate(-50%, -50%); }
.pf-mark.bad { background: #c81e1e; }
.pf-mark.ok { background: #047857; }
.pf-mark.pf-inline { position: static; transform: none; display: inline-block; margin-inline-end: 5px; }

.pf-legend, .pf-points { border: 1px solid #111; border-radius: 6px; padding: 6px 9px; margin-bottom: 7px; }
.pf-legend h3, .pf-points h3 { font-size: 11px; margin: 0 0 4px; }
.pf-legend ul, .pf-points ul { margin: 0; padding-inline-start: 4px; list-style: none; columns: 2; column-gap: 18px; }
.pf-legend li, .pf-points li { break-inside: avoid; margin-bottom: 2px; font-size: 10.5px; }
.pf-legend-view { color: #666; margin-inline-end: 4px; }
.pf-tick { display: inline-block; width: 13px; height: 13px; border: 1px solid #111; margin-inline-end: 5px; text-align: center; line-height: 12px; font-size: 10px; }
.pf-tick.bad { color: #c81e1e; }
.pf-tick.ok { color: #047857; }

.pf-notes { border: 1px solid #111; border-radius: 6px; padding: 6px 9px; margin-bottom: 7px; }
.pf-notes-title { font-size: 11px; font-weight: 700; margin-bottom: 3px; }
.pf-notes-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pf-notes ul { margin: 0; padding-inline-start: 15px; }
.pf-notes li { font-size: 10px; margin-bottom: 2px; }

.pf-types { display: flex; gap: 5px; margin-bottom: 7px; }
.pf-type {
  flex: 1; display: flex; align-items: center; gap: 6px; justify-content: center;
  background: #111; color: #fff; border-radius: 5px; padding: 4px 6px; font-size: 10.5px; font-weight: 600;
}
.pf-box { width: 13px; height: 13px; background: #fff; color: #111; border-radius: 2px; text-align: center; line-height: 13px; font-size: 10px; }

.pf-signs { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 7px; }
.pf-signer, .pf-sign { border: 1px solid #111; border-radius: 6px; padding: 5px 9px; min-height: 46px; }
.pf-sign-label { display: block; font-size: 9.5px; color: #555; margin-bottom: 2px; }
.pf-signer strong { font-size: 12px; }
.pf-sign img { height: 32px; display: block; object-fit: contain; }
.pf-sign-line { display: block; border-bottom: 1px dotted #666; margin-top: 16px; }

@media print {
  @page { size: A4; margin: 9mm; }
  .printed-form { display: block !important; }
  .printed-form .pf-view { break-inside: avoid; }
  .damage-card { break-before: page; }
}

.logo-preview { height: 46px; width: auto; max-width: 150px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: var(--panel); }
.fields-table td { padding: 5px 8px; }
.fields-table input[type="checkbox"] { width: auto; }
.pf-lines { width: 100%; border-collapse: collapse; margin-bottom: 7px; font-size: 10.5px; }
.pf-lines th, .pf-lines td { border: 1px solid #111; padding: 3px 7px; text-align: start; }
.pf-lines thead th { background: #111; color: #fff; font-size: 10px; }
.pf-lines tfoot th { background: #eee; font-weight: 700; }
.pf-footer { text-align: center; font-size: 10.5px; color: #444; margin-top: 6px; }

/* Damage-grid crosshair: the hovered cell's row and column light up together. */
.grid-table tr.hl-row > *,
.grid-table .hl-col { background: color-mix(in srgb, var(--brand-soft) 62%, var(--panel)); }
.grid-table tr.hl-row > th.rowhead,
.grid-table thead th.hl-col { background: var(--brand-soft); color: var(--brand); }
.grid-table tr.hl-row > .hl-col { background: color-mix(in srgb, var(--brand) 16%, var(--panel)); }
.grid-table tr.hl-row > .hl-col.on { background: color-mix(in srgb, var(--brand) 28%, var(--panel)); }

/* Static demo build only. */
.demo-logins { border-top: 1px solid var(--line); padding-top: 14px; }
.demo-hint { font-size: 12.5px; color: var(--muted); margin-bottom: 9px; }
.demo-logins .chips { gap: 6px; }
.demo-logins .chip { cursor: pointer; font-size: 13px; padding: 6px 12px; }
.demo-logins .chip:hover { border-color: var(--brand); color: var(--brand); }
.nav-item.demo-reset { color: var(--warn); }
