/* Modell-Viewer – IFC im Browser (three.js + web-ifc)
   1.3.1: am Handy Werkzeugleiste als Seitenleiste rechts, quer mit Panels links */
:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel2: #f6f7f9;
  --line: #d9dde3;
  --tx: #1b1f24;
  --mut: #66707c;
  --ac: #0b6bcb;
  --acTx: #ffffff;
  --view: #e4e8ed;
  --view2: #f7f8fa;
  --warn: #c2410c;
  --ok: #15803d;
  --shadow: 0 6px 24px rgba(15, 23, 42, .14);
  --r: 10px;
  --bar: 52px;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --panel: #171b21; --panel2: #1d2229; --line: #2b313a; --tx: #e6e9ee; --mut: #8b95a3;
    --ac: #4ea1ff; --acTx: #06121f; --view: #1a1f26; --view2: #252b33; --warn: #fb923c; --ok: #4ade80;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --panel: #171b21; --panel2: #1d2229; --line: #2b313a; --tx: #e6e9ee; --mut: #8b95a3;
  --ac: #4ea1ff; --acTx: #06121f; --view: #1a1f26; --view2: #252b33; --warn: #fb923c; --ok: #4ade80;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--tx); overflow: hidden;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Leiste */
.bar {
  height: var(--bar); display: flex; align-items: center; gap: 10px; padding: 0 10px;
  padding-top: env(safe-area-inset-top); height: calc(var(--bar) + env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 260px; }
.logo { width: 26px; height: 26px; fill: var(--ac); flex: none; }
.tt { display: flex; flex-direction: column; min-width: 0; }
.tt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.tt span { color: var(--mut); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tools > :first-child { margin-left: auto; }
.tools::-webkit-scrollbar { display: none; }
.sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; flex: none; }
.tb {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 52px; height: 44px; padding: 2px 6px; border: 0; border-radius: 8px; background: transparent;
  cursor: pointer; flex: none;
}
.tb svg { width: 20px; height: 20px; fill: currentColor; }
.tb span { font-size: 11px; color: var(--mut); }
.tb:hover { background: var(--panel2); }
.tb.on { background: var(--ac); color: var(--acTx); }
.tb.on span { color: var(--acTx); }
.tb:disabled { opacity: .35; cursor: default; background: transparent; }
.embed .title { display: none; }
.embed .tools > :first-child { margin-left: 0; }

/* Bühne */
.stage { position: relative; height: calc(100% - var(--bar) - env(safe-area-inset-top)); display: flex; }
.view { position: relative; flex: 1; min-width: 0; background: linear-gradient(var(--view2), var(--view)); overflow: hidden; }
#cv { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.view.measuring #cv { cursor: crosshair; }

/* Panels */
.panel {
  width: 300px; flex: none; background: var(--panel); display: flex; flex-direction: column; min-height: 0;
  z-index: 10;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); width: 330px; }
