/*
 * MhanDoctor office. Every colour, radius, space step, font size and shadow below comes from design/tokens.json,
 * defined once in the two :root blocks (test/tokens.test.ts fails on drift). Nothing else in this file or in
 * admin.js may carry a literal colour, radius or font size: use the variables.
 */
:root {
  --ground: #FBF7EF;
  --card: #FFFFFF;
  --ink: #33302A;
  --ink-muted: #6E655A;
  --ink-faint: #B4AA98;
  --line: #E9E1D2;
  --field-border: #D8CFBE;
  --action: #2B7A52;
  --action-foreground: #FFFFFF;
  --action-accent: #3E9B6C;
  --action-wash: #E3F1E8;
  --action-wash-foreground: #1F6A45;
  --warn-wash: #FBEFD9;
  --warn-wash-foreground: #7A5210;
  --warn: #D9962E;
  --problem-wash: #F8E1DC;
  --problem-wash-foreground: #9A3322;
  --problem: #C9503A;
  --plate: #16181A;
  --plate-foreground: #FFFFFF;
  --placeholder-a: #EFE8DA;
  --placeholder-b: #E6DDCB;

  --radius-card: 18px;
  --radius-control: 14px;
  --radius-field: 12px;
  --radius-badge: 8px;
  --radius-chip: 6px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --text-11: 11px;
  --text-12: 12px;
  --text-13: 13px;
  --text-14: 14px;
  --text-15: 15px;
  --text-16: 16px;
  --text-17: 17px;
  --text-20: 20px;
  --text-26: 26px;
  --text-32: 32px;

  --shadow-card: 0 2px 16px rgba(0,0,0,0.05);

  --size-touch-min: 48px;
  --size-button: 56px;
  --size-field: 60px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", "Myanmar Text", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Roboto Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #1C1915;
    --card: #26221E;
    --ink: #F0E8D8;
    --ink-muted: #B9AF9E;
    --ink-faint: #6E655A;
    --line: #3A342D;
    --field-border: #574F44;
    --action: #5DBB8A;
    --action-foreground: #10231A;
    --action-accent: #5DBB8A;
    --action-wash: #1E3A2B;
    --action-wash-foreground: #A8E0C0;
    --warn-wash: #40300F;
    --warn-wash-foreground: #F2CE85;
    --warn: #D9962E;
    --problem-wash: #4A1F18;
    --problem-wash-foreground: #F4B3A6;
    --problem: #E0705A;
    --plate: #16181A;
    --plate-foreground: #FFFFFF;
    --placeholder-a: #2E2923;
    --placeholder-b: #38322B;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: var(--text-15)/1.4 var(--sans); }
[hidden] { display: none !important; }
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: var(--text-17); font-weight: 700; }
h2 { font-size: var(--text-20); font-weight: 700; line-height: 1.25; }
h3 { font-size: var(--text-14); font-weight: 700; color: var(--ink-muted); }
a { color: var(--action); }
.muted { color: var(--ink-muted); }
.small { font-size: var(--text-13); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.top, main { max-width: 1280px; margin: 0 auto; padding: 0 var(--space-5); }
.top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding-top: var(--space-4); padding-bottom: var(--space-3); }
.top h1 { display: flex; align-items: center; gap: var(--space-2); }
.who { color: var(--ink-muted); font-size: var(--text-14); text-align: right; }
main { padding-bottom: var(--space-8); }

/* Buttons */
.btn { font: inherit; font-weight: 600; font-size: var(--text-14); color: var(--ink); background: var(--card); border: 1px solid var(--field-border);
  border-radius: var(--radius-field); padding: var(--space-2) var(--space-3); min-height: 40px; cursor: pointer; }
.btn:hover { border-color: var(--ink-muted); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--action-foreground); }
.btn.quiet { border-color: transparent; background: none; color: var(--action); }
.btn.danger { color: var(--problem-wash-foreground); }
.btn.danger.solid { background: var(--problem); border-color: var(--problem); color: var(--card); } /* as the phone: text-card on problem */
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--action-accent); outline-offset: 2px; }

