/* macOS-style window: unified toolbar, canvas, inspector on the right (stacks under the canvas on phones). */
:root {
  --window: #ececec;
  --toolbar: rgba(246, 246, 246, 0.82);
  --inspector: #f3f3f3;
  --canvas: #fbfbfb;
  --label: rgba(0, 0, 0, 0.85);
  --secondary: rgba(0, 0, 0, 0.56);
  --separator: rgba(0, 0, 0, 0.1);
  --group: rgba(0, 0, 0, 0.035);
  --group-border: rgba(0, 0, 0, 0.06);
  --control: #ffffff;
  --control-border: rgba(0, 0, 0, 0.16);
  --control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.14);
  --hover: rgba(0, 0, 0, 0.06);
  --track: rgba(0, 0, 0, 0.07);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.14);
  --on-accent: #ffffff;
  --red: #d70015;
  --orange: #b25000;
  --green: #248a3d;
  --wall: #3a3a3c;
  --plan-note: rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --window: #1e1e1e;
    --toolbar: rgba(44, 44, 46, 0.82);
    --inspector: #272729;
    --canvas: #161617;
    --label: rgba(255, 255, 255, 0.88);
    --secondary: rgba(255, 255, 255, 0.6);
    --separator: rgba(255, 255, 255, 0.12);
    --group: rgba(255, 255, 255, 0.05);
    --group-border: rgba(255, 255, 255, 0.07);
    --control: rgba(255, 255, 255, 0.11);
    --control-border: rgba(255, 255, 255, 0.1);
    --control-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.4);
    --hover: rgba(255, 255, 255, 0.09);
    --track: rgba(255, 255, 255, 0.09);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.24);
    --red: #ff453a;
    --orange: #ff9f0a;
    --green: #30d158;
    --wall: #98989d;
    --plan-note: rgba(255, 255, 255, 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--window);
  color: var(--label);
  font: 13px/1.35 var(--font);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }

/* ---- toolbar ---- */
.toolbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px max(14px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  background: var(--toolbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.title { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.title strong { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 11px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status[data-state="offline"] { color: var(--red); }
.tools { display: flex; justify-content: flex-end; gap: 2px; }
.tb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--secondary); cursor: pointer;
}
.tb:hover:not(:disabled) { background: var(--hover); color: var(--label); }
.tb:disabled { opacity: 0.35; cursor: default; }
.tb svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--track); }
.seg button {
  border: 0; background: none; min-width: 62px; height: 24px; padding: 0 12px; border-radius: 6px; cursor: pointer;
  font-weight: 500; color: var(--label);
}
.seg button[aria-pressed="true"] { background: var(--control); box-shadow: 0 0.5px 2px rgba(0, 0, 0, 0.22); }

