/* WOBD theme: every color is taken from Bob's illustration. */
:root {
  --navy: #1F3F8F;          /* jumpsuit */
  --navy-dark: #152B63;     /* jumpsuit shadows */
  --bg: #F4F5F7;            /* cap panel, T-shirt */
  --rag-red: #D32F2F;       /* logo and active tab only */
  --silver: #B0B6BE;        /* wrench */
  --leather: #6B4423;       /* belt and boots */

  --surface: #FFFFFF;
  --text: #1B1F27;
  --muted: #5A6270;
  --row-stripe: #F0F2F5;
  --focus: #F2B705;

  /* Urgency keeps its own colors because they carry meaning. */
  --low: #2E7D32;
  --low-bg: #E7F4E8;
  --medium: #8A6100;
  --medium-border: #E0A800;
  --medium-bg: #FFF6D6;
  --high: #C62828;
  --high-bg: #FDECEC;
  --unknown: #5A6270;
  --unknown-bg: #EEF0F3;

  /* Roles, so dark mode only has to swap values. */
  --link: var(--navy);
  --link-hover: var(--navy-dark);
  --heading: var(--navy-dark);
  --primary: var(--navy);
  --primary-hover: var(--navy-dark);
  --header-bg: var(--navy);
  --line: var(--silver);
  --hover-bg: #E9EDF7;
  --selected-bg: #E3E9F6;
  --info-bg: #E3E9F6;
  --field-bg: #FFFFFF;
  --field-border: var(--navy-dark);

  --radius: 10px;
  --shadow: 0 1px 2px rgb(21 43 99 / 8%), 0 4px 16px rgb(21 43 99 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Dark mode: the same Bob palette, dimmed for night-time garages. */
:root[data-theme="dark"] {
  --bg: #0E1320;
  --surface: #171E2E;
  --text: #E4E8F0;
  --muted: #A2AABA;
  --row-stripe: #1C2436;
  --leather: #8C5E36;

  --link: #9DB8FF;
  --link-hover: #C4D4FF;
  --heading: #D2DDFA;
  --primary: #2F5BC8;
  --primary-hover: #3C6BE0;
  --header-bg: #152B63;
  --line: #354057;
  --hover-bg: #212C45;
  --selected-bg: #22304F;
  --info-bg: #18233D;
  --field-bg: #0E1320;
  --field-border: #3C4A6B;

  --low: #7BD389;
  --low-bg: #16301E;
  --medium: #F2C94C;
  --medium-border: #C99A00;
  --medium-bg: #332A0C;
  --high: #FF8A80;
  --high-bg: #3A1818;
  --unknown: #B7BECB;
  --unknown-bg: #242B3A;

  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); }
a:hover { color: var(--link-hover); }

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

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.45rem 1.15rem;
  border: 2px solid var(--link);
  background: var(--surface);
  color: var(--link);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--link-hover); color: var(--link-hover); background: var(--hover-bg); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }

.btn-light { background: #fff; color: var(--navy); border-color: #fff; }
.btn-light:hover:not(:disabled) { background: #E9EDF7; border-color: #E9EDF7; }

/* Fixed red: in dark mode --high is a light text color, too pale behind white text. */
.btn-danger { background: #C62828; border-color: #C62828; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #A51F1F; border-color: #A51F1F; color: #fff; }

.link-button {
  font: inherit;
  background: none;
  border: 0;
  padding: 0.25rem;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Header ---------- */

.site-header {
  background: var(--header-bg);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1.25rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}
.logo:hover { color: #fff; }
.logo-mark {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  background: var(--rag-red);
  transform: rotate(45deg);
}

.car-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
}
.car-form select,
.car-form input {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text);
  min-width: 0;
}
#car-year { width: 6rem; }
#car-make { width: 9.5rem; }
#car-make-other { width: 8rem; }
#car-model { flex: 1 1 8rem; max-width: 14rem; }


.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}
.header-link { color: #fff; font-size: 0.95rem; }
.header-link:hover { color: #E9EDF7; }

.demo-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--navy-dark);
  border: 1px solid var(--silver);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}

.theme-btn {
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 1.5px solid rgb(255 255 255 / 55%);
  background: none;
  color: #fff;
  cursor: pointer;
}
.theme-btn:hover { background: rgb(255 255 255 / 12%); }
.theme-btn svg { width: 1.15rem; height: 1.15rem; }
.theme-btn .icon-sun { display: none; }
.theme-btn[aria-pressed="true"] .icon-sun { display: inline; }
.theme-btn[aria-pressed="true"] .icon-moon { display: none; }

/* ---------- Development banner ---------- */

/* Neutral colors on purpose: yellow and red are reserved for urgency. */
.dev-banner {
  background: var(--info-bg);
  color: var(--heading);
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 1.25rem;
  text-align: center;
  font-size: 0.93rem;
}

/* Shown when this browser can't use Web Serial. Caution colors, like the live data note. */
.browser-alert {
  background: var(--medium-bg);
  border-bottom: 3px solid var(--medium-border);
  color: var(--text);
  padding: 0.7rem 1.25rem;
  text-align: center;
}
.browser-alert p { margin: 0; }

/* ---------- Main layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5rem 1.25rem 1.25rem;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}
.tab {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 0.75rem 0 0.5rem;
  margin-bottom: -1px;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--link); }
.tab[aria-selected="true"] { color: var(--link); border-bottom-color: var(--rag-red); }

.tab-panel { display: flex; flex-direction: column; flex: 1; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.status { margin: 0; color: var(--muted); font-size: 0.95rem; }
.status::before {
  content: "";
  display: inline-block;
  width: 0.6rem; height: 0.6rem;
  border-radius: 50%;
  background: var(--silver);
  margin-right: 0.45rem;
  vertical-align: 0.05rem;
}
.status[data-state="connected"]::before { background: var(--low); }
.status[data-state="busy"]::before { background: var(--medium-border); }

.scan-summary {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--row-stripe);
  font-size: 0.95rem;
}

/* ---------- Codes table ---------- */

.codes-table { width: 100%; border-collapse: collapse; }
.codes-table th {
  text-align: left;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.codes-table td { padding: 0.6rem 0.75rem; vertical-align: middle; }
.codes-table tbody tr:nth-child(even) td { background: var(--row-stripe); }
.codes-table tbody tr.selected td { background: var(--selected-bg); }
.codes-table tbody tr.selected td:first-child { box-shadow: inset 4px 0 0 var(--primary); }
.codes-table .col-urgency { width: 7.5rem; }

.code-link {
  font: inherit;
  font-weight: 700;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  background: none;
  border: 0;
  padding: 0;
  color: var(--link);
  text-decoration: underline;
  cursor: pointer;
}
.code-link:hover { color: var(--link-hover); }

.empty { color: var(--muted); margin: 1.5rem 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.75rem 0 0; }

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1.5rem;
}

/* ---------- Urgency badges ---------- */

.badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  border: 1.5px solid currentColor;
  white-space: nowrap;
}
.badge[data-level="low"] { color: var(--low); background: var(--low-bg); }
.badge[data-level="medium"] { color: var(--medium); background: var(--medium-bg); border-color: var(--medium-border); }
.badge[data-level="high"] { color: var(--high); background: var(--high-bg); }
.badge[data-level="unknown"] { color: var(--unknown); background: var(--unknown-bg); }

/* ---------- Welcome card ---------- */

.welcome {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  padding: 1rem 0 0.5rem;
}
.welcome h2 { margin: 0 0 0.4rem; font-size: 1.2rem; color: var(--heading); }
.welcome p { margin: 0 0 0.6rem; }
.welcome-art { flex: 0 0 150px; color: var(--link); }
.welcome-art svg { width: 100%; height: auto; display: block; }

.demo-list {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.demo-list a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.6rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
}
.demo-list a:hover { background: var(--hover-bg); border-color: var(--link); }
.demo-list a[aria-current="page"] { border-color: var(--primary); box-shadow: inset 4px 0 0 var(--primary); }
.demo-list small { font-weight: 400; color: var(--muted); font-size: 0.85rem; }

/* ---------- Live data ---------- */

.safety-note {
  margin: 0 0 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--medium-bg);
  border-left: 4px solid var(--medium-border);
  font-size: 0.95rem;
}

.gauges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.9rem;
}
.gauge {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
}
.gauge-label { margin: 0; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.gauge-value {
  margin: 0.2rem 0 0.5rem;
  font-size: 1.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--heading);
}
.gauge-unit { font-size: 0.95rem; font-weight: 600; color: var(--muted); margin-left: 0.2rem; }
.gauge-track { height: 6px; border-radius: 3px; background: var(--row-stripe); overflow: hidden; }
.gauge-fill { height: 100%; width: 0; background: var(--primary); transition: width 0.3s ease-out; }
.gauge[data-state="unsupported"] .gauge-value { font-size: 1rem; color: var(--muted); font-weight: 500; }

/* ---------- Bob panel ---------- */

.bob-panel {
  background: var(--surface);
  border: 2px solid var(--leather);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 1rem;
  overflow: hidden;
}

.bubble-slot { width: 100%; min-height: 3rem; display: flex; align-items: flex-end; }

.bubble {
  --tone: var(--link);
  position: relative;
  width: 100%;
  margin-bottom: 14px;
  background: var(--surface);
  border: 2px solid var(--tone);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  font-size: 0.93rem;
  cursor: default;
  transform-origin: 50% calc(100% + 12px);  /* grows out of the tail */
}
.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 16px;
  height: 16px;
  background: var(--surface);
  border-right: 2px solid var(--tone);
  border-bottom: 2px solid var(--tone);
  transform: translateX(-50%) rotate(45deg);
}
.bubble[data-tone="low"] { --tone: var(--low); }
.bubble[data-tone="medium"] { --tone: var(--medium-border); }
.bubble[data-tone="high"] { --tone: var(--high); }
.bubble[data-tone="unknown"] { --tone: var(--silver); }

