/* Distrolio - shared styles. Light/dark via prefers-color-scheme. */
:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14181f; --muted: #5b6472; --line: #e3e6ea;
  --brand: #0f6e56; --brand-ink: #ffffff; --brand-soft: #e4f3ee; --accent: #c7641a;
  --ok: #1d7a46; --warn: #a66b00; --bad: #b3261e; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(20,24,31,.06);
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #171b21; --ink: #e8ebef; --muted: #9aa4b1; --line: #2a3139;
    --brand: #35b391; --brand-ink: #06130f; --brand-soft: #14312a; --accent: #e08a45; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; } h1 { font-size: 2rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; } .muted { color: var(--muted); } .small { font-size: .85rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; }
.btn:hover { border-color: var(--brand); } .btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { border-color: var(--bad); color: var(--bad); } .btn.sm { padding: 5px 10px; font-size: .85rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 16px; } .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 800px) { .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }
label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
input[type="checkbox"] { width: auto; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); }   /* a field the server refused */
table { width: 100%; border-collapse: collapse; font-size: .92rem; } th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
/* batch 13: long text never breaks a list. A long word or code wraps inside its cell instead of widening the table, and
   free text in list cells (customer PO, notes, memos: class clip, the full text in the title) ends with an ellipsis. */
td { overflow-wrap: anywhere; }
.clip { display: inline-block; max-width: 18em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: color-mix(in srgb, var(--brand) 5%, transparent); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.pill.off { background: var(--line); color: var(--muted); } .pill.bad { background: #fde8e6; color: var(--bad); } .pill.warn { background: #fff3d6; color: var(--warn); }
.msg { padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: .92rem; }
.msg.err { background: #fde8e6; color: var(--bad); } .msg.ok { background: var(--brand-soft); color: var(--brand); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; } .spread { justify-content: space-between; }
.toggle { position: relative; width: 42px; height: 24px; border-radius: 999px; background: var(--line); border: 0; cursor: pointer; flex: none; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--brand); } .toggle.on::after { left: 21px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .02em; color: var(--ink); text-decoration: none !important; }
.logo .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: .8rem; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); padding: 22px; width: min(560px, 94vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* point-and-click (app/nav.js) */
a.ent { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--brand) 45%, transparent); text-underline-offset: 2px; }
a.ent:hover { color: var(--brand); text-decoration-color: var(--brand); }
a.ent.drill { color: inherit; }
#peek { position: absolute; z-index: 60; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px 14px; font-size: .9rem; }
#peek .peek-h { margin-bottom: 2px; }
#peek .peek-f { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; }
#peek dt { color: var(--muted); } #peek dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#peek .peek-a { gap: 8px; }
.rel-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--brand); } .chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: .85rem; margin: -4px 0 10px; color: var(--muted); }
.crumbs a { color: var(--brand); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs .sep { color: var(--muted); } .crumbs .here { color: var(--ink); font-weight: 600; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .crumbs a:not(:nth-last-of-type(1)) { display: none; } .crumbs .sep:not(:nth-last-of-type(2)) { display: none; } }

/* date boxes: the whole box opens the calendar (shared/datepick.js); calendar icon follows light / dark */
input[type="date"], input[type="month"], input[type="week"], input[type="time"], input[type="datetime-local"] { cursor: pointer; color-scheme: light; min-height: 38px; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="month"]::-webkit-calendar-picker-indicator, input[type="datetime-local"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .75; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) input[type="date"], :root:not([data-theme="light"]) input[type="month"], :root:not([data-theme="light"]) input[type="week"], :root:not([data-theme="light"]) input[type="time"], :root:not([data-theme="light"]) input[type="datetime-local"] { color-scheme: dark; } }

