:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-2: #f7f9fa;
  --ink: #1b2630;
  --muted: #6b7884;
  --faint: #9aa5ae;
  --line: #e2e7eb;
  --accent: #0f8b8d;
  --accent-ink: #0b6f71;
  --accent-soft: #e2f3f3;
  --sel: #ff7a1a;
  --measure: #e8590c;
  --shadow: 0 8px 28px rgba(20, 35, 50, .12), 0 1px 3px rgba(20, 35, 50, .08);
  --radius: 12px;
  --top: 56px;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 13.5px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.small { padding: 3px 9px; font-size: 12.5px; white-space: nowrap; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
button.ghost:hover { color: var(--ink); background: var(--panel-2); }
button.ghost svg { width: 15px; height: 15px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
input[type=search] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
input[type=search]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 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; }
#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; }
#selRect { position: absolute; display: none; pointer-events: none; border: 1.5px solid var(--accent);
  background: rgba(15, 139, 141, .08); }
#selRect.crossing { border-style: dashed; background: rgba(255, 122, 26, .08); border-color: var(--sel); }

#loadBar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; }
#loadBarFill { height: 100%; width: 0; background: var(--accent); transition: width .2s, opacity .6s; }
#toast { position: fixed; top: calc(var(--top) + 70px); left: 50%; transform: translateX(-50%); z-index: 40; background: #24323d; color: #fff;
  padding: 7px 14px; border-radius: 8px; display: none; max-width: calc(100% - 32px); text-align: center; }

/* ---------------- top bar ---------------- */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top); z-index: 20; background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 14px;
  box-shadow: 0 1px 8px rgba(20,35,50,.05); }
#brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 260px; }
#brand .logo { width: 26px; height: 26px; color: var(--accent); flex: none; stroke-width: 1.6; }
#brand .bt { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
#title { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#statusText { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#searchWrap { position: relative; flex: 0 1 300px; min-width: 160px; }
#searchWrap > svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--faint); }
#searchWrap input { padding-left: 32px; background: var(--panel-2); }
#searchResults { position: absolute; top: calc(100% + 6px); left: 0; width: max(100%, 360px); list-style: none; margin: 0; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto; z-index: 25; }
#searchResults li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
#searchResults li:hover, #searchResults li.all { background: var(--panel-2); }
#searchResults li.all { font-weight: 600; color: var(--accent); }
#searchResults .c { color: var(--muted); flex: none; font-family: var(--mono); font-size: 12px; }
#filters { display: flex; gap: 6px; align-items: center; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#filters::-webkit-scrollbar { display: none; }
.fsel { position: relative; flex: none; }
.fsel select { appearance: none; -webkit-appearance: none; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 6px 28px 6px 10px; font-size: 12.5px; cursor: pointer; max-width: 190px; }
.fsel select:hover { border-color: var(--accent); }
.fsel.on select { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.fsel::after { content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
#topRight { display: flex; gap: 8px; align-items: center; flex: none; }
#filterCount { font-family: var(--mono); font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.switch input { display: none; }
.switch .track { width: 32px; height: 18px; border-radius: 999px; background: #cdd5db; position: relative; transition: background .15s; flex: none; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .knob { left: 16px; }
.switch .lbl { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: #3d4a55; }

/* ---------------- floating panels ---------------- */
.panel { position: fixed; top: calc(var(--top) + 12px); bottom: 44px; width: 290px; z-index: 10; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel.left { left: 12px; }
.panel.right { right: 0; top: var(--top); bottom: 0; width: 360px; border-radius: 0; border-width: 0 0 0 1px; box-shadow: -6px 0 24px rgba(20,35,50,.06); }
.panel.closed { display: none; }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px; }
.panel h2 { margin: 0; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: #3d4a55; }
.panel .x { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 2px 6px; color: var(--muted); }
.panel .x:hover { color: var(--ink); }
.pbody { padding: 4px 14px 14px; overflow: auto; flex: 1; min-height: 0; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; justify-content: flex-start; }
.hint { color: var(--muted); font-size: 12.5px; }
.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

.seg { display: inline-flex; background: #eef2f4; border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; font-size: 12.5px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--accent-ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

#layerTree, #layerTree ul { list-style: none; margin: 0; padding: 0; }
#layerTree ul { padding-left: 16px; }
#layerTree li > .lrow { display: flex; align-items: center; gap: 7px; padding: 4px 3px; border-radius: 6px; }
#layerTree li > .lrow:hover { background: var(--panel-2); }
.lrow .tw { width: 14px; text-align: center; color: var(--muted); cursor: pointer; user-select: none; }
.lrow .sw { position: relative; width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.2); flex: none; cursor: pointer; }
.lrow .sw input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.lrow .sw.custom { box-shadow: 0 0 0 2px var(--accent); }
.lrow .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; font-size: 12.5px; }
.lrow .ct { color: var(--faint); font-size: 11px; font-family: var(--mono); }
.lrow input { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent); }
li.collapsed > ul { display: none; }
li.hiddenByFilter { display: none; }

/* ---------------- properties ---------------- */
.phead { align-items: flex-start !important; padding: 16px 16px 10px !important; border-bottom: 1px solid var(--line); }
.phead .pt { min-width: 0; }
#propsTitle { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--accent-ink); word-break: break-all; }
#propsSub { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-top: 3px; word-break: break-all; }
.pbar { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.panel.right .pbody { padding: 0 16px 18px; }
.stitle { display: flex; justify-content: space-between; align-items: center; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint); font-weight: 600; margin: 18px 0 8px; }
.kv { display: grid; grid-template-columns: minmax(96px, 42%) 1fr; column-gap: 10px; }
.kv > div { padding: 6px 0; border-bottom: 1px solid #eef1f3; font-size: 12.5px; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-family: var(--mono); font-size: 12px; word-break: break-all; color: var(--ink); }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; }
.crumbs button { padding: 3px 8px; font-size: 11.5px; border-radius: 6px; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-family: var(--mono); background: var(--panel-2); }
.crumbs button.cur { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.crumbs .sep { color: var(--faint); }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0 2px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px; font-size: 11.5px; color: #3d4a55; }
.actions svg { width: 18px; height: 18px; }
.glist { list-style: none; padding: 0; margin: 0 0 10px; }
.glist li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #eef1f3; cursor: pointer; font-size: 12.5px; }
.glist li:hover { background: var(--panel-2); }
.glist .c { color: var(--muted); flex: none; font-family: var(--mono); }
.glist .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600;
  color: var(--accent-ink); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; }
#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: 15px; font-family: var(--mono); }
#measList .d { color: var(--muted); font-size: 12px; }
#measList button { float: right; }

/* ---------------- dock ---------------- */
#dock { position: fixed; left: 50%; top: calc(var(--top) + 12px); transform: translateX(-50%); z-index: 12;
  display: flex; gap: 12px; align-items: center; padding: 6px 10px; background: rgba(255,255,255,.97);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none; }
#dock::-webkit-scrollbar { display: none; }
.dgroup { display: flex; gap: 2px; flex: none; }
.dgroup + .dgroup { border-left: 1px solid var(--line); padding-left: 10px; }
#dock button { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: #34424d; flex: none; }
#dock button:hover { background: #eef2f4; }
#dock button.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px rgba(15,139,141,.45); }
#dock svg { width: 19px; height: 19px; }
#selChip { position: fixed; left: 50%; top: calc(var(--top) + 64px); transform: translateX(-50%); z-index: 11;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; color: var(--accent-ink);
  background: rgba(226,243,243,.95); border: 1px solid rgba(15,139,141,.35); border-radius: 999px; padding: 4px 12px; }
#stats { position: fixed; left: 14px; bottom: 12px; z-index: 9; font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; pointer-events: none; }

.pop { position: fixed; left: 50%; top: calc(var(--top) + 64px); transform: translateX(-50%); z-index: 13; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px;
  width: min(520px, calc(100% - 24px)); }
#sectionPop { display: flex; gap: 10px; align-items: center; }
#sectionPop input[type=range] { flex: 1; accent-color: var(--accent); }
#secVal { font-family: var(--mono); min-width: 92px; text-align: right; color: var(--muted); }

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

/* ---------------- tablets / phones ---------------- */
@media (max-width: 1100px) {
  #brand { flex-basis: 180px; }
  .switch .lbl { display: none; }
  .panel.right { width: 330px; }
}
@media (max-width: 760px) {
  :root { --top: 96px; }
  #topbar { flex-wrap: wrap; height: var(--top); padding: 6px 10px; gap: 6px 8px; align-content: center; }
  #brand { flex: 1 1 40%; }
  #statusText { display: none; }
  #searchWrap { flex: 1 1 50%; min-width: 0; }
  #searchResults { width: calc(100vw - 20px); left: auto; right: 0; }
  #topRight { display: contents; }
  .switch { order: 3; padding: 3px 6px; }
  #filters { order: 4; flex: 1 1 200px; }
  #btnSelectFiltered, #btnResetFilters { order: 5; }
  .fsel select { max-width: 150px; padding: 5px 24px 5px 8px; }
  .panel { top: calc(var(--top) + 8px); bottom: 70px; }
  .panel.left { left: 8px; right: auto; width: min(86vw, 320px); }
  .panel.right { left: 0; right: 0; width: auto; top: auto; bottom: 0; max-height: 50vh; border-radius: 14px 14px 0 0; border-width: 1px 0 0 0; z-index: 14; }
  #dock { top: auto; bottom: 10px; gap: 8px; padding: 5px 8px; justify-content: flex-start; }
  .dgroup + .dgroup { padding-left: 6px; }
  #dock button { width: 36px; height: 36px; }
  #selChip { top: calc(var(--top) + 10px); }
  .pop { top: auto; bottom: 64px; }
  #stats { display: none; }
}
