/* Design-Tokens aus dem webbasierten Saab CIM Tool (eep/webapp). */
:root {
  color-scheme: dark;
  --bg: #0f1216;
  --bg-elev: #171b21;
  --bg-elev2: #1e242c;
  --border: #2a323d;
  --border-soft: #232a33;
  --text: #e6e9ee;
  --text-dim: #9aa4b2;
  --text-faint: #8b97a8;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --green: #34d399;
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.13);
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Code", "Consolas", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%239aa4b2' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-elev2: #eef1f5;
  --border: #d7dde5;
  --border-soft: #e5e9ef;
  --text: #1a1f27;
  --text-dim: #5b6472;
  --text-faint: #667085;
  --accent-soft: rgba(59, 130, 246, 0.1);
  --amber-soft: rgba(251, 191, 36, 0.18);
  --red-soft: rgba(248, 113, 113, 0.1);
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%235b6472' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

/* Ohne diesen Reset ueberstimmen eigene display-Regeln das hidden-Attribut
   (z. B. .hk-home { display: inline-flex }) und Elemente bleiben sichtbar. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

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

:where(button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- shell */
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 56px auto 1fr;
}

/* ---------------------------------------------------------------- header */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand .logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-text small {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 12px;
}

.header-spacer {
  flex: 1;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 5px 11px;
  background: var(--bg-elev2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  max-width: 46vw;
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
  flex-shrink: 0;
}

.status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.error {
  color: var(--red);
}

.status-pill.error .dot {
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

.status-pill.busy .dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.btn-icon {
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.btn-icon:hover {
  background: var(--bg-elev2);
  color: var(--text);
}

.btn-with-label {
  gap: 6px;
  white-space: nowrap;
}

/* Rueck-Link zur HK-One-Plattform (nur hinter dem Reverse-Proxy sichtbar). */
.hk-home {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px 5px 8px;
  margin-right: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev2);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.hk-home:hover {
  color: var(--text);
  border-color: var(--accent);
}

.hk-home > span:first-child {
  font-size: 15px;
  line-height: 1;
}

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.ui-language select {
  min-width: 94px;
  min-height: 30px;
}

/* Theme-Umschalter: im Dark-Theme Sonne anbieten, im Light-Theme Mond. */
.icon-moon {
  display: none;
}

:root[data-theme="light"] .icon-moon {
  display: block;
}

:root[data-theme="light"] .icon-sun {
  display: none;
}

/* ---------------------------------------------------------------- tabs */
.tabbar {
  display: flex;
  gap: 2px;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 12px 15px 11px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.12s;
  display: flex;
  align-items: center;
  gap: 7px;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-hint {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- panels */
main,
.panel {
  min-height: 0;
}

main {
  display: grid;
}

.panel {
  display: none;
  grid-area: 1 / 1;
  min-width: 0;
}

.panel.active {
  display: grid;
  /* minmax(0, 1fr) statt auto: sonst waechst die Spalte auf die max-content-
     Breite der Toolbar und schiebt die ganze Seite ueber den Viewport hinaus. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
}

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  position: relative; /* Bezug für das Fahrzeugprofil-Panel */
  display: flex;
  align-items: end;
  min-width: 0; /* darf unter die Inhaltsbreite schrumpfen statt zu ueberlaufen */
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border-soft);
  overflow: visible;
}

.toolbar label {
  display: grid;
  gap: 4px;
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 650;
}

select,
input {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

/* Eigener Pfeil statt des nativen: der klebt sonst am Rahmen und sieht
   je nach Plattform anders aus. */
select {
  min-width: 130px;
  cursor: pointer;
  appearance: none;
  padding-right: 30px;
  background-color: var(--bg);
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 11px;
}

select:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

button {
  cursor: pointer;
}

.toolbar button,
.sidebar-head button,
.drawing-controls button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  transition: background 0.13s, border-color 0.13s, transform 0.05s;
}

.toolbar button:hover,
.sidebar-head button:hover,
.drawing-controls button:hover {
  background: var(--border-soft);
  border-color: var(--border);
}

.toolbar button:active,
.sidebar-head button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toolbar button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.search-box {
  display: flex;
  gap: 8px;
  align-items: end;
  margin-left: auto;
}

.search-box input {
  width: min(34vw, 360px);
  min-width: 220px;
}

/* Kein eigener Positionsbezug: das Panel richtet sich an der Toolbar aus,
   sonst wandert es bei mittiger Trigger-Position aus dem Viewport. */
.vehicle-profile {
  flex: 0 0 auto;
}

.vehicle-profile > summary {
  min-height: 32px;
  display: flex;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12.5px;
  list-style-position: inside;
}

.vehicle-profile[open] > summary {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.vehicle-profile-fields {
  position: absolute;
  z-index: 12;
  top: calc(100% + 7px);
  left: 16px; /* bündig mit dem Toolbar-Padding */
  width: min(680px, calc(100% - 32px));
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}

.vehicle-profile-fields label {
  min-width: 0;
}

.vehicle-profile-fields :is(select, input) {
  width: 100%;
  min-width: 0;
}

/* ---------------------------------------------------------------- WIS layout */
.wis-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 30vw) minmax(0, 1fr);
}

.sidebar,
.reader,
.epc-column,
.epc-parts {
  min-height: 0;
  background: var(--bg);
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: grid;
  /* wie beim Panel: sonst waechst die Spalte auf die Breite des laengsten
     Inhalts (z. B. der Breadcrumb in der Kopfzeile) und ueberlaeuft. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 44px 1fr;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

/* Gleiche Schriftmetrik wie der Pfad daneben: bei zentrierten Boxen richten
   sich unterschiedliche Schriftgroessen zwar mittig aus, ihre Grundlinien
   liegen aber versetzt - die Zeile wirkt dann schief. */
.sidebar-head strong {
  font-size: 12px;
  line-height: 18px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 650;
}

.sidebar-head button {
  min-height: 26px;
  padding: 0 10px;
  font-size: 12px;
  line-height: 18px;
}

.sidebar-head-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* Einklapp-Toggle nur auf schmalen Viewports (siehe @media unten). */
.sidebar-toggle {
  display: none;
  min-height: 26px;
  width: 26px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev2);
  color: var(--text-dim);
  cursor: pointer;
}
.sidebar-toggle:hover { color: var(--text); border-color: var(--accent); }
.sidebar-toggle .chev { transition: transform 0.15s ease; }
.sidebar.is-collapsed .sidebar-toggle .chev { transform: rotate(-90deg); }

.tree,
.reader,
.list,
.parts-table {
  overflow: auto;
}

.tree {
  padding: 8px;
}

details {
  border-bottom: 1px solid var(--border-soft);
}

summary {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0 6px;
}

summary:hover {
  background: var(--bg-elev2);
}

.tree-level {
  margin-left: 14px;
  border-left: 1px solid var(--border-soft);
  padding-left: 8px;
}

/* Gleiche Geometrie wie <summary>, damit Buttons und Kategorie-Zeilen
   buendig fluchten (gleiche Hoehe, gleiche Einrueckung, vertikal zentriert). */
.tree button,
.list button {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1.35;
  transition: background 0.13s;
}

.tree button:hover,
.list button:hover {
  background: var(--bg-elev2);
}

.tree button.active,
.list button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.node-meta {
  color: var(--text-faint);
  font-size: 12px;
  font-family: var(--mono);
}

/* Technical Bulletin (TA): Kurzcode SI/TN/MI vor dem Titel. */
.node-bulletin {
  flex: none;
  min-width: 24px;
  padding: 1px 5px;
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-radius: 4px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: center;
}

.tree-hint {
  margin: 10px 8px;
  color: var(--text-dim);
  font-size: 13px;
}

/* Umschalter in der Toolbar (z. B. "Nur Bulletins"). */
.toolbar .toggle-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  white-space: nowrap;
  cursor: pointer;
}

.toggle-field input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Kategorie ohne Artikel: klar kennzeichnen statt beim Klick ins Leere laufen. */
.node-empty {
  margin-left: auto;
  padding: 1px 7px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-elev2);
  color: var(--text-faint);
  font-size: 11px;
  white-space: nowrap;
}

details.is-empty > summary {
  color: var(--text-faint);
}

/* Pfad-Anzeige in der eingeklappten Navigationsleiste (nur Mobile sichtbar). */
.sidebar-context {
  display: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
  font-size: 12px;
}

.tree span + .node-meta {
  margin-left: 0.35em;
}

/* ---------------------------------------------------------------- reader */
.reader {
  position: relative;
  padding: 22px;
}

.article-actions {
  position: sticky;
  top: -22px;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: -10px 0 10px;
  padding: 8px 0;
  background: linear-gradient(var(--bg) 75%, transparent);
}

.article-actions[hidden] {
  display: none;
}

.article-actions button,
.row-actions button,
.worklist button,
.mobile-back {
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev2);
  color: var(--text);
}

