/* ==========================================================
   SleepWell Delivery Hub — "night shift" theme
   Deep night-indigo surfaces, one warm lamp-amber accent,
   and a colour per delivery status. All colours are variables.
   ========================================================== */

:root {
  color-scheme: dark;

  /* Surfaces */
  --bg: #0e1120;
  --sidebar: #121730;
  --surface: #171d36;
  --raised: #1f2745;
  --input: #10142a;
  --border: #2b3457;
  --border-strong: #3a4672;

  /* Text */
  --text: #e7eaf6;
  --muted: #98a1c0;
  --placeholder: #6b7598;
  --heading: #ffffff;

  /* Accent: bedside-lamp amber (primary actions, current page) */
  --accent: #f3b648;
  --accent-hover: #ffc865;
  --accent-ink: #1d1606;
  --accent-soft: rgba(243, 182, 72, 0.12);
  --link: #8fb3ff;
  --focus: #8fb3ff;

  /* Feedback */
  --ok: #4cc38a;
  --ok-bg: rgba(76, 195, 138, 0.12);
  --ok-text: #8ee2b6;
  --err: #ff6b6b;
  --err-bg: rgba(255, 107, 107, 0.10);
  --err-text: #ffb0b0;

  /* Delivery statuses */
  --st-total: #c3c9e4;      /* neutral, for "Total orders" */
  --st-new: #ff8a7a;        /* coral: waiting for a truck, needs action */
  --st-open: #a3acc9;       /* packing slip not started yet */
  --st-assigned: #7aa2ff;
  --st-transit: #f3b648;
  --st-customer: #c792ff;
  --st-completed: #4cc38a;
  --st-return: #ff6b9a;     /* pink-red: unsuccessful delivery, goods coming back */
  --st-received: #4fd1c5;   /* teal: back at the warehouse, waiting to go out again */
  --st-cancelled: #8f97ad;  /* grey: customer cancelled */
  --st-ret-pending: #f5a35c; /* amber-orange: return booked, not yet received at the warehouse */
  --st-ret-done: #6fd39b;    /* green: return received */
  --st-incident: #d32f2f;   /* dark red: incident reported (card, borders, fills) */
  --st-incident-text: #f05454; /* same red, light enough for small text on the dark theme */

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-w: 248px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.18);
}

/* ---------- Base ---------- */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Tahoma", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; }
h3 { font-size: 16px; font-weight: 650; margin: 0 0 12px; }
h4 { font-size: 15px; font-weight: 650; }
a { color: var(--link); }
small { font-size: 12px; }

/* ---------- App layout: sidebar + main ---------- */
.app { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 20;
}

.brand { display: flex; flex-direction: column; align-items: stretch; gap: 10px; padding: 0 2px 4px; }
/* The Sleep Well logo is navy on white, so it sits on a white tile */
.brand__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  background: #ffffff;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.brand__logo img { display: block; width: 100%; max-width: 168px; height: auto; }
.brand__name {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--muted);
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.nav__item:hover { background: var(--raised); color: var(--text); }
.nav__item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav__icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav__badge {
  margin-left: auto;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.sidebar__note {
  margin: auto 0 0;
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.main { margin-left: var(--sidebar-w); min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 28px 14px;
  background: rgba(14, 17, 32, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.menu-btn {
  display: none;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.menu-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

main { max-width: 1120px; padding: 22px 28px 48px; }

.scrim { position: fixed; inset: 0; background: rgba(4, 6, 14, 0.6); z-index: 15; }

/* Phones and small tablets: sidebar becomes a slide-out drawer */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4);
  }
  body.menu-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 19px; }
  main { padding: 16px 16px 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* ---------- Sign-in screen ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(243, 182, 72, 0.10), transparent 60%),
    var(--bg);
}
.login__card {
  width: min(400px, 100%);
  padding: 28px 26px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.login__brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; }
.login__brand .brand__logo { width: 100%; padding: 14px 18px; }
.login__brand .brand__logo img { max-width: 200px; }
.login h1 { font-size: 22px; margin: 0 0 16px; }
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.segmented label { display: block; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 8px 0;
  border-radius: 7px;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.password-field { position: relative; }
.password-field input { padding-right: 76px; }
.password-field button { position: absolute; right: 6px; top: 12px; }
.login__hint { margin: -4px 0 8px; min-height: 0; }
.login__hint:empty, .login__error:empty { display: none; }
.login__error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--err-bg);
  color: var(--err-text);
  font-size: 13px;
}
.login__submit { width: 100%; padding: 12px; margin-top: 4px; }

