/* ==========================================================================
   GuzziOnBoard — Motorcycle ECU Tuning & Diagnostic Suite
   Modeled after TunerStudio MS / TunerPro RT / Haltech NSP desktop IDEs:
   - Locked-viewport 4-row desktop shell (Menubar, Telemetry Ribbon,
     Docked Explorer + Multi-Column Workbench, Status Bar)
   - Flush inset pane title bars, machined 5px corners, tabular readouts
   - High-contrast Dark (Gunmetal) & Light (Daylight Shop) palettes
   ========================================================================== */

:root {
  --bg: #0b0f14;
  --bg-2: #111720;
  --panel: #151d28;
  --panel-2: #1c2635;
  --panel-3: #233042;
  --line: #2a3648;
  --line-strong: #394960;
  --text: #e5edf5;
  --muted: #8b9bb0;
  --accent: #20c997;
  --accent-dim: #124d3b;
  --cyan: #38bdf8;
  --danger: #ef5350;
  --warn: #f59e0b;
  --ok: #22c55e;
  --radius: 5px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.hidden { display: none !important; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 13.5px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   1. DESKTOP IDE SHELL (4-Row Locked Viewport on > 960px)
   ========================================================================== */
@media screen and (min-width: 961px) {
  html, body {
    height: 100vh;
    overflow: hidden;
  }
  body {
    display: grid;
    grid-template-columns: 234px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "menubar menubar"
      "ribbon  ribbon"
      "sidebar main"
      "status  status";
  }
  body.explorer-collapsed {
    grid-template-columns: 0px minmax(0, 1fr);
  }
  body.explorer-collapsed .sidebar {
    display: none;
  }
  .app-menubar { grid-area: menubar; }
  .command-ribbon { grid-area: ribbon; }
  .sidebar {
    grid-area: sidebar;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
  main {
    grid-area: main;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .status-bar { grid-area: status; }
}

@media screen and (max-width: 960px) {
  html, body {
    max-width: 100vw;
    overflow-x: clip;
  }
  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
  }
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--mono); }
code {
  font-size: .82em;
  background: rgba(139, 155, 176, .12);
  padding: 1px 4px;
  border-radius: 3px;
}
pre code { background: none; padding: 0; }

/* ==========================================================================
   2. ROW 1 — TOP APPLICATION MENU BAR (#appMenubar)
   ========================================================================== */
.app-menubar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 3px 10px;
  background: #090d12;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 60;
  min-width: 0;
  max-width: 100%;
  user-select: none;
}

.menubar-left,
.menubar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-width: 0;
  max-width: 100%;
}

.menubar-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 8px 2px 2px;
  margin-right: 4px;
  border-right: 1px solid var(--line);
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--accent);
  color: #062118;
  font: 800 .72rem/1 var(--mono);
  display: inline-grid;
  place-items: center;
  letter-spacing: -.03em;
  flex: none;
}
.menubar-app-name {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
}
.menubar-app-name b {
  color: var(--accent);
  font-weight: 700;
}

