/* ============================================================
   diag4free — Mobile & Touch Layer
   ------------------------------------------------------------
   Angewendet nach style.css. Adressiert UI/UX-Pro-Max-Regeln:
     R22/R66/R104  Touch-Target ≥ 24×24 (Web) / 44 px empfohlen
     R23           ≥ 8 px Spacing zwischen Touch-Zielen
     R25           touch-action manipulation (Tap-Delay weg)
     R67           Body-Font ≥ 16 px auf Mobile
     R68           Safe-Area-Insets (Notch / Home-Indicator)
     R69           Kein horizontaler Scroll
     R111          overflow-wrap: anywhere für lange Tokens
     R113/R116     Essenzielle Text-Reflow, keine Clamp-Verluste
     R115          Chip-Collection-Reflow (statt clip)
     R119          Cancellable Transitions
   ============================================================ */

/* ------------------------------------------------------------
   1. Globale Touch-Optimierung (R25 + R69)
------------------------------------------------------------ */
html {
  /* iOS: Font-Size-Adjust bei Rotation abschalten */
  -webkit-text-size-adjust: 100%;
}
html, body {
  overflow-x: hidden;                      /* R69 */
  overscroll-behavior-y: contain;          /* Kein Bounce über PWA-Shell */
}
button, a, [role="button"], input, select, textarea, label {
  touch-action: manipulation;              /* R25 — 300ms Delay entfernen */
}
/* Größere Tap-Feedback-Area für native Buttons */
button, [role="button"] {
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------
   2. Long-Token-Wrapping (R111 + R113)
------------------------------------------------------------ */
.drawer-title,
.doc-title,
.tile-title,
.guide-name,
.result-title,
.kpi-value,
.step-question,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.doc-summary,
.tile-desc,
.guide-desc,
.kpi-hint,
.drawer-subtitle {
  overflow-wrap: anywhere;
}

/* Code/Kabel-IDs dürfen brechen wo sinnvoll */
code, .measure-target, .pin-num, .doc-code {
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------
   3. Chip-Reflow (R115)
------------------------------------------------------------ */
.filter-chips,
.doc-engines,
.detail-tags {
  flex-wrap: wrap;
  row-gap: var(--space-2);
}

/* ------------------------------------------------------------
   4. Safe-Area (R68) — Notch, Home-Indicator, Statusbar
   Aktiv bei standalone PWA und Landscape auf iPhone
------------------------------------------------------------ */
@supports (padding: max(0px)) {
  .topbar {
    padding-left:  max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
  }
  .sidebar {
    padding-left:  env(safe-area-inset-left);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .view-inner {
    padding-left:  max(var(--space-6), env(safe-area-inset-left));
    padding-right: max(var(--space-6), env(safe-area-inset-right));
    padding-bottom: max(var(--space-16), env(safe-area-inset-bottom));
  }
  .drawer {
    padding-right: env(safe-area-inset-right);
  }
}

/* ------------------------------------------------------------
   5. Reduced Motion (R119 + R66)
------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .sidebar {
    transition: none !important;
  }
}

/* ============================================================
   MOBILE  ≤ 960 px  (Tablet Portrait + Phones)
   ============================================================ */
@media (max-width: 960px) {
  /* R67 — mind. 16px Body-Text */
  html { font-size: 16px; }

  /* Touch-Targets (R22 / R66 / R104) — durchgehend ≥ 44 px */
  .btn,
  .icon-btn,
  .chip,
  .filter-chip,
  .nav-item,
  .model-item,
  .step-actions .btn,
  .card button,
  .link-inline {
    min-height: 44px;
  }
  .link-inline {
    display: inline-flex;
    align-items: center;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--color-primary-tint-2);
    color: var(--color-primary);
    font-weight: 600;
    text-decoration: none;
  }
  .link-inline:hover,
  .link-inline:focus-visible {
    background: var(--color-primary-tint);
  }

  /* R23 — 8px Spacing zwischen Touch-Zielen */
  .topbar-actions { gap: var(--space-2); }
  .filter-chips   { gap: var(--space-2); }

  /* Icon-Buttons in Topbar größer */
  .topbar .icon-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
  }

  /* Topbar: kompaktere Höhe, größere Trefferzone */
  :root { --topbar-h: 56px; }
  .topbar-title-mobile {
    font-size: var(--text-md);
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  /* View-Padding auf Mobile knapper (Werkstatt = viel Content sichtbar) */
  .view-inner {
    padding-top: var(--space-4);
    padding-bottom: var(--space-16);
  }

  /* KPI-Grid: 2×2 mit prominenten Zahlen (Bento-artig) */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
  }
  .kpi { padding: var(--space-3) var(--space-4); }
  .kpi-label { font-size: 11px; }
  .kpi-value { font-size: 1.5rem; }         /* fix statt clamp — prominenter */
  .kpi-hint  { font-size: 12px; line-height: 1.4; }

  /* Doc-Cards & Tiles: dichtere Grid, aber mit klaren Grenzen */
  .doc-list  { grid-template-columns: 1fr; gap: var(--space-3); }
  .tile-grid { grid-template-columns: 1fr; gap: var(--space-3); }
  .doc-card, .tile { padding: var(--space-4); }

  /* Guide-Step: Buttons Full-Width, Aktion primär */
  .step-actions {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .step-actions .btn {
    flex: 1 1 100%;
    justify-content: center;
    font-size: var(--text-md);
    padding: var(--space-3) var(--space-4);
  }
  .step-actions .btn.btn-primary { order: -1; }   /* JA nach oben */

  /* Drawer Fullwidth, Header sticky sichtbar */
  .drawer {
    width: 100%;
    max-width: 100vw;
  }
  .drawer-header {
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 5;
    border-bottom: 1px solid var(--color-divider);
  }
  .drawer-footer {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-divider);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }

  /* Metadaten (10-11px hardcodiert) auf Mobile lesbar */
  .doc-code,
  .doc-type-badge,
  .kicker,
  .measure-target {
    font-size: 12px !important;
  }

  /* Sidebar-Baureihen-Baum: größere Trefferzonen.
     Vorher zielten hier `.model-item` und `.model-group-toggle` — beide
     Klassen gibt es im Markup nicht, die Regeln liefen ins Leere und die
     Knöpfe blieben bei 33 bzw. 34 px. */
  .model-items button,
  .model-group-header {
    min-height: 44px;
  }
  .model-items button { padding-top: var(--space-2); padding-bottom: var(--space-2); }

  /* Immer sichtbare Bedienelemente der Topbar */
  .topbar-menu-btn { min-width: 44px; min-height: 44px; }
  .vin-btn { min-height: 44px; padding-inline: var(--space-3); }
}

/* ============================================================
   PHONE  ≤ 480 px
   ============================================================ */
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 1.375rem; }
  .kpi-label { font-size: 10.5px; letter-spacing: 0.06em; }

  /* Titelblöcke straffer */
  .view-header h1 { font-size: 1.25rem; }
  .view-header .kicker { display: block; margin-bottom: var(--space-1); }

  /* Suche im Topbar full-width overlay */
  .topbar-search.mobile-active {
    padding-inline: max(var(--space-3), env(safe-area-inset-right));
  }

  /* Pin-Tabelle horizontal scrollen statt cramped */
  .pin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pin-table      { min-width: 320px; font-size: 12.5px; }

  /* Guide-Step: Frage groß und prominent */
  .step-question {
    font-size: 1.125rem;
    line-height: 1.35;
  }
}

