:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #18233a;
  --line: #26334d;
  --text: #e6edf7;
  --muted: #93a3bd;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #eab308;
  --alert: #f97316;
  --danger: #ef4444;
  --unknown: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap;
  padding: 16px 24px;
  background: linear-gradient(90deg, #0e1a2e, #132542);
  border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.brand .code { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.head-right { display: flex; align-items: center; gap: 12px; }
#clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

button {
  background: var(--accent); color: #06263a; border: 0; border-radius: 6px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; font-size: 14px;
}
button:hover { filter: brightness(1.08); }

.tabs {
  display: flex; gap: 4px; padding: 0 16px; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tab {
  background: transparent; color: var(--muted); border-radius: 0;
  border-bottom: 2px solid transparent; padding: 12px 16px; white-space: nowrap;
  font-weight: 500;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 20px 24px 60px; max-width: 1500px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

h2 { font-size: 17px; margin: 28px 0 8px; }
h3 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 14px; max-width: 90ch; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px;
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .7px; }
.card .value { font-size: 25px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card.warn { border-color: var(--warn); }
.card.danger { border-color: var(--danger); }

.wave-line { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding: 10px 0 4px; }
.wave-node {
  min-width: 132px; flex: 1; text-align: center;
  padding: 12px 8px; border-radius: 10px; margin-right: 6px;
  background: var(--panel); border: 1px solid var(--line); position: relative;
}
.wave-node .dot { width: 14px; height: 14px; border-radius: 50%; margin: 0 auto 8px; }
.wave-node .n { font-size: 12px; color: var(--muted); }
.wave-node .lvl { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.wave-node .tt { font-size: 11px; color: var(--muted); margin-top: 5px; }
.wave-node .seed { color: var(--warn); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 12px;
     text-transform: uppercase; letter-spacing: .5px; }
tbody tr:hover { background: rgba(56, 189, 248, .05); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }

.alert-item {
  border-left: 4px solid var(--line); background: var(--panel);
  border-radius: 0 8px 8px 0; padding: 11px 14px; margin-bottom: 8px;
}
.alert-item .t { font-weight: 650; }
.alert-item .m { color: var(--muted); font-size: 13px; margin-top: 3px; }

#maplibre { height: 68vh; min-height: 420px; border-radius: 10px; border: 1px solid var(--line); }

.chart-controls { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
select, input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 14px; min-width: 150px;
}
/* A fixed-height box lets Chart.js run with maintainAspectRatio off, which is
   what makes it size correctly when the panel was hidden at creation time. */
.chart-box {
  height: 300px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; margin-bottom: 8px;
}
canvas { width: 100% !important; height: 100% !important; }

.form-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .wide input { width: 100%; }
.result { margin-top: 10px; font-size: 13px; }
.result.ok { color: var(--ok); }
.result.err { color: var(--danger); }

.threshold-group { background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.threshold-group .st { font-weight: 650; margin-bottom: 6px; }
.threshold-row { display: flex; gap: 10px; align-items: baseline; font-size: 13px; padding: 3px 0; flex-wrap: wrap; }
.threshold-row .src { color: var(--muted); font-size: 12px; }
td .src { color: var(--muted); font-size: 12px; }

footer {
  padding: 18px 24px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; max-width: 90ch;
}

@media (max-width: 640px) {
  main { padding: 16px 12px 48px; }
  header { padding: 12px 14px; }
}
