/* Layout: tool sidebar left, full-bleed 3D viewport right; stacks below 820px. */
:root {
  --bg: #eceff3;
  --panel: #f9fafc;
  --line: #d6dbe3;
  --fg: #151922;
  --muted: #5b6474;
  --accent: #2453cf;
  --accent-fg: #ffffff;
  --accent-soft: #dfe7fb;
  --ok: #1d7f47;
  --warn: #a8661a;
  --view-bg: #dde2ea;
  --font-ui: "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --panel: #151920; --line: #262c37; --fg: #e5e8ee; --muted: #8b94a4;
    --accent: #7096ff; --accent-fg: #0a0f1d; --accent-soft: #1c2742; --ok: #4cc782; --warn: #e3a84d;
    --view-bg: #12161d; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --panel: #151920; --line: #262c37; --fg: #e5e8ee; --muted: #8b94a4;
  --accent: #7096ff; --accent-fg: #0a0f1d; --accent-soft: #1c2742; --ok: #4cc782; --warn: #e3a84d;
  --view-bg: #12161d; color-scheme: dark;
}
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font-ui); }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
#app { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100%; }
/* Seitenleiste: fester Kopf (Datei), scrollender Mittelteil (Abschnitte), feste Aktionsleiste unten */
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#side-head { padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
#side-head .hint { font-size: 12px; }
#side-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; }
#actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel); }
#actions .btn { padding: 11px 8px; }
#view { position: relative; min-width: 0; background: var(--view-bg); overflow: hidden; }
#c { display: block; width: 100%; height: 100%; touch-action: none; }

