:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --panel-2: #f8f7f3;
  --ink: #1f2328;
  --ink-2: #5b616b;
  --ink-3: #8a9099;
  --line: #e2e0d9;
  --line-2: #cfccc3;
  --accent: #2f7d4a;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1e7;
  --bad: #c9362f;
  --bad-soft: #fbe6e4;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --ok: #2f7d4a;
  --ok-soft: #e3f1e7;
  --sel: #2f80ed;
  --plan-bg: #fbfaf7;
  --floor: rgba(255, 255, 255, .55);
  --wall: #2a2d31;
  --hatch: #c4c0b6;
  --dim: #2f5fb3;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1d2024; --panel-2: #23272c; --ink: #e8e6e1; --ink-2: #aeb3ba; --ink-3: #7d838b;
    --line: #2e3238; --line-2: #3b4047; --accent: #4fb070; --accent-ink: #0d1a12; --accent-soft: #1d3325;
    --bad: #ef6b63; --bad-soft: #3a1f1d; --warn: #e3a64a; --warn-soft: #3a2e1a; --ok: #4fb070; --ok-soft: #1d3325;
    --plan-bg: #1a1c1f; --floor: rgba(255,255,255,.04); --wall: #e0ddd6; --hatch: #4a4f57; --dim: #7aa7ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --panel: #1d2024; --panel-2: #23272c; --ink: #e8e6e1; --ink-2: #aeb3ba; --ink-3: #7d838b;
  --line: #2e3238; --line-2: #3b4047; --accent: #4fb070; --accent-ink: #0d1a12; --accent-soft: #1d3325;
  --bad: #ef6b63; --bad-soft: #3a1f1d; --warn: #e3a64a; --warn-soft: #3a2e1a; --ok: #4fb070; --ok-soft: #1d3325;
  --plan-bg: #1a1c1f; --floor: rgba(255,255,255,.04); --wall: #e0ddd6; --hatch: #4a4f57; --dim: #7aa7ff;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 18px 0 8px; font-weight: 600; }