.menu-dropdown { position: relative; }
.menubar-btn {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 8px;
  font: inherit;
  font-size: .79rem;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.menubar-btn:hover,
.menubar-btn[aria-expanded="true"] {
  background: var(--panel-2);
  border-color: var(--line);
}
.menu-caret { font-size: .68rem; opacity: .7; }

.menubar-chip {
  appearance: none;
  background: var(--bg-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 8px;
  font: 600 .7rem/1.3 var(--mono);
  cursor: pointer;
  max-width: min(320px, calc(100vw - 40px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menubar-chip:hover { color: var(--text); border-color: var(--accent); }

.menubar-link {
  font: 600 .72rem/1.3 var(--sans);
  color: var(--muted);
  padding: 3px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.menubar-link:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
  text-decoration: none;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 256px;
  max-width: min(336px, calc(100vw - 24px));
  max-height: min(78vh, 560px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, .58);
  z-index: 120;
}
.quick-settings-panel { min-width: min(308px, calc(100vw - 24px)); padding: 7px 9px; }

.menu-section-title {
  padding: 5px 8px 3px;
  font: 700 .62rem/1.2 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.menu-item {
  width: 100%;
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 4px;
  padding: 6px 9px;
  font: inherit;
  font-size: .8rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.menu-item:hover:not(:disabled),
.menu-item:focus-visible { background: var(--panel-2); }
.menu-item:focus-visible {
  /* A keyboard user has to be able to see where they are: background alone
     is not a focus indicator on a menu that is already highlighted. */
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.menu-item kbd {
  font: 600 .65rem/1 var(--mono);
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 5px;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.menu-item.primary { font-weight: 600; color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: rgba(239, 83, 80, .14); }

/* Quick settings popover */
.qs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 3px;
  flex-wrap: wrap;
}
.qs-label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.qs-seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px;
  gap: 2px;
}
.qs-seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .74rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
}
.qs-seg-btn.active { background: var(--accent); color: #062118; }
.qs-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 7px;
  font: inherit;
  font-size: .78rem;
  max-width: 100%;
}
.qs-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px;
  font-size: .74rem;
  color: var(--muted);
}

/* ==========================================================================
   3. ROW 2 — TUNERSTUDIO / HALTECH TELEMETRY & PERSPECTIVE RIBBON
   ========================================================================== */
.command-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 5px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
  z-index: 35;
}

.ribbon-perspectives {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-width: 0;
}
.persp-tab {
  appearance: none;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 9px;
  font: 600 .75rem/1.2 var(--sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: border-color .12s, color .12s, background .12s;
}
.persp-tab:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--panel-2);
}
.persp-tab.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.persp-num {
  font: 700 .64rem/1 var(--mono);
  color: var(--accent);
  opacity: .9;
}

.ribbon-telemetry {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  background: #080b0f;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 4px;
  min-width: 0;
}
.tele-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 2px 8px;
  border-right: 1px solid #1b2430;
}
.tele-cell:last-child { border-right: 0; }
.tele-lbl {
  font: 700 .61rem/1 var(--mono);
  color: var(--muted);
  letter-spacing: .06em;
}
.tele-val {
  font: 700 .78rem/1.1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 4ch;
  text-align: right;
}
.ribbon-telemetry.offline .tele-val { color: #556577; }

.ribbon-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.ribbon-poll-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.poll-glyph {
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 4px 0 4px 7px;
  border-color: transparent transparent transparent currentColor;
}
.ribbon-poll-btn.polling {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.ribbon-poll-btn.polling .poll-glyph {
  width: 7px;
  height: 7px;
  border: 0;
  border-radius: 1px;
  background: currentColor;
}

.unit-pick {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: .72rem;
  color: var(--muted);
}
.unit-pick select {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 1px 2px;
  font: 600 .74rem/1.2 var(--mono);
  cursor: pointer;
}
.unit-pick select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 2px;
}

/* ==========================================================================
   4. ROW 3 LEFT — DOCKED EXPLORER & XDF PARAMETER TREE (.sidebar)
   ========================================================================== */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.sidebar > .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 7px;
  border-bottom: 1px solid var(--line);
}
.sidebar > .brand .brand-mark {
  width: 24px;
  height: 24px;
  font-size: .72rem;
}
.brand-copy { min-width: 0; }
.brand strong { display: block; font-size: .82rem; letter-spacing: -.01em; line-height: 1.15; }
.brand strong span { color: var(--accent); }
.brand small {
  display: block;
  color: var(--muted);
  font: 500 .66rem/1.2 var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-filter input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font: 500 .76rem/1.2 var(--sans);
}
.explorer-filter input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* TunerPro RT-style Active XDF Calibration Tree */
.xdf-tree-dock {
  background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  border-radius: 4px;
  padding: 6px;
}
.xdf-tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.xdf-tree-count {
  font: 700 .64rem/1 var(--mono);
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 5px;
  border-radius: 3px;
}
.xdf-tree-title {
  font: 600 .72rem/1.25 var(--sans);
  color: var(--text);
  margin-bottom: 5px;
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.xdf-tree-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 185px;
  overflow-y: auto;
}
.xdf-tree-item {
  appearance: none;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 2px solid var(--line);
  padding: 3px 6px;
  color: var(--muted);
  font: 500 .72rem/1.25 var(--sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-radius: 0 3px 3px 0;
}
.xdf-tree-item:hover {
  background: var(--panel-2);
  color: var(--text);
  border-left-color: var(--accent);
}
.xdf-tree-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.xdf-tree-item em {
  font: 600 .63rem/1 var(--mono);
  color: var(--muted);
  flex: none;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-label {
  font: 700 .62rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 2px 6px 3px;
}
.nav {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font: 500 .8rem/1.25 var(--sans);
  text-align: left;
}
.nav i {
  font-style: normal;
  width: 15px;
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  flex: none;
}
.nav:hover {
  background: var(--panel);
  border-color: var(--line);
}
.nav.active {
  background: var(--panel-2);
  border-color: var(--line-strong);
  box-shadow: inset 3px 0 0 var(--accent);
  color: #ffffff;
  font-weight: 600;
}
.nav.active i { color: var(--accent); }

.badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font: 700 .65rem/1 var(--mono);
  padding: 2px 6px;
  border-radius: 3px;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.conn-card {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #556577;
  flex: none;
}
.conn-dot.on {
  background: var(--ok);
  box-shadow: 0 0 7px var(--ok);
}
.conn-card strong { display: block; font-size: .76rem; line-height: 1.2; }
.conn-card small { display: block; color: var(--muted); font-size: .68rem; line-height: 1.25; }

.desktop-row {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.desktop-row .nav-label { padding: 0; }
.desktop-row .toolbar { gap: 4px; }
.desktop-row code {
  font-size: .66rem;
  color: var(--muted);
  word-break: break-all;
  line-height: 1.25;
}

.disclaimer {
  font-size: .66rem;
  color: var(--muted);
  line-height: 1.35;
  margin: 0;
}

@media screen and (max-width: 960px) {
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
  }
  .xdf-tree-dock { display: none; }
  nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .nav-group {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
  }
  .nav-label { display: none; }
  .nav { padding: 4px 7px; font-size: .76rem; }
}

/* ==========================================================================
   5. ROW 3 RIGHT — MAIN WORKBENCH CANVAS (<main>) & CONTEXT BAR (.topbar)
   ========================================================================== */
main {
  padding: 10px 14px 20px;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 10px;
  margin-bottom: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1 1 280px;
}
.icon-btn {
  padding: 4px 8px !important;
  font-size: .84rem !important;
  line-height: 1;
}
@media screen and (max-width: 960px) {
  #toggleExplorerBtn { display: none; }
}
.topbar-titles { min-width: 0; }
.workspace-eyebrow,
.section-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 .63rem/1.1 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}
.workspace-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.topbar-heading-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 1px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.topbar-sep { color: var(--muted); font-size: .82rem; }
.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
}
.topbar-right {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  background: var(--accent-dim);
  color: #79f2c8;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 2px 8px;
  border-radius: 3px;
  font: 700 .68rem/1.3 var(--mono);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.pill.live { background: #4a1c19; border-color: var(--danger); color: #ffb4ab; }
.pill.ghost {
  background: var(--bg-2);
  border-color: var(--line);
  color: var(--muted);
  text-transform: none;
}

/* ==========================================================================
   6. ROW 4 — BOTTOM STATUS BAR (#workstationStatusBar)
   ========================================================================== */
.status-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 3px 12px;
  background: #080b0f;
  border-top: 1px solid var(--line);
  font: 600 .69rem/1.35 var(--mono);
  color: var(--muted);
  min-width: 0;
  max-width: 100%;
  user-select: none;
}
.status-seg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
}
.status-key { color: #5f7187; }
.status-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #556577;
  flex: none;
}
.status-led.on {
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
.status-spacer { flex: 1 1 auto; }
@media screen and (max-width: 720px) {
  .status-hide-narrow { display: none; }
}

/* ==========================================================================
   7. NOTICES, FLOW DIVIDERS & DOCKED INSTRUMENT PANELS (.panel)
   ========================================================================== */
#notices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.notice {
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: .8rem;
  border-left: 3px solid var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.notice.info { border-left-color: #4f9cf9; background: #101c2b; color: #c7dffb; }
.notice.warn { border-left-color: var(--warn); background: #221b0f; color: #f3ddb0; }
.notice.danger { border-left-color: var(--danger); background: #261313; color: #f9c2bc; }

.flow-intro,
.flow-divider {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
  padding: 5px 10px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
.flow-divider {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 6px 2px 5px;
  margin-top: 10px;
}
.flow-step {
  font: 700 .66rem/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Machined Docked Instrument Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  margin-bottom: 10px;
  min-width: 0;
}
.secondary-panel { background: var(--bg-2); }
.toolbar-panel { padding: 8px 11px; }

/* Flush Inset Panel Header Bar (TunerStudio / TunerPro / Haltech style) */
.panel > h2:first-child {
  margin: -11px -13px 10px;
  padding: 6px 13px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  font: 700 .75rem/1.35 var(--mono);
  text-transform: uppercase;
  letter-spacing: .055em;
  color: var(--text);
}
.panel h2 {
  margin: 0 0 8px;
  font-size: .88rem;
  font-weight: 700;
}
.panel h3 {
  margin: 10px 0 6px;
  font-size: .84rem;
  font-weight: 650;
}

.muted { color: var(--muted); }
.small { font-size: .76rem; line-height: 1.42; }
p { margin: 6px 0; }

/* Optional ultra-clean Compact Guidance Notes toggle */
body.compact-notes .panel > p.muted.small {
  font-size: .71rem;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body.compact-notes .panel > p.muted.small:hover {
  display: block;
}

/* Grids */
.grid-2,
.garage-lower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}
@media screen and (max-width: 980px) {
  .grid-2,
  .garage-lower-grid { grid-template-columns: 1fr; }
}

/* Multi-Column Tuning Workbenches for #tools and #firmware on Desktop */
@media screen and (min-width: 1120px) {
  #tools:not(.hidden):not(.tools-focus-mode) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
  }
  #tools:not(.hidden) > #toolsIntroPanel {
    grid-column: 1 / -1;
  }
  #tools:not(.hidden) > article.panel {
    margin-bottom: 0;
  }

  #firmware:not(.hidden) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: start;
  }
  #firmware:not(.hidden) > #firmwareIntroPanel,
  #firmware:not(.hidden) > #mapsCard,
  #firmware:not(.hidden) > #writePanel {
    grid-column: 1 / -1;
  }
  #firmware:not(.hidden) > article.panel {
    margin-bottom: 0;
  }
}

/* ==========================================================================
   8. CONTROLS, INPUTS, BUTTONS & FORMS
   ========================================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 9px;
  min-width: 0;
}
.field > span {
  font-size: .73rem;
  color: var(--muted);
  font-weight: 600;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font: inherit;
  font-size: .82rem;
  max-width: 100%;
  min-width: 0;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  /* The ring is the focus indicator; do not remove it without replacing it. */
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}
/* Keyboard focus is stronger still: a 2px ring, so a cell or a select is
   locatable in a dense grid without hunting for a 1px colour shift. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr));
  gap: 8px 10px;
  margin: 8px 0;
}
.form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr));
  gap: 7px 9px;
}
.form-grid > label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: .73rem;
  color: var(--muted);
  min-width: 0;
}

.btn {
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 5px 11px;
  font: 600 .8rem/1.25 var(--sans);
  cursor: pointer;
  transition: background .12s, border-color .12s;
  max-width: 100%;
}
.btn:hover:not(:disabled) {
  background: var(--panel-3);
  border-color: var(--accent);
}
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #052017;
  font-weight: 700;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger {
  background: #3a1919;
  border-color: #7c302e;
  color: #ffc2bc;
}
.btn.danger:hover:not(:disabled) { background: #4d2020; border-color: var(--danger); }
.btn.block { width: 100%; padding: 7px 12px; }
.btn.small { padding: 4px 8px; font-size: .75rem; }

.toolbar {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}
.toolbar + .toolbar { margin-top: 7px; }
.toolbar .grow { flex: 1 1 200px; min-width: 0; }
.spacer { flex: 1; }
.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
  min-width: 0;
  max-width: 100%;
}
.check {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  font-size: .8rem;
  cursor: pointer;
  margin: 5px 0;
}

details.advanced {
  margin: 8px 0;
  border-top: 1px solid var(--line);
  padding-top: 7px;
}
details.advanced > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}

/* ==========================================================================
   9. GARAGE, TRANSPORTS, DATA TABLES & OVERVIEW
   ========================================================================== */