.article-actions button:hover,
.row-actions button:hover,
.worklist button:hover {
  border-color: var(--accent);
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-faint);
  text-align: center;
  padding: 22px;
}

.empty-state[hidden] {
  display: none;
}

.empty-state .empty-icon {
  font-size: 40px;
  opacity: 0.5;
}

.empty-state h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0;
}

.empty-state p {
  max-width: 380px;
  font-size: 13px;
  margin: 0;
}

.article {
  max-width: 1080px;
}

.article:empty {
  display: none;
}

.article-body {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px 24px;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
}

.article-body * {
  font-family: var(--sans) !important;
  color: var(--text) !important;
  background-color: transparent !important;
}

.article-body table {
  max-width: 100%;
  border-collapse: collapse !important;
  border-color: var(--border-soft) !important;
}

.article-body td {
  border-color: var(--border-soft) !important;
  font-size: 13.5px !important;
  line-height: 1.45 !important;
  padding: 7px 9px !important;
  vertical-align: top;
}

.article-body img {
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 6px;
}

.article-body a {
  color: var(--accent) !important;
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h2[style] {
  font-size: 17px !important;
  margin: 18px 0 8px !important;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 5px;
  font-weight: 650;
}

.article-body p {
  margin: 0 0 10px !important;
}

/* Modernisierte Überschriften (ersetzen die blauen Legacy-Titelbalken) */
.article-body h1.wis-heading-title {
  font-size: 20px !important;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 14px !important;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.article-body h2.wis-heading {
  font-size: 15px !important;
  font-weight: 650;
  margin: 22px 0 8px !important;
  padding-bottom: 0;
  border-bottom: none;
}

/* Callouts: Warnung / Achtung / Anmerkung im Stil der CIM-Banner */
.article-body .callout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 640px;
  margin: 10px 0 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  font-size: 13px;
}

.article-body .callout-icon {
  display: flex;
  flex-shrink: 0;
  margin-top: 1px;
}

.article-body .callout-main {
  min-width: 0;
}

.article-body .callout-title {
  display: block;
  font-size: 11px !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.article-body .callout-body p {
  margin: 0 0 6px !important;
  font-size: 13px !important;
}

.article-body .callout-body p:last-child {
  margin-bottom: 0 !important;
}

.article-body .callout.danger {
  background-color: var(--red-soft) !important;
  border-color: rgba(248, 113, 113, 0.3);
}

.article-body .callout.danger .callout-icon,
.article-body .callout.danger .callout-icon *,
.article-body .callout.danger .callout-title {
  color: var(--red) !important;
}

.article-body .callout.caution {
  background-color: var(--amber-soft) !important;
  border-color: rgba(251, 191, 36, 0.3);
}

.article-body .callout.caution .callout-icon,
.article-body .callout.caution .callout-icon *,
.article-body .callout.caution .callout-title {
  color: var(--amber) !important;
}

.article-body .callout.note {
  background-color: rgba(52, 211, 153, 0.1) !important;
  border-color: rgba(52, 211, 153, 0.3);
}

.article-body .callout.note .callout-icon,
.article-body .callout.note .callout-icon *,
.article-body .callout.note .callout-title {
  color: var(--green) !important;
}

/* Im Light-Theme brauchen die Callout-Farben mehr Kontrast. */
:root[data-theme="light"] .article-body .callout.danger .callout-icon,
:root[data-theme="light"] .article-body .callout.danger .callout-icon *,
:root[data-theme="light"] .article-body .callout.danger .callout-title {
  color: #dc2626 !important;
}

:root[data-theme="light"] .article-body .callout.caution .callout-icon,
:root[data-theme="light"] .article-body .callout.caution .callout-icon *,
:root[data-theme="light"] .article-body .callout.caution .callout-title {
  color: #b45309 !important;
}

:root[data-theme="light"] .article-body .callout.note .callout-icon,
:root[data-theme="light"] .article-body .callout.note .callout-icon *,
:root[data-theme="light"] .article-body .callout.note .callout-title {
  color: #047857 !important;
}

/* ---------------------------------------------------------------- WIS gallery */
.wis-gallery {
  display: grid;
  gap: 0;
  margin: 0 0 18px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
}

.wis-gallery-main {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  min-height: 260px;
}

.wis-gallery-main img {
  max-width: 100%;
  max-height: 58vh;
  justify-self: center;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}

.gallery-nav {
  height: 100%;
  min-height: 260px;
  border: 0;
  border-radius: 0;
  background: var(--bg-elev2);
  color: var(--text-dim);
  font-size: 22px;
  transition: background 0.13s, color 0.13s;
}

.gallery-nav:hover {
  background: var(--border-soft);
  color: var(--text);
}

.wis-gallery-strip {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border-soft);
  overflow-x: auto;
}

.wis-gallery-strip button {
  min-width: 34px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--bg-elev2);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 12.5px;
}