/* ============================================================
   POINTER: COARSE  (Touch-Devices, unabhängig von Breite)
   ============================================================ */
@media (pointer: coarse) {
  /* Hover-Effekte, die auf Touch nach dem Tap kleben, deaktivieren */
  .tile:hover,
  .doc-card:hover,
  .chip:hover,
  .btn:hover {
    transform: none;
  }
  /* Fokus-Ring bleibt für Keyboard-Nutzer */
}

/* ============================================================
   STANDALONE (PWA installiert) — echte App-Anmutung
   ============================================================ */
@media (display-mode: standalone) {
  /* iOS-Statusbar-Bereich abfangen. Die Rasterzeile muss mitwachsen:
     vorher blieb sie bei 56 px, die Leiste bekam die Statusbar als
     Polster obendrauf, und ihre Knoepfe ragten unter die Statusbar und
     ueber den Inhalt. */
  :root { --topbar-h: calc(56px + max(0px, env(safe-area-inset-top))); }
  .topbar { padding-top: max(0px, env(safe-area-inset-top)); }
  /* Install-Button nicht mehr anzeigen */
  #installBtn { display: none !important; }
}

/* ============================================================
   Fokus-Ring (WCAG 2.1 — 3:1 Kontrast, sichtbar auf allen Themes)
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
[data-theme="dark"] :focus-visible {
  outline-color: var(--color-primary-active);
}

/* ============================================================
   Engine-Picker Dialog (Motor wählen)
   ============================================================ */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 26, 43, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: var(--space-4);
  animation: fadeIn 120ms ease-out;
}
[data-theme="dark"] .dialog-backdrop {
  background: rgba(0, 0, 0, 0.6);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.dialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}