/* ---- controls ---- */
.btn {
  border: 0.5px solid var(--control-border);
  background: var(--control);
  box-shadow: var(--control-shadow);
  border-radius: 6px;
  padding: 0 10px;
  height: 24px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active:not(:disabled) { filter: brightness(0.93); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; height: 30px; }
.btn.danger { color: var(--red); }
input[type="text"], input[type="number"], input[type="password"], select {
  background: var(--control);
  border: 0.5px solid var(--control-border);
  box-shadow: var(--control-shadow);
  border-radius: 6px;
  padding: 0 7px;
  height: 24px;
  width: 100%;
  min-width: 0;
}
input:focus-visible, select:focus-visible { outline-offset: 0; }
input:disabled { opacity: 0.5; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 24px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='18'%3E%3Crect width='16' height='18' rx='4' fill='%230071e3'/%3E%3Cpath d='M5 7.2 8 4.4l3 2.8M5 10.8l3 2.8 3-2.8' fill='none' stroke='%23fff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 3px center;
}
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--secondary); min-width: 0; }
label.f > span { white-space: nowrap; }
label.f input { color: var(--label); }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
label.check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row > .fill { flex: 1 1 110px; min-width: 0; }
.row.spread { justify-content: space-between; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---- main split ---- */
.app { flex: 1 1 auto; min-height: 0; display: flex; }
.stage { position: relative; flex: 1 1 auto; min-width: 0; background: var(--canvas); overflow: hidden; }
#plan, #view3d { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; display: block; }
#plan { cursor: grab; }
#plan.panning, #view3d.grabbing { cursor: grabbing; }
#view3d { cursor: grab; outline: none; }
.hud {
  position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: 12px; display: flex; padding: 3px; gap: 1px; border-radius: 10px;
  background: var(--toolbar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--separator); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.hud button { border: 0; background: none; min-width: 32px; height: 28px; padding: 0 9px; border-radius: 7px; cursor: pointer; font-weight: 500; }
.hud button:hover { background: var(--hover); }
.toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--toolbar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid var(--separator); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  padding: 7px 14px; border-radius: 999px; max-width: calc(100% - 24px); pointer-events: none; text-align: center;
}

.inspector {
  flex: 0 0 304px;
  background: var(--inspector);
  border-left: 1px solid var(--separator);
  overflow-y: auto;
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.inspector section { min-width: 0; }
.inspector h2 { font-size: 11px; font-weight: 600; color: var(--secondary); margin: 0 0 6px 8px; }
.group { background: var(--group); border: 0.5px solid var(--group-border); border-radius: 8px; padding: 10px; }
.group .empty, .note { color: var(--secondary); font-size: 11.5px; margin: 0; }
.note { padding: 0 8px; }
.issues { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.issues li { display: flex; gap: 6px; align-items: baseline; }
.issues li::before { content: "●"; font-size: 8px; position: relative; top: -1px; }
.issues li.bad { color: var(--red); }
.issues li.warn { color: var(--orange); }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 0.5px solid rgba(128, 128, 128, 0.6); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--inspector), 0 0 0 4px var(--accent); }

/* catalogue: disclosure groups of rows */
.group.cat { padding: 2px 0; }
.cat details + details { border-top: 0.5px solid var(--separator); }
.cat summary { list-style: none; cursor: pointer; padding: 6px 10px; font-weight: 600; display: flex; align-items: center; gap: 6px; border-radius: 6px; }
.cat summary::-webkit-details-marker { display: none; }
.cat summary::before { content: ""; width: 0; height: 0; border-style: solid; border-width: 4px 0 4px 6px; border-color: transparent transparent transparent var(--secondary); }
.cat details[open] > summary::before { transform: rotate(90deg); }
.cat .rows { padding: 0 4px 6px; display: flex; flex-direction: column; }
.chip {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; width: 100%;
  border: 0; background: none; border-radius: 5px; padding: 4px 8px 4px 22px; cursor: pointer; text-align: left; min-height: 24px;
}
.chip:hover { background: var(--hover); }
.chip small, .pieces .dims { color: var(--secondary); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.group.pieces { list-style: none; margin: 0; padding: 4px; display: flex; flex-direction: column; }
.pieces button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  background: none; border: 0; border-radius: 5px; padding: 4px 8px; min-height: 24px; cursor: pointer; text-align: left;
}
.pieces button:hover { background: var(--hover); }
.pieces button[aria-current="true"] { background: var(--accent); color: var(--on-accent); }
.pieces button[aria-current="true"] .dims, .pieces button[aria-current="true"] .tag { color: var(--on-accent); }
.pieces .tag { font-size: 10.5px; color: var(--green); margin-left: 6px; font-weight: 600; }
.pieces .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; background: transparent; position: relative; top: -1px; }
.pieces .dot.bad { background: var(--red); }
.pieces .dot.warn { background: var(--orange); }
kbd { font: 10.5px ui-monospace, SFMono-Regular, Menlo, monospace; border: 0.5px solid var(--control-border); border-radius: 4px; padding: 0 3px; background: var(--control); }

