:root {
  --bg: #f4f1ea; --bg3d: #e6ebee; --panel: #fffdf8; --ink: #2a2620; --muted: #766e60; --line: #d9d2c2;
  --accent: #b9622b; --accent-ink: #fff; --wall: #2b2823; --wall-parapet: #7a7366; --slab: #fbf8f0; --room: rgba(185,98,43,0.06);
  --glass: #74b7e4; --axis: #b9b2a3; --dim: #8a5a12; --stair: #6a6254; --shadow: 0 1px 2px rgba(40,30,10,.12), 0 6px 20px rgba(40,30,10,.08);
  --radius: 10px;
}
:root[data-theme="dark"] {
  --bg: #1b1a17; --bg3d: #23272b; --panel: #262420; --ink: #efe9dc; --muted: #a39a89; --line: #3a362f;
  --accent: #e08a4f; --accent-ink: #1b1a17; --wall: #e8e1d2; --wall-parapet: #a59d8c; --slab: #2d2a25; --room: rgba(224,138,79,0.09);
  --glass: #5da3d1; --axis: #4b463d; --dim: #e0b25a; --stair: #b3a995;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17; --bg3d: #23272b; --panel: #262420; --ink: #efe9dc; --muted: #a39a89; --line: #3a362f;
    --accent: #e08a4f; --accent-ink: #1b1a17; --wall: #e8e1d2; --wall-parapet: #a59d8c; --slab: #2d2a25; --room: rgba(224,138,79,0.09);
    --glass: #5da3d1; --axis: #4b463d; --dim: #e0b25a; --stair: #b3a995;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; overscroll-behavior: none; }
.bar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .1px; }
h1 small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.spacer { flex: 1; }
.group { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg, .chip { font: inherit; color: var(--ink); background: transparent; border: 0; padding: 7px 13px; cursor: pointer; }
.group .seg + .seg { border-left: 1px solid var(--line); }
.seg.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.edit { border: 1px solid var(--line); border-radius: var(--radius); }
.edit.on { background: var(--accent); color: var(--accent-ink); }
.toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.status { font-size: 12px; color: var(--muted); }
#stage { position: relative; flex: 1; min-height: 0; }
.pane { position: absolute; inset: 0; }
.pane[hidden] { display: none; }
svg.plan2d { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; background: var(--bg); }
svg.plan2d:active { cursor: grabbing; }
canvas.view3d { width: 100%; height: 100%; display: block; touch-action: none; }
.floating { position: absolute; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.floating[hidden] { display: none; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); font-size: 13px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--bg); text-align: center; padding: 20px; }
.loading[hidden] { display: none; }
#error { inset: auto 12px 12px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); padding: 10px 14px; box-shadow: var(--shadow); }
/* plan drawing */
.axis { stroke: var(--axis); stroke-width: .02; stroke-dasharray: .35 .12 .05 .12; }
.bubble { fill: var(--panel); stroke: var(--axis); stroke-width: .03; }
.bubble-t { fill: var(--muted); font-weight: 600; }
.slab { fill: var(--slab); }
.porch { fill: none; stroke: var(--axis); stroke-width: .03; stroke-dasharray: .2 .15; }
.balcony { fill: var(--slab); stroke: var(--wall-parapet); stroke-width: .05; }
.room { fill: var(--room); }
.wall { fill: var(--wall); }
.wall.parapet { fill: var(--wall-parapet); }
.window-fill { fill: var(--panel); }
.window-line { stroke: var(--glass); stroke-width: .035; }
.door-gap { fill: var(--slab); }
.door-leaf { stroke: var(--wall); stroke-width: .045; }
.door-arc { fill: none; stroke: var(--wall-parapet); stroke-width: .02; }
.stair { stroke: var(--stair); stroke-width: .03; fill: none; }
.stair.ghost { stroke-dasharray: .12 .1; opacity: .7; }
.stair.outline { stroke-width: .05; }
.stair-t { fill: var(--stair); font-weight: 700; }
.room-name { fill: var(--ink); font-weight: 600; letter-spacing: .02em; }
.room-dims { fill: var(--accent); font-weight: 600; }
.dim-line { stroke: var(--dim); }
.dim-t { fill: var(--dim); font-weight: 600; }
.dim-t.strong { font-weight: 800; }
text { font-family: system-ui, sans-serif; pointer-events: none; user-select: none; }
@media (max-width: 640px) {
  .bar { padding: 8px 12px; gap: 8px; }
  h1 small { display: none; }
  .seg { padding: 7px 11px; }
}

