:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #1d2730;
  --muted: #66737f;
  --line: #d6dde3;
  --accent: #0f8b8d;
  --accent-ink: #ffffff;
  --measure: #e8590c;
  --side-w: 300px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.35 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button, select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; cursor: pointer; min-height: 34px; }
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 3px 8px; min-height: 28px; font-size: 13px; }
button.icon { width: 38px; padding: 0; font-size: 18px; }

#app { display: grid; height: 100%; grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto; grid-template-areas: "bar bar" "side view" "status status"; }
#app.noside { grid-template-columns: 0 minmax(0, 1fr); }
#app.noside #side { display: none; }

#toolbar { grid-area: bar; display: flex; min-width: 0; align-items: center; gap: 8px; padding: 6px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#title { font-weight: 600; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.group { display: flex; gap: 4px; flex-wrap: wrap; }

#side { grid-area: side; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; border-bottom: 2px solid transparent; }
#tabs button.active { color: var(--accent); background: transparent; border-bottom-color: var(--accent); }
.tab { display: none; padding: 8px; overflow: auto; flex: 1; min-height: 0; }
.tab.active { display: block; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; justify-content: space-between; }
.row input[type=search] { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.hint { color: var(--muted); font-size: 13px; }
.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

#layerTree, #layerTree ul { list-style: none; margin: 0; padding: 0; }
#layerTree ul { padding-left: 16px; }
#layerTree li > .lrow { display: flex; align-items: center; gap: 6px; padding: 3px 2px; border-radius: 4px; }
#layerTree li > .lrow:hover { background: #f2f6f8; }
.lrow .tw { width: 16px; text-align: center; color: var(--muted); cursor: pointer; user-select: none; }
.lrow .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); flex: none; }
.lrow .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lrow .ct { color: var(--muted); font-size: 12px; }
.lrow input { width: 18px; height: 18px; margin: 0; flex: none; }
li.collapsed > ul { display: none; }
li.hiddenByFilter { display: none; }

#measList { padding-left: 20px; margin: 4px 0; }
#measList li { padding: 6px 0; border-bottom: 1px solid var(--line); }
#measList .big { font-weight: 600; font-size: 16px; }
#measList .d { color: var(--muted); font-size: 12px; }
#measList button { float: right; }

#infoBody table { width: 100%; border-collapse: collapse; font-size: 13px; }
#infoBody td { border-bottom: 1px solid var(--line); padding: 4px 2px; vertical-align: top; word-break: break-all; }
#infoBody td:first-child { color: var(--muted); width: 38%; word-break: normal; }
#infoBody h3 { margin: 6px 0; font-size: 15px; word-break: break-all; }

#view { grid-area: view; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; }
.mlabel { position: absolute; transform: translate(-50%, -130%); background: var(--measure); color: #fff;
  padding: 2px 6px; border-radius: 4px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.mlabel.pt { background: #2b3a45; }
#snapMark { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--measure);
  border-radius: 2px; pointer-events: none; display: none; }
#snapMark.face { border-radius: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; }
#sectionBar { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px;
  align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  width: min(560px, calc(100% - 32px)); }
#sectionBar input[type=range] { flex: 1; }
#secVal { font-variant-numeric: tabular-nums; min-width: 90px; text-align: right; color: var(--muted); }
#toast { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #2b3a45; color: #fff;
  padding: 6px 12px; border-radius: 6px; display: none; max-width: calc(100% - 32px); }

#status { grid-area: status; display: flex; min-width: 0; overflow: hidden; align-items: center; gap: 10px; padding: 4px 10px;
  background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#progress { width: 140px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; flex: none; }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#picker { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
#picker .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; width: min(520px, 100%); }
#picker h1 { font-size: 18px; margin: 0 0 10px; }
#modelList { list-style: none; padding: 0; margin: 0; }
#modelList a { display: block; padding: 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px;
  color: var(--ink); text-decoration: none; }
#modelList a:hover { border-color: var(--accent); }
#modelList small { color: var(--muted); display: block; }

@media (max-width: 760px) {
  #app, #app.noside { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "view" "status"; }
  #side { position: fixed; z-index: 5; left: 0; width: min(88vw, 340px);
    top: var(--bar-h, 47px); bottom: var(--status-h, 26px); box-shadow: 0 0 20px rgba(0,0,0,.2); }
  #app.noside #side { display: none; }
  #title { display: none; }
  #toolbar { flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding: 6px; }
  .group { flex-wrap: nowrap; }
  #toolbar button, #toolbar select { padding: 4px 8px; flex: none; }
}
