/* ════════════════════════════════════════════════════════════════════════
   TOM Driver — design system (UI-1) + driver app reskin (UI-2)
   Token-driven: every component reads from the scales below, so a rebrand
   or a new surface is a token edit, not a sweep. Both themes (night default,
   day optional) are first-class.
   ════════════════════════════════════════════════════════════════════════ */
:root {
  /* ── colour: brand + semantic ── */
  --brand-900:#071224; --brand-800:#0b1c36; --brand-700:#123059; --brand-600:#1c4d8f;
  --brand-500:#2A6BCC; --brand-400:#4D9EF5; --brand-300:#8ec1f9;

  --bg: #0E1623; --surface: #1A2638; --surface2: #22324a; --line: #2c3e58;
  --text: #EAF1FB; --muted: #93a6c2;
  --accent: #4D9EF5; --accent-d: #2A6BCC;
  --ok: #2ED47A; --warn: #E0A200; --danger: #FF5A5A; --red: var(--danger);
  --on-accent: #04203f;

  /* ── elevation ── */
  --shadow-1: 0 1px 2px rgba(2,8,20,.35), 0 2px 8px rgba(2,8,20,.25);
  --shadow-2: 0 4px 14px rgba(2,8,20,.40), 0 1px 4px rgba(2,8,20,.30);
  --shadow-3: 0 12px 34px rgba(2,8,20,.55);

  /* ── geometry / spacing / type ── */
  --radius: 14px; --radius-sm: 10px; --radius-lg: 18px; --radius-pill: 999px;
  --pad: 16px; --tap: 52px;
  --fs-title: 1.25rem; --fs-body: 1.0625rem; --fs-small: 0.8125rem; --fs-tiny: 0.75rem;

  /* ── motion ── */
  --ease: cubic-bezier(.2,.8,.25,1);
  --t-fast: .12s; --t-med: .22s;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}
/* Text-size setting (Me → App & display): the readable text below is rem-
   based, so scaling the root font-size scales body/card/button text without
   touching layout dimensions. */
html { font-size: 16px; }
html[data-textsize="large"] { font-size: 18px; }
html[data-textsize="extra"] { font-size: 20px; }

:root[data-theme="day"] {
  --bg:#F1F4F9; --surface:#FFFFFF; --surface2:#EDF1F8; --line:#D9E1EE;
  --text:#14213A; --muted:#55688A; --on-accent:#FFFFFF;
  --shadow-1: 0 1px 2px rgba(20,40,80,.07), 0 2px 8px rgba(20,40,80,.06);
  --shadow-2: 0 6px 18px rgba(20,40,80,.10), 0 1px 4px rgba(20,40,80,.07);
  --shadow-3: 0 16px 40px rgba(20,40,80,.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  /* Stop iOS Safari inflating font sizes; kill rubber-band/pull-to-refresh. */
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overscroll-behavior: none; }
body { font-size: var(--fs-body); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Disable the iOS long-press callout / forced text selection on app chrome. */
  -webkit-touch-callout: none; }
/* Inputs and content must stay selectable even though the chrome isn't. */
input, textarea, select, .selectable { -webkit-user-select: text; user-select: text; }
/* Full-height that survives the iOS dynamic toolbar (100vh is wrong on iOS). */
#app { max-width: 520px; margin: 0 auto; min-height: 100%;
  min-height: -webkit-fill-available; min-height: 100dvh;
  display: flex; flex-direction: column; }

/* ── header: branded, gradient, sits above content ── */
.hdr { position: sticky; top: 0; z-index: 5; color: #fff;
  background: linear-gradient(135deg, var(--brand-700) 0%, var(--accent-d) 60%, var(--brand-600) 100%);
  box-shadow: var(--shadow-2);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--pad) 14px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.hdr-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hdr h1 { font-size: var(--fs-title); margin: 0; font-weight: 700; letter-spacing: -.01em; }
.hdr-back { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.16); color: #fff; font-size: 26px; line-height: 1;
  display: grid; place-items: center; padding: 0 0 3px; cursor: pointer;
  transition: background var(--t-fast) var(--ease); }