.transports { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.transport {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 7px 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
}
.transport.off { opacity: .45; cursor: not-allowed; }
.transport input { margin-top: 2px; accent-color: var(--accent); }
.transport strong { display: block; font-size: .82rem; }
.transport small { display: block; color: var(--muted); font-size: .73rem; }
.transport .ports { color: var(--accent); font-family: var(--mono); }
.transport:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}

.resolve { margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.resolve-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 11px;
}
.resolve-card.bad { border-color: #6e302b; background: #261313; }
.resolve-card.warn { border-color: var(--warn); background: #231c0f; font-size: .8rem; }
.resolve-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}
.resolve-card .note { font-size: .76rem; color: var(--muted); margin: 4px 0; }

.checklist {
  background: #231c0f;
  border: 1px solid #594418;
  border-radius: 4px;
  padding: 9px 12px;
  margin-bottom: 10px;
}
.checklist h3 { font-size: .82rem; margin-top: 0; }
.checklist ul { margin: 0 0 8px; padding-left: 18px; font-size: .78rem; color: #eddba8; }
.checklist li { margin-bottom: 3px; }

.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 4px; }
.table-scroll { max-height: 310px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .79rem; }
table.data th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-2);
  text-align: left;
  color: var(--muted);
  font: 700 .67rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
table.data td {
  padding: 6px 8px;
  border-bottom: 1px solid #1d2633;
  vertical-align: top;
}
table.data tr:hover td { background: rgba(56, 189, 248, .05); }
table.data tr.dim td { opacity: .45; }
table.data tr.changed td { background: rgba(32, 201, 151, .11); }

.tag {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: #b7c8da;
  border-radius: 3px;
  padding: 1px 6px;
  font: 600 .68rem/1.3 var(--mono);
  margin: 1px 2px 1px 0;
}
.tag.muted-tag { opacity: .4; text-decoration: line-through; }
.conf { border-radius: 3px; padding: 1px 6px; font: 700 .66rem/1.3 var(--mono); }
.conf.ok { background: #0f382a; color: #63e6b2; }
.conf.mid { background: #33290e; color: #f5ca63; }
.conf.low { background: #381a17; color: #f79b8e; }
.yes { color: var(--ok); font-weight: 600; }
.no { color: var(--danger); font-weight: 600; }
.err { color: var(--danger); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 7px; }
.kv > div { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 7px 9px; }
.kv > div.full { grid-column: 1 / -1; }
.kv span { display: block; color: var(--muted); font: 700 .65rem/1.2 var(--mono); text-transform: uppercase; letter-spacing: .04em; }
.kv b { font-size: .86rem; font-weight: 600; word-break: break-all; }
.kv code { font-size: .74rem; color: #8ce5bf; word-break: break-all; }
.kv-empty { color: var(--muted); font-size: .82rem; padding: 6px 0; }

.caps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 7px; }
.cap {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 10px;
}
.cap b { color: var(--ok); font-size: .92rem; }
.cap.off { opacity: .52; }
.cap.off b { color: var(--muted); }
.cap strong { display: block; font-size: .8rem; }
.cap small { color: var(--muted); font-size: .71rem; }

/* ==========================================================================
   10. LIVE TELEMETRY GAUGE CLUSTER & STRIP-CHART RECORDER
   ========================================================================== */
.metrics-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 2px 6px;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.metric {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #161f2b 0%, #0e141c 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px 8px;
  font-variant-numeric: tabular-nums;
}
.metric:not(.derived)::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
}
.metric.bad { border-color: var(--danger); }
.metric.bad::before { background: var(--danger); }
.metric small {
  display: block;
  color: var(--muted);
  font: 700 .65rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 3px;
}
.metric strong {
  display: block;
  font: 700 1.38rem/1.15 var(--mono);
  letter-spacing: -.02em;
  color: #f4f8fc;
}
.metric strong em {
  font: 600 .72rem/1 var(--sans);
  font-style: normal;
  color: var(--muted);
  margin-left: 3px;
}
.metric label {
  display: block;
  color: #6b7d93;
  font: 500 .66rem/1.2 var(--mono);
  margin-top: 4px;
}
.metric.derived {
  border-style: dashed;
  background: var(--bg);
}
.metric.derived strong { font-size: 1.15rem; }
.metric.derived label .conf { margin-right: 5px; }
#derivedMissing { margin-top: 8px; }
#derivedMissing .btn { margin-left: 6px; }

.spark { width: 100%; height: 24px; margin-top: 5px; display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* Strip-Chart Oscilloscope Panel */
.plot-panel { padding-bottom: 11px; }
.plot-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.plot-heading h2 { margin: 2px 0 2px; font-size: .92rem; }
.plot-live-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: #82f3cb;
  font: 700 .64rem/1 var(--mono);
  letter-spacing: .08em;
  flex: none;
}
.plot-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px;
  gap: 10px;
  align-items: start;
}
@media screen and (max-width: 1040px) {
  .plot-layout { grid-template-columns: 1fr; }
}
.plot-chart {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #080b10;
  padding: 8px 10px;
}
.plot-empty,
.plot-lane-empty {
  color: var(--muted);
  font-size: .78rem;
  margin: 0;
  padding: 20px 6px;
  text-align: center;
}
.plot-lane { padding: 4px 0 8px; border-bottom: 1px solid #18212d; }
.plot-lane:last-of-type { border-bottom: 0; }
.plot-lane-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: 3px;
}
.plot-lane-head b { font-size: .78rem; }
.plot-lane-head span,
.plot-time {
  color: var(--muted);
  font: 500 .67rem/1.3 var(--mono);
  font-variant-numeric: tabular-nums;
}
.plot-svg { width: 100%; height: 96px; display: block; overflow: visible; }
.plot-grid { stroke: #182330; stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; }
.plot-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.plot-time { display: flex; justify-content: space-between; gap: 8px; padding-top: 6px; }
.plot-side {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  padding: 9px 10px;
}
.plot-side-title {
  display: flex;
  justify-content: space-between;
  font: 700 .66rem/1 var(--mono);
  letter-spacing: .08em;
  color: var(--text);
  margin-bottom: 7px;
}
.plot-side-title span { color: var(--muted); }
#plotChannels { display: grid; gap: 6px; max-height: 250px; overflow-y: auto; }
.plot-channel {
  display: grid;
  grid-template-columns: auto 8px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  font-size: .75rem;
  color: var(--text);
  cursor: pointer;
}
.plot-channel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--channel-color, var(--muted));
}
.plot-channel.off { opacity: .45; cursor: not-allowed; }
.plot-channel small { display: block; color: var(--muted); font: 500 .65rem/1.15 var(--mono); margin-top: 1px; }
.plot-footnote { margin: 8px 0 0; }

.channel-picker { position: relative; }
.channel-picker summary { cursor: pointer; color: var(--muted); font-size: .79rem; font-weight: 600; }
#live .channel-picker > div {
  position: absolute;
  right: 0;
  z-index: 30;
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 8px 11px;
  max-height: 56vh;
  overflow-y: auto;
  min-width: min(300px, calc(100vw - 40px));
  box-shadow: 0 14px 36px rgba(0, 0, 0, .55);
}

/* ==========================================================================
   11. FAULTS, SERVICE ACTIONS, PROCEDURES, SIMULATOR & SESSIONS
   ========================================================================== */
.finding {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 8px 11px;
  margin-bottom: 7px;
  background: var(--bg);
}
.finding.bad { border-left-color: var(--danger); }
.finding.warn { border-left-color: var(--warn); }
.finding.info, .finding.ok { border-left-color: var(--muted); }
.finding p { margin: 4px 0 0; }
.finding-head { display: flex; align-items: center; gap: 8px; }
.finding-level {
  font: 700 .62rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .07em;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 6px;
  color: var(--muted);
}
.finding-level.bad { color: var(--danger); border-color: currentColor; }
.finding-level.warn { color: var(--warn); border-color: currentColor; }

