:root {
    --bg: #f4f5f7; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #d9dde3;
    --ok: #1f9d55; --stale: #d69e2e; --bad: #d64545; --frozen: #8e44ad; --accent: #2563eb;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #14171c; --panel: #1e232b; --text: #e6e8eb; --muted: #9aa3ae; --line: #313844; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 system-ui, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
.topbar { display: flex; align-items: center; gap: 24px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar .user { display: flex; gap: 8px; align-items: center; color: var(--muted); }
button { font: inherit; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--bad); }
main { padding: 16px; }
.login { max-width: 320px; margin: 10vh auto; background: var(--panel); padding: 24px; border-radius: 10px; border: 1px solid var(--line); }
.login label { display: block; margin-bottom: 12px; }
.login input { width: 100%; padding: 6px; margin-top: 4px; }
.error { color: var(--bad); }
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.filters { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.banner { background: #fff4d6; color: #5c4500; border: 1px solid #f0d68a; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.room h2 { font-size: 15px; margin: 18px 0 8px; }
.floor { position: relative; overflow: visible; margin-top: 4px; }
.extra { display: flex; flex-wrap: wrap; gap: 8px; }
.extra .card { position: static; width: 200px; height: 62px; }

/* Room furniture: wood-coloured desks, the dashed divide between rooms, room labels */
:root { --wood: #c8a27a; --wood-edge: #a47c55; }
@media (prefers-color-scheme: dark) { :root { --wood: #7a5a3c; --wood-edge: #5e432b; } }
.desk { position: absolute; border-radius: 3px; background: linear-gradient(180deg, var(--wood), color-mix(in srgb, var(--wood) 80%, #000));
        border: 1px solid var(--wood-edge); z-index: 0; }
.room-divide { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--muted); opacity: .6; }
.room-label { position: absolute; left: 0; width: 56px; font-weight: 700; font-size: 15px; color: var(--muted); }
.seat-inactive { position: absolute; width: 18px; height: 6px; border-radius: 2px; background: color-mix(in srgb, var(--muted) 55%, transparent);
                 z-index: 1; }

/* Cards: three lines; the status colour is the "screen" edge on the desk side (left edge when there's no desk) */
.card { position: absolute; z-index: 2; padding: 4px 8px; background: var(--panel); border: 1px solid var(--line);
        border-left: 5px solid var(--muted); border-radius: 7px; cursor: pointer; overflow: hidden; font-size: 12px; line-height: 17px;
        box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.card.face-down, .card.face-up { border-left-width: 1px; }
.card.face-down { border-bottom: 5px solid var(--muted); }
.card.face-up { border-top: 5px solid var(--muted); }
.card.selected { outline: 2px solid var(--accent); z-index: 3; }
.card.dimmed { opacity: .3; }
.status-online { border-color: var(--line); }
.status-online:not(.face-down):not(.face-up) { border-left-color: var(--ok); }
.status-online.face-down { border-bottom-color: var(--ok); }
.status-online.face-up { border-top-color: var(--ok); }
.status-stale:not(.face-down):not(.face-up) { border-left-color: var(--stale); }
.status-stale.face-down { border-bottom-color: var(--stale); }
.status-stale.face-up { border-top-color: var(--stale); }
.status-offline, .status-disabled { background: color-mix(in srgb, var(--bad) 8%, var(--panel)); }
.status-offline:not(.face-down):not(.face-up), .status-disabled:not(.face-down):not(.face-up) { border-left-color: var(--bad); }
.status-offline.face-down, .status-disabled.face-down { border-bottom-color: var(--bad); }
.status-offline.face-up, .status-disabled.face-up { border-top-color: var(--bad); }
.status-noagent, .status-pending { border-style: dashed; color: var(--muted); box-shadow: none; }
/* State backgrounds (pastel, mixed into the panel colour so text stays readable in light and dark mode).
   Later rules win: location < inactive < error. */
:root { --st-intro: #b9a6e8; --st-tutorial: #f2d34f; --st-hub: #7fb2f0; --st-world: #6fcf8f; --st-inactive: #f5a26a; --st-error: #ef6b6b; }
.card.loc-intro { background: color-mix(in srgb, var(--st-intro) 22%, var(--panel)); }
.card.loc-tutorial { background: color-mix(in srgb, var(--st-tutorial) 24%, var(--panel)); }
.card.loc-hub { background: color-mix(in srgb, var(--st-hub) 22%, var(--panel)); }
.card.loc-world { background: color-mix(in srgb, var(--st-world) 22%, var(--panel)); }
.card.inactive { background: color-mix(in srgb, var(--st-inactive) 28%, var(--panel)); }
.card.has-error { background: color-mix(in srgb, var(--st-error) 24%, var(--panel)); }
.legend { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; border: 1px solid var(--line); }
.card.lost { opacity: .6; filter: grayscale(.8); }
.card.lost .location { color: var(--bad); }
.badge.lostbadge { background: #fde2e2; color: #8a1c1c; }
.card-top { display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.machine { font-weight: 700; white-space: nowrap; }
.card-top .student { flex: 1; min-width: 0; margin-left: 4px; }
.badge { font-size: 10px; line-height: 15px; padding: 0 5px; border-radius: 8px; background: var(--line); flex: none; }
.badge.mode-VR { background: #dbeafe; color: #1e3a8a; }
.badge.mode-2D { background: #e5e7eb; color: #374151; }
.badge.warn { background: #fde2e2; color: #8a1c1c; }
.badge.admin { background: #fef3c7; color: #78350f; }
.student { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.location { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line); }
.bar .fill { height: 100%; background: var(--accent); }
.card-foot { display: flex; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.card-foot .age { margin-left: auto; }
/* World colour as side bars (left + right) while in a world; instance number large and clear */
.card.in-world { border-left: 6px solid var(--world) !important; border-right: 6px solid var(--world) !important; padding-left: 6px; padding-right: 6px; }
.location .world-name { margin-right: 6px; }
.location .instance { font-weight: 800; font-size: 15px; color: var(--text); letter-spacing: .5px; }
.location .virtual { margin-left: 6px; color: var(--bad); font-weight: 600; }
.legend i.world-swatch { width: 18px; height: 12px; border: none; }
.err { color: var(--bad); font-weight: 600; }
.detail { position: fixed; top: 48px; right: 0; bottom: 0; width: min(420px, 100vw); overflow-y: auto; background: var(--panel);
          border-left: 1px solid var(--line); padding: 16px; box-shadow: -4px 0 16px rgba(0,0,0,.08); z-index: 20; }
/* Wide screens: the side panel is always docked and the room view always leaves space for it, so nothing moves.
   Narrow screens: the panel covers the room, and only while a PC is selected. */
@media (min-width: 900px) { .lab-page main { padding-right: calc(380px + 16px); } .lab-page .detail { width: 380px; } }
@media (max-width: 899px) { body:not(.detail-open) .detail { display: none; } }
.detail-hint { color: var(--muted); }
.legend-panel { flex-direction: column; align-items: flex-start; gap: 6px; font-size: 13px; }
.detail .close { float: right; }
.detail table { border-collapse: collapse; width: 100%; }
.detail th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 8px 3px 0; vertical-align: top; width: 38%; }
.detail td { padding: 3px 0; word-break: break-word; }
.events, .installed { padding-left: 18px; color: var(--muted); }
table.list { border-collapse: collapse; width: 100%; background: var(--panel); }
table.list th, table.list td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.form-row { display: flex; gap: 8px; align-items: end; margin: 12px 0; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; gap: 2px; }
.notice { background: color-mix(in srgb, var(--ok) 12%, var(--panel)); border: 1px solid var(--ok); padding: 8px 12px; border-radius: 6px; }

/* Selection and the command controls in the side panel */
.card.selected { outline: 3px solid var(--accent); outline-offset: 1px; z-index: 3; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.select-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 10px; }
.actions { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; background: color-mix(in srgb, var(--accent) 4%, var(--panel)); }
.actions h3 { margin: 0 0 8px; font-size: 14px; }
.action-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: end; margin: 6px 0; }
.action-block { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.actions label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.actions label.inline { flex-direction: row; align-items: center; gap: 4px; }
.actions label.grow { flex: 1; }
.actions textarea, .actions input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); color: var(--text); }
.actions textarea { width: 100%; resize: vertical; }
.actions input[type=number] { width: 70px; }
.cmd-result { min-height: 1.2em; margin: 6px 0 0; font-size: 12px; color: var(--ok); }
.cmd-result.warn { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.chip-off { opacity: .55; text-decoration: line-through; }
.commands .cmd-refused, .commands .cmd-expired, .commands .cmd-offline { color: var(--bad); }
.commands .cmd-done { color: var(--ok); }
.cmd-ind { font-weight: 600; }
.cmd-wait { color: var(--accent); }
.cmd-fail { color: var(--bad); }
.cmd-done { color: var(--ok); }

/* Seats with no agent (or awaiting enrolment) are not selectable */
.card.status-noagent, .card.status-pending { cursor: default; }
