:root {
  --bg: #0a0a0a;
  --panel: #111416;
  --panel2: #181c20;
  --text: #e8eef4;
  --muted: #a0aec0; /* bumped for OLED AA-ish contrast */
  --cyan: #00f3ff;
  --magenta: #ff00aa;
  --accent: #00f3ff;
  --ok: #3d9a6a;
  --warn: #e8b84a;
  --danger: #ff4d6d;
  --border: #2a323c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --tap: 48px;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}
body {
  overflow-x: hidden;
  min-height: 100dvh;
  min-height: 100vh; /* fallback */
}
img, video, pre, table, canvas, svg {
  max-width: 100%;
}
img, video {
  height: auto;
}
a { color: var(--cyan); }
a:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding:
    calc(1rem + var(--safe-top))
    calc(1rem + var(--safe-right))
    calc(5.5rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.75rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border); padding-bottom: 0.75rem; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.02em; font-size: 1.05rem; }
.brand span { color: var(--magenta); font-weight: 500; font-size: 0.8rem; margin-left: 0.4rem; }
.brand a { color: inherit; text-decoration: none; }
.badge {
  background: var(--panel2); border: 1px solid var(--border);
  color: var(--warn); font-size: 0.72rem; padding: 0.25rem 0.55rem;
  border-radius: 4px; white-space: nowrap; font-weight: 600; letter-spacing: 0.03em;
}
.badge.ok { color: var(--ok); border-color: #2a4a38; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.75rem; }
.chip {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 0.28rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel2); color: var(--muted);
}
.chip.draft { color: var(--warn); border-color: #5a4a20; }
.chip.safe { color: var(--cyan); border-color: #1a4a50; }
.hero { margin: 1.25rem 0 1.5rem; }
.hero h1 {
  font-size: clamp(1.35rem, 4.5vw, 2.1rem);
  margin: 0 0 0.75rem; line-height: 1.2; font-weight: 700;
}
.hero .lede {
  font-size: clamp(0.95rem, 2.5vw, 1.05rem);
  color: var(--muted);
  max-width: 42rem;
  margin: 0;
}
.prose, .legal-body p, .legal-body li, .hero .lede {
  max-width: 42rem;
}
.trust {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem; margin: 1.25rem 0;
}
.trust-item {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.85rem 1rem;
}
.trust-item strong { display: block; color: var(--cyan); font-size: 0.9rem; margin-bottom: 0.25rem; }
.trust-item span { font-size: 0.85rem; color: var(--muted); }
h1 { font-size: clamp(1.25rem, 4vw, 1.75rem); margin: 0.25rem 0 0.75rem; line-height: 1.25; }
h2 { font-size: clamp(1rem, 2.5vw, 1.15rem); margin: 1.1rem 0 0.5rem; color: var(--cyan); }
.section-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--magenta); font-weight: 700; margin: 0 0 0.5rem;
}
p, li { line-height: 1.55; color: var(--text); }
.muted { color: var(--muted); }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin: 0.75rem 0;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.65rem; }
.trade-pill {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem; text-align: center; font-size: 0.9rem;
  min-height: var(--tap); display: flex; align-items: center; justify-content: center;
}
button, .cta, .capture-btn, .modes button, .history-item {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.cta {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap);
  background: linear-gradient(135deg, var(--cyan), #00b8c4);
  color: #041018; text-decoration: none; font-weight: 700;
  padding: 0.75rem 1.25rem; border-radius: var(--radius); border: none; cursor: pointer;
  font-size: 1rem;
}
.cta:hover { filter: brightness(1.08); }
.cta.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.cta.magenta { background: linear-gradient(135deg, var(--magenta), #b01870); color: #fff; }
.cta:disabled, .cta.disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.65rem 0 0.3rem; font-weight: 600; }
/* iOS Safari: ≥16px prevents auto-zoom on focus */
select, textarea, input[type=text], input[type=password], input[type=search], input[type=email], input[type=tel], input[type=number] {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 0.85rem; font: inherit;
  font-size: 16px;
  min-height: var(--tap);
}
textarea { min-height: 120px; resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.modes { display: flex; gap: 0.5rem; margin: 0.65rem 0; flex-wrap: wrap; }
.modes button {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 0.65rem 1.1rem; border-radius: 999px; cursor: pointer;
  min-height: var(--tap); font-size: 1rem; font-weight: 600;
}
.modes button.active { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }
.out {
  white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.85rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.refuse { border-color: var(--danger); background: #1a0c10; }
.checklist { margin: 0.4rem 0; padding-left: 1.2rem; }
.checklist li { margin: 0.35rem 0; }
.footer {
  margin-top: 2rem; font-size: 0.8rem; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 0.75rem;
}
.footer nav { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; margin-bottom: 0.5rem; }
.footer nav a { color: var(--muted); text-decoration: none; }
.footer nav a:hover { color: var(--cyan); }
.parts-fields { display: none; }
.parts-fields.show { display: block; }
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
}
.table-scroll::after {
  content: "← scroll →";
  display: block;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.25rem;
  border-top: 1px solid var(--border);
  background: var(--panel2);
}
@media (min-width: 561px) {
  .table-scroll::after { display: none; }
}
table.cart { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 420px; }
table.cart th, table.cart td { border: 1px solid var(--border); padding: 0.55rem 0.5rem; text-align: left; }
table.cart th { background: var(--panel2); color: var(--muted); font-weight: 600; }
.job-id { font-family: var(--mono); color: var(--magenta); font-size: 0.9rem; }
.sticky-run {
  position: sticky; bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 28%);
  padding: 0.75rem 0 calc(0.5rem + env(safe-area-inset-bottom, 0px));
  margin-top: 0.5rem; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 0.5rem;
}
/* Keep sticky visible in standalone / display-mode PWA */
@media (display-mode: standalone), (display-mode: fullscreen) {
  .sticky-run {
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
  }
  .wrap {
    padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
  }
}
.sticky-run .cta { flex: 1 1 140px; }
.history-item {
  display: block; width: 100%; text-align: left;
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.75rem; margin: 0.4rem 0; cursor: pointer;
  min-height: var(--tap); font: inherit;
}
.history-item:hover { border-color: var(--cyan); }
.shop-key-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.shop-key-row > div { flex: 1 1 180px; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.legal-body { max-width: 720px; }
.legal-body h1 { color: var(--text); }
.legal-draft {
  background: #1a1608; border: 1px solid #5a4a20; color: var(--warn);
  padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.9rem; margin: 1rem 0;
}
.cta-row { margin: 1.25rem 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.feature-fallback {
  font-size: 0.85rem;
  color: var(--warn);
  background: #1a1608;
  border: 1px solid #5a4a20;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  margin: 0.5rem 0;
}
.feature-fallback:empty { display: none; }

.supplier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.supplier-cat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.supplier-cat h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  color: var(--cyan);
}
.supplier-cat .checklist { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; }

/* Field van / one-thumb — plate capture + order path */
.coach {
  font-size: clamp(0.95rem, 2.8vw, 1.05rem);
  font-weight: 600;
  color: var(--cyan);
  margin: 0 0 0.5rem;
  line-height: 1.35;
}
.short-lede { margin: 0 0 0.5rem; font-size: 0.95rem; max-width: 42rem; }
.modes-large { gap: 0.65rem; }
.modes-large button {
  flex: 1 1 140px;
  min-height: 56px;
  font-size: 1.1rem;
  border-radius: 12px;
}
.modes-large button.mode-parts.active {
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.18), rgba(0, 184, 196, 0.08));
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 0 2px var(--cyan);
}
.shop-settings summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  list-style: none;
  touch-action: manipulation;
}
.shop-settings summary::-webkit-details-marker { display: none; }
.shop-settings summary::before {
  content: "▸ ";
  color: var(--magenta);
  margin-right: 0.25rem;
}
.shop-settings[open] summary::before { content: "▾ "; }
.shop-settings[open] summary { margin-bottom: 0.65rem; color: var(--text); }
.privacy-note {
  font-size: 0.85rem;
  color: var(--warn);
  background: #1a1608;
  border: 1px solid #5a4a20;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  margin: 0.35rem 0 0.75rem;
}
.plate-capture { margin-top: 0.85rem; }
.capture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.capture-btn {
  flex: 1 1 140px;
  cursor: pointer;
  text-align: center;
  min-height: var(--tap);
}
.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.thumb {
  margin: 0;
  width: 96px;
  max-width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.thumb img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
}
.thumb figcaption {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  padding: 0.25rem;
}
.live-camera {
  margin: 0.5rem 0 0.75rem;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.live-camera video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(280px, 50dvh);
  object-fit: cover;
  background: #000;
}
.live-camera-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--panel);
}
.ocr-panel { margin-top: 0.5rem; }
.cta-supplier {
  flex: 1 1 100%;
  min-height: 56px;
  font-size: 1.15rem;
  box-shadow: 0 0 0 2px rgba(0, 243, 255, 0.35);
}
.actions-order { gap: 0.65rem; }
.next-step {
  margin: 0.5rem 0 0.25rem;
  font-size: 1rem;
  color: var(--text);
}
.parts-fields.show { display: block; }