.dialog-header h2 {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
}
.dialog-body {
  padding: var(--space-4) var(--space-5) var(--space-5);
  overflow-y: auto;
}
.dialog-lead {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-4);
}
.engine-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-2);
}
.engine-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 44px;
  transition: var(--transition-interactive);
}
.engine-option:hover, .engine-option:focus-visible {
  border-color: var(--color-primary);
  background: var(--color-primary-tint-2);
}
.engine-option.active {
  background: var(--color-primary-tint);
  border-color: var(--color-primary);
}
.engine-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-text);
}
.engine-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  background: var(--color-surface);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   Chip-Overflow-Disclosure (R115) — vorbereitet für +n
   ============================================================ */
.chip-collection {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
.chip-collection .chip-overflow {
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
}

/* ============================================================
   SOFTWARE-UPDATES VIEW (.sw-*)
   ============================================================ */
.sw-section {
  margin-top: var(--space-8);
}
.sw-section h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-3);
}
.sw-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: var(--space-2) 0 var(--space-3);
  max-width: 62ch;
}
.sw-checker { max-width: 26rem; }
.sw-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  letter-spacing: 0.06em;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease;
}
.sw-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 113, 187, 0.15);
}
.sw-result { margin-top: var(--space-4); }
.sw-warn, .sw-none {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--color-warning-tint);
  color: var(--color-text);
  border: 1px solid var(--color-warning);
}
.sw-none {
  background: var(--color-surface-2);
  border-color: var(--color-divider);
}
.sw-none p { margin: var(--space-2) 0 0; color: var(--color-text-muted); }
.sw-match {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
}
.sw-match-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.sw-file {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-md);
}
.sw-date {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.sw-desc {
  margin: var(--space-2) 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.sw-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--space-2) var(--space-5);
  margin: var(--space-3) 0;
}
.sw-detail dt {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
}
.sw-detail dd {
  margin: 0;
  font-size: var(--text-sm);
}
.sw-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}
.sw-install {
  margin-top: var(--space-2);
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}
.sw-install summary {
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
}
.sw-install ol {
  margin: var(--space-3) 0 var(--space-2);
  padding-left: 1.4em;
  font-size: var(--text-sm);
}
.sw-install li { margin-bottom: var(--space-2); }
.sw-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: var(--space-2) 0 0;
}
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}
.data-table th {
  background: var(--color-surface-offset);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}
