/* flat3d / app.css — dark instrument panel around a bright 3D view */

:root {
  --bg: #0e1117;
  --panel: #161b23;
  --panel-2: #1d242e;
  --line: #2b3340;
  --ink: #e7ecf3;
  --ink-dim: #96a1b2;
  --accent: #35d0ff;
  --accent-2: #7ee0b8;
  --warn: #ffc857;
  --danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------------------------------------------------------------- gate */

.gate {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background:
    radial-gradient(1100px 620px at 50% -12%, #23405c 0%, transparent 62%),
    linear-gradient(160deg, #0d1016 0%, #131a24 55%, #0b0e13 100%);
  padding: 24px;
}

.gate-card {
  width: min(400px, 100%);
  background: rgba(22, 27, 35, .92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 30px 26px;
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(14px);
}

.gate-mark { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.gate-card h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.4px; font-weight: 650; }
.gate-sub { margin: 0 0 22px; color: var(--ink-dim); font-size: 13.5px; line-height: 1.55; }

.gate-card input {
  width: 100%; padding: 13px 15px; font-size: 16px;
  background: #0e131b; border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.gate-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53,208,255,.16); }

.gate-card button {
  width: 100%; margin-top: 12px; padding: 13px;
  font-size: 15px; font-weight: 600;
  background: linear-gradient(180deg, #3ad4ff, #17a8d8);
  color: #05202c; border: 0; border-radius: 10px; cursor: pointer;
  transition: filter .15s, transform .08s;
}
.gate-card button:hover { filter: brightness(1.08); }
.gate-card button:active { transform: translateY(1px); }
.gate-card button:disabled { opacity: .6; cursor: default; }

.gate-err { margin-top: 12px; color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------------------------------------------------------------- boot */

.boot {
  position: fixed; inset: 0; z-index: 55;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #0d1016, #131a24);
}
.boot-inner { text-align: center; color: var(--ink-dim); font-size: 14px; line-height: 1.6; }
.boot-spin {
  width: 42px; height: 42px; margin: 0 auto 18px;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- app */

.app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 54px; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: linear-gradient(180deg, rgba(10,13,18,.92), rgba(10,13,18,.35) 70%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none; }

.brand { font-weight: 650; letter-spacing: -.3px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand em { font-style: normal; color: var(--accent); font-weight: 600; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }

.seg { display: inline-flex; background: rgba(26,32,41,.9); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  background: transparent; border: 0; color: var(--ink-dim);
  padding: 8px 14px; font-size: 13px; cursor: pointer; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent); color: #062430; font-weight: 600; }
.seg.small button { padding: 6px 10px; font-size: 12px; }

.topactions { display: flex; gap: 8px; }

button.ghost, button.primary, button.danger {
  border-radius: 9px; padding: 8px 13px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--line); transition: background .15s, border-color .15s, transform .08s;
}
button.ghost { background: rgba(26,32,41,.9); color: var(--ink); }
button.ghost:hover { background: #222a35; border-color: #3a4452; }
button.primary { background: var(--accent); border-color: var(--accent); color: #062430; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: rgba(60,26,30,.9); border-color: #5b2b2f; color: #ffb4b4; }
button.danger:hover { background: #6b2b30; color: #fff; }
button.small { padding: 6px 10px; font-size: 12px; }
button.wide { width: 100%; }
button.icon { padding: 8px 11px; }
button:active { transform: translateY(1px); }

/* ---------------------------------------------------------------- panels */

.panel {
  position: absolute; top: 62px; bottom: 54px; width: 322px; z-index: 22;
  background: rgba(19,24,31,.95);
  border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow); backdrop-filter: blur(16px);
  animation: slide .18s ease-out;
}
.panel.left { left: 12px; }
.panel.right { right: 12px; }
.panel.wide-panel { width: 400px; }
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.panel .x { background: none; border: 0; color: var(--ink-dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.panel .x:hover { color: var(--ink); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px 14px 18px; }
.panel-foot { padding: 10px 14px; border-top: 1px solid var(--line); }

.panel-body::-webkit-scrollbar { width: 9px; }
.panel-body::-webkit-scrollbar-thumb { background: #2f3946; border-radius: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }

.panel section { margin-bottom: 20px; }
.panel section h3 {
  margin: 0 0 9px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .09em; color: var(--ink-dim); font-weight: 600;
}

.row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.row > * { flex: 1; }
.row input[type=color] { flex: 0 0 44px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; }

.search {
  width: 100%; padding: 8px 10px; font-size: 13px;
  background: #0e131b; border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); outline: none;
}
.search:focus { border-color: var(--accent); }
select.search { cursor: pointer; }

.fld { display: block; margin-bottom: 10px; font-size: 12px; color: var(--ink-dim); }
.fld span { display: block; margin-bottom: 4px; }
.fld input[type=range] { width: 100%; accent-color: var(--accent); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; }

/* room list */

.room-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; margin-bottom: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink); padding: 10px 12px; font-size: 13px; cursor: pointer;
  transition: background .14s, border-color .14s;
}
.room-btn:hover { background: #26303c; border-color: #3c4757; }
.room-btn.on { border-color: var(--accent); background: #1b2c36; }
.room-btn small { color: var(--ink-dim); font-size: 11px; }

/* selection info */

.sel-info {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font-size: 12.5px; line-height: 1.6; color: var(--ink-dim);
  min-height: 44px;
}
.sel-info strong { color: var(--ink); font-weight: 600; }
.sel-info code { font-size: 11px; color: var(--accent-2); }

/* swatches */

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches button {
  aspect-ratio: 1; border-radius: 7px; border: 1px solid rgba(255,255,255,.14);
  cursor: pointer; padding: 0; transition: transform .1s, box-shadow .1s;
}
.swatches button:hover { transform: scale(1.12); box-shadow: 0 0 0 2px var(--accent); }

/* add catalogue */

.addlist { margin-top: 8px; max-height: 236px; overflow-y: auto; }
.addlist::-webkit-scrollbar { width: 8px; }
.addlist::-webkit-scrollbar-thumb { background: #2f3946; border-radius: 6px; }
.add-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #66728a; margin: 10px 0 5px; }
.add-btn {
  display: block; width: 100%; text-align: left; margin-bottom: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); padding: 7px 10px; font-size: 12.5px; cursor: pointer;
}
.add-btn:hover { background: #26303c; border-color: var(--accent); }

/* doors + windows */

.openlist { margin-top: 8px; max-height: 240px; overflow-y: auto; }
.openlist::-webkit-scrollbar { width: 8px; }
.openlist::-webkit-scrollbar-thumb { background: #2f3946; border-radius: 6px; }
.open-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #66728a; margin: 10px 0 5px; }
.open-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
.open-row span { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-row button {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink-dim); cursor: pointer; font-size: 11px; padding: 2px 8px; min-width: 56px;
}
.open-row button.on { color: #0d1117; background: var(--accent); border-color: var(--accent); }
.open-row button:hover { border-color: var(--accent); }

/* snapshots */
.snaplist { margin: 8px 0; }
.snap-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 5px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
.snap-row span { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snap-row button { background: none; border: 0; color: var(--ink-dim); cursor: pointer; font-size: 12px; padding: 2px 5px; }
.snap-row button:hover { color: var(--accent); }
.snap-row button.rm:hover { color: var(--danger); }

/* photos */

.photogrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.photogrid img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 7px;
  cursor: pointer; border: 1px solid var(--line); transition: transform .12s, border-color .12s;
  background: #0e131b;
}
.photogrid img:hover { transform: scale(1.05); border-color: var(--accent); }

/* ---------------------------------------------------------------- hud */

.hud {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46px; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: linear-gradient(0deg, rgba(10,13,18,.9), transparent);
  font-size: 12px; color: var(--ink-dim); pointer-events: none;
}
.hud-room { color: var(--ink); font-weight: 600; }
.hud-tip { flex: 1; text-align: center; opacity: .8; }
.hud-save { font-variant-numeric: tabular-nums; }
.hud-save.dirty { color: var(--warn); }
.hud-save.ok { color: var(--accent-2); }
.hud-save.err { color: var(--danger); }

/* ---------------------------------------------------------------- menu */

.menu {
  position: absolute; top: 58px; right: 12px; z-index: 30;
  background: rgba(19,24,31,.97); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; min-width: 182px;
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: var(--ink); padding: 10px 14px; font-size: 13px; cursor: pointer;
}
.menu button:hover { background: #26303c; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: absolute; left: 50%; bottom: 62px; transform: translateX(-50%) translateY(10px);
  z-index: 40; padding: 9px 16px; border-radius: 9px; font-size: 13px;
  background: rgba(24,30,39,.96); border: 1px solid var(--line); color: var(--ink);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 76vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: #2c6b52; }
.toast.warn { border-color: #6b5a2c; }
.toast.err { border-color: #6b2c2c; }

/* ---------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6,8,12,.94);
  display: grid; place-items: center; padding: 42px 60px;
}
.lb-stage { max-width: 100%; max-height: 100%; display: grid; place-items: center; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 82vh; border-radius: 10px; box-shadow: var(--shadow); }
.lb-cap { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center; font-size: 12.5px; color: var(--ink-dim); }
.lb-x {
  position: absolute; top: 16px; right: 20px; background: none; border: 0;
  color: #fff; font-size: 34px; line-height: 1; cursor: pointer; opacity: .75;
}
.lb-x:hover { opacity: 1; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.08); border: 0; color: #fff;
  width: 46px; height: 74px; font-size: 30px; cursor: pointer; border-radius: 9px;
}
.lb-nav:hover { background: rgba(255,255,255,.18); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

.help-card {
  max-width: 620px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 28px; box-shadow: var(--shadow);
  max-height: 84vh; overflow-y: auto;
}
.help-card h2 { margin: 0 0 16px; font-size: 19px; }
.help-card table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-card th {
  text-align: left; vertical-align: top; padding: 8px 14px 8px 0;
  color: var(--accent); font-weight: 600; white-space: nowrap;
}
.help-card td { padding: 8px 0; color: var(--ink-dim); line-height: 1.6; border-bottom: 1px solid #222a35; }
.help-card em { color: var(--ink); font-style: normal; font-weight: 600; }
.help-note { margin-top: 18px; font-size: 12.5px; color: var(--ink-dim); line-height: 1.65; }
kbd {
  background: #0e131b; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; font-size: 11px; font-family: ui-monospace, monospace;
  color: var(--ink); margin-right: 2px;
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .topbar { height: 50px; gap: 8px; padding: 0 8px; }
  .brand { display: none; }
  .topactions button.ghost { padding: 7px 9px; font-size: 12px; }
  .panel { top: 56px; bottom: 50px; width: auto; left: 8px; right: 8px; }
  .panel.wide-panel { width: auto; }
  .hud-tip { display: none; }
  .lightbox { padding: 30px 12px; }
  .lb-nav { width: 38px; height: 60px; font-size: 24px; }
  .photogrid { grid-template-columns: repeat(4, 1fr); }
}

/* ------------------------------------------------------------------ *
 * measurement overlay
 * ------------------------------------------------------------------ */

.measure-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.mlabel {
  position: absolute;
  top: 0;
  left: 0;
  white-space: nowrap;
  font: 600 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .01em;
  color: #06202b;
  background: rgba(190, 240, 255, .93);
  border: 1px solid rgba(8, 60, 80, .55);
  border-radius: 6px;
  padding: 3px 7px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
  will-change: transform;
}

.mlabel b { font-weight: 700; margin-right: 4px; color: #0b3b4d; }

.mlabel.m-sel {
  background: var(--accent);
  color: #04222c;
  border-color: #b8f2ff;
  font-size: 12px;
  padding: 4px 9px;
  box-shadow: 0 3px 16px rgba(53, 208, 255, .4);
}

.mlabel.m-wall    { background: rgba(255, 224, 160, .93); }
.mlabel.m-floor   { background: rgba(200, 255, 214, .93); }
.mlabel.m-ceiling { background: rgba(224, 214, 255, .93); }
.mlabel.m-door    { background: rgba(255, 196, 168, .95); }
.mlabel.m-window  { background: rgba(186, 226, 255, .95); }
.mlabel.m-sel     { background: var(--accent); }
.panel .hint {
  margin: 6px 0 0; font-size: 11px; line-height: 1.45; color: var(--ink-dim);
}

/* ------------------------------------------------------------------ *
 * walk-mode reticle
 * ------------------------------------------------------------------ */
.reticle {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  pointer-events: none;
  z-index: 60;
  opacity: .92;
}
.reticle.hidden { display: none; }
.reticle::before,
.reticle::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,.9);
  box-shadow: 0 0 2px rgba(0,0,0,.85);
}
.reticle::before { left: 0; right: 0; top: 12px; height: 2px; }
.reticle::after  { top: 0; bottom: 0; left: 12px; width: 2px; }
.reticle i {
  position: absolute;
  left: 9px;
  top: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.95);
  background: rgba(0,0,0,.28);
  box-shadow: 0 0 3px rgba(0,0,0,.9);
}
.reticle.hot i { border-color: #59c6ff; background: rgba(89,198,255,.35); }

/* browser-only (/view) badge in the top bar */
.mode-badge {
  margin-left: .55rem;
  padding: .12rem .45rem;
  border-radius: 999px;
  font: 600 10px/1.6 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #ffd79a;
  background: rgba(255,170,60,.16);
  border: 1px solid rgba(255,170,60,.38);
  vertical-align: middle;
}
.mode-badge.hidden { display: none; }