/* Desk layout: single column by default; two-col job | result when wide */
.desk-layout {
  display: block;
}
@media (min-width: 900px) {
  .desk-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
  }
  .desk-layout > .shop-settings {
    grid-column: 1 / -1;
  }
  .desk-layout > .card-job {
    grid-column: 1;
  }
  .desk-layout > #refusePanel,
  .desk-layout > #result {
    grid-column: 2;
  }
  .desk-layout > #buyAnywhereCard,
  .desk-layout > #historyCard {
    grid-column: 1 / -1;
  }
  .wrap { max-width: 1100px; }
}

/* Narrow phones / large phones */
@media (max-width: 560px) {
  .wrap {
    padding:
      calc(0.75rem + var(--safe-top))
      calc(0.75rem + var(--safe-right))
      calc(6rem + var(--safe-bottom))
      calc(0.75rem + var(--safe-left));
  }
  .topbar { align-items: flex-start; }
  table.cart { font-size: 0.78rem; }
  /* Card-stack cart on narrow */
  table.cart.card-stack,
  .table-scroll.card-stack table.cart {
    min-width: 0;
    border: 0;
  }
  .table-scroll.card-stack {
    border: 0;
    overflow: visible;
  }
  .table-scroll.card-stack::after { display: none; }
  table.cart.card-stack thead { display: none; }
  table.cart.card-stack,
  table.cart.card-stack tbody,
  table.cart.card-stack tr,
  table.cart.card-stack td {
    display: block;
    width: 100%;
  }
  table.cart.card-stack tr {
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.65rem;
  }
  table.cart.card-stack td {
    border: 0;
    padding: 0.2rem 0;
  }
  table.cart.card-stack td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
  }
  .modes-large button { font-size: 1rem; min-height: 52px; }
  .trust { grid-template-columns: 1fr; }
}