.hdr-back:active { background: rgba(255,255,255,.30); }
.hdr-back:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.hdr .sub { font-size: var(--fs-small); opacity: .88; }
.chip { font-size: var(--fs-tiny); padding: 4px 11px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,.18); display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; backdrop-filter: blur(4px); }
.chip.ok { background: rgba(46,212,122,.25); }
.chip.warn { background: rgba(224,162,0,.30); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.off { background: var(--muted); } .dot.warn { background: var(--warn); }

/* ── layout ── */
main { flex: 1; padding: var(--pad); padding-bottom: 104px; }
.section-title { font-size: var(--fs-small); text-transform: uppercase; letter-spacing: .07em;
  font-weight: 700; color: var(--muted); margin: 20px 2px 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 15px; margin-bottom: 12px; box-shadow: var(--shadow-1); }
.card.tap { cursor: pointer; transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.card.tap:active { transform: scale(.985); box-shadow: var(--shadow-2); }
/* Keyboard users: tappable cards/rows are focusable (tabindex set at render) and show a ring. */
.tap:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 2px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); } .small { font-size: var(--fs-small); } .tiny { font-size: var(--fs-tiny); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.spacer { height: 8px; }

/* ── pills / status ── */
.pill { font-size: var(--fs-tiny); padding: 3px 11px; border-radius: var(--radius-pill);
  font-weight: 700; white-space: nowrap; letter-spacing: .01em; }
.pill.green { background: rgba(46,212,122,.18); color: var(--ok); }
.pill.amber { background: rgba(224,162,0,.20); color: var(--warn); }
.pill.red { background: rgba(255,90,90,.18); color: var(--danger); }
.pill.blue { background: rgba(77,158,245,.18); color: var(--accent); }
.pill.grey { background: var(--surface2); color: var(--muted); }
.seqnum { width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-d)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800;
  box-shadow: var(--shadow-1); }

/* ── buttons ── */
button { font: inherit; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: var(--tap); border: 0; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-d) 100%);
  color: #fff; font-weight: 700; font-size: var(--fs-body); padding: 0 16px;
  box-shadow: var(--shadow-1); cursor: pointer;
  transition: filter var(--t-fast) var(--ease), transform var(--t-fast) var(--ease); }
.btn:active { filter: brightness(.92); transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 2px; }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--line);
  box-shadow: none; }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--line);
  box-shadow: none; }
.btn.danger { background: linear-gradient(180deg, #ff7070, var(--danger)); color: #fff; }
.btn.ok { background: linear-gradient(180deg, #45e28e, var(--ok)); color: #06321c; }
.btn:disabled { opacity: .45; box-shadow: none; }
/* Small buttons keep a 44px minimum hit target (accessibility). */
.btn.sm { min-height: 44px; font-size: 0.9375rem; width: auto; padding: 0 14px; border-radius: var(--radius-sm); }
.btn-row { display: flex; gap: 10px; }
.fab-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 520px; margin: 0 auto;
  padding: 12px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: linear-gradient(180deg, transparent, var(--bg) 35%); }

/* ── bottom nav ── */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 520px; margin: 0 auto;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 18px rgba(2,8,20,.18);
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.nav a { flex: 1; text-align: center; padding: 9px 0 11px; color: var(--muted); font-size: 0.6875rem;
  font-weight: 600; text-decoration: none; display: flex; flex-direction: column; align-items: center;
  gap: 3px; transition: color var(--t-fast) var(--ease); }
.nav a.active { color: var(--accent); }
.nav a.active .ico { transform: translateY(-1px); }
.nav .ico { font-size: 21px; line-height: 1; transition: transform var(--t-fast) var(--ease); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 10px;
  font-weight: 700; padding: 1px 6px; margin-left: 4px; box-shadow: var(--shadow-1); }

/* ── forms ── */
label { font-size: var(--fs-small); font-weight: 600; color: var(--muted);
  display: block; margin: 12px 2px 6px; }
input[type=text], input[type=password], input[type=search], input[type=number],
input[type=date], input[type=time], input[type=tel], input[type=email], textarea, select {
  width: 100%; min-height: var(--tap); background: var(--surface2); border: 1.5px solid var(--line);
  border-radius: var(--radius); color: var(--text); padding: 12px 14px; font: inherit;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px; background-repeat: no-repeat; }
textarea { min-height: 88px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,158,245,.25); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }

/* ── login: brand hero ── */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 28px; gap: 4px; }
.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.logo .mark { width: 48px; height: 48px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-d));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 22px;
  box-shadow: var(--shadow-2); }