/* ---- header ---- */
.top { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M11 25V6l10 4-10 4' fill='none' stroke='white' stroke-width='2.6' stroke-linejoin='round'/%3E%3Ccircle cx='21' cy='24' r='3' fill='white'/%3E%3C/svg%3E") center/100%; }
.layout-name { flex: 1; min-width: 60px; max-width: 360px; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 8px; font-weight: 550; }
.layout-name:hover { border-color: var(--line); }
.layout-name:focus { outline: none; border-color: var(--accent); background: var(--panel-2); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.btn { border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.chip { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; color: var(--ink-2); }
.chip.cloud { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); background: var(--ok-soft); }
.chip.locked { color: var(--warn); background: var(--warn-soft); }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: 330px minmax(0, 1fr) 300px; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
.side, .checks { background: var(--panel); overflow: auto; }
.side { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.checks { border-left: 1px solid var(--line); padding: 14px; }
.checks h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 4px 9px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--ink-2); font-weight: 550; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.pane { display: none; padding: 12px 14px 40px; }
.pane.on { display: block; }
.only-narrow { display: none !important; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; font-weight: 700; background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad); color: #fff; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.seg { flex: none; display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.status { flex: 1; min-width: 0; color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.views { flex: 1; display: grid; min-height: 0; gap: 1px; background: var(--line); }
.views[data-mode="split"] { grid-template-columns: 1fr 1fr; }
.views[data-mode="plan"] .view-3d, .views[data-mode="3d"] .view-plan { display: none; }
.view { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--plan-bg); }
.view-3d { background: linear-gradient(#dfe6ec, #eef0ee); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .view-3d { background: linear-gradient(#20252b, #16181b); } }
.view-3d canvas { display: block; touch-action: none; }
.overlay { position: absolute; display: flex; gap: 6px; z-index: 3; }
.overlay.tl { top: 10px; left: 10px; }
.overlay.tr { top: 10px; right: 10px; }
.cams { flex-wrap: wrap; right: 60px; }
.cams button { border: 1px solid var(--line-2); background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.cams button:hover { background: var(--panel); }
.hint { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: var(--ink-3); pointer-events: none; }

/* ---- plan svg ---- */
.plan-svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: grab; outline: none; }
.plan-svg:active { cursor: grabbing; }
.room-floor { fill: var(--floor); stroke: none; }
.wall { stroke: var(--wall); stroke-width: .42; stroke-linecap: square; }
.wall-open { stroke: var(--wall); stroke-width: .08; stroke-dasharray: .3 .25; }
.suite { opacity: .8; }
.suite-wall { stroke: var(--wall); stroke-width: .42; }
.suite-label, .room-label { font-size: .75px; fill: var(--ink-3); text-anchor: middle; font-weight: 600; letter-spacing: .02em; }
.suite-label { font-size: 1px; }
.stairs rect { fill: var(--panel-2); stroke: var(--ink-3); stroke-width: .06; }
.stairs line { stroke: var(--ink-3); stroke-width: .05; }
.stair-arrow { stroke: var(--dim) !important; stroke-width: .08 !important; }
.window { stroke: #5aa6e6; stroke-width: .5; stroke-linecap: butt; }
.wall-tag circle { fill: var(--accent); }
.wall-tag text { fill: var(--accent-ink); font-size: .95px; font-weight: 800; text-anchor: middle; }
.north path { fill: var(--ink-2); }
.north text, .scalebar text { font-size: .7px; fill: var(--ink-2); text-anchor: middle; font-weight: 700; }
.scalebar text { text-anchor: start; }
.scalebar rect { fill: var(--ink-2); stroke: var(--ink-2); stroke-width: .04; }
.cad path, .cad polyline, .cad line, .cad polygon, .cad circle, .cad rect { vector-effect: non-scaling-stroke; }
.cad { opacity: .55; }
.cad #cad-text, .cad #cad-dims, .cad #cad-symbols { display: none; }
.contour { fill: none; stroke: var(--ink-2); stroke-width: .05; stroke-dasharray: .25 .18; opacity: .7; }
.contour-label { font-size: .55px; fill: var(--ink-2); font-weight: 700; paint-order: stroke; stroke: var(--plan-bg); stroke-width: .12px; text-anchor: middle; }

.item { cursor: move; }
.item .shape { stroke: rgba(0,0,0,.35); stroke-width: .05; }
.item .cushion { fill: rgba(0,0,0,.18); }
.item .felt { fill: #2e9a5f; stroke: rgba(0,0,0,.25); stroke-width: .04; }
.item .felt.wood { fill: #d8b98a; }
.item .pocket { fill: #111; }
.item .net { stroke: #fff; stroke-width: .12; }
.item .detail { stroke: rgba(255,255,255,.4); stroke-width: .05; }
.item .detail.light { stroke-dasharray: .2 .2; }
.item .stool { fill: #555; stroke: #222; stroke-width: .05; }
.item .tv-face { stroke: #4ea3ff; stroke-width: .12; }
.item .zone { fill: rgba(47,128,237,.06); stroke: rgba(47,128,237,.55); stroke-width: .06; stroke-dasharray: .3 .2; }
.item-label { font-size: .62px; fill: #fff; text-anchor: middle; font-weight: 650; pointer-events: none; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: .08px; }
.item-label.outside { fill: var(--ink); stroke: var(--plan-bg); stroke-width: .15px; }
.lvl-bad > .shape, .lvl-bad > .pad { stroke: var(--bad); stroke-width: .16; }
.lvl-warn > .shape { stroke: var(--warn); stroke-width: .14; }

.turf { opacity: .85; }
.bay-back { fill: rgba(0,0,0,.06); }
.pad { fill: #34383e; }
.net-side { stroke: #34383e; stroke-width: .12; stroke-dasharray: .25 .12; }
.screen { stroke: #fff; stroke-width: .28; filter: drop-shadow(0 0 .08px #000); }
.beam { fill: rgba(255, 214, 90, .2); stroke: rgba(210, 160, 20, .6); stroke-width: .04; }
.flight { fill: rgba(255,255,255,.12); stroke: rgba(255,255,255,.4); stroke-width: .03; }
.mat { fill: #2c6a35; stroke: #1c4a23; stroke-width: .05; }
.arc { fill: none; stroke-width: .09; opacity: .9; }
.arc-RH { stroke: #2f80ed; }
.arc-LH { stroke: #f2994a; }
.golfer ellipse { fill: #2f80ed; stroke: #fff; stroke-width: .06; }
.golfer-LH ellipse { fill: #f2994a; }
.golfer .head { fill: #f1d3b3; stroke: #333; stroke-width: .04; }
.golfer-tag { font-size: .55px; fill: #fff; font-weight: 800; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.5); stroke-width: .1px; }
.ball { fill: #fff; stroke: #333; stroke-width: .03; }
.monitor rect { fill: #24272b; stroke: #3a86ff; stroke-width: .08; }
.mon-overhead rect { stroke-dasharray: .15 .1; }
.mon-tag { font-size: .45px; fill: var(--ink); font-weight: 700; text-anchor: middle; }
.projector rect { fill: #eee; stroke: #444; stroke-width: .06; }
.projector .lens { fill: #222; }
.bay-label { font-size: .58px; fill: #fff; font-weight: 650; paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: .12px; pointer-events: none; }
.bay-label.start { text-anchor: start; }

.sel-box { fill: none; stroke: var(--sel); stroke-width: .08; stroke-dasharray: .3 .15; pointer-events: none; }
.sel-stem { stroke: var(--sel); stroke-width: .06; }
.rot-handle { fill: var(--panel); stroke: var(--sel); stroke-width: .12; cursor: grab; }
.dim line { stroke: var(--dim); stroke-width: .05; }
.dim text { font-size: .55px; fill: var(--dim); text-anchor: middle; font-weight: 700; }
.dim-bg { fill: var(--plan-bg); opacity: .9; }
.measure .dim line { stroke-width: .08; }
.measure .dim text { font-size: .75px; }
.size-tag { font-size: .55px; fill: var(--ink-2); text-anchor: middle; font-weight: 600; }

.legend { position: absolute; left: 10px; bottom: 10px; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 11px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.legend .ramp { width: 120px; height: 8px; border-radius: 4px; }

/* ---- forms ---- */
.field { display: grid; grid-template-columns: 1fr 128px; align-items: center; gap: 8px; margin: 7px 0; }
.field label { color: var(--ink-2); font-size: 13px; }
.field input, .field select { width: 100%; border: 1px solid var(--line-2); background: var(--panel); border-radius: 7px; padding: 5px 8px; font-variant-numeric: tabular-nums; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input.bad { border-color: var(--bad); }
.field.wide { grid-template-columns: 1fr; }
.field.toggle { grid-template-columns: auto 1fr; }
.field.toggle input { width: auto; }
.note { font-size: 12px; color: var(--ink-2); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0 4px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.group { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 12px; }
.group:first-child { border-top: 0; margin-top: 0; }
.group h3 { margin-top: 10px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--ink-3); }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.add-btn { display: flex; align-items: center; gap: 8px; text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px; cursor: pointer; }
.add-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.add-btn i { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.add-btn small { display: block; color: var(--ink-3); font-size: 11px; }
.empty { color: var(--ink-3); padding: 20px 4px; text-align: center; }

.check { display: flex; gap: 9px; padding: 8px 9px; border-radius: 8px; margin-bottom: 6px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.check .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; margin-top: 1px; }
.check.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.check.bad .dot { background: var(--bad); }
.check.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.check.warn .dot { background: var(--warn); }
.check.ok .dot { background: var(--ok); }
.check b { display: block; font-weight: 600; font-size: 13px; }
.check span { color: var(--ink-2); font-size: 12px; }
.checks-sub { font-size: 12px; color: var(--ink-3); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

/* ---- dialogs ---- */
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.dlg.small { width: min(380px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); margin: 0; }
.dlg-body { padding: 14px 16px 18px; max-height: 70vh; overflow: auto; }
.dlg-body input#pinInput { width: 100%; font-size: 20px; letter-spacing: .3em; text-align: center; padding: 8px; border: 1px solid var(--line-2); border-radius: 8px; margin: 6px 0 14px; background: var(--panel-2); }
.ly-list { list-style: none; margin: 0; padding: 0; }
.ly-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.ly-list li.cur { border-color: var(--accent); background: var(--accent-soft); }
.ly-list .grow { flex: 1; min-width: 0; }
.ly-list .grow b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ly-list .grow span { font-size: 12px; color: var(--ink-3); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; }
.toast.on { opacity: 1; transform: translateX(-50%); }

/* ---- narrow screens ---- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 310px minmax(0, 1fr); }
  .checks { display: none; }
  .only-narrow { display: revert !important; }
  .pane.only-narrow:not(.on) { display: none !important; }
  .tabs button.only-narrow { display: block !important; }
}
@media (max-width: 820px) {
  body { height: auto; }
  .top { padding: 0 10px; gap: 8px; }
  .brand-t { display: none; }
  .shell { display: flex; flex-direction: column-reverse; height: auto; }
  .stage { height: 62vh; height: 62dvh; position: sticky; top: 0; z-index: 5; }
  .side { border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
  .hide-narrow { display: none; }
  .views[data-mode="split"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .tabs { overflow-x: auto; }
  .tabs button { flex: none; padding: 8px 10px 9px; }
  .hint { display: none; }
  .cams { right: 50px; }
  .field { grid-template-columns: 1fr 140px; }
  .field input, .field select { font-size: 16px; }
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cad { filter: invert(1) hue-rotate(180deg); opacity: .45; } }
:root[data-theme="dark"] .cad { filter: invert(1) hue-rotate(180deg); opacity: .45; }
