    :root {
      --bg:#0f1720; --panel:#182430; --panel2:#1e2c3a; --line:#2a3a48;
      --fg:#eef4f9; --muted:#9fb1c1; --accent:#4aa8ff; --accent-ink:#04121f;
      --ok:#5fe08a; --warn:#ffb15c; --bad:#ff7d8a;
    }
    /* Light mode: follow the OS unless the user overrides via the toggle. */
    @media (prefers-color-scheme: light) {
      :root:not([data-theme="dark"]) {
        --bg:#f3f6f9; --panel:#ffffff; --panel2:#eef2f6; --line:#d3dde6;
        --fg:#12222f; --muted:#4c6072; --accent:#0a66c2; --accent-ink:#ffffff;
        --ok:#1c7a41; --warn:#8a5200; --bad:#b3261e;
      }
    }
    :root[data-theme="light"] {
      --bg:#f3f6f9; --panel:#ffffff; --panel2:#eef2f6; --line:#d3dde6;
      --fg:#12222f; --muted:#4c6072; --accent:#0a66c2; --accent-ink:#ffffff;
      --ok:#1c7a41; --warn:#8a5200; --bad:#b3261e;
    }
    * { box-sizing:border-box; }
    body { margin:0; background:var(--bg); color:var(--fg);
      font:15px/1.5 system-ui,-apple-system,Segoe UI,Roboto,sans-serif; }
    :focus-visible { outline:3px solid var(--warn); outline-offset:2px; }
    header { display:flex; flex-wrap:wrap; gap:.6rem; align-items:center;
      padding:.7rem 1rem; border-bottom:1px solid var(--line); }
    header h1 { font-size:1.05rem; margin:0 1rem 0 0; }
    header .spacer { flex:1; }
    .zoom { display:flex; align-items:stretch; gap:2px; }
    .zoom button { min-width:2.2rem; font-weight:700; }
    #zoom-reset { min-width:3.4rem; font-weight:600; }
    select, input, button, textarea {
      font:inherit; color:var(--fg); background:var(--panel2);
      border:1px solid var(--line); border-radius:8px; padding:.4rem .55rem;
    }
    button { cursor:pointer; background:var(--panel2); }
    button.accent { background:var(--accent); color:var(--accent-ink); border:none; font-weight:700; }
    button.danger { background:color-mix(in srgb,var(--bad) 22%,transparent); border-color:var(--bad); }
    button.active { background:color-mix(in srgb,var(--accent) 28%,transparent); border-color:var(--accent); }
    .layout { position:relative; display:flex; height:calc(100vh - 56px); overflow:hidden; }
    /* min-width:0 lets this flex item shrink below the (huge) SVG's width, so
       its own overflow:auto scrolls the canvas instead of widening the page. */
    .canvas-wrap { flex:1; min-width:0; overflow:hidden; background:var(--bg); }
    .canvas-wrap.panning { cursor:grabbing; }
    /* Grid lives on the SVG so it covers the whole (scrollable) canvas, and the
       canvas is sized in JS to fill at least the viewport - no CSS scaling, so
       1 screen pixel stays 1 SVG unit (the drag maths depends on this). */
    svg#canvas { display:block; cursor:grab; background:
      radial-gradient(circle, color-mix(in srgb,var(--line) 60%,transparent) 1px, transparent 1px) 0 0/26px 26px; }
    .canvas-wrap.panning svg#canvas { cursor:grabbing; }
    /* Editor drawer: slides in from the right, wide enough for the two-column
       field grids, vertical scroll only - never a horizontal scrollbar. */
    .panel { position:absolute; top:0; right:0; height:100%; width:min(96vw, 560px);
      background:var(--panel); border-left:1px solid var(--line);
      overflow-y:auto; overflow-x:hidden; padding:0 1.1rem 1.2rem;
      transform:translateX(100%); transition:transform .22s ease;
      box-shadow:-8px 0 26px rgba(0,0,0,.28); z-index:5; }
    /* Grid children default to min-width:auto, which lets wide intrinsic inputs
       (datetime-local) overflow the column. Let them shrink instead. */
    .grid2 > *, .grid3 > * { min-width:0; }
    .row input { min-width:0; }
    .panel.open { transform:translateX(0); }
    @media (prefers-reduced-motion: reduce) { .panel { transition:none; } }
    .panel-bar { position:sticky; top:0; background:var(--panel); z-index:1;
      display:flex; justify-content:flex-end; padding:.7rem 0 .5rem; margin-bottom:.3rem;
      border-bottom:1px solid var(--line); }
    .panel h2 { font-size:1rem; margin:.2rem 0 .8rem; }
    .row { margin-bottom:.7rem; }
    .row label { display:block; font-size:.8rem; font-weight:600; color:var(--muted); margin-bottom:.25rem; }
    .row input[type=text], .row input[type=number], .row select, .row textarea { width:100%; }
    .row.inline { display:flex; align-items:center; gap:.5rem; }
    .row.inline label { margin:0; color:var(--fg); font-weight:400; }
    .grid2 { display:grid; grid-template-columns:1fr 1fr; gap:.5rem; }
    .grid3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:.5rem; }
    .btns { display:flex; gap:.5rem; margin-top:1rem; }
    .btns button { flex:1; }
    .hint { color:var(--muted); font-size:.82rem; }
    .alert-box { background:color-mix(in srgb,var(--bad) 16%,transparent); border:1px solid var(--bad);
      border-radius:8px; padding:.55rem .7rem; font-size:.85rem; margin:.2rem 0 .7rem; }
    .empty { color:var(--muted); padding:2rem 1rem; text-align:center; }
    .photos { margin-top:.6rem; display:flex; flex-direction:column; gap:.5rem; }
    .photo { display:flex; gap:.5rem; align-items:center; background:var(--panel2);
      border:1px solid var(--line); border-radius:8px; padding:.4rem; }
    .photo img { width:60px; height:40px; object-fit:cover; border-radius:5px; cursor:zoom-in; }
    dialog.photo-modal { border:none; background:transparent; max-width:96vw; max-height:96vh; padding:0; }
    dialog.photo-modal::backdrop { background:rgba(0,0,0,.8); }
    .modal-inner { position:relative; }
    .modal-inner img { max-width:96vw; max-height:90vh; border-radius:10px; display:block; }
    .modal-close { position:absolute; top:.5rem; right:.5rem; min-height:44px; min-width:44px;
      background:rgba(0,0,0,.6); color:#fff; border:1px solid rgba(255,255,255,.4); border-radius:10px; font-size:1.2rem; cursor:pointer; }
    .photo .cap { flex:1; font-size:.8rem; }
    .photo .cap input { width:100%; margin-top:.2rem; font-size:.78rem; padding:.25rem .35rem; }
    /* Persona manager modal. */
    dialog.persona-modal { border:1px solid var(--line); background:var(--panel); color:var(--fg);
      border-radius:12px; padding:0; width:min(96vw,640px); max-height:90vh; }
    dialog.persona-modal::backdrop { background:rgba(0,0,0,.6); }
    .persona-bar { position:sticky; top:0; display:flex; align-items:center; gap:.5rem;
      background:var(--panel); border-bottom:1px solid var(--line); padding:.7rem 1rem; z-index:1; }
    .persona-bar h2 { font-size:1rem; margin:0; flex:1; }
    .persona-bar .modal-close { position:static; background:var(--panel2); color:var(--fg); border:1px solid var(--line); }
    #persona-list, #persona-form { padding:1rem; overflow:auto; max-height:calc(90vh - 3.4rem); }
    .p-row { display:flex; align-items:center; gap:.6rem; padding:.55rem .2rem; border-bottom:1px solid var(--line); }
    .p-row .p-name { flex:1; font-weight:600; }
    .p-badge { font-size:.68rem; font-weight:700; text-transform:uppercase; letter-spacing:.03em;
      padding:.12rem .4rem; border-radius:6px; border:1px solid var(--line); color:var(--muted); }
    .p-badge.custom { color:var(--accent); border-color:var(--accent); }
    .p-row button { padding:.3rem .55rem; font-size:.82rem; }
    .p-actions { display:flex; gap:.4rem; }
    #persona-form .row.inline { padding:.15rem 0; }
    #persona-form fieldset { border:1px solid var(--line); border-radius:8px; margin:.6rem 0; padding:.5rem .7rem; }
    #persona-form legend { font-size:.78rem; color:var(--muted); font-weight:700; padding:0 .3rem; }
    .p-form-actions { display:flex; gap:.5rem; margin-top:.8rem; }
    .p-form-actions button { flex:1; }
    /* Availability editor block. */
    .avail { border:1px solid var(--line); border-radius:8px; padding:.6rem .7rem; margin:.3rem 0 .7rem; }
    .avail.armed { border-color:var(--warn); background:color-mix(in srgb,var(--warn) 10%,transparent); }
    .avail .status { font-weight:700; font-size:.85rem; margin:0 0 .5rem; }
    .avail .status .dot { font-size:.9rem; }
    /* Decorative inline SVG icons; meaning carried by adjacent text. */
    .ico { width:1.05em; height:1.05em; fill:none; stroke:currentColor; stroke-width:2;
      stroke-linecap:round; stroke-linejoin:round; vertical-align:-.15em; flex:0 0 auto; }
    .ico.ok { color:var(--ok); } .ico.bad { color:var(--bad); } .ico.warn { color:var(--warn); }
    /* Downtime cues on the canvas. */
    .node.down circle { stroke:var(--bad); stroke-width:3; stroke-dasharray:4 3; }
    .edge.down { opacity:.45; stroke-dasharray:6 4; }
    /* Forced in service (manual override of a live 'out' reading). */
    .edge.forced { stroke:var(--warn); stroke-dasharray:9 3; }
    .toast { position:fixed; bottom:1rem; left:50%; transform:translateX(-50%);
      background:var(--panel); border:1px solid var(--line); border-radius:10px;
      padding:.6rem 1rem; box-shadow:0 6px 24px rgba(0,0,0,.4); opacity:0; transition:opacity .2s; }
    .toast.show { opacity:1; }
    .toast.err { border-color:var(--bad); }
    /* Edges: clean straight COLOUR-coded lines, each with a small mode badge
       (coloured dot + glyph) at its midpoint. Two channels - colour + glyph -
       so it reads without relying on colour alone. */
    :root {
      --edge-level:#7f93a3; --edge-ramp:#e08a2e; --edge-lift:#7c9cff;
      --edge-stairs:#e0607a; --edge-escalator:#2ba6b8; --edge-sightline:#8a97a8;
    }
    .edge { fill:none; stroke:var(--muted); stroke-width:2.5; stroke-linecap:round; cursor:pointer; }
    .edge.mode-level     { stroke:var(--edge-level); }
    .edge.mode-ramp      { stroke:var(--edge-ramp); }
    .edge.mode-lift_connection      { stroke:var(--edge-lift); }
    .edge.mode-stairs    { stroke:var(--edge-stairs); }
    .edge.mode-escalator_connection { stroke:var(--edge-escalator); }
    /* Sightline: dotted, so it reads as a reference link, not a path to walk. */
    .edge.mode-sightline { stroke:var(--edge-sightline); stroke-dasharray:2 5; stroke-width:2; }
    .edge:hover { stroke-width:3.5; }
    .edge.sel { stroke:var(--accent); stroke-width:4; }
    /* Unroutable lift/escalator NODE (no Citadel id): hazard ring so it stands
       out. The Citadel id lives on the node, never on the edges it connects. */
    .node.unroutable circle { stroke:#f2c200; stroke-width:4; stroke-dasharray:4 3; }
    /* Midpoint mode badge. */
    /* Text label running along an edge. paint-order:stroke draws a background
       halo so it stays legible where it crosses lines. */
    .edge-label { font-size:9px; font-weight:700; letter-spacing:.02em; cursor:pointer;
      fill:var(--muted); paint-order:stroke; stroke:var(--bg); stroke-width:3px; stroke-linejoin:round; }
    .edge-label.mode-ramp      { fill:var(--edge-ramp); }
    .edge-label.mode-lift_connection      { fill:var(--edge-lift); }
    .edge-label.mode-stairs    { fill:var(--edge-stairs); }
    .edge-label.mode-escalator_connection { fill:var(--edge-escalator); }
    .edge-label.mode-sightline { fill:var(--edge-sightline); }
    /* Direction arrowhead on one-way edges; fill matches the edge colour. */
    .edge-arrow { cursor:pointer; stroke:var(--panel); stroke-width:.5; }
    .edge-arrow.mode-level     { fill:var(--edge-level); }
    .edge-arrow.mode-ramp      { fill:var(--edge-ramp); }
    .edge-arrow.mode-lift_connection      { fill:var(--edge-lift); }
    .edge-arrow.mode-stairs    { fill:var(--edge-stairs); }
    .edge-arrow.mode-escalator_connection { fill:var(--edge-escalator); }
    .edge-badge { cursor:pointer; }
    .edge-badge circle { stroke:var(--panel); stroke-width:1.5; }
    .edge-badge text { font-size:10px; fill:#fff; pointer-events:none; font-weight:700; }
    .edge-badge.mode-ramp circle      { fill:var(--edge-ramp); }
    .edge-badge.mode-lift_connection circle      { fill:var(--edge-lift); }
    .edge-badge.mode-stairs circle    { fill:var(--edge-stairs); }
    .edge-badge.mode-escalator_connection circle { fill:var(--edge-escalator); }
    .edge-badge.mode-sightline circle { fill:var(--edge-sightline); }
    /* touch-action:none keeps a node press from being hijacked by the scroll
       container's native gesture, so dragging works reliably. */
    .node { touch-action:none; }
    .node circle { stroke:var(--line); stroke-width:2; cursor:pointer; }
    .node.sel circle { stroke:var(--warn); stroke-width:4; }
    /* Connect mode: nodes are click targets, and the chosen source is ringed. */
    .node.linkable circle { cursor:crosshair; }
    .node.linking circle { stroke:var(--ok); stroke-width:4; stroke-dasharray:4 3; }
    .node text { font-size:11px; fill:var(--fg); pointer-events:none; }
    .node .typ { font-size:9px; fill:var(--muted); }
    /* Edge-type legend, bottom-left of the canvas. */
    .legend { position:absolute; left:.8rem; bottom:.8rem; background:color-mix(in srgb,var(--panel) 92%,transparent);
      border:1px solid var(--line); border-radius:10px; padding:.5rem .7rem; font-size:.8rem; pointer-events:none; }
    .legend div { display:flex; align-items:center; gap:.55rem; margin:.2rem 0; }
    .legend .swatch { display:inline-flex; align-items:center; justify-content:center;
      width:20px; height:20px; border-radius:50%; color:#fff; font-size:11px; font-weight:700; flex:0 0 auto; }
    .legend .line { width:26px; height:0; border-top:3px solid var(--edge-level); flex:0 0 auto; }
