:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #5b9dff;
  --accent-ink: #07101f;
  --danger: #ff5d6c;
  --ok: #3ecf8e;
  --rec: #ff3b4e;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* buttons + inputs */
button, .btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { border-color: #3b4252; background: #242935; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--panel-2); }
button.sm { padding: 4px 9px; font-size: 13px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error { color: var(--danger); min-height: 1.4em; font-size: 13px; }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card button { width: 100%; justify-content: center; padding: 10px; }

/* app shell */
header.top {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 0 3px rgba(255,59,78,.18); }
nav { display: flex; gap: 4px; }
nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; }
nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--panel-2); }
.spacer { flex: 1; }
main { padding: 22px 20px 60px; max-width: 1200px; margin: 0 auto; }
main.wide { max-width: none; padding: 14px 16px 24px; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.page-head select { width: auto; min-width: 200px; }

/* tables / cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; background: var(--panel); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255,255,255,.015); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.sub { color: var(--muted); font-size: 12.5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.rec { color: #fff; background: var(--rec); border-color: var(--rec); animation: pulse 1.6s infinite; }
.badge.ok { color: var(--ok); }
.badge.warn { color: #ffb454; }
@keyframes pulse { 50% { opacity: .65; } }

/* switch */
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #2d3340; border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #aab; transition: .15s; }
.switch input:checked + span { background: var(--rec); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* viewer */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .title { font-weight: 600; margin-right: 6px; }
.toolbar input[type=range] { flex: 1; min-width: 160px; padding: 0; accent-color: var(--accent); }
.toolbar select { width: auto; padding: 6px 8px; }
.toolbar label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); }
.toolbar label.inline input { width: auto; }
.screen { background: #000; border: 1px solid var(--line); border-radius: var(--radius); height: calc(100vh - 215px); min-height: 360px; overflow: hidden; position: relative; }
.screen .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; text-align: center; padding: 20px; }
/* forced pointer styles override the inline cursor noVNC sets from the remote cursor shape */
.screen[data-ptr="arrow"] canvas { cursor: default !important; }
.screen[data-ptr="cross"] canvas { cursor: crosshair !important; }
.timecode { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 110px; text-align: right; }

/* dialogs + toasts */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-bottom: 16px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; z-index: 50; max-width: 360px; }
.toast.err { border-color: var(--danger); color: var(--danger); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; color: var(--muted); }

