:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #667085;
  --line: #e3e6ea;
  --accent: #1f6f54;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --warn-bg: #fef6e7;
  --bad: #b42318;
  --bad-bg: #fef3f2;
  --good: #067647;
  --good-bg: #ecfdf3;
  --info: #175cd3;
  --info-bg: #eff8ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --sample: #6941c6;
  --sample-bg: #f4f3ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101318; --panel: #171b21; --ink: #e7eaee; --muted: #9aa4b2; --line: #272d36;
    --accent: #2f9e77; --warn-bg: #2a1f0d; --bad-bg: #2a1413; --good-bg: #0e2318;
    --info-bg: #0f1d33; --sample-bg: #1d1730;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #101318; --panel: #171b21; --ink: #e7eaee; --muted: #9aa4b2; --line: #272d36;
  --accent: #2f9e77; --warn-bg: #2a1f0d; --bad-bg: #2a1413; --good-bg: #0e2318;
  --info-bg: #0f1d33; --sample-bg: #1d1730;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.sample-banner {
  background: var(--sample-bg); color: var(--sample); border-bottom: 1px solid var(--line);
  padding: 7px 16px; font-size: 12.5px; font-weight: 600; letter-spacing: .01em;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.sample-banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sample); flex: none; }

header.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header.top h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* The office menu (public/nav.js), the same on every office page. */
nav.appnav {
  display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
nav.appnav .brand { font-weight: 700; font-size: 16px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; margin-right: 6px; }
nav.appnav .links { display: flex; gap: 2px; flex-wrap: wrap; }
nav.appnav .grow { flex: 1 1 auto; }
nav.appnav .who { color: var(--muted); font-size: 13px; }
nav.appnav .navlink {
  font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); text-decoration: none;
  background: none; border: 0; border-radius: 8px; padding: 7px 10px; cursor: pointer;
}
nav.appnav .navlink:hover { color: var(--ink); background: color-mix(in srgb, var(--accent) 8%, transparent); }
nav.appnav .navlink.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
/* A page's own controls sit under the menu, not stuck to the top. */
nav.appnav + header.top { position: static; }
header.top .grow { flex: 1 1 auto; }
/* Running late / Filling up on the board: a chip each, the list opens over the page. */
.alert-chip { position: relative; display: inline-block; margin-right: 8px; }
.alert-chip > summary { list-style: none; cursor: pointer; }
.alert-chip > summary::-webkit-details-marker { display: none; }
.alert-chip > summary .tag { font-size: 12px; padding: 3px 9px; }
.alert-chip[open] > summary .tag { box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 30%, transparent); }
.alert-pop { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; width: min(620px, 90vw); max-height: 50vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(16, 24, 40, .18); font-size: 13px; }
.alert-pop h3 { margin: 0 0 6px; font-size: 13px; }
header.top .top-row { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; flex: 1 1 auto; }
/* A page's own controls in the menu line (the board: warehouse, date, find) - a box of their own after
   the links, set apart by a divider and a tint, so they read as the board's filters, not menu items. */
.nav-tools { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; margin-left: 6px; padding: 3px 4px 3px 12px;
  border-left: 1px solid var(--line); }
