/* JoFo 3D: dark viewer in the JoFo event look (brand guide: event = indigo violet #785BCF, #9D84E9 on dark;
   yellow #F7E200 only as signal colour, used for measurements). */
@font-face { font-family: "JetBrains Mono"; src: url("assets/fonts/JetBrainsMono-Regular.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("assets/fonts/JetBrainsMono-Bold.ttf"); font-weight: 700; font-display: swap; }

:root {
  --night: #141517;
  --surface: #1C1D20;
  --line: #2E3034;
  --line-strong: #4A4D52;
  --text: #DAD9D6;
  --text-2: #ADAEB0;
  --muted: #7A7D81;
  --event: #9D84E9;
  --event-fill: #785BCF;
  --signal: #F7E200;
  --red: #E8664F;
  --radius: 2px;
  --font: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* elements with their own display (e.g. the side list) must still hide */
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--text); font: 14px/1.4 var(--font); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, select { font: inherit; color: inherit; }

#viewport { position: fixed; inset: 0; touch-action: none; }
#viewport canvas { display: block; outline: none; }
body.measuring #viewport { cursor: crosshair; }

/* ---------- bars */
.bar { position: fixed; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding-left: calc(16px + var(--safe-l)); padding-right: calc(16px + var(--safe-r));
  background: rgba(20, 21, 23, 0.86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.bar.top { top: 0; padding-top: calc(10px + var(--safe-t)); padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.bar.bottom { bottom: 0; padding-top: 6px; padding-bottom: calc(6px + var(--safe-b)); border-top: 1px solid var(--line);
  justify-content: center; gap: 4px; }
.logo { height: 34px; width: auto; flex: none; }

.model-title { margin-left: auto; min-width: 0; display: flex; align-items: baseline; gap: 8px; padding: 8px 0; }
.model-title .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.model-title .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw; }

.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; padding: 6px 8px;
  background: none; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; color: var(--text-2); font-size: 11px; }
.tool .ico { font-size: 20px; line-height: 1.1; color: var(--text); }
.tool:hover { border-color: var(--line-strong); }
.tool[aria-pressed="true"] { color: var(--event); border-color: var(--event); background: rgba(120, 91, 207, 0.16); }
.tool[aria-pressed="true"] .ico { color: var(--event); }
.tool:focus-visible, .btn:focus-visible { outline: 2px solid var(--event); outline-offset: 2px; }

/* ---------- loader */
.loader { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--event-fill); padding: 14px 16px; }
.loader-label { font-size: 13px; margin-bottom: 10px; color: var(--text-2); }
.loader-track { height: 4px; background: var(--line); }
.loader-fill { height: 100%; width: 0; background: var(--event); transition: width .15s; }

/* ---------- measure panel */
.panel { position: fixed; z-index: 11; left: calc(16px + var(--safe-l)); top: calc(70px + var(--safe-t)); width: min(380px, calc(100vw - 32px));
  background: rgba(28, 29, 32, 0.94); border: 1px solid var(--line); border-left: 3px solid var(--signal); padding: 12px 14px; }
.panel-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; position: relative; padding-right: 36px; }
.panel-head .close { position: absolute; top: -4px; right: -4px; padding: 4px 8px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--signal); }
.hint { font-size: 12px; color: var(--text-2); }
.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 12px; }
.seg { background: none; border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 7px 2px; font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg:hover { border-color: var(--event); color: var(--text); }
.seg[aria-pressed="true"] { border-color: var(--signal); color: var(--signal); background: rgba(247, 226, 0, 0.08); }
.readout { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.readout .wide { grid-column: 1 / -1; }
.readout div { display: flex; flex-direction: column; }
.readout .k { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.readout .v { font-variant-numeric: tabular-nums; }
.readout .v.big { font-size: 22px; font-weight: 700; color: var(--signal); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.btn { background: var(--event-fill); color: #fff; border: 1px solid var(--event-fill); border-radius: var(--radius); padding: 7px 10px; cursor: pointer; font-size: 12px; }
.btn.ghost { background: none; color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { border-color: var(--event); }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.link { background: none; border: none; padding: 0; color: var(--event); text-decoration: underline; cursor: pointer; }

/* measurement labels (CSS2D) */
.m-label { font: 700 12px/1 var(--font); color: #000; background: var(--signal); padding: 4px 6px; border-radius: var(--radius);
  white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.m-label.big { font-size: 14px; padding: 5px 8px; }
.m-label.small { font-size: 10px; padding: 3px 4px; opacity: .92; }
.m-label.preview { background: var(--event); color: #fff; }
.m-label.sel { outline: 2px solid #fff; }

/* ---------- dialogs */
.sheet { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto; padding: 16px 18px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-top: 3px solid var(--event-fill); border-radius: var(--radius); }
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet h2 { margin: 0; font-size: 17px; }
.note { font-size: 12px; color: var(--text-2); margin: 14px 0 0; }
.help { width: 100%; border-collapse: collapse; font-size: 12px; }
.help th, .help td { text-align: left; vertical-align: top; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.help th { color: var(--muted); font-weight: 400; text-transform: uppercase; font-size: 10px; letter-spacing: .08em; }
.help td:first-child { color: var(--event); white-space: nowrap; }

.toast { position: fixed; z-index: 30; left: 50%; top: calc(72px + var(--safe-t)); transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line-strong); border-left: 3px solid var(--event-fill); padding: 8px 12px; font-size: 12px; }
.toast.err { border-left-color: var(--red); }



/* ---------- target row, side list */
.target-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.target-row .k, .field .k { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); white-space: nowrap; }
select, input.text, .field input, .g-new input, input.inline {
  font: 13px var(--font); color: var(--text); background: var(--night); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 7px 8px; min-width: 0; }
.target-row select { flex: 1; }
select:focus, input:focus { outline: 2px solid var(--event); outline-offset: 1px; }

.side { position: fixed; z-index: 12; right: calc(16px + var(--safe-r)); top: calc(70px + var(--safe-t)); bottom: calc(76px + var(--safe-b));
  width: 360px; display: flex; flex-direction: column; background: rgba(28, 29, 32, 0.96); border: 1px solid var(--line);
  border-top: 3px solid var(--event-fill); }
.side-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 6px; }
.side-head .tag { color: var(--event); }
.side-head .close { margin-left: auto; padding: 4px 8px; }
.sync { font-size: 11px; color: var(--muted); }
.sync.err { color: var(--red); }
.g-new { display: flex; gap: 6px; padding: 4px 12px 10px; border-bottom: 1px solid var(--line); }
.g-new input { flex: 1; }
.side-list { flex: 1; overflow: auto; padding: 6px 0 10px; overscroll-behavior: contain; }
.side-list .empty { color: var(--muted); font-size: 12px; padding: 6px 12px; list-style: none; }
.side-foot { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-2); }
.side-foot .note { display: block; margin: 4px 0 0; font-size: 11px; color: var(--muted); }

.grp { padding: 4px 0 8px; }
.grp + .grp { border-top: 1px solid var(--line); }
.ghead { display: flex; align-items: center; gap: 6px; padding: 6px 10px 2px 8px; }
.gname { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp.target .gname { color: var(--signal); }
.cnt { font-size: 11px; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 9px; padding: 0 6px; }
.ghead .note { font-size: 11px; color: var(--muted); }
.spacer { flex: 1; }
.gmeta { font-size: 10px; color: var(--muted); padding: 0 12px 4px 38px; }
.mini { background: none; border: 1px solid transparent; border-radius: var(--radius); color: var(--text-2); font-size: 11px; padding: 3px 6px; cursor: pointer; white-space: nowrap; }
.mini:hover { border-color: var(--line-strong); color: var(--text); }
.grp.target .tgt { color: var(--signal); }
.mini.danger:hover { color: var(--red); border-color: var(--red); }

.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 2px; padding: 0 8px; }
.item .main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; background: none; border: 1px solid transparent;
  border-radius: var(--radius); padding: 6px 6px; cursor: pointer; text-align: left; }
.item .main:hover { border-color: var(--line-strong); }
.item.sel .main { border-color: var(--signal); background: rgba(247, 226, 0, 0.06); }
.item.active .nm::after { content: " ✎"; color: var(--event); }
.item .ic { color: var(--signal); width: 1.2em; text-align: center; flex: none; }
.item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .val { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.eye { background: none; border: none; color: var(--event); font-size: 15px; width: 28px; height: 28px; cursor: pointer; flex: none; padding: 0; }
.eye.off { color: var(--muted); }
.detail { margin: 2px 10px 8px 38px; padding: 8px 10px; border-left: 2px solid var(--signal); background: rgba(0, 0, 0, 0.18); display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; align-items: center; gap: 8px; }
.field .k { width: 52px; }
.field input, .field select { flex: 1; }
.dvals { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.dvals div { display: flex; flex-direction: column; }
.dvals .k { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dvals .v { font-size: 12px; font-variant-numeric: tabular-nums; }
.detail .meta { font-size: 11px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 6px; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.detail .row .btn { padding: 6px 8px; font-size: 11px; }

/* dialogs: name, export */
.sheet.narrow { width: min(440px, calc(100vw - 32px)); }
.sheet h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; font-weight: 400; }
.sheet .row .btn { text-decoration: none; display: inline-block; }
input.text { width: 100%; font-size: 16px; padding: 10px 12px; margin-top: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }

@media (max-width: 520px) {
  .logo { height: 26px; }
  .tool { min-width: 0; flex: 1; padding: 6px 0; font-size: 9.5px; }
  .tool .ico { font-size: 18px; }
  .model-title .lbl { display: none; }
  .model-title .name { max-width: 60vw; }
  .panel { top: auto; bottom: calc(72px + var(--safe-b)); left: 8px; width: calc(100vw - 16px); padding: 10px 12px; }
  .readout { grid-template-columns: repeat(2, 1fr); gap: 4px 10px; }
  .readout .wide { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 8px; }
  .seg { font-size: 9.5px; padding: 6px 0; letter-spacing: -.02em; }
  .side { left: 0; right: 0; width: auto; top: auto; height: min(62dvh, 560px); bottom: calc(60px + var(--safe-b)); border-left: 0; border-right: 0; }
  body.side-open .panel { display: none; }
  .tools { margin-bottom: 8px; }
  .readout .v { font-size: 12px; }
  .readout .v.big { font-size: 16px; }
  .panel-actions .btn { flex: 1; padding: 7px 4px; font-size: 11px; }
  .hint { font-size: 11px; }
}

/* ---------- simple pages (landing, login, not found) */
.page { min-height: 100%; display: flex; align-items: center; justify-content: center; overflow: auto;
  padding: calc(24px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }
html:has(.page), body.page-body { overflow: auto; }
.card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--event-fill); padding: 24px 22px; }
.card .logo { height: 40px; display: block; margin-bottom: 22px; }
.card h1 { font-size: 18px; margin: 0 0 6px; }
.card p { color: var(--text-2); font-size: 13px; margin: 0 0 18px; }
.card label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.card input[type=password] { width: 100%; font: 16px var(--font); color: var(--text); background: var(--night); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 11px 12px; }
.card input[type=password]:focus { outline: 2px solid var(--event); outline-offset: 1px; border-color: var(--event); }
.card .btn { width: 100%; margin-top: 14px; padding: 11px; font-size: 14px; font-weight: 700; }
.card .btn:hover { background: #8B6FDB; }
.card .err { color: var(--red); font-size: 13px; margin: 10px 0 0; }
.card .foot { margin: 20px 0 0; font-size: 11px; color: var(--muted); }
