:root {
  --bg: #f4efe7; --card: #fbf8f3; --ink: #2e2620; --muted: #7a6d60; --line: #e2d9cc;
  --accent: #9a5236; --ok: #2f8a4c; --mid: #c98a1c; --bad: #c8322c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, "SF Arabic", "Geeza Pro", "Segoe UI", Tahoma, sans-serif; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 6px 10px; }
button:hover { border-color: var(--accent); }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; color: var(--ink); }
header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--card); -webkit-app-region: drag; }
header button, header nav { -webkit-app-region: no-drag; }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 400; font-size: 13px; }
nav { display: flex; gap: 4px; }
nav button { border: none; background: none; padding: 6px 12px; border-radius: 20px; }
nav button.on { background: var(--ink); color: #fff; }
.tools { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
button.warn { color: var(--bad); border-color: #efc9c5; }
#sync { font-size: 12px; color: var(--ok); }
#sync.saving { color: var(--mid); } #sync.err { color: var(--bad); }
main { display: flex; height: calc(100% - 58px); }
#stage { flex: 1; position: relative; min-width: 0; }
#plan { width: 100%; height: 100%; touch-action: none; user-select: none; display: block; }
#panel { width: 360px; overflow-y: auto; padding: 16px; border-inline-start: 1px solid var(--line); background: var(--card); }
.zoom { position: absolute; bottom: 14px; left: 14px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 36px; height: 36px; padding: 0; font-size: 18px; }
#legend { position: absolute; top: 10px; left: 14px; font-size: 12px; background: #fffc; padding: 4px 8px; border-radius: 6px; display: flex; gap: 6px; align-items: center; }
#legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
#legend .g { background: var(--ok); } #legend .a { background: var(--mid); } #legend .r { background: var(--bad); }
#floors { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 4px; background: #fffd; padding: 4px; border-radius: 22px; box-shadow: 0 1px 6px #0002; }
#floors button { border: none; background: none; padding: 5px 15px; border-radius: 18px; font-size: 13px; color: var(--muted); }
#floors button.on { background: var(--ink); color: #fff; }

/* plan */
.wall { fill: #2e2620; }
.door { fill: #fff; opacity: .85; }
.glass { fill: #bcd6e0; }
.fixed { fill: #ddd3c5; stroke: #b9ad9c; stroke-width: 1; }
.fixed.col { fill: #2e2620; }
.room polygon { cursor: pointer; }
.room.on polygon:first-child { stroke: var(--accent); stroke-width: 4; stroke-dasharray: 10 6; }
.wallpaint { pointer-events: none; opacity: .9; }
.roomlabel { font-size: 20px; fill: #7a6d60; text-anchor: middle; dominant-baseline: middle; pointer-events: none; opacity: .75; }
#stage3d { position: absolute; inset: 0; display: none; }
body[data-tab="3d"] #plan, body[data-tab="3d"] .zoom, body[data-tab="3d"] #legend { display: none; }
body[data-tab="3d"] #stage3d { display: block; }
#stage3d canvas { display: block; touch-action: none; cursor: grab; }
#stage3d canvas:active { cursor: grabbing; }
.v3dbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; background: #fffd; padding: 6px 10px; border-radius: 24px; box-shadow: 0 1px 6px #0002; font-size: 12px; color: var(--muted); max-width: 92%; }
.v3dbar button { width: 32px; height: 32px; padding: 0; border-radius: 50%; }
.v3dbar span { margin-inline-start: 6px; }
#tour { display: none; }
body[data-tab="tour"] #stage, body[data-tab="tour"] #panel { display: none; }
body[data-tab="tour"] #tour { display: block; flex: 1; overflow-y: auto; }
.tourwrap { max-width: 1100px; margin: 0 auto; padding: 20px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.gallery figure { margin: 0; cursor: zoom-in; border-radius: 10px; overflow: hidden; background: #ddd; box-shadow: 0 1px 4px #0001; }
.gallery img { width: 100%; height: 190px; object-fit: cover; display: block; }
.gallery figcaption { padding: 8px 10px; font-size: 14px; }
.panos { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.panobtn { padding: 0; border-radius: 10px; overflow: hidden; position: relative; display: block; }
.panobtn img { width: 100%; height: 150px; object-fit: cover; display: block; }
.panobtn span { position: absolute; inset-inline: 0; bottom: 0; background: #000a; color: #fff; font-size: 13px; padding: 6px; }
#tour video { width: 100%; max-width: 720px; border-radius: 10px; margin-top: 8px; }
.lightbox { position: relative; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 8px; display: block; }
.lightbox #lbx { position: absolute; top: 8px; inset-inline-end: 8px; border-radius: 50%; width: 36px; height: 36px; }
.panoview { width: min(960px, 94vw); }
.panostage { height: min(60vh, 520px); overflow: hidden; border-radius: 10px; background: #111; cursor: grab; touch-action: none; }
.panostage img { height: 100%; max-width: none; user-select: none; }
.panobar { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--muted); }
.item { cursor: grab; }
.lightglyph circle { fill: #f6d79a; stroke: #c99a3a; stroke-width: 2; }
.lightglyph line { stroke: #c99a3a; stroke-width: 2; }
.lightglyph .lightname { font-size: 13px; fill: #9a7a2a; text-anchor: middle; paint-order: stroke; stroke: #fffc; stroke-width: 3px; }
.item .body { stroke: #2e262066; stroke-width: 1.5; }
.item .back { filter: brightness(.82); stroke: none; }
.item.layer .body { opacity: .65; stroke-dasharray: 6 4; }
.item .rugframe { stroke: #8c6a43; stroke-width: 3; opacity: .6; }
.item .screen { stroke: #111; stroke-width: 5; }
.item.sel .body { stroke: var(--accent); stroke-width: 4; }
.item.bad .body { stroke: var(--bad); stroke-width: 3; }
.ilabel { font-size: 13px; text-anchor: middle; dominant-baseline: middle; fill: #2e2620; pointer-events: none; paint-order: stroke; stroke: #fff9; stroke-width: 3px; }
.gap line { stroke-width: 3; } .gap circle { stroke: none; }
.gap text { font-size: 14px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.gapbg { fill: #fff; }
.gap.ok line, .gap.ok circle { stroke: var(--ok); fill: var(--ok); } .gap.ok text { fill: var(--ok); }
.gap.mid line, .gap.mid circle { stroke: var(--mid); fill: var(--mid); } .gap.mid text { fill: var(--mid); }
.gap.bad line, .gap.bad circle { stroke: var(--bad); fill: var(--bad); } .gap.bad text { fill: var(--bad); }
.overlap { fill: var(--bad); opacity: .45; pointer-events: none; }

/* panel */
h2 { margin: 4px 0 2px; font-size: 20px; } h2 input { font-size: 18px; font-weight: 700; width: 100%; }
h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
.tag { color: var(--muted); font-size: 12px; }
.okmsg { color: var(--ok); }
.back-btn { border: none; background: none; padding: 0; color: var(--muted); }
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.row label { flex: 1; font-size: 13px; color: var(--muted); }
.row input { width: 100%; margin-top: 2px; }
.danger { color: var(--bad); }
.primary { background: var(--ink); color: #fff; border-color: var(--ink); width: 100%; margin-top: 6px; }
.catalog { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.catalog button { display: flex; align-items: center; gap: 6px; text-align: start; font-size: 13px; }
.catalog span, .roomlist span { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid #0002; flex: none; }
.catalog small { margin-inline-start: auto; color: var(--muted); font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 20px; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatches button.on { box-shadow: 0 0 0 2px var(--accent); }
.swatches .custom { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.swatches input[type=color] { width: 30px; height: 30px; padding: 0; border: none; background: none; }
.warns, .gaps, .rules, .links, .roomlist { padding: 0; margin: 0; list-style: none; }
.warns li { padding: 6px 8px; border-radius: 6px; background: #fbe9e7; color: var(--bad); margin-bottom: 4px; cursor: pointer; font-size: 13px; }
.gaps li { font-size: 13px; padding: 2px 0; } .gaps .ok { color: var(--ok); } .gaps .mid { color: var(--mid); } .gaps .bad { color: var(--bad); }
.rules li { font-size: 13px; padding: 2px 0; }
.links li { font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.roomlist li { display: flex; align-items: center; gap: 6px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.roomlist small { color: var(--muted); margin-inline-start: auto; font-size: 12px; }
.opts { display: grid; gap: 6px; }
.opts button { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; text-align: start; }
.opts button span { grid-row: span 2; width: 28px; height: 28px; border-radius: 6px; border: 1px solid #0002; }
.opts button small { color: var(--muted); font-size: 12px; }
.opts button.on { border-color: var(--accent); background: #f6ebe4; }
.calc { font-size: 14px; background: #f1ebe2; padding: 8px; border-radius: 8px; }
textarea { width: 100%; margin-top: 8px; min-height: 60px; }
.wait { color: var(--mid); } .err { color: var(--bad); }
.ans { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 8px; font-size: 14px; }
.sug { border-top: 1px solid var(--line); padding: 8px 0; }
.sug .sw { width: 16px; height: 16px; border-radius: 4px; display: inline-block; vertical-align: middle; }
.sug button { font-size: 12px; padding: 3px 8px; margin-top: 4px; margin-inline-end: 4px; }
details { margin-top: 18px; font-size: 13px; }
#modal { position: fixed; inset: 0; background: #0006; display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal[hidden] { display: none; }
#modal .box { background: var(--card); border-radius: 14px; padding: 20px; width: min(480px, 92vw); max-height: 90vh; overflow: auto; }
.check { display: block; margin: 10px 0; font-size: 14px; }

/* phone */
@media (max-width: 760px) {
  header { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand small { display: none; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  .tools button.warn { font-size: 12px; padding: 4px 8px; }
  main { flex-direction: column; height: calc(100% - 96px); }
  #stage { flex: 1 1 55%; min-height: 0; overflow: hidden; }
  #panel { min-height: 0; }
  #panel { width: auto; flex: 1 1 45%; border-inline-start: none; border-top: 1px solid var(--line); padding: 12px 16px; }
  #legend { font-size: 11px; }
}
.fixed.open { opacity: .45; }
