:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e2e7ee;
  --ink: #1f2630;
  --muted: #7a8696;
  --accent: #1a8cff;
  --accent-ink: #ffffff;
  --ok: #18a558;
  --no: #d8443a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  /* Touch/iPad: kein Gummiband-Scrollen, keine Doppeltipp-Zoom-Verzoegerung */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
/* Bedienelemente reagieren ohne 300ms-Verzoegerung; keine Textauswahl beim Tippen */
.btn, .swatch, .lang-select, select, label { touch-action: manipulation; }
#toolbar, .group, .seg, .menu-pop { -webkit-user-select: none; user-select: none; }

/* Toolbar — zweizeilig */
#toolbar {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  z-index: 10;
}

/* Hauptzeile: scrollbarer linker Teil + fixierter rechter Teil */
#toolbar-main { display: flex; align-items: stretch; }

#toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  flex: 1 1 0;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#toolbar-left::-webkit-scrollbar { display: none; }

#toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  position: relative; /* Anker für Hamburger-Dropdown */
}

/* Desktop: inner = normaler Inline-Flex-Container */
#toolbar-right-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Icon-Gruppe: Desktop = inline Flex-Row (fügt sich nahtlos ein) */
.toolbar-icon-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Hamburger: nur auf Mobile sichtbar */
#btn-hamburger { display: none; }

/* Kontextzeile: Bauteil-Auswahl + Farbe */
#toolbar-ctx {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  border-top: 1px solid var(--line);
  background: #f7f9fc;
  /* Kein overflow hier — nur #grp-build scrollt intern */
}
/* Bauteil-Gruppe nimmt alle verfügbare Breite und scrollt intern. */
#toolbar-ctx #grp-build {
  flex: 1 1 0;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#toolbar-ctx #grp-build::-webkit-scrollbar { display: none; }
/* Kein Umbruch in der Bauteil-Gruppe */
#toolbar-ctx .part-row { flex-wrap: nowrap; }
/* Farbe-Gruppe und alle anderen ctx-Kinder nicht schrumpfen */
#toolbar-ctx .group { flex-shrink: 0; }
/* Auch die einzelnen Knöpfe nicht: "Auswahl" und "Verstärken" hängen direkt in
   #grp-build (nicht in einer .part-row) und wurden sonst schmaler als ihre
   Beschriftung gequetscht, statt die Gruppe scrollen zu lassen. */
#toolbar-ctx .btn { flex-shrink: 0; }

.brand { font-weight: 800; letter-spacing: 0.5px; font-size: 18px; white-space: nowrap; }
.brand span { color: var(--accent); font-weight: 700; }
.group { display: flex; align-items: center; gap: 6px; }
.group > label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; }

/* Senkrechter Trenner zwischen Toolbar-Bereichen */
/* EIN Trenner für alle Leisten: gleiche Höhe in der Kopf- und in der
   Bauteil-Zeile -- vorher sah der eine gestreckt, der andere kurz aus. */
.divider {
  width: 1px; height: 20px; align-self: center;
  background: var(--line); margin: 0 5px; flex-shrink: 0;
}
/* Trenner, der nach dem Umhängen von Knöpfen nichts mehr trennt (siehe
   tidyDividers in ui.js). */
.divider.divider-off { display: none; }

/* Autosave-Anzeige als kleiner Statuspunkt (jetzt im Entwürfe-Button) */