/* Tabs: the selected one is lifted onto a card, as the phone lifts cards off the ground. */
.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin-bottom: var(--space-5); }
.tab { font: inherit; font-weight: 600; font-size: var(--text-15); color: var(--ink-muted); background: none; border: 0;
  border-radius: var(--radius-control); padding: var(--space-2) var(--space-4); min-height: 40px; cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--card); box-shadow: var(--shadow-card); }
.count { display: inline-block; margin-left: var(--space-2); padding: 0 var(--space-2); border-radius: var(--radius-chip); font-size: var(--text-12);
  font-weight: 700; background: var(--warn-wash); color: var(--warn-wash-foreground); }
.tabs .updated { margin-left: auto; color: var(--ink-muted); font-size: var(--text-13); }

section + section { margin-top: var(--space-6); }
section > h2, .head { margin-bottom: var(--space-3); }
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3); }
.head h2 { margin: 0; }
.card { background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: var(--space-4); }
.empty { padding: var(--space-5) var(--space-4); border: 2px dashed var(--line); border-radius: var(--radius-card); color: var(--ink-muted); }
.loading { color: var(--ink-muted); padding: var(--space-4) 0; }
.error { color: var(--problem-wash-foreground); background: var(--problem-wash); border-radius: var(--radius-field); padding: var(--space-3) var(--space-4); }

/* Chips, as on the phone: Quote/Draft amber, Done green, problems red. */
.chip { display: inline-block; font-size: var(--text-12); font-weight: 700; line-height: 1.35; padding: 2px var(--space-2); border-radius: var(--radius-chip);
  white-space: nowrap; background: var(--placeholder-a); color: var(--ink-muted); vertical-align: middle; }
.chip.good { background: var(--action-wash); color: var(--action-wash-foreground); }
.chip.warn { background: var(--warn-wash); color: var(--warn-wash-foreground); }
.chip.bad { background: var(--problem-wash); color: var(--problem-wash-foreground); }
.chip.plain { background: none; box-shadow: inset 0 0 0 1px var(--line); }

/* The licence plate: white characters on the plate black, region small above the serial. The one loud thing. */
.plate { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; background: var(--plate); color: var(--plate-foreground);
  border-radius: var(--radius-badge); padding: 3px var(--space-3) var(--space-1); font-family: var(--mono); white-space: nowrap; vertical-align: middle; }
.plate .region { font-size: var(--text-11); line-height: 14px; font-weight: 700; letter-spacing: 3px; padding-left: 3px; }
.plate .serial { font-size: var(--text-20); line-height: 24px; font-weight: 800; letter-spacing: 2px; padding-left: 2px; }
.plate.lg { padding: 3px 14px 5px; }
.plate.lg .serial { font-size: var(--text-26); line-height: 30px; }
.plate.code .serial { font-size: var(--text-20); letter-spacing: 4px; }
.plate.code.lg .serial { font-size: var(--text-32); line-height: 1.2; letter-spacing: 6px; }
.plate.code.lg { padding: var(--space-3) var(--space-5); }

/* Waiting devices */
.pending { display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-2) var(--space-5); align-items: center; padding: var(--space-4);
  background: var(--card); border: 2px dashed var(--warn); border-radius: var(--radius-card); }
.pending + .pending { margin-top: var(--space-3); }
.pending .name { font-weight: 700; font-size: var(--text-16); overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pending .actions { justify-content: flex-end; }

/* Tables */
.table-wrap { background: var(--card); border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: var(--text-13); font-weight: 600; color: var(--ink-muted); padding: var(--space-3) var(--space-4) var(--space-2); border-bottom: 1px solid var(--line); }
td { padding: var(--space-3) var(--space-4); vertical-align: middle; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
tr:last-child td { border-bottom: 0; }
td.actions-cell { width: 1%; white-space: nowrap; }
td .actions { flex-wrap: nowrap; justify-content: flex-end; }
td strong { font-weight: 700; }
td.right, th.right { text-align: right; }
tr.off td:not(.actions-cell) { color: var(--ink-muted); }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--ground); }
.code-inline { font-family: var(--mono); letter-spacing: 1px; }

