:root {
  --bg: #0a0912;
  --panel: #14111f;
  --panel-2: #1b1729;
  --line: #2a2440;
  --text: #ece9f7;
  --muted: #9b94b8;
  --accent: #4fd1a5;
  --accent-2: #7c9cff;
  --violet: #a07cff;
  --amber: #f5b941;
  --red: #ff6b7a;
  --ok: #4fd1a5;
  --warn: #f5b941;
  --crit: #ff5d6c;
  --stale: #6f6990;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #1d1440 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 8px; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header */
.top {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: center;
  padding: 18px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000; background: rgba(10, 9, 18, 0.88); backdrop-filter: blur(8px);
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo { width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-items: center; position: relative; }
.logo span { width: 14px; height: 14px; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.logo::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 1px dashed rgba(79, 209, 165, 0.4); animation: spin 18s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
h1 { font-size: 22px; }
h1 small { font-weight: 400; color: var(--muted); font-size: 16px; margin-left: 6px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-right { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.clock { font-family: var(--mono); font-size: 15px; }
.sim-ctrl { display: flex; align-items: center; gap: 4px; }
.sim-ctrl .lbl { margin-right: 4px; }
.sim-ctrl button, .btn-ghost {
  font: inherit; font-size: 12px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.sim-ctrl button.active { border-color: var(--accent); color: var(--accent); }
.btn-ghost:hover, .sim-ctrl button:hover { border-color: var(--accent-2); }
.btn-ghost.live { border-color: var(--accent); color: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 10px 24px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.tabs a:hover { color: var(--text); background: var(--panel-2); }

main { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; max-width: 1500px; margin: 0 auto; }
section { scroll-margin-top: 130px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.k-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.k-val { font-size: 22px; font-weight: 700; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.k-val.good { color: var(--accent); }
.k-sub { font-size: 12px; color: var(--muted); }

/* cards & grids */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.unit { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.chip { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--accent-2); color: var(--accent-2); }
.chip.live { border-color: var(--accent); color: var(--accent); }
.chip.warn { border-color: var(--amber); color: var(--amber); }
.grid { display: grid; gap: 18px; }
.ops { grid-template-columns: 2fr 1fr; }
.tele { grid-template-columns: repeat(2, 1fr); }
.bloom { grid-template-columns: 2fr 1fr; }
.budgets { grid-template-columns: repeat(4, 1fr); }
.budgets .span2 { grid-column: span 4; }
.mission { grid-template-columns: 3fr 2fr; }

.map { height: 420px; border-radius: 10px; overflow: hidden; background: #0d0c16; }
.leaflet-container { background: #0d0c16; font-family: inherit; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.legend i.dash { width: 16px; height: 0; border-top: 2px dashed var(--accent); border-radius: 0; }

.state { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0; }
.state div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.state dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.state dd { margin: 2px 0 0; font-family: var(--mono); font-size: 14px; }
.subs { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.subs li { display: flex; justify-content: space-between; font-size: 13px; background: var(--panel-2); border-radius: 8px; padding: 6px 10px; }
.subs b { font-family: var(--mono); font-weight: 600; font-size: 12px; }
.on { color: var(--accent); }
.off { color: var(--muted); }
.log { list-style: none; padding: 0; margin: 0; max-height: 150px; overflow-y: auto; font-family: var(--mono); font-size: 12px; }
.log li { padding: 4px 0; border-bottom: 1px dashed var(--line); color: var(--muted); }
.log li b { color: var(--text); font-weight: 600; }

.scale { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 10px; flex-wrap: wrap; }
.scale .bar { width: 180px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #1b3a6b, #1f8a7a, #9bd34a, #f5b941, #ff6b7a); }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
td.num, th.num { text-align: right; font-family: var(--mono); }
.table-wrap { overflow-x: auto; }
.alerts { margin: 10px 0 14px; }
.status-ok { color: var(--accent); }
.status-watch { color: var(--amber); }
.status-warn { color: var(--red); font-weight: 700; }
.howto { padding-left: 18px; margin: 0; color: var(--muted); font-size: 13px; }
.howto li { margin-bottom: 6px; }

.timeline { display: flex; height: 46px; border-radius: 10px; overflow: hidden; margin-bottom: 14px; position: relative; }
.timeline .seg { display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #0a0912; padding: 0 6px; text-align: center; overflow: hidden; }
.timeline .cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 8px #fff; }
.matrix td.dot { text-align: center; }
.matrix td.dot span { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--line); }
.matrix td.dot span.y { background: var(--accent); }
.matrix th.mode { text-align: center; }

.filter { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.filter select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.bom tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

.margins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.margin .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.margin .row b { font-family: var(--mono); }
.meter { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 5px; }

.ms { margin: 0; display: grid; gap: 12px; }
.ms dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ms dd { margin: 3px 0 0; }
.team { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.team li { display: flex; gap: 12px; align-items: center; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: linear-gradient(135deg, var(--violet), var(--accent-2)); color: #0a0912; flex: none; }
.team span { display: block; font-size: 12px; color: var(--muted); }

footer { border-top: 1px solid var(--line); padding: 18px 24px 30px; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 1100px) {
  .ops, .bloom, .mission { grid-template-columns: 1fr; }
  .budgets { grid-template-columns: repeat(2, 1fr); }
  .budgets .span2 { grid-column: span 2; }
  .margins { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .top, .tabs, main, footer { padding-left: 16px; padding-right: 16px; }
  .tele, .budgets { grid-template-columns: 1fr; }
  .budgets .span2 { grid-column: span 1; }
  .margins, .subs, .state { grid-template-columns: 1fr; }
  .map { height: 320px; }
  .top { position: static; }
}

.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 280px; }

/* ---------- ground-segment status (Dashboard Design Manual) ---------- */
.mono { font-family: var(--mono); }
.link-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.link-status #pktAge { font-size: 13px; min-width: 64px; }
.pill { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; padding: 4px 10px; border-radius: 999px; border: 1px solid currentColor; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); text-decoration: none; }
.badge.st-warn { background: rgba(245, 185, 65, 0.15); }
.badge.st-crit { background: rgba(255, 93, 108, 0.18); animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { 50% { border-color: transparent; } }

.st-ok { color: var(--ok); }
.st-warn { color: var(--warn); }
.st-crit { color: var(--crit); }
.st-stale, .st-missing { color: var(--stale); }
.st-invalid { color: #d88bff; }

.status-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.status-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.st-legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 0; font-size: 12px; }
.st::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: currentColor; margin-right: 6px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid currentColor; border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tile .t-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile .t-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.tile .t-st { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.tile .t-val { font-family: var(--mono); font-size: 24px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-val small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.tile .t-sub { font-size: 12px; color: var(--muted); min-height: 1.2em; }
.tile .t-lim { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.tile.st-stale .t-val, .tile.st-missing .t-val { color: var(--stale); }
.tile.st-crit { background: linear-gradient(180deg, rgba(255, 93, 108, 0.12), var(--panel) 70%); }
.tile.st-warn { background: linear-gradient(180deg, rgba(245, 185, 65, 0.09), var(--panel) 70%); }
.gauge { position: relative; height: 6px; border-radius: 3px; background: var(--panel-2); margin: 4px 0 2px; overflow: hidden; }
.gauge .zone { position: absolute; top: 0; bottom: 0; }
.gauge .zone.w { background: rgba(245, 185, 65, 0.35); }
.gauge .zone.c { background: rgba(255, 93, 108, 0.45); }
.gauge .zone.n { background: rgba(79, 209, 165, 0.18); }
.gauge .mark { position: absolute; top: -2px; bottom: -2px; width: 3px; margin-left: -1px; background: var(--text); border-radius: 2px; box-shadow: 0 0 6px rgba(255, 255, 255, 0.6); }
.tile.st-stale .gauge .mark, .tile.st-missing .gauge .mark { background: var(--stale); box-shadow: none; }

.health { grid-template-columns: 1fr 1.4fr; }
.alarms { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.alarms li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); border-left: 3px solid currentColor; font-size: 13px; }
.alarms li .lvl { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; }
.alarms li span.msg { color: var(--text); }
.alarms li time { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.alarms li.acked { opacity: 0.6; }
.alarms li.none { color: var(--ok); grid-template-columns: 1fr; }
.alarm-log li .lvl { font-weight: 700; margin-right: 4px; }
.faults { display: flex; flex-wrap: wrap; gap: 6px; }
.faults button[aria-pressed="true"] { border-color: var(--crit); color: var(--crit); background: rgba(255, 93, 108, 0.1); }

.readings td:nth-child(2) { font-family: var(--mono); text-align: right; }
.readings td.lim { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.readings td.age { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.readings td.stc { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.readings td.stc::before { content: "●"; margin-right: 5px; }
.readings tr.st-stale td:nth-child(2), .readings tr.st-missing td:nth-child(2) { color: var(--stale); }

.contract { grid-template-columns: 1.6fr 1fr; }
.contract-table td:first-child { font-family: var(--mono); color: var(--accent); }
.contract-table td.desc { white-space: normal; min-width: 220px; color: var(--muted); }
.pkt { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border-radius: 10px; padding: 12px; overflow-x: auto; margin: 0; line-height: 1.5; color: var(--text); }

@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .health, .contract { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .tiles { gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .t-val { font-size: 19px; }
  .tile .t-lim { display: none; }
  .link-status { width: 100%; }
}