.wis-gallery-strip button:hover {
  background: var(--border-soft);
  color: var(--text);
}

.wis-gallery-strip button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------------------------------------------------------------- EPC layout */
.epc-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px 360px 1fr;
}

.epc-column,
.epc-parts {
  display: grid;
  grid-template-rows: 40px 1fr;
  border-right: 1px solid var(--border);
}

.epc-column {
  background: var(--bg-elev);
}

.epc-parts {
  border-right: 0;
}

.epc-detail {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, 46vh) minmax(220px, 1fr);
  overflow: hidden;
}

.epc-column header,
.epc-parts header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 650;
}

.epc-parts header #epc-section-meta {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.list {
  padding: 6px;
}

/* ---------------------------------------------------------------- drawing */
.drawing {
  margin: 0;
  min-height: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  position: relative;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.drawing.dragging {
  cursor: grabbing;
}

.image-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  transform-origin: center center;
  will-change: transform;
}

.drawing img {
  display: block;
  max-width: 100%;
  max-height: calc(46vh - 20px);
  width: auto;
  height: auto;
  image-rendering: auto;
  pointer-events: none;
  user-select: none;
  background: #fff;
  border-radius: 6px;
}

.drawing[hidden] {
  display: none;
}

.marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.position-marker {
  position: absolute;
  display: block;
  min-width: 16px;
  min-height: 16px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 3px;
  outline: 1px solid rgba(248, 113, 113, 0.75);
  outline-offset: 2px;
  background: rgba(248, 113, 113, 0.08);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.42);
  pointer-events: auto;
  cursor: pointer;
}

