/* UniFi-style dark console: icon rail, top bar, filter panel, dense tables */
:root {
  --bg: #1b1c20; --panel: #212226; --raised: #27282d; --rail: #141518; --top: #18191c;
  --line: #2c2e33; --line-soft: #26272c;
  --fg: #dcdee2; --fg-strong: #f2f3f5; --muted: #8f939b; --faint: #5d6169;
  --blue: #4797ff; --blue-strong: #006fff; --blue-bg: rgba(71,151,255,.14);
  --ok: #38c26c; --crit: #f0444b; --high: #ff8b2b; --med: #f2c12e; --low: #7e838c;
  --font: "Lato", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--blue); text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { float: right; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* sign-in */
.signin { height: 100%; display: grid; place-items: center; padding: 16px; }
.signin-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 36px 32px; width: min(380px, 100%); text-align: center; display: grid; gap: 14px; justify-items: center; }
.signin-card h1 { margin: 0; font-size: 22px; color: var(--fg-strong); }
.signin-card p { margin: 0; }
.brand-mark { width: 52px; height: 52px; border-radius: 12px; background: var(--blue-strong) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 6l8 3v6c0 5-3.4 9.3-8 11-4.6-1.7-8-6-8-11V9z' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E") center/70% no-repeat; }

/* shell */
.app { display: grid; grid-template-columns: 56px 1fr; grid-template-rows: 56px 1fr; height: 100%; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 0; background: var(--top); border-bottom: 1px solid var(--line); padding-right: 16px; min-width: 0; }
.console { display: flex; align-items: center; gap: 10px; padding: 0 20px 0 22px; height: 100%; font-weight: 700; color: var(--fg-strong); border-right: 1px solid var(--line); white-space: nowrap; }
.section-tab { display: flex; align-items: center; gap: 9px; padding: 0 20px; height: 100%; background: var(--panel); color: var(--blue); font-size: 17px; border-right: 1px solid var(--line); white-space: nowrap; }
.tab-ico svg { width: 22px; height: 22px; display: block; }
.wordmark { flex: 1; text-align: center; color: var(--faint); font-weight: 700; letter-spacing: .12em; font-size: 15px; }
.top-right { display: flex; align-items: center; gap: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue-strong); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.pill { border: 1px solid var(--line); background: var(--raised); border-radius: 999px; padding: 4px 11px 4px 9px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--low); flex: none; }
.dot.ok { background: var(--ok); } .dot.off { background: var(--high); }
.dot.Critical { background: var(--crit); } .dot.High { background: var(--high); } .dot.Medium { background: var(--med); } .dot.Low { background: var(--low); }

.rail { background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail a { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); }
.rail a:hover { color: var(--fg-strong); background: var(--raised); }
.rail a.on { color: var(--blue); background: var(--blue-bg); }
.rail svg { width: 22px; height: 22px; }
.rail-spacer { flex: 1; }

.main { overflow: auto; min-width: 0; position: relative; }
.page { padding: 20px 24px 40px; }
.page-full { padding: 0; height: 100%; position: relative; }
.page-split { padding: 0; display: grid; grid-template-columns: 290px 1fr; height: 100%; }

