/* Repair Tracker — single stylesheet (app + printable receipt). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #d9dee5;
  --primary: #1f5fbf;
  --primary-text: #ffffff;
  --danger: #b42318;
  --due: #b42318;
  --focus: #1f5fbf55;
  --radius: 8px;
  --shadow: 0 1px 2px #0000000f;

  /* status colours: background / text */
  --st-received: #e8eefc;    --st-received-t: #1d4ea8;
  --st-diagnosing: #f1e8fd;  --st-diagnosing-t: #6b2fb5;
  --st-awaiting_approval: #fde7f1; --st-awaiting_approval-t: #a3195b;
  --st-waiting_parts: #fff1d6; --st-waiting_parts-t: #8a5300;
  --st-in_repair: #dff3f7;   --st-in_repair-t: #0c6378;
  --st-ready: #def5e3;       --st-ready-t: #18703a;
  --st-collected: #eceef1;   --st-collected-t: #4a525d;
  --st-cancelled: #fbe4e2;   --st-cancelled-t: #9f2a1e;

  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --border: #2e3640;
    --primary: #5b9bff;
    --primary-text: #0b1220;
    --danger: #ff7b6e;
    --due: #ff8a7e;
    --focus: #5b9bff66;
    --shadow: none;

    --st-received: #1e2c47;    --st-received-t: #a8c4ff;
    --st-diagnosing: #2e2245;  --st-diagnosing-t: #d2b6ff;
    --st-awaiting_approval: #401a2e; --st-awaiting_approval-t: #ffa8cf;
    --st-waiting_parts: #3a2c10; --st-waiting_parts-t: #ffd27a;
    --st-in_repair: #10343d;   --st-in_repair-t: #87dbee;
    --st-ready: #143522;       --st-ready-t: #8fe0a8;
    --st-collected: #262b31;   --st-collected-t: #b4bcc6;
    --st-cancelled: #3f1d1a;   --st-cancelled-t: #ffaaa1;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0.75rem 0 0.25rem; color: var(--muted); }