/* ---- the drawing ---- */
.wall { fill: var(--wall); }
.sill { fill: #e6f0f7; stroke: var(--wall); stroke-width: 1; vector-effect: non-scaling-stroke; }
.glass { stroke: #5aa9e6; stroke-width: 2; vector-effect: non-scaling-stroke; }
.leaf { stroke: #3a3a3c; stroke-width: 3; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.swing { fill: rgba(40, 40, 44, 0.05); stroke: #3a3a3c; stroke-opacity: 0.45; stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.room-label { fill: var(--plan-note); font-family: var(--font); font-weight: 600; text-anchor: middle; pointer-events: none; }
.room-label .area { font-weight: 400; }
.dim line { stroke: var(--plan-note); stroke-width: 1; vector-effect: non-scaling-stroke; }
.dim text { fill: var(--plan-note); font-family: var(--font); text-anchor: middle; font-variant-numeric: tabular-nums; pointer-events: none; }

.item { cursor: grab; }
.item.locked, .item.fixed { cursor: default; }
.item .hit { fill: transparent; }
.item * { vector-effect: non-scaling-stroke; }
.f-body { fill: #f3e9d6; stroke: #5d4c35; stroke-width: 1.2; }
.f-detail { fill: none; stroke: #5d4c35; stroke-width: 1; stroke-opacity: 0.5; }
.f-soft { fill: #ffffff; stroke: #5d4c35; stroke-width: 1; stroke-opacity: 0.55; }
.f-dark { fill: #4b241d; stroke: #2a120e; stroke-width: 1.2; }
.f-white { fill: #ffffff; stroke: #5a6c74; stroke-width: 1.2; }
.f-key { stroke: #2a120e; stroke-width: 1; }
.f-metal { fill: none; stroke: #7b858c; stroke-width: 2; stroke-linecap: round; }
.f-water { fill: #e4f1f8; stroke: #5a6c74; stroke-width: 1; }
.f-rug { fill: #7d99ad; fill-opacity: 0.82; stroke: #4b5f6e; stroke-width: 1.2; }
.f-rug2 { fill: none; stroke: #e8dccb; stroke-width: 3; stroke-opacity: 0.9; }
.f-leaf { fill: #7fae7a; stroke: #3f6b3c; stroke-width: 1; }
.item.elev .f-body { fill-opacity: 0.55; stroke-dasharray: 5 3; }
.item.is-new .f-body { fill: #d9f2de; stroke: #248a3d; }
.item.is-new .f-detail { stroke: #248a3d; }
.item.warn .f-body, .item.warn .f-dark, .item.warn .f-white, .item.warn .f-rug { stroke: #e07b00; stroke-width: 2.4; }
.item.bad .f-body, .item.bad .f-dark, .item.bad .f-white, .item.bad .f-rug { stroke: #ff3b30; stroke-width: 2.4; }
.sel-box { fill: none; stroke: #0a84ff; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.rot-line { stroke: #0a84ff; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.rot-handle { fill: #ffffff; stroke: #0a84ff; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: crosshair; }
.lbl { font-family: var(--font); text-anchor: middle; pointer-events: none; fill: #2b2318; font-weight: 600; }
.lbl.sub { font-weight: 400; fill-opacity: 0.75; }
.lbl.on-dark { fill: #f6ece2; }
.lbl.on-new { fill: #0f5223; }
.gap line { stroke: #0a84ff; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.gap text { font-family: var(--font); font-weight: 600; text-anchor: middle; fill: #004a99; stroke: #ffffff; stroke-width: 3.5; paint-order: stroke; stroke-linejoin: round; font-variant-numeric: tabular-nums; pointer-events: none; }
.gap.tight line { stroke: #ff3b30; }
.gap.tight text { fill: #b3140a; }

/* ---- sign-in ---- */
body.login { align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: min(320px, 100%); background: var(--inspector); border: 0.5px solid var(--separator); border-radius: 12px; padding: 24px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18); text-align: center;
}
.login-card h1 { margin: 0; font-size: 15px; font-weight: 700; }
.login-card p { margin: 0; color: var(--secondary); font-size: 12px; }
.login-card label { font-size: 11px; color: var(--secondary); margin-top: 6px; text-align: left; }
.login-card input { height: 28px; }
.login-card .msg { color: var(--red); }

@media (max-width: 820px), (pointer: coarse) {
  body { font-size: 15px; }
  .btn, input[type="text"], input[type="number"], input[type="password"], select { height: 36px; }
  .seg button { height: 32px; min-width: 72px; }
  .tb { width: 44px; height: 40px; }
  .chip, .pieces button { min-height: 40px; }
  .hud button { min-width: 44px; height: 40px; }
  label.check input { width: 20px; height: 20px; }
  .swatch { width: 30px; height: 30px; }
  label.f, .inspector h2, .chip small, .pieces .dims, .status { font-size: 12px; }
}
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .stage { flex: 0 0 54vh; }
  .inspector { flex: 1 1 auto; border-left: 0; border-top: 1px solid var(--separator); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .toolbar { grid-template-columns: 1fr auto auto; }
}
@media (prefers-reduced-transparency: reduce) {
  .toolbar, .hud, .toast { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--inspector); }
}
@media (prefers-contrast: more) {
  :root { --separator: rgba(128, 128, 128, 0.6); --control-border: rgba(128, 128, 128, 0.8); --secondary: var(--label); }
}
