/* ---------- 3D floor plan viewer ---------- */
:root {
  --panel: rgba(24, 26, 30, 0.86);
  --panel-2: rgba(255, 255, 255, 0.06);
  --ink: #ececec;
  --muted: #a9adb3;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #f0b64a;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #d9dde3; color: var(--ink); }
#app { position: fixed; inset: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; }
#c:active { cursor: grabbing; }
body.walking #c { cursor: crosshair; }

/* labels projected from 3D */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.room-label { position: absolute; left: 0; top: 0; text-align: center; color: #1c1e22; text-shadow: 0 0 3px rgba(255,255,255,.9), 0 0 8px rgba(255,255,255,.7); white-space: nowrap; line-height: 1.15; }
.room-label b { display: block; font-size: 13px; letter-spacing: .02em; }
.room-label small { display: block; font-size: 11px; color: #3b3f46; }
body.hide-dims .room-label small { display: none; }

/* top bar */
#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 10px 14px; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { background: var(--panel); border-radius: var(--radius); padding: 8px 12px; min-width: 0; }
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; font-size: 11.5px; color: var(--muted); }
.modes { display: flex; background: var(--panel); border-radius: var(--radius); padding: 4px; gap: 4px; }
.modes button, #btn-settings, #btn-exit-walk, .seg button { appearance: none; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.modes button.active { background: var(--accent); color: #1a1a1a; font-weight: 600; }
.modes button:hover:not(.active) { background: var(--panel-2); }
#btn-settings { margin-left: auto; background: var(--panel); border-radius: var(--radius); font-size: 18px; line-height: 1; padding: 9px 12px; }
#btn-exit-walk { position: absolute; top: 12px; right: 14px; background: var(--panel); border-radius: var(--radius); }
body.walking #topbar .modes, body.walking #topbar .brand, body.walking #btn-settings { opacity: .35; }
body.walking #topbar .modes:hover, body.walking #btn-settings:hover { opacity: 1; }

/* settings panel */
#panel { position: absolute; top: 64px; right: 14px; bottom: 14px; width: 300px; background: var(--panel); border-radius: var(--radius); padding: 6px 16px 16px; overflow: auto; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 13px; transform: translateX(calc(100% + 20px)); transition: transform .25s ease; }
body.panel-open #panel { transform: none; }
#panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
#panel section:last-child { border-bottom: 0; }
#panel h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
#panel-close { position: absolute; top: 8px; right: 10px; border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
label { display: block; margin: 8px 0; color: var(--ink); }
label output { float: right; color: var(--accent); font-variant-numeric: tabular-nums; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check output { margin-left: auto; float: none; }
input[type=range] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
select { width: 100%; margin-top: 6px; background: #2b2e34; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; line-height: 1.4; }
.seg { display: flex; gap: 4px; margin-top: 6px; }
.seg button { flex: 1; background: var(--panel-2); padding: 5px 0; font-size: 12px; }
.seg button:hover { background: rgba(255,255,255,.14); }
.compass { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.compass svg { width: 84px; height: 84px; flex: none; }
.compass .hint { margin: 0; }
#rose { transition: transform .2s ease; transform-origin: 50px 50px; }
ul.notes { margin: 6px 0 0; padding-left: 16px; color: var(--muted); font-size: 11.5px; line-height: 1.45; }

/* walk joystick */
#joystick { position: absolute; left: 22px; bottom: 26px; width: 120px; height: 120px; border-radius: 50%; background: rgba(0,0,0,.28); border: 2px solid rgba(255,255,255,.35); touch-action: none; }
#joystick .knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.75); transform: translate(-50%,-50%); }

/* toast */
.toast { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(10px); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: min(92vw, 520px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }

[hidden] { display: none !important; }

/* ---------- renovation edit mode ---------- */
#btn-edit { background: var(--panel); border-radius: var(--radius); border: 0; color: var(--ink); font: inherit; font-size: 13px; padding: 9px 12px; cursor: pointer; margin-left: auto; }
#btn-edit.active { background: #c0392b; color: #fff; font-weight: 600; }
#btn-edit + #btn-shot, #btn-shot + #btn-settings { margin-left: 0; }
#btn-shot { background: var(--panel); border-radius: var(--radius); border: 0; color: var(--ink); font: inherit; font-size: 16px; line-height: 1; padding: 9px 11px; cursor: pointer; }
button.wide { display: block; width: 100%; margin-top: 8px; appearance: none; border: 0; background: var(--panel-2); color: var(--ink); font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
button.wide:hover { background: rgba(255,255,255,.16); }
button.wide.on { background: var(--accent); color: #1a1a1a; font-weight: 600; }
#shot { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
#shot img { max-width: 100%; max-height: 62vh; border-radius: 8px; display: block; }
/* room finishes */
#inspector .sec { margin: 10px 0 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
#inspector .sec span { text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 500; margin-left: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 38px; height: 38px; border-radius: 8px; border: 2px solid rgba(255,255,255,.15); padding: 0; cursor: pointer; background-size: cover; background-position: center; position: relative; }
.swatch:hover { border-color: rgba(255,255,255,.55); }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240,182,74,.35); }
.swatch.custom { display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(#3a3d43 0 25%, #2a2d33 0 50%) 0 0 / 12px 12px; color: var(--muted); font-size: 18px; }
.swatch.custom input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#edit-toolbar { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 5px; background: var(--panel); border-radius: var(--radius); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); max-width: calc(100vw - 24px); flex-wrap: wrap; justify-content: center; }
#edit-toolbar button { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); font: inherit; font-size: 12.5px; padding: 7px 11px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
#edit-toolbar button:hover:not(:disabled) { background: rgba(255,255,255,.16); }
#edit-toolbar button:disabled { opacity: .35; cursor: default; }
#edit-toolbar button.on { background: var(--accent); color: #1a1a1a; font-weight: 600; }
#edit-toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
#edit-toolbar .count { color: var(--muted); font-size: 12px; padding: 0 8px; }
#inspector { position: absolute; left: 14px; bottom: 74px; width: 320px; max-width: calc(100vw - 28px); background: var(--panel); border-radius: var(--radius); padding: 14px 16px 12px; font-size: 13px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 8px 30px rgba(0,0,0,.25); }
#inspector .ins-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-bottom: 8px; padding-right: 24px; }
#inspector .ins-head b { font-size: 14px; }
#inspector .tag { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
#inspector .dim { color: var(--muted); font-size: 12px; flex-basis: 100%; }
#inspector .row { display: flex; align-items: center; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
#inspector .row > span { color: var(--muted); min-width: 64px; }
#inspector .row .seg { flex: 1; margin: 0; }
#inspector button { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); font: inherit; font-size: 12.5px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
#inspector button:hover { background: rgba(255,255,255,.16); }
#inspector button.danger { background: rgba(192,57,43,.35); }
#inspector button.danger:hover { background: rgba(192,57,43,.6); }
#inspector .seg button.on { background: var(--accent); color: #1a1a1a; font-weight: 600; }
#inspector .ins-close { position: absolute; top: 6px; right: 8px; background: transparent; color: var(--muted); font-size: 18px; padding: 2px 6px; }
#inspector label { margin: 6px 0; }
body.editing #c { cursor: default; }
/* furniture palette */
#palette { position: absolute; top: 64px; right: 14px; bottom: 74px; width: 300px; background: var(--panel); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: flex; flex-direction: column; gap: 8px; transform: translateX(calc(100% + 20px)); transition: transform .25s ease; }
body.palette-open #palette { transform: none; }
#palette .pal-head { display: flex; align-items: center; justify-content: space-between; }
#palette .pal-head b { font-size: 14px; }
#palette .hint { margin: 0; }
#palette-close { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; }
.pal-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.pal-tabs button { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 999px; cursor: pointer; }
.pal-tabs button.on { background: var(--accent); color: #1a1a1a; font-weight: 600; }
.pal-items { overflow: auto; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.pal-items button { appearance: none; border: 0; background: var(--panel-2); color: var(--ink); font: inherit; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.pal-items button:hover { background: rgba(255,255,255,.16); }
.pal-items button b { font-size: 13px; font-weight: 600; }
.pal-items button small { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#edit-toolbar button#btn-furniture.on { background: var(--accent); color: #1a1a1a; font-weight: 600; }
#measure-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.m-label { position: absolute; left: 0; top: 0; background: #f0b64a; color: #1a1a1a; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 2px 7px; border-radius: 999px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.35); line-height: 1.3; text-align: center; }
.m-label small { font-weight: 500; font-size: 10px; margin-left: 3px; opacity: .8; }
.m-label .sub { display: block; font-weight: 500; font-size: 10px; opacity: .8; }
.m-label.total { background: #1d1f23; color: #f0b64a; }
.m-label.dim { background: #4aa3f0; color: #fff; }
.m-label.live { opacity: .85; }
.m-label.lock { background: #4aa3f0; color: #fff; padding: 1px 5px; font-size: 11px; }
#export { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
.export-card { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; width: min(760px, 100%); max-height: 90vh; display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.export-card h3 { margin: 0; font-size: 14px; }
.export-card textarea { width: 100%; height: min(50vh, 420px); background: #16181c; color: #d7dce2; border: 1px solid var(--line); border-radius: 8px; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 10px; resize: vertical; }
.export-card .row { display: flex; gap: 8px; justify-content: flex-end; }
.export-card button { appearance: none; border: 0; background: var(--accent); color: #1a1a1a; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.export-card button#export-close { background: var(--panel-2); color: var(--ink); font-weight: 500; }

/* phones */
@media (max-width: 640px) {
  #topbar { padding: 8px; gap: 6px; }
  .modes button, #btn-edit, #btn-shot, #btn-settings { min-height: 40px; }
  #btn-edit .lbl { display: none; }
  #btn-edit, #btn-shot, #btn-settings { padding: 8px 11px; font-size: 16px; }
  .brand { order: 3; flex: 1 1 100%; }
  /* edit toolbar: one thumb-scrollable row at the very bottom */
  #edit-toolbar { bottom: 0; left: 0; right: 0; transform: none; max-width: none; border-radius: var(--radius) var(--radius) 0 0; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  #edit-toolbar button { min-height: 40px; padding: 8px 12px; flex: none; }
  #edit-toolbar .count { flex: none; white-space: nowrap; }
  /* inspector and palette: bottom sheets above the toolbar, scrollable */
  #inspector { left: 0; right: 0; width: auto; max-width: none; bottom: 64px; border-radius: var(--radius) var(--radius) 0 0; max-height: 48vh; overflow: auto; padding: 12px 14px 12px; }
  #inspector button { min-height: 38px; }
  #inspector .row { gap: 8px; }
  #palette { top: auto; left: 0; right: 0; bottom: 64px; width: auto; max-height: 52vh; border-radius: var(--radius) var(--radius) 0 0; transform: translateY(calc(100% + 90px)); }
  body.palette-open #palette { transform: none; }
  .pal-items button { min-height: 44px; }
  .swatch { width: 44px; height: 44px; }
  input[type=range] { height: 28px; }
  body.editing .toast { bottom: 72px; }
  #joystick { left: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); }
  #topbar { padding: 8px; gap: 8px; flex-wrap: wrap; }
  .brand { flex: 1 1 100%; order: 3; padding: 6px 10px; }
  .brand span { display: none; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 70vh; transform: translateY(calc(100% + 20px)); }
  body.panel-open #panel { transform: none; }
  .room-label b { font-size: 11px; }
  .room-label small { font-size: 9.5px; }
}