/* ── scanner ── */
.scan-wrap { background: #04101f; border-radius: var(--radius-lg); overflow: hidden; position: relative;
  aspect-ratio: 4/3; display: grid; place-items: center; box-shadow: var(--shadow-2); }
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; }
.reticle { position: absolute; width: 70%; height: 36%; border: 3px solid var(--accent);
  border-radius: 10px; box-shadow: 0 0 0 2000px rgba(4,16,31,.5);
  animation: reticle-pulse 2s var(--ease) infinite; }
@keyframes reticle-pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.checklist .ck { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.ck .tick { color: var(--ok); } .ck .pending { color: var(--muted); }

/* ── signature ── */
.sig { width: 100%; height: 180px; background: #fff; border-radius: var(--radius); touch-action: none;
  box-shadow: inset 0 0 0 1.5px var(--line); }
.photo-prev { width: 100%; border-radius: var(--radius); margin-top: 8px; max-height: 220px; object-fit: cover; }

/* ── status timeline ── */
.timeline { display: flex; gap: 4px; margin: 10px 0 14px; }
.timeline .seg { flex: 1; height: 6px; border-radius: 3px; background: var(--surface2);
  transition: background var(--t-med) var(--ease); }
.timeline .seg.done { background: var(--ok); }
.timeline .seg.cur { background: linear-gradient(90deg, var(--accent), var(--brand-300)); }

/* ── map fallback ── */
.mapbox { height: 220px; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--line);
  background: var(--surface2); position: relative; box-shadow: var(--shadow-1); }
.map-fallback { height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: var(--muted); text-align: center; padding: 16px; }

/* ── toast ── */
.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); z-index: 20;
  background: rgba(10,18,32,.92); color: #fff; padding: 11px 18px; border-radius: var(--radius-pill);
  font-size: 0.875rem; font-weight: 600; max-width: 90%; box-shadow: var(--shadow-3);
  backdrop-filter: blur(6px); animation: toast-in var(--t-med) var(--ease); }
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── modal sheet ── */
.sheet-bg { position: fixed; inset: 0; background: rgba(2,8,20,.6); z-index: 30; display: flex;
  align-items: flex-end; backdrop-filter: blur(3px); animation: fade-in var(--t-fast) var(--ease); }
.sheet { background: var(--surface); width: 100%; max-width: 520px; margin: 0 auto;
  border-radius: 22px 22px 0 0; padding: 10px var(--pad) calc(env(safe-area-inset-bottom,0) + 18px);
  box-shadow: var(--shadow-3); animation: sheet-up var(--t-med) var(--ease); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 12px; font-size: var(--fs-title); }
.warn-sheet .icon { font-size: 30px; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── install prompt (Android custom prompt / iOS A2HS guide) ── */
.install-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; max-width: 520px;
  margin: 0 auto; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-3);
  padding: 12px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px); }
.install-bar img { width: 38px; height: 38px; border-radius: 9px; }
.install-bar .txt { flex: 1; min-width: 0; }
.install-steps { display: flex; flex-direction: column; gap: 12px; margin: 8px 0 4px; }
.install-steps .step { display: flex; gap: 12px; align-items: flex-start; }
.install-steps .n { flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-d); color: #fff; font-weight: 700; font-size: 13px;
  display: grid; place-items: center; }
.ios-share { display: inline-block; font-weight: 700; color: var(--accent); }

/* ── profile / vehicle photos ── */
.photo-grid { display: flex; gap: 16px; }
.photo-pick { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar-lg { width: 84px; height: 84px; border-radius: 50%; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-d));
  display: grid; place-items: center; font-size: 28px; font-weight: 800; overflow: hidden;
  box-shadow: var(--shadow-1); }
