:root {
  --bg: #0a0f1a;
  --bg-2: #0e1524;
  --panel: #121a2b;
  --panel-2: #172238;
  --line: #1f2b42;
  --line-2: #2a3856;
  --text: #e7edf7;
  --muted: #8693ab;
  --dim: #5d6b85;
  --accent: #14b8a6;
  --accent-2: #2dd4bf;
  --accent-ink: #04211e;
  --blue: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }
code { font-family: var(--mono); font-size: 12.5px; background: #ffffff10; padding: 1px 5px; border-radius: 4px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #3a4c72; background: #1c2944; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 0;
  background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: #ffffff12; color: var(--text); }
.icon-btn.on { color: var(--accent-2); }
.icon-btn.rec-on { color: var(--bad); animation: blink 1s infinite; }
.icon-btn.lg { width: 40px; height: 40px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2); }
.icon-btn:disabled { opacity: .4; cursor: default; }
@keyframes blink { 50% { opacity: .35; } }
input, select { height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg-2); outline: none; width: 100%; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #14b8a62a; }
input[type=date], input[type=time] { color-scheme: dark; }
label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); height: 28px; min-width: 32px; padding: 0 9px;
  border-radius: 6px; cursor: pointer; display: inline-grid; place-items: center; font-weight: 500; font-size: 13px; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px #22c55e22; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 70% -10%, #14b8a61f, transparent 60%), radial-gradient(900px 500px at 0% 110%, #3b82f61a, transparent 60%), var(--bg); }