/* cards */
.dash { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; min-width: 0; }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; }
.card-h { font-weight: 700; color: var(--fg-strong); margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card-h .right { margin-left: auto; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--raised); border-radius: 6px; padding: 12px 14px; cursor: pointer; border: 1px solid transparent; }
.kpi:hover { border-color: var(--line); }
.kpi .n { font-size: 28px; font-weight: 700; color: var(--fg-strong); font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .l { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 13px; }
.bar .track { grid-column: 1 / -1; height: 4px; background: var(--raised); border-radius: 2px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--blue); border-radius: 2px; }
.bar .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
canvas#timeline { width: 100%; display: block; }
.legend { font-weight: 400; font-size: 12px; color: var(--muted); display: inline-flex; gap: 12px; margin-left: auto; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.grid th { text-align: left; font-weight: 700; color: var(--fg-strong); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.card .grid th { background: var(--panel); }
.grid th.sorted { color: var(--blue); }
.sortable th { cursor: pointer; user-select: none; }
.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.grid tr.row { cursor: pointer; }
.grid tr.row:hover td { background: var(--raised); }
.grid tr.sel td { background: var(--blue-bg); }
.grid tr.dim td { color: var(--faint); }
.grid td.num { font-variant-numeric: tabular-nums; text-align: right; }
.grid .mono, .mono { font-family: var(--mono); font-size: 12.5px; }
.grid .wrap { white-space: normal; max-width: 420px; }
#threat-table { width: max-content; min-width: 100%; }
#threat-table td { white-space: nowrap; }
#threat-table td.why-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.grid .nowrap { white-space: nowrap; }
.grid tr.group td { background: var(--rail); color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.risk { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.risk.Critical { background: rgba(240,68,75,.16); color: #ff7378; }
.risk.High { background: rgba(255,139,43,.16); color: #ffa45c; }
.risk.Medium { background: rgba(242,193,46,.14); color: #f5cf5a; }
.risk.Low { background: rgba(126,131,140,.18); color: #a9adb4; }
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.tag { display: inline-block; background: var(--raised); border-radius: 4px; padding: 1px 7px; font-size: 12px; margin: 1px 3px 1px 0; white-space: nowrap; }

/* buttons, forms */
.btn { border: 1px solid var(--line); background: var(--raised); border-radius: 6px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3a3d44; color: var(--fg-strong); }
.btn.primary { background: var(--blue-strong); border-color: var(--blue-strong); color: #fff; }
.btn.danger { background: #b9262c; border-color: #b9262c; color: #fff; }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 34px; height: 34px; border: 0; background: transparent; border-radius: 6px; display: grid; place-items: center; cursor: pointer; color: var(--fg); }
.icon-btn:hover { background: var(--raised); }
.icon-btn svg { width: 18px; height: 18px; }
input:not([type]), input[type=text] { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 11px; color: var(--fg-strong); font: inherit; min-width: 0; }
input:not([type]):focus { border-color: var(--blue); outline: none; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.inline-form input { flex: 1 1 200px; }

/* filter panel */
.filters { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 24px; display: grid; align-content: start; gap: 4px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; margin-bottom: 10px; }
.search input { border: 0 !important; background: transparent !important; padding: 8px 0 !important; flex: 1; }
.ico-search { width: 14px; height: 14px; border: 2px solid var(--muted); border-radius: 50%; position: relative; flex: none; }
.ico-search::after { content: ""; position: absolute; width: 6px; height: 2px; background: var(--muted); right: -6px; bottom: -3px; transform: rotate(45deg); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; font-weight: 700; font-size: 13px; color: var(--fg-strong); gap: 12px; }
.toggle-row.big { font-weight: 400; font-size: 14px; }
.switch { position: relative; width: 34px; height: 18px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: #3a3c42; border-radius: 999px; transition: background .15s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + i { background: var(--blue-strong); }
.switch input:checked + i::after { transform: translateX(16px); }
.fgroup { border-top: 1px solid var(--line); padding: 12px 0 8px; margin-top: 6px; }
.fgroup-h { font-weight: 700; font-size: 13px; color: var(--fg-strong); margin-bottom: 6px; display: flex; justify-content: space-between; cursor: pointer; }
.fgroup-h::after { content: ""; width: 7px; height: 7px; border-left: 1.5px solid var(--muted); border-top: 1.5px solid var(--muted); transform: rotate(45deg); margin: 5px 4px 0 0; }
.fgroup.closed .fgroup-h::after { transform: rotate(225deg); margin-top: 0; }
.fgroup.closed .fopts { display: none; }
.fopt { display: flex; align-items: center; gap: 10px; padding: 5px 0; cursor: pointer; font-size: 14px; }
.fopt input { appearance: none; width: 16px; height: 16px; border: 1.5px solid #5d6169; border-radius: 3px; margin: 0; flex: none; cursor: pointer; }
.fopt input:checked { background: var(--blue-strong) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E") center/12px no-repeat; border-color: var(--blue-strong); }
.fopt .cnt { color: var(--muted); }
.fopt span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.range-label { text-align: right; margin-bottom: 2px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; margin: 0; height: 20px; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: var(--blue-strong); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 3px; background: var(--blue-strong); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; margin-top: -5.5px; box-shadow: 0 0 0 3px rgba(0,111,255,.35); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 3px rgba(0,111,255,.35); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 2px; }
.ticks.abs { position: relative; height: 16px; margin: 0 7px; }
.ticks.abs span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks.abs span:first-child { transform: none; } .ticks.abs span:last-child { transform: translateX(-100%); }
.list-area { min-width: 0; min-height: 0; padding: 4px 16px 12px; display: flex; flex-direction: column; overflow: hidden; }
.list-area .table-wrap { flex: 1; min-height: 0; overflow: auto; }
.list-head { padding: 10px 2px 4px; }
#f-clear { margin-top: 12px; }

/* map */
#map { position: absolute; inset: 0; background: #0f1012; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92) saturate(.35); }
.leaflet-container { font-family: var(--font); }
.leaflet-control-zoom a { background: var(--panel) !important; color: var(--fg) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { background: rgba(20,21,24,.75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--blue) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--fg); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; min-width: 220px; }
.pop-h { font-weight: 700; color: var(--fg-strong); font-size: 14px; margin-bottom: 6px; }
.pop-ip { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-top: 1px solid var(--line-soft); }
.map-filters { position: absolute; top: 14px; left: 60px; z-index: 500; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: rgba(33,34,38,.92); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.chip.off { opacity: .45; }
.map-stats { position: absolute; top: 14px; right: 14px; z-index: 500; background: rgba(33,34,38,.92); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 13px; min-width: 190px; }
.map-stats .big { font-size: 22px; font-weight: 700; color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.player { position: absolute; left: 16px; right: 16px; bottom: 16px; z-index: 500; background: rgba(33,34,38,.95); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px 10px; }
.player-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.player-time { display: grid; flex: 1; min-width: 150px; }
.player-time strong { color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--blue-strong); color: #fff; }
#play { background: var(--blue-strong); color: #fff; border-radius: 50%; }
.slider-box { position: relative; height: 46px; }
.slider-box canvas { position: absolute; left: 7px; right: 7px; top: 0; height: 30px; width: calc(100% - 14px); }
.slider-box input { position: absolute; left: 0; right: 0; bottom: 0; }
.pulse-icon { pointer-events: none; }
.pulse-icon i { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; border: 2px solid currentColor; animation: pulse 1.4s ease-out forwards; }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pulse-icon i { animation: none; opacity: 0; } }

/* drawer */
.drawer { position: fixed; top: 56px; right: 0; bottom: 0; width: min(460px, 100%); background: var(--panel); border-left: 1px solid var(--line); z-index: 900; display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(0,0,0,.35); }
.drawer-h { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 18px 10px; gap: 10px; }
.drawer-title { font-size: 18px; font-weight: 700; color: var(--fg-strong); font-family: var(--mono); overflow-wrap: anywhere; }
.drawer-tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.drawer-tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.drawer-tabs button.on { color: var(--blue); border-bottom-color: var(--blue); }
.drawer-body { overflow-y: auto; padding: 16px 18px 30px; display: grid; gap: 16px; align-content: start; }
.scorebar { height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; }
.scorebar i { display: block; height: 100%; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.why { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.hist-item { border-bottom: 1px solid var(--line-soft); padding-bottom: 10px; display: grid; gap: 4px; font-size: 13px; }
.hist-item code { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; display: block; }

/* tooltips */
.tip { position: fixed; z-index: 4000; background: #2e3036; color: var(--fg-strong); border: 1px solid #3a3d44; border-radius: 6px; padding: 7px 10px; font-size: 12.5px; line-height: 1.4; max-width: 300px; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,.45); }
[data-tip] { cursor: help; }
button[data-tip], a[data-tip], .kpi[data-tip], .chip[data-tip], .pill[data-tip], th[data-tip], .seg[data-tip], input[type=range][data-tip] { cursor: pointer; }
input:not([type])[data-tip] { cursor: text; }

/* modal, toasts */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: min(440px, 100%); display: grid; gap: 12px; }
.modal-card h3 { margin: 0; color: var(--fg-strong); }
.modal-card p { margin: 0; color: var(--fg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 3000; }
.toast { background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--ok); padding: 10px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { border-left-color: var(--crit); }
.footnote { margin-top: 20px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

@media (max-width: 1000px) {
  .dash { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page-split { grid-template-columns: 1fr; height: auto; } .list-area { overflow: visible; } .list-area .table-wrap { max-height: 75vh; } .filters { border-right: 0; border-bottom: 1px solid var(--line); }
  .wordmark, .updated { display: none; } .console { padding: 0 12px; }
  .section-tab { font-size: 15px; padding: 0 12px; }
}
@media (max-width: 600px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; }
  .rail { flex-direction: row; justify-content: space-around; padding: 6px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .rail-spacer { display: none; }
  .console span:last-child { display: none; }
  .page { padding: 14px 16px 30px; }
  .page-full { height: calc(100vh - 110px); }
  .drawer { top: 0; }
}
