:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2128;
  --border: #2a323b;
  --text: #e6e9ee;
  --muted: #9aa4b1;
  --accent: #ff9900;      /* colorSnr */
  --blue: #33b5e5;        /* holo blue */
  --green: #00ff52;
  --yellow: #ffeb3b;
  --red: #ff1e1a;
  --cyan: #00ffff;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer; color: var(--text); }
button:hover { border-color: #3b4754; background: #222a33; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #ffad33; }
button.active { border-color: var(--accent); color: var(--accent); }
button.danger { border-color: #7a2a28; color: #ff6b67; }
select, input[type=text], input[type=number], input[type=search] { background: #0f1318; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; color: var(--text); }
input[type=number] { width: 7em; }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.small { font-size: 12px; }
.accent { color: var(--accent); }

#app { display: flex; flex-direction: column; height: 100%; }

/* ---- top bar ---- */
#topbar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
#topbar .brand { font-weight: 700; letter-spacing: .5px; color: var(--accent); white-space: nowrap; }
#topbar .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
#topbar nav { display: flex; gap: 4px; margin-left: auto; }
#topbar nav button { padding: 6px 12px; }
#status { display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--muted); }
#status .dot { width: 9px; height: 9px; border-radius: 50%; background: #555; display: inline-block; margin-right: 6px; vertical-align: middle; }
#status .dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
#status .dot.busy { background: var(--yellow); }
.batt { display: inline-flex; align-items: center; gap: 4px; }
.batt .cell { width: 22px; height: 11px; border: 1px solid var(--muted); border-radius: 2px; position: relative; }
.batt .cell::after { content: ''; position: absolute; right: -4px; top: 3px; width: 2px; height: 5px; background: var(--muted); }
.batt .cell i { display: block; height: 100%; background: var(--green); border-radius: 1px; }
.batt .cell i.low { background: var(--red); }

/* ---- info bar ---- */
#infobar { display: flex; align-items: stretch; gap: 8px; padding: 4px 12px; background: var(--panel); border-bottom: 1px solid var(--border); }
#infobar .imm { flex: 0 0 auto; background: var(--blue); color: #000; font-weight: 700; padding: 4px 10px; border-radius: 4px; font-family: var(--mono); font-size: 13px; white-space: nowrap; }
#infobar .imm.error { background: #cc0000; color: #fff; }
#infobar .btinfo { flex: 1 1 auto; font-family: var(--mono); text-align: left; font-size: 13px; }
#infobar .btinfo.lock { color: var(--green); border-color: #1f5a33; }

/* ---- screens ---- */
#main { position: relative; overflow: hidden; flex: 1 1 auto; min-height: 0; }
.screen { position: absolute; inset: 0; display: none; overflow: auto; }
.screen.active { display: block; }

/* start */
#screen-start { display: none; padding: 24px; }
#screen-start.active { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.start-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; width: min(720px, 100%); }
.tile { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; transition: .15s; }
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile:disabled { opacity: .4; transform: none; }
.tile .ico { font-size: 34px; line-height: 1; }
.tile .cap { font-size: 13px; color: var(--text); }
.connect-card { width: min(720px, 100%); }
.connect-card h2 { margin: 0 0 8px 0; font-size: 16px; }
.connect-card p { margin: 6px 0; color: var(--muted); line-height: 1.4; }

/* spectrum */
#screen-spectrum.active, #screen-measures.active { display: grid; grid-template-columns: 1fr 330px; gap: 8px; padding: 8px; }
@media (max-width: 980px) { #screen-spectrum.active, #screen-measures.active { grid-template-columns: 1fr; grid-template-rows: minmax(300px, 1fr) auto; } }
.spec-area { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.spec-toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.spec-toolbar .sep { flex: 1 1 auto; }
.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 240px; background: #010101; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.pos-overlay { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0,0,0,.55); padding: 10px 24px; border-radius: 12px; display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.pos-overlay b { font-size: 64px; text-shadow: 0 2px 6px #000; }
.pos-overlay span { font-size: 36px; }
.side { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow: auto; }
.side .card { padding: 10px 12px; }
.side h4 { margin: 0 0 6px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.indicator { display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.indicator .head { display: flex; justify-content: space-between; align-items: baseline; }
.indicator .title { color: #c3c3c3; font-size: 14px; }
.indicator .value { font-weight: 700; font-size: 32px; color: #c3c3c3; font-variant-numeric: tabular-nums; }
.indicator canvas { width: 100%; height: 42px; display: block; }
.btn-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.btn-grid.cols2 { grid-template-columns: repeat(2, 1fr); }
.btn-grid.cols3 { grid-template-columns: repeat(3, 1fr); }
.btn-grid.cols8 { grid-template-columns: repeat(8, 1fr); }
.btn-grid button { padding: 6px 4px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 6px; }
.tabs button { padding: 4px 8px; font-size: 12px; border-radius: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.kv b { color: var(--muted); font-weight: 500; }

/* measures */
.meas-area { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.meas-top { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px; }
@media (max-width: 700px) { .meas-top { grid-template-columns: 1fr; } }
.meas-main { padding: 10px 14px; }
.meas-main .head { display: flex; justify-content: space-between; align-items: baseline; }
.meas-main .title { color: var(--accent); font-size: 22px; }
.meas-main .value { color: var(--accent); font-weight: 700; font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.meas-main canvas { width: 100%; height: 56px; display: block; margin-top: 6px; }
.miv-list { display: flex; flex-direction: column; }
.miv { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 4px; cursor: pointer; font-size: 18px; }
.miv:hover { background: var(--panel-2); }
.miv.sel .t { color: #fff; }
.miv .t { color: #bdbdbd; }
.miv .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.miv.divider { border-top: 1px solid #3a3a3a; margin-top: 4px; padding-top: 8px; }
.const-wrap { position: relative; aspect-ratio: 1 / 1; max-height: 320px; background: #000; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.const-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.nit { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; }
.nit .head { font-size: 16px; padding: 6px 8px; border-bottom: 1px solid var(--blue); }
.nit .head .net { color: var(--muted); font-size: 13px; }
.nit ul { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1 1 auto; }
.nit li { padding: 5px 8px; border-bottom: 1px solid #1f262e; }
.nit li .n { font-size: 15px; }
.nit li .p { font-size: 12px; color: var(--muted); }

/* constellation full screen */
#screen-constellation.active { display: grid; grid-template-columns: 1fr 320px; gap: 8px; padding: 8px; }
@media (max-width: 800px) { #screen-constellation.active { grid-template-columns: 1fr; } }
#screen-constellation .const-wrap { max-height: none; height: 100%; aspect-ratio: auto; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; min-width: 320px; max-width: min(92vw, 760px); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.modal header { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 12px 16px; overflow: auto; }
.modal footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.list { display: flex; flex-direction: column; max-height: 60vh; overflow: auto; }
.list button { text-align: left; border-radius: 0; border-width: 0 0 1px 0; background: transparent; padding: 8px 10px; }
.list button:hover { background: var(--panel-2); }
.list button.cur { color: var(--accent); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; }
.toast { background: #222a33; border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
.toast.error { border-color: #7a2a28; color: #ff9a97; }
.progress { height: 8px; background: #222; border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
label.chk { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.debug-log { font-family: var(--mono); font-size: 11px; height: 160px; overflow: auto; background: #0a0c0f; border: 1px solid var(--border); padding: 6px; white-space: pre; }
kbd { font-family: var(--mono); font-size: 11px; background: #222; border: 1px solid #444; border-radius: 3px; padding: 0 4px; }

/* ---- Dish alignment tool -------------------------------------------------- */
.dish-align { --dish-face: #0d1622; --dish-tick: #5b6672; --dish-card: var(--text); gap: 12px; }
.dish-grid { display: flex; gap: 22px; flex-wrap: wrap; align-items: center; justify-content: center; }
.dish-visuals { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dish-compass { display: block; }
.dish-card { font: 700 15px var(--font); }
.dish-az-big { font: 700 20px var(--mono); }
.dish-el-lab { font: 700 14px var(--mono); }
.dish-readout { display: grid; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 10px; flex: 1 1 260px; }
.dish-stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.dish-stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.dish-stat-value { color: var(--accent); font: 700 30px var(--mono); line-height: 1.1; font-variant-numeric: tabular-nums; }
.dish-stat-sub { margin-top: 2px; }
.dish-controls { justify-content: center; margin-top: 4px; }
.dish-controls label { display: inline-flex; align-items: center; gap: 6px; }
.warn { background: color-mix(in srgb, var(--red) 18%, var(--panel)); border: 1px solid var(--red); color: var(--text); border-radius: 8px; padding: 8px 12px; }
@media (max-width: 560px) { .dish-readout { grid-template-columns: 1fr 1fr; } }

/* ---- Waterfall / spectrogram (under the spectrum canvas) ------------------ */
.waterfall-wrap { position: relative; flex: 0 0 34%; min-height: 90px; background: #000; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.waterfall-wrap.hidden { display: none; }
.waterfall-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ---- QoS datalogger ------------------------------------------------------- */
.datalog { min-width: min(88vw, 820px); }
.datalog .datalog-canvas { image-rendering: auto; }
.datalog-stats { gap: 16px; }
.datalog-stat { display: inline-flex; gap: 6px; align-items: baseline; }
.datalog-stat b { font-variant-numeric: tabular-nums; }
.datalog-avail { display: flex; flex-direction: column; gap: 4px; }
.datalog-avail-head { gap: 12px; align-items: baseline; flex-wrap: wrap; }
.datalog-avail .avail-pct { font-variant-numeric: tabular-nums; font-size: 15px; }
.datalog-avail .avail-ok { color: var(--green); }
.datalog-avail .avail-warn { color: var(--yellow); }
.datalog-avail .avail-bad { color: var(--red); }
.datalog-avail .ok-txt { color: var(--green); }
.datalog-avail .warn-txt { color: var(--yellow); }
.datalog-avail .bad-txt { color: var(--red); }
.datalog-events { font-variant-numeric: tabular-nums; }

/* ---- W2.3 pass/fail thresholds + acceptance report ---------------------- */
.miv.ok { box-shadow: inset 3px 0 0 var(--green); }
.miv.warn { box-shadow: inset 3px 0 0 var(--yellow); }
.miv.bad { box-shadow: inset 3px 0 0 var(--red); }
.verdict-badge { padding: 2px 12px; border-radius: 4px; font-weight: 700; letter-spacing: .04em; background: var(--panel-2); border: 1px solid var(--border); }
.verdict-badge.pass { background: color-mix(in srgb, var(--green) 24%, var(--panel)); border-color: var(--green); color: var(--green); }
.verdict-badge.fail { background: color-mix(in srgb, var(--red) 22%, var(--panel)); border-color: var(--red); color: var(--red); }
.accept-table { border-collapse: collapse; width: 100%; }
.accept-table th, .accept-table td { border: 1px solid var(--border); padding: 4px 10px; text-align: left; }
.accept-table tr.ok td { color: var(--green); }
.accept-table tr.warn td { color: var(--yellow); }
.accept-table tr.bad td { color: var(--red); }
.accept-table th { color: var(--muted); font-weight: 600; }

/* ---- LNB health (W2.4) ---------------------------------------------------- */
.lnb-live, .lnb-test { display: flex; flex-direction: column; gap: 6px; }
.lnb-verdict { padding: 6px 10px; border-radius: 6px; font-weight: 600; border: 1px solid var(--border); }
.lnb-verdict.ok { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.lnb-verdict.warn { color: var(--yellow); border-color: color-mix(in srgb, var(--yellow) 40%, var(--border)); }
.lnb-verdict.bad { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.lnb-verdict.idle { color: var(--muted); }
.lnb-fault { color: var(--muted); }
.lnb-steptable { border-collapse: collapse; }
.lnb-steptable td, .lnb-steptable th { border: 1px solid var(--border); padding: 3px 10px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Constellation fault-diagnosis advisor (W2.13) ---- */
.const-advisor { margin-top: 6px; padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--muted); background: var(--panel-2); font-size: 13px; }
.const-advisor.ok { border-left-color: var(--green); }
.const-advisor.info { border-left-color: var(--blue); }
.const-advisor.warn { border-left-color: var(--yellow); }
.const-advisor.bad { border-left-color: var(--red); }

/* ---- Limit-mask alarm + drift monitor (W2.8/W2.10) ---- */
.mask-alarm { font: 700 12px var(--mono); color: var(--muted); }
.mask-alarm.on { color: #fff; background: var(--red); padding: 1px 8px; border-radius: 4px; animation: maskflash 0.8s steps(1) infinite; }
@keyframes maskflash { 50% { background: transparent; color: var(--red); } }