/* ---------- furniture ---------- */
.chip.sm { padding: 5px 11px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.chip.danger { color: #b3261e; border-color: #e3b5b1; }
:root[data-theme="dark"] .chip.danger { color: #ff9b94; border-color: #6b3a37; }
.chip:disabled { opacity: .45; cursor: default; }
.status.saving { color: var(--accent); } .status.offline { color: #b3261e; }
.f-body { stroke: var(--wall); stroke-width: .02; }
.f-front { stroke: var(--wall); stroke-width: .03; opacity: .55; }
.f-label { fill: var(--ink); font-weight: 600; paint-order: stroke; stroke: var(--slab); stroke-width: .035; opacity: .9; }
.f-size { fill: var(--accent); font-weight: 700; paint-order: stroke; stroke: var(--slab); stroke-width: .03; }
.f-item { cursor: pointer; }
body.editing .f-item { cursor: move; }
.f-item.sel .f-body { stroke: var(--accent); stroke-width: .035; }
.f-item.warn .f-body { stroke: #d93025; stroke-width: .04; }
.f-item.warn { filter: drop-shadow(0 0 .05px #d93025); }
.f-outline { fill: none; stroke: var(--accent); stroke-width: .02; stroke-dasharray: .08 .06; pointer-events: none; }
.f-handle { fill: var(--panel); stroke: var(--accent); stroke-width: .03; }
.f-handle.rot { fill: var(--accent); }
#furniture-ui { position: absolute; z-index: 5; right: 12px; top: 12px; bottom: auto; max-height: calc(100% - 24px); width: 300px; max-width: calc(100% - 24px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
#furniture-ui[hidden] { display: none; }
.fp-catalog { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1 1 auto; }
.fp-catalog input[type=search] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
.fp-tabs { display: flex; flex-wrap: wrap; gap: 5px; }
.fp-list { display: flex; flex-direction: column; gap: 4px; overflow: auto; min-height: 120px; }
.fp-item { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; text-align: left; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: grab; }
.fp-item:hover { border-color: var(--accent); }
.fp-dims { color: var(--muted); font-size: 12px; white-space: nowrap; }
.fp-hint { color: var(--muted); font-size: 13px; margin: 0; }
.fp-inspector { padding-top: 2px; }
.fp-catalog + .fp-inspector, .fp-hint + .fp-inspector { border-top: 1px solid var(--line); padding-top: 10px; }
body.editing #furniture-ui { bottom: 12px; }
.fp-inspector h3 { margin: 0 0 2px; font-size: 15px; }
.fp-size { margin: 0 0 8px; color: var(--accent); font-weight: 600; font-size: 14px; }
.fp-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fp-field { display: grid; grid-template-columns: 1fr; gap: 3px; font-size: 12px; color: var(--muted); position: relative; }
.fp-field input { width: 100%; padding: 6px 28px 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; }
.fp-field input[type=color] { padding: 2px; height: 34px; }
.fp-field em { position: absolute; right: 8px; bottom: 7px; font-style: normal; color: var(--muted); font-size: 12px; pointer-events: none; }
.fp-warn { color: #b3261e; font-size: 13px; margin: 8px 0 0; }
.fp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
dialog#login-dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 18px 20px; max-width: min(380px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog#login-dialog::backdrop { background: rgba(0,0,0,.4); }
#login-dialog h2 { margin: 0 0 6px; font-size: 18px; }
#login-dialog p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
#login-dialog label { display: grid; gap: 4px; font-size: 13px; }
#login-dialog input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
#login-dialog .err { color: #b3261e; min-height: 1.3em; margin: 8px 0 0; }
#login-dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
@media (max-width: 640px) {
  #furniture-ui, body.editing #furniture-ui { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-width: none; max-height: 48%; }
  .fp-fields { grid-template-columns: 1fr 1fr; }
  .floating { bottom: calc(50% + 14px); }
}

/* panel sections never shrink into each other; the list scrolls on its own */
#furniture-ui > * { flex: 0 0 auto; }
.fp-catalog { flex: 0 0 auto; min-height: 0; }
.fp-list { max-height: clamp(150px, 34vh, 400px); min-height: 0; }
@media (max-width: 640px) {
  #furniture-ui, body.editing #furniture-ui { max-height: 52%; }
  .fp-list { max-height: 22vh; }
  .fp-fields { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .fp-field input { padding: 5px 22px 5px 6px; font-size: 13px; }
}