.brand { display: flex; gap: 12px; align-items: center; }
.brand svg { width: 40px; height: 40px; flex: none; }
.brand h1 { font: 600 20px/1.1 var(--font-display); margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

/* Einklappbare Abschnitte */
.sec { border-bottom: 1px solid var(--line); }
.sec > summary { font: 600 11.5px/1 var(--font-ui); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); display: flex; align-items: center; gap: 8px; padding: 13px 18px; cursor: pointer; list-style: none; user-select: none; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: rotate(-45deg); transition: transform .12s; flex: none; }
.sec[open] > summary::before { transform: rotate(45deg); }
.sec > summary:hover { color: var(--fg); }
.sec > summary .count { margin-left: auto; }
.sec-body { display: flex; flex-direction: column; gap: 10px; padding: 0 18px 16px; }
h3 { font: 600 12.5px/1 var(--font-ui); color: var(--fg); margin: 8px 0 0; }
.count { font-family: var(--font-mono); letter-spacing: 0; text-transform: none; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; text-wrap: pretty; }
.meta { font: 12px/1.5 var(--font-mono); color: var(--muted); word-break: break-all; }
.meta b { color: var(--fg); font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn, button { font: 500 13px/1 var(--font-ui); color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: 7px; padding: 9px 12px; cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover, button:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { width: 100%; padding: 11px 12px; }
.btn.small { padding: 7px 10px; font-size: 12.5px; }
.btn.ghost { border-style: dashed; color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { border: 0; border-radius: 5px; padding: 8px 4px; font-size: 12.5px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.field output { font-family: var(--font-mono); color: var(--fg); }
input[type=range] { width: 100%; accent-color: var(--accent); }
select, input[type=number] { font: 13px var(--font-ui); color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 8px; width: 100%; }
input[type=number] { width: 84px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.span2 { grid-column: 1 / -1; }
.subpanel { display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.num { display: flex; flex-direction: column; justify-content: space-between; gap: 4px; font-size: 12.5px; color: var(--muted); }
.num span { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 12px var(--font-mono); }
.num input[type=number] { width: 100%; min-width: 0; }
.btn.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.inline { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; font-size: 13px; }

#palette, #parts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pal { display: grid; grid-template-columns: 30px 26px minmax(0, 1fr) auto 28px; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; }
.pal:hover { background: var(--bg); }
.pal.sel { border-color: var(--accent); background: var(--accent-soft); }
.pal.off .lbl, .pal.off .n { opacity: .45; text-decoration: line-through; }
.slot { font: 600 11px/1 var(--font-mono); color: var(--muted); text-align: center; border: 1px solid var(--line); border-radius: 4px; padding: 4px 0; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); padding: 0; overflow: hidden; position: relative; }
.sw input { position: absolute; inset: -8px; width: 44px; height: 44px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.lbl { border: 0; background: transparent; font: 13px var(--font-ui); color: var(--fg); padding: 2px 0; min-width: 0; width: 100%; }
.lbl:focus { outline: none; border-bottom: 1px solid var(--accent); }
.n { font: 11.5px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.eye { border: 0; padding: 4px; color: var(--muted); display: grid; place-items: center; }
.eye svg { width: 17px; height: 17px; }

/* Teileliste: Zeile 1 Name, Status, Sichtbarkeit; Zeile 2 Details und Umfärben */
.part { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto 18px; gap: 2px 8px; align-items: center; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.part:last-child { border-bottom: 0; }
.part .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--line); }
.part .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part .sub { grid-column: 2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part .reassign { grid-column: 3 / -1; justify-self: end; width: auto; max-width: 110px; font-size: 12px; padding: 2px 4px; border-color: transparent; background: transparent; color: var(--muted); cursor: pointer; }
.part .reassign:hover { border-color: var(--line); color: var(--fg); }
.optrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.unit { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 12px var(--font-mono); }
.unit input[type=number] { width: 68px; }
.btns .btn { width: 100%; padding: 8px 4px; }
/* Leiste im 3D-Fenster, solange das Modell geteilt ist */
#splitbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 8px 10px 8px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 14px rgb(0 0 0 / .08); max-width: calc(100% - 24px); }
#splitbar .field { width: 220px; gap: 2px; }
#splitbar .btn { white-space: nowrap; }
#btn-fit { position: absolute; right: 14px; bottom: 34px; background: var(--panel); color: var(--muted); }
.badge { font: 600 10.5px/1 var(--font-mono); padding: 4px 6px; border-radius: 4px; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

#hud { position: absolute; left: 14px; bottom: 12px; font: 12px/1.5 var(--font-mono); color: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums; }
#legend { position: absolute; right: 14px; bottom: 12px; font-size: 12px; color: var(--muted); pointer-events: none; text-align: right; }
#drop-overlay { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 14px; display: grid; place-items: center; font: 600 18px var(--font-display); color: var(--accent); background: color-mix(in srgb, var(--view-bg) 80%, transparent); pointer-events: none; }
#busy { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--view-bg) 65%, transparent); font-weight: 500; }
#busy span { background: var(--panel); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; }
#toast { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  #view { order: -1; height: 58vh; }
  #legend { display: none; }
  #side { border-right: 0; border-top: 1px solid var(--line); }
  #side-scroll { overflow: visible; }
  #actions { position: sticky; bottom: 0; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
  #btn-fit { display: none; }
  #splitbar { flex-wrap: wrap; justify-content: center; gap: 6px 12px; }
  #splitbar .field { width: min(220px, 60vw); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
#pin-opts { display: flex; flex-direction: column; gap: 10px; }

/* Hilfe-Dialog */
#help { width: min(760px, calc(100vw - 24px)); max-height: min(86vh, 900px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); }
#help::backdrop { background: rgb(0 0 0 / .45); }
#help-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
#help-head h2 { font: 600 18px/1.2 var(--font-display); margin: 0; }
#help-body { padding: 6px 20px 24px; font-size: 14px; line-height: 1.55; }
#help-body h3 { font: 600 15px/1.3 var(--font-ui); margin: 22px 0 6px; scroll-margin-top: 64px; }
#help-body p { margin: 6px 0; }
#help-body ul, #help-body ol { margin: 6px 0; padding-left: 20px; }
#help-body li { margin: 3px 0; }
#help-body table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13.5px; }
#help-body th, #help-body td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--line); }
#help-body th { color: var(--muted); font-weight: 600; }
#help-body kbd { font: 12px var(--font-mono); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; background: var(--bg); }
#help-toc { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 0 2px; font-size: 13px; }
#help-toc a { color: var(--accent); text-decoration: none; }
#help-toc a:hover { text-decoration: underline; }
.tablewrap { overflow-x: auto; }

/* Schneiden */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 .num input[type=number] { width: 100%; min-width: 0; }
.ax-x { color: #d13d43; } .ax-y { color: #23875a; } .ax-z { color: #2f6fe0; }
.hintlabel { font-size: 12.5px; color: var(--muted); }
.row.tight { gap: 4px; flex-wrap: nowrap; }
.row.tight .btn { padding: 6px 10px; }
#cut-readout { position: absolute; padding: 4px 8px; border-radius: 6px; background: var(--fg); color: var(--bg); font: 12px var(--font-mono); pointer-events: none; white-space: nowrap; }
