:root {
  --ink: #1d2430;
  --muted: #6b7683;
  --line: #dfe3e8;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --warn-bg: #fff6e0;
  --warn-line: #e8cf94;
  --err: #a8321f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.titles h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.stats { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.viewctl { display: flex; gap: 10px; align-items: center; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  background: var(--panel);
  color: var(--muted);
  user-select: none;
}
.seg label + input + label { border-left: 1px solid var(--line); }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); }

#levelsAndCameras {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px;
}

.warn {
  padding: 9px 20px;
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-line);
  font-size: 13px;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  padding: 18px 20px 28px;
  align-items: start;
}

.stage { min-width: 0; display: grid; gap: 18px; }

.canvaswrap {
  position: relative;
  height: 58vh;
  min-height: 360px;
  background: #cfd4d8;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#viewerCanvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}
.progress {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 80%);
  padding: 16px 18px;
  border-radius: 12px;
  background: rgba(29, 36, 48, 0.78);
  color: #fff;
  text-align: center;
}
.progress progress { width: 100%; }
.progress label { display: block; margin-top: 6px; font-size: 12px; }
.hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  margin: 0;
  font-size: 12px;
  color: #46505c;
  background: rgba(255, 255, 255, 0.82);
  padding: 4px 9px;
  border-radius: 6px;
}

.planwrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 16px;
}
.planhead {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.planhead h2 { margin: 0; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.planactions { display: flex; gap: 10px; align-items: center; }
.planhint { font-size: 12px; color: var(--muted); }

.planhost { width: 100%; overflow-x: auto; }
.planhost svg { display: block; width: 100%; height: auto; cursor: crosshair; }
.planhost.pinning svg { cursor: cell; }

.pin circle { fill: var(--accent); stroke: #fff; stroke-width: 2; cursor: pointer; }
.pin text { fill: #fff; font-family: inherit; pointer-events: none; }
.pin.pending circle { fill: #c98a17; opacity: 0.85; }

.rail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 18px;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
.rail h2 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }

.pinnote { margin: 0 0 8px; font-size: 12px; color: #8a6a1a; }

#cform { display: grid; gap: 8px; }
#cform input, #cform textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fcfcfd;
  resize: vertical;
}
.formrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pinstate { font-size: 12px; color: #8a6a1a; }

.btn {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: #c4cbd3; }
.btn.active { background: #fdf3dd; border-color: var(--warn-line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.err { color: var(--err); font-size: 13px; margin: 4px 0 0; }

.clist { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.clist li {
  position: relative;
  padding: 9px 10px 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfcfd;
  font-size: 14px;
}
.clist li.flash { border-color: var(--accent); background: #f0f7f2; }
.clist li.empty { color: var(--muted); font-style: italic; border-style: dashed; }
.cmeta { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.cmeta time { color: var(--muted); font-size: 11px; }
.cbody { margin-top: 3px; white-space: pre-wrap; word-wrap: break-word; }
.pinbadge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  padding: 0 4px;
}

.foot { padding: 0 20px 22px; color: var(--muted); font-size: 12px; }

/* Landing + admin */
.center { max-width: 640px; margin: 14vh auto; padding: 0 22px; }
.center h1 { font-size: 22px; margin: 0 0 8px; }
.center p { color: var(--muted); }

table.admin { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 14px; }
table.admin th, table.admin td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.admin th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
table.admin small { color: var(--muted); }
.ok { color: var(--accent); font-weight: 600; }
.bad { color: var(--err); }
input.link { width: 100%; min-width: 230px; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fcfcfd; }

@media (max-width: 960px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; max-height: none; }
  .canvaswrap { height: 48vh; }
}

/* Camera marker on the plan */
.cam .cone {
  fill: #2f6f4f;
  fill-opacity: 0.16;
  stroke: #2f6f4f;
  stroke-opacity: 0.45;
  pointer-events: none;
}
.cam .aim {
  stroke: #2f6f4f;
  stroke-opacity: 0.55;
  pointer-events: none;
}
.cam .body {
  fill: #2f6f4f;
  stroke: #fff;
  cursor: grab;
}
.cam .handle {
  fill: #fff;
  stroke: #2f6f4f;
  cursor: grab;
}
.cam-aerial .cone { fill: #4a6a8c; stroke: #4a6a8c; }
.cam-aerial .aim { stroke: #4a6a8c; }
.cam-aerial .body { fill: #4a6a8c; cursor: default; }
.cam-aerial .handle { stroke: #4a6a8c; }
.cam-offplan .body { fill-opacity: 0.55; }
.planhost.dragging svg { cursor: grabbing; }
.planhost.dragging .cam .body,
.planhost.dragging .cam .handle { cursor: grabbing; }

.camstate {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

/* Camera glyph */
.cam .shell { fill: #2f6f4f; stroke: #ffffff; stroke-linejoin: round; }
.cam .glass { fill: #dff0e6; stroke: #ffffff; }
.cam .grab { fill: transparent; stroke: none; }
.cam .body { cursor: grab; }
.cam-aerial .shell { fill: #4a6a8c; }
.cam-aerial .glass { fill: #dce6f0; }
.cam-aerial .body { cursor: default; }
.cam-offplan .shell, .cam-offplan .glass { opacity: 0.6; }

/* Zoom controls */
.zoomctl { display: inline-flex; align-items: center; gap: 4px; }
.zbtn { min-width: 30px; padding: 5px 8px; font-size: 15px; line-height: 1; }
.zoomlevel {
  min-width: 44px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#zoomReset:disabled { opacity: 0.45; cursor: default; }
.planhost svg { touch-action: none; }
.planhost.panning svg { cursor: grabbing; }

/* Design picker */
.titlerow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.picker {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  max-width: 320px;
  cursor: pointer;
}
.picker:hover { border-color: #c4cbd3; }

/* ---- Home page ---- */
/* Must restate grid-template-columns: the generic `main` rule above sets a
   two-column viewer layout that would otherwise still apply here. */
.homemain {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px 20px 28px;
  max-width: 1500px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.cardhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.cardhead h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.cardhead h2 a { color: inherit; text-decoration: none; }
.cardhead h2 a:hover { color: var(--accent); }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: #7a5c12;
  font-size: 11px;
  white-space: nowrap;
}

.cardbody {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(280px, 1fr);
  gap: 16px;
  padding: 14px 16px 16px;
  align-items: start;
}
.cardplan {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  min-width: 0;
}
.cardplan img { display: block; width: 100%; height: auto; }
.cardplan:hover { border-color: var(--accent); }

.cardcomments h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 650;
}
.cardcomments .clist { margin: 0; max-height: 340px; overflow-y: auto; }
.cardcomments .clist li { font-size: 13px; }
.cardcomments .cbody { max-height: none; }
.clist li.more { text-align: center; border-style: dashed; padding: 6px; }
.pinbadge.inline {
  position: static;
  display: inline-block;
  margin-top: 5px;
  min-width: 0;
  height: auto;
  line-height: 1.5;
  border-radius: 9px;
  padding: 0 7px;
  font-size: 10px;
}

.backlink {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.backlink:hover { color: var(--accent); }

@media (max-width: 900px) {
  .cardbody { grid-template-columns: minmax(0, 1fr); }
  .cardcomments .clist { max-height: none; }
}

/* ---- Access gate ---- */
.gatewrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gatecard {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 26px 22px;
}
.gatecard h1 { margin: 0 0 8px; font-size: 20px; letter-spacing: -0.01em; }
.gatecard p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.gatecard form { display: flex; gap: 8px; }
.gatecard input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fcfcfd;
}
.gatecard .err { margin: 12px 0 0; }
.revoke { color: var(--err); font-size: 12px; text-decoration: none; }
.revoke:hover { text-decoration: underline; }
