/* ==========================================================================
   Transport Ops — app.css
   Back office shell, shared tokens, components and utilities.
   Reference: docs/UI-GUIDE.md. Phone pages add field.css, TV uses tv.css only,
   print pages use print.css only.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */
:root {
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #e3e8ef;
  --border-strong: #cdd5df;
  --input-border: #c3ccd8;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --link: #1d4ed8;

  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-active: #1e3a8a;
  --primary-soft: #eff6ff;
  --primary-ring: rgba(29, 78, 216, .32);
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 4px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18), 0 2px 8px rgba(15, 23, 42, .08);
  --focus: 0 0 0 3px var(--primary-ring);

  --sidebar-w: 236px;
  --topbar-h: 56px;
  --sidebar-bg: #0f172a;
  --sidebar-line: rgba(148, 163, 184, .14);
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #8d9bb0;
  --sidebar-hover: rgba(148, 163, 184, .10);
  --sidebar-active: rgba(148, 163, 184, .18);
  --sidebar-accent: #93c5fd;
  --avatar-bg: #dbe5f4;
  --avatar-fg: #1e3a8a;

  /* tones: bg / fg / border */
  --t-neutral-bg: #f1f5f9; --t-neutral-fg: #334155; --t-neutral-bd: #e2e8f0;
  --t-info-bg: #eff6ff;    --t-info-fg: #1d4ed8;    --t-info-bd: #bfdbfe;
  --t-success-bg: #f0fdf4; --t-success-fg: #15803d; --t-success-bd: #bbf7d0;
  --t-warning-bg: #fff7ed; --t-warning-fg: #c2410c; --t-warning-bd: #fed7aa;
  --t-danger-bg: #fef2f2;  --t-danger-fg: #b91c1c;  --t-danger-bd: #fecaca;
  --t-purple-bg: #faf5ff;  --t-purple-fg: #7e22ce;  --t-purple-bd: #e9d5ff;
  --t-teal-bg: #f0fdfa;    --t-teal-fg: #0f766e;    --t-teal-bd: #99f6e4;
  --t-indigo-bg: #eef2ff;  --t-indigo-fg: #4338ca;  --t-indigo-bd: #c7d2fe;
  --t-amber-bg: #fffbeb;   --t-amber-fg: #b45309;   --t-amber-bd: #fde68a;
  --t-yellow-bg: #fefce8;  --t-yellow-fg: #854d0e;  --t-yellow-bd: #fde047;

  /* job status: solid colour (bars, dots, planner edges) */
  --st-booked: #64748b;
  --st-allocated: #2563eb;
  --st-picked_up: #d97706;
  --st-delivered: #16a34a;
  --st-invoiced: #9333ea;
  --st-cancelled: #dc2626;
  --sev-critical: #dc2626;
  --sev-major: #ea580c;
  --sev-minor: #ca8a04;
  --oos: #dc2626;

  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
    color-scheme: dark;
    --bg: #0b1120;
    --surface: #111a2b;
    --surface-2: #142034;
    --surface-3: #1b283e;
    --border: #22314a;
    --border-strong: #2f4160;
    --input-border: #3a4d6e;
    --text: #e6ebf2;
    --text-2: #a9b6c8;
    --text-3: #8697ae;
    --link: #8fb3ff;
    --primary: #2f63e8;
    --primary-hover: #3b72f6;
    --primary-active: #1d4ed8;
    --primary-soft: rgba(59, 130, 246, .14);
    --primary-ring: rgba(96, 150, 255, .45);
    --danger: #e24343;
    --danger-hover: #ef5555;
    --danger-soft: rgba(239, 68, 68, .12);
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
    --sidebar-bg: #070c17;
    --sidebar-line: rgba(148, 163, 184, .10);
    --avatar-bg: rgba(96, 150, 255, .2);
    --avatar-fg: #c7d8ff;

    --t-neutral-bg: rgba(148, 163, 184, .13); --t-neutral-fg: #cbd5e1; --t-neutral-bd: rgba(148, 163, 184, .26);
    --t-info-bg: rgba(59, 130, 246, .15);     --t-info-fg: #93c5fd;    --t-info-bd: rgba(59, 130, 246, .34);
    --t-success-bg: rgba(34, 197, 94, .12);   --t-success-fg: #86efac; --t-success-bd: rgba(34, 197, 94, .30);
    --t-warning-bg: rgba(249, 115, 22, .13);  --t-warning-fg: #fdba74; --t-warning-bd: rgba(249, 115, 22, .34);
    --t-danger-bg: rgba(239, 68, 68, .13);    --t-danger-fg: #fca5a5;  --t-danger-bd: rgba(239, 68, 68, .34);
    --t-purple-bg: rgba(168, 85, 247, .15);   --t-purple-fg: #d8b4fe;  --t-purple-bd: rgba(168, 85, 247, .36);
    --t-teal-bg: rgba(20, 184, 166, .13);     --t-teal-fg: #5eead4;    --t-teal-bd: rgba(20, 184, 166, .32);
    --t-indigo-bg: rgba(99, 102, 241, .17);   --t-indigo-fg: #a5b4fc;  --t-indigo-bd: rgba(99, 102, 241, .38);
    --t-amber-bg: rgba(245, 158, 11, .13);    --t-amber-fg: #fcd34d;   --t-amber-bd: rgba(245, 158, 11, .34);
    --t-yellow-bg: rgba(234, 179, 8, .13);    --t-yellow-fg: #fde047;  --t-yellow-bd: rgba(234, 179, 8, .34);

    --st-booked: #94a3b8;
    --st-allocated: #3b82f6;
    --st-picked_up: #f59e0b;
    --st-delivered: #22c55e;
    --st-invoiced: #a855f7;
    --st-cancelled: #ef4444;
    --sev-critical: #ef4444;
    --sev-major: #f97316;
    --sev-minor: #eab308;
    --oos: #ef4444;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5l6 6 6-6'/%3E%3C/svg%3E");
  }
}

