/* styles.css — all CSS for the AutoDispatch RD2 frontend (spec §2.1, §8).
   Color tokens (light default + dark via prefers-color-scheme AND a manual
   data-theme toggle), the two-region layout (rail + canvas), chat/thread/
   composer, map, tree, chips, :focus-visible, prefers-reduced-motion.
   System font stack only — no web fonts, no external requests. */

:root {
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --rule: #c3c2b7;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;

  --cat-1: #2a78d6;
  --cat-2: #1baf7a;
  --cat-3: #eda100;
  --cat-4: #008300;
  --cat-5: #4a3aa7;
  --cat-6: #e34948;
  --cat-7: #e87ba4;
  --cat-8: #eb6834;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232320;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --rule: #383835;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --accent: #3987e5;
    --cat-1: #3987e5;
    --cat-2: #199e70;
    --cat-3: #c98500;
    --cat-5: #9085e9;
    --cat-6: #e66767;
    --cat-7: #d55181;
    --cat-8: #d95926;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232320;
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --rule: #383835;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --accent: #3987e5;
  --cat-1: #3987e5;
  --cat-2: #199e70;
  --cat-3: #c98500;
  --cat-5: #9085e9;
  --cat-6: #e66767;
  --cat-7: #d55181;
  --cat-8: #d95926;
}