nav.appnav .nav-tools { background: color-mix(in srgb, var(--accent) 6%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
  border-radius: 10px; padding: 3px 6px; }
.nav-tool { display: inline-flex; align-items: center; gap: 5px; padding: 0 5px; font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; }
.nav-tool + .nav-tool { border-left: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line)); }
.nav-tool select, .nav-tool input { font-size: 13px; padding: 4px 6px; height: 30px; text-transform: none; letter-spacing: 0; }
.nav-tool select { max-width: 190px; }
.nav-tool input[type="date"] { width: 132px; }
.nav-tool input[type="search"] { width: 170px; }
/* The board's warehouse and day: what everything on the page is for, so larger and in red with white text (the office asked). */
nav.appnav .nav-tools:has(.nav-tool.key) { background: #f25c5c; border-color: #f25c5c; padding: 5px 8px; }
nav.appnav .nav-tools:has(.nav-tool.key) .nav-tool { color: #fff; }
nav.appnav .nav-tools:has(.nav-tool.key) .nav-tool + .nav-tool { border-left-color: rgba(255, 255, 255, .45); }
.nav-tool.key { font-size: 12px; font-weight: 700; gap: 7px; padding: 0 8px; }
.nav-tool.key select, .nav-tool.key input { font-size: 16px; font-weight: 700; color: #000; height: 40px; padding: 5px 10px;
  border: 2px solid #fff; background: #fff; color-scheme: light; }
/* The opened list stays dark on light, as everywhere. */
.nav-tool.key select option { color: var(--ink); background: var(--panel); }
.nav-tool.key select { max-width: 280px; }
.nav-tool.key input[type="date"] { width: 175px; }
/* A smaller laptop screen: the captions go (still read out by screen readers), the boxes get narrower,
   so the menu stays on one line. The search box says "Find..." itself. */
@media (max-width: 1460px) {
  .nav-tool:not(.key) > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav-tool select { max-width: 165px; }
  .nav-tool input[type="search"] { width: 150px; }
}

label.field { display: inline-flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
select, input:not([type]), input[type=text], input[type=date], input[type=search], input[type=time],
input[type=number], input[type=tel], input[type=email], input[type=password], textarea {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 8px 12px;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
button.small { padding: 4px 8px; font-size: 12px; border-radius: 6px; }

main { padding: 16px; max-width: 1560px; margin: 0 auto; }

.buckets { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.bucket {
  flex: 0 0 auto; min-width: 118px; text-align: left; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer;
}
.bucket[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.bucket .n { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bucket .k { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel > h2 { font-size: 13px; margin: 0; padding: 11px 14px; border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.panel .body { padding: 12px 14px; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .cols { grid-template-columns: minmax(0, 1fr); } }
/* The dispatcher board: the deliveries list / map uses the whole window; routes and the order
   system queue sit side by side under it (one above the other on a narrow screen). */
main.board { max-width: none; }
/* Plan the day: nearly the whole window - the drivers on the left, their routes on the map. */
dialog.plan-dlg { max-width: none; width: calc(100vw - 32px); max-height: calc(100vh - 24px); }
dialog.plan-dlg .body { max-height: calc(100vh - 150px); }
.pd-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 12px; align-items: start; }
.pd-list { max-height: calc(100vh - 320px); overflow: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }
.pd-map { height: calc(100vh - 320px); min-height: 320px; }
.pd-drv { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; text-align: left; width: 100%;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; font: inherit; }
.pd-drv[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.pd-drv .pd-name { flex: 1; font-weight: 600; }
.pd-drv .pd-sub { flex-basis: 100%; }
.pd-group { margin: 8px 2px 0; }
@media (max-width: 800px) { .pd-grid { grid-template-columns: minmax(0, 1fr); } .pd-list { max-height: 30vh; } .pd-map { height: 50vh; } }
.board-below { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .board-below { grid-template-columns: minmax(0, 1fr); } }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; letter-spacing: .02em; }
.t-awaiting_production { background: var(--warn-bg); color: var(--warn); }
.t-ready, .t-unassigned { background: var(--info-bg); color: var(--info); }
.t-assigned { background: var(--sample-bg); color: var(--sample); }
.t-loaded { background: #e8eaed; color: #3f4650; }
.t-out_for_delivery { background: var(--info-bg); color: var(--info); }
.t-delivered { background: var(--good-bg); color: var(--good); }
.t-failed { background: var(--bad-bg); color: var(--bad); }
.t-returned, .t-cancelled { background: var(--warn-bg); color: var(--warn); }
.flag { background: var(--bad-bg); color: var(--bad); }
.flag-warn { background: var(--warn-bg); color: var(--warn); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Maps (Leaflet). Pins carry the stop's place in the driver's order. */
.map { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); position: relative; z-index: 0; }
.map .map-msg { padding: 16px; font-size: 13px; color: var(--muted); }
/* The board's map, in the Deliveries panel in place of the list. */
.panel > h2.panel-head { display: flex; align-items: center; gap: 8px; }
.board-map { height: 80vh; min-height: 480px; border-radius: 0; border-width: 0 0 1px; }
/* The board's map with the drivers on the left and the picked driver's tasks on the right. */
.map-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.map-grid.has-tasks { grid-template-columns: 250px minmax(0, 1fr) 330px; }
.map-side { height: 80vh; min-height: 480px; overflow: auto; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 13px; }
#mapDrivers { border-right: 1px solid var(--line); }
#mapTasks { border-left: 1px solid var(--line); }
.map-side .side-head { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 8px 10px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 6px; font-weight: 700; }
.map-side .side-head .grow { flex: 1; }
.map-drv, .map-task { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
  border-radius: 0; padding: 8px 10px; font: inherit; color: inherit; text-transform: none; letter-spacing: 0; cursor: pointer; }
.map-drv:hover, .map-task:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.map-drv[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 13%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.map-drv .nm { font-weight: 600; }
.map-drv .sub, .map-task .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.map-task .top { display: flex; gap: 6px; align-items: baseline; }
.map-task .top .grow { flex: 1; min-width: 0; }
.map-task .seq { display: inline-block; min-width: 20px; height: 20px; border-radius: 50%; color: #fff; text-align: center; font: 700 11px/20px system-ui, sans-serif; }
@media (max-width: 1000px) { .map-grid, .map-grid.has-tasks { grid-template-columns: minmax(0, 1fr); } .map-side { height: auto; max-height: 40vh; } }
.viewtoggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.viewtoggle button { border: 0; border-radius: 0; padding: 4px 12px; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--muted); background: var(--panel); }
.viewtoggle button + button { border-left: 1px solid var(--line); }
.viewtoggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 10px; font-size: 12px; }
.legend .sw, .sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dp-pin span { display: block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff;
  color: #fff; font: 600 10px/18px system-ui, sans-serif; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
/* A delivery's D while its details are open: white with a blue border. */
.dp-sel span { background: #fff !important; color: #2563eb !important; border-color: #2563eb !important; box-shadow: 0 0 0 2px rgba(37, 99, 235, .35), 0 1px 3px rgba(0,0,0,.45); }
.dp-label span { display: block; width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff;
  color: #fff; font: 700 12px/18px system-ui, sans-serif; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.legend .sw-zone, .sw-zone { border-radius: 3px; width: 14px; height: 11px; }
.zone-legend { display: inline-flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.zone-chip { display: inline-flex; align-items: center; background: none; border: 0; padding: 2px 4px; margin: 0;
  font: inherit; color: inherit; cursor: pointer; border-radius: 4px; }
.zone-chip:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.zone-legend label { display: inline-flex; gap: 4px; align-items: center; font-weight: 600; }
.legend .sw-label, .sw-label { width: 13px; height: 13px; border-radius: 3px; color: #fff; font: 700 9px/13px system-ui, sans-serif; text-align: center; }
.dp-van span { display: block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-sizing: border-box;
  font: 10px/16px system-ui, sans-serif; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.55); }
.dp-place span { display: block; width: 24px; height: 24px; border-radius: 5px; border: 2px solid #fff;
  color: #fff; font: 700 12px/20px system-ui, sans-serif; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--muted); }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; max-width: 620px; width: calc(100% - 32px);
  background: var(--panel); color: var(--ink); box-shadow: 0 20px 40px rgba(16,24,40,.22);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog h3 { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
dialog .body { padding: 14px 16px; max-height: 62vh; overflow: auto; }
dialog .foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); }

.empty { padding: 28px 14px; text-align: center; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* "hidden" means hidden, even on elements that set their own display. */
[hidden] { display: none !important; }

/* A status line with nothing to say takes no room. */
p[role="status"]:empty { display: none; }

/* The Task ID column of the Deliveries list: the number the orders app keeps as the tracking number. */
td.task-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; white-space: nowrap; }
/* What is in the order (the orders app's products): small, so a long basket name does not widen the table. */
td.items { font-size: 12.5px; line-height: 1.35; min-width: 140px; max-width: 260px; }

/* Address suggestions under an address box (Change address). Google's mark sits on white, as its terms show it. */
label.field.has-suggest { position: relative; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 2px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(16, 24, 40, .18); overflow: hidden;
  text-transform: none; letter-spacing: normal; font-weight: 400; font-size: 13px; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: none; color: var(--ink);
  padding: 7px 10px; cursor: pointer; }
.suggest button:hover, .suggest button.on { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.suggest .by { background: #fff; padding: 4px 10px; text-align: right; line-height: 0; }
/* A board label that filters the list when clicked (the address checks). */
button.tag-btn { border: 0; cursor: pointer; font: inherit; font-size: 11px; font-weight: 700; }
button.tag-btn[aria-pressed="true"] { box-shadow: 0 0 0 2px currentColor; }

/* The map in the change-address form: click the building to set the map position. */
.pick-map{height:320px;border:1px solid var(--line, #d0d5dd);border-radius:8px;margin-top:6px}

/* The map's tasks column: drag a delivery to change the driver's order. */
.map-task { cursor: pointer; }
.map-task[draggable="true"] .grip { cursor: grab; color: var(--muted); margin-right: 2px; user-select: none; }
.map-task.dragging { opacity: .45; }
.map-task.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.map-task.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.map-task:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* The picked driver's deliveries on the board map: bigger, numbered in stop order, in their route's colour. */
.dp-big span { width: 28px; height: 28px; font: 700 12px/24px system-ui, sans-serif; border-width: 2px; box-shadow: 0 0 0 2px rgba(0,0,0,.25), 0 2px 5px rgba(0,0,0,.45); }
