:root {
  --bg: #0b0e14;
  --bg-elev: #131826;
  --bg-elev2: #1b2233;
  --border: #283044;
  --text: #eef2fb;
  --text-dim: #9aa6bf;
  --accent: #ffb020;        /* amber — TX/oilfield warmth */
  --accent2: #4ea1ff;
  --high: #34d399;          /* green  */
  --med: #fbbf24;           /* amber  */
  --low: #f87171;           /* red    */
  --danger-bg: #3a1d1d;
  --warn-bg: #3a2f15;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}
button, input, a { font-family: inherit; }

.topbar {
  display: flex; align-items: baseline; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #10141f, #0b0e14);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: 0.3px; cursor: pointer; }
.brand .logo { color: var(--accent); margin-right: 4px; }
.brand .tx { color: var(--accent); }
.tagline { color: var(--text-dim); font-size: 13px; }
.install-btn { margin-left: auto; }

.disclaimer {
  background: var(--warn-bg);
  border-bottom: 1px solid #5a4a1e;
  color: #f3e6c0; font-size: 13.5px;
  padding: 9px 22px; text-align: center;
}
.disclaimer strong { color: #ffe9a8; }

/* PWA install + update flow (BUILDOUT P7-A8) */
.ios-install-hint {
  position: relative; background: var(--bg-elev2); border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 13.5px; padding: 10px 40px 10px 22px; text-align: center;
}
.ios-hint-dismiss {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-dim); font-size: 15px; cursor: pointer; padding: 4px;
}
.update-toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 950;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 14px;
  max-width: min(92vw, 420px);
}

/* LANDING */
.landing { display: flex; flex-direction: column; align-items: center; padding: 8vh 20px; }
.dropzone {
  width: min(680px, 92vw); padding: 56px 32px; text-align: center;
  background: var(--bg-elev); border: 2px dashed var(--border);
  border-radius: 20px; transition: border-color .15s, background .15s;
  cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); background: var(--bg-elev2); }
.drop-icon { font-size: 46px; color: var(--accent); }
.dropzone h1 { font-size: 26px; margin: 10px 0 6px; }
.muted { color: var(--text-dim); font-size: 14px; }
.link {
  background: none; border: none; color: var(--accent2);
  cursor: pointer; font-size: inherit; text-decoration: underline; padding: 0;
}

.error-box {
  margin-top: 22px; max-width: 680px; padding: 16px 18px;
  background: var(--danger-bg); border: 1px solid #6e2b2b;
  border-radius: var(--radius); color: #ffd9d9;
}

