:root {
  --bg: #0e1116;
  --bg-soft: #161b22;
  --card: #1a2029;
  --card-2: #20262f;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #2dd4a7;   /* teal-green */
  --accent-dim: #1c7a63;
  --down: #38bdf8;     /* download */
  --up: #fb923c;       /* upload */
  --danger: #f87171;
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* Reserve the vertical scrollbar's space so the 5s auto-refresh can't toggle it
   on/off and shift the whole page sideways. Fallback to always-on for old browsers. */
html { scrollbar-gutter: stable; overflow-y: scroll; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #18202b 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 22px;
  background: rgba(13, 17, 23, .7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { color: var(--accent); font-size: 26px; text-shadow: 0 0 16px var(--accent-dim); }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand-sub { color: var(--muted); font-size: 11px; }

.status { display: flex; gap: 8px; flex-wrap: wrap; margin-left: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line);
  padding: 5px 11px; border-radius: 999px; font-size: 12px; color: var(--muted);
}
.db-size { font-size: 10px; color: var(--muted); align-self: center; opacity: .8; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.stale { background: var(--danger); }

.toggles { margin-left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.windows, .scopes { display: flex; gap: 4px; }
.windows button, .scopes button {
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.windows button:hover, .scopes button:hover { color: var(--text); }
.windows button.active, .scopes button.active { background: var(--accent); color: #06231c; border-color: var(--accent); font-weight: 600; }
.scopes button.active { background: var(--down); }

.kpi.local .kpi-val { color: var(--accent); }
.cc {
  display: inline-block; font-family: var(--mono); font-size: 10px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 0 4px; color: var(--muted); margin-right: 5px; vertical-align: middle;
}

/* ---- layout ---- */
main { padding: 20px 22px 40px; max-width: 1500px; margin: 0 auto; }
.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 14px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }
.dev-meta { color: var(--muted); font-size: 12px; margin-bottom: 12px; font-family: var(--mono); }
.dev-ap { color: var(--accent); font-weight: 600; }
.dev-ap-sm { font-size: 10px; color: var(--accent); opacity: .85; margin-top: 1px; }
.dev-snmp { display: inline-block; margin-left: 7px; padding: 0 5px; font-size: 9px; font-weight: 700; letter-spacing: .4px; line-height: 14px; border-radius: 4px; vertical-align: middle; background: var(--accent); color: #06231c; cursor: help; }
.dev-snmp.other { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); font-weight: 600; }
.wifi-tl-card { margin-bottom: 18px; }
.wifi-tl-wrap { width: 100%; }
.wifi-tl-wrap canvas { display: block; width: 100%; }
.wifi-tl-legend { display: flex; gap: 18px; align-items: center; margin-top: 10px; font-size: 11px; color: var(--muted); }
.sig-key { display: inline-flex; align-items: center; gap: 7px; }
.sig-bar { display: inline-block; width: 90px; height: 8px; border-radius: 4px;
  background: linear-gradient(to right, #e5484d, #e3c84f, #2dd4a7); }
.band-key { display: inline-flex; align-items: center; gap: 6px; }
.band-sw { display: inline-block; width: 26px; height: 9px; border-radius: 2px; vertical-align: middle;
  background-color: #1a2230; }
.band-sw.five { background-image: repeating-linear-gradient(45deg, rgba(205,214,226,.65) 0 2px, transparent 2px 5px); }
.band-sw.twofour { background-image: repeating-linear-gradient(45deg, rgba(205,214,226,.65) 0 2.5px, transparent 2.5px 12px); }
.dev-tabs { display: inline-flex; gap: 3px; }
.dev-tabs button { background: var(--card); color: var(--muted); border: 1px solid var(--line);
  padding: 4px 13px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.dev-tabs button:hover { color: var(--text); }
.dev-tabs button.active { background: var(--accent); color: #06231c; border-color: var(--accent); font-weight: 600; }
.tab-count { opacity: .75; font-size: 11px; margin-left: 2px; }
.tl-tip { position: fixed; z-index: 60; pointer-events: none; background: #11161d;
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; font-size: 12px;
  color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,.5); white-space: nowrap; }
.tl-tip-sub { color: var(--muted); font-size: 11px; }
.wifi-tl-wrap canvas { cursor: grab; }
#cpu-tl { cursor: crosshair; }
#wifi-zoom button { min-width: 26px; font-size: 14px; line-height: 1; padding: 2px 7px; }
.snmp-cov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.snmp-col h3.snmp-h { font-size: 13px; margin: 0 0 8px; font-weight: 600; }
.snmp-h.on { color: var(--accent); }
.snmp-h.off { color: var(--muted); }
.snmp-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.snmp-row { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 6px; font-size: 12px; }
.snmp-row.on { cursor: pointer; }
.snmp-row:hover { background: rgba(255,255,255,.04); }
.snmp-name { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snmp-ip { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.snmp-os { color: var(--accent); opacity: .85; font-size: 11px; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.snmp-stat { font-size: 10px; font-weight: 600; white-space: nowrap; }
.snmp-stat.on { color: var(--accent); }
.snmp-stat.off { color: var(--muted); font-weight: 500; }
.snmp-stat.unknown { color: var(--muted); opacity: .55; font-weight: 500; }
.snmp-list .empty { color: var(--muted); padding: 8px; }
.app-tl-i { flex: 0 0 14px; text-align: center; margin: 0 7px 0 3px; color: var(--accent); opacity: .7; cursor: help; font-style: normal; font-size: 11px; }
.app-tl-i:empty { cursor: default; }
.dns-search { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 5px 11px; font-size: 12px; min-width: 230px; }
.dns-search:focus { outline: none; border-color: var(--accent); }
.dns-dom { font-family: var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* SNMP per-app run/idle timeline (device detail → Running apps) */
.app-tl-axis { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--muted); margin: 2px 0 9px; }
.app-tl-axis .app-tl-t { font-family: var(--mono); white-space: nowrap; }
.app-tl-key { display: inline-flex; align-items: center; gap: 5px; }
.app-tl-key i { width: 13px; height: 9px; border-radius: 2px; display: inline-block; margin-left: 9px; }
.app-tl-key i:first-child { margin-left: 0; }
.app-tl-key .k-run { background: var(--accent); }
.app-tl-key .k-idle { background: var(--card-2); border: 1px solid var(--line); }
.app-tl-key .k-off { background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(139,150,165,.3) 3px 5px); border: 1px solid var(--line); }
.app-tl-list { display: flex; flex-direction: column; gap: 3px; }
.app-tl-row { display: flex; align-items: center; gap: 10px; padding: 3px 4px; border-radius: 6px; }
.app-tl-row:hover { background: rgba(255,255,255,.04); }
.app-tl-name { width: 170px; flex: 0 0 auto; font-family: var(--mono); font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-tl-n { color: var(--muted); font-style: normal; font-size: 11px; margin-left: 6px; }
.app-tl-track { position: relative; flex: 1 1 auto; height: 13px; background: var(--card-2); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.app-tl-seg { position: absolute; top: 0; bottom: 0; background: var(--accent); box-shadow: 0 0 6px var(--accent-dim); }
.app-tl-off { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(139,150,165,.22) 3px 5px); }
@media (max-width: 640px) { .app-tl-name { width: 104px; } }
.head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.metric-toggle { display: inline-flex; gap: 2px; }
.metric-toggle button { background: var(--card); color: var(--muted); border: 1px solid var(--line); padding: 2px 8px; border-radius: 6px; cursor: pointer; font-size: 11px; }
.metric-toggle button:hover { color: var(--text); }
.metric-toggle button.active { background: var(--accent); color: #06231c; border-color: var(--accent); font-weight: 600; }
.chart-box { position: relative; height: 280px; width: 100%; }

.pies { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.apps-wrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.apps-chart-box { position: relative; width: 230px; height: 230px; flex: 0 0 auto; }
.apps-legend { flex: 1 1 240px; display: flex; flex-direction: column; gap: 7px; min-width: 220px; }
.apps-legend .row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.apps-legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.apps-legend .nm { flex: 1 1 auto; }
.apps-legend .by { font-family: var(--mono); color: var(--text); }
.apps-legend .pc { font-family: var(--mono); color: var(--muted); width: 42px; text-align: right; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 4px; }
.kpi { padding: 16px 18px; margin: 0; }
.kpi-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi-val { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.kpi.down .kpi-val { color: var(--down); }
.kpi.up .kpi-val { color: var(--up); }

.grid { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
/* Let grid cards shrink below their content width so a table's nowrap content
   can't inflate the column and make the cards jump sideways each refresh. */
.grid > *, .kpis > *, .pies > * { min-width: 0; }
@media (max-width: 1000px) { .grid, .kpis { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px)  { .grid, .kpis { grid-template-columns: 1fr; } }

/* ---- tables ---- */
.table-wrap { overflow: auto; max-height: 460px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--bg-soft); z-index: 1; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tbody tr { cursor: default; }
#devices tbody tr { cursor: pointer; }
#devices tbody tr:hover { background: var(--card-2); }
#devices tbody tr.selected { background: rgba(45, 212, 167, .12); box-shadow: inset 3px 0 0 var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 28px; }
.dev-name { font-weight: 600; }
.ip { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.bar { height: 4px; border-radius: 3px; background: var(--accent-dim); margin-top: 4px; }

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px;
  font-family: var(--mono); background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
}
.proto-tcp { color: var(--down); } .proto-udp { color: var(--up); } .proto-icmp { color: var(--accent); }

.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 7px; padding: 4px 9px; cursor: pointer; font-size: 12px; }
.ghost:hover { color: var(--text); }
.hidden { display: none !important; }

.sub-section { margin-top: 16px; }
.sub-section h3 { font-size: 12px; color: var(--muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .5px; }

.footer { text-align: center; padding: 10px; }