/* ---------- Signed-in user (sidebar) ---------- */
.user-box {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.user-box button { white-space: nowrap; }
.user-box { flex-wrap: wrap; }
.sync-status { flex-basis: 100%; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sync-status:empty { display: none; }
.sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-status[data-state="saved"]::before { background: var(--ok); }
.sync-status[data-state="saving"]::before, .sync-status[data-state="loading"]::before { background: var(--accent); }
.sync-status[data-state="error"] { color: var(--err-text); }
.sync-status[data-state="error"]::before { background: var(--err); }
.login__mode { margin: 0 0 12px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.login__mode:empty { display: none; }
.login__mode::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.login__mode[data-state="central"]::before { background: var(--ok); }
.legacy-banner { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.legacy-banner p { margin: 0 0 12px; }
.user-box__name { font-weight: 650; font-size: 13.5px; color: var(--heading); }
.user-box .muted { font-size: 12px; }
.user-box + .sidebar__note { margin-top: 0; }

/* Dashboard filters: search and dates on the first row, Transporter + Status on the second */
@media (min-width: 1100px) {
  .filters.dash-filters { grid-template-columns: repeat(5, minmax(0, 1fr)); row-gap: 12px; }
}

.slip-list-filters { margin-bottom: 4px; }

/* Packing slip list: order list folds away behind the arrow */
.slip .truck__head { align-items: flex-start; }
.slip__summary { flex: 1; min-width: 0; }
.slip-toggle {
  flex: none; width: 34px; height: 34px; padding: 0; margin: 2px 4px 0 -4px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid var(--border); background: var(--input); color: var(--text);
}
.slip-toggle:hover { border-color: var(--accent); background: var(--raised); }
.slip-toggle__arrow { display: inline-block; font-size: 16px; line-height: 1; transition: transform 0.15s ease; }
.slip--open .slip-toggle__arrow { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .slip-toggle__arrow { transition: none; } }

/* Service flags on an order (Assembly / Without lift) */
.flag-badge { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700;
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Man power on a packing slip */
.slip-men { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); margin: 4px 0; }
.slip-men input { width: 90px; height: 34px; margin: 0; padding: 4px 8px; }

/* ---------- User Access ---------- */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; margin-bottom: 12px; }
.module-check, .check-line { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; padding: 6px 0; }
.module-check input, .check-line input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.check-line { margin: 4px 0 8px; }
.users-table td:nth-child(3) { max-width: 420px; }

/* ---------- Driver: extra delivery photos ("Add Image") ---------- */
.extra-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  border: 2px dashed var(--border-strong); cursor: pointer; min-height: 150px; position: relative; }
.extra-add:hover { border-color: var(--accent); }
.extra-add__plus { font-size: 40px; line-height: 1; font-weight: 300; color: var(--accent); }
.extra-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; margin: 0; }
.extra-add--full { opacity: 0.55; cursor: not-allowed; }
.extra-add:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.extra-thumbs { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.extra-thumb { position: relative; margin: 0; }
.extra-thumb__img { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background: var(--input); border: 1px solid var(--border); }
.extra-thumb__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.extra-thumb__remove { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.7); color: #fff; border: 1px solid rgba(255, 255, 255, 0.4); font-size: 16px; line-height: 1; }
.extra-thumb figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: center; }

/* ---------- Edit Order ---------- */
.order-dialog { width: min(860px, 96vw); }
.order-dialog .pod-dialog__inner { max-height: 88vh; overflow-y: auto; }
.oe-item { display: grid; grid-template-columns: 1.2fr 2fr 0.7fr 0.7fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.oe-item input { margin: 0; }
@media (max-width: 640px) { .oe-item { grid-template-columns: 1fr 1fr; } .oe-item .oe-desc { grid-column: 1 / -1; } }
#orders-search { max-width: 360px; }

/* ---------- Report Incident ---------- */
.incident-box { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border); }
.incident-box h4 { margin: 0 0 6px; color: var(--st-incident-text); }
.incident-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 8px 0; }
.incident-photos .extra-add { min-height: 110px; aspect-ratio: auto; }
.incident-badge { display: inline-block; margin-left: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700;
  color: var(--st-incident-text); border: 1px solid color-mix(in srgb, var(--st-incident) 70%, transparent); background: color-mix(in srgb, var(--st-incident) 18%, transparent); }
