:root {
  --bg: #e9ecf1; --panel: #f5f6f8; --line: #c9ced6; --line2: #dde1e7; --text: #1f2933; --muted: #5f6b7a;
  --accent: #1f6fbf; --accent-soft: #dbe9f8; --wood: #c8a165; --wood-dark: #5d4037; --danger: #c62828; --ok: #2e7d32;
  --fs: 13px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: var(--fs)/1.35 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto auto auto minmax(0,1fr) auto; overflow: hidden; }

/* Titel + Menü */
#titlebar { display: flex; align-items: center; gap: 12px; background: #2f3b4a; color: #eef2f6; padding: 0 10px; height: 32px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: .2px; }
#menubar { display: flex; height: 100%; }
#menubar > div { position: relative; }
#menubar > div > button { background: none; border: 0; color: #eef2f6; padding: 0 11px; height: 32px; cursor: pointer; }
#menubar > div > button:hover, #menubar > div.open > button { background: #46566a; }
.menu { position: absolute; top: 32px; left: 0; min-width: 250px; background: #fff; color: var(--text); border: 1px solid var(--line); box-shadow: 0 6px 22px rgba(0,0,0,.18); z-index: 50; padding: 4px 0; display: none; }
#menubar > div.open .menu { display: block; }
.menu button { display: flex; width: 100%; justify-content: space-between; gap: 24px; background: none; border: 0; padding: 6px 14px; text-align: left; cursor: pointer; }
.menu button:hover { background: var(--accent-soft); }
.menu button:disabled { color: #aab; cursor: default; background: none; }
.menu .kb { color: var(--muted); font-size: 12px; }
.menu hr { border: 0; border-top: 1px solid var(--line2); margin: 4px 0; }
#docname { margin-left: auto; cursor: pointer; padding: 2px 8px; border-radius: 3px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#docname:hover { background: #46566a; }
#storeinfo { font-size: 12px; color: #b9c4d0; white-space: nowrap; }

/* Werkzeugleiste */
#toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
#toolbar .sep { width: 1px; background: var(--line); margin: 3px 5px; }
.tb { width: 34px; height: 34px; border: 1px solid transparent; border-radius: 4px; background: none; display: grid; place-items: center; cursor: pointer; padding: 0; }
.tb:hover { background: #e3e8ef; border-color: var(--line); }
.tb.on { background: var(--accent-soft); border-color: #8fb6e0; }
.tb svg { width: 22px; height: 22px; stroke: #2a3644; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Kontextleiste */
#ctxbar { display: flex; align-items: center; gap: 14px; padding: 0 10px; height: 36px; overflow: hidden; background: #fbfbfc; border-bottom: 1px solid var(--line); }
#toolname { font-weight: 600; min-width: 110px; }
#ctxopts { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
#ctxopts label { display: flex; gap: 6px; align-items: center; }
#ctxopts input[type=number] { width: 80px; }
input[type=number], input[type=text], select { border: 1px solid var(--line); border-radius: 3px; padding: 3px 5px; background: #fff; }
input:focus, select:focus { outline: 2px solid #8fb6e0; outline-offset: 0; }

main { display: flex; min-height: 0; }
#dock { width: 300px; min-width: 220px; max-width: 60vw; background: var(--panel); display: flex; flex-direction: column; border-right: 1px solid var(--line); }
#dockgrip { width: 5px; cursor: col-resize; background: transparent; }
#dockgrip:hover { background: var(--accent-soft); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 4px; cursor: pointer; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabbody { overflow: auto; flex: 1; padding: 8px; }

#stage { flex: 1; display: flex; min-width: 0; }
#cursorbar { width: 38px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 4px 0; gap: 2px; }
#cursorbar .tb { width: 32px; height: 32px; }
#cursorbar .tb svg { width: 20px; height: 20px; }
#cursorbar .lbl { font-size: 10px; color: var(--muted); margin-top: 6px; }
#canvaswrap { flex: 1; position: relative; min-width: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; cursor: none; display: block; }
#toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: #2f3b4a; color: #fff; padding: 7px 14px; border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.2); opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 80%; }
#toast.show { opacity: .95; }

/* Statusleiste */
#statusbar { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(220px, 340px) auto; align-items: center; gap: 10px; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 8px; }
#prompt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #0d47a1; font-weight: 500; }
#cmdwrap { display: flex; align-items: center; gap: 6px; }
#cmdwrap span { color: var(--muted); font-size: 12px; }
#cmd { flex: 1; font-family: Consolas, "Courier New", monospace; padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; }
#cmd.active { border-color: var(--accent); background: #f2f8ff; }
#coords { display: flex; gap: 12px; font-family: Consolas, "Courier New", monospace; font-size: 12px; white-space: nowrap; }
#coords b { color: var(--muted); font-weight: normal; }

/* Folien */
.ltable { width: 100%; border-collapse: collapse; }
.ltable td { padding: 3px 3px; border-bottom: 1px solid var(--line2); }
.ltable tr.cur { background: var(--accent-soft); }
.ltable tr:hover { background: #eef3f9; }
.ltable .name { width: 100%; cursor: pointer; }
.ltable .cnt { color: var(--muted); font-size: 11px; text-align: right; }
.ibtn { border: 0; background: none; cursor: pointer; padding: 2px; display: grid; place-items: center; }
.ibtn svg { width: 17px; height: 17px; stroke: #2a3644; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ibtn.off svg { stroke: #b0b7c1; }
.swatch { width: 18px; height: 18px; border: 1px solid #889; border-radius: 3px; padding: 0; cursor: pointer; }
.row { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 4px; padding: 5px 10px; cursor: pointer; }
.btn:hover { background: #f0f4f9; border-color: #9fb3c8; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #185c9f; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 2px 7px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.warn { background: #fff4e5; border: 1px solid #ffcc80; color: #7a4a00; padding: 6px 8px; border-radius: 4px; margin: 6px 0; font-size: 12px; }
.ok { background: #e8f5e9; border: 1px solid #a5d6a7; padding: 6px 8px; border-radius: 4px; margin: 6px 0; font-size: 12px; }

/* Inspektor */
.insp h4 { margin: 4px 0 8px; font-size: 13px; }
.insp .f { display: grid; grid-template-columns: 96px 1fr; gap: 6px; align-items: center; margin: 4px 0; }
.insp .f input, .insp .f select { width: 100%; }
.insp .f span { color: var(--muted); }
.vt { width: 100%; border-collapse: collapse; font-size: 12px; }
.vt td { padding: 1px 2px; }
.vt input { width: 100%; padding: 2px 3px; }

/* Werkstücke */
.part { border: 1px solid var(--line); background: #fff; border-radius: 5px; padding: 7px 8px; margin-bottom: 7px; }
.part .t { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.part .d { color: var(--muted); font-size: 12px; margin: 2px 0 5px; }

/* Dialog */
#modal { position: fixed; inset: 0; background: rgba(20,28,38,.35); display: grid; place-items: center; z-index: 100; }
.dlg { background: #fff; border-radius: 6px; box-shadow: 0 16px 50px rgba(0,0,0,.3); width: min(880px, 96vw); max-height: 92vh; display: flex; flex-direction: column; }
.dlg.narrow { width: min(520px, 96vw); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line2); font-weight: 600; font-size: 15px; }
.dlg-h button { border: 0; background: none; font-size: 16px; cursor: pointer; }
.dlg-b { padding: 12px 14px; overflow: auto; }
.dlg-f { padding: 10px 14px; border-top: 1px solid var(--line2); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .f { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: center; margin: 5px 0; }
.form .f input[type=text], .form .f input[type=number], .form .f select { width: 100%; }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 4px 0 8px; }
table.t th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 3px 4px; }
table.t td { border-bottom: 1px solid var(--line2); padding: 3px 4px; }
table.t input[type=number] { width: 70px; }
fieldset { border: 1px solid var(--line2); border-radius: 5px; margin: 0 0 10px; padding: 6px 10px 8px; }
legend { color: var(--muted); padding: 0 4px; }
pre.code { background: #1e2731; color: #d7e3ee; padding: 10px; border-radius: 5px; max-height: 55vh; overflow: auto; font-size: 12px; }
.filelist { width: 100%; border-collapse: collapse; }
.filelist td { padding: 6px 6px; border-bottom: 1px solid var(--line2); }
.filelist tr:hover { background: #f2f6fb; }
.filelist .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 5px; font-family: Consolas, monospace; font-size: 12px; background: #fafafa; }
.help td { padding: 3px 8px 3px 0; vertical-align: top; }

@media (max-width: 760px) {
  #dock { display: none; }
  #statusbar { grid-template-columns: 1fr; }
  #coords { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
.insp .f input[type=color] { width: 46px; height: 26px; padding: 1px; flex: none; }

/* 3D */
#view3d { position: absolute; inset: 0; background: #dfe4ea; display: flex; flex-direction: column; z-index: 5; }
.v3bar { display: flex; gap: 6px; align-items: center; padding: 6px 8px; background: rgba(245,246,248,.95); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#v3canvas { flex: 1; position: relative; min-height: 0; }
#v3canvas canvas { display: block; width: 100%; height: 100%; }
.v3info { position: absolute; left: 10px; bottom: 10px; background: rgba(255,255,255,.93); border: 1px solid var(--line); border-left: 3px solid #1f78d1; border-radius: 6px; padding: 6px 10px; font-size: 12.5px; line-height: 1.45; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.08); max-width: calc(100% - 20px); }
.v3info span { color: var(--muted); font-size: 11.5px; }
.v3info.hidden { display: none; }
.tabs button { font-size: 12.5px; padding: 7px 2px; }
.mob .f { grid-template-columns: 74px 1fr; }
.pos3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 4px; }
.pos3 label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; }
.pos3 input, .pos3 select { width: 100%; }

.v3load { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; color: var(--muted); z-index: 2; background: #dfe4ea; }
.v3load .bar { width: 260px; height: 6px; border-radius: 3px; background: #c9d0d9; overflow: hidden; position: relative; }
.v3load .bar div { position: absolute; top: 0; bottom: 0; width: 35%; border-radius: 3px; background: linear-gradient(90deg, #c8a165, #8d6e63); animation: v3slide 1.1s ease-in-out infinite; }
@keyframes v3slide { 0% { left: -35%; } 100% { left: 100%; } }

/* KI */
.ai textarea { width: 100%; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 4px; resize: vertical; }
.ai-ex .btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-list { margin: 4px 0 0; padding-left: 18px; }
.ai-list li { margin: 2px 0; }
.sw { display: inline-block; width: 11px; height: 11px; border: 1px solid #8a7a6a; border-radius: 2px; vertical-align: -1px; margin-right: 3px; }

/* Katalog */
.catgrp { margin: 0 0 6px; }
.catgrp > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; margin: 4px 0 8px; }
.cattile { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 5px; padding: 4px; cursor: pointer; font-size: 11.5px; line-height: 1.25; }
.cattile:hover { border-color: #8fb6e0; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.cattile .pv { height: 70px; display: grid; place-items: center; background: #fafbfc; border-radius: 3px; overflow: hidden; }
.cattile .pv svg { width: 100%; height: 100%; }
.cattile .nm { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cattile .wh { position: absolute; top: 3px; left: 5px; font-size: 10px; }
.cattile .del { position: absolute; top: 2px; right: 2px; border: 0; background: #fff; color: var(--danger); border-radius: 3px; cursor: pointer; display: none; font-size: 11px; }
.cattile:hover .del { display: block; }
.aisym-pv { border: 1px solid var(--line); border-radius: 5px; background: #fafbfc; }
.aisym-pv svg { width: 100%; height: auto; display: block; }
label.btn input.hidden { display: none; }

.bom { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; overflow-x: auto; }
.bom table.t { font-size: 12px; margin: 0; }
.bom td { white-space: nowrap; }
.bom-t { white-space: nowrap; }

/* Raumplaner */
.dlg.rp-dlg { width: min(1400px, 97vw); height: 92vh; }
.rp-dlg .dlg-b { padding: 0; display: flex; flex: 1; min-height: 0; }
.rp { display: grid; grid-template-columns: 1fr 270px; grid-template-rows: auto 1fr; width: 100%; min-height: 0; }
.rp-tools { grid-column: 1 / 3; display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line2); flex-wrap: wrap; }
.rp-tools .btn.on { background: var(--accent-soft); border-color: #8fb6e0; font-weight: 600; }
.rp-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.rp-main { position: relative; min-height: 0; background: #fafbfc; }
#rp-svg { width: 100%; height: 100%; display: block; outline: none; user-select: none; touch-action: none; }
#rp-len { position: absolute; width: 110px; padding: 5px 7px; font-size: 14px; border: 2px solid var(--accent); border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.rp-side { border-left: 1px solid var(--line2); padding: 8px 12px; overflow: auto; }
.rp-side h4 { margin: 4px 0 6px; }
.rp-side .form .f { grid-template-columns: 110px 1fr; }
/* Kalkulation */
table.calc tr.crow { cursor: pointer; }
table.calc tr.crow:hover td { background: #f6f9fc; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
.tw { display: inline-block; width: 12px; color: var(--muted); }
tr.cdet td { background: #fafbfc; }
.cdetail { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.cdetail h5 { margin: 2px 0 4px; font-size: 12px; color: var(--muted); }
table.t.mini td { padding: 2px 5px; font-size: 12px; }
.csum { margin: 12px 0 4px auto; width: 360px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: #fbfaf7; }
.csum > div { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.csum > div.big { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-size: 15px; }
.form.two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.form.two .f { grid-template-columns: 150px 1fr; }
.form textarea { width: 100%; font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; resize: vertical; }
.ptext { margin: 6px 0 10px; } .ptext textarea { display: block; width: 100%; margin-top: 3px; font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; }
@media (max-width: 800px) { .cdetail, .form.two { grid-template-columns: 1fr; } }