.data-table tr:last-child td { border-bottom: none; }
.sw-tools {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: var(--space-4);
}
.sw-tool {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.sw-tool-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}
.sw-tool-ver {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-primary);
  white-space: nowrap;
}
.sw-tool-target {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin: 0;
}
.sw-tool-note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
  flex: 1;
}
.sw-tool-links {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.sw-tool-links a {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}
.sw-tool-links a:hover { text-decoration: underline; }
.sw-attribution {
  margin-top: var(--space-10);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.sw-attribution a { color: var(--color-text-muted); }

/* ============================================================
   VIN-DECODER (.vin-*)
   ============================================================ */
.vin-btn {
  margin-left: var(--space-3);
  padding: 0.2rem 0.6rem;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  background: transparent;
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.vin-btn:hover {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.dialog-wide { max-width: 34rem; }
.vin-input {
  margin-top: var(--space-3);
  text-transform: uppercase;
}
.vin-result { margin-top: var(--space-4); }
.vin-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-4);
}
.vin-facts dt {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
}
.vin-facts dd {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
}
.vin-facts code {
  font-family: var(--font-mono);
  background: var(--color-surface-offset);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}
.vin-online {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px dashed var(--color-border);
}
.vin-online-head {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

/* ============================================================
   TOUCH-EBENE — Bedienung am Fahrzeug
   Tab-Bar in der Daumenzone, Antwortleiste, Schritt-Spur.
   Desktop bleibt unverändert: alles unten ist ≤ 960 px gated.
   ============================================================ */

/* --- Bottom-Tabbar: auf Desktop aus, auf Touch die Primärnavigation --- */
.tabbar { display: none; }

@media (max-width: 960px) {
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    z-index: 60;
    background: color-mix(in srgb, var(--color-surface) 97%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--color-divider);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 56px;
    padding: var(--space-2) 2px;
    border: 0;
    background: none;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 120ms ease, transform 120ms ease;
  }
  .tab svg { width: 22px; height: 22px; }
  .tab span { line-height: 1; }

  /* Aktiver Tab: Farbe + Indikator oben, kein Layout-Shift */
  .tab.active { color: var(--color-primary); }
  .tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 28px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--color-primary);
  }
  .tab:active { transform: scale(0.94); }

  /* Offene Fehlersuche → Punkt am Diagnose-Tab */
  .tab-dot {
    position: absolute;
    top: 8px;
    right: calc(50% - 16px);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-surface);
  }

  /* Platz für die Tabbar, sonst verdeckt sie den letzten Eintrag */
  .view-inner { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* Sidebar-Nav dupliziert die Tabbar → auf Touch ausblenden,
     die Baureihen-Auswahl im Drawer bleibt erhalten */
  .sidebar .nav-list,
  .sidebar .nav-section:first-of-type { display: none; }
}

/* --- Antwortleiste: klebt am unteren Rand, direkt über der Tabbar --- */
.step-answerbar {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.answer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 100ms ease, filter 120ms ease;
}
.answer svg { width: 20px; height: 20px; flex: none; }
.answer:active { transform: scale(0.97); }

/* Auf schmalen Phones tragen die Kurzlabels — sie halten beide Flächen
   gleich groß und treffsicher; die Langform bleibt im aria-label. */
.answer-short { display: none; }
@media (max-width: 560px) {
  .answer { min-width: 0; }
  .answer-full  { display: none; }
  .answer-short { display: inline; }
}