.fault {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 13px;
  margin-bottom: 7px;
}
.fault.warn { border-left-color: var(--danger); }
.fault-code { font: 700 .98rem/1 var(--mono); min-width: 68px; }
.fault-info { flex: 1; min-width: 0; }
.fault-info strong { display: block; font-size: .84rem; font-weight: 600; }
.fault-info small { color: var(--muted); font-size: .73rem; }
.fault-status {
  font: 700 .66rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 7px;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--muted);
}
.fault-status.current { background: #3f1c19; color: #ffb3a6; }

.panel.empty { text-align: center; padding: 24px; }
.empty-icon { font-size: 1.8rem; color: var(--ok); }

.gate { border-radius: 4px; padding: 7px 11px; font-size: .79rem; margin-top: 8px; }
.gate.ok { background: #0f291e; border: 1px solid #1f5740; color: #84e4b8; }
.gate.blocked { background: #261414; border: 1px solid #632825; color: #f6b5aa; }
.gate ul { margin: 5px 0 0; padding-left: 18px; }
.gate code { color: #ffd4c9; }

.warn-panel { background: #221b0f; border-color: #594418; }
.warn-panel h2 { color: #f5ca63 !important; }
.warn-panel p { font-size: .81rem; color: #eddba8; margin: 0; }

.action-list { display: flex; flex-direction: column; gap: 7px; }
.action {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 11px;
}
.action.blocked { opacity: .76; }
.action.armed { border-color: var(--warn); background: #221b0f; }
#simFaultList .action,
#procedureList .action { display: flex; gap: 10px; align-items: flex-start; }
.tagline {
  font: 600 .66rem/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 6px;
  margin-left: 5px;
}
.warn-text { color: var(--warn); }
.action-main { flex: 1; min-width: 0; }
.action-main p { margin: 3px 0 0; }
.action-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 5px; }
.action-head strong { font-size: .86rem; margin-right: 5px; }
.action-head code { color: var(--muted); margin-left: 4px; }
.action p { font-size: .79rem; margin: 4px 0; }
.action-warn { color: #f5b6a3; background: #281414; border-radius: 4px; padding: 6px 9px; font-size: .77rem !important; }
.fail-list { margin: 6px 0 0; padding-left: 18px; font-size: .76rem; color: #d69f93; }
.fail-list code { color: #ffd2c5; }

.sim-readout {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}
.sim-readout div { display: flex; flex-direction: column; gap: 2px; }
.sim-readout span { color: var(--muted); font: 700 .65rem/1 var(--mono); text-transform: uppercase; letter-spacing: .05em; }
.sim-readout b { font: 700 .9rem/1.2 var(--mono); }
#simPanels input[type="range"] { width: 100%; accent-color: var(--accent); padding: 0; }

.session-item { border-bottom: 1px solid var(--line); padding-bottom: 7px; margin-bottom: 7px; }
.session-item .toolbar { margin-top: 4px; }
#replayScrub { flex: 1; min-width: 140px; accent-color: var(--accent); }
#replayGrid, #replayFindings { margin-top: 10px; }

.session-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 11px;
  margin-bottom: 6px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
}
.session-row:hover { background: var(--panel-2); border-color: var(--accent); }
.session-row strong { display: block; font-size: .82rem; }
.session-row small { color: var(--muted); font-size: .71rem; }

.log-view { max-height: 56vh; overflow-y: auto; font-size: .74rem; font-family: var(--mono); }
.log-line { padding: 3px 0; border-bottom: 1px solid #1a2330; display: flex; gap: 8px; flex-wrap: wrap; }
.log-t { color: #617286; flex: none; }
.log-k { color: #7cb3dc; min-width: 50px; flex: none; }
.dir.tx { color: #f0ca67; }
.dir.rx { color: #5ee0a6; }

.report {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  overflow-x: auto;
  font-size: .76rem;
  line-height: 1.52;
  color: #cfdce9;
  white-space: pre;
  margin: 0;
}

/* ==========================================================================
   12. TUNERPRO / TUNERSTUDIO CALIBRATION EDITOR (#firmware & #mapsCard)
   ========================================================================== */
.progress {
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0 5px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  transition: width .35s ease;
}

.gate-card {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 4px;
  background: var(--bg);
  padding: 8px 11px;
  margin: 7px 0;
}
.gate-card h4 { margin: 0 0 3px; font-size: .81rem; font-weight: 650; }
.gate-card p, .gate-card ul { margin: 3px 0 0; font-size: .76rem; color: var(--muted); }
.gate-card ul { padding-left: 18px; }
.gate-card.ok { border-left-color: var(--accent); }
.gate-card.ok h4 { color: #7ae6b8; }
.gate-card.warn { border-left-color: var(--warn); background: #221b0f; }
.gate-card.warn h4 { color: #f5ca63; }
.gate-card.bad { border-left-color: var(--danger); background: #261313; }
.gate-card.bad h4 { color: #f69689; }

.danger-zone { border-color: #6a302b; }
.danger-zone > h2 { color: #f69689 !important; }
.danger-zone > h2::before { content: "⚠ "; }

b.ok { color: #5ee0a6; }
b.bad { color: #f69689; }
b.warn { color: var(--warn); }

.link-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0 2px;
  margin: 0;
  color: var(--accent);
  font: inherit;
  font-size: .78rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link-btn:hover { filter: brightness(1.15); }

#adapterOut { white-space: pre-wrap; font-size: .75rem; max-height: 280px; }
#memProgressText { font-variant-numeric: tabular-nums; }

/* Docked Cell Math Ribbon directly above #mapsOut */
.map-editor-tools {
  display: grid;
  gap: 6px;
  margin: 10px 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-2);
}
.map-math-strip { gap: 5px; }

.map-navigator {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 6px;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.map-navigator h3 { margin: 2px 0 0; font-size: .88rem; }
.map-navigator input { min-width: min(260px, 78vw); }

#mapsOut details,
#mapBuildOut details {
  border: 1px solid var(--line);
  border-radius: 4px;
  margin: 6px 0;
  padding: 0 10px;
  background: var(--bg);
}
#mapsOut .map-table-entry[open] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}
#mapsOut details > summary,
#mapBuildOut details > summary {
  cursor: pointer;
  padding: 7px 0;
  font-weight: 650;
  font-size: .82rem;
  list-style: none;
}
#mapsOut details > summary::before,
#mapBuildOut details > summary::before { content: "▸ "; color: var(--accent); }
#mapsOut details[open] > summary::before,
#mapBuildOut details[open] > summary::before { content: "▾ "; }
#mapsOut details > .table-wrap,
#mapBuildOut details > .table-wrap { margin: 4px 0 9px; }

.map-trace-mapping {
  margin: 5px 0 8px;
  padding: 0 9px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 5%, var(--panel));
}
.trace-axis-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 8px; }
.trace-axis { display: grid; grid-template-columns: minmax(150px, 1fr) 84px 84px; gap: 6px; border: 1px solid var(--line); border-radius: 4px; padding: 7px; }
.trace-axis legend { color: var(--muted); padding: 0 4px; font-size: .73rem; }
.trace-axis label { display: grid; gap: 3px; font-size: .72rem; color: var(--muted); }
.trace-axis select, .trace-axis input { min-width: 0; }
.trace-axis small { grid-column: 1 / -1; }

.map-grid td { padding: 1px !important; }
.map-value {
  position: relative;
  width: 100%;
  min-width: 46px;
  border: 1px solid rgba(10, 15, 22, .45);
  border-radius: 2px;
  color: #f3f7fb;
  background: color-mix(in srgb, #b84a27 var(--map-heat, 50%), #134a63);
  font: 600 .76rem/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  padding: 4px 6px;
  cursor: cell;
}
.map-value:hover {
  border-color: #e2eef7;
  filter: brightness(1.16);
}
.map-value:focus {
  border-color: #e2eef7;
  filter: brightness(1.16);
}
.map-value:focus-visible {
  /* A map cell is the keyboard's unit of navigation; the ring has to survive
     the heat-map background it sits on. */
  outline: 2px solid #ffffff;
  outline-offset: 1px;
  box-shadow: 0 0 0 3px #0d131a;
}
.map-value.selected {
  border-color: #ffffff;
  box-shadow: inset 0 0 0 1px #0d131a, 0 0 0 1px var(--accent);
}
.map-value.modified {
  border-color: var(--warn);
  background: #3d2c0e;
  color: #ffdc7d;
  font-weight: 700;
}
.map-value.modified.selected { border-color: #ffffff; }
.map-value.live-trace-weight {
  outline: 1px dashed color-mix(in srgb, var(--accent) calc(35% + var(--trace-weight, 0) * 55%), #fff);
  outline-offset: -2px;
  filter: brightness(calc(.9 + var(--trace-weight, 0) * .28));
}
.map-value.live-trace {
  outline: 3px solid #fff;
  outline-offset: -3px;
  box-shadow: 0 0 0 2px var(--accent), 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent);
  animation: map-trace-pulse 1.15s ease-in-out infinite alternate;
}
@keyframes map-trace-pulse { to { box-shadow: 0 0 0 3px var(--accent), 0 0 20px var(--accent); } }
.map-value.log-overlay::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-bottom: 3px solid hsl(calc(45 - var(--log-error) * 3) 88% 58%);
  pointer-events: none;
}

.map-axis-value {
  appearance: none;
  border: 1px dashed color-mix(in srgb, var(--accent) 48%, var(--line));
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: inherit;
  font: 700 .74rem/1.15 var(--mono);
  min-width: 3.1rem;
  padding: .2rem .3rem;
  cursor: cell;
}
.map-axis-value:hover,
.map-axis-value:focus-visible,
.map-axis-value.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.map-axis-value.modified { border-style: solid; border-color: var(--warn); color: #ffdc7d; }
.map-axis-legend { border-bottom: 1px dotted currentColor; cursor: help; }

.map-viz-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.map-viz {
  margin: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #090d12;
}
.map-viz figcaption {
  color: var(--muted);
  font: 700 .7rem/1.2 var(--mono);
  margin: 0 0 4px;
}
.map-viz svg { display: block; width: 100%; height: auto; min-height: 145px; }
.map-viz-axis { stroke: var(--muted); stroke-width: 1; opacity: .55; }

.map-builder {
  margin: 12px 0 4px;
  padding: 11px 12px;
  border: 1px solid #6a302b;
  border-radius: 4px;
  background: #1b1313;
}
.map-builder > h3 { color: #f69689; margin: 4px 0 6px; font-size: .86rem; }
.map-builder > h3::before { content: "⚠ "; }
.map-log-tools,
.recommendation-packages {
  margin: 8px 0;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 42%, var(--line));
  border-radius: 4px;
  background: var(--bg);
}
.map-log-tools > summary,
.recommendation-packages > summary { cursor: pointer; font-size: .8rem; }

.builder-evidence {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin: 10px 0;
  padding: 8px 10px 10px;
}
.builder-evidence legend { color: var(--text); font-size: .77rem; padding: 0 5px; }
.builder-evidence .field:nth-last-child(-n+2) { grid-column: 1 / -1; }
.ack-text {
  display: block;
  width: fit-content;
  margin: 4px 0 6px;
  padding: 5px 8px;
  border: 1px solid #6a302b;
  border-radius: 3px;
  color: #f4b1a3;
  background: #140e0e;
}
.preview-scroll { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.preview-scroll table.data { font-size: .73rem; }
.preview-scroll table.data th, .preview-scroll table.data td { padding: 4px 6px; }

@media screen and (max-width: 850px) {
  .map-viz-grid, .trace-axis-grid { grid-template-columns: 1fr; }
  .trace-axis { grid-template-columns: 1fr 1fr; }
  .trace-axis label:first-of-type, .trace-axis small { grid-column: 1 / -1; }
  .builder-evidence { grid-template-columns: 1fr; }
  .builder-evidence .field { grid-column: 1 !important; }
}

.map-tips {
  border: 1px solid #2b4d40;
  border-left: 3px solid var(--accent);
  background: #0e2019;
  border-radius: 4px;
  padding: 9px 12px;
  margin: 8px 0;
}
.map-tips h4 { margin: 0 0 3px; font-size: .81rem; }
.map-tips p { margin-bottom: 5px; }
.map-tips ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .78rem; }
.map-tips li { margin: 3px 0; }
.map-tips b { color: var(--text); }

.tip {
  border-left: 3px solid var(--accent);
  background: var(--bg-2);
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
  padding: 7px 10px;
  border-radius: 0 4px 4px 0;
  margin: 8px 0;
}
.tip.warn { border-left-color: var(--warn); color: #dfc58e; }
.tip b, .tip strong { color: var(--text); font-weight: 600; }

/* ==========================================================================
   13. SECTION ORGANIZERS, QUICK-JUMP DIRECTORY & TOOLS BENCH
   ========================================================================== */
.organizer-panel { margin-bottom: 10px; }
.organizer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.organizer-head h2 { margin: 0 0 2px; font-size: .92rem; }
.organizer-head p { margin: 0; font-size: .77rem; }
.organizer-head-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.organizer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.filter-pills,
.jump-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}
.filter-pill {
  appearance: none;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 9px;
  font: 600 .74rem/1.2 var(--sans);
  cursor: pointer;
}
.filter-pill:hover { color: var(--text); border-color: var(--accent); }
.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #052017;
}
.organizer-search {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 220px;
  max-width: 340px;
  min-width: 0;
}
.organizer-search input { width: 100%; }

.tools-quick-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
  max-height: 82px;
  overflow-y: auto;
}
.tool-jump-chip {
  appearance: none;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 7px;
  font: 550 .69rem/1.3 var(--sans);
  cursor: pointer;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-jump-chip:hover,
.tool-jump-chip.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--panel-2);
}

textarea.mono-in,
textarea.mono-out,
#tools textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
  font: 400 .77rem/1.4 var(--mono);
}
textarea.mono-out { background: var(--bg-2); color: var(--muted); }

#serviceTemplateOut,
#hondaOut,
#multiResearchOut,
#yamahaOut { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.manual-excerpt { border-top: 1px solid var(--line); padding: 8px 0; }
.manual-excerpt pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 5px 0; }
#manualTextStatus, #manualTextOut p { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }

@media screen and (max-width: 520px) {
  #tools .toolbar label.inline { flex-wrap: wrap; max-width: 100%; min-width: 0; }
  #tools .toolbar select, #tools .toolbar input, #tools input[type="file"] { max-width: 100%; min-width: 0; }
}

/* Equipment guide */
.equipment-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 10px; }
.equipment-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}
.equipment-card h3, .equipment-card p { margin: 0; }
.equipment-card h3 { font-size: .85rem; }
.equipment-card p { color: var(--muted); font-size: .77rem; line-height: 1.45; }
.equipment-card .equipment-link { margin-top: auto; font-size: .78rem; font-weight: 650; }

/* Hosted demo banner */
.demo-banner {
  margin: 0 0 10px;
  padding: 7px 11px;
  border-radius: var(--radius);
  background: #332510;
  color: #f3dba4;
  border: 1px solid #6b4f24;
  font-size: 12px;
  line-height: 1.45;
}
.demo-banner a { color: inherit; font-weight: 600; }
.demo-local-notice {
  grid-column: 1 / -1;
  margin: 0 0 10px;
  padding: 8px 11px;
  border-radius: var(--radius);
  background: #2a2013;
  border: 1px solid #6b4f24;
  color: #f3dba4;
}

/* ==========================================================================
   14. COMPACT DENSITY MODE (body[data-density="compact"])
   ========================================================================== */
body[data-density="compact"] main { padding: 7px 10px 14px; }
body[data-density="compact"] .panel { padding: 8px 10px; margin-bottom: 7px; }
body[data-density="compact"] .panel > h2:first-child { margin: -8px -10px 7px; padding: 5px 10px; }
body[data-density="compact"] .grid-2,
body[data-density="compact"] .garage-lower-grid,
body[data-density="compact"] #tools:not(.hidden),
body[data-density="compact"] #firmware:not(.hidden) { gap: 7px; }
body[data-density="compact"] .metrics { gap: 6px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
body[data-density="compact"] .metric { padding: 7px 9px; }
body[data-density="compact"] .metric strong { font-size: 1.2rem; }
body[data-density="compact"] table.data th,
body[data-density="compact"] table.data td { padding: 4px 6px; }

/* ==========================================================================
   15. MODALS, TOASTS, SAFETY GUIDES & PREFERENCES DIALOG
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translate(-50%, 16px);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 8px 16px;
  font-size: .82rem;
  opacity: 0;
  pointer-events: none;
  transition: all .18s;
  z-index: 250;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
  max-width: min(680px, 90vw);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--accent); }
.toast.bad { border-color: var(--danger); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, .74);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 16px;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 18px 20px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .65);
}
.modal-card h2 { margin-top: 0; font-size: 1rem; }
.modal-card p { font-size: .83rem; }
.modal-card.busy { border-color: var(--cyan); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.guide-intro { color: var(--text); margin: 0 0 10px; }
.guide-steps {
  list-style: none;
  padding: 0;
  margin: 10px 0;
  counter-reset: guide-step;
  display: grid;
  gap: 7px;
}
.guide-steps li {
  counter-increment: guide-step;
  position: relative;
  min-height: 28px;
  padding: 5px 10px 5px 34px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: .8rem;
}
.guide-steps li::before {
  content: counter(guide-step);
  position: absolute;
  left: 8px;
  top: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font: 700 .7rem/18px var(--mono);
  text-align: center;
}
.guide-callout {
  background: #231c0f;
  border-left: 3px solid var(--warn);
  padding: 7px 10px;
  border-radius: 0 4px 4px 0;
  font-size: .78rem;
  color: #eddba8;
  margin-top: 8px;
}
.guide-callout.danger { background: #261313; border-left-color: var(--danger); color: #f6b5aa; }
.guide-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
@media screen and (max-width: 520px) {
  .guide-choice { grid-template-columns: 1fr; }
}

.prefs-modal-card {
  width: min(820px, 95vw);
  max-width: 95vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.prefs-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.prefs-header h3 { margin: 2px 0 0; font-size: 1.08rem; }
.prefs-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.prefs-tab {
  appearance: none;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 11px;
  font: 600 .78rem/1.2 var(--sans);
  cursor: pointer;
}
.prefs-tab.active { background: var(--accent); border-color: var(--accent); color: #052017; }
.prefs-body { overflow-y: auto; padding-right: 4px; min-height: 200px; flex: 1 1 auto; }
.prefs-pane h4 { margin: 0 0 5px; font-size: .92rem; }
.prefs-subgrid { margin-top: 12px; }

.theme-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr));
  gap: 8px;
  margin: 8px 0 4px;
}
.theme-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
}
.theme-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.theme-card input { margin: 0 5px 0 0; accent-color: var(--accent); }

.preset-list, .preset-files-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.preset-files-list { max-height: 44vh; overflow-y: auto; }
.preset-row, .preset-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}
.preset-row.active { border-color: var(--accent); }
.preset-meta { min-width: 0; flex: 1 1 220px; }
.preset-meta strong { font-size: .82rem; }
.preset-meta code { display: block; font-size: .72rem; word-break: break-all; margin-top: 2px; color: var(--muted); background: none; padding: 0; }
.preset-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.preset-editor {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}
.preset-editor h5 { margin: 0 0 8px; font-size: .82rem; }
.prefs-footer { border-top: 1px solid var(--line); padding-top: 8px; align-items: center; flex-wrap: wrap; }

/* ==========================================================================
   16. DAYLIGHT SHOP LIGHT THEME (html[data-theme="light"])
   ========================================================================== */
@media screen {
  html[data-theme="light"] {
    --bg: #edf1f5;
    --bg-2: #e2e8ef;
    --panel: #ffffff;
    --panel-2: #eef3f8;
    --panel-3: #e1eaf2;
    --line: #c5d1de;
    --line-strong: #aab9ca;
    --text: #111b27;
    --muted: #4b5d73;
    --accent: #0d7a56;
    --accent-dim: #d2efe3;
    --cyan: #0284c7;
    --danger: #c93326;
    --warn: #a66304;
    --ok: #12784b;
    color-scheme: light;
  }
  html[data-theme="light"] .app-menubar,
  html[data-theme="light"] .status-bar {
    background: #dce4ed;
    border-color: var(--line);
    color: var(--text);
  }
  html[data-theme="light"] .brand-mark { color: #ffffff; }
  html[data-theme="light"] .ribbon-telemetry {
    background: #ffffff;
    border-color: var(--line);
  }
  html[data-theme="light"] .tele-cell { border-right-color: var(--line); }
  html[data-theme="light"] .ribbon-telemetry.offline .tele-val { color: #7a8b9e; }
  html[data-theme="light"] .nav.active {
    background: #ffffff;
    color: var(--text);
    border-color: var(--line-strong);
  }
  html[data-theme="light"] .btn.primary,
  html[data-theme="light"] .filter-pill.active,
  html[data-theme="light"] .prefs-tab.active,
  html[data-theme="light"] .qs-seg-btn.active {
    color: #ffffff;
  }
  html[data-theme="light"] .btn.danger {
    background: #fdeceb;
    border-color: #df9e96;
    color: #962114;
  }
  html[data-theme="light"] .pill { color: #095239; }
  html[data-theme="light"] .pill.live { background: var(--danger); color: #ffffff; }
  html[data-theme="light"] table.data td { border-bottom-color: #e2e8f0; }
  html[data-theme="light"] .metric {
    background: linear-gradient(180deg, #ffffff 0%, #f4f7fa 100%);
  }
  html[data-theme="light"] .metric strong { color: var(--text); }
  html[data-theme="light"] .metric label { color: var(--muted); }
  html[data-theme="light"] .plot-chart,
  html[data-theme="light"] .map-viz { background: #f8fafc; }
  html[data-theme="light"] .plot-lane { border-bottom-color: #e2e8f0; }
  html[data-theme="light"] .plot-grid { stroke: #d6e0ea; }
  html[data-theme="light"] .plot-live-label { color: #095239; }
  html[data-theme="light"] .tag { color: #2b3d52; }
  html[data-theme="light"] .conf.ok { background: #d3f2e3; color: #0b5d3b; }
  html[data-theme="light"] .conf.mid { background: #fcecc4; color: #784904; }
  html[data-theme="light"] .conf.low { background: #fbdad5; color: #8c2214; }
  html[data-theme="light"] .kv code { color: #0c6244; }
  html[data-theme="light"] .report,
  html[data-theme="light"] .log-view { color: #192838; }
  html[data-theme="light"] .log-line { border-bottom-color: #e2e8f0; }
  html[data-theme="light"] .dir.tx { color: #945d06; }
  html[data-theme="light"] .dir.rx { color: #0e6f46; }
  html[data-theme="light"] .notice.info { background: #e8f3fc; color: #123852; }
  html[data-theme="light"] .notice.warn,
  html[data-theme="light"] .warn-panel,
  html[data-theme="light"] .checklist,
  html[data-theme="light"] .resolve-card.warn,
  html[data-theme="light"] .gate-card.warn,
  html[data-theme="light"] .action.armed,
  html[data-theme="light"] .guide-callout,
  html[data-theme="light"] .demo-banner,
  html[data-theme="light"] .demo-local-notice {
    background: #fef8e7;
    border-color: #dfb457;
    color: #523604;
  }
  html[data-theme="light"] .warn-panel h2,
  html[data-theme="light"] .gate-card.warn h4 { color: #855204 !important; }
  html[data-theme="light"] .warn-panel p,
  html[data-theme="light"] .checklist ul { color: #523604; }
  html[data-theme="light"] .notice.danger,
  html[data-theme="light"] .resolve-card.bad,
  html[data-theme="light"] .gate-card.bad,
  html[data-theme="light"] .gate.blocked,
  html[data-theme="light"] .action-warn,
  html[data-theme="light"] .fault-status.current,
  html[data-theme="light"] .guide-callout.danger {
    background: #fdf0ee;
    border-color: #df9c92;
    color: #7d1d10;
  }
  html[data-theme="light"] .gate-card.bad h4,
  html[data-theme="light"] .danger-zone > h2,
  html[data-theme="light"] .map-builder > h3,
  html[data-theme="light"] b.bad { color: #a82413 !important; }
  html[data-theme="light"] .gate.ok { background: #e5f6ed; color: #0d5b39; }
  html[data-theme="light"] .gate-card.ok h4,
  html[data-theme="light"] b.ok { color: #0f7348; }
  html[data-theme="light"] .map-builder { background: #fcf6f5; border-color: #dfb0a8; }
  html[data-theme="light"] .ack-text { background: #fdf0ee; color: #7d1d10; border-color: #df9c92; }
  html[data-theme="light"] .map-tips { background: #ebf8f2; border-color: #9dd4be; }
}

.flag-toggle-btn {
  min-width: 72px;
  font-weight: 600;
}
.flag-toggle-btn[aria-pressed="true"] {
  border-color: var(--ok, #22c55e);
}
tr[data-patch-card].modified {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* ==========================================================================
   17. PRINT SNAPSHOT MODE
   ========================================================================== */
@media print {
  @page { margin: 12mm; }
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; color: #000 !important; }
  aside.sidebar, .no-print, #notices, .toolbar, button, .btn, .progress,
  .nav, input, select, textarea { display: none !important; }
  .view.hidden { display: none !important; }
  main { margin: 0 !important; padding: 0 !important; overflow: visible !important; }
  .panel {
    border: 1px solid #999 !important; background: #fff !important;
    color: #000 !important; box-shadow: none !important; break-inside: avoid;
  }
  .panel > h2:first-child { background: #f2f2f2 !important; color: #000 !important; border-bottom-color: #bbb !important; }
  .panel h2, .panel h4, .resolve-card, .gate-card { color: #000 !important; }
  .muted { color: #444 !important; }
  .log-view, pre { border: 1px solid #999 !important; background: #fff !important; color: #000 !important; }
  table.data { font-size: 9px; }
  table.data th { position: static !important; background: #eee !important; color: #000 !important; }
  #mapsOut details { border: none !important; }
  #mapsOut details > *:not(summary) { display: block !important; }
  #mapsOut details > summary { font-weight: 700; }
  #mapsOut details > summary::before { content: ""; }
  .table-wrap, .table-scroll { max-height: none !important; overflow: visible !important; }
}

/* ==========================================================================
   17. HELP & REFERENCE MODULE
   Global search spotlight, guide center, tool directory, ECU/XDF explorer.
   ========================================================================== */
.menubar-kbd {
  font: 600 .62rem/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px 4px;
  margin-left: 4px;
}
#menubarHelpSearchBtn { display: inline-flex; align-items: center; gap: 4px; }

.help-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.help-sidebar-panel {
  padding: 10px;
  max-height: calc(100vh - 190px);
  overflow-y: auto;
}
.help-sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 7px;
  margin-bottom: 7px;
  border-bottom: 1px solid var(--line);
}
.help-sidebar-head strong { font-size: .8rem; }
.help-topic-tree { display: flex; flex-direction: column; gap: 10px; }
.help-tree-group { display: flex; flex-direction: column; gap: 1px; }
.help-tree-group-head {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font: 700 .66rem/1.4 var(--sans);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 3px 4px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 2px;
}
.help-tree-item {
  appearance: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 6px;
  color: var(--text);
  font: 500 .76rem/1.35 var(--sans);
  cursor: pointer;
}
.help-tree-item:hover { background: var(--panel-2); border-color: var(--line); }
.help-tree-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}
.help-tree-kind {
  flex: 0 0 auto;
  font: 700 .56rem/1.4 var(--mono);
  letter-spacing: .05em;
  color: var(--muted);
  min-width: 46px;
}
.help-tree-item.active .help-tree-kind { color: var(--accent); }
.help-tree-title { min-width: 0; }
.help-tree-empty { padding: 6px; }

.help-article-panel { padding: 16px 18px; min-height: 320px; }
.help-article-head { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 12px; }
.help-article-kicker {
  font: 700 .66rem/1.4 var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.help-dot { color: var(--muted); }
.help-article-title { margin: 0 0 4px; font-size: 1.16rem; line-height: 1.25; }
.help-article-summary { margin: 0; color: var(--muted); font-size: .84rem; max-width: 76ch; }
.help-article-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.help-body { font-size: .84rem; line-height: 1.6; max-width: 92ch; }
.help-body h3 {
  margin: 18px 0 6px;
  font-size: .9rem;
  color: var(--text);
  letter-spacing: .01em;
}
.help-body h3:first-child { margin-top: 4px; }
.help-body p { margin: 6px 0; }
.help-body ul, .help-body ol { margin: 6px 0 6px 0; padding-left: 20px; }
.help-body li { margin: 3px 0; }
.help-body code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 3px;
  font-size: .78rem;
}
.help-body pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 9px 11px;
  overflow-x: auto;
  font-size: .76rem;
  line-height: 1.45;
}
.help-body pre code { background: none; border: 0; padding: 0; }
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: .78rem;
}
.help-table th, .help-table td {
  border: 1px solid var(--line);
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
.help-table thead th {
  background: var(--panel-2);
  font: 700 .7rem/1.35 var(--sans);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.help-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, .015); }
.help-spec-table th { width: 30%; white-space: normal; }
.help-steps { margin-left: 2px; }
.help-tagline { margin-top: 12px; font-size: .74rem; color: var(--muted); }
.help-tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  margin: 1px 2px;
  font: 600 .66rem/1.5 var(--mono);
  color: var(--muted);
  background: var(--bg);
}
.help-jump-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 8px; }
.help-jump { border-color: var(--accent) !important; color: var(--accent) !important; }
.help-jump:hover { background: var(--accent-dim) !important; }
.help-related { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 10px; }
.help-related h3 { margin: 0 0 6px; font-size: .82rem; }
.help-related-list { display: flex; flex-direction: column; gap: 3px; }
.help-related-link {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: .78rem;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 5px;
}
.help-related-link:hover { border-color: var(--line); background: var(--panel-2); }
.help-related-kind {
  font: 700 .56rem/1.4 var(--mono);
  letter-spacing: .05em;
  color: var(--muted);
  min-width: 58px;
}

/* Search results */
.help-search-status { margin: 4px 2px 8px; }
.help-search-results { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.help-result {
  appearance: none;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 10px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.help-result:hover { border-color: var(--accent); background: var(--panel-2); }
.help-result-kind,
.help-spot-result .help-result-kind {
  flex: 0 0 auto;
  font: 700 .56rem/1.6 var(--mono);
  letter-spacing: .06em;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--muted);
  min-width: 52px;
  text-align: center;
}
.kind-guide { color: var(--accent); border-color: var(--accent-dim); }
.kind-ecu { color: var(--cyan); border-color: #164e63; }
.kind-xdf { color: var(--cyan); border-color: #164e63; }
.kind-protocol { color: var(--warn); border-color: #6b3f10; }
.kind-tool, .kind-panel { color: var(--text); }
.kind-action { color: var(--muted); }
.help-result-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.help-result-title { font-weight: 600; font-size: .84rem; }
.help-result-snippet { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.help-result-arrow { color: var(--muted); }
.help-result mark { background: var(--accent-dim); color: var(--text); border-radius: 2px; padding: 0 1px; }
.help-empty { padding: 14px; border: 1px dashed var(--line); border-radius: 5px; color: var(--muted); font-size: .82rem; }

/* Tool directory, ECU catalog, XDF library, glossary */
.help-directory-group { margin-bottom: 18px; }
.help-directory-group > h3 { margin: 0 0 7px; font-size: .86rem; }
.help-directory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 7px;
}
.help-directory-card {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px 10px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.help-directory-title { font-weight: 600; font-size: .8rem; }
.help-directory-card p { margin: 0; }

.help-ecu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px; margin: 8px 0 12px; }
.help-ecu-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 9px;
  background: var(--panel-2);
  color: var(--text);
}
.help-ecu-card:hover { border-color: var(--accent); }
.help-ecu-name { font-weight: 600; font-size: .8rem; }
.help-ecu-meta { color: var(--muted); font-size: .72rem; }
.help-ecu-caps { display: flex; flex-wrap: wrap; gap: 2px; }

.help-xdf-brand { margin-bottom: 14px; }
.help-xdf-brand > h3 { margin: 0 0 6px; font-size: .84rem; }
.help-xdf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 5px; }
.help-xdf-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  background: var(--panel-2);
  color: var(--text);
}
.help-xdf-card:hover { border-color: var(--accent); }
.help-xdf-name { font-size: .77rem; font-weight: 600; }
.help-xdf-meta { font: 500 .68rem/1.4 var(--mono); color: var(--muted); }
.help-xdf-counts { font-size: .7rem; color: var(--muted); }

.help-glossary-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.help-glossary-term {
  border-left: 2px solid var(--accent-dim);
  padding: 2px 0 2px 9px;
  border-radius: 2px;
}
.help-glossary-term h3 { margin: 0 0 3px; font-size: .82rem; }
.help-glossary-term p { margin: 0; color: var(--muted); font-size: .78rem; }
.help-glossary-term.help-focus-ring { border-left-color: var(--accent); background: var(--accent-dim); }

.help-focus-ring {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px;
  animation: help-ring-pulse .9s ease-in-out 2;
}
@keyframes help-ring-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(32, 201, 151, .0); }
  50% { box-shadow: 0 0 0 5px rgba(32, 201, 151, .18); }
}

/* Global search spotlight */
.help-spotlight-card {
  max-width: 720px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(78vh, 720px);
}
.help-spotlight-header { display: flex; align-items: center; gap: 8px; }
.help-spotlight-icon { font-size: 1rem; }
#helpSpotlightInput {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 9px 11px;
  font: 500 .9rem/1.3 var(--sans);
}
#helpSpotlightInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.help-spotlight-filters { display: flex; flex-wrap: wrap; gap: 4px; }
.help-spotlight-results {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 120px;
}
.help-spot-result {
  appearance: none;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 8px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.help-spot-result:hover { background: var(--panel-2); border-color: var(--line); }
.help-spot-result.active { background: var(--accent-dim); border-color: var(--accent); }
.help-spot-hint { flex: 0 0 auto; color: var(--muted); font: 600 .66rem/1.6 var(--mono); }
.help-spotlight-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 7px;
}
.help-spotlight-footer kbd {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
  font-size: .68rem;
  color: var(--muted);
}

/* Light theme adjustments */
html[data-theme="light"] .help-tree-item:hover { background: var(--panel-2); }
html[data-theme="light"] .help-result mark { background: var(--accent-dim); color: var(--text); }
html[data-theme="light"] .help-table tbody tr:nth-child(even) td { background: rgba(0, 0, 0, .018); }
html[data-theme="light"] .help-directory-card,
html[data-theme="light"] .help-ecu-card,
html[data-theme="light"] .help-xdf-card { background: var(--panel-2); }
html[data-theme="light"] .help-spotlight-card { background: var(--panel); }

/* Narrow screens: stack the sidebar above the article */
@media (max-width: 900px) {
  .help-layout { grid-template-columns: minmax(0, 1fr); }
  .help-sidebar-panel { max-height: 260px; }
  .help-glossary-list { grid-template-columns: minmax(0, 1fr); }
}

@media print {
  .help-sidebar-panel, .help-article-actions, .help-jump-row,
  .help-search-results, .help-organizer-bar, .help-spotlight-card { display: none !important; }
  .help-layout { display: block; }
  .help-article-panel { border: 0; padding: 0; }
  .help-body { max-width: none; font-size: 10.5pt; }
  .help-table th, .help-table td { border-color: #999; }
}

/* --------------------------------------------------------------------------
   Tools bench: organisation by brand
   A brand <select> in the organizer bar, a heading per brand inside the bench,
   and an "Only <brand>" affordance on each heading.
   -------------------------------------------------------------------------- */
.tools-brand-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.tool-brand-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 .74rem/1.2 var(--sans);
  color: var(--muted);
  letter-spacing: .02em;
}
#toolsBrandSelect {
  appearance: none;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b9bb0' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 7px center;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 5px 24px 5px 8px;
  font: 600 .76rem/1.2 var(--sans);
  cursor: pointer;
  max-width: 240px;
}
#toolsBrandSelect:hover { border-color: var(--accent); }
#toolsBrandSelect:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tool-brand-badge {
  font: 600 .7rem/1.4 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.tool-brand-badge.filtered {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.tools-brand-heading {
  display: flex;
  align-items: baseline;
  gap: 8px 12px;
  flex-wrap: wrap;
  margin: 6px 0 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--panel-2);
}
.tools-brand-name {
  font: 700 .82rem/1.3 var(--sans);
  color: var(--text);
  letter-spacing: .01em;
}
.tools-brand-note {
  flex: 1 1 220px;
  min-width: 0;
  font-size: .72rem;
  color: var(--muted);
}
.tools-brand-count {
  font: 600 .68rem/1.4 var(--mono);
  color: var(--muted);
  white-space: nowrap;
}
.tools-brand-only {
  padding: 2px 7px;
  font-size: .68rem;
}
.tools-brand-only.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

@media screen and (min-width: 1120px) {
  #tools:not(.hidden) > .tools-brand-heading {
    grid-column: 1 / -1;
    margin: 2px 0 0;
  }
}
@media print {
  .tools-brand-heading { break-after: avoid; }
  .tools-brand-only, .tools-brand-bar { display: none !important; }
}

/* Brand chips used by the help center (tool entries and search results) */
.help-brand-pick { margin-left: auto; }
.help-brand-chip {
  display: inline-block;
  font: 700 .6rem/1.5 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--cyan);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 0 4px;
  vertical-align: middle;
}
.help-brand-chip.small { font-size: .56rem; opacity: .85; }
.help-brand-line { margin: 2px 0 6px; font-size: .78rem; color: var(--muted); }
.help-brand-note { margin: -2px 0 8px; }
.help-tool-card-meta {
  font: 600 .64rem/1.4 var(--mono);
  color: var(--muted);
  letter-spacing: .03em;
  text-transform: uppercase;
}

/* 18 · Tool bench: frame lab, ROM map, XDF finder, checksum workbench -------- */

#frameLabOut,
#isotpOut,
#isotpInOut,
#kwpOut {
  margin: 6px 0 0;
}

#frameLabPanel h3 {
  margin: 16px 0 6px;
  font-size: .86rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.rom-strip {
  display: block;
  width: 100%;
  height: 64px;
  margin: 8px 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}

.rom-blank { fill: #2a3140; }
.rom-code { fill: #4f8cff; }
.rom-data { fill: #35c48a; }
.rom-sparse { fill: #b08a3c; }

#xdfFindQuery {
  min-width: 260px;
}

#widebandLab input[type="number"] {
  width: 6.5em;
}

.xdf-find-group {
  margin: 14px 0 0;
}

.xdf-find-group h3 {
  margin: 0 0 6px;
  font-size: .9rem;
}

#xdfFindOut .table-wrap {
  max-height: 380px;
  overflow: auto;
}

#cksOut .table-wrap,
#cksDetail .table-wrap {
  max-height: 360px;
  overflow: auto;
}

#cksDetail .kv {
  margin-top: 10px;
}

@media print {
  .rom-strip { border-color: #999; }
  #frameLabPanel, #romMapPanel, #xdfFinderPanel, #checksumWorkbench, #widebandLab { break-inside: avoid; }
}

/* ==========================================================================
   ACCESSIBILITY — motion and forced colours
   ========================================================================== */

/* A user who asks the operating system for less motion should not get the
   live-trace pulses, the spinner or the toast slide. Nothing here removes
   information: every state that moves is also stated in text. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Windows High Contrast and similar modes drop background colours, which is
   exactly what the heat map and the selected/modified cell states use. Keep
   the borders, which survive forced colours. */
@media (forced-colors: active) {
  .map-value,
  .map-value.selected,
  .map-value.modified,
  .map-value.live-trace-weight,
  .badge,
  .chip {
    border: 1px solid CanvasText;
    outline-color: Highlight;
  }
  .map-value:focus-visible,
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 2px solid Highlight;
  }
}
