/* The editor: a drafting desk. The plan and the room are the work; every control sits at
   the edges and stays quiet until something is selected. */
body.ed { overflow: hidden; height: 100dvh; background: var(--sunk); }
.ed-shell { display: grid; height: 100dvh; grid-template-columns: 340px minmax(0, 1fr) 300px;
  grid-template-rows: 58px minmax(0, 1fr); grid-template-areas: "bar bar bar" "side stage insp"; }

/* ───────────── top bar */
.ed-bar { grid-area: bar; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--card); border-bottom: 1px solid var(--line); min-width: 0; }
.ed-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 300px; }
.ed-title input { border: 1px solid transparent; background: transparent; font: 700 18px/1 var(--display); min-height: 38px; padding: 4px 8px; min-width: 0; width: 100%; border-radius: var(--r-sm); }
.ed-title input:hover { border-color: var(--line); }
.ed-title input:focus { border-color: var(--firuze); box-shadow: none; background: var(--card); }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state.err { color: var(--brick); font-weight: 700; }
.ed-group { display: flex; gap: 2px; align-items: center; }
.ed-group.end { margin-inline-start: auto; gap: 6px; }
.seg { display: inline-flex; background: var(--sunk); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; min-height: 34px; padding: 0 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.seg button[aria-selected=true], .seg button[aria-pressed=true] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.small button { min-height: 30px; padding: 0 11px; font-size: 13px; }

/* ───────────── side library */
.ed-side { grid-area: side; display: flex; flex-direction: column; background: var(--card); border-inline-end: 1px solid var(--line); min-height: 0; }
.side-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); flex: none; }
.side-tabs button { border: 0; background: none; padding: 10px 4px 9px; display: grid; justify-items: center; gap: 3px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.side-tabs button svg { width: 21px; height: 21px; }
.side-tabs button[aria-selected=true] { color: var(--firuze-deep); border-bottom-color: var(--firuze); }
.side-body { overflow: auto; padding: 14px; flex: 1; min-height: 0; overscroll-behavior: contain; }
.side-h { font: 700 13px/1.4 var(--ui); color: var(--muted); margin: 16px 0 8px; }
.side-h:first-child { margin-top: 0; }
.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tool { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); cursor: pointer; text-align: start; font-weight: 600; font-size: 14px; min-height: 48px; }
.tool svg { width: 22px; height: 22px; color: var(--firuze-deep); flex: none; }
.tool:hover { border-color: var(--line-2); background: var(--paper); }
.tool[aria-pressed=true] { border-color: var(--firuze); background: var(--firuze-wash); }
.tool small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; line-height: 1.4; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.search { position: relative; margin-bottom: 10px; }
.search svg { position: absolute; inset-inline-start: 12px; top: 12px; width: 19px; color: var(--muted); }
.search input { padding-inline-start: 38px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.lib-card { border: 1px solid var(--line); border-radius: var(--r); background: var(--card); padding: 0; overflow: hidden; cursor: pointer; text-align: start; display: flex; flex-direction: column; }
.lib-card:hover { border-color: var(--firuze); box-shadow: var(--shadow); }
.lib-card .pic { display: grid; width: 100%; aspect-ratio: 1; background: linear-gradient(#f7f7f4, #ecebe6); display: grid; place-items: center; }
.lib-card .pic img { width: 82%; height: 82%; object-fit: contain; }
.lib-card .pic svg { width: 44%; height: 44%; color: var(--ink-2); stroke-width: 1.2; }
.lib-card .cap { display: block; padding: 7px 9px 9px; font-size: 12.5px; line-height: 1.45; font-weight: 600; }
.lib-card .cap span { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.lib-card .badge { font-size: 10.5px; font-weight: 700; color: var(--saffron); }
.swatches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.sw { border: 0; padding: 0; background: none; cursor: pointer; text-align: center; font-size: 11px; line-height: 1.35; color: var(--ink-2); }
.sw i { display: block; aspect-ratio: 1; border-radius: 10px; background-size: cover; background-position: center; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); margin-bottom: 4px; }
.sw[aria-pressed=true] i { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--firuze); }
.sw span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.target { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.note { font-size: 13px; color: var(--muted); background: var(--paper); border-radius: var(--r); padding: 10px 12px; line-height: 1.7; }
.note.warn { background: var(--saffron-wash); color: #7a5205; }
.lock { font-size: 11px; font-weight: 700; color: var(--lapis); background: var(--lapis-wash); border-radius: 999px; padding: 1px 8px; }

/* ───────────── stage */
.ed-stage { grid-area: stage; position: relative; display: grid; grid-template-columns: 1fr 1fr; min-width: 0; min-height: 0; background: var(--sunk); gap: 1px; }
.ed-shell[data-view="2d"] .ed-stage, .ed-shell[data-view="3d"] .ed-stage { grid-template-columns: 1fr; }
.ed-shell[data-view="2d"] .pane-3d { position: absolute; inset: 0; visibility: hidden; pointer-events: none; }
.ed-shell[data-view="3d"] .pane-2d { display: none; }
.pane { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.plan-host, .scene-host { position: absolute; inset: 0; }
.scene-host canvas { width: 100% !important; height: 100% !important; display: block; }
.pane-tools { position: absolute; top: 12px; inset-inline: 12px; display: flex; gap: 8px; flex-wrap: wrap; z-index: 2; pointer-events: none; }
.pane-tools > * { pointer-events: auto; }
.pane-tools .seg { background: rgba(255,255,255,.92); box-shadow: var(--shadow); backdrop-filter: blur(6px); }
.pane-tools .seg button[aria-pressed=true] { background: var(--ink); color: #fff; }
.pane-hint { position: absolute; bottom: 12px; inset-inline-start: 12px; margin: 0; font-size: 12.5px; color: var(--ink-2); background: rgba(255,255,255,.9); padding: 5px 12px; border-radius: 999px; pointer-events: none; max-width: calc(100% - 24px); }
.pane-hint:empty { display: none; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--paper); color: var(--ink-2); font-weight: 600; z-index: 3; transition: opacity .3s; }
.loading span { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--firuze); animation: spin 1s linear infinite; }
.loading.done { opacity: 0; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.joystick { position: absolute; bottom: 24px; inset-inline-end: 24px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.55); border: 1px solid rgba(255,255,255,.9); backdrop-filter: blur(6px); z-index: 2; touch-action: none; }
.joystick span { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px; border-radius: 50%; background: var(--ink); opacity: .8; }

/* ───────────── inspector */
.ed-insp { grid-area: insp; background: var(--card); border-inline-start: 1px solid var(--line); overflow: auto; padding: 16px; min-height: 0; overscroll-behavior: contain; }
.insp-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.insp-head h3 { margin: 0; font-size: 18px; flex: 1; }
.insp-kind { font-size: 12px; color: var(--muted); font-weight: 600; }
.insp-sec { border-top: 1px solid var(--line); padding: 12px 0; display: grid; gap: 10px; }
.insp-sec:first-of-type { border-top: 0; padding-top: 0; }
.insp-sec h4 { margin: 0; font-size: 13px; color: var(--muted); }
.dims { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.dims label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.dims input { min-height: 38px; padding: 6px 8px; font-size: 15px; text-align: center; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.fact { background: var(--paper); border-radius: var(--r); padding: 10px 12px; }
.fact b { display: block; font: 700 22px/1.2 var(--display); }
.fact span { font-size: 12px; color: var(--muted); }
.fact.measure b { color: var(--saffron); }
.finish { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; background: var(--card); text-align: start; width: 100%; }
.finish:hover { border-color: var(--firuze); }
.finish i { width: 38px; height: 38px; border-radius: 8px; background-size: cover; background-position: center; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.finish small { display: block; font-size: 11.5px; color: var(--muted); }
.finish b { font-size: 13px; font-weight: 600; }
.tints { display: flex; flex-wrap: wrap; gap: 7px; }
.tint { width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.tint[aria-pressed=true] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--firuze); }
.tint.custom { background: conic-gradient(#e44, #ec4, #4c6, #4ae, #a4e, #e44); position: relative; overflow: hidden; }
.tint.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.walls-list { display: grid; gap: 6px; }
.walls-list button { display: flex; gap: 8px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 10px; background: var(--card); cursor: pointer; font-size: 13px; }
.walls-list button[aria-pressed=true] { border-color: var(--firuze); background: var(--firuze-wash); }
.walls-list i { width: 18px; height: 18px; border-radius: 4px; background-size: cover; }
input[type=range] { width: 100%; accent-color: var(--firuze); }

/* ───────────── dock (phones) */
.ed-dock { display: none; }

/* ───────────── dialogs owned by the editor */
.shot { width: 100%; border-radius: var(--r); background: var(--sunk); aspect-ratio: 16/10; object-fit: cover; }
.mv-host { height: min(60vh, 460px); border-radius: var(--r); overflow: hidden; background: var(--paper); }
.mv-host model-viewer { width: 100%; height: 100%; }
.mv-ar-btn { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: var(--firuze); color: #fff; border: 0; border-radius: 999px; padding: 12px 22px; font: 600 15px var(--ui); }
table.bill { width: 100%; border-collapse: collapse; font-size: 14px; }
table.bill th { text-align: start; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.bill td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.bill td.n { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.bill tr.group td { background: var(--paper); font-weight: 700; color: var(--ink-2); font-size: 13px; }
table.bill input { min-height: 34px; padding: 4px 8px; font-size: 14px; width: 120px; }
table.bill tfoot td { font-weight: 800; font-size: 16px; border: 0; padding-top: 14px; }
.share-link { display: flex; gap: 8px; }
.share-link input { direction: ltr; text-align: left; font-size: 14px; }
.comments { display: grid; gap: 10px; max-height: 260px; overflow: auto; }
.cmt { background: var(--paper); border-radius: var(--r); padding: 9px 12px; font-size: 14px; }
.cmt.own { background: var(--firuze-wash); }
.cmt b { font-size: 12.5px; }
.cmt time { font-size: 11.5px; color: var(--muted); margin-inline-start: 6px; }
.cmt p { margin: 3px 0 0; white-space: pre-wrap; }

@media (max-width: 1240px) { .ed-shell { grid-template-columns: 300px minmax(0, 1fr) 270px; } }

/* Phones and small tablets: the stage is the screen; library and inspector are sheets. */
@media (max-width: 999px) {
  .ed-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr) 62px; grid-template-areas: "bar" "stage" "dock"; }
  .ed-shell[data-view="split"] .ed-stage { grid-template-columns: 1fr; }
  .ed-shell[data-view="split"] .pane-2d { display: none; }
  .ed-bar { gap: 4px; padding: 0 6px; }
  .ed-title { flex: 1 1 auto; }
  .ed-title input { font-size: 16px; }
  .save-state, .hide-sm, .ed-bar .btn.sm .lbl, #undo, #redo { display: none; }
  .ed-group.end { margin-inline-start: 0; gap: 2px; }
  .ed-bar .btn.sm { padding: 0 9px; }
  .ed-bar .seg { display: none; }
  .ed-side, .ed-insp { position: fixed; inset-inline: 0; bottom: 62px; height: min(62dvh, 520px); z-index: 20; border: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); transform: translateY(110%); transition: transform .22s ease; }
  .ed-side.open, .ed-insp.open { transform: none; }
  .ed-dock { grid-area: dock; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-top: 1px solid var(--line); z-index: 25; }
  .ed-dock button { border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 2px; font: 600 12px var(--ui); color: var(--ink-2); cursor: pointer; }
  .ed-dock button svg { width: 22px; height: 22px; }
  .ed-dock button[aria-expanded=true] { color: var(--firuze-deep); }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .swatches { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .pane-tools { top: 8px; inset-inline: 8px; }
}
@media (max-width: 520px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .swatches { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media print { body.ed > :not(dialog) { display: none !important; } dialog.modal { position: static; box-shadow: none; width: 100%; max-height: none; } .modal-foot, [data-close] { display: none !important; } }
.mv-host { position: relative; }