/* link-style buttons (history, cards) */
.btn { text-decoration: none; }
.btn:hover { text-decoration: none; border-color: #3b4252; background: #242935; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.page-head label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); }
.page-head label.inline input { width: auto; }

/* servers: folder tree + thumbnail grid */
.srv-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.srv-main { min-width: 0; }
.tree { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 6px; position: sticky; top: 66px; max-height: calc(100vh - 90px); overflow: auto; }
.tree-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 4px 8px 8px; font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.tree-head .sub { text-transform: none; letter-spacing: 0; font-size: 11px; }
.trow { display: flex; align-items: center; gap: 2px; border-radius: 8px; border: 1px dashed transparent; min-height: 32px; padding-right: 4px; }
.trow:hover, .trow:focus-within { background: var(--panel-2); }
.trow.sel { background: rgba(91,157,255,.16); }
.trow.drop { border-color: var(--accent); background: rgba(91,157,255,.24); }
.trow button { background: transparent; border: 0; padding: 0; color: inherit; border-radius: 6px; cursor: pointer; }
.trow .caret { width: 18px; height: 22px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.tlabel { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; text-align: left; padding: 6px 4px; overflow: hidden; white-space: nowrap; cursor: pointer; border-radius: 6px; }
.tlabel:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tlabel .ico { color: var(--muted); font-size: 12px; flex: none; }
.cnt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding: 0 4px; }
.tact { display: none; gap: 2px; }
.trow:hover .tact, .trow:focus-within .tact { display: inline-flex; }
.trow:hover .cnt, .trow:focus-within .cnt { display: none; }
.tact button { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.tact button:hover { background: var(--line); color: var(--text); }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid[data-size="s"] { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid[data-size="l"] { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }
.srv { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.srv:active { opacity: .7; }
.thumb { position: relative; display: block; aspect-ratio: 3 / 2; background: #05070a; overflow: hidden; }
.thumb:hover { text-decoration: none; }
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12.5px; padding: 12px; text-align: center; }
.pill { position: absolute; left: 8px; top: 8px; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: rgba(15,17,21,.85); color: var(--text); border: 1px solid var(--line); }
.pill.rec { background: var(--rec); border-color: var(--rec); color: #fff; animation: pulse 1.6s infinite; }
.pill.ok { color: var(--ok); }
.pill.warn { color: #ffb454; }
.age { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #cfd4dc; background: rgba(15,17,21,.72); padding: 1px 6px; border-radius: 6px; }
.age:empty { display: none; }
.meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.path { font-size: 12px; }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 4px; }
.tg { display: inline-flex; align-items: center; gap: 7px; margin: 0; font-size: 12.5px; color: var(--text); cursor: pointer; }
.statusline { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.4em; }
.statusline.bad { color: var(--danger); }
.row-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

pre.cmd { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 6px 0; font-size: 12px; white-space: pre-wrap; word-break: break-all; user-select: all; }
.hint.okc { color: var(--ok); }
.hint.badc { color: #ffb454; }
dialog p { margin: 8px 0; }

@media (max-width: 900px) {
  .srv-layout { grid-template-columns: 1fr; }
  .tree { position: static; max-height: 240px; }
}

@media (max-width: 720px) {
  header.top { padding: 0 10px; gap: 8px; }
  th:nth-child(n+4), td:nth-child(n+4):not(.actions) { display: none; }
  main { padding: 16px 10px 40px; }
}

.screen-holder { position: relative; }
.screen.in-pip { height: 100vh; border: 0; border-radius: 0; }
.pip-note { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: #000c; color: var(--muted); border-radius: var(--radius); }
.pip-chip { position: fixed; right: 14px; bottom: 14px; z-index: 50; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card, #1b1f27); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 4px 16px #0006; font-size: 13px; }

a.btn { display: inline-flex; align-items: center; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; color: inherit; text-decoration: none; font-size: 14px; }
a.btn.sm, button.sm { padding: 3px 8px; font-size: 12px; }
.wall { display: grid; gap: 10px; }
.tile { background: #000; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile.ctl { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile-head { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--card, #1b1f27); font-size: 13px; }
.tile-head .dot { width: 8px; height: 8px; border-radius: 50%; background: #888; flex: none; }
.tile-head .dot.on { background: #3fb950; }
.wall-screen { aspect-ratio: 4 / 3; background: #000; position: relative; overflow: hidden; }
.pick { position: relative; }
.pick summary { cursor: pointer; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; list-style: none; font-size: 14px; }
.pick-list { position: absolute; z-index: 20; top: 100%; margin-top: 4px; min-width: 200px; max-height: 50vh; overflow: auto; padding: 8px; background: var(--card, #1b1f27); border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 6px; }
.pick-list label { display: flex; gap: 8px; align-items: center; margin: 0; }
.pick-list input { width: auto; }

.viewer .admin-only { display: none !important; }
.no-history .needs-history, .no-history nav a[data-nav=history] { display: none !important; }
article.srv { position: relative; }
.pick-card { position: absolute; top: 8px; left: 8px; z-index: 3; width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; opacity: .55; }
article.srv:hover .pick-card, .pick-card:checked { opacity: 1; }
.urow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ulist { margin: 10px 0 14px; max-height: 40vh; overflow: auto; }
.pick-list.static { position: static; max-height: 200px; margin: 0; }

tr.failed td { background: #f851491a; }
.badge.bad { background: #f8514933; color: #ff7b72; }

.page-head label { white-space: nowrap; }

img.stream { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.streambox { position: relative; display: block; }
.streambox .overlay { position: absolute; inset: 0; display: grid; place-content: center; color: var(--muted); background: #000a; text-align: center; padding: 20px; }
.wall-screen img.stream { position: absolute; inset: 0; }
video.videoplayer { width: 100%; height: 100%; background: #000; display: block; }
.videobox { display: block; }

/* ---- RAW (TCP / UDP) logger */
.rawholder { display: flex; flex-direction: column; min-height: 420px; height: calc(100vh - 150px); }
.rawbox { display: flex; flex: 1; min-height: 0; width: 100%; }
.rawbox.in-pip { height: 100vh; }
.rawpanel { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; background: #0b0d10; border: 1px solid var(--line, #2a2f36); border-radius: 8px; overflow: hidden; }
.rawbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line, #2a2f36); }
.rawbar input[type=search] { min-width: 160px; flex: 1; }
.rawlist { flex: 1; min-height: 0; overflow: auto; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 4px 0; }
.rawrow { display: grid; grid-template-columns: 6.8em 3.4em minmax(8em, 14em) 4.5em 1fr; gap: 8px; padding: 2px 10px; align-items: start; border-left: 3px solid transparent; }
.rawrow:hover { background: rgba(255,255,255,.04); }
.rawrow.rx { border-left-color: #3fb27f; }
.rawrow.tx { border-left-color: #e0a73a; }
.rawrow.ev { border-left-color: #6b7280; color: #9aa3ad; }
.rawrow .t, .rawrow .peer, .rawrow .len { color: #8b95a1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rawrow .dir { font-weight: 600; }
.rawrow.rx .dir { color: #3fb27f; } .rawrow.tx .dir { color: #e0a73a; }
.rawrow .body { margin: 0; white-space: pre-wrap; word-break: break-all; font: inherit; color: #d6dbe1; }
.rawrow .msg { grid-column: 4 / -1; }
.rawempty { padding: 24px; text-align: center; color: #8b95a1; }
.rawmore { text-align: center; }
.rawmore button[hidden] { display: none; }
.rawsend { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; border-top: 1px solid var(--line, #2a2f36); }
.rawsend input[type=text]:first-child { flex: 2; min-width: 200px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.walllog { margin: 0; height: 100%; overflow: hidden; padding: 6px 8px; background: #0b0d10; color: #cfd6dd; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
@media (max-width: 700px) { .rawrow { grid-template-columns: 6.2em 3em 1fr; } .rawrow .peer, .rawrow .len { display: none; } .rawrow .msg { grid-column: 3; } }
.rawbar select, .rawsend select, .rawbar input, .rawsend input { width: auto; margin: 0; }
.rawbar input[type=search] { width: auto; flex: 1 1 200px; }
.rawbar input[type=checkbox] { width: auto; }
.rawsend input[type=text]:first-child { flex: 3 1 260px; }
.rawsend input[placeholder^="to"] { flex: 1 1 160px; }
.rawbar label.inline { display: inline-flex; flex-direction: row; gap: 6px; align-items: center; }
.rawrow { grid-template-columns: 8.4em 3.6em minmax(8em, 13em) 4.5em 1fr; }
.rawbar .sub { margin-left: auto; }
.pvs { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.pv { background: rgba(255,255,255,.07); border-radius: 5px; padding: 1px 7px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.pv b { color: #8fb4ff; font-weight: 600; }
.pv.na { opacity: .5; }
.rawrow .body .dim { color: #7d8793; margin: 3px 0 0; font-size: 11.5px; }
#f-parser { width: 100%; font: 12.5px/1.45 ui-monospace, Menlo, Consolas, monospace; resize: vertical; }
/* table view, send form */
.rawtable { width: 100%; border-collapse: collapse; font: 12.5px/1.4 ui-monospace, Menlo, Consolas, monospace; }
.rawtable thead th { position: sticky; top: 0; background: #151a21; text-align: left; padding: 5px 10px; border-bottom: 1px solid #2a2f36; white-space: nowrap; font-weight: 600; }
.rawtable th small { color: #8b95a1; font-weight: 400; }
.rawtable td { padding: 2px 10px; border-bottom: 1px solid rgba(255,255,255,.04); white-space: nowrap; max-width: 28em; overflow: hidden; text-overflow: ellipsis; }
.rawtable tr:hover td { background: rgba(255,255,255,.04); }
.rawtable td.num { text-align: right; color: #8b95a1; } .rawtable td.t, .rawtable td.peer { color: #8b95a1; } .rawtable td.na { opacity: .45; }
.rawtable tr.rx .dir { color: #3fb27f; font-weight: 600; } .rawtable tr.tx .dir { color: #e0a73a; font-weight: 600; }
.txform { border-top: 1px solid var(--line, #2a2f36); padding: 6px 10px 8px; }
.txform summary { cursor: pointer; font-weight: 600; padding: 2px 0; }
.txgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px; margin: 8px 0; }
.txf { display: flex; flex-direction: column; gap: 3px; }
.txl small { display: block; color: #8b95a1; font-weight: 400; font-size: 11px; }
.txf input[type=text], .txf input[type=number] { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; }
.txf input[type=checkbox] { width: 20px; height: 20px; margin: 2px 0; }
.txbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.txbar input { flex: 1 1 200px; width: auto; }
.txprev { display: block; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; color: #9aa3ad; margin-top: 6px; word-break: break-all; flex-basis: 100%; }
.txprev.bad { color: #ff7b72; }
.rawsend .txprev { margin: 0; }

/* folder README and files */
.folder-panel { margin-bottom: 12px; padding: 12px 14px; }
.md h2, .md h3, .md h4 { margin: 10px 0 4px; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 6px 0; }
.md pre { background: rgba(127,127,127,.15); padding: 8px; border-radius: 6px; overflow: auto; }
.md code { background: rgba(127,127,127,.15); padding: 0 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid rgba(127,127,127,.5); padding-left: 10px; opacity: .85; }
.ffiles { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.ffile { display: flex; gap: 10px; align-items: center; }
.ffile a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md-table { overflow-x: auto; margin: 6px 0; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid rgba(127,127,127,.4); padding: 4px 10px; }
.md th { background: rgba(127,127,127,.15); }