.ph { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); }
.ptitle { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ptitle b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptitle span { font-size: 12px; color: var(--mut); }
.pb { overflow: auto; flex: 1; min-height: 0; padding: 8px; -webkit-overflow-scrolling: touch; }
.x { border: 0; background: transparent; font-size: 22px; line-height: 1; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--mut); flex: none; }
.x:hover { background: var(--panel2); color: var(--tx); }
.tabs { display: flex; gap: 2px; flex: 1; }
.tab { border: 0; background: transparent; padding: 7px 9px; border-radius: 7px; cursor: pointer; color: var(--mut); font-size: 13px; }
.tab.on { background: var(--panel2); color: var(--tx); font-weight: 600; }
.acts { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* Listen */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 7px; min-height: 38px; cursor: pointer;
}
.row:hover { background: var(--panel2); }
.row.sel { background: color-mix(in srgb, var(--ac) 16%, transparent); }
.row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ac); flex: none; margin: 0; }
.row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { display: block; font-size: 11.5px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .cnt { font-size: 12px; color: var(--mut); font-variant-numeric: tabular-nums; flex: none; }
.row .tw { width: 22px; height: 22px; border: 0; background: transparent; cursor: pointer; color: var(--mut); flex: none; border-radius: 5px; padding: 0; }
.row .tw:hover { background: var(--line); }
.row .mini { flex: none; }
.child { padding-left: 22px; }
.child2 { padding-left: 44px; }
.sw { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.more { color: var(--mut); font-size: 12px; padding: 6px 8px; }

/* Darstellung */
.vsec { margin: 10px 0 12px; }
.vlab { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--mut); margin-bottom: 6px; display: flex; justify-content: space-between; }
.vlab small { text-transform: none; letter-spacing: 0; }
.vopts { display: grid; gap: 4px; }
.vopts label, .vchk { display: grid; grid-template-columns: 20px 1fr; gap: 2px 8px; align-items: start; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.vopts label:has(input:checked), .vchk:has(input:checked) { border-color: var(--ac); background: color-mix(in srgb, var(--ac) 8%, transparent); }
.vopts input, .vchk input { margin: 3px 0 0; accent-color: var(--ac); }
.vopts b, .vchk b { grid-column: 2; font-weight: 600; }
.vopts small, .vchk small { grid-column: 2; color: var(--mut); font-size: 12px; }
.vrow { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 13px; }
.vrow label { display: flex; align-items: center; gap: 6px; }
.vrow input[type=range] { width: 120px; accent-color: var(--ac); }
.vrow input[type=checkbox] { accent-color: var(--ac); width: 16px; height: 16px; margin: 0; }
.vrow .hint { width: 100%; margin: 0; }
/* Formate im Leerzustand, Achsen-Dialog */
.fmts { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.fmts span { font: 600 11px/1 var(--mono); color: var(--mut); border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; }
.axrow { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.axrow label { font-size: 12.5px; color: var(--mut); }
.dlg .fbtns .btn { white-space: nowrap; }
/* Knöpfe, die nur in der Baustellen-App Sinn ergeben */
.noapp .app-only { display: none !important; }
/* Mengen */
.qbar { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; }
.seg2 { display: flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; flex: 1; }
.seg2 button { flex: 1; border: 0; background: transparent; padding: 5px 4px; border-radius: 6px; font-size: 12.5px; cursor: pointer; color: var(--mut); }
.seg2 button.on { background: var(--panel); color: var(--tx); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.qlist { font-size: 12.5px; }
.qrow { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 10px; padding: 7px 6px; border-radius: 7px; cursor: pointer; align-items: baseline; }
.qrow:hover { background: var(--panel2); }
.qrow .qn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qrow .qs { grid-column: 1 / -1; color: var(--mut); font-size: 11.5px; }
.qrow .qv { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.qhead { color: var(--mut); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 6px 2px; border-top: 1px solid var(--line); margin-top: 4px; }
.qsum { border-top: 2px solid var(--line); margin-top: 4px; font-weight: 600; cursor: default; }
.qsum:hover { background: transparent; }
.sq { margin: 2px 0 6px; }
.qgsel { padding: 5px 8px; font-size: 12.5px; min-width: 0; }
.qbar .qgsel { flex: 1; }
.sqgrp { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px; font-size: 11.5px; color: var(--mut); }
.sqgrp .qgsel { flex: 1; width: auto; }
.sqbox { border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); padding: 2px 4px 4px; }
.sqbox > summary { display: grid; grid-auto-flow: column; grid-template-columns: 1fr; grid-auto-columns: auto; gap: 10px; align-items: center; padding: 6px 4px; cursor: pointer; font-weight: 600; list-style: none; }
.sqbox > summary::-webkit-details-marker { display: none; }
.sqbox > summary > span:first-child::before { content: '▸ '; color: var(--mut); }
.sqbox[open] > summary > span:first-child::before { content: '▾ '; }
.sqbox[open] > summary .qv { display: none; }
.sqbox > summary > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sqbox > summary .qv { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.sqbox .qrow:hover { background: var(--panel); }
.sqbox .qsum:hover { background: transparent; }
.inp { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); outline: none; }
.inp:focus { border-color: var(--ac); }
.hint { font-size: 12px; color: var(--mut); margin: 6px 2px; }

.btn {
  border: 1px solid var(--line); background: var(--panel2); padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 500;
}
.btn:hover { border-color: var(--ac); }
.btn.pri { background: var(--ac); color: var(--acTx); border-color: var(--ac); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.mini { border: 1px solid var(--line); background: var(--panel2); border-radius: 6px; font-size: 12px; padding: 3px 7px; cursor: pointer; }
.mini:hover { border-color: var(--ac); }

/* Eigenschaften */
.pgrp { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.pgrp > summary {
  list-style: none; cursor: pointer; padding: 8px 10px; background: var(--panel2); font-weight: 600; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.pgrp > summary::-webkit-details-marker { display: none; }
.pgrp > summary small { color: var(--mut); font-weight: 400; margin-left: auto; }
.pgrp > summary::after { content: "›"; color: var(--mut); transition: transform .15s; }
.pgrp[open] > summary::after { transform: rotate(90deg); }
.ptab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ptab td { padding: 5px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.ptab td:first-child { color: var(--mut); width: 44%; word-break: break-word; }
.ptab td:last-child { word-break: break-word; }
.ptab td.mono { font-family: var(--mono); font-size: 12px; }
.copy { cursor: copy; }
.copy:hover { color: var(--ac); }

/* Leerzustand */
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.drop {
  max-width: 440px; width: 100%; text-align: center; padding: 28px 22px; border: 2px dashed var(--line); border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}
.drop svg { width: 48px; height: 48px; fill: var(--ac); }
.drop h1 { font-size: 20px; margin: 8px 0 6px; }
.drop p { color: var(--mut); margin: 0 0 16px; }
.view.dragging .drop { border-color: var(--ac); background: color-mix(in srgb, var(--ac) 10%, var(--panel)); }
.recent { margin-top: 20px; text-align: left; }
.recent h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); margin: 0 0 6px; }
.recent .row { border: 1px solid var(--line); margin-bottom: 6px; background: var(--panel); }

/* Schwebende Boxen */
.float {
  position: absolute; right: 12px; top: 12px; width: 300px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow); padding: 8px 10px 10px; z-index: 6;
}
.fh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.fh .x { width: 28px; height: 28px; font-size: 20px; }
.srow { display: grid; grid-template-columns: 80px 1fr auto; align-items: center; gap: 8px; padding: 5px 0; }
.srow label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.srow input[type=checkbox] { accent-color: var(--ac); width: 17px; height: 17px; margin: 0; }
.srow input[type=range] { width: 100%; accent-color: var(--ac); }
.fbtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.mlist { font-family: var(--mono); font-size: 13px; max-height: 180px; overflow: auto; }
.mlist div { display: flex; justify-content: space-between; padding: 4px 2px; border-bottom: 1px solid var(--line); }
.mlist button { border: 0; background: transparent; color: var(--mut); cursor: pointer; }

.modehint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; box-shadow: var(--shadow); z-index: 5; white-space: nowrap;
}

/* Maßbeschriftung */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mlabel {
  position: absolute; transform: translate(-50%, -50%); background: var(--ac); color: var(--acTx); font: 600 12px/1 var(--mono);
  padding: 4px 7px; border-radius: 6px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.snapdot {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--ac); border-radius: 3px;
  pointer-events: none; background: color-mix(in srgb, var(--ac) 25%, transparent);
}

/* Lade-Overlay, Toast */
.busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 55%, transparent); z-index: 30; }
.bx { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; box-shadow: var(--shadow); min-width: 240px; text-align: center; }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--ac); border-radius: 50%; margin: 0 auto 10px; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.pbar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: var(--ac); transition: width .15s; }
.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: var(--tx); color: var(--bg); padding: 8px 14px;
  border-radius: 8px; font-size: 13px; z-index: 40; box-shadow: var(--shadow); max-width: 90%; text-align: center;
}