.veh-lg { width: 100%; height: 84px; border-radius: var(--radius); background: var(--surface2);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 34px; overflow: hidden; }
.avatar-lg img, .veh-lg img { width: 100%; height: 100%; object-fit: cover; }
.pod-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pod-thumb { position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.pod-thumb img { width: 100%; height: 100%; object-fit: cover; }
/* 44px hit target drawn as a 22px disc (the thumbnail is only 76px wide). */
.pod-thumb .rm { position: absolute; top: -8px; right: -8px; width: 44px; height: 44px; border: 0; padding: 0;
  border-radius: 50%; background: radial-gradient(circle at center, rgba(0,0,0,.65) 0 11px, transparent 12px);
  color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }
.pod-thumb .rm:focus-visible { outline: 3px solid var(--brand-300); outline-offset: -8px; }

/* ── misc ── */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 0.9375rem; }
.kv .k { color: var(--muted); }
.kv.tap { cursor: pointer; border-radius: var(--radius-sm); }
.kv.tap:active { background: var(--surface2); }

/* Skeleton shimmer for loading states */
.skel { position: relative; overflow: hidden; background: var(--surface2); border-radius: var(--radius-sm); }
.skel::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent);
  animation: skel-slide 1.4s var(--ease) infinite; }
@keyframes skel-slide { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ── TOM Assist (AI chat) ── */
.ai-bubble { max-width: 86%; padding: 10px 14px; border-radius: 16px; line-height: 1.4;
  font-size: 0.9375rem; white-space: pre-wrap; overflow-wrap: break-word;
  animation: bubble-in var(--t-fast) var(--ease); }
.ai-bubble.me { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-d));
  color: #fff; border-bottom-right-radius: 4px; margin-left: auto; box-shadow: var(--shadow-1); }
.ai-bubble.tom { align-self: flex-start; background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 4px; box-shadow: var(--shadow-1); }
.ai-composer { position: fixed; bottom: calc(env(safe-area-inset-bottom, 0px) + 62px); left: 0; right: 0;
  max-width: 520px; margin: 0 auto; display: flex; gap: 8px; padding: 10px var(--pad);
  background: var(--bg); border-top: 1px solid var(--line); z-index: 6; }
.ai-composer input { flex: 1; min-width: 0; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Respect reduced-motion preferences (toast/sheet slide-ins included) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .toast, .sheet, .sheet-bg { animation: none; }
}

/* Profile destinations remain readable and easy to select on a phone. */
.profile-menu-item { min-height: 52px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--text); gap: 12px; }
.profile-menu-item:last-child { border-bottom: 0; }

/* Reflow for long identifiers, enlarged text and small screens. */
.hdr h1, .hdr .sub, .card, .kv, .sheet { overflow-wrap: anywhere; }
.row > .stack, .kv > span, .hdr-row > div { min-width: 0; }
.btn { white-space: normal; padding-top: 10px; padding-bottom: 10px; }
.nav a:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 2px; }
.route-loading { padding-top: 32px; }
@media (max-width: 360px) { .hdr-row { flex-wrap: wrap; } .hdr-row > .stack { flex-direction: row; flex-wrap: wrap; } .btn-row { flex-wrap: wrap; } }

.file-pick { position: relative; overflow: hidden; }
.file-pick input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-pick:focus-within { outline: 3px solid var(--brand-300); outline-offset: 2px; }

.row > .btn.sm { flex-shrink: 0; overflow-wrap: normal; }

.pill { white-space: normal; max-width: 100%; overflow-wrap: anywhere; }
@media (max-width: 360px) { .hdr { position: relative; } }

/* Keep the page action above bottom navigation, including enlarged text. */
.nav { height: calc(48px + 1rem + env(safe-area-inset-bottom, 0px)); }
.nav a { position: relative; }
.nav .badge { position: absolute; top: 3px; left: calc(50% + 7px); }
#app:has(.nav) .fab-bar { bottom: calc(48px + 1rem + env(safe-area-inset-bottom, 0px)); padding-bottom: 8px; }
#app:has(.nav):has(.fab-bar) main { padding-bottom: calc(160px + 3rem + env(safe-area-inset-bottom, 0px)); }

/* Run actions retain whole labels at phone widths and enlarged text. */
.run-summary { flex-wrap: wrap; align-items: flex-start; gap: 12px; }
.run-summary > .stack { flex: 1 1 180px; }
.run-summary > .btn-row { flex: 0 0 auto; flex-wrap: wrap; max-width: 100%; }
.run-summary .btn { white-space: nowrap; word-break: normal; overflow-wrap: normal; }

/* Status words stay intact beside long stop addresses. */
.row > .pill { flex-shrink: 0; overflow-wrap: normal; }
#dispatch-contact .pill { display: inline-block; overflow-wrap: normal; }