.incident-head { color: var(--st-incident-text); }
.incident-report { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid color-mix(in srgb, var(--st-incident) 45%, transparent);
  background: color-mix(in srgb, var(--st-incident) 8%, transparent); margin-bottom: 10px; }
.incident-report p { margin: 0 0 4px; white-space: pre-wrap; }

/* ---------- Call Customer ---------- */
.pod-calls { color: var(--accent); }
.call-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; margin: 2px 6px 2px 0; border-radius: 10px;
  background: #2f9e62; color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap; }
.call-btn::before { content: "☎"; }
.call-btn:hover, .call-btn:focus-visible { background: #36b16f; outline: 2px solid var(--focus); outline-offset: 2px; }
.call-count { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 8px;
  border-radius: 99px; font-size: 16px; font-weight: 800; background: var(--raised); color: var(--muted); border: 1px solid var(--border); margin-right: 8px; }
.call-count--some { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.calls-table td.c-count small { display: block; margin-top: 4px; }
/* Customer confirmed delivery date & time (Call Customer page, POD window) */
.confirm-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.confirm-form input[type="date"] { width: 150px; }
.confirm-form input[type="time"] { width: 128px; }
.cf-label { display: none; }
.confirm-form input { padding: 6px 8px; margin: 0; }
.confirm-form button { margin: 0; }
.cf-note { display: block; margin-top: 4px; }
.calls-table td.c-confirm { min-width: 300px; }
.pod-confirmed { color: var(--accent); }
.pod-confirm { margin: 10px 0 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.pod-confirm > b { display: block; margin-bottom: 6px; font-size: 13px; }
.call-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.call-stack .call-btn { margin: 0; }
@media (max-width: 640px) {
  .calls-table thead { display: none; }
  .calls-table, .calls-table tbody, .calls-table td { display: block; width: 100%; }
  .calls-table tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .calls-table td { padding: 0; border: 0; }
  .calls-table .c-ref { grid-column: 1; }
  .calls-table .c-count { grid-column: 2; grid-row: 1; text-align: right; }
  .calls-table .c-cust, .calls-table .c-phone { grid-column: 1 / -1; }
  .calls-table .c-call { grid-column: 1 / -1; }
  .calls-table td.c-confirm { grid-column: 1 / -1; min-width: 0; }
  .calls-table .cf-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 4px 0 6px; }
  .calls-table .call-btn { padding: 10px 22px; }
  .calls-table .c-count small { max-width: 150px; margin-left: auto; font-size: 11px; }
  .calls-table .c-ref small { white-space: nowrap; }
}

/* ---------- Payment Reco ---------- */
.reco-kex { padding: 16px 18px; }
.reco-kex iframe { display: block; width: 100%; height: 900px; border: 0; background: transparent; }
.reco-table td.num, .reco-table th:nth-last-child(-n+3) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reco-table td.over { color: var(--st-return); font-weight: 700; }
.reco-table td.under { color: var(--st-received); }
.reco-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 12px 0; }
.reco-totals > div { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--raised); display: flex; flex-direction: column; gap: 4px; }
.reco-totals span { font-size: 12px; color: var(--muted); }
.reco-totals b { font-size: 20px; font-variant-numeric: tabular-nums; }
.reco-totals .over b { color: var(--st-return); }
.pin-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.pin-row input { margin: 0; }
.small-note { font-size: 12px; margin: 0 0 10px; }
#reco-rules .card-head .segmented { margin: 0; }