details > summary { cursor: pointer; font-weight: 600; color: var(--ink-muted); padding: var(--space-2) 0; }
details[open] > summary { margin-bottom: var(--space-2); }

/* Whole-page states: waiting, removed, not for the office, unsupported, error */
.state { max-width: 34rem; margin: 9vh auto 0; text-align: center; }
.state h2 { font-size: var(--text-26); margin-bottom: var(--space-2); }
.state p + p, .state .plate, .state form, .state .btn { margin-top: var(--space-5); }
.state form { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; }

/* Forms and dialogs */
dialog { width: min(28rem, calc(100vw - 2 * var(--space-4))); padding: var(--space-5); color: var(--ink); background: var(--card);
  border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
dialog::backdrop { background: color-mix(in srgb, var(--plate) 55%, transparent); }
dialog h2 { margin-bottom: var(--space-3); }
dialog p { margin-bottom: var(--space-3); }
label { display: block; font-weight: 600; font-size: var(--text-14); margin-bottom: var(--space-3); }
input[type="text"], input[type="search"], input[type="date"], input[type="time"], input[type="datetime-local"], input[type="number"], select, textarea {
  display: block; width: 100%; margin-top: var(--space-1); font: inherit; font-size: var(--text-16); color: var(--ink); background: var(--ground);
  border: 2px solid var(--field-border); border-radius: var(--radius-field); padding: var(--space-2) var(--space-3); min-height: var(--size-touch-min); }
input:focus, select:focus, textarea:focus { border-color: var(--action-accent); outline: none; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--action); width: 18px; height: 18px; margin: 0; vertical-align: middle; }
textarea { resize: vertical; min-height: 72px; }
.state input[type="text"] { width: 15rem; margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.form-error { color: var(--problem-wash-foreground); font-weight: 600; margin: 0; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 600; margin: 0; cursor: pointer; min-height: 32px; }

.toast { position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%); max-width: calc(100vw - 2 * var(--space-4)); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control); background: var(--problem-wash); color: var(--problem-wash-foreground); font-weight: 600; box-shadow: var(--shadow-card); z-index: 2000; }

/* ---- Dispatch: map left, the workers nearest the customer right ---- */
.dispatch { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-4); align-items: start; }
.map { height: calc(100vh - 170px); min-height: 420px; border-radius: var(--radius-card); box-shadow: var(--shadow-card); background: var(--placeholder-a); z-index: 0; }
.side { display: flex; flex-direction: column; gap: var(--space-3); max-height: calc(100vh - 170px); min-height: 420px; }
.banner { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-field);
  background: var(--action-wash); color: var(--action-wash-foreground); font-size: var(--text-13); font-weight: 600; }
.banner::before { content: ""; width: 8px; height: 8px; border-radius: var(--radius-badge); background: var(--action); flex: none; }
.banner.idle { background: var(--placeholder-a); color: var(--ink-muted); }
.banner.idle::before { background: var(--ink-faint); }
.pin-form { display: flex; gap: var(--space-2); align-items: end; }
.pin-form label { flex: 1; margin: 0; }
.pin-help { font-size: var(--text-13); color: var(--ink-muted); }
.workers { overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-2); padding: 2px; margin: -2px; }
.worker { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--space-3); padding: var(--space-3) var(--space-4); background: var(--card);
  border-radius: var(--radius-control); box-shadow: var(--shadow-card); cursor: pointer; }
.worker:hover { box-shadow: var(--shadow-card), inset 0 0 0 1px var(--field-border); }
.worker .name { font-weight: 700; font-size: var(--text-16); overflow-wrap: anywhere; }
.worker .dist { font-weight: 800; font-size: var(--text-17); text-align: right; font-variant-numeric: tabular-nums; }
.worker .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: var(--text-13); color: var(--ink-muted); }
.worker .meta .check { margin-left: auto; font-size: var(--text-13); min-height: 0; }
.worker.stale .dist, .worker.stale .when { color: var(--ink-muted); }
.worker.off .name { color: var(--ink-muted); font-weight: 600; }
.worker.nearest { box-shadow: var(--shadow-card), inset 0 0 0 2px var(--action-accent); }

