:root {
  --bg: #f6f6f3; --panel: #ffffff; --ink: #1d2126; --muted: #6a717a; --line: #e3e3de;
  --accent: #2a78d6; --wall: #2b2f35; --detail: #c4c6c2; --furn: #b7bab5; --room: #ffffff; --sel: #ffb000;
  --chip: #f0f0ec; --map-bg: #fbfbf9;
  --lbl-nm: var(--muted); --lbl-ex: var(--accent); --halo: transparent; --halo-w: 0; --lbl-dim: .35;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1c1f23; --ink: #e8e8e4; --muted: #9aa1a9; --line: #2c3036;
    --accent: #5aa1f0; --wall: #d9dbd6; --detail: #4a4e54; --furn: #5a5f66; --room: #1f2226; --sel: #ffb000;
    --chip: #262a2f; --map-bg: #17191c; --room: #2a2e33;
    --lbl-nm: #c4c9cf; --lbl-ex: #f2f6ff; --halo: rgba(10,11,13,.85); --halo-w: .38px; --lbl-dim: .6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --panel: #1c1f23; --ink: #e8e8e4; --muted: #9aa1a9; --line: #2c3036;
    --accent: #5aa1f0; --wall: #d9dbd6; --detail: #4a4e54; --furn: #5a5f66; --room: #1f2226; --sel: #ffb000;
    --chip: #262a2f; --map-bg: #17191c; --room: #2a2e33;
    --lbl-nm: #c4c9cf; --lbl-ex: #f2f6ff; --halo: rgba(10,11,13,.85); --halo-w: .38px; --lbl-dim: .6;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid; grid-template-columns: 340px 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; }
aside { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
h3 { margin: 0 0 6px; font-size: 16px; }
.sub { color: var(--muted); font-size: 12px; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; }
.chk { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
input[type=search], select, input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
.search { position: relative; }
#results { margin-top: 6px; display: flex; flex-direction: column; max-height: 300px; overflow-y: auto; }
#results button { text-align: left; border: 0; background: none; color: var(--ink); padding: 6px 8px; border-radius: 6px; cursor: pointer; font: inherit; display: flex; gap: 8px; align-items: baseline; }
#results button:hover, #results button:focus { background: var(--chip); outline: none; }
#results .k { font-size: 11px; color: var(--muted); min-width: 64px; }
#legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
#legend li { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
#legend li:hover { background: var(--chip); }
#legend li.on { background: var(--chip); font-weight: 600; }
#legend li.empty { opacity: .55; }
#legend li.hdr { cursor: default; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 6px 4px; }
#legend li.hdr:hover { background: none; }
#legend .nm { flex: 1; min-width: 0; }
.opts { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
#legend .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
#legend .n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#details { background: var(--chip); border-radius: 10px; padding: 12px; position: relative; }
#details .close { position: absolute; top: 6px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
#details .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
#details .dept.big { font-size: 16px; padding-right: 20px; }
#details ul.exts { max-height: 46vh; overflow-y: auto; }
#details li .who { flex: 1; min-width: 0; }
#details li .act { display: flex; gap: 4px; align-items: center; flex: none; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-weight: 600; padding: 0 4px; }
#banner { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 3; background: var(--sel); color: #111; padding: 8px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
#banner .btn.ghost { color: #111; border-color: rgba(0,0,0,.3); }
svg.placing .room { cursor: copy; fill-opacity: .25; }
#details .room-no { font-size: 20px; font-weight: 700; }
#details .meta { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
#details .dept { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
#details ul { list-style: none; padding: 0; margin: 6px 0 0; }
#details li { display: flex; gap: 8px; padding: 3px 0; align-items: center; }
#details li .x { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 48px; }
#details .row { display: flex; gap: 6px; margin-top: 8px; }
#details .note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 6px 10px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 2px 8px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

main { position: relative; overflow: hidden; background: var(--map-bg); }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
#map.drag { cursor: grabbing; }
#floors { position: absolute; top: 12px; left: 12px; z-index: 2; display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
#floors button { border: 0; background: none; color: var(--ink); padding: 6px 12px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; }
#floors button.on { background: var(--accent); color: #fff; }
#floors button small { font-weight: 400; opacity: .8; }
#zoom { position: absolute; right: 12px; top: 12px; z-index: 2; display: flex; flex-direction: column; gap: 4px; }
#zoom button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-size: 18px; cursor: pointer; }
#tip { position: absolute; z-index: 3; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: 260px; }
#tip b { font-size: 13px; }

/* map layers */
.detail { fill: none; stroke: var(--detail); stroke-width: calc(var(--px, .5) * .6); }
.walls { fill: none; stroke: var(--wall); stroke-width: calc(var(--px, .5) * 1.1); }
/* furniture (HDR furniture plans / addition telecom sheets): thin grey, above room colour, under walls and labels;
   drawn once zoomed in to about 3 px per foot (svg.zf) while the Furniture box is ticked */
.furniture { display: none; fill: none; stroke: var(--furn); stroke-width: calc(var(--px, .5) * .55); stroke-linejoin: round; pointer-events: none; }
svg.zf:not(.no-furn) .furniture { display: inline; }
/* rooms never overlap (build_map.py); a thin gap in the page colour keeps neighbouring rooms apart */
.room { fill: var(--room); fill-opacity: 0; stroke: var(--panel); stroke-width: calc(var(--px, .5) * 1.2); cursor: pointer; transition: fill-opacity .12s; }
/* no colour by default: rooms fill only when they answer a question (a chosen department / list / paging group,
   or the selected room) */
.room.has-dept { fill-opacity: 0; }
.room:hover { fill-opacity: .25; stroke: var(--sel); stroke-width: calc(var(--px, .5) * 1.5); }
.room.hl { fill-opacity: .6; }
.room.sel { stroke: var(--sel); stroke-width: calc(var(--px, .5) * 4); fill-opacity: .75; }
.room.sel:not(.has-dept):not(.hl) { fill: var(--sel); fill-opacity: .25; }
svg.has-sel .room:not(.sel):not(.hl) { fill-opacity: 0; }
svg.has-sel .room.hl:not(.sel) { fill-opacity: .3; }
#floors .fc { margin-left: 6px; min-width: 18px; padding: 0 5px; border-radius: 9px; color: #fff; font-size: 11px; font-weight: 700; display: inline-block; text-align: center; }
svg.has-sel .lbl:not(.force), svg.has-sel .pin, svg.has-sel .pin-t { opacity: var(--lbl-dim); }
.lbl.force { paint-order: stroke; stroke: var(--panel); stroke-width: .45px; stroke-linejoin: round; }
svg .lbl.force, svg .lbl.force .nm, svg .lbl.force .ex { display: inline !important; }
.pin.tight, .pin-t.tight { opacity: .85; }
.room.telecom { stroke: #1f9bd1; stroke-dasharray: 1.5 1; stroke-width: calc(var(--px, .5) * 2.5); fill-opacity: .25; }
svg.dim .room.hl { fill-opacity: .6; }
/* desks: one area per workstation in an open office, drawn once zoomed in (svg.zf) like the furniture */
.room.desk { display: none; fill: var(--accent); fill-opacity: 0; stroke: var(--furn); stroke-width: calc(var(--px, .5) * .8);
  stroke-dasharray: calc(var(--px, .5) * 4) calc(var(--px, .5) * 3); }
svg.zf .room.desk { display: inline; }
.room.desk.has-ph { fill-opacity: .1; }
.room.desk:hover { fill: var(--sel); fill-opacity: .2; stroke: var(--sel); stroke-dasharray: none; }
.room.desk.hl { fill-opacity: .6; }
.room.desk.sel { fill: var(--sel); fill-opacity: .3; stroke: var(--sel); stroke-dasharray: none; stroke-width: calc(var(--px, .5) * 3); }
svg:not(.zf) .desk-lbl { display: none; }
/* Edit mode: the selected desk moves by dragging it and resizes by its handles */
.room.desk.editable { cursor: move; }
.hdl { fill: var(--panel); stroke: var(--sel); stroke-width: calc(var(--px, .5) * 2); }
.hdl[data-k=n], .hdl[data-k=s] { cursor: ns-resize; }
.hdl[data-k=e], .hdl[data-k=w] { cursor: ew-resize; }
.hdl[data-k=ne], .hdl[data-k=sw] { cursor: nesw-resize; }
.hdl[data-k=nw], .hdl[data-k=se] { cursor: nwse-resize; }
svg:not(.zf) .hdl { display: none; }
.hdl.vtx { cursor: move; }
.hdl.mid { fill: var(--sel); stroke: var(--panel); cursor: copy; opacity: .8; }
.hdl.mid.h { cursor: ns-resize; }
.hdl.mid.v { cursor: ew-resize; }
/* a room whose highlighted phones are all on desks: zoomed in, only those desks are coloured */
svg.zf .room.hl.desk-only:not(.sel) { fill-opacity: 0; }
.desk-lbl .no { font-size: 1.05px; fill: var(--lbl-nm); }
.lbl { font: 600 1.5px system-ui, sans-serif; fill: var(--ink); pointer-events: none; text-anchor: middle; }
.lbl .no { font-weight: 700; }
.lbl .nm { font-weight: 400; font-size: 1.15px; fill: var(--lbl-nm); }
.lbl .ex { font-weight: 700; font-size: 1.2px; fill: var(--lbl-ex); }
svg:not(.z2) .lbl { display: none; }
svg.z2:not(.z3) .lbl .nm, svg.z2:not(.z3) .lbl .ex { display: none; }
.pin { fill: var(--accent); stroke: var(--panel); stroke-width: .3; pointer-events: none; }
.pin-t { font: 700 1.6px system-ui; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
svg.z3 .pin:not(.keep), svg.z3 .pin-t:not(.keep) { display: none; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); max-width: 420px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: 58vh minmax(0, 1fr); }
  main { grid-row: 1; }
  aside { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); padding: 16px; }
}

#flash { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 4; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 90%; }
body.shared #export-js, body.shared #reset, body.shared .csv-import { display: none; }
.chip { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; border: 1px dashed var(--muted); color: var(--muted); border-radius: 999px; padding: 0 6px; margin-left: 4px; white-space: nowrap; }
.lbl .ex.auto { fill: var(--muted); font-style: italic; }
.pin.auto { fill: var(--panel); stroke: var(--accent); stroke-width: .35; stroke-dasharray: .6 .4; }
.pin.auto + .pin-t { fill: var(--accent); }
.pc { fill: var(--panel); stroke: #2e7d32; stroke-width: .3; pointer-events: none; }
.pc-t { font: 700 1.5px system-ui; fill: #2e7d32; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
svg.z3 .pc, svg.z3 .pc-t { display: none; }
#details li .x.pcx { color: #2e7d32; font-size: 11px; }
.ap { fill: #6a1b9a; stroke: var(--panel); stroke-width: .3; pointer-events: none; }
.ap-t { font: 700 1.3px system-ui; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }

/* plan-sheet images under the addition ("Plan drawings" toggle); white paper drops out over the map background */
.underlay { display: none; mix-blend-mode: multiply; pointer-events: none; }
svg.show-plan .underlay { display: inline; }
svg.show-plan .room.hl { fill-opacity: .4; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .underlay { filter: invert(1) hue-rotate(180deg); mix-blend-mode: screen; } }
:root[data-theme="dark"] .underlay { filter: invert(1) hue-rotate(180deg); mix-blend-mode: screen; }

/* a phone that isn't in the group chosen in the legend */
.lbl .ex.out { opacity: .35; text-decoration: line-through; }

/* export button above the layer toggles */
#export-pdf, #export-html, #export-fill { width: 100%; margin: 0 0 6px; }
#pdfimpdlg { max-width: 640px; }
#pdfimp-list { max-height: 50vh; overflow: auto; font-size: 13px; }
#pdfimp-list table { border-collapse: collapse; width: 100%; }
#pdfimp-list th, #pdfimp-list td { text-align: left; padding: 3px 8px 3px 0; border-bottom: 1px solid var(--line); }
#pdfimp-list h4 { margin: 12px 0 4px; }

/* dark mode: a dark outline behind map labels so they read over walls and coloured rooms (none in light mode) */
.lbl:not(.force) { paint-order: stroke; stroke: var(--halo); stroke-width: var(--halo-w); stroke-linejoin: round; }

/* dashboards app */
.home { font-size: 13px; color: var(--accent); text-decoration: none; }
.home:hover { text-decoration: underline; }