.answer-yes {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.answer-no {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

@media (max-width: 960px) {
  .step-answerbar {
    position: fixed;
    /* 56px Tabbar + 1px deren Oberkante — sonst überlappen die Ränder */
    inset: auto 0 calc(57px + env(safe-area-inset-bottom)) 0;
    z-index: 55;
    margin: 0;
    padding: var(--space-3);
    gap: var(--space-2);
    background: color-mix(in srgb, var(--color-surface) 97%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--color-divider);
  }
  .answer { min-height: 56px; font-size: 1rem; }
  .answer span { white-space: nowrap; }

  /* Der Runner braucht Luft, damit die fixierte Leiste nichts verdeckt */
  .guide-step { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* --- Schritt-Spur: beantwortete Schritte bleiben antippbar --- */
.step-trail {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  padding-left: var(--space-3);
  border-left: 2px solid var(--color-divider);
}
.trail-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.trail-item:hover,
.trail-item:focus-visible { background: var(--color-primary-tint-2); color: var(--color-text); }
.trail-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-divider);
  font-size: 11px;
  font-weight: 700;
}
.trail-q {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step-doc-ref { margin-bottom: var(--space-4); }

@media (max-width: 960px) {
  .trail-item { min-height: 44px; }
}

/* --- Wiederaufnahme: dort weitermachen, wo abgebrochen wurde --- */
.resume-card {
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-primary-tint-2);
}
.resume-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.resume-badge {
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.resume-time { color: var(--color-text-muted); font-size: var(--text-sm); }
.resume-name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.resume-progress {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.resume-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
@media (max-width: 480px) {
  .resume-actions .btn { flex: 1; justify-content: center; min-height: 48px; }
}

/* --- Druck: Touch-Chrom gehört nicht aufs Papier --- */
@media print {
  .tabbar, .step-answerbar { display: none !important; }
  .guide-step { padding-bottom: 0 !important; }
}

/* ============================================================
   TRICHTER auf Touch
   ============================================================ */
@media (max-width: 960px) {
  /* Zwei Karten pro Reihe — genug Fläche zum Treffen, genug Übersicht */
  .pick-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
  .pick-card { padding: var(--space-2); min-height: 132px; }
  .pick-art svg { max-height: 62px; }
  .pick-name { font-size: var(--text-sm); }
  .pick-sub, .pick-meta { font-size: 11.5px; }

  /* Cockpit untereinander — nebeneinander wird auf dem Phone unlesbar */
  .cockpit { grid-template-columns: 1fr; }
  .cockpit-veh, .cockpit-eng { min-height: 76px; }

  /* Filter-Chips: horizontal wischbar statt umbrechend */
  .chip-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .fchip { flex: none; min-height: 44px; }

  .filter-row { flex-direction: column; gap: var(--space-3); }

  /* Stepper kompakter, aber Knoten bleiben antippbar */
  .stepper { margin-bottom: var(--space-4); }
  .step-dot { width: 44px; height: 44px; }
  .step-node + .step-node::before { top: 21px; }
  .step-label { font-size: 12px; }

  .route { min-height: 96px; }
}

@media (max-width: 380px) {
  /* Auf sehr schmalen Geräten eine Karte pro Reihe — lieber groß als gequetscht */
  .pick-grid { grid-template-columns: 1fr; }
}

/* --- Kopfbereich verdichten: die Fahrzeuge müssen ohne Scrollen sichtbar sein.
   Stepper, Überschrift und zwei Filterzeilen haben vorher den ganzen ersten
   Bildschirm belegt — die Einladung zum Tippen lag unter der Falz. --- */
@media (max-width: 960px) {
  .view-inner .page-title { font-size: 1.375rem; line-height: 1.18; }
  .view-inner .page-lead  { font-size: var(--text-sm); line-height: 1.4; }

  .stepper { gap: 0; margin-bottom: var(--space-3); }
  .step-dot { width: 34px; height: 34px; font-size: 12px; }
  .step-dot svg { width: 14px; height: 14px; }
  /* Nur die rücksprungfähigen Knoten brauchen die volle Trefferfläche —
     ohne das Layout zu verschieben (pro-rules: Hitbox erweitern, nicht Größe). */
  .step-dot:not(:disabled)::after { content: ''; position: absolute; inset: -7px; }
  .step-node + .step-node::before { top: 16px; }
  .step-label { font-size: 11px; }
  .step-value { font-size: 11px; }

  .filter-row {
    gap: var(--space-3);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-3);
  }
  .filter-group { gap: var(--space-1); }
  .fchip { min-height: 40px; }
  .filter-legend { font-size: 10px; }
}

/* --- Messplan auf Touch: Eingabefeld groß genug für nasse Finger --- */
@media (max-width: 960px) {
  /* Eingabe unter den Text statt daneben — nebeneinander wird auf dem
     Phone beides zu schmal und das Urteil läuft über den Rand. */
  .measure-input {
    padding-left: var(--space-4);
    padding-bottom: var(--space-4);
    align-items: flex-start;
  }
  .measure-input-row { flex: none; }
  .verdict { flex-basis: 100%; }
  .measure-input input { width: 8rem; min-height: 48px; font-size: 1.0625rem; }
  .measure-head input[type="checkbox"] { width: 26px; height: 26px; }
  .measure-progress { flex-direction: column; align-items: stretch; gap: var(--space-2); }
  .measure-progress .step-progress-bar { max-width: none; }
  /* Volle Zeile, sonst hängen die beiden Buttons unausgerichtet
     im umbrechenden .page-header. */
  .page-actions { display: flex; width: 100%; gap: var(--space-2); }
  .page-actions .btn { flex: 1; justify-content: center; min-height: 44px; }
}

/* ============================================================
   QUERFORMAT auf flachen Viewports
   Bei 390 px Höhe fressen Topbar, Antwortleiste und Tabbar die Hälfte.
   Ohne diesen Block steht die Diagnosefrage unterhalb der Antwortleiste —
   man soll Ja/Nein tippen, ohne die Frage lesen zu können.
   ============================================================ */
@media (orientation: landscape) and (max-height: 540px) {
  .view-inner { padding-top: var(--space-3); }
  .view-inner .page-title { font-size: 1.125rem; line-height: 1.2; }
  .view-inner .page-lead { display: none; }          /* Kontext weicht dem Inhalt */
  .page-header { margin-bottom: var(--space-3); }

  /* Die Frage ist das Wichtigste auf dem Schirm */
  .step-question { font-size: 1.0625rem; margin-bottom: var(--space-2); }
  .step-progress { margin-bottom: var(--space-2); }
  .step-trail { display: none; }                     /* Rückweg bleibt per Wischen */
  .step-help, .step-measure { font-size: var(--text-sm); }
  .guide-step { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }

  /* Leisten flacher, Trefferflächen bleiben >= 44 px */
  .step-answerbar { padding: var(--space-2) var(--space-3); inset-block-end: calc(49px + env(safe-area-inset-bottom)); }
  .answer { min-height: 46px; }
  .tabbar .tab { min-height: 48px; gap: 1px; }
  .tab svg { width: 19px; height: 19px; }
  .tab span { font-size: 10px; }

  /* Fahrzeugauswahl: mehr Spalten, die Höhe ist knapper als die Breite */
  .pick-grid { grid-template-columns: repeat(4, 1fr); }
  .pick-art svg { max-height: 48px; }
  .stepper { margin-bottom: var(--space-2); }
  .step-dot { width: 30px; height: 30px; }
  .step-node + .step-node::before { top: 14px; }
}

@media (max-width: 960px) {
  /* Quellen-Links sind Trefferflächen, keine reine Typografie */
  .source-list a { display: inline-flex; align-items: center; min-height: 44px; }
}

@media (max-width: 960px) {
  .result-next-item { min-height: 56px; padding: var(--space-3) var(--space-4); }
}

/* ============================================================
   OBD-SCAN auf kleinen Geraeten
   ============================================================ */

@media (max-width: 560px) {
  /* Drei Wortlabels nebeneinander passen bei 320px nicht. Die Ziffern
     tragen den Fortschritt allein — der Text bleibt nur beim aktiven
     Schritt stehen, wo er etwas erklaert. */
  .scan-step-label { display: none; }
  .scan-step.now .scan-step-label { display: inline; }
  .scan-step { flex: 0 0 auto; }
  .scan-step.now { flex: 1; }

  .scan-entry { padding: var(--space-3) var(--space-4); gap: var(--space-3); }
  .scan-entry-sub { font-size: var(--text-xs); }

  /* Zwei Kacheln nebeneinander bleiben lesbar, drei nicht. */
  .live-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .live-tile { min-height: 84px; padding: var(--space-3); }

  /* Code und Beschreibung untereinander — nebeneinander bricht der Text
     nach zwei Zeichen um. */
  .dtc-item { flex-direction: column; gap: var(--space-2); }

  .scan-section-head { flex-direction: column; align-items: stretch; }
  .scan-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .scan-actions .btn { width: 100%; }
}

@media (pointer: coarse) {
  /* Trefferflaechen im Werkstattkontext: mit Handschuh oder oeligen
     Fingern ist 44px die Untergrenze, nicht das Ziel. */
  .scan-big      { min-height: 96px; }
  .scan-entry    { min-height: 80px; }
  .detail-link   { min-height: 52px; }
  .scan-actions .btn { min-height: 48px; }
}

/* Querformat auf dem Handy: die Schrittanzeige frisst sonst die halbe
   Hoehe, obwohl davon nur drei Ziffern uebrig bleiben. */
@media (max-height: 480px) and (orientation: landscape) {
  .scan-steps { margin-bottom: var(--space-3); }
  .scan-step  { padding: var(--space-1) var(--space-2); }
  .live-grid  { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .live-tile  { min-height: 72px; }
  .live-val   { font-size: var(--text-lg); }
}

/* Artikeltabellen auf dem Phone: der Container scrollt, die Seite nicht. */
@media (max-width: 560px) {
  .markdown-content .md-table-wrap table { font-size: var(--text-xs); }
  .markdown-content pre { font-size: 11px; }
}