:root[data-theme="light"] {
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --rule: #c3c2b7;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #2a78d6;
  --cat-1: #2a78d6;
  --cat-2: #1baf7a;
  --cat-3: #eda100;
  --cat-5: #4a3aa7;
  --cat-6: #e34948;
  --cat-7: #e87ba4;
  --cat-8: #eb6834;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden; /* the page body NEVER scrolls horizontally (spec §11) */
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.ad-root { height: 100vh; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- Auth screen --- */
.auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
  width: 360px;
  max-width: 90vw;
}
.auth-card__title { margin: 0 0 16px; font-size: 20px; }
.auth-card__error { color: var(--critical); margin-bottom: 12px; }
.auth-card__form { display: flex; flex-direction: column; gap: 12px; }
.auth-card__form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.auth-card__input, .auth-card__submit {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.auth-card__submit { background: var(--accent); color: #fff; border: none; cursor: pointer; }
.auth-card__link { background: none; border: none; color: var(--accent); cursor: pointer; margin-top: 12px; padding: 0; font: inherit; }

/* --- Shell layout: rail + resize handle + stage (two-region, spec §2.1) --- */
.shell {
  display: flex;
  height: 100%;
  width: 100%;
}

.rail {
  width: 380px;
  min-width: 280px;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.rail__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.rail__title { font-weight: 600; flex: 1; }
.rail__theme-toggle, .rail__logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
  font: inherit;
}
.rail__thread-mount { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.rail-resize {
  width: 6px;
  cursor: col-resize;
  background: var(--rule);
  flex-shrink: 0;
}
.rail-resize:hover, .rail-resize:focus-visible { background: var(--accent); }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

/* --- Chat / thread / composer --- */
.thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.turn { max-width: 90%; padding: 8px 12px; border-radius: 8px; line-height: 1.4; }
.turn--user { align-self: flex-end; background: var(--accent); color: #fff; }
.turn--agent { align-self: flex-start; background: var(--surface-2); color: var(--text); }
.turn--system { align-self: center; color: var(--text-muted); font-size: 13px; }
.turn--error { color: var(--critical); }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.composer__input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.composer__send {
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
}

.inline-card {
  align-self: stretch;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.inline-card__title { font-weight: 600; text-transform: capitalize; margin-bottom: 6px; }
.inline-card__body { overflow-x: auto; margin: 0; white-space: pre-wrap; }
.inline-card--error { color: var(--critical); }
.inline-card__list { margin: 4px 0; padding-left: 20px; }
.inline-card__table { display: flex; flex-direction: column; gap: 4px; }
.inline-card__row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface);
}

/* --- Fleet-status strip --- */
.strip-mount { border-bottom: 1px solid var(--border); background: var(--surface); }
.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  align-items: center;
}
.strip-stale {
  flex-basis: 100%;
  color: var(--warning);
  font-weight: 600;
}

.stage-mount { flex: 1; overflow: auto; padding: 12px 16px; }

/* --- Map --- */
.map-wrap { display: flex; flex-direction: column; gap: 8px; }
.fleet-map { width: 100%; height: auto; max-height: 70vh; }
.map-plane { fill: var(--surface-2); }
.map-gridline { stroke: var(--gridline); stroke-width: 1; }
.map-lane { stroke-width: 2; fill: none; }
.map-lane--loaded { stroke: var(--text-secondary); }
.map-lane--deadhead {
  stroke: var(--text-muted);
  stroke-dasharray: 6 4;
}
.map-lane--pulse { stroke: var(--accent); stroke-width: 3; }
/* Categorical truck-identity hue (UX §6.2/§7.1): applied ONLY to a focused
   (<=8) truck's lane(s), direct-labeled via the map-truck's own aria-label;
   fixed slot order, never cycled. Placed after the loaded/deadhead rules so
   the cascade lets the identity hue win over the neutral encoding. */
.map-lane--cat-1 { stroke: var(--cat-1); }
.map-lane--cat-2 { stroke: var(--cat-2); }
.map-lane--cat-3 { stroke: var(--cat-3); }
.map-lane--cat-4 { stroke: var(--cat-4); }
.map-lane--cat-5 { stroke: var(--cat-5); }
.map-lane--cat-6 { stroke: var(--cat-6); }
.map-lane--cat-7 { stroke: var(--cat-7); }
.map-lane--cat-8 { stroke: var(--cat-8); }
.map-pin--pickup { fill: var(--good); }
.map-pin--dropoff { fill: var(--accent); }
.map-truck { cursor: pointer; }
.map-truck--good .map-truck-glyph { fill: var(--good); }
.map-truck--warning .map-truck-glyph { fill: var(--warning); }
.map-truck--critical .map-truck-glyph { fill: var(--critical); }
.map-truck--muted .map-truck-glyph { fill: var(--text-muted); }
.map-truck--dimmed { opacity: 0.25; }
.map-truck-label { fill: var(--text); font-size: 10px; }
.map-unlocated-tray {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.map-unlocated-tray__title { font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.map-unlocated-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 0;
  font: inherit;
}
.map-unlocated-item--critical { color: var(--critical); }
.map-unlocated-item--warning { color: var(--warning); }

.faded { opacity: 0.2; }
.annotate--highlight, .annotate--circle { outline: 2px solid var(--accent); }
.annotate--pulse { outline: 2px solid var(--warning); }
.annotate--callout { outline: 2px dashed var(--accent); }
.annotate--strike { text-decoration: line-through; }

/* --- Tree --- */
.tree-root { display: flex; flex-direction: column; gap: 12px; }
.tree-header { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.tree-header__hero { font-size: 18px; }
.tree-spine {
  display: flex;
  gap: 24px;
  overflow-x: auto; /* wide blocks scroll in their own container, not the page */
  padding-bottom: 8px;
}
.tree-column { display: flex; flex-direction: column; gap: 8px; min-width: 240px; }
.tree-fan { display: flex; flex-direction: column; gap: 6px; padding-left: 16px; border-left: 2px dashed var(--baseline); }
.tree-fan__more { color: var(--text-muted); font-size: 12px; }
.tree-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.tree-node--backup { background: var(--surface-2); border-style: dashed; }
.tree-node--greyed { opacity: 0.35; }
.tree-node--chain-broken { border-color: var(--critical); }
.tree-node__header { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.tree-node__lane { margin: 4px 0; }
.tree-node__meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.tree-empty { padding: 16px; color: var(--serious); font-weight: 600; }
.node-detail { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.node-detail__section { margin-bottom: 8px; }
.node-detail__section h4 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; color: var(--text-muted); }

.fleet-overview, .loads-overview { display: flex; flex-direction: column; gap: 4px; }
.fleet-overview__row, .loads-overview__row {
  display: flex;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface);
}

.canvas-split { display: flex; gap: 16px; }
.canvas-split__pane { flex: 1; min-width: 0; overflow-x: auto; }

.canvas-note { color: var(--text-muted); padding: 24px; text-align: center; }

/* --- Chips --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
}
.chip--good { color: var(--good); }
.chip--warning { color: var(--warning); }
.chip--serious { color: var(--serious); }
.chip--critical { color: var(--critical); }
.chip--muted { color: var(--text-muted); }
.chip--accent { color: var(--accent); }

.tabular { font-variant-numeric: tabular-nums; }
.text-muted { color: var(--text-muted); }
