:root {
  --bg: #0f1419; --panel: #171e26; --line: #263240; --text: #dce3ea; --muted: #8a99a8;
  --accent: #4ea3ff; --high: #ff5a52; --medium: #f2b33d; --low: #4cc38a; --fix: #c77dff;
}
* { box-sizing: border-box; }
#app { height: 100%; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.small, small { color: var(--muted); font-size: 12px; }
small { display: block; margin-top: 3px; }
code { background: #0b0f13; padding: 1px 4px; border-radius: 3px; }
.err { color: var(--high); min-height: 1em; }
button, .btn { background: var(--accent); color: #fff; border: 0; border-radius: 5px; padding: 6px 12px;
  font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover, .btn.ghost:hover { border-color: var(--accent); }
button.danger { background: transparent; border: 1px solid #5a2a2a; color: var(--high); }
button.sm { padding: 2px 8px; font-size: 12px; }
input, select, textarea { background: #0b0f13; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 6px 8px; font: inherit; }
label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
label input, label textarea, label select { display: block; width: 100%; margin-top: 3px; color: var(--text); font-size: 14px; }
label.inline { display: flex; gap: 6px; align-items: center; }
label.inline input { width: auto; display: inline; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.row h2 { margin: 0; flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.spacer { flex: 1; }

.login { position: fixed; inset: 0; display: grid; place-items: center; }
.login form { background: var(--panel); border: 1px solid var(--line); padding: 28px; border-radius: 10px; width: 320px; }
.login button { width: 100%; margin-top: 6px; }

header { display: flex; align-items: center; gap: 18px; padding: 0 16px; height: 50px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .3px; }
.brand span { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 2px; flex: 1; }
nav button { background: transparent; color: var(--muted); border-radius: 0; padding: 15px 12px;
  border-bottom: 2px solid transparent; }
nav button.active { color: var(--text); border-bottom-color: var(--accent); }
header .right { display: flex; gap: 12px; align-items: center; }
header .right label { margin: 0; display: flex; gap: 5px; align-items: center; }
#pickLoc { margin-bottom: 12px; }
.badge { background: var(--high); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.conn { font-size: 12px; }
.conn.on { color: var(--low); } .conn.off { color: var(--high); }

.tab { padding: 16px; height: calc(100% - 50px); overflow: auto; }
#tab-live { padding: 0; overflow: hidden; }
.live { display: grid; grid-template-columns: 1fr 380px; height: 100%; }
#map { height: 100%; background: #0b0f13; }
.live aside { border-left: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; min-height: 0; }
.feed { flex: 1; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.alert { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 6px; padding: 8px 10px;
  margin-bottom: 8px; background: var(--panel); cursor: pointer; }
.alert.high { border-left-color: var(--high); } .alert.medium { border-left-color: var(--medium); }
.alert.low { border-left-color: var(--low); }
.alert.reviewed { opacity: .55; }
.alert.flash { animation: flash 1.2s ease-out 2; }
@keyframes flash { from { background: #3a1d1d; } to { background: var(--panel); } }
.alert .top { display: flex; justify-content: space-between; gap: 6px; }
.alert .acts { display: flex; gap: 4px; margin-top: 6px; }
.nodestrip { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); border-radius: 12px; padding: 2px 8px; font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.dot.on { background: var(--low); } .dot.off { background: var(--high); } .dot.dis { background: #555; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted); }
.sw { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; }
.sw.high { background: var(--high); } .sw.medium { background: var(--medium); } .sw.low { background: var(--low); }
.sw.fix { background: var(--fix); height: 8px; width: 8px; border-radius: 50%; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--bg); }
.grid tr:hover td { background: #141b22; }
.grid td.num { font-variant-numeric: tabular-nums; }
.sev { font-size: 12px; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.sev.high { background: #4a1f1d; color: #ffb3ad; } .sev.medium { background: #4a3a17; color: #ffd98a; }
.sev.low { background: #173a29; color: #9fe3bf; }
.note { width: 100%; min-width: 140px; padding: 3px 6px; font-size: 12px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; }

.cols { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.tokenbox { margin-top: 12px; background: #0b0f13; border: 1px solid var(--medium); border-radius: 6px;
  padding: 10px; font-size: 12px; word-break: break-all; }
.tokenbox pre { white-space: pre-wrap; margin: 6px 0 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 8px 0 0; border-bottom: 1px solid var(--line); }
.chart .bar { flex: 1; display: flex; flex-direction: column-reverse; height: 100%; position: relative; }
.chart .bar i { display: block; width: 100%; }
.chart .bar i.high { background: var(--high); } .chart .bar i.medium { background: var(--medium); }
.chart .bar i.low { background: var(--low); }
.chart-x { display: flex; gap: 3px; font-size: 10px; color: var(--muted); }
.chart-x span { flex: 1; text-align: center; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 6px; z-index: 2000; }
.picking #map { cursor: crosshair; }
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
#allowForm input { flex: 1; min-width: 0; }
#tab-stats table { margin-bottom: 24px; }
@media (max-width: 900px) {
  header { height: auto; flex-wrap: wrap; gap: 0 12px; padding: 4px 10px; }
  .brand span { display: none; }
  nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  nav button { padding: 8px 8px; white-space: nowrap; }
  .tab { height: calc(100% - 82px); }
  .live, .cols { grid-template-columns: 1fr; }
  .live { grid-template-rows: 55% 45%; }
}