/* Leaflet paths carry these classes; CSS wins over the stroke/fill attributes Leaflet writes. */
.mk-on { stroke: var(--card); fill: var(--action); stroke-width: 3; fill-opacity: 1; }
.mk-stale { stroke: var(--card); fill: var(--ink-faint); stroke-width: 3; fill-opacity: 1; }
.mk-acc { stroke: var(--action-accent); fill: var(--action-accent); stroke-width: 1; fill-opacity: 0.12; }
.mk-acc.stale { stroke: var(--ink-faint); fill: var(--ink-faint); }
.mk-customer { stroke: var(--plate); fill: var(--warn); stroke-width: 3; fill-opacity: 1; }
.mk-trail { stroke: var(--action-accent); stroke-width: 3; stroke-dasharray: 6 6; fill: none; }
.mk-entry { stroke: var(--card); fill: var(--plate); stroke-width: 3; fill-opacity: 1; }
.leaflet-container { font: var(--text-13)/1.35 var(--sans); background: var(--placeholder-a); }
.leaflet-tooltip.tip { background: var(--card); color: var(--ink); border: 0; border-radius: var(--radius-chip); box-shadow: var(--shadow-card);
  font-size: var(--text-13); font-weight: 600; padding: 2px var(--space-2); }
.leaflet-tooltip.tip::before { display: none; }
.leaflet-tooltip.tip.stale { color: var(--ink-muted); }
.leaflet-tooltip.tip .t { display: block; font-weight: 400; font-size: var(--text-12); color: var(--ink-muted); }
.leaflet-control-attribution { font-size: var(--text-11); }
.map-note { position: absolute; z-index: 1000; left: var(--space-3); right: var(--space-3); top: var(--space-3); margin: 0; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-field); background: var(--card); color: var(--ink-muted); font-size: var(--text-13); box-shadow: var(--shadow-card); }

/* ---- Entries ---- */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: end; margin-bottom: var(--space-4); }
.filters label { margin: 0; min-width: 10rem; }
.filters label.grow { flex: 1; min-width: 12rem; }
.filters .hint { font-size: var(--text-13); color: var(--ink-muted); padding-bottom: var(--space-3); }
.price { font-weight: 700; font-size: var(--text-16); white-space: nowrap; font-variant-numeric: tabular-nums; }
.more { display: flex; justify-content: center; margin-top: var(--space-4); }

.detail-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-4); margin-bottom: var(--space-5); }
.detail-top .grow { flex: 1; min-width: 10rem; }
.detail-top .car { font-size: var(--text-17); font-weight: 600; overflow-wrap: anywhere; }
.detail-top .right { display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-1); }
.detail-top .price { font-size: var(--text-20); }
.detail { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: var(--space-5); align-items: start; }
.detail > div { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.photo { display: block; width: 100%; max-height: 420px; object-fit: contain; border-radius: var(--radius-card); background: var(--placeholder-a); }
.ph { display: flex; align-items: flex-end; height: 200px; padding: var(--space-3); border-radius: var(--radius-card); color: var(--ink-muted); font-size: var(--text-13);
  background: repeating-linear-gradient(135deg, var(--placeholder-a) 0 12px, var(--placeholder-b) 12px 24px); }
.fields { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); }
.fields dt { color: var(--ink-muted); font-size: var(--text-14); }
.fields dd { overflow-wrap: anywhere; }
.mini-map { height: 200px; border-radius: var(--radius-control); z-index: 0; }
.history li + li { border-top: 1px solid var(--line); }
.history button { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-2) 0; background: none; border: 0; font: inherit;
  color: inherit; text-align: left; cursor: pointer; }