/* status + tone classes set local variables that components read */
.st-booked    { --st: var(--st-booked);     --st-bg: var(--t-neutral-bg); --st-fg: var(--t-neutral-fg); --st-bd: var(--t-neutral-bd); }
.st-allocated { --st: var(--st-allocated);  --st-bg: var(--t-info-bg);    --st-fg: var(--t-info-fg);    --st-bd: var(--t-info-bd); }
.st-picked_up { --st: var(--st-picked_up);  --st-bg: var(--t-amber-bg);   --st-fg: var(--t-amber-fg);   --st-bd: var(--t-amber-bd); }
.st-delivered { --st: var(--st-delivered);  --st-bg: var(--t-success-bg); --st-fg: var(--t-success-fg); --st-bd: var(--t-success-bd); }
.st-invoiced  { --st: var(--st-invoiced);   --st-bg: var(--t-purple-bg);  --st-fg: var(--t-purple-fg);  --st-bd: var(--t-purple-bd); }
.st-cancelled { --st: var(--st-cancelled);  --st-bg: var(--t-danger-bg);  --st-fg: var(--t-danger-fg);  --st-bd: var(--t-danger-bd); }

/* ---------- 2. Base ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.005em; }
h2 { font-size: 16px; }
h3 { font-size: 14.5px; }
p { margin: 0 0 .6em; }
p:last-child { margin-bottom: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { vertical-align: middle; }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
small { font-size: 12.5px; }
table { font-variant-numeric: tabular-nums; }
time, .num, .tnum { font-variant-numeric: tabular-nums; }
code, kbd, .mono { font-family: var(--font-mono); font-size: .92em; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
::selection { background: rgba(29, 78, 216, .18); }

.icon { width: 18px; height: 18px; flex: none; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }
.icon-xl { width: 28px; height: 28px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 300;
  background: var(--primary); color: #fff; padding: 10px 14px; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* ---------- 3. App shell ------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
@media (min-width: 1024px) {
  /* paint the sidebar column too, so it stays dark however long the page is (the sticky sidebar is
     only one viewport tall) */
  .shell { background: var(--bg) linear-gradient(to right, var(--sidebar-bg), var(--sidebar-bg)) no-repeat left top / var(--sidebar-w) 100%; }
}
.main-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; max-height: 100vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, .3) transparent;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 18px; flex: none;
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.01em;
  border-bottom: 1px solid var(--sidebar-line);
}
.sb-brand:hover { text-decoration: none; color: #fff; }
.sb-brand img { width: 28px; height: 28px; border-radius: 7px; }
.sb-nav { padding: 12px 10px 20px; flex: 1 1 auto; }
.sb-item {
  display: flex; align-items: center; gap: 11px;
  min-height: 36px; padding: 7px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 550; text-decoration: none;
}
.sb-item .icon { color: var(--sidebar-muted); width: 18px; height: 18px; }
.sb-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sb-item.is-active { color: #fff; }
.sb-item.is-active .icon { color: var(--sidebar-accent); }
.sb-group:not(.is-active) > .sb-sub { display: none; }
.sb-leaf.is-active { background: var(--sidebar-active); }
.sb-sub { margin: 0 0 6px; padding: 2px 0 2px 39px; position: relative; }
.sb-sub::before { content: ""; position: absolute; left: 19px; top: 4px; bottom: 4px; width: 1px; background: var(--sidebar-line); }
.sb-subitem {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 32px; padding: 6px 10px; border-radius: 7px;
  color: var(--sidebar-muted); font-size: 13.5px; font-weight: 500;
}
.sb-subitem:hover { color: #fff; background: var(--sidebar-hover); text-decoration: none; }
.sb-subitem.is-active { color: #fff; background: var(--sidebar-active); }
.sb-count {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(148, 163, 184, .18); color: #e2e8f0; font-size: 11.5px; font-weight: 650;
}
.sb-count.is-alert { background: #dc2626; color: #fff; }
.sb-foot { padding: 12px 18px 16px; border-top: 1px solid var(--sidebar-line); font-size: 12px; color: var(--sidebar-muted); }

.nav-backdrop { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tb-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 9px; color: var(--text-2); flex: none;
}
.tb-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.tb-menu, .tb-search-link { display: none; }
/* "Replies N" (manage users with unread SMS replies) */
.tb-replies {
  display: inline-flex; align-items: center; gap: 7px; flex: none; height: 36px; padding: 0 10px 0 9px;
  border: 1px solid var(--t-info-bd); border-radius: 9px; background: var(--t-info-bg); color: var(--t-info-fg);
  font-weight: 650; font-size: 13.5px; white-space: nowrap;
}
.tb-replies:hover { text-decoration: none; border-color: var(--t-info-fg); color: var(--t-info-fg); }
.tb-replies .icon { width: 17px; height: 17px; }
.tb-replies .count-badge { background: var(--primary); }
.tb-search { position: relative; flex: 0 1 360px; min-width: 180px; }
.tb-search .icon { position: absolute; left: 11px; top: 50%; margin-top: -8px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.tb-search .input { height: 36px; padding-left: 34px; background: var(--surface-2); }
.tb-search .input:focus { background: var(--surface); }
.tb-spacer { flex: 1 1 auto; }
.tb-user > summary {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 4px; border-radius: 10px;
  color: var(--text); font-weight: 550;
}
.tb-user > summary:hover { background: var(--surface-3); }
.tb-user > summary .icon { width: 16px; height: 16px; color: var(--text-3); }
.tb-user-name { max-width: 160px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--avatar-bg); color: var(--avatar-fg); font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
}

.page { width: 100%; max-width: 1480px; margin: 0 auto; padding: 22px 28px 48px; flex: 1 0 auto; }
.page:focus { outline: none; }
.page-wide { max-width: none; }
.page-narrow { max-width: 920px; }
.page-flush { padding: 0; max-width: none; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.page-head-main { min-width: 0; }
.page-title { font-size: 22px; font-weight: 680; letter-spacing: -.015em; line-height: 1.2; }
.page-title:empty { display: none; }
.page-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 6px; color: var(--text-2); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions:empty { display: none; }
.back-link {
  display: inline-flex; align-items: center; gap: 3px; margin: 0 0 6px -3px;
  font-size: 13px; font-weight: 550; color: var(--text-2);
}
.back-link .icon { width: 16px; height: 16px; }
.back-link:hover { color: var(--text); text-decoration: none; }

/* ---------- 4. Layout helpers ------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.row-top { align-items: flex-start; }
.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
.grid-main { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

/* ---------- 5. Cards ----------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 50px; padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.card-title { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 650; margin: 0; }
.card-title .icon { color: var(--text-3); }
.card-sub { font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.card-actions { display: flex; align-items: center; gap: 6px; }
.card-body { padding: 16px; }
.card-body-sm { padding: 12px 16px; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
.card > .table-wrap:last-child, .card > .table:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.card-accent { border-left: 4px solid var(--st, var(--primary)); }
.card-danger { border-color: var(--t-danger-bd); }
.card-danger .card-head { background: var(--t-danger-bg); border-bottom-color: var(--t-danger-bd); border-radius: var(--radius) var(--radius) 0 0; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--border-strong); }

/* ---------- 6. Buttons --------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none; user-select: none; -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--input-border); text-decoration: none; color: var(--text); }
.btn:active { background: var(--surface-3); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn .icon { width: 17px; height: 17px; margin: 0 -1px 0 -3px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn-primary:active { background: var(--primary-active); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-danger-soft { color: var(--t-danger-fg); }
.btn-danger-soft:hover { background: var(--t-danger-bg); border-color: var(--t-danger-bd); color: var(--t-danger-fg); }
.btn-success { background: #15803d; border-color: #15803d; color: #fff; }
.btn-success:hover { background: #166534; border-color: #166534; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }
.btn-link { height: auto; padding: 0; border: 0; background: none; box-shadow: none; color: var(--link); font-weight: 550; }
.btn-link:hover { background: none; text-decoration: underline; color: var(--link); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; gap: 5px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 15px; border-radius: 9px; }
.btn-xl { height: 56px; padding: 0 22px; font-size: 17px; border-radius: 12px; font-weight: 700; }
.btn-xl .icon { width: 22px; height: 22px; }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon .icon { margin: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn[disabled], .btn.is-disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; box-shadow: none; }
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; }
.btn-group > .btn:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.btn-group > .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group > .btn.is-active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); position: relative; z-index: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 7. Forms ----------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid.cols-1 { grid-template-columns: minmax(0, 1fr); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.form-section + .form-section { margin-top: 16px; }
.form-narrow { max-width: 760px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-set { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); padding: 0; }
.field-label .opt { font-weight: 450; color: var(--text-3); }
.req { color: var(--danger); margin-left: 3px; font-weight: 700; }
.field-help { font-size: 12.5px; color: var(--text-3); line-height: 1.4; }
.field-help ul { margin: 2px 0 0; padding-left: 18px; }
.field-errors { list-style: none; margin: 0; padding: 0; color: var(--t-danger-fg); font-size: 13px; font-weight: 550; }
.field-errors li { display: flex; gap: 5px; align-items: flex-start; }
.field-errors .icon { width: 15px; height: 15px; margin-top: 1px; }

.input, .select, .textarea {
  display: block; width: 100%; min-width: 0; height: 38px; padding: 0 11px;
  border: 1px solid var(--input-border); border-radius: 8px;
  background-color: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.3;
  transition: border-color .12s, box-shadow .12s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: .9; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: var(--focus); outline: none; }
.input[disabled], .select[disabled], .textarea[disabled], .input[readonly] { background-color: var(--surface-3); color: var(--text-2); cursor: not-allowed; }
.textarea { height: auto; min-height: 92px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.select-multiple, select[multiple].select { height: auto; min-height: 96px; padding: 6px 8px; background-image: none; }
select[multiple].select option { padding: 4px 6px; border-radius: 5px; }
select[multiple].select option:checked { background: var(--primary-soft) linear-gradient(var(--primary-soft), var(--primary-soft)); color: var(--text); font-weight: 600; }
.form-grid.cols-3 > .fw-datetime, .form-grid.cols-4 > .fw-datetime { grid-column: span 2; }
.select-sm, .input-sm { height: 32px; font-size: 13.5px; border-radius: 7px; }
input[type="date"].input, input[type="time"].input, input[type="datetime-local"].input { padding-right: 8px; }
input[type="number"].input { font-variant-numeric: tabular-nums; }
.has-error .input, .has-error .select, .has-error .textarea,
[aria-invalid="true"].input, [aria-invalid="true"].select, [aria-invalid="true"].textarea { border-color: var(--danger); }
.has-error .input:focus, .has-error .select:focus, .has-error .textarea:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .22); }

.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-addon {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 32px; border: 0; border-radius: 6px; background: none; color: var(--text-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.input-addon:hover { color: var(--text); background: var(--surface-3); }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 10px; top: 50%; margin-top: -8px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.input-icon > .input { padding-left: 33px; }
.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-radius: 0; flex: 1 1 auto; }
.input-group > .input:first-child { border-radius: 8px 0 0 8px; }
.input-group > .input:last-child { border-radius: 0 8px 8px 0; }
.input-group-text {
  display: inline-flex; align-items: center; padding: 0 10px; border: 1px solid var(--input-border);
  background: var(--surface-2); color: var(--text-2); font-size: 13px; white-space: nowrap;
}
.input-group-text:first-child { border-right: 0; border-radius: 8px 0 0 8px; }
.input-group-text:last-child { border-left: 0; border-radius: 0 8px 8px 0; }

.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-weight: 500; line-height: 1.4; }
.check-input, .choice input, .check input {
  width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--primary); cursor: pointer;
}
.check-label { padding-top: 0; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices-stack { flex-direction: column; align-items: stretch; }
.choice {
  display: inline-flex; align-items: center; gap: 9px; min-height: 38px; padding: 7px 12px;
  border: 1px solid var(--input-border); border-radius: 8px; background: var(--surface);
  cursor: pointer; font-weight: 500; line-height: 1.3;
}
.choice input { margin: 0; }
.choice:hover { border-color: var(--text-3); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:focus-visible) { box-shadow: var(--focus); }
.file-input { font: inherit; font-size: 13.5px; color: var(--text-2); max-width: 100%; }
.file-input::file-selector-button {
  font: inherit; font-weight: 600; font-size: 13.5px; margin-right: 10px; height: 34px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer;
}
.fw-clearablefile, .fw-file { font-size: 13px; color: var(--text-2); }
.fw-clearablefile a { word-break: break-all; }

.form-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}
.form-actions .spacer { flex: 1 1 auto; }
.card > .form-actions { margin: 0; padding: 12px 16px; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.form-error-summary { margin-bottom: 16px; }
.form-subhead { margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-2); }
.card-body > .form-subhead:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.field-note { display: flex; align-items: flex-start; gap: 8px; align-self: end; padding: 9px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 13px; line-height: 1.4; }
.field-note .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--text-3); }
.logo-field { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.logo-field > .field { flex: 1 1 260px; }
.logo-current { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-current img { max-height: 48px; max-width: 220px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.input.input-short { max-width: 140px; }

/* ---------- 8. Tables ---------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 9px 12px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 650; color: var(--text-2); letter-spacing: .01em;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table th a { color: inherit; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr[data-href] { cursor: pointer; }
.table .num, .table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .c { text-align: center; }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .min { width: 1%; white-space: nowrap; }
.table tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; }
.table-sm td { padding: 7px 10px; }
.table-sm th { padding: 7px 10px; }
.table-plain th { background: transparent; }
.table-plain tbody tr:hover td { background: transparent; }
.cell-main { font-weight: 600; color: var(--text); }
a.cell-main { color: var(--text); }
a.cell-main:hover { color: var(--link); }
.cell-sub { display: block; margin-top: 2px; font-size: 12.5px; color: var(--text-3); }
.cell-route { display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.cell-route .icon { width: 14px; height: 14px; color: var(--text-3); }
.row-cancelled td { color: var(--text-3); }
.row-cancelled .cell-main, .row-cancelled .cell-route { text-decoration: line-through; }
.row-alert td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.row-muted td { color: var(--text-3); }
.row-muted .cell-main { color: var(--text-2); }

/* ---------- 9. Chips ----------------------------------------------------- */
.chip {
  --chip-bg: var(--t-neutral-bg); --chip-fg: var(--t-neutral-fg); --chip-bd: var(--t-neutral-bd);
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border: 1px solid var(--chip-bd); border-radius: 999px; background: var(--chip-bg); color: var(--chip-fg);
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap; vertical-align: middle;
}
.chip .icon { width: 13px; height: 13px; margin-left: -2px; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; margin-left: -1px; }
.chip-lg { height: 28px; padding: 0 12px; font-size: 13px; gap: 7px; }
.chip-lg .dot { width: 8px; height: 8px; }
.chip-sm { height: 19px; padding: 0 6px; font-size: 11px; }
.chip-info    { --chip-bg: var(--t-info-bg);    --chip-fg: var(--t-info-fg);    --chip-bd: var(--t-info-bd); }
.chip-success { --chip-bg: var(--t-success-bg); --chip-fg: var(--t-success-fg); --chip-bd: var(--t-success-bd); }
.chip-warning { --chip-bg: var(--t-warning-bg); --chip-fg: var(--t-warning-fg); --chip-bd: var(--t-warning-bd); }
.chip-danger  { --chip-bg: var(--t-danger-bg);  --chip-fg: var(--t-danger-fg);  --chip-bd: var(--t-danger-bd); }
.chip-purple  { --chip-bg: var(--t-purple-bg);  --chip-fg: var(--t-purple-fg);  --chip-bd: var(--t-purple-bd); }
.chip-teal    { --chip-bg: var(--t-teal-bg);    --chip-fg: var(--t-teal-fg);    --chip-bd: var(--t-teal-bd); }
.chip-indigo  { --chip-bg: var(--t-indigo-bg);  --chip-fg: var(--t-indigo-fg);  --chip-bd: var(--t-indigo-bd); }
.chip-amber   { --chip-bg: var(--t-amber-bg);   --chip-fg: var(--t-amber-fg);   --chip-bd: var(--t-amber-bd); }
.chip.st { --chip-bg: var(--st-bg); --chip-fg: var(--st-fg); --chip-bd: var(--st-bd); }
.chip.st-cancelled { text-decoration: line-through; }
.chip.sev-critical, .chip.as-out_of_service { --chip-bg: var(--sev-critical); --chip-fg: #fff; --chip-bd: var(--sev-critical); }
.chip.sev-major { --chip-bg: var(--t-warning-bg); --chip-fg: var(--t-warning-fg); --chip-bd: var(--t-warning-bd); }
.chip.sev-minor { --chip-bg: var(--t-yellow-bg); --chip-fg: var(--t-yellow-fg); --chip-bd: var(--t-yellow-bd); }
.chip.as-in_service { --chip-bg: var(--t-success-bg); --chip-fg: var(--t-success-fg); --chip-bd: var(--t-success-bd); }
.chip.as-retired { --chip-bg: var(--t-neutral-bg); --chip-fg: var(--text-3); --chip-bd: var(--t-neutral-bd); }
.chip-code { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .02em; }
.chip.lbl-solid { --chip-bg: var(--danger); --chip-fg: #fff; --chip-bd: var(--danger); }
.chip.lbl-outline { --chip-bg: transparent; --chip-fg: var(--t-danger-fg); --chip-bd: var(--danger); border-width: 1.5px; }

/* depot filter chips (components/depot_filter.html): All · MID · MSW */
.depot-filter { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.dchip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 28px; padding: 0 10px;
  border-radius: 7px; color: var(--text-2); font-size: 13px; font-weight: 650; letter-spacing: .02em; white-space: nowrap;
}
.dchip:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.dchip.is-active { background: var(--primary); color: var(--on-primary); }
.dchip:focus-visible { outline: none; box-shadow: var(--focus); }
.filters .depot-filter { align-self: flex-end; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--st, var(--text-3)); flex: none; }
.count-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 11.5px; font-weight: 700;
}

/* ---------- 10. Alerts --------------------------------------------------- */
.alert {
  --a-bg: var(--t-info-bg); --a-fg: var(--t-info-fg); --a-bd: var(--t-info-bd);
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px;
  border: 1px solid var(--a-bd); border-radius: var(--radius); background: var(--a-bg); color: var(--text);
}
.alert > .icon { color: var(--a-fg); margin-top: 1px; }
.alert-body { flex: 1 1 auto; min-width: 0; }
.alert-title { font-weight: 650; color: var(--text); }
.alert p { margin: 0; }
.alert p + p, .alert-title + p { margin-top: 2px; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert .alert-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.alert-success { --a-bg: var(--t-success-bg); --a-fg: var(--t-success-fg); --a-bd: var(--t-success-bd); }
.alert-warning { --a-bg: var(--t-warning-bg); --a-fg: var(--t-warning-fg); --a-bd: var(--t-warning-bd); }
.alert-danger  { --a-bg: var(--t-danger-bg);  --a-fg: var(--t-danger-fg);  --a-bd: var(--t-danger-bd); }
.alert-neutral { --a-bg: var(--surface-2);    --a-fg: var(--text-3);       --a-bd: var(--border); }
.alert-close { margin: -4px -6px -4px auto; }
.banners { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* ---------- 11. Key/value lists ----------------------------------------- */
.kv { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: 9px 18px; margin: 0; }
.kv dt { color: var(--text-3); font-size: 13px; font-weight: 500; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv-tight { gap: 5px 14px; }
.kv-stack { grid-template-columns: minmax(0, 1fr); gap: 2px; }
.kv-stack dd { margin-bottom: 10px; }
.kv-2 { grid-template-columns: minmax(96px, max-content) minmax(0, 1fr) minmax(96px, max-content) minmax(0, 1fr); }
.kv-blocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 18px; margin: 0; }
.kv-blocks > div { min-width: 0; }
.kv-blocks dt { font-size: 12px; color: var(--text-3); font-weight: 550; margin-bottom: 2px; }
.kv-blocks dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- 12. Tabs ----------------------------------------------------- */
.tabs {
  display: flex; gap: 2px; margin: 0 0 16px; border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 10px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-2); font-weight: 600; white-space: nowrap; text-decoration: none;
}
.tab .icon { width: 16px; height: 16px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-2); font-size: 11.5px; font-weight: 650;
}
.tab.is-active .tab-count { background: var(--primary-soft); color: var(--primary); }
.tabs-pills { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); max-width: 100%; }
.tabs-pills .tab { margin: 0; border: 0; border-radius: 7px; padding: 6px 11px; font-size: 13.5px; }
.tabs-pills .tab:hover { background: var(--surface-3); }
.tabs-pills .tab.is-active { background: var(--primary); color: #fff; }
.tabs-pills .tab.is-active .tab-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ---------- 13. Stat tiles ---------------------------------------------- */
.stat {
  position: relative; display: flex; flex-direction: column; padding: 14px 16px 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; min-width: 0;
}
a.stat:hover { border-color: var(--border-strong); text-decoration: none; color: var(--text); box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }
.stat::before { content: ""; position: absolute; left: -1px; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--stat-accent, transparent); }
.stat-label { display: flex; align-items: flex-start; gap: 7px; flex: 1 0 auto; font-size: 12.5px; font-weight: 600; line-height: 1.35; color: var(--text-2); }
.stat-label .icon { margin-top: 1px; }
.stat-label .icon { width: 16px; height: 16px; color: var(--stat-accent, var(--text-3)); }
.stat-value { margin-top: 6px; font-size: 28px; font-weight: 720; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--stat-fg, var(--text)); }
.stat-hint { margin-top: 3px; font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-info    { --stat-accent: var(--t-info-fg); }
.stat-success { --stat-accent: var(--st-delivered); }
.stat-warning { --stat-accent: var(--sev-major); --stat-fg: var(--t-warning-fg); }
.stat-danger  { --stat-accent: var(--danger); --stat-fg: var(--t-danger-fg); }
.stat-purple  { --stat-accent: var(--st-invoiced); }
.stat-indigo  { --stat-accent: var(--t-indigo-fg); }
.stat-amber   { --stat-accent: var(--st-picked_up); }
.stat.is-zero { --stat-accent: transparent; --stat-fg: var(--text-3); }
.stat.is-zero .stat-label .icon { color: var(--text-3); }

/* ---------- 14. Filters bar --------------------------------------------- */
.filters { position: relative; display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 10px; margin: 0 0 14px; }
.filter-item { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--text-3); }
.filters .input, .filters .select { height: 34px; font-size: 13.5px; }
.filters .select { min-width: 140px; max-width: 220px; }
.filters .fw-date .input { width: 150px; }
.filters .filter-search { flex: 1 1 220px; max-width: 340px; }
.filter-actions { display: flex; align-items: center; gap: 6px; padding-bottom: 2px; }
.filters-more { display: contents; }
.filters-check, .filters-toggle { display: none; }
.filters-toggle .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- 15. Pagination ---------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; padding: 12px 2px 0; font-size: 13px; color: var(--text-2); }
.card > .pagination, .card-foot.pagination { padding: 10px 16px; }
.card > .pagination { border-top: 1px solid var(--border); }
.pagination-links { display: flex; align-items: center; gap: 8px; }
.pagination-page { color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- 16. Empty state --------------------------------------------- */
.empty { padding: 40px 20px 44px; text-align: center; color: var(--text-2); }
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 46px; height: 46px; margin-bottom: 12px;
  border-radius: 12px; background: var(--surface-3); color: var(--text-3);
}
.empty-icon .icon { width: 22px; height: 22px; }
.empty-title { margin: 0 0 4px; font-size: 15px; font-weight: 650; color: var(--text); }
.empty-text { max-width: 440px; margin: 0 auto; }
.empty .btn { margin-top: 16px; }
.empty-compact { padding: 22px 16px; }
.empty-compact .empty-icon { width: 38px; height: 38px; margin-bottom: 8px; }

/* ---------- 17. Timeline ------------------------------------------------ */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { --tl: var(--text-3); position: relative; padding: 0 0 16px 26px; }
.tl-item::before { content: ""; position: absolute; left: 6px; top: 17px; bottom: 1px; width: 2px; border-radius: 2px; background: var(--border); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item:last-child::before { display: none; }
.tl-dot { position: absolute; left: 0; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--tl); }
.tl-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 10px; flex-wrap: wrap; }
.tl-title { font-weight: 600; }
.tl-time { font-size: 12.5px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-body { margin-top: 2px; color: var(--text-2); overflow-wrap: anywhere; }
.tl-meta { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; margin-top: 3px; font-size: 12.5px; color: var(--text-3); }
.tl-meta .icon { width: 13px; height: 13px; }
.tl-info    { --tl: var(--st-allocated); }
.tl-success { --tl: var(--st-delivered); }
.tl-warning { --tl: var(--sev-major); }
.tl-danger  { --tl: var(--danger); }
.tl-purple  { --tl: var(--st-invoiced); }
.tl-indigo  { --tl: var(--t-indigo-fg); }
.tl-amber   { --tl: var(--st-picked_up); }
.tl-empty { color: var(--text-3); padding: 4px 0; }

/* ---------- 18. Toasts -------------------------------------------------- */
.toasts {
  position: fixed; bottom: 20px; right: 20px; z-index: 250;
  display: flex; flex-direction: column; gap: 8px; width: 400px; max-width: calc(100vw - 32px); pointer-events: none;
}
.toast {
  --a-fg: var(--t-info-fg);
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 11px 10px 11px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--a-fg);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
.toast > .icon { color: var(--a-fg); margin-top: 1px; }
.toast-msg { flex: 1 1 auto; min-width: 0; padding-top: 1px; font-weight: 500; overflow-wrap: anywhere; }
.toast-close {
  flex: none; width: 28px; height: 28px; margin: -4px 0 -4px 0; border: 0; border-radius: 6px; background: none;
  color: var(--text-3); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.toast-close:hover { background: var(--surface-3); color: var(--text); }
.toast-close .icon { width: 16px; height: 16px; }
.toast-success { --a-fg: var(--st-delivered); }
.toast-warning { --a-fg: var(--sev-major); }
.toast-danger  { --a-fg: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
.toast-action {
  flex: none; align-self: center; height: 30px; margin: -4px 0; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: 7px; background: var(--surface); color: var(--link); font: inherit; font-size: 13.5px; font-weight: 700;
  cursor: pointer;
}
.toast-action:hover { background: var(--surface-3); }
.toast-action:focus-visible { outline: none; box-shadow: var(--focus); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 19. Modal --------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-start; justify-content: center;
  padding: 9vh 16px 16px; overflow-y: auto; background: rgba(15, 23, 42, .48);
  animation: fade-in .12s ease-out;
}
.modal {
  width: 100%; max-width: 560px; background: var(--surface); color: var(--text);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); outline: none;
  animation: modal-in .16s ease-out;
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 680; }
.modal-body { padding: 16px 20px 20px; }
.modal-text { color: var(--text-2); margin: 0; }
.modal-actions, .modal-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
body.modal-open { overflow: hidden; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- 20. Menus (details/summary) --------------------------------- */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu-left .menu-panel { right: auto; left: 0; }
.menu-head { padding: 8px 10px 8px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 7px 10px;
  border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-weight: 500;
  text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item .icon { color: var(--text-3); width: 17px; height: 17px; }
.menu-item:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.menu-item.is-danger { color: var(--t-danger-fg); }
.menu-item.is-danger .icon { color: var(--t-danger-fg); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-panel form { margin: 0; }

/* ---------- 21. Files, signatures, maps --------------------------------- */
.files { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.file-tile {
  position: relative; display: block; overflow: hidden; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
.file-tile:hover { border-color: var(--border-strong); text-decoration: none; }
.file-tile img, .file-doc { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.file-doc { display: flex; align-items: center; justify-content: center; color: var(--text-3); background: var(--surface-3); }
.file-doc .icon { width: 28px; height: 28px; }
.file-name { display: block; padding: 6px 8px; font-size: 12px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-flag {
  position: absolute; top: 6px; left: 6px; display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: rgba(15, 23, 42, .78); color: #fff; font-size: 11px; font-weight: 600;
}
.file-flag .icon { width: 11px; height: 11px; }
.sig { display: inline-block; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
.sig img { display: block; max-width: 100%; max-height: 120px; height: auto; }
.sig-caption { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.addr { line-height: 1.45; }
.addr-name { font-weight: 650; }
.map-link { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.map-link .icon { width: 15px; height: 15px; }

/* ---------- 22. Auth + error pages -------------------------------------- */
.auth-body { background: var(--bg); }
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card {
  width: 100%; max-width: 410px; padding: 30px 28px 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 2px 12px rgba(15, 23, 42, .06);
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; font-size: 17px; font-weight: 750; letter-spacing: -.01em; }
.auth-brand img { max-height: 44px; width: auto; }
.auth-brand .mark { width: 36px; height: 36px; border-radius: 9px; }
.auth-title { margin: 0 0 6px; font-size: 21px; font-weight: 700; text-align: center; letter-spacing: -.01em; }
.auth-lead { margin: 0 0 20px; color: var(--text-2); text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-links { margin: 18px 0 0; text-align: center; font-size: 13.5px; }
.auth-or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--text-3); font-size: 12.5px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--border); }
.auth-foot { margin: 18px 0 0; font-size: 12.5px; color: var(--text-3); text-align: center; }
.auth-state {
  display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; margin: 0 auto 14px;
  border-radius: 50%; background: var(--t-info-bg); color: var(--t-info-fg);
}
.auth-state .icon { width: 26px; height: 26px; }
.auth-state-success { background: var(--t-success-bg); color: var(--t-success-fg); }
.auth-state-warning { background: var(--t-warning-bg); color: var(--t-warning-fg); }
.auth-state-danger  { background: var(--t-danger-bg); color: var(--t-danger-fg); }
.auth-card .btn-row { justify-content: center; }
.auth-who { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 0 0 18px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.auth-card-wide { max-width: 760px; }
.prose { line-height: 1.6; font-size: 15px; }
.prose h2 { margin: 24px 0 8px; font-size: 16.5px; font-weight: 700; }
.prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li + li { margin-top: 6px; }
.prose p { margin: 0 0 10px; }
.prose .table-wrap { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; }
.prose .table td { vertical-align: top; }
.auth-who .avatar { width: 34px; height: 34px; }

/* ---------- 23. Misc components ----------------------------------------- */
.confirm-card { max-width: 560px; }
.confirm-foot { justify-content: flex-end; }
.confirm-reason { padding-top: 0; }
.confirm-head { display: flex; gap: 14px; align-items: flex-start; }
.confirm-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; background: var(--t-danger-bg); color: var(--t-danger-fg); }
.confirm-icon.tone-primary { background: var(--t-info-bg); color: var(--t-info-fg); }
.confirm-title { font-size: 16px; margin-bottom: 4px; }
.confirm-object { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list-main { flex: 1 1 auto; min-width: 0; }
.list-title { font-weight: 600; }
.list-sub { font-size: 12.5px; color: var(--text-3); }
.list-title { color: var(--text); }
a.list-title:hover { color: var(--link); }
.list-links > li { padding: 0; }
.list-links a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 16px; color: var(--text); font-weight: 550; }
.list-links a:hover { background: var(--surface-2); text-decoration: none; }
.list-links .icon { color: var(--text-3); }
.ref-list { margin: 14px 0 0; padding: 10px 12px 10px 30px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.ref-list li + li { margin-top: 2px; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.kbd { display: inline-block; padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; font: 11px var(--font-mono); color: var(--text-2); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.money-total { font-size: 16px; font-weight: 700; }
.placeholder-box {
  display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border-strong); border-radius: 10px;
  background: var(--surface-2); color: var(--text-3); min-height: 120px;
}

/* ---------- 24. Utilities ----------------------------------------------- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 650; }
.medium { font-weight: 550; }
.upper { text-transform: uppercase; letter-spacing: .06em; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.break { overflow-wrap: anywhere; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.strike { text-decoration: line-through; }
.text-danger { color: var(--t-danger-fg); }
.text-success { color: var(--t-success-fg); }
.text-warning { color: var(--t-warning-fg); }
.text-info { color: var(--t-info-fg); }
.w-full { width: 100%; }
.ml-auto { margin-left: auto; }
.m-0 { margin: 0; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.p-0 { padding: 0; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.show-sm { display: none; }
.pre { white-space: pre-line; }

/* ---------- 25. Responsive ---------------------------------------------- */
@media (max-width: 1279.98px) {
  .grid-main { grid-template-columns: minmax(0, 1fr) 320px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1023.98px) {
  .sidebar {
    /* align-self: stretch - Chromium applies align-self to fixed boxes, and the desktop flex-start would
       make the drawer only as tall as its links (the "sidebar background on tall pages" glitch) */
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 120; height: auto; max-height: none; width: 284px;
    align-self: stretch; transform: translateX(-102%); transition: transform .2s ease; box-shadow: none;
  }
  body.nav-open .sidebar, .sidebar:target { transform: none; box-shadow: var(--shadow-lg); }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 110; background: rgba(2, 6, 23, .5);
    opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
  }
  body.nav-open .nav-backdrop, .sidebar:target + .nav-backdrop { opacity: 1; visibility: visible; }
  body.nav-open { overflow: hidden; }
  .tb-menu { display: inline-flex; margin-left: -8px; }
  .topbar { padding: 0 16px; }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .tb-search { display: none; }
  .tb-search-link { display: inline-flex; }
  .tb-user-name, .tb-user > summary .icon { display: none; }
  .tb-user > summary { padding: 0 2px; }
  .tb-new span { display: none; }
  .tb-new { width: 38px; padding: 0; }
  .tb-new .icon { margin: 0; }
  .tb-replies span:not(.count-badge) { display: none; }
  .tb-replies { padding: 0 7px; }
}

@media (max-width: 720px) {
  .page { padding: 16px 16px 32px; }
  .page-head { margin-bottom: 14px; align-items: flex-start; }
  .page-title { font-size: 20px; }
  .page-actions { width: 100%; }
  .grid-2, .grid-3, .grid-4, .kv-2 { grid-template-columns: minmax(0, 1fr); }
  .kv-2 { grid-template-columns: minmax(96px, max-content) minmax(0, 1fr); }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 13px 11px; }
  .stat-value { font-size: 24px; }
  .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .card-head, .card-body { padding-left: 14px; padding-right: 14px; }
  .form-actions {
    position: sticky; bottom: 0; z-index: 30; margin: 20px -16px -32px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 14px rgba(15, 23, 42, .06);
  }
  .form-actions .btn { flex: 1 1 0; height: 44px; }
  .card > .form-actions { margin: 0; position: static; box-shadow: none; }
  /* iOS zooms into inputs under 16px */
  .input, .select, .textarea { font-size: 16px; height: 42px; }
  .textarea { height: auto; }
  .filters { gap: 8px; align-items: flex-end; }
  .filters .filter-item { flex: 1 1 calc(50% - 4px); }
  .filters .filter-search { flex: 1 1 0; max-width: none; }
  .filters .select, .filters .fw-date .input { width: 100%; max-width: none; min-width: 0; }
  .filters .input, .filters .select { height: 40px; font-size: 16px; }
  /* phones: everything except the search box folds behind one "Filters" toggle (CSS only, no JS) */
  .filters-check { display: block; position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
  .filters-toggle { display: inline-flex; height: 40px; flex: none; }
  .filters-check:focus-visible + .filters-toggle { box-shadow: var(--focus); }
  .filters-check:checked + .filters-toggle { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
  .filters-more { display: none; }
  .filters-check:checked ~ .filters-more { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; width: 100%; }
  .tabs-pills { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .hide-sm { display: none !important; }
  .show-sm { display: initial; }
  .toasts { top: auto; bottom: calc(76px + env(safe-area-inset-bottom)); right: 8px; left: 8px; width: auto; max-width: none; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal, .modal-sm, .modal-lg { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
  .modal-actions .btn { flex: 1 1 0; height: 44px; }

  /* tables -> stacked cards */
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards thead { display: none; }
  .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table-cards tbody tr:last-child { border-bottom: 0; }
  .table-cards tbody tr:hover td { background: transparent; }
  /* label floats left, the value (all of the cell's content) sits right-aligned beside it */
  .table-cards td, .table-cards td:first-child, .table-cards td:last-child {
    padding: 3px 0; border: 0; text-align: right; line-height: 20px; overflow: hidden; overflow-wrap: anywhere;
  }
  .table-cards td::before {
    content: attr(data-label); float: left; margin-right: 14px;
    color: var(--text-3); font-size: 12.5px; font-weight: 550; line-height: 20px; text-align: left;
  }
  .table-cards td:not([data-label])::before, .table-cards td[data-label=""]::before { content: none; }
  .table-cards td.nowrap { white-space: normal; }
  .table-cards td .cell-sub { display: inline; margin: 0; }
  .table-cards td .cell-sub::before { content: " \00b7  "; }
  .table-cards td.tc-main { text-align: left; padding: 0 0 6px; font-size: 15px; }
  .table-cards td.tc-main .cell-sub { margin-left: 6px; }
  .table-cards td.tc-main .cell-sub::before { content: none; }
  .table-cards td.tc-hide { display: none; }
  .table-cards td.actions { text-align: left; padding-top: 8px; }
  .table-cards .row-alert td:first-child { box-shadow: none; }
  .table-cards .row-alert { box-shadow: inset 3px 0 0 var(--danger); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .sidebar, .topbar, .nav-backdrop, .toasts, .page-actions, .no-print { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}
