:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel2: #1e2739;
  --line: #2a3550;
  --text: #e6ebf5;
  --muted: #8b97b0;
  --accent: #4f8cff;
  --green: #2ec27e;
  --yellow: #f5c211;
  --red: #ed5a5a;
  --grey: #5e6a82;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 10px; font-weight: 600; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 5px; font-size: 13px; word-break: break-all; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1em; margin: 6px 0; }
.logo { color: var(--accent); }

button, select, input {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.danger-ghost { color: var(--red); background: transparent; }
button.small { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
label input, label select { color: var(--text); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.center-screen { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; }
.login-card button { width: 100%; margin-top: 6px; }
.login-card { width: 400px; }
.setup-title { font-weight: 600; font-size: 15px; margin: 4px 0 8px; }
.setup-steps { margin: 0 0 8px; padding-left: 20px; color: var(--muted); font-size: 13px; }
.setup-steps b { color: var(--text); }
.code-input { font: 600 22px ui-monospace, monospace !important; letter-spacing: 4px; text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; display: flex; align-items: center; gap: 9px; }
.brand-logo { width: 28px; height: 28px; }
.login-logo { width: 64px; height: 64px; display: block; margin: 0 auto 14px; }
.login-card h1 { text-align: center; }
.login-card > p.muted { text-align: center; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav button { background: transparent; border-color: transparent; color: var(--muted); }
#nav button.active { color: var(--text); background: var(--panel2); border-color: var(--line); }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.authcode { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px; }
.authcode strong { font: 600 18px/1 ui-monospace, monospace; letter-spacing: 2px; color: var(--green); }
.ring { font-size: 12px; color: var(--muted); width: 26px; text-align: right; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.view-head h2 { margin: 0; margin-right: auto; }
#desk-filter { width: 260px; }
.summary { display: flex; gap: 8px; }
.empty { color: var(--muted); text-align: center; padding: 60px 0; }

/* desk cards */
.desk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.desk { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--grey); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.desk.active { border-left-color: var(--green); }
.desk.idle { border-left-color: var(--yellow); }
.desk.locked { border-left-color: var(--red); }
.desk.logged-out { border-left-color: var(--accent); }
.desk-top { display: flex; align-items: center; gap: 8px; }
.desk-name { font-weight: 600; font-size: 15px; margin-right: auto; }
.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.badge.active { background: rgba(46,194,126,.15); color: var(--green); }
.badge.idle { background: rgba(245,194,17,.15); color: var(--yellow); }
.badge.locked { background: rgba(237,90,90,.15); color: var(--red); }
.badge.logged-out { background: rgba(79,140,255,.15); color: var(--accent); }
.badge.pending { background: rgba(245,194,17,.18); color: var(--yellow); }
.desk.pending { border-left-color: var(--yellow); }
.badge.live { background: var(--red); color: #fff; }
.desk-user { display: flex; flex-direction: column; gap: 2px; }
.desk-user b { font-size: 14px; }
.desk-meta { font-size: 12.5px; color: var(--muted); }
.tabs { list-style: none; margin: 0; padding: 0; max-height: 170px; overflow: auto; border-top: 1px solid var(--line); }
.tabs li { display: flex; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.tabs li.current { background: rgba(79,140,255,.08); }
.tabs li .t { flex: 1; min-width: 0; }
.tabs li .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs li .u { color: var(--muted); font-size: 11.5px; }
.tabs li .dot { width: 7px; height: 7px; border-radius: 50%; background: transparent; flex: none; }
.tabs li.current .dot { background: var(--accent); }
.tabs li button { visibility: hidden; }
.tabs li:hover button { visibility: visible; }
.desk-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.desk-code { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.desk-code .lbl { color: var(--muted); font-size: 12px; }
.desk-code strong { font: 600 20px/1 ui-monospace, monospace; letter-spacing: 3px; color: var(--green); }
.desk-code .secs { color: var(--muted); font-size: 12px; margin-right: auto; }
.user-code { display: inline-flex; padding: 4px 8px; gap: 8px; }
.user-code strong { font-size: 17px; }

/* camera wall */
.camera-grid { --tile: 360px; display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); gap: 12px; background: var(--bg); }
.camera-grid:fullscreen { padding: 12px; overflow: auto; align-content: start; }
.cam-tile { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--grey); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.cam-tile.active { border-top-color: var(--green); }
.cam-tile.idle { border-top-color: var(--yellow); }
.cam-tile.locked { border-top-color: var(--red); }
.cam-tile.logged-out { border-top-color: var(--accent); }
.cam-tile.offline { opacity: .55; }
.cam-view { position: relative; aspect-ratio: 4 / 3; background: #000; display: grid; place-items: center; cursor: zoom-in; }
.cam-view img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-view .cam-msg { padding: 12px; text-align: center; font-size: 12.5px; }
.cam-tile.stale .cam-view::after { content: 'No signal'; position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.7); color: var(--yellow); font-size: 11px; padding: 2px 7px; border-radius: 5px; }
.cam-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13px; }
.cam-name { font-weight: 600; white-space: nowrap; }
.cam-user { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
label.inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.small-note { font-size: 12px; margin-top: 14px; }

/* policies & extensions */
textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; resize: vertical; }
.checks { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; max-height: 220px; overflow: auto; }
.checks label { margin: 0; }
.default-row td { background: rgba(79,140,255,.06); }
.inline-form { display: flex; gap: 6px; }
.inline-form input { width: 380px; }
.upload-btn { flex-direction: row; margin: 0; cursor: pointer; color: var(--text); font-size: 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.upload-btn:hover { border-color: var(--accent); }
.ext-list { display: flex; flex-direction: column; gap: 10px; }
.ext { display: flex; gap: 14px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.ext.off { opacity: .55; }
.ext img, .ext-ph { width: 40px; height: 40px; flex: none; border-radius: 8px; object-fit: contain; font-size: 28px; text-align: center; }
.ext-info { flex: 1; min-width: 0; }
.ext-where { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.ext-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.mode-pick { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.mode-pick label { align-items: flex-start; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; cursor: pointer; }
.mode-pick label:has(input:checked) { border-color: var(--accent); }
.mode-pick input { margin-top: 3px; }
.shot-thumb { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.toast.alert { border-color: var(--yellow); color: var(--yellow); cursor: pointer; }

.rep-sites { font-size: 12px; color: var(--muted); }
.rep-sites b { color: var(--text); font-weight: 500; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; width: 90px; }
.bar > i { display: block; height: 100%; background: var(--green); }
.snap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.snap-grid figure { margin: 0; cursor: zoom-in; }
.snap-grid img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; aspect-ratio: 16 / 10; object-fit: cover; background: #000; }
.snap-grid figcaption { font-size: 11.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.admin-row b { margin-right: auto; }
body.role-viewer .owner-only, body.role-admin .owner-only { display: none; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; background: var(--panel2); }
.table.compact td { padding: 6px 12px; font-size: 13px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions button { margin-left: 4px; }
.table td.wrap { word-break: break-all; max-width: 600px; }

/* settings */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 10px 0 14px; }
.qr-box img { background: #fff; padding: 8px; border-radius: 8px; width: 200px; height: 200px; }
@media (max-width: 1000px) { .settings-grid { grid-template-columns: 1fr; } }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(560px, 94vw); max-height: 92vh; overflow: auto; }
.modal-box.wide { width: min(1000px, 96vw); }
.modal-head { display: flex; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; margin-right: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.days label { flex-direction: row; align-items: center; gap: 4px; margin: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; color: var(--text); }
.stream { background: #000; border-radius: 8px; min-height: 300px; display: grid; place-items: center; overflow: hidden; }
.stream img { max-width: 100%; max-height: 75vh; display: block; }
.stream .muted { padding: 40px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.err { border-color: var(--red); color: var(--red); }
