:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1f2630; --line: #2b3440;
  --text: #e6edf3; --muted: #8b949e; --accent: #2f81f7; --ok: #3fb950;
  --warn: #d29922; --bad: #f85149;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }
button, select, input { font: inherit; color: var(--text); }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button.ghost { background: transparent; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px; flex: none; }
.dot.on { background: var(--ok); }
.dot.warn { background: var(--warn); }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; color: var(--muted); }

/* layout */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .3px; }
#nav { display: flex; gap: 4px; }
#nav button { border: none; background: transparent; color: var(--muted); }
#nav button.active { color: var(--text); background: var(--panel2); }
.stats { display: flex; gap: 14px; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); }
.user { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.view { flex: 1; min-height: 0; }

/* live */
.live { display: flex; }
.sidebar { width: 290px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; padding: 10px; gap: 8px; }
.sidebar input[type=search] { width: 100%; }
.tree-actions { color: var(--muted); font-size: 13px; }
.tree { overflow-y: auto; overflow-x: hidden; flex: 1; font-size: 13px; padding-right: 2px; }
.tree details { margin: 0; }
.tree summary { cursor: pointer; padding: 0 6px 0 2px; min-height: 30px; border-radius: 6px; display: flex; align-items: center; gap: 6px; list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover, .tree .cam:hover { background: var(--panel2); }
.tree .lt-chev { display: inline-flex; width: 14px; color: var(--muted); transition: transform .15s; flex: none; }
.tree .lt-chev svg { width: 12px; height: 12px; }
.tree details[open] > summary .lt-chev { transform: rotate(90deg); color: var(--text); }
.tree .lt-ico { color: var(--muted); }
.tree .lt-ico.on { color: var(--ok); }
.tree .lt-ico.warn { color: var(--warn); }
.tree .lt-ico.off { color: var(--bad); }
.tree .lt-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.tree .lt-count { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }
.tree .lt-kids { margin-left: 9px; padding-left: 8px; border-left: 1px dashed var(--line); }
.tree .lt-region { margin-bottom: 6px; }
.tree .lt-region > summary { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text); background: var(--panel2); }
.tree .lt-region > summary .lt-ico { color: var(--accent); }
.tree .lt-site > summary { font-weight: 600; }
.tree .play { margin-left: 4px; padding: 0 6px; font-size: 11px; opacity: .6; }
.tree summary:hover .play { opacity: 1; }
.tree .cam { display: flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 6px 0 4px; cursor: pointer; border-radius: 6px; }
.tree .cam.off .lt-name { color: var(--muted); }
.tree .count { color: var(--muted); font-size: 11px; }
.wall { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.wall-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.spacer { flex: 1; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 4px 9px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.active { background: var(--accent); border-color: var(--accent); }
.tour { color: var(--muted); display: flex; gap: 4px; align-items: center; }
.grid { flex: 1; display: grid; gap: 3px; padding: 3px; background: #000; min-height: 0; }
.tile { position: relative; background: #05070a; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile .label { position: absolute; left: 0; right: 0; top: 0; padding: 4px 8px; font-size: 12px; background: linear-gradient(#000c, #0000); display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; pointer-events: none; }
.tile.empty { border: 1px dashed #1c232c; }
.tile:hover { outline: 1px solid var(--accent); outline-offset: -1px; cursor: zoom-in; }

/* fullscreen */
.fullscreen { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.fs-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--panel); }
.fs-tile { flex: 1; display: grid; min-height: 0; }
.fs-tile .tile:hover { outline: none; cursor: default; }
.fs-bar { gap: 10px; flex-wrap: wrap; }
.fs-bar #fs-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* tile buttons (shown on hover) */
.tile .tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tools, .tile:focus-within .tools { opacity: 1; }
.tile .tools button { padding: 3px 8px; font-size: 12px; background: #000b; }
@media (hover: none) { .tile .tools { opacity: 1; } }
/* playback */
.pb-panel { background: var(--panel); padding: 8px 12px 6px; display: grid; gap: 6px; }
.pb-controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pb-timeline { position: relative; height: 26px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; overflow: hidden; }
.pb-timeline .rec { position: absolute; top: 0; bottom: 0; background: #2f81f799; }
.pb-timeline .cursor { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--warn); pointer-events: none; }
.pb-timeline .hover { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--text); pointer-events: none; opacity: .5; }
.pb-hours { position: relative; height: 14px; font-size: 10px; color: var(--muted); }
.pb-hours span { position: absolute; transform: translateX(-50%); }

/* health */
.health, .admin { overflow: auto; padding: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .k { color: var(--muted); font-size: 12px; }
.card.bad .v { color: var(--bad); } .card.warn .v { color: var(--warn); }
.health-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.panel h2 { font-size: 15px; margin: 0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.wrap { white-space: normal; }
.events { max-height: 70vh; overflow: auto; font-size: 13px; }
.ev { padding: 6px 4px; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.ev .t { color: var(--muted); font-size: 11px; }
.ev.critical { border-left: 3px solid var(--bad); padding-left: 8px; }
.ev.warning { border-left: 3px solid var(--warn); padding-left: 8px; }
.ev.info { border-left: 3px solid var(--ok); padding-left: 8px; }

/* admin */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); }
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.row-actions { display: flex; gap: 4px; }
.row-actions button { padding: 3px 8px; font-size: 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; }
.modal-card h3 { margin: 0 0 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.form label.full { grid-column: 1 / -1; }
.form .check { display: flex; gap: 6px; align-items: center; }
.multi { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px; display: grid; gap: 2px; }
.form .field { display: grid; gap: 4px; color: var(--muted); font-size: 12px; grid-column: 1 / -1; }
.tp-wrap { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); }
.tp-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tp-search { flex: 1; min-width: 160px; display: flex !important; align-items: center; gap: 6px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--muted) !important; }
.tp-search:focus-within { border-color: var(--accent); }
.tp-search-in { border: 0 !important; background: transparent !important; outline: none; padding: 7px 0 !important; flex: 1; min-width: 0; }
.tp-tool { padding: 5px 10px !important; font-size: 12px; border-radius: 8px; background: var(--panel); color: var(--muted) !important; }
.tp-tool:hover { color: var(--text) !important; border-color: var(--accent); }
.tp-tree { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.tp-group { flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.tp-kids { margin-left: 22px; border-left: 1px dashed var(--line); padding: 2px 0 4px 6px; }
.tp-row { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 10px 0 6px; border-radius: 6px; cursor: default; color: var(--text); font-size: 13px; transition: background .12s; }
.tp-row.kids { cursor: pointer; }
.tp-row:hover { background: var(--panel2); }
.tp-row.lvl0 { min-height: 44px; }
.tp-row.lvl2 { min-height: 32px; font-size: 12.5px; }
.tp-row.all .tp-ico, .tp-row.some .tp-ico { color: var(--accent); }
.tp-row.all.lvl2 { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.tp-chev { display: inline-flex; width: 16px; color: var(--muted); transition: transform .15s; flex: none; }
.tp-chev.hide { visibility: hidden; }
.tp-row.open .tp-chev { transform: rotate(90deg); color: var(--text); }
.ico { display: inline-flex; flex: none; }
.tp-ico { color: var(--muted); }
.tp-check { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; flex: none; }
.tp-text { display: flex; align-items: baseline; gap: 8px; flex: 1; min-width: 0; }
.tp-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl0 .tp-title { font-weight: 700; }
.tp-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tp-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); white-space: nowrap; flex: none; }
.tp-badge.all { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tp-badge.some { background: color-mix(in srgb, var(--accent) 18%, transparent); color: #79b8ff; }
.tp-badge.plain { background: transparent; }
.tp-empty { padding: 18px; text-align: center; color: var(--muted); }
.tp-foot { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 6px; }
.tp-foot-h { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tp-count { text-transform: none; letter-spacing: 0; color: var(--text); }
.tp-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 84px; overflow: auto; }
.tp-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12px; color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tp-chip.all { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.tp-chip svg { width: 13px; height: 13px; color: var(--muted); }
.tp-chip em { font-style: normal; color: var(--muted); }
.tp-chip em::before { content: "· "; }
.tp-none { font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 70; max-width: 90vw; }

@media (max-width: 900px) {
  .live { flex-direction: column; }
  .sidebar { width: 100%; max-height: 35vh; border-right: none; border-bottom: 1px solid var(--line); }
  .health-cols { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .stats { display: none; }
}

td.bad { color: var(--bad); font-weight: 600; cursor: help; }

/* loading indicators */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; overflow: hidden; opacity: 0; transition: opacity .2s; pointer-events: none; }
.progress.on { opacity: 1; }
.progress div { position: absolute; top: 0; bottom: 0; width: 35%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: progress-run 1.1s ease-in-out infinite; }
@keyframes progress-run { from { left: -35%; } to { left: 100%; } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; flex: none; }
.spin.big { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--muted); justify-content: center; }
.page-loader { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); }
button.loading { position: relative; color: transparent !important; pointer-events: none; }
button.loading::after { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -9px 0 0 -9px; border: 2px solid currentColor; border-color: var(--text) var(--text) var(--text) transparent; border-radius: 50%; animation: spin .8s linear infinite; }
button:disabled { opacity: .6; cursor: default; }
.tp-badge:empty { display: none; }
.tp-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin: 2px 8px 8px 46px; }
.tp-tile { display: flex !important; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; transition: border-color .12s, background .12s; min-width: 0; }
.tp-tile:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.tp-tile.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.tp-tile.on .tp-ico { color: var(--accent); }
.tp-tile-t { display: grid; min-width: 0; line-height: 1.25; }
.tp-tile-n { color: var(--text); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-tile-c { color: var(--muted); font-size: 11px; }

/* live tree: what is on the wall */
.tree summary, .tree .cam { min-width: 0; }
.tree .lt-live { font-size: 10px; font-weight: 700; letter-spacing: .04em; color: var(--accent); white-space: nowrap; flex: none; }
.tree .lt-live:empty { display: none; }
.tree summary.active { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 2px 0 0 var(--accent); }
.tree summary.active .lt-live { color: #fff; background: var(--bad); padding: 1px 6px; border-radius: 4px; }
.tree summary.partial .lt-live { color: var(--accent); font-weight: 600; }
.tree .play { width: 26px; height: 22px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.tree .play.on { opacity: 1; background: var(--accent); border-color: var(--accent); color: #fff; }
.tree .play.on:hover { background: var(--bad); border-color: var(--bad); }
.tree .play.on:hover .eq { display: none; }
.tree .play.on:hover::after { content: "■"; font-size: 11px; }
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 11px; }
.eq i { width: 3px; height: 6px; border-radius: 1px; background: #fff; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .2s; } .eq i:nth-child(3) { animation-delay: .4s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 11px; } }
.tree .cam.playing { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tree .cam.playing .lt-name { color: var(--text); font-weight: 600; }
.tree .cam.playing::after { content: "● LIVE"; margin-left: auto; font-size: 9.5px; font-weight: 700; color: var(--bad); letter-spacing: .04em; }
.tree .cam.onwall::after { content: "on wall"; margin-left: auto; font-size: 10px; color: var(--muted); }

/* export: clip / long download */
.pb-arrow { color: var(--muted); }
.pb-dl { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.pb-dl select { padding: 5px 6px; }
#ex-len { font-size: 12px; white-space: nowrap; }
.pb-timeline .sel { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--warn) 35%, transparent); border-left: 2px solid var(--warn); border-right: 2px solid var(--warn); pointer-events: none; }
#ex-badge, #dl-badge { font-size: 10px; background: var(--ok); color: #000; border-radius: 999px; padding: 0 6px; }
#ex-badge:empty, #dl-badge:empty { display: none; }
#ex-badge.busy, #dl-badge.busy { background: var(--accent); color: #fff; }
.dl-list { display: grid; gap: 8px; max-height: 60vh; overflow: auto; }
.dl-row { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.dl-row.done { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.dl-row.error { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.dl-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.dl-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-sub, .dl-status { font-size: 11.5px; color: var(--muted); }
.dl-row.error .dl-status { color: var(--bad); }
.dl-row.done .dl-status { color: var(--ok); }
.dl-act { display: flex; gap: 6px; align-items: center; }
a.btn { display: inline-block; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); text-decoration: none; color: var(--text); background: var(--panel2); }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dl-bar { height: 6px; background: var(--panel2); border-radius: 999px; overflow: hidden; position: relative; }
.dl-bar div { height: 100%; background: var(--accent); transition: width .4s; }
.dl-bar.indet div { position: absolute; animation: progress-run 1.2s ease-in-out infinite; }