h3:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.wrap { overflow-wrap: anywhere; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.due { color: var(--due); font-weight: 600; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---------- layout ---------- */

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a { padding: 0.35rem 0.7rem; border-radius: var(--radius); text-decoration: none; color: var(--muted); }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }
.me { margin-left: auto; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 0.6rem; }
.menu { display: flex; align-items: center; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar .menu-btn { display: none; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin-top: 0; }
.login-card .btn { width: 100%; }
.container { max-width: 1100px; margin: 0 auto; padding: 1rem; outline: none; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: 2.5rem; padding: 0.45rem 0.9rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled, .btn.is-busy { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.9rem; }
.btn-big { font-size: 1.1rem; font-weight: 600; min-height: 3rem; padding: 0.6rem 1.3rem; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.45rem 0.6rem; min-height: 2.5rem; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--primary); }
[aria-invalid="true"] { border-color: var(--danger); }
.input-short { max-width: 10rem; }
.input-qty { max-width: 5.5rem; }

.field { margin-bottom: 0.9rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.field-error { color: var(--danger); font-size: 0.9rem; margin: 0.3rem 0; font-weight: 600; }
.form { max-width: 640px; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: flex-end; margin-top: 0.75rem; }
.inline-form .field { margin-bottom: 0; }
.inline-form .field:has([name="description"]) { flex: 1 1 14rem; }
.inline-form > .btn { margin-bottom: 0; }
.inline-form .field-error { flex-basis: 100%; }

.alert { padding: 0.6rem 0.8rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin: 0 0 1rem; display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; }
.alert-error { border-color: var(--danger); color: var(--danger); }
.alert-info { background: var(--st-received); color: var(--st-received-t); border-color: transparent; font-size: 0.9rem; }

/* ---------- list ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
.toolbar .search { flex: 1 1 16rem; }
.toolbar select { width: auto; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; cursor: pointer; }
.empty { padding: 2rem 0; text-align: center; color: var(--muted); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
.table th.num, .table td.num { text-align: right; }
.list-results .table { border: 1px solid var(--border); border-radius: var(--radius); }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--bg); }
.ticket { font-weight: 600; font-family: ui-monospace, Menlo, Consolas, monospace; text-decoration: none; white-space: nowrap; }
.row-actions { text-align: right; width: 1%; }

.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.badge-received      { background: var(--st-received);      color: var(--st-received-t); }
.badge-diagnosing    { background: var(--st-diagnosing);    color: var(--st-diagnosing-t); }
.badge-awaiting_approval { background: var(--st-awaiting_approval); color: var(--st-awaiting_approval-t); }
.badge-waiting_parts { background: var(--st-waiting_parts); color: var(--st-waiting_parts-t); }
.badge-in_repair     { background: var(--st-in_repair);     color: var(--st-in_repair-t); }
.badge-ready         { background: var(--st-ready);         color: var(--st-ready-t); }
.badge-collected     { background: var(--st-collected);     color: var(--st-collected-t); }
.badge-cancelled     { background: var(--st-cancelled);     color: var(--st-cancelled-t); }

/* Tables become stacked cards on phones */
@media (max-width: 640px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border-bottom: 1px solid var(--border); padding: 0.4rem 0; }
  .table-cards td { border: 0; padding: 0.15rem 0.6rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .table-cards td::before { content: attr(data-label); color: var(--muted); font-size: 0.85rem; font-weight: 400; text-align: left; }
  .table-cards td.row-actions { width: 100%; justify-content: flex-end; }
  .table-cards td.row-actions::before { content: none; }
  .toolbar .btn-big { width: 100%; }
  .toolbar select { flex: 1; }
}

/* ---------- detail ---------- */

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.ticket-big { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 2rem; margin: 0 0 0.25rem; letter-spacing: 0.02em; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.btn-status { border-color: transparent; font-weight: 600; opacity: 0.75; }
.btn-status:hover { opacity: 1; border-color: currentColor; }
.btn-status.is-current { opacity: 1; outline: 2px solid currentColor; outline-offset: 1px; cursor: default; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.totals > div { display: flex; flex-direction: column; }
.totals span { color: var(--muted); font-size: 0.85rem; }
.totals strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.totals .due strong { color: var(--due); }

/* ---------- reports ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat span { color: var(--muted); font-size: 0.9rem; }
.stat strong { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.bar-cell { width: 35%; }
.bar { height: 0.7rem; background: var(--primary); border-radius: 4px; min-width: 2px; }

/* ---------- receipt ---------- */

.receipt-page { background: var(--bg); }
.receipt-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0.75rem 1rem; justify-content: center; }
.segmented { display: inline-flex; }
.segmented .btn { border-radius: 0; }
.segmented .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.segmented .btn.is-current { background: var(--text); color: var(--bg); border-color: var(--text); }

/* The receipt itself is always black-on-white, also in dark mode. */
.sheet {
  color-scheme: light; color: #111; background: #fff;
  width: 100%; max-width: 190mm; margin: 0 auto 2rem; padding: 8mm;
  border-radius: 4px; box-shadow: 0 2px 12px #0003;
  font-size: 10.5pt; line-height: 1.35;
}
.sheet .muted { color: #555; }
body[data-layout="a5"] .sheet { max-width: 128mm; }
.receipt { break-inside: avoid; }
.receipt-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid #111; padding-bottom: 2mm; margin-bottom: 3mm; }
.shop-name { font-weight: 700; font-size: 12pt; }
.shop-line { font-size: 9pt; color: #444; }
.copy-label { font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.08em; border: 1px solid #111; padding: 0.5mm 2mm; align-self: flex-start; white-space: nowrap; }
.ticket-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 3mm; }
.ticket-row .right { text-align: right; }
.label { font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.06em; color: #555; }
.ticket-huge { font-family: ui-monospace, Menlo, Consolas, "Liberation Mono", monospace; font-size: 26pt; font-weight: 800; line-height: 1.1; letter-spacing: 0.02em; }
.receipt-facts { display: grid; grid-template-columns: max-content 1fr; gap: 1mm 4mm; margin: 0 0 3mm; }
.receipt-facts dt { font-weight: 600; }
.receipt-facts dd { margin: 0; overflow-wrap: anywhere; }
.handwrite { border: 1px solid #111; border-radius: 2mm; padding: 2mm 3mm 1mm; margin-bottom: 3mm; }
.write-line { display: flex; align-items: flex-end; gap: 2mm; height: 8mm; }
.write-line span:first-child { white-space: nowrap; font-weight: 600; }
.write-line .blank { flex: 1; border-bottom: 1px solid #111; height: 100%; }
.contact-note { margin: 1.5mm 0 0; font-size: 8.5pt; font-style: italic; }
.terms { font-size: 8pt; color: #333; margin-bottom: 2mm; }
.terms ol { margin: 0.5mm 0 0; padding-left: 4.5mm; }
.receipt-foot .small { font-size: 8.5pt; margin: 1.5mm 0 0; }
.cut-line { border-top: 1px dashed #777; margin: 6mm -8mm; position: relative; }
.cut-line::after { content: "✂"; position: absolute; left: 4mm; top: -0.75em; background: #fff; color: #777; padding: 0 1mm; }

@page { size: A4; margin: 10mm; }
@page a5 { size: A5; margin: 8mm; }

.sku-row { margin-top: 0.3rem; }
.sku-row input { width: 100%; max-width: 16rem; font-size: 0.85rem; }
.import-cols .field { min-width: 9rem; }

/* ---------- phones (≤ 640px): compact layout ---------- */

@media (min-width: 641px) {
  .mobile-only { display: none !important; }
  details.adder > summary { display: none; }
}
@media (max-width: 640px) {
  .desktop-only, .m-hide { display: none !important; }

  /* top bar: brand + menu button; the menu drops down */
  .topbar { gap: 0.5rem; padding: 0.4rem 0.75rem; }
  .topbar .menu-btn { display: inline-flex; margin-left: auto; }
  .menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0.25rem; padding: 0.25rem 0 0.5rem; }
  .topbar.menu-open .menu { display: flex; }
  .nav { flex-direction: column; gap: 0.1rem; }
  .nav a { padding: 0.7rem 0.75rem; font-size: 1.05rem; }
  .me { margin: 0.4rem 0 0; justify-content: space-between; padding: 0.5rem 0.75rem 0; border-top: 1px solid var(--border); }
  .container { padding: 0.75rem; }
  .card { padding: 0.8rem; margin-bottom: 0.75rem; }
  h1 { font-size: 1.3rem; margin: 0.25rem 0 0.75rem; }

  /* compact rows: a | b  /  c | d  /  e */
  .table-compact tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 0.75rem; row-gap: 0.15rem;
    grid-template-areas: "a b" "c d" "e e"; align-items: center; padding: 0.55rem 0.6rem;
  }
  .table-compact td { display: block; padding: 0; text-align: left; }
  .table-compact td::before { content: none; }
  .table-compact .m-a { grid-area: a; font-weight: 600; }
  .table-compact .m-b { grid-area: b; justify-self: end; text-align: right; }
  .table-compact .m-c { grid-area: c; min-width: 0; }
  .table-compact .m-d { grid-area: d; justify-self: end; text-align: right; }
  .table-compact .m-e { grid-area: e; }
  /* row with a delete button: it sits at the right edge across both lines */
  .table-compact tr:has(> .m-x) { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "a b x" "c d x"; }
  .table-compact .m-x { grid-area: x; align-self: center; }
  .table-compact td.row-actions { width: auto; }

  /* repair page: totals first, then the rest */
  .detail { display: flex; flex-direction: column; }
  .detail > .detail-head { order: -3; }
  .detail > .detail-msg { order: -2; }
  .detail > .totals { order: -1; }
  .detail-head { margin-bottom: 0.25rem; }
  .detail-head .actions { width: 100%; }
  .detail-head .actions .btn { flex: 1 1 auto; }
  .ticket-big { font-size: 1.6rem; }
  .totals { gap: 0.5rem; }
  .totals strong { font-size: 1.1rem; }
  .status-card { display: flex; align-items: center; gap: 0.75rem; }
  .status-card h2 { margin: 0; }
  .status-select { flex: 1; min-height: 2.75rem; font-weight: 600; }
  details.adder { margin-top: 0.75rem; }
  details.adder > summary { list-style: none; width: 100%; }
  details.adder > summary::-webkit-details-marker { display: none; }
  details.adder[open] > summary { margin-bottom: 0.5rem; }

  /* finger-sized buttons */
  .btn-small { min-height: 2.75rem; min-width: 2.75rem; }
}

/* ---------- public status page (customers, no login) ---------- */

.public-status { max-width: 36rem; }
.public-shop { margin: 1rem 0 0; font-weight: 600; }
.public-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.public-msg { font-size: 1.05rem; margin: 0.75rem 0 1rem; }
.public-contact a { word-break: break-all; }
.steps { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.steps li { font-size: 0.8rem; padding: 0.2rem 0.55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.steps li.done { color: var(--text); border-color: var(--muted); }
.steps li.done::before { content: "✓ "; }
.steps li.current { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.status-link-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.status-link-row input { flex: 1 1 18rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8rem; }
.status-link-box { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.qr { background: #fff; flex: none; }
.status-link-main { flex: 1 1 18rem; min-width: 0; }
.receipt-qr { display: flex; gap: 4mm; align-items: center; margin: 0 0 3mm; font-size: 9pt; }
.receipt-qr .small { font-size: 8pt; }
.receipt-qr .url { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 7pt; overflow-wrap: anywhere; }

@media print {
  .no-print, .topbar { display: none !important; }
  body, .receipt-page { background: #fff; }
  .sheet { box-shadow: none; margin: 0; padding: 0; max-width: none; border-radius: 0; }
  body[data-layout="a5"] .sheet { page: a5; max-width: none; }
  /* A4: each copy fills roughly half the sheet */
  body[data-layout="a4"] .receipt { min-height: 132mm; }
  .cut-line { margin: 4mm 0; }
}

/* ---------- photos ---------- */

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.6rem; }
.photo { position: relative; margin: 0; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--bg); border: 1px solid var(--border); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del { position: absolute; top: 0.3rem; right: 0.3rem; background: var(--surface); }
.photo-actions { margin-top: 0.75rem; }
.photo-status { margin-top: 0.5rem; }
.photo-status .alert { margin: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- invoice ---------- */

.invoice-sheet { font-size: 10pt; }
.inv-head { display: flex; justify-content: space-between; gap: 8mm; border-bottom: 2px solid #111; padding-bottom: 4mm; margin-bottom: 5mm; }
.inv-company { font-size: 9.5pt; line-height: 1.4; }
.inv-company .shop-name { font-size: 14pt; margin-bottom: 1mm; }
.inv-title { text-align: right; }
.inv-word { font-size: 22pt; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.inv-meta { display: grid; grid-template-columns: auto auto; gap: 0.5mm 4mm; margin: 2mm 0 0; justify-content: end; }
.inv-meta dt { color: #555; }
.inv-meta dd { margin: 0; font-weight: 600; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-bottom: 5mm; }
.inv-parties .handwrite { margin: 0; }
.inv-repair .value { font-weight: 600; margin: 1mm 0; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 4mm; }
.inv-table th, .inv-table td { padding: 1.6mm 2mm; border-bottom: 1px solid #ccc; text-align: left; vertical-align: top; }
.inv-table th { font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.05em; color: #444; border-bottom: 1.5px solid #111; }
.inv-table .num, .inv-table th.num { text-align: right; }
.inv-table tfoot td { border-bottom: 0; text-align: right; }
.inv-table tfoot td.num { font-variant-numeric: tabular-nums; }
.inv-total td { border-top: 1.5px solid #111; font-weight: 700; }
.inv-balance td { font-size: 12pt; font-weight: 800; }
.inv-table-small td { font-size: 9pt; padding: 1mm 2mm; }
.inv-payments { width: 60%; margin-left: auto; }
.inv-foot { border-top: 1px solid #ccc; padding-top: 3mm; margin-top: 6mm; font-size: 9pt; }
.inv-foot p { margin: 0 0 1.5mm; }
@media (max-width: 640px) { .inv-parties { grid-template-columns: 1fr; } .inv-payments { width: 100%; } }

/* ---------- print helpers ---------- */

.print-only { display: none; }
@media print {
  .print-only { display: block; }
  .no-print { display: none !important; }
  .print-head { margin-bottom: 4mm; }
  .print-head strong { font-size: 14pt; }
  body:not(.receipt-page) { background: #fff; color: #111; color-scheme: light; }
  body:not(.receipt-page) .card { box-shadow: none; break-inside: avoid; background: #fff; color: #111; }
  body:not(.receipt-page) .container { max-width: none; padding: 0; }
}
@media print { .bar, .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---------- work log & history ---------- */

.log-form { display: flex; gap: 0.6rem; align-items: flex-start; flex-wrap: wrap; }
.log-form .field { flex: 1 1 18rem; margin-bottom: 0; }
.log-form .field-error { flex-basis: 100%; }
.log-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.log-entry { border-left: 3px solid var(--primary); padding: 0.1rem 0 0.1rem 0.75rem; margin-bottom: 0.9rem; }
.log-meta { color: var(--muted); font-size: 0.85rem; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.log-del { margin-left: auto; }
.history summary { cursor: pointer; list-style: none; }
.history summary::-webkit-details-marker { display: none; }
.history summary h2 { display: inline; margin: 0; }
.history summary::before { content: "▸ "; color: var(--muted); }
.history[open] summary::before { content: "▾ "; }
.history[open] summary { margin-bottom: 0.75rem; }
.nowrap { white-space: nowrap; }

/* ---------- parts & orders ---------- */

.badge-o-draft     { background: var(--st-waiting_parts); color: var(--st-waiting_parts-t); }
.badge-o-ordered   { background: var(--st-received);  color: var(--st-received-t); }
.badge-o-received  { background: var(--st-ready);     color: var(--st-ready-t); }
.badge-o-cancelled { background: var(--st-cancelled); color: var(--st-cancelled-t); }
.sync { display: inline-block; width: 1.4rem; text-align: center; font-weight: 700; }
.sync-ok { color: var(--st-ready-t); }
.sync-pending { color: var(--st-waiting_parts-t); }
.sync-none { color: var(--muted); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 0.25rem 0; border-bottom: 1px solid var(--border); }
.plain li:last-child { border-bottom: 0; }
.subhead { font-weight: 600; margin-top: 1rem; color: var(--muted); font-size: 0.9rem; }
.stock-use { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px dashed var(--border); }
.stock-use .grow { flex: 1 1 18rem; }
.on-order { margin-bottom: 0.5rem; }
.order-table input, .order-table select { min-width: 0; }
.order-table td:first-child { min-width: 16rem; }
.order-table [name="new_part_no"] { margin-top: 0.3rem; }
.order-totals { display: flex; gap: 2rem; justify-content: flex-end; margin: 0.5rem 0 1rem; flex-wrap: wrap; }
.order-totals > div { display: flex; flex-direction: column; align-items: flex-end; }
.order-totals span { color: var(--muted); font-size: 0.85rem; }
.order-totals strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