.history button:hover .car { text-decoration: underline; }
.history .car { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.thread { display: flex; flex-direction: column; gap: var(--space-3); }
.note { align-self: flex-end; max-width: 85%; background: var(--card); border-radius: var(--radius-card) var(--radius-card) var(--space-1) var(--radius-card);
  box-shadow: var(--shadow-card); padding: var(--space-2) var(--space-4); display: flex; flex-direction: column; gap: 2px; }
.note.office { align-self: flex-start; background: var(--action-wash); box-shadow: none; border-radius: var(--radius-card) var(--radius-card) var(--radius-card) var(--space-1); }
.note .who { font-size: var(--text-12); font-weight: 700; color: var(--ink-muted); text-align: left; }
.note.office .who { color: var(--action-wash-foreground); }
.note .body { font-size: var(--text-16); white-space: pre-wrap; overflow-wrap: anywhere; }
.note .meta { font-size: var(--text-12); color: var(--ink-muted); align-self: flex-end; display: flex; gap: var(--space-2); align-items: center; }
.note.office .meta { color: var(--action-wash-foreground); }
.note img { display: block; max-width: 100%; max-height: 320px; border-radius: var(--radius-control); margin: var(--space-1) 0; }
.note audio { display: block; width: 260px; max-width: 100%; margin: var(--space-1) 0; }
.composer { display: flex; flex-direction: column; gap: var(--space-3); }
.composer textarea { margin: 0; }
.composer .row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.composer .row .btn { margin-left: auto; }

/* ---- Shifts ---- */
.shifts { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--space-3); }
.shift { display: flex; flex-direction: column; gap: var(--space-3); }
.shift .head { margin: 0; }
.shift .head h3 { color: var(--ink); font-size: var(--text-17); }
.days { display: flex; flex-wrap: wrap; gap: var(--space-1); border: 0; padding: 0; margin: 0; }
.days legend { font-weight: 600; font-size: var(--text-14); margin-bottom: var(--space-1); padding: 0; }
.day { position: relative; margin: 0; }
.day input { position: absolute; opacity: 0; width: 100%; height: 100%; inset: 0; cursor: pointer; }
.day span { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 36px; padding: 0 var(--space-2); border-radius: var(--radius-chip);
  font-size: var(--text-13); font-weight: 700; background: var(--ground); color: var(--ink-muted); box-shadow: inset 0 0 0 1px var(--field-border); }
.day input:checked + span { background: var(--action-wash); color: var(--action-wash-foreground); box-shadow: inset 0 0 0 1px var(--action-accent); }
.day input:focus-visible + span { outline: 3px solid var(--action-accent); outline-offset: 2px; }
.times { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.times label { margin: 0; }
.shift .bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.shift .bar .grow { flex: 1; }

/* ---- Settings ---- */
.settings { max-width: 34rem; display: flex; flex-direction: column; gap: var(--space-4); }
.settings label { margin: 0; }
.settings .help { font-weight: 400; color: var(--ink-muted); font-size: var(--text-13); margin-top: var(--space-1); }

/* Narrow screens: one column; table rows become stacked blocks, each value named by its column. */
@media (max-width: 900px) {
  .dispatch, .detail { grid-template-columns: 1fr; }
  .map { height: 55vh; min-height: 300px; }
  .side { max-height: none; min-height: 0; }
}
@media (max-width: 720px) {
  .top, main { padding: 0 var(--space-4); }
  .top { padding-top: var(--space-3); padding-bottom: var(--space-2); }
  .pending { grid-template-columns: 1fr; }
  .pending .actions { justify-content: flex-start; }
  .btn { min-height: 44px; }
  .tab { padding: var(--space-2) var(--space-3); }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tr, td { display: block; }
  tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
  tr:last-child { border-bottom: 0; }
  td { padding: 2px 0; border: 0; }
  td.right { text-align: left; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-muted); font-size: var(--text-13); }
  td.bare::before { content: none; }
  td.actions-cell { width: auto; white-space: normal; padding-top: var(--space-2); }
  td .actions { flex-wrap: wrap; justify-content: flex-start; }
  .tabs .updated { display: none; }
  .shifts { grid-template-columns: 1fr; }
  .filters label, .filters label.grow { min-width: 0; flex: 1 1 100%; }
  .note { max-width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: rise 0.14s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } }
}