.position-marker.active {
  z-index: 2;
  outline-width: 3px;
  outline-color: var(--amber);
  background: rgba(251, 191, 36, 0.2);
}

.drawing.markers-hidden .position-marker {
  display: none;
}

.drawing-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev2);
  box-shadow: var(--shadow);
  cursor: default;
}

.drawing-controls button,
.drawing-controls output {
  min-width: 30px;
  min-height: 26px;
  height: 26px;
  padding: 0 8px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  line-height: 1;
  font-size: 13px;
}

.drawing-controls output {
  min-width: 46px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
}

/* ---------------------------------------------------------------- lists */
.list-title {
  display: block;
  font-weight: 600;
}

.list-subtitle {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 2px;
}

.tree button.active .node-meta,
.list button.active .list-subtitle {
  color: inherit;
  opacity: 0.75;
}

/* ---------------------------------------------------------------- parts table */
table.parts {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.parts th,
.parts td {
  border-bottom: 1px solid var(--border-soft);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}

.parts th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-elev);
  color: var(--text-faint);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 650;
}

.parts td strong {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12.5px;
}

.parts tbody tr {
  cursor: pointer;
}

.parts tbody tr:hover {
  background: var(--bg-elev2);
}

.parts tbody tr.active-position {
  background: var(--amber-soft);
  outline: 2px solid var(--amber);
  outline-offset: -2px;
}

.parts tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.parts .row-actions {
  width: 1%;
  white-space: nowrap;
}

.row-actions button {
  min-width: 29px;
  margin: 0 2px;
  font-size: 12px;
}

.search-summary {
  padding: 5px 8px 9px;
}

.empty-state.compact {
  min-height: 180px;
}

.mobile-back {
  display: none;
  margin-right: 8px;
  min-width: 28px;
  padding: 0 7px;
}

/* ---------------------------------------------------------------- worklist */
.worklist {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  width: min(430px, 100vw);
  height: 100vh;
  height: 100dvh;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.worklist[hidden] {
  display: none;
}

.worklist > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.worklist h2 {
  margin: 0;
  font-size: 17px;
}

.worklist-items {
  min-height: 0;
  overflow: auto;
}

.worklist-item {
  display: grid;
  gap: 6px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border-soft);
}

.worklist-item > span:not(.pill) {
  color: var(--text-dim);
  font-size: 12.5px;
}