/* ---------- Ownership notice ---------- */
.login__copyright { margin: 16px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Language switch (EN | ไทย) ---------- */
.topbar__title { flex: 1; min-width: 0; }
.lang-switch {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--input);
}
.lang-switch button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.lang-switch button:hover { background: var(--raised); color: var(--text); }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.login__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.login__top h1 { margin: 0; }
/* Thai text is taller: a little more line height reads better */
html[lang="th"] body { line-height: 1.6; }

/* ---------- Buttons ---------- */
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 650;
}
button:hover { background: var(--accent-hover); }
button.secondary {
  background: var(--raised);
  color: var(--text);
  border-color: var(--border);
  font-weight: 550;
}
button.secondary:hover { border-color: var(--border-strong); background: #263055; }
button.small { padding: 6px 11px; font-size: 13px; }
button:disabled,
button:disabled:hover {
  background: var(--raised);
  color: var(--placeholder);
  border-color: var(--border);
  cursor: not-allowed;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Forms ---------- */
label { display: inline-block; font-size: 13px; font-weight: 600; color: var(--text); }
label .muted { font-weight: 400; }

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  margin: 6px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input);
  color: var(--text);
  font: inherit;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select { height: 42px; }
textarea { min-height: 76px; resize: vertical; }
input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input[type="file"] { padding: 8px; }
input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  vertical-align: middle;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.pod-thumb:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Trucks: create / check in ---------- */
.row-actions { white-space: nowrap; }
.row-actions button + button { margin-left: 6px; }
.delete-btn:hover:not(:disabled) { border-color: var(--st-return); color: var(--st-return); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; text-decoration: underline; cursor: pointer; margin: -6px 0 12px; }
.link-btn:hover { background: none; filter: brightness(1.1); }
.truck-info { align-self: start; }
.truck-info__body { margin: 6px 0 14px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius-sm); min-height: 42px; color: var(--text); }
.truck-info:empty { display: none; }

/* ---------- Change truck on a packing slip ---------- */
.order-note { margin: 4px 0 0; font-size: 12px; color: var(--st-return); }
.order-note:empty { display: none; }
.slip-truck-change { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); margin: 4px 0; }
.slip-truck-change select { width: auto; min-width: 200px; height: 34px; margin: 0; padding: 4px 8px; }

/* ---------- Multi-select dropdown (tick boxes) ---------- */
.field-label { display: inline-block; font-size: 13px; font-weight: 600; color: var(--text); }
.ms { position: relative; margin: 6px 0 14px; }
.filters .ms { margin-bottom: 0; }
.ms__btn {
  width: 100%; height: 42px; padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--input); color: var(--text); font: inherit; font-weight: 400; text-align: left;
}
.ms__btn:hover { border-color: var(--border-strong); background: var(--input); }
.ms__btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.ms__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms__caret { color: var(--muted); font-size: 12px; }
.ms--active .ms__btn { border-color: var(--accent); }
.ms__panel {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: 320px;
  padding: 6px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--raised); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.ms__opts { max-height: 260px; overflow-y: auto; }
.ms__opt { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border-radius: 6px; font-weight: 400; cursor: pointer; }
.ms__opt:hover { background: var(--surface); }
.ms__opt input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.ms__label { flex: 1; }
.ms__count { color: var(--muted); font-size: 12px; }
.ms__foot { display: flex; justify-content: flex-end; padding: 6px 4px 2px; border-top: 1px solid var(--border); margin-top: 4px; }
.ms__empty { margin: 6px 8px; }