.bubble-mood {
  position: absolute;
  top: -0.7rem;
  right: -0.5rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #fff;
  background: var(--tone);
  border: 2px solid var(--surface);
}

.bubble h3 { margin: 0 1rem 0.3rem 0; font-size: 1rem; line-height: 1.3; }
.bubble h3 .code { font-family: ui-monospace, Menlo, monospace; color: var(--link); }
.bubble p { margin: 0 0 0.5rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h4 { margin: 0.6rem 0 0.2rem; font-size: 0.85rem; color: var(--muted); }
.bubble ul { margin: 0 0 0.4rem; padding-left: 1.1rem; }
.bubble .urgency-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.bubble .tell { font-style: italic; }
.bubble .typing::after { content: "▍"; color: var(--silver); }

.bob-figure {
  position: relative;
  width: min(100%, 240px);
  aspect-ratio: 640 / 720;   /* waist-up crop of the full-body art */
  overflow: hidden;
  flex-shrink: 0;
}
.bob-figure img {
  position: absolute;
  top: 0;
  left: -68.75%;
  width: 175.3%;
  max-width: none;
  height: auto;
}

.bob-name {
  margin: 0;
  padding: 0.35rem 0 0.6rem;
  font-weight: 700;
  color: var(--heading);
  width: 100%;
  text-align: center;
  border-top: 1px solid var(--line);
}

/* Name centered, voice toggle tucked to the right. */
.bob-name-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-top: 1px solid var(--line);
}
.bob-name-row .bob-name { grid-column: 2; border-top: 0; padding: 0.45rem 0.5rem 0.6rem; }

.voice-btn {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.6rem 0.15rem 0.45rem;
  cursor: pointer;
}
.voice-btn:hover { color: var(--link); border-color: var(--link); }
.voice-btn svg { width: 1.1rem; height: 1.1rem; }
.voice-btn .voice-on { display: none; }
.voice-btn[aria-pressed="true"] { color: #fff; background: var(--primary); border-color: var(--primary); }
.voice-btn[aria-pressed="true"] .voice-on { display: inline; }
.voice-btn[aria-pressed="true"] .voice-off { display: none; }

/* ---------- Speech bubble motion ---------- */

.bubble.pop-in { animation: bubble-in 200ms ease-out both; }
.bubble.fade-out { animation: bubble-out 120ms ease-in both; }
.badge.pulse { animation: badge-pulse 700ms ease-out 1; }

@keyframes bubble-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes bubble-out {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.96); }
}
@keyframes badge-pulse {
  0% { box-shadow: 0 0 0 0 rgb(198 40 40 / 55%); }
  100% { box-shadow: 0 0 0 10px rgb(198 40 40 / 0%); }
}

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

/* ---------- Dialog ---------- */

dialog {
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgb(0 0 0 / 25%);
  padding: 1.25rem;
  max-width: 460px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(21 43 99 / 45%); }
dialog h2 { margin: 0 0 0.5rem; font-size: 1.2rem; color: var(--heading); }
.dialog-bob { display: flex; gap: 0.9rem; align-items: flex-start; }
.dialog-bob .bob-figure { width: 84px; border-radius: 50%; background: var(--bg); }
.dialog-bob p { margin: 0 0 0.6rem; }
.check-row { display: flex; gap: 0.5rem; align-items: flex-start; margin: 0.75rem 0 0; font-weight: 600; }
.check-row input { margin-top: 0.3rem; width: 1.05rem; height: 1.05rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 1rem 1.25rem 1.5rem;
}
.site-footer p { margin: 0.2rem 0; }

/* The printable report is built on demand and only shown by print.css. */
.report { display: none; }

/* ---------- Guide page ---------- */

.guide {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}
.guide h1 { color: var(--heading); margin: 0 0 0.25rem; }
.guide .lede { color: var(--muted); margin: 0 0 1.5rem; }
.guide section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.guide h2 { margin: 0 0 0.5rem; font-size: 1.2rem; color: var(--link); }
.guide ol, .guide ul { padding-left: 1.3rem; }
.guide li { margin-bottom: 0.3rem; }
.guide figure { margin: 0.75rem 0 0; }
.guide figcaption { font-size: 0.85rem; color: var(--muted); }
.guide svg { width: 100%; height: auto; max-width: 480px; display: block; }

/* ---------- Narrow screens: Bob drops below the table ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 1rem; }
  .bob-panel { position: static; max-width: 420px; width: 100%; justify-self: center; }
  .header-right { margin-left: 0; }
  .panel { padding: 0.5rem 1rem 1rem; }
  .welcome { flex-direction: column; }
  .welcome-art { flex-basis: auto; width: 130px; }
}