/* Dialog */
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--tx); padding: 18px; width: min(480px, 92vw); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, .35); }
.dlg h2 { margin: 0 0 10px; font-size: 17px; }
.dlg p { margin: 6px 0; }
.dlg .opt { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.dlg .opt .btn { text-align: left; }
.dlg .opt .btn small { display: block; color: var(--mut); font-weight: 400; }
.dlg code { font-family: var(--mono); font-size: 12px; word-break: break-all; background: var(--panel2); padding: 2px 4px; border-radius: 4px; }

/* Schmal: Panels als Bodenblatt */
@media (max-width: 760px) {
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto !important; max-height: 62%; height: 62%;
    border: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.right.peek { height: 38%; }
  .float { left: 8px; right: 8px; width: auto; top: 8px; }
  .modehint { bottom: 10px; font-size: 12px; }
}

/* Handy (hochkant schmal oder quer niedrig): Werkzeugleiste als Seitenleiste rechts.
   Die Bühne bekommt die volle Höhe, die 3D-Ansicht passt sich über den ResizeObserver an. */
@media (max-width: 760px), (max-height: 500px) and (orientation: landscape) {
  :root { --rail: 62px; }
  .bar {
    position: fixed; top: 0; right: 0; bottom: 0; left: auto; z-index: 20;
    width: calc(var(--rail) + env(safe-area-inset-right)); height: auto;
    flex-direction: column; align-items: stretch; gap: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
    border-bottom: 0; border-left: 1px solid var(--line);
  }
  .title { flex: none; max-width: none; justify-content: center; padding: 8px 0 4px; }
  .tt { display: none; }
  .logo { width: 24px; height: 24px; }
  .embed .title { display: none; }
  .tools {
    flex-direction: column; align-items: stretch; gap: 2px; flex: 1; min-height: 0;
    overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 4px 4px 6px;
    -webkit-overflow-scrolling: touch;
  }
  .tools > :first-child, .embed .tools > :first-child { margin-left: 0; }
  .sep { display: block; width: auto; height: 1px; margin: 3px 6px; }
  .tb { min-width: 0; width: 100%; height: 46px; padding: 3px 1px; border-radius: 9px; }
  .tb svg { width: 21px; height: 21px; }
  .tb span {
    font-size: 9.5px; line-height: 1.3; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .tb:hover { background: transparent; }
  .tb:active { background: var(--panel2); }
  .tb.on:hover, .tb.on:active { background: var(--ac); }
  .stage { height: 100%; margin-right: calc(var(--rail) + env(safe-area-inset-right)); }
  .toast { max-width: calc(100% - 24px); }
}

/* Handy quer: Panels als Seitenblatt links statt Bodenblatt */
@media (max-height: 500px) and (orientation: landscape) {
  .panel {
    position: absolute; top: 0; bottom: 0; left: 0; right: auto; width: min(320px, 46vw) !important; height: auto; max-height: none;
    border: 0; border-right: 1px solid var(--line); border-radius: 0; box-shadow: var(--shadow);
    padding-left: env(safe-area-inset-left); padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.right.peek { height: auto; }
  .float { left: auto; right: 8px; top: 8px; width: min(300px, 50vw); max-height: calc(100% - 16px); overflow: auto; }
  /* Zwei Spalten Symbole, damit alles ohne Scrollen in die niedrige Höhe passt */
  :root { --rail: 92px; }
  .title { display: none; }
  .tools { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 2px; }
  .sep { grid-column: 1 / -1; }
  .tb { height: 42px; }
  .tb span { display: none; }
}