/* Administration: category menu + search for long admin pages (app/adminnav.js) */
.adm-wrap { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 14px; }
.adm-cats { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 24px); overflow-y: auto; }
.adm-q { margin: 0; }
.adm-list { display: flex; flex-direction: column; gap: 2px; }
.adm-cat { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; width: 100%; border: 0; background: none;
  color: var(--ink); font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.adm-cat:hover { background: var(--brand-soft); }
.adm-cat.on { background: var(--brand); color: var(--brand-ink); }
.adm-cat.dim { opacity: .45; }
.adm-cat .n { font-size: .78rem; font-weight: 600; min-width: 22px; text-align: center; padding: 1px 7px; border-radius: 10px; background: var(--line); color: var(--ink); }
.adm-cat.on .n { background: rgba(255,255,255,.25); color: inherit; }
.adm-pick { display: none; margin: 0; }
.adm-group { display: flex; flex-direction: column; }
.adm-head { justify-content: flex-start; }
.adm-head .t { flex: 1; } .adm-head .chev { width: 12px; color: var(--muted); font-size: .8rem; }
.adm-head.cur .t { color: var(--brand); }
.adm-subs { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 18px; border-left: 2px solid var(--line); padding-left: 6px; }
.adm-sub { text-align: left; border: 0; background: none; color: var(--ink); font: inherit; font-size: .9rem; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.adm-sub:hover { background: var(--brand-soft); }
.adm-sub.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.adm-sub.dim { opacity: .45; }
.adm-body > * { margin: 0 0 16px !important; max-width: 880px !important; }
.adm-body > [hidden] { display: none !important; }
.adm-body > .card { overflow-x: auto; }
.adm-body[data-empty]::before { content: attr(data-empty); display: block; color: var(--muted); padding: 20px 4px; }
@media (max-width: 900px) {
  .adm-wrap { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .adm-cats, .adm-body { min-width: 0; }
  .adm-cats { position: static; max-height: none; overflow: visible; }
  .adm-list { display: none; }
  .adm-pick { display: block; }
}

/* route maps (shared/routemap.js over Leaflet) */
.rm-map { height: 460px; border-radius: 8px; isolation: isolate; position: relative; z-index: 0; background: var(--bg); }
@media (max-width: 700px) { .rm-map { height: 340px; } }
.rm-map.rm-plain { background: var(--bg); }
.rm-stop { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; box-sizing: border-box; border-radius: 50%;
  background: var(--c); color: #fff; font: 700 11px/1 system-ui, -apple-system, "Segoe UI", sans-serif; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); cursor: pointer; }
.rm-stop.late { border-color: #c0392b; border-width: 3px; }
.rm-depot { display: block; width: 20px; height: 20px; box-sizing: border-box; border-radius: 4px; background: var(--ink); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.rm-unrouted { display: block; width: 18px; height: 18px; box-sizing: border-box; border-radius: 50%; background: var(--panel); border: 2px dashed var(--muted); cursor: pointer; }
.rm-map .leaflet-tooltip { font: 12px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; max-width: 260px; white-space: normal; }
.rm-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.nowrap { white-space: nowrap; }
/* screen loading (app.js route): skeleton when the screen changes, a thin bar and dimmed page while the same screen reloads */
.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; }
.skel .skel-line { height: 12px; margin: 12px 0; border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--bg) 50%, var(--line) 75%); background-size: 200% 100%; animation: skel 1.2s linear infinite; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
#routebar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--brand); z-index: 1000; opacity: 0; transition: width .2s, opacity .2s; pointer-events: none; }
#routebar.on { width: 70%; opacity: 1; transition: width 4s cubic-bezier(.1,.7,.3,1), opacity .1s; }
main.busy { opacity: .6; transition: opacity .15s .15s; }
.kpi .how { display: block; margin-top: 4px; font-size: .74rem; color: var(--muted); line-height: 1.3; }
@media (prefers-reduced-motion: reduce) { .skel .skel-line { animation: none; } #routebar, #routebar.on { transition: none; } main.busy { transition: none; } }
/* sortable table headers (biz.js sortHead): the whole header is a button; the arrow shows the order */
th.sortable { padding: 0; }
th .th-sort { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%; padding: 9px 10px; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; }
th.num .th-sort { justify-content: flex-end; }
th .th-sort:hover { color: var(--ink); } th .th-sort:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; border-radius: 4px; }
th .sort-arrow { font-size: .75em; opacity: .45; } th[aria-sort="ascending"] .sort-arrow, th[aria-sort="descending"] .sort-arrow { opacity: 1; color: var(--brand); }