.worklist-item > div {
  display: flex;
  gap: 6px;
}

.worklist-item .pill {
  width: max-content;
}

.empty-worklist {
  color: var(--text-dim);
  text-align: center;
  margin: 40px 12px;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

.error {
  color: var(--red);
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
  }

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

  .status-pill.busy,
  .status-pill.error {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 30;
    width: auto;
    max-width: calc(100vw - 24px);
    height: auto;
    padding: 7px 12px;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .brand-text small,
  .btn-with-label > span:nth-child(2) {
    display: none;
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
    overflow-x: auto;
  }

  .search-box {
    width: 100%;
    margin-left: 0;
  }

  .vehicle-profile {
    width: 100%;
  }

  .vehicle-profile-fields {
    position: static;
    width: 100%;
    margin-top: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    box-shadow: none;
  }

  .search-box input {
    width: 100%;
    min-width: 0;
    flex: 1;
  }

  .wis-layout,
  .epc-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Suchfeld darf schrumpfen; sonst erzwingt min-width einen Ueberlauf. */
  .search-box input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .epc-layout[data-mobile-current="groups"] [data-mobile-step]:not([data-mobile-step="groups"]),
  .epc-layout[data-mobile-current="sections"] [data-mobile-step]:not([data-mobile-step="sections"]),
  .epc-layout[data-mobile-current="parts"] [data-mobile-step]:not([data-mobile-step="parts"]) {
    display: none;
  }

  .mobile-back {
    display: inline-grid;
    place-items: center;
  }

  .sidebar,
  .epc-column {
    min-height: 280px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  /* Auf Mobile ist der Navigationsbaum einklappbar, damit man nicht erst am
     ganzen Baum vorbeiscrollen muss, um zum Artikel zu kommen. */
  .sidebar-toggle {
    display: inline-grid;
  }

  /* Groessere Touch-Ziele; Buttons und Kategorien gleich hoch. */
  .sidebar-head {
    min-height: 48px;
  }

  .sidebar-toggle {
    width: 34px;
    height: 34px;
    min-height: 34px;
    flex: none;
  }

  .tree button,
  .tree summary {
    min-height: 40px;
  }

  /* Eingeklappt: eine vollwertige, gut greifbare Leiste statt eines duennen
     Streifens - inkl. Pfad, damit erkennbar bleibt, dass es dort weitergeht. */
  .sidebar.is-collapsed {
    min-height: 0;
    grid-template-rows: auto;
    background: var(--bg-elev2);
    border-bottom: 1px solid var(--border);
  }

  .sidebar.is-collapsed .sidebar-head {
    min-height: 52px;
  }

  .sidebar.is-collapsed .sidebar-context {
    display: block;
  }

  .sidebar.is-collapsed .tree {
    display: none;
  }

  .reader,
  .epc-parts {
    min-height: 420px;
  }

  .epc-detail {
    grid-template-rows: minmax(260px, 42vh) minmax(260px, 1fr);
  }

  .drawing img {
    max-height: calc(42vh - 20px);
  }

  .panel.active {
    height: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    gap: 8px;
    padding: 0 10px;
  }

  .brand-text {
    display: none;
  }

  /* Rueck-Link auf den Pfeil reduzieren - "HK One" kostet sonst ~50px
     Kopfzeilen-Breite, die auf schmalen Geraeten fehlen. */
  .hk-home {
    padding: 5px 9px;
  }

  .hk-home > span:last-child {
    display: none;
  }

  .ui-language select {
    /* 82px schnitt "Deutsch" ab - genug Platz fuer Label + Pfeil lassen. */
    min-width: 104px;
    width: auto;
  }

  .reader {
    padding: 12px;
  }

  .vehicle-profile-fields {
    grid-template-columns: 1fr;
  }

  .article-body {
    padding: 14px;
  }

  .parts th,
  .parts td {
    padding: 7px 6px;
  }

  .parts th:nth-child(4),
  .parts td:nth-child(4),
  .parts th:nth-child(5),
  .parts td:nth-child(5) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .topbar,
  .tabbar,
  .toolbar,
  .sidebar,
  .article-actions,
  #epc-panel,
  .worklist {
    display: none !important;
  }

  html,
  body,
  .app-shell,
  main,
  .panel,
  .wis-layout,
  .reader {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #000 !important;
  }

  .reader {
    padding: 0;
  }

  .article-body {
    border: 0;
    padding: 0;
  }
}