.login-card { width: min(380px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; display: grid; gap: 16px; box-shadow: 0 30px 80px #0008; }
.login-sub { margin: -8px 0 6px; color: var(--muted); }
.login-err { color: #fca5a5; min-height: 18px; font-size: 13px; }

/* ---------- layout ---------- */
.app{display:flex;flex-direction:column;height:100vh}                    
.topbar { height: 56px; display: flex; align-items: center; gap: 22px; padding: 0 16px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: -.01em; }
.brand b { color: var(--accent-2); font-weight: 700; }
.brand.big { font-size: 24px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 2.5px solid #fff; }
.brand.big .brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.brand.big .brand-mark::after { inset: 8px; border-width: 3px; }
.tabs { display: flex; gap: 4px; }
.tabs button { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 500; position: relative; }
.tabs button:hover { color: var(--text); background: #ffffff0a; }
.tabs button.active { color: var(--text); background: var(--panel-2); }
.badge { background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 6px; line-height: 17px; }
.top-stats { margin-left: auto; display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }
.pill b { color: var(--text); font-weight: 600; }
.banner { background: #f59e0b1f; color: #fcd34d; border-bottom: 1px solid #f59e0b44; padding: 9px 16px; font-size: 13px; }

.views{flex:1;min-height:0;position:relative}
.view { display: none; height: 100%; min-height: 0; }
.view.active { display: grid; }
#view-monitor, #view-playback { grid-template-columns: 290px 1fr; }

/* ---------- sidebar / tree ---------- */
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--dim); }
.search input { padding-left: 34px; }
.filters { display: flex; gap: 6px; }
.filters button { flex: 1; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.filters button.active { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }
.tree { overflow: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.veh { border-radius: 9px; margin-bottom: 2px; }
.veh-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; padding: 8px 8px; border-radius: 9px; cursor: pointer; user-select: none; }
.veh-row:hover { background: #ffffff09; }
.veh.sel .veh-row { background: var(--panel-2); }
.veh-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.veh-sub { color: var(--dim); font-size: 12px; font-family: var(--mono); }
.veh-speed { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.veh.off .veh-name { color: var(--muted); }
.chs { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 8px 10px 33px; }
.ch { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line-2);
  background: var(--panel); color: var(--muted); font-size: 12px; cursor: pointer; font-weight: 500; }
.ch svg { width: 12px; height: 12px; }
.ch:hover { color: var(--text); border-color: var(--accent); }
.ch.playing { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.veh.off .ch { opacity: .45; cursor: not-allowed; }
.tree .empty, .feed .empty { color: var(--dim); text-align: center; padding: 30px 10px; font-size: 13px; }

/* ---------- monitor main ---------- */
.monitor-main { display: grid; grid-template-rows: auto 1fr; min-height: 0; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.hint { color: var(--dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.split { display: grid; grid-template-rows: var(--top, 62%) 6px 1fr; min-height: 0; }
.gutter { cursor: row-resize; background: var(--bg-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.gutter:hover { background: var(--panel-2); }
.grid { display: grid; gap: 4px; padding: 4px; background: #04070d; min-height: 0; }
.grid[data-n="1"] { grid-template: 1fr / 1fr; }
.grid[data-n="4"] { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.grid[data-n="9"] { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.grid[data-n="16"] { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }
.bottom { display: grid; grid-template-columns: 1fr 320px; min-height: 0; }
.map { min-height: 0; background: #0b1220; }
.feed { border-left: 1px solid var(--line); background: var(--bg-2); display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.feed-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--line); }
.feed-list { overflow: auto; }
.feed-item { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; }
.feed-item:hover { background: #ffffff07; }
.feed-item .t { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 13px; }
.feed-item .s { color: var(--muted); font-size: 12px; }
.feed-item.new { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #ef444433; } to { background: transparent; } }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; border-radius: 5px; background: #ffffff14; color: var(--muted); text-transform: uppercase; }
.tag.ADAS { background: #3b82f62e; color: #93c5fd; }
.tag.DSM { background: #a855f72e; color: #d8b4fe; }
.tag.BSD { background: #f59e0b2e; color: #fcd34d; }
.tag.basic { background: #ef44442e; color: #fca5a5; }
.tag.video { background: #14b8a62e; color: #5eead4; }

/* ---------- video tiles ---------- */
.tile { position: relative; background: #05080f; border-radius: 6px; overflow: hidden; min-height: 0; min-width: 0;
  outline: 1px solid #ffffff0d; display: grid; place-items: center; }
.tile.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile canvas, .tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #05080f; position: absolute; inset: 0; }
.tile.gpu canvas { display: none; }
.tile:not(.gpu) video { display: none; }
.tile .ph { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--dim); font-size: 12.5px; padding: 12px; pointer-events: none; }
.tile .ph svg { width: 26px; height: 26px; display: block; margin: 0 auto 6px; opacity: .6; }
.tile .bar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: linear-gradient(#000c, #0000); font-size: 12px; opacity: 1; transition: opacity .2s; }
.tile .bar .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .bar .chn { color: var(--accent-2); font-weight: 700; font-family: var(--mono); font-size: 11.5px; }
.tile .tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 2px; background: #000a; border-radius: 9px; padding: 2px; opacity: 0; transition: opacity .2s; }
.tile .tools .icon-btn { width: 28px; height: 28px; color: #cbd5e1; }
.tile .tools svg { width: 16px; height: 16px; }
.tile:hover .tools, .tile.sel .tools { opacity: 1; }
.tile .stats { position: absolute; left: 8px; bottom: 7px; font-family: var(--mono); font-size: 10.5px; color: #cbd5e1cc; background: #0009; padding: 2px 6px; border-radius: 5px; cursor: pointer; white-space: pre; z-index: 2; }
.tile .stats.diag { background: #000d; color: #e2e8f0; line-height: 1.5; padding: 6px 8px; max-width: calc(100% - 16px); overflow: hidden; }
.tile .state { position: absolute; inset: auto 0 42% 0; text-align: center; font-size: 12.5px; color: #cbd5e1; pointer-events: none; }
.tile .state.err { color: #fca5a5; padding: 0 16px; }
.spin { width: 22px; height: 22px; border: 2.5px solid #ffffff22; border-top-color: var(--accent-2); border-radius: 50%; margin: 0 auto 8px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hdtag { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 4px; border: 1px solid currentColor; line-height: 15px; }
.tile:fullscreen { border-radius: 0; }

/* ---------- map markers ---------- */
.leaflet-container { background: #0b1220; font: inherit; }
.map.dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.88) saturate(.6); }
.vm { width: 30px; height: 30px; display: grid; place-items: center; }
.vm .arrow { width: 26px; height: 26px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; display: grid; place-items: center; box-shadow: 0 2px 8px #0008; }
.vm .arrow::after { content: ""; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 9px solid #fff; transform: translateY(-1px); }
.vm.moving .arrow { background: var(--ok); }
.vm.off .arrow { background: #64748b; }
.vm.alarm .arrow { background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px #ef444433; } }
.vm-label { position: absolute; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap; background: #0a0f1ae6; color: #fff; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 5px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); box-shadow: 0 10px 30px #0009; }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.pop h4 { margin: 0 0 6px; font-size: 14px; }
.pop .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; color: var(--muted); font-size: 12.5px; }
.pop .kv b { color: var(--text); font-weight: 500; }
.pop .acts { display: flex; gap: 6px; margin-top: 10px; }
.leaflet-control-zoom a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { background: #0a0f1acc !important; color: var(--dim) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }

/* ---------- playback ---------- */
.pb-side h3 { margin: 4px 0 0; font-size: 15px; }
.side-note { margin: 0; color: var(--dim); font-size: 12.5px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pb-msg { font-size: 12.5px; color: var(--muted); min-height: 18px; }
.pb-msg.err { color: #fca5a5; }
.files { overflow: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.file { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.file:hover { background: #ffffff08; }
.file.cur { border-color: var(--accent); background: #14b8a612; }
.file .when { font-family: var(--mono); font-size: 12px; }
.file .meta { color: var(--dim); font-size: 11.5px; }
.file .chb { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--accent-2); background: #14b8a61c; border-radius: 5px; padding: 2px 6px; }
.pb-main { display: grid; grid-template-rows: 1fr auto auto; min-height: 0; min-width: 0; background: #04070d; }
.pb-player { padding: 8px; min-height: 0; display: grid; }
.pb-controls { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bg-2); border-top: 1px solid var(--line); }
.pb-pos { display: grid; line-height: 1.2; margin-left: 6px; }
.pb-pos span { font-family: var(--mono); font-size: 17px; font-weight: 500; }
.pb-pos small { color: var(--dim); font-size: 12px; }
.timeline-wrap { background: var(--bg-2); border-top: 1px solid var(--line); padding: 10px 14px 14px; }
.timeline { position: relative; user-select: none; }
.tl-empty { color: var(--dim); text-align: center; padding: 16px; font-size: 13px; }
.tl-axis { position: relative; height: 20px; margin-left: 46px; color: var(--dim); font-size: 10.5px; font-family: var(--mono); }
.tl-axis span { position: absolute; transform: translateX(-50%); top: 2px; }
.tl-lane { display: grid; grid-template-columns: 46px 1fr; align-items: center; height: 26px; }
.tl-lane > b { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 600; }
.tl-track { position: relative; height: 18px; background: #ffffff08; border-radius: 4px; cursor: pointer; overflow: hidden;
  background-image: repeating-linear-gradient(90deg, #ffffff0d 0 1px, transparent 1px calc(100% / 24)); }
.tl-seg { position: absolute; top: 2px; bottom: 2px; background: var(--accent); border-radius: 3px; opacity: .85; }
.tl-seg.alarm { background: var(--bad); }
.tl-track:hover .tl-seg { opacity: 1; }
.tl-head { position: absolute; top: 18px; bottom: 0; width: 2px; background: #fff; margin-left: 46px; pointer-events: none; box-shadow: 0 0 6px #fff8; }
.tl-hover { position: absolute; top: -2px; transform: translateX(-50%); background: #000; color: #fff; font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 4px; pointer-events: none; margin-left: 46px; }

/* ---------- pages ---------- */
.page { padding: 20px 24px; overflow: auto; height: 100%; }
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); white-space: nowrap; position: sticky; top: 0; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #ffffff05; }
.table .mono { font-family: var(--mono); font-size: 12.5px; }
.table .muted { color: var(--muted); }
.table .empty td { text-align: center; color: var(--dim); padding: 34px; }
.status { display: inline-flex; align-items: center; gap: 7px; }
.connect-card { background: linear-gradient(135deg, #14b8a614, #3b82f60d); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.connect-card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.connect-card p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.kvs { display: flex; flex-wrap: wrap; gap: 10px; }
.kvs div { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.kvs small { display: block; color: var(--dim); font-size: 11.5px; }
.kvs b { font-family: var(--mono); font-weight: 500; }

/* ---------- dialog & toasts ---------- */
.dialog { border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); color: var(--text); padding: 22px; width: min(400px, calc(100vw - 32px)); }
.dialog::backdrop { background: #000a; }
.dialog form { display: grid; gap: 14px; }
.dialog h3 { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 5000; }
.toast { background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: 0 12px 30px #0009;
  max-width: 360px; font-size: 13px; animation: tin .25s ease-out; }
.toast.bad { border-left-color: var(--bad); }
.toast.alarm { border-left-color: var(--bad); cursor: pointer; }
.toast b { display: block; margin-bottom: 2px; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .bottom { grid-template-columns: 1fr; }
  .feed { display: none; }
  .top-stats { display: none; }
}
@media (max-width: 800px) {
  #view-monitor, #view-playback { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .tabs button { padding: 0 9px; font-size: 13px; }
  .tabs button svg { display: none; }
  .hint { display: none; }
  .brand span:last-child { display: none; }
}