/* Very small phones */
@media (max-width: 380px) {
  .hero h1 { font-size: clamp(1.15rem, 6vw, 1.45rem); }
  .hero { margin: 0.85rem 0 1rem; }
  .brand { font-size: 0.95rem; }
  .badge { font-size: 0.65rem; white-space: normal; }
  .capture-actions .capture-btn,
  .capture-actions .cta,
  .capture-actions label.cta {
    flex: 1 1 100%;
    width: 100%;
  }
  .modes-large button {
    flex: 1 1 100%;
    font-size: 0.95rem;
    min-height: 48px;
  }
  .sticky-run .cta { flex: 1 1 100%; }
  .cta-row .cta { flex: 1 1 100%; }
  .thumb { width: calc(50% - 0.25rem); }
  .card { padding: 0.75rem; }
  .wrap {
    padding-left: calc(0.55rem + var(--safe-left));
    padding-right: calc(0.55rem + var(--safe-right));
  }
}

/* Landscape phones — keep sticky usable, tighten chrome */
@media (max-height: 500px) and (orientation: landscape) {
  .wrap {
    padding-top: calc(0.45rem + var(--safe-top));
    padding-bottom: calc(4.25rem + var(--safe-bottom));
  }
  .hero { margin: 0.5rem 0 0.75rem; }
  .hero h1 { font-size: 1.2rem; margin-bottom: 0.4rem; }
  .card { padding: 0.65rem; margin: 0.45rem 0; }
  .sticky-run {
    padding-top: 0.4rem;
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0px));
  }
  .sticky-run .cta { min-height: 44px; padding: 0.5rem 0.85rem; }
  .modes-large button { min-height: 44px; font-size: 0.95rem; }
  .live-camera video { max-height: 140px; }
  .topbar { margin-bottom: 0.5rem; padding-bottom: 0.4rem; }
  textarea { min-height: 72px; }
  .coach { font-size: 0.9rem; }
}

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

/* Focus / hover: never rely on hover alone — borders already visible */
@media (hover: none) {
  .cta:hover { filter: none; }
  .history-item:hover { border-color: var(--border); }
  .footer nav a:hover { color: var(--muted); }
}