/* ---------- Cards & layout pieces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 0 0 18px;
  box-shadow: var(--shadow);
}
.card > p.muted:first-of-type { margin-top: -4px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.card-head select, .card-head input { width: auto; margin: 0; }
.form-error { color: var(--err-text); }
.truck-note { margin: -8px 0 12px; font-size: 12px; }
.truck-note:empty { display: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.muted { color: var(--muted); font-size: 13px; }
.spaced { display: block; margin-top: 16px; }

/* ---------- Status tags & pills ---------- */
.tag {
  --c: var(--st-new);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag--new { --c: var(--st-new); }
.tag--open { --c: var(--st-open); }
.tag--assigned { --c: var(--st-assigned); }
.tag--in-transit, .tag--in-progress { --c: var(--st-transit); }
.tag--at-customer { --c: var(--st-customer); }
.tag--completed { --c: var(--st-completed); }
.tag--pending-return { --c: var(--st-return); }
.tag--received-back { --c: var(--st-received); }
.tag--cancelled { --c: var(--st-cancelled); }
.tag--pending-return-receive { --c: var(--st-ret-pending); }
.tag--return-completed { --c: var(--st-ret-done); }
.tag--booked { --c: var(--st-assigned); }
.tag--picked-up { --c: var(--st-completed); }
/* Gate status */
.tag--in { --c: var(--st-completed); }
.tag--out { --c: var(--st-open); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid;
  font-size: 12px;
  font-weight: 600;
}
.pill-ok { color: var(--ok-text); border-color: color-mix(in srgb, var(--ok) 55%, transparent); background: var(--ok-bg); }
.pill-err { color: var(--err-text); border-color: color-mix(in srgb, var(--err) 55%, transparent); background: var(--err-bg); }

/* ---------- Dashboard ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
/* Wide screens: 5 cards per row, Transporter Logs as a tall card on the right across both rows */
@media (min-width: 1100px) {
  .stats { grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 1.15fr); }
  .stats .stat--transporters { grid-column: 6; grid-row: 1 / span 2; }
}
.stat {
  --c: var(--accent);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  /* Fallbacks first, then the status-tinted versions */
  background: var(--surface);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--c) 13%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  border-top: 3px solid var(--c);
  border-radius: var(--radius-lg);
}
.stat__label {
  display: flex;
  align-items: flex-start; /* dot stays by the first line when a title wraps */
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.stat__label::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent);
  margin-top: 4px;
}
.stat__value { font-size: 32px; font-weight: 750; color: var(--c); line-height: 1; margin-top: auto; }
/* Breakdown next to a card's number (Waiting for truck: New orders / Redelivery); the number stays level with other cards */
.stat__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: auto; }
.stat__row .stat__value { margin-top: 0; }
.stat__split { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12.5px; color: var(--muted); text-align: right; }
.stat__split b { color: var(--text); font-weight: 750; margin-left: 4px; } /* numbers line up even when a title wraps */
.stat--total { --c: var(--st-total); }
.stat--total .stat__value { color: var(--heading); }
.stat--new { --c: var(--st-new); }
.stat--assigned { --c: var(--st-assigned); }
.stat--pending-return { --c: var(--st-return); }
.stat--cancelled { --c: var(--st-cancelled); }
.stat--incident { --c: var(--st-incident); }
.stat--pending-return-receive { --c: var(--st-ret-pending); }
.stat--return-completed { --c: var(--st-ret-done); }
.stat--transporters { --c: #9b8cff; }
.tlog { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 5px; }
.tlog li { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 8px; font-size: 13px; }
.tlog__name { font-weight: 700; color: var(--text); }
.tlog__bar { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--c) 18%, transparent); overflow: hidden; }
.tlog__bar span { display: block; height: 100%; border-radius: 99px; background: var(--c); }
.tlog__num { font-weight: 700; color: var(--c); white-space: nowrap; }
.tlog__num small { font-weight: 500; color: var(--muted); }
.tlog__empty { font-size: 13px; margin-top: auto; }
.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; }
.cancel-order:hover:not(:disabled) { border-color: var(--st-return); color: var(--st-return); }
.receive-btn { margin-top: 6px; }
.stat--in-transit { --c: var(--st-transit); }
.stat--completed { --c: var(--st-completed); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0 14px;
  align-items: start;
}
.filters input, .filters select { margin-bottom: 0; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 6px; }
.quick-dates [aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.dash-table { min-width: 860px; }
.gate-table { min-width: 780px; }
.gate-table td { vertical-align: middle; }
.gate-table td:nth-child(3), .gate-table td:nth-child(4) { white-space: nowrap; }
.dash-table td:nth-child(3), .dash-table td:nth-child(4), .dash-table td:nth-child(6) { white-space: nowrap; }
.dash-table td { vertical-align: middle; }
.dash-table button { white-space: nowrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 10px; text-align: left; font-size: 13.5px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: none; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }

/* ---------- Order items (SKU + QTY) ---------- */
.items, .choice {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 6px 0 16px;
}
.items legend, .choice legend { font-size: 13px; font-weight: 600; padding: 0 6px; }
.item-row { display: grid; grid-template-columns: 1fr 110px 40px; gap: 8px; align-items: center; }
.item-row input { margin: 0 0 8px; }
.item-row .item-remove { margin-bottom: 8px; padding: 8px 0; }
.item-row--head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.choice label { display: flex; gap: 10px; align-items: center; font-weight: 400; padding: 5px 0; }

/* ---------- Bulk upload ---------- */
.bulk-table, .slip-table {
  max-height: 420px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.bulk-table th, .slip-table th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.slip-table td:first-child, .slip-table th:first-child { width: 36px; }
.row-error td { background: var(--err-bg); }
.issues { color: var(--err-text); min-width: 180px; }

/* ---------- Trucks & packing slips (list blocks) ---------- */
.truck, .slip {
  border: 1px solid var(--border);
  background: var(--raised);
  border-radius: var(--radius);
  padding: 14px;
  margin: 10px 0;
}
.truck h4, .slip h4 { margin: 0 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.truck-type {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--input);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.small-note { font-size: 12px; font-weight: 400; }
.truck__head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.truck__buttons { display: flex; gap: 6px; align-items: flex-start; }
.truck__deliveries { list-style: none; padding: 0; margin: 12px 0 0; }
.truck__deliveries li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

/* ---------- Partial loads (Load QTY) ---------- */
.load-line { display: flex; align-items: center; gap: 8px; margin: 2px 0; flex-wrap: wrap; }
.load-sku { min-width: 110px; font-size: 13px; }
.load-qty { width: 84px; height: 34px !important; margin: 0; padding: 4px 8px; }
.load-qty--bad { border-color: var(--err); background: var(--err-bg); }
.load-summary { margin: 8px 0 0; }
.load-summary:empty { display: none; }
.split-note { color: var(--st-transit); font-weight: 600; }
.fail-note { color: var(--st-return); }

/* ---------- POD Register ---------- */
.pod-count-row { display: flex; align-items: center; gap: 12px; margin: 10px 0 6px; min-height: 30px; }

/* ---------- Return Booking ---------- */
.items-fieldset { margin: 14px 0; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.items-fieldset legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
.ret-item { display: grid; grid-template-columns: 1.1fr 2fr 0.7fr 0.7fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.ret-item input { margin: 0; }
@media (max-width: 700px) {
  .ret-item { grid-template-columns: 1fr 1fr; }
  .ret-item .ret-desc { grid-column: 1 / -1; order: 2; }
}

/* ---------- Driver portal ---------- */
.contact-line { display: inline-block; margin: 2px 0; }
.tel-link { color: var(--accent); font-weight: 650; text-decoration: none; padding: 2px 0; }
.tel-link::before { content: "☎ "; }
.tel-link:hover, .tel-link:focus-visible { text-decoration: underline; }
/* Completed deliveries: a table on wide screens, one card per delivery on phones */
@media (max-width: 640px) {
  .done-table thead { display: none; }
  .done-table, .done-table tbody, .done-table tr, .done-table td { display: block; width: 100%; }
  .done-table tr {
    display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
    padding: 12px 0; border-bottom: 1px solid var(--border);
  }
  .done-table td { padding: 0; border: 0; }
  .done-table .done-cust { grid-column: 1 / -1; }
  .done-table .done-ref { grid-column: 1; }
  .done-table .done-status { grid-column: 2; grid-row: 1; text-align: right; }
  .done-table .done-when { grid-column: 1; color: var(--muted); font-size: 13px; }
  .done-table .done-pod { grid-column: 2; text-align: right; }
}
.subtabs { display: flex; gap: 6px; margin-bottom: 16px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--input); width: max-content; max-width: 100%; }
.subtabs button { background: transparent; color: var(--muted); border: 0; padding: 9px 16px; border-radius: 9px; font-weight: 650; display: inline-flex; align-items: center; gap: 8px; }
.subtabs button:hover { color: var(--text); background: var(--raised); }
.subtabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
/* Second level (e.g. Delivery → Open & In progress / Completed): lighter, so the two levels read apart */
.subtabs--small { margin-bottom: 14px; padding: 3px; border-radius: 10px; }
.subtabs--small button { padding: 7px 14px; font-size: 13px; }
.subtabs--small button[aria-selected="true"] { background: var(--raised); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.fail-box { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--border); }
.fail-box h4 { margin: 0 0 4px; color: var(--st-return); }
button.danger { background: var(--st-return); color: #1a0710; }
button.danger:hover:not(:disabled) { filter: brightness(1.08); }
.slip-evidence {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 14px;
  background: rgba(255, 255, 255, 0.015);
}
.slip-evidence__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.slip-evidence p { margin: 4px 0 8px; }
.slip-trip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 18px; }
.trip-blocked { color: var(--err-text); font-size: 13px; }

.evidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0 12px;
}
.evidence {
  border: 1px solid var(--border);
  padding: 12px 14px 2px;
  border-radius: var(--radius);
  margin: 10px 0;
  background: var(--raised);
}
.evidence input { margin-bottom: 10px; }
.evidence.ok { border-color: color-mix(in srgb, var(--ok) 60%, transparent); background: var(--ok-bg); }

/* ---------- POD viewer ---------- */
.pod-dialog {
  width: min(880px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.gate-out { width: min(640px, calc(100vw - 24px)); }
.gate-out #gate-out-info { margin: 0 0 6px; }
.pod-dialog::backdrop { background: rgba(4, 6, 14, 0.72); }
.pod-dialog__inner { position: relative; padding: 18px; }
.pod-dialog__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: -18px;
  margin: -18px -18px 14px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.pod-dialog__head h3 { margin: 0; }
.pod-dialog h4 { margin: 20px 0 10px; }
.pod-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; line-height: 1.7; }
.pod-facts { margin-top: 14px; }
.pod-facts th { width: 120px; }
.pod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.pod-tile { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--raised); }
.pod-tile__img { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--input); }
.pod-tile__img .muted { padding: 8px; }
.pod-thumb { padding: 0; border: 0; border-radius: 0; background: none; width: 100%; height: 100%; }
.pod-thumb:hover { background: none; }
.pod-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pod-tile figcaption { padding: 8px 10px; font-size: 13px; }
.pod-dialog video { width: 100%; max-height: 360px; border-radius: var(--radius); background: #000; }
.pod-zoom {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: rgba(4, 6, 14, 0.94);
  cursor: zoom-out;
}
.pod-zoom img { max-width: 100%; max-height: calc(100vh - 100px); object-fit: contain; }

/* ---------- Printing a packing slip ---------- */
.print-items td.num { text-align: right; white-space: nowrap; }
#print-area { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; color: #000; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font: 11px system-ui, "Sarabun", "Leelawadee UI", "Tahoma", sans-serif; color: #000; }
  .print-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 8px; }
  .print-head h1 { margin: 0; font-size: 22px; color: #000; }
  .print-brand { display: flex; align-items: center; gap: 14px; }
  .print-brand img { height: 56px; width: auto; }
  .print-copyright { margin-top: 14px; text-align: center; font-size: 9px; color: #555; }
  .print-number { font-size: 20px; font-weight: 700; border: 2px solid #000; padding: 6px 10px; }
  .print-right { display: flex; align-items: flex-start; gap: 14px; }
  .print-qr { display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .print-qr img { width: 27mm; height: 27mm; display: block; image-rendering: pixelated; }
  .print-qr__text { display: flex; flex-direction: column; align-items: center; font-size: 9px; line-height: 1.25; }
  .print-qr__text b { font-size: 10px; }
  .print-meta, .print-items { width: 100%; border-collapse: collapse; margin-top: 12px; }
  .print-meta th, .print-meta td, .print-items th, .print-items td {
    border: 1px solid #999; padding: 6px; text-align: left; vertical-align: top; font-size: 12px; color: #000;
  }
  .print-meta th, .print-items th { background: #eee; }
  .print-items tr { break-inside: avoid; }
  .print-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 48px; }
  .print-sign div { border-top: 1px solid #000; padding-top: 4px; }
}