/* Bauteil-Leiste (Rohre + Platten gemeinsam) */
.part-row { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.btn.part {
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 4px 7px; min-width: 36px; line-height: 1.1;
}
.btn.part svg { display: block; }
.btn.part span { font-size: 11px; font-variant-numeric: tabular-nums; }

/* Aktive Bauteil-Buttons: in der gewählten Baufarbe einfärben */
.btn.part[data-tube].active,
.btn.part[data-panel].active {
  background: var(--part-bg, var(--accent));
  border-color: var(--part-bg, var(--accent));
  color: var(--part-ink, var(--accent-ink));
  box-shadow: none;
}

/* Löschen-Button: pinned rechts in toolbar-ctx, rot wenn aktiv */
.delete-part { flex-shrink: 0; }
.delete-part.active {
  background: var(--no);
  border-color: var(--no);
  color: #fff;
  box-shadow: none;
}

/* Disabled-Zustand für Part-Buttons (z. B. Undo wenn leer) */
.btn.part:disabled { opacity: 0.38; cursor: default; }
.btn.part:disabled:hover { border-color: var(--line); background: #fff; }

/* Varianten-Popup unter den Bauteil-Buttons (Rohre / Platten) */
.part-popup {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  min-width: 180px;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  z-index: 200;
}
.part-popup-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px;
  border: none; border-radius: 7px;
  background: none; color: var(--ink);
  font-size: 13px; font-family: inherit; text-align: left;
  cursor: pointer;
}
.part-popup-row:hover { background: #f1f4f8; }
.part-popup-row.active { background: var(--accent); color: var(--accent-ink); }
.part-popup-row svg { flex: 0 0 auto; }
.part-popup-row .pp-name { flex: 1; white-space: nowrap; }
.btn.icon-btn { display: inline-flex; align-items: center; gap: 5px; }
.btn.icon-btn svg { display: block; }

/* Segmentierte Modus-Gruppe */
.group.seg { gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.group.seg .btn { border: none; border-radius: 0; border-right: 1px solid var(--line); }
.group.seg .btn:last-child { border-right: none; }
.group.seg .btn.active { box-shadow: none; }

/* Dropdown-Menue (Entwuerfe/Datei) */
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  padding: 10px; width: 260px;
  max-width: min(260px, calc(100vw - 28px));
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
/* Entwürfe-Menü: breiter, damit lange Dateinamen lesbar bleiben */
#file-pop {
  width: min(380px, calc(100vw - 28px));
}
#file-pop select { max-width: none; }
.menu-section { display: flex; flex-direction: column; gap: 6px; }
.menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.menu-row { display: flex; gap: 6px; align-items: center; }
.menu-row select { flex: 1; max-width: none; }
.menu-row .menu-label { white-space: nowrap; }
.menu-sep { border: none; border-top: 1px solid var(--line); margin: 2px 0; }
.btn.full { width: 100%; justify-content: center; }
.menu-row .btn.full { flex: 1; }
.menu-item { text-align: left; justify-content: flex-start; }
.btn.danger { color: var(--no); }
.btn.danger:hover { border-color: var(--no); background: #fdeceb; }
.menu-pop hr, .menu-section + .btn { margin-top: 2px; }
/* Einstellungen: schmaler als das Entwürfe-Menü, Hinweis ohne Extra-Abstand */
#settings-pop { width: min(240px, calc(100vw - 28px)); }
#settings-pop select { width: 100%; max-width: none; }
#settings-pop .hint { margin-top: 2px; }
/* Quadratische Icon-Buttons */
.btn.icon-sq { padding: 6px 8px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.btn:hover { border-color: #c4ccd6; }
/* Gesperrt heisst blass -- gilt für jeden Knopf, nicht nur die Bauteil-Zeile
   (Zurück/Wieder stehen jetzt oben in der Kopfzeile). */
.btn:disabled { opacity: 0.38; cursor: default; }
.btn:disabled:hover { border-color: var(--line); background: #fff; }
.btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { padding: 7px 11px; color: #45505f; }
.lang-btn { font-weight: 600; letter-spacing: 0.04em; min-width: 2.8em; }
.lang-select {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.12s ease;
  font-family: inherit;
}
.lang-select:hover { border-color: #c4ccd6; }
.lang-select:focus { outline: none; border-color: var(--accent); }

select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  max-width: 200px;
}

.swatches { display: flex; gap: 5px; }
.swatch {
  background: var(--swatch);
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  outline: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
}
.swatch.active { outline: 2px solid var(--ink); transform: scale(1.08); }
/* Zufallsfarbe: alle Baufarben als Tortenstuecke, damit der Schalter ohne
   Beschriftung erkennbar ist (Schwarz ist dabei, weil Platten es duerfen). */
.swatch-random {
  background: conic-gradient(
    #d42e2e 0deg 72deg, #2e9e4a 72deg 144deg, #f4c020 144deg 216deg,
    #1f63b5 216deg 288deg, #2b2b2b 288deg 360deg);
}

/* --- Kollaps: enge Bauteil-Zeile --------------------------------------- */
/* Stufe 1 nimmt die Farbreihe weg und zeigt EINEN Swatch-Knopf, Stufe 2 legt
   die Ansichts-Schalter hinter ein Ausklapp-Panel. Welche Stufe gilt, misst
   ui.js -- hier steht nur, was die Klasse bewirkt. */
body.compact-colors #color-buttons,
body.compact-view .view-row { display: none; }
/* Der Trenner davor bleibt: er scheidet jetzt Bauteile von den Ansichts-
   Schaltern. Ob er gebraucht wird, entscheidet tidyDividers in ui.js. */
/* Im Popup gilt das nicht: dort SOLL die umgehängte Gruppe zu sehen sein. */
.part-popup #color-buttons,
.part-popup .view-row { display: flex !important; }
/* Im Popup werden aus den Icon-Knöpfen Listenzeilen mit Icon UND Name --
   ohne Beschriftung rät man bei Schnitt/Perspektive nur. Versteckt wird der
   Name nur DORT, wo er stört: in den Werkzeugleisten selbst. */
.view-row .pp-name,
#color-buttons .pp-name,
.toolbar-icon-row .pp-name { display: none; }
.part-popup .pp-name,
/* Mit ID, sonst gewinnt #color-buttons oben und die Farben blieben namenlos. */
.part-popup #color-buttons .pp-name,
#menu-file-rows .pp-name { display: block; flex: 1; text-align: left; white-space: nowrap; font-size: 13px; }
.part-popup.color-popup #color-buttons,
.part-popup.view-popup .view-row { flex-direction: column; align-items: stretch; gap: 2px; }
.part-popup.view-popup .btn,
.part-popup.color-popup .swatch {
  display: flex; align-items: center; gap: 10px;
  justify-content: flex-start; text-align: left;
  width: 100%; padding: 7px 8px;
  border: none; border-radius: 7px; background: none; outline: none;
  color: var(--ink); font-family: inherit; min-height: 0;
}
.part-popup.view-popup .btn:hover,
.part-popup.color-popup .swatch:hover { background: #f1f4f8; }
.part-popup.view-popup .btn.active,
.part-popup.color-popup .swatch.active { background: var(--accent); color: var(--accent-ink); }
/* Der Farbtupfer wandert in ein eigenes Kästchen vor dem Namen. */
.part-popup.color-popup .swatch { position: relative; padding-left: 36px; transform: none; }
.part-popup.color-popup .swatch::before {
  content: ""; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--swatch); outline: 1px solid var(--line);
}
.part-popup.color-popup .swatch-random::before {
  background: conic-gradient(
    #d42e2e 0deg 72deg, #2e9e4a 72deg 144deg, #f4c020 144deg 216deg,
    #1f63b5 216deg 288deg, #2b2b2b 288deg 360deg);
}

/* Der Ersatz-Knopf für die Farbreihe: Swatch statt Icon */
#btn-color { padding: 5px 7px; }
#btn-color .swatch { display: block; pointer-events: none; }

/* Main */
:root { --sidebar-w: 320px; }
main { flex: 1; display: flex; min-height: 0; }
#canvas-wrap { position: relative; flex: 1; min-width: 0; }
#canvas { position: absolute; inset: 0; touch-action: none; overflow: hidden; }
/* Der Canvas folgt immer exakt seinem Container. Feste px-Groessen (von
   renderer.setSize) wuerden ihn ueber den Container hinauswachsen lassen ->
   Dokument-Scrollbar -> Container schrumpft -> ResizeObserver -> Flackern. */
#canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Floating Canvas-Buttons (Tastenkürzel, ggf. weitere) */
.canvas-btn {
  position: absolute;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.13);
  border-radius: 8px;
  cursor: pointer;
  padding: 7px 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  color: var(--ink);
  z-index: 10;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.12s ease;
}
.canvas-btn:hover { background: #fff; transform: scale(1.06); box-shadow: 0 4px 14px rgba(0,0,0,0.22); }
.canvas-btn:active { transform: scale(0.94); }
#btn-help { bottom: 12px; right: 12px; }

/* Szene-Toggle-Icon: Kreis links oben im 3D-Viewport */
.scene-icon {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  width: 48px; height: 48px; padding: 0; border: none;
  border-radius: 50%; overflow: hidden; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.30);
  transition: filter 0.25s, opacity 0.25s, box-shadow 0.2s, transform 0.1s;
  outline: 2px solid rgba(255,255,255,0.55);
  outline-offset: 1px;
}
.scene-icon:hover { transform: scale(1.08); box-shadow: 0 4px 14px rgba(0,0,0,0.35); }
.scene-icon:active { transform: scale(0.96); }
.scene-icon.off { filter: grayscale(1); opacity: 0.45; outline-color: rgba(0,0,0,0.15); }
body.resizing { cursor: col-resize; user-select: none; }

/* Ziehgriff zwischen Canvas und Seitenleiste */
#sidebar-resizer {
  width: 6px; flex: 0 0 6px; cursor: col-resize;
  background: var(--line); opacity: 0.35;
  transition: opacity 0.15s ease;
}
#sidebar-resizer:hover, body.resizing #sidebar-resizer { opacity: 1; background: var(--accent); }
body.sidebar-hidden #sidebar, body.sidebar-hidden #sidebar-resizer { display: none; }

/* Gewähltes Bauteil: oben mittig über der Szene, Gegenstück zur Statuszeile
   unten links. Zeigt, was gerade "in der Hand" liegt. */
.current-part {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 38, 48, 0.82);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.status {
  position: absolute;
  left: 12px; bottom: 12px;
  background: rgba(31, 38, 48, 0.82);
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 70%;
  pointer-events: none;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  /* Kein Innenabstand oben: die Tab-Leiste sitzt bündig, der Abstand kommt
     beim Inhalt darunter (.panel). */
  padding: 0 14px 14px;
}
.panel { margin-bottom: 22px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.panel h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); margin: 14px 0 6px;
}

.bom-list { display: flex; flex-direction: column; gap: 3px; }
.bom-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.bom-row:nth-child(odd) { background: #f7f9fc; }
.bom-row.muted { color: var(--muted); }
.bom-name { display: flex; align-items: center; gap: 7px; }
.bom-count { font-variant-numeric: tabular-nums; color: var(--muted); }
.bom-sub { font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.dot { width: 11px; height: 11px; border-radius: 50%; outline: 1px solid rgba(0,0,0,0.12); flex-shrink: 0; }
.muted { color: var(--muted); font-size: 13px; padding: 4px 6px; }

.totals {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 5px;
}
.totals div { display: flex; justify-content: space-between; font-size: 13px; }
.totals span { color: var(--muted); }
.totals strong { font-variant-numeric: tabular-nums; }

/* Inventory */
/* Schnittebene: schwebende Leiste oben mittig über dem Viewport */
#slice-bar {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  z-index: 6;
}
#slice-bar .btn.small { padding: 4px 9px; font-size: 12px; }
#slice-bar .seg .btn { min-width: 28px; }
#slice-range { width: 220px; }
.slice-value {
  font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--muted); min-width: 56px; text-align: right;
}

/* Auswahl-Rechteck im Cursor-Modus (Drag über dem Canvas) */
.select-box {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(26, 140, 255, 0.14);
  pointer-events: none;
  z-index: 5;
}

/* Aussenmasse des Modells über der Bestandsliste */
.model-size {
  display: flex; gap: 6px;
  margin-bottom: 10px;
}
.model-size .dim {
  flex: 1;
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 8px;
  background: #f4f6f9; border-radius: 8px;
}
.model-size .dim-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
}
.model-size .dim-value { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

.feasibility {
  font-size: 13px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 10px;
  min-height: 0;
}
.feasibility:empty { display: none; }
.feasibility.ok { background: #e6f7ee; color: var(--ok); }
.feasibility.no { background: #fdeceb; color: var(--no); }

.inv-list { display: flex; flex-direction: column; gap: 4px; }
.inv-row {
  display: grid;
  grid-template-columns: 1fr auto 58px auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
}
.inv-row.bad { background: #fdeceb; }
/* Bestandszeile ist anklickbar; die markierte hebt ihre Teile im Modell hervor.
   Muss NACH .bad stehen, sonst gewinnt dort der rote Hintergrund. */
.inv-row { cursor: pointer; }
.inv-row.marked { background: #fff3e3; box-shadow: inset 0 0 0 1px #ffb765; }
.inv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-need { color: var(--muted); font-size: 12px; }
.inv-input { width: 56px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.inv-status { font-size: 12px; color: var(--muted); min-width: 54px; text-align: right; }
.inv-row.bad .inv-status { color: var(--no); font-weight: 600; }

.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.45; }

/* Bestandseditor */
.inv-editor-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 14px;
}
.inv-editor-head h3 { margin: 0; }
.inv-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.inv-editor { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.inv-grp {
  margin: 8px 0 2px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.inv-edit-row {
  display: grid; grid-template-columns: 1fr 58px; gap: 8px;
  align-items: center; font-size: 13px; padding: 2px 6px;
}

/* hidden muss display:flex der .group ueberschreiben */
[hidden] { display: none !important; }

/* Button-Reihen (Rohr-/Platten-Auswahl) */
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; }
.btn.small { padding: 6px 9px; font-size: 13px; min-width: 34px; font-variant-numeric: tabular-nums; }

/* Karten in den Overlays (Hilfe, Rückfragen) */
.help-card {
  background: #fff; border-radius: 12px; padding: 20px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  max-width: 380px; width: 90%;
}
.help-card h3 { margin: 0 0 12px; font-size: 16px; }
.help-card table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.help-card td { padding: 5px 4px; font-size: 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-card td:first-child { font-weight: 600; white-space: nowrap; padding-right: 14px; }

/* Modell-Bibliothek */
/* Zustand des Server-Abgleichs. Steht nur da, wenn die Verbindung in dieser
   Sitzung schon einmal stand -- ohne Server sagt die Liste nichts dazu. */
.sync-line { margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.sync-line::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #2ea043; flex: 0 0 auto;
}
.sync-line.sync-off::before { background: #d29922; }

.lib-actions { display: flex; gap: 4px; margin: 10px 0 8px; }
.lib-actions .btn { flex: 1; }
.lib-actions .btn.danger { flex: 0 0 auto; }
.lib-search {
  width: 100%; padding: 6px 9px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.lib-search:focus { outline: none; border-color: var(--accent); }
.lib-opt { display: flex; align-items: center; gap: 7px; font-size: 12px; margin: 8px 0 4px; cursor: pointer; }
.lib-status { font-size: 11px; color: var(--muted); min-height: 1.2em; margin-bottom: 6px; }
.lib-list { display: flex; flex-direction: column; gap: 4px; }
.lib-row {
  display: flex; flex-direction: column; gap: 2px;
  padding: 7px 9px; text-align: left; font-family: inherit;
  border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
}
.lib-row:hover { border-color: var(--accent); border-left-color: var(--accent); }
.lib-row.ok { border-left-color: var(--ok); }
.lib-row-head { display: flex; align-items: baseline; gap: 8px; }
.lib-name { flex: 1; font-size: 13px; font-weight: 600; }
.lib-badge {
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--no); flex: 0 0 auto;
}
.lib-row.ok .lib-badge { color: var(--ok); }
.lib-meta { font-size: 11px; color: var(--muted); }

/* Aufbaumodus */
.asm-head { display: flex; align-items: center; justify-content: space-between; }
.asm-head h2 { margin: 0; }
.asm-nav { display: flex; align-items: center; gap: 8px; margin: 12px 0 8px; }
.asm-nav .btn { padding: 6px 14px; font-size: 16px; line-height: 1; }
.asm-nav .btn:disabled { opacity: 0.4; cursor: default; }
.asm-counter { flex: 1; text-align: center; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.asm-progress { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 12px; }
#asm-progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s ease; }
.asm-title { font-size: 14px; color: var(--ink); margin: 0 0 8px; text-transform: none; letter-spacing: 0; }
.asm-body { display: flex; flex-direction: column; gap: 2px; }
.asm-cat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 12px 0 4px; }
.asm-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 6px 6px; border-radius: 6px; font-size: 13px;
}
.asm-row:nth-child(even) { background: #f7f9fc; }
.asm-name { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.asm-count { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
/* Zeilen sind anklickbar: hebt die Teile des Schritts im Modell hervor.
   Muss NACH .asm-row:nth-child(even) stehen, sonst gewinnt der Zebrastreifen. */
.asm-row { cursor: pointer; }
.asm-row.marked { background: #f3e8ff; box-shadow: inset 0 0 0 1px #c79bff; }
.asm-opt {
  display: flex; align-items: center; gap: 7px;
  margin: 2px 0 8px; font-size: 12px; color: var(--muted); cursor: pointer;
}
.asm-opt input { cursor: pointer; }
.asm-badge {
  font-size: 11px; font-weight: 700; color: #45505f;
  background: #eef2f7; border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 6px; font-variant-numeric: tabular-nums;
}

/* Responsive — das Layout richtet sich NICHT nach festen Breakpoints, sondern
   nach dem, was ui.js misst und als Klasse auf <body> setzt:
   compact-colors / compact-view  — Bauteil-Zeile wird eng (Kollaps-Stufen)
   compact-head                   — Kopfzeile wird eng (Menü-Knopf)
   sidebar-overlay                — Seitenleiste legt sich über die Seite
   mobile-portrait                — Telefon im Hochformat (Bedienung unten) */

/* Kopfzeile: nichts wird gequetscht -- läuft die Zeile über, klappt ui.js
   stufenweise ein (erst "Automatisch speichern", dann das Menü). */
#toolbar-left > * { flex-shrink: 0; }
/* Stufe 1: nur noch der Kasten, der Text wandert in den Tooltip. */
body.compact-autosave #toolbar-left .autosave-toggle span { display: none; }
body.compact-autosave #toolbar-left .autosave-toggle { padding: 0 2px; }

/* --- Enge Kopfzeile ----------------------------------------------------
   Reicht der Platz oben nicht, bleiben Datei, Zurück und Wieder stehen; alles
   Weitere hängt ui.js in das Menü (#toolbar-right-inner), der Seitenleisten-
   Schalter rückt neben den Menü-Knopf. */
body.compact-head .brand span { display: none; }
body.compact-head .hide-mobile { display: none !important; }
body.compact-head #toolbar-left  { padding: 5px 10px; gap: 6px; }
body.compact-head #toolbar-right { padding: 5px 8px; gap: 4px; border-left: none; }
body.compact-head #btn-hamburger { display: inline-flex !important; }

body.compact-head #toolbar-right-inner {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.13);
  padding: 8px;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 220px;
  z-index: 300;
}
body.compact-head #toolbar-right-inner.open { display: flex; }
/* Im Menü stehen die Einträge untereinander und über die volle Breite. */
body.compact-head #menu-extra { display: flex; flex-direction: column; gap: 6px; }
body.compact-head #menu-extra .group.seg { width: 100%; }
body.compact-head #menu-extra .group.seg .btn { flex: 1 1 0; }
/* Im Menü sind auch die Icon-Knöpfe Listenzeilen mit Namen -- und die
   Einstellungen stehen direkt unter den Datei-Einträgen. */
body.compact-head #toolbar-right-inner { display: none; }
body.compact-head #toolbar-right-inner.open { display: flex; }
body.compact-head #menu-file-rows { order: 1; }
body.compact-head #toolbar-right-inner .toolbar-icon-row { order: 2; display: flex; flex-direction: column; gap: 2px; }
body.compact-head #menu-extra { order: 3; }
body.compact-head #toolbar-right-inner .toolbar-icon-row .btn,
body.compact-head #toolbar-right-inner .menu { width: 100%; }
body.compact-head #toolbar-right-inner .toolbar-icon-row .btn {
  display: flex; align-items: center; gap: 10px;
  justify-content: flex-start; padding: 7px 8px;
  border: none; border-radius: 7px; background: none; min-width: 0;
}
body.compact-head #toolbar-right-inner .toolbar-icon-row .btn:hover { background: #f1f4f8; }
body.compact-head #toolbar-right-inner .toolbar-icon-row .pp-name {
  display: block; font-size: 13px; text-align: left;
}
body.compact-head #toolbar-right-inner .divider {
  width: 100%; height: 1px; background: var(--line); margin: 3px 0;
}

/* --- Seitenleiste als Overlay ------------------------------------------
   Ab schmalen Schirmen legt sie sich über Canvas UND Werkzeugleisten und
   verhält sich wie ein Menü: Hintergrund abgedunkelt, Klick daneben schließt. */
body.sidebar-overlay #sidebar {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 88vw);
  z-index: 400;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  /* Sie fährt von rechts herein wie ein übliches Menü. Geschlossen steht sie
     neben dem Bild -- display:none würde die Bewegung verschlucken, deshalb
     hebt die Regel unten das Ausblenden im Overlay-Modus auf. */
  transform: translateX(0);
  transition: transform 0.2s ease;
}
body.sidebar-overlay.sidebar-hidden #sidebar {
  display: block;
  transform: translateX(100%);
  pointer-events: none;
}
/* Der Hintergrund blendet mit -- ohne hidden-Attribut, sonst schluckt
   `[hidden] { display: none !important }` die Blende. */
#sidebar-backdrop { opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
#sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
body.sidebar-overlay #sidebar-resizer { display: none; }
/* Schließen-Kreuz gehört zur überlagernden Leiste; im Desktop-Layout schließt
   der Schalter oben rechts, dort wäre es doppelt. */
.sidebar-close { display: none; }
body.sidebar-overlay .sidebar-close {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; align-self: center;
  width: 30px; height: 30px; margin-left: 4px;
  border: none; border-radius: 8px; background: none;
  color: var(--muted); cursor: pointer;
}
body.sidebar-overlay .sidebar-close:hover { background: rgba(0, 0, 0, 0.06); color: var(--ink); }
#sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 26, 34, 0.35);
  z-index: 390;
}

/* --- Hochformat: Bedienung nach unten ---------------------------------- */
/* Der Datei-Knopf fällt weg -- seine Einträge stehen im Menü, das auch ein
   Tipp auf die Marke öffnet. */
body.mobile-portrait #file-actions { display: none; }
body.mobile-portrait .brand { cursor: pointer; }
body.mobile-portrait .brand:active { opacity: 0.6; }
#menu-file-rows { display: flex; flex-direction: column; gap: 2px; }
#menu-file-rows + #menu-extra { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
#menu-file-rows[hidden] + #menu-extra { border-top: none; padding-top: 0; margin-top: 0; }

body.mobile-portrait #work { flex-direction: column; }
body.mobile-portrait #tab-bar     { order: 1; }
body.mobile-portrait #canvas-wrap { order: 2; }
body.mobile-portrait #toolbar-ctx {
  order: 3;
  border-top: 1px solid var(--line);
  border-bottom: none;
  padding-bottom: max(5px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
/* Trenner kosten in der unteren Leiste nur Breite -- die Gruppen stehen dort
   ohnehin dicht an dicht und werden gescrollt. */
body.mobile-portrait #toolbar-ctx .divider { display: none; }
/* Ein einziger Entwurf braucht keine Tableiste -- die Zeile ist Canvas wert. */
body.mobile-portrait #tab-bar.single { display: none; }

/* --- Aufbau als Karte über der Szene ----------------------------------- */
#asm-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  max-height: 80%;
  /* Die Höhe setzt ui.js in Pixeln: eingeklappt die Ruhehöhe, aufgeklappt die
     halbe Szene, dazwischen beim Ziehen jeder Wert. Aufgeklappt IMMER gleich
     hoch -- sonst springt die Karte bei jedem Schrittwechsel, weil mal drei und
     mal zwölf Teile in der Liste stehen. */
  transition: height 0.18s ease;
}
/* Während der Finger zieht, folgt die Karte ohne Übergang. */
#asm-sheet.dragging, #asm-sheet.no-anim { transition: none; }
/* ... und die Liste rührt sich dabei nicht: sonst wächst die Karte, während
   der gerade eingeblendete Inhalt unter dem Finger wegscrollt. */
#asm-sheet.dragging #asm-sheet-body { overflow: hidden; touch-action: none; }
/* Eingeklappt gibt es nichts zu scrollen -- und vor allem darf der Browser die
   Wischgeste gar nicht erst als Scrollen beanspruchen. Er entscheidet das im
   Compositor, BEVOR das erste touchmove bei uns ankommt; ein preventDefault
   käme dann zu spät und die Liste flöge beim Loslassen weiter. */
#asm-sheet:not(.open) #asm-sheet-body { touch-action: none; }
.asm-sheet-handle {
  border: none; background: none; padding: 10px 0 6px; cursor: pointer;
  display: flex; justify-content: center; flex: 0 0 auto;
  /* Der Wisch gehört dem Griff, nicht dem Scrollen der Seite. */
  touch-action: none;
}
.asm-sheet-grip {
  display: block; width: 42px; height: 4px; border-radius: 2px; background: #c4ccd6;
}
#asm-sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 14px 10px;
  /* Gescrollt wird nur innerhalb der Liste. Ob aus einem senkrechten Wisch
     Scrollen oder ein Zug an der Karte wird, entscheidet ui.js anhand der
     Scrollposition (touchmove mit preventDefault). */
  overscroll-behavior: contain;
  touch-action: pan-y;
}
/* Eingeklappt bleiben Schrittzähler, Fortschritt und Titel stehen; die
   Teileliste kommt erst beim Aufklappen. Während des Ziehens ist sie schon da,
   sonst zöge man an einer leeren Fläche. */
#asm-sheet:not(.open):not(.dragging) #asm-body,
#asm-sheet:not(.open):not(.dragging) .asm-order-row,
#asm-sheet:not(.open):not(.dragging) .asm-opt,
#asm-sheet:not(.open):not(.dragging) .asm-head,
#asm-sheet:not(.open):not(.dragging) .hint { display: none; }
#asm-sheet .panel { margin: 0; }
#asm-sheet .asm-nav { margin: 0 0 8px; }
#asm-sheet .asm-nav .btn { flex: 1 1 0; min-height: 44px; font-size: 20px; }
#asm-sheet .asm-title { margin: 0 0 6px; }
/* Statusmeldung nicht an den Rand der unteren Leiste kleben lassen. */
body.mobile-portrait .status { bottom: 16px; max-width: calc(100% - 24px); }

/* --- Touch: größere Ziele ---------------------------------------------
   Mit dem Finger trifft man 26-px-Knöpfe schlecht; auf Zeigern ohne feine
   Auflösung wachsen die Bedienelemente auf ~40 px. */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn.part { min-height: 44px; padding: 5px 9px; }
  .btn.icon-sq { min-width: 40px; }
  .side-tab { padding: 11px 6px; }
  .tab { padding-top: 9px; padding-bottom: 9px; }
  .own-tools button, .lib-row button { min-width: 38px; min-height: 34px; }
  .part-popup-row { padding: 10px 8px; }
  .swatch { width: 30px; height: 30px; }
  /* Popups dürfen breiter werden -- die Liste soll lesbar bleiben. */
  .part-popup { min-width: min(62vw, 260px); }
  .part-popup.color-popup { max-width: min(80vw, 260px); }
}

/* Druckbereich (nur beim Drucken sichtbar) */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block; position: absolute; left: 0; top: 0; width: 100%;
    padding: 0 8mm; color: #000; font-size: 12pt;
  }
  #print-area h1 { font-size: 20pt; margin: 0 0 12px; }
  #print-area .p-step { break-inside: avoid; margin-bottom: 12px; }
  #print-area h2 { font-size: 14pt; margin: 10px 0 4px; border-bottom: 1px solid #888; padding-bottom: 3px; }
  #print-area ul { margin: 4px 0 0; padding-left: 20px; }
  #print-area li { margin: 2px 0; }
}


/* --- Datei-Tabs -------------------------------------------------------- */
.tab-bar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 0 8px;
  background: var(--panel, #f4f6f8);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  min-height: 34px;
}
.tab-list {
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  flex: 1 1 auto;
}
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: rgba(0, 0, 0, 0.04);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  max-width: 240px;
}
.tab:hover { background: rgba(0, 0, 0, 0.07); }
/* Aktiver Entwurf: blau wie ein aktiver Knopf -- so sieht man auf einen Blick,
   welches Modell gerade offen ist. */
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.tab.active:hover { background: var(--accent); }
.tab.active .tab-close { opacity: 0.85; }
.tab.active .tab-close:hover { background: rgba(255, 255, 255, 0.25); opacity: 1; }
.tab.active .tab-dirty { background: #fff; }
.tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab-dirty {
  width: 7px; height: 7px; border-radius: 50%;
  background: #e08c1a;
  flex: 0 0 auto;
}
.tab-close {
  border: none; background: none; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  color: inherit; opacity: 0.55;
}
.tab-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.1); }
.tab-new {
  border: none; background: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 10px; border-radius: 6px;
  color: inherit; opacity: 0.7;
}
.tab-new:hover { opacity: 1; background: rgba(0, 0, 0, 0.08); }

.ask-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* Dialog: liegt über der ganzen Seite -- Kopfzeile, Toolbar und Seitenleiste
   sind gesperrt, solange die Karte steht. */
.dlg-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 26, 34, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}

/* Dialogkarte: Text und Eingabefeld der gemeinsamen Rückfrage-Karte */
.dlg-text { margin: 0; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.dlg-input {
  width: 100%; margin-top: 12px; padding: 7px 10px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  box-sizing: border-box;
}
.dlg-input:focus { outline: none; border-color: var(--accent); }

/* Kein Modell offen: Einstiegskarte über der leeren Szene */
.empty-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(246, 248, 250, 0.92);
  z-index: 5;
}
.empty-card {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 24px 28px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  max-width: 420px;
  text-align: center;
}
.empty-card h2 { margin: 0 0 6px; font-size: 17px; }
.empty-card p { margin: 0 0 16px; color: #566; font-size: 13px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* --- Seitenleiste: Tabs ------------------------------------------------ */
.side-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex: 0 0 auto;
}
.side-tab {
  flex: 1 1 0;
  border: none;
  background: none;
  padding: 7px 6px;
  font-size: 12.5px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: inherit;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-tab:hover { opacity: 1; }
.side-tab.active { opacity: 1; font-weight: 600; border-bottom-color: currentColor; }

.bom-row.bad { color: #a4243b; }
.bom-row.marked { background: rgba(26, 140, 255, 0.12); border-radius: 6px; }
.bom-row .inv-status { min-width: 34px; text-align: right; font-size: 11.5px; opacity: 0.8; }

/* Arbeitsbereich: Bauteil-Zeile, Datei-Tabs und Szene stehen links, die
   Seitenleiste reicht daneben bis unter die oberste Leiste. */
#work { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#work #canvas-wrap { flex: 1; min-height: 0; }
#sidebar { align-self: stretch; }

/* Stückliste: Name | Anzahl | Bestand | Preis -- alles in EINER Zeile. */
.bom-row {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 6px;
}
.bom-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bom-stock {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  opacity: 0.85;
  min-width: 46px;
  text-align: right;
}
/* Bestand reicht nicht: die ganze Zeile leicht rot hinterlegen. */
.bom-row.bad, .bom-row.bad:nth-child(odd) { background: rgba(164, 36, 59, 0.12); }
.bom-row.bad .bom-stock { color: #a4243b; font-weight: 600; }

/* Zeilen der Stückliste, die Teile im Modell hervorheben, sind anklickbar. */
.bom-row.clickable { cursor: pointer; }
.bom-row.clickable:hover { background: rgba(26, 140, 255, 0.08); }
.bom-row.bad.clickable:hover { background: rgba(164, 36, 59, 0.18); }

/* Eintrag unter "Meine Modelle": links Name, Anzahl und Datum, rechts die
   Werkzeuge -- alles in einer Zeile. */
.own-row { display: flex; flex-direction: row; align-items: stretch; gap: 8px; }
.own-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.own-main .lib-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.own-main .lib-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Rechte Spalte eines Modell-Eintrags: Abzeichen oben, Werkzeuge unten. */
.own-side {
  display: flex; flex-direction: column; justify-content: space-between;
  align-items: flex-end; align-self: stretch; gap: 6px; flex: 0 0 auto;
}
.own-tools { display: flex; gap: 2px; flex: 0 0 auto; }
.own-tools .btn { padding: 3px; }

/* Auto-Save-Schalter in der Kopfzeile, neben "Speichern unter". */
.autosave-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--muted);
  padding: 0 6px; white-space: nowrap; cursor: pointer;
}
.autosave-toggle input { margin: 0; cursor: pointer; }

/* Tabs umsortieren: der gezogene Tab hebt sich ab, der Rest rutscht weiter. */
body.tab-dragging { cursor: grabbing; user-select: none; }
body.tab-dragging .tab { cursor: grabbing; }
.tab.dragging {
  opacity: 0.75;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}

/* Aufbau-Modus: die Bauteil-Zeile bleibt stehen, das Bauen ist gesperrt. */
#toolbar-ctx.locked .btn[disabled],
#toolbar-ctx.locked button[disabled] { opacity: 0.4; cursor: not-allowed; }
#toolbar-ctx.locked .swatch[disabled] { opacity: 0.35; cursor: not-allowed; }

/* Werkzeuge und Schalter über der Stückliste */
.bom-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 4px; }
.bom-opts { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.bom-row .inv-input { width: 58px; }

/* Mengen-Spalte: rechtsbündig, damit die Zahlen aller Zeilen untereinander
   stehen (auch die Hinweiszeile "Offene Enden"). */
.bom-count { text-align: right; min-width: 44px; }

/* Die Tab-Leiste der Seitenleiste klebt oben, der Inhalt darunter bekommt Luft. */
.side-tabs {
  position: sticky; top: 0; z-index: 2;
  margin: 0 -14px;
  padding: 6px 14px 0;
  background: var(--panel);
}
#sidebar .panel { margin-top: 14px; }

/* Knöpfe, die nur ein Sinnbild tragen (Zurück/Wieder). */
.btn.icon-only { padding: 5px 7px; }
.btn.icon-only svg { display: block; }

/* Bis der Katalog da ist, sind die Bauteil-Knöpfe noch nicht gebaut. Die
   Leiste bleibt so lange unsichtbar und erscheint dann vollständig, statt dass
   die Knöpfe einzeln hineinspringen. */
body.booting #toolbar-ctx,
body.booting #tab-bar,
body.booting #sidebar { visibility: hidden; }