/* PROCESSING */
.processing { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 16vh 0; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* RESULT */
.result { padding: 0; }
.summary { padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.summary-top { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: baseline; }
.summary-top h2 { margin: 0; font-size: 19px; }
.summary-sub { color: var(--text-dim); font-size: 13.5px; }

/* Mileage-delta badge (BUILDOUT P1-08) — thresholds mirror
   backend/app/confidence/sanity.py MILEAGE_WARN_PCT/MILEAGE_SEVERE_PCT. */
.mileage-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 700; padding: 4px 10px;
  border-radius: 20px; white-space: nowrap;
}
.mileage-badge.high { background: rgba(52,211,153,.16); color: var(--high); }
.mileage-badge.med { background: rgba(251,191,36,.16); color: var(--med); }
.mileage-badge.low { background: rgba(248,113,113,.18); color: var(--low); }

.badges { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.badge {
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; min-width: 84px;
}
.badge .b-label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.badge .b-val { font-size: 20px; font-weight: 700; }

.banners { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.banner { padding: 10px 14px; border-radius: 10px; font-size: 14px; border: 1px solid; }
.banner.amber { background: var(--warn-bg); border-color: #5a4a1e; color: #f3e6c0; }
.banner.red { background: var(--danger-bg); border-color: #6e2b2b; color: #ffd9d9; }
.banner b { display: block; margin-bottom: 2px; }

.split { display: grid; grid-template-columns: 1.4fr 1fr; height: calc(100vh - 250px); min-height: 440px; }
.map-wrap { position: relative; height: 100%; }
.map { height: 100%; background: #0e1320; }

/* Persistent map legend (BUILDOUT P1-08) */
.map-legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500;
  background: rgba(19, 24, 38, .92); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  font-size: 12px; color: var(--text-dim);
  display: flex; flex-direction: column; gap: 5px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.legend-item { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.legend-swatch {
  display: inline-block; width: 16px; height: 3px; border-radius: 2px; flex-shrink: 0;
}
.legend-swatch.high { background: var(--high); }
.legend-swatch.med { background: var(--med); }
.legend-swatch.low { background: var(--low); }
.legend-swatch.gap {
  background: repeating-linear-gradient(90deg, #8a93a8 0 4px, transparent 4px 9px);
  height: 3px;
}
.steps-panel { border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.steps-head { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.conf-summary { font-size: 13.5px; color: var(--text-dim); margin-bottom: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 14px; cursor: pointer; font-size: 14px; text-decoration: none;
}
.btn.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 700; }
.btn.reset { margin-left: auto; }
.btn:hover { border-color: var(--accent2); }

.step-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.step {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 4px 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.step:hover, .step.active { background: var(--bg-elev); }
.step.active { box-shadow: inset 3px 0 0 var(--accent); }
.step .seq { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: 13px; }
.step .maneuver { font-size: 14.5px; }
.step .road { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.step .meta { text-align: right; white-space: nowrap; }
.step .mile { font-weight: 700; font-variant-numeric: tabular-nums; }
.step .time { color: var(--text-dim); font-size: 12px; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; margin-top: 4px;
}
.chip.high { background: rgba(52,211,153,.16); color: var(--high); }
.chip.med { background: rgba(251,191,36,.16); color: var(--med); }
.chip.low { background: rgba(248,113,113,.18); color: var(--low); }
.verify-hint { font-size: 12px; margin-top: 3px; }
.verify-hint.low { color: var(--low); }
.verify-hint.med { color: var(--med); }
.verify-hint .what-to-do { display: block; color: var(--text-dim); margin-top: 2px; }

/* EXPORT ACKNOWLEDGMENT MODAL (spec P1-02/P1-03) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 6, 10, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: min(560px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal-body { font-size: 14px; }
.modal-body .modal-lede { color: var(--text-dim); margin-bottom: 14px; }

.gate-banner { padding: 10px 14px; border-radius: 10px; font-size: 13.5px; border: 1px solid; margin-bottom: 12px; }
.gate-banner.red { background: var(--danger-bg); border-color: #6e2b2b; color: #ffd9d9; }
.gate-banner.amber { background: var(--warn-bg); border-color: #5a4a1e; color: #f3e6c0; }
.gate-banner b { display: block; margin-bottom: 2px; }

.gate-step-list { list-style: none; margin: 0 0 14px; padding: 0; max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.gate-step-list li { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.gate-step-list li:last-child { border-bottom: none; }
.gate-step-list .gs-seq { color: var(--low); font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; }
.gate-step-list .gs-cause { color: var(--text-dim); display: block; margin-top: 2px; }
.gate-empty { color: var(--text-dim); font-size: 13.5px; margin-bottom: 14px; }

.gate-check-row {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; margin-top: 10px; cursor: pointer;
}
.gate-check-row.override { border-color: #6e2b2b; background: var(--danger-bg); }
.gate-check-row input { margin-top: 3px; width: 16px; height: 16px; flex-shrink: 0; }
.gate-check-row span { font-size: 13.5px; line-height: 1.4; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal .btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.modal .spinner { margin: 20px auto; }

/* REPORT-A-PROBLEM MODAL (BUILDOUT P1-10) */
.field-label {
  display: block; font-size: 12.5px; color: var(--text-dim);
  margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .4px;
}
.field-select, .field-textarea {
  width: 100%; background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px;
  font-size: 14px; font-family: inherit;
}
.field-textarea { resize: vertical; min-height: 80px; }
.field-select:focus, .field-textarea:focus { outline: none; border-color: var(--accent2); }

.success-box {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: rgba(52,211,153,.14); border: 1px solid #1f6b4f; color: var(--high);
  font-size: 14px;
}

/* FOLLOW MODE (BUILDOUT P7-A4) -- full-screen cab view, not a modal. */
.follow-mode { position: fixed; inset: 0; z-index: 900; background: #000; }
.follow-map { position: absolute; inset: 0; }
.follow-hud {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  display: flex; flex-direction: column; padding: 16px;
  /* leave room for a phone's status bar / notch */
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.follow-top { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.follow-btn {
  background: rgba(19,24,38,.88); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 18px; font-size: 15px; font-weight: 600;
  cursor: pointer; min-height: 48px; min-width: 48px;
}
.follow-btn:disabled { opacity: .4; cursor: not-allowed; }
.follow-btn.active { background: var(--accent); color: #1a1205; border-color: var(--accent); }
.follow-speed {
  margin-left: auto; background: rgba(19,24,38,.88); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 16px; font-size: 18px; font-weight: 700;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.follow-offroute {
  margin-top: 12px; padding: 14px 16px; border-radius: 12px; font-weight: 700;
  font-size: 16px; text-align: center; pointer-events: none;
}
.follow-offroute.soft { background: rgba(251,191,36,.92); color: #1a1205; }
.follow-offroute.alarm { background: rgba(248,113,113,.95); color: #2a0a0a; }
.follow-spacer { flex: 1; }
.follow-maneuver-card {
  pointer-events: none; background: rgba(11,14,20,.92); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px 20px; text-align: center;
}
.follow-maneuver-card.verify-warning { border-color: var(--low); box-shadow: 0 0 0 2px rgba(248,113,113,.35); }
.follow-conf-badge {
  display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; padding: 3px 10px; border-radius: 20px; margin-bottom: 8px;
}
.follow-conf-badge.high { background: rgba(52,211,153,.18); color: var(--high); }
.follow-conf-badge.med { background: rgba(251,191,36,.18); color: var(--med); }
.follow-conf-badge.low { background: rgba(248,113,113,.2); color: var(--low); }
.follow-maneuver-text { font-size: 26px; font-weight: 700; line-height: 1.25; }
.follow-distance { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 6px; color: var(--accent); }
/* Text-only preview of the P7-A5 spoken form -- no speechSynthesis call
   anywhere; voice guidance itself (P7-A6) stays dark behind its own gate. */
.follow-speech-preview { margin-top: 10px; font-size: 13px; color: var(--text-dim); font-style: italic; }
.follow-speech-preview:not(:empty)::before { content: "🔊 "; font-style: normal; }
.follow-bottom { display: flex; gap: 12px; margin-top: 16px; pointer-events: auto; }
.follow-bottom .follow-btn:last-child { margin-left: auto; }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 50vh; }
  .map { height: 100%; }
  .steps-panel { border-left: none; border-top: 1px solid var(--border); }
  .badge .b-val { font-size: 18px; }
  .map-legend { font-size: 11px; padding: 7px 9px; }
  .update-toast { flex-direction: column; align-items: stretch; left: 12px; right: 12px; transform: none; max-width: none; }
  .update-toast .btn { width: 100%; }
}
