:root {
  color-scheme: dark;
  --bg: #071018;
  --bg-deep: #040a0f;
  --bg-elevated: #0b1721;
  --panel: rgba(15, 31, 43, 0.94);
  --panel-soft: rgba(20, 42, 56, 0.74);
  --panel-strong: rgba(8, 23, 32, 0.98);
  --line: rgba(144, 183, 207, 0.18);
  --line-strong: rgba(144, 183, 207, 0.34);
  --text: #edf7fb;
  --muted: #9bb0bd;
  --blue: #4aa8ff;
  --cyan: #43d9e6;
  --green: #56e0bb;
  --amber: #ffc765;
  --red: #ff7785;
  --purple: #aa91ff;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.30);
  --sidebar-width: clamp(330px, 22vw, 410px);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); }
body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% -12%, rgba(74, 168, 255, 0.15), transparent 34%),
    radial-gradient(circle at 88% 0%, rgba(86, 224, 187, 0.11), transparent 31%),
    linear-gradient(180deg, #09141d 0%, var(--bg) 50%, #050b10 100%);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
h1, h2, h3, p { margin: 0; }

.ssa-app { height: 100vh; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.ssa-app.embedded { grid-template-rows: auto minmax(0, 1fr); }
.ssa-app.embedded .ssa-topbar { display: none; }

.ssa-topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px clamp(16px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 24, 0.90);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
  z-index: 50;
}
.brand-block { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { width: 48px; height: 48px; position: relative; display: grid; place-items: center; flex: 0 0 auto; }
.brand-mark::before, .brand-mark::after, .brand-mark span {
  content: "";
  position: absolute;
  border: 2px solid var(--green);
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
}
.brand-mark::before { inset: 2px; border-color: var(--blue); border-top-color: transparent; border-bottom-color: transparent; }
.brand-mark::after { inset: 11px; }
.brand-mark span:nth-child(1) { width: 7px; height: 7px; border: 0; background: var(--green); box-shadow: 0 0 18px var(--green); }
.brand-mark span:nth-child(2) { inset: 18px; border-color: var(--blue); border-top-color: transparent; border-bottom-color: transparent; }
.brand-mark span:nth-child(3) { display: none; }
.eyebrow, .section-kicker {
  display: block;
  color: var(--green);
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .17em;
  text-transform: uppercase;
}
.brand-block h1 { font-size: clamp(1.55rem, 2.3vw, 2.2rem); line-height: 1; letter-spacing: -.045em; }
.brand-block p { margin-top: 4px; color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 740px; }
.operator-box { display: grid; grid-template-columns: minmax(150px, 230px) auto auto; align-items: end; gap: 7px; }
.operator-box label { grid-column: 1 / -1; color: var(--muted); font-size: .68rem; }

.banner {
  min-height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: rgba(20, 42, 56, .55);
  font-size: .78rem;
  z-index: 40;
}
.banner-good { color: #bffbed; background: rgba(86, 224, 187, .09); }
.banner-bad { color: #ffd1d6; background: rgba(255, 119, 133, .10); }
.ssa-app.embedded .banner { min-height: 30px; font-size: .72rem; }

.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 780;
  color: var(--text);
  background: var(--panel-soft);
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease, border-color 120ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .38; }
.button-primary { color: #03131b; background: var(--green); }
.button-cyan { color: #03131b; background: var(--cyan); }
.button-secondary { color: var(--text); border-color: var(--line-strong); background: var(--panel-soft); }
.button-amber { color: #211400; border-color: rgba(255,199,101,.72); background: var(--amber); }
.button-danger { color: #fff; border-color: rgba(255,119,133,.46); background: rgba(255,119,133,.18); }
.button-small { min-height: 30px; padding: 0 9px; font-size: .72rem; }
.button-block { width: 100%; }

input, select {
  min-width: 0;
  width: 100%;
  height: 37px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  color: #ffffff !important;
  background: rgba(2, 10, 16, .82);
  outline: none;
}
select option { color: #fff; background: #08151e; }
input::placeholder { color: #728995; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(74,168,255,.11); }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  overflow: hidden;
}
.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(7, 17, 24, .96);
  scrollbar-color: rgba(144,183,207,.25) transparent;
}
.sidebar-inner { padding: 12px; }
.visual-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(280px, 53%) minmax(340px, 47%);
  overflow: hidden;
  background: #061016;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(15,31,43,.96), rgba(7,20,29,.98));
  box-shadow: var(--shadow);
}
.sidebar .panel { margin-bottom: 10px; box-shadow: none; }
.panel-head {
  min-height: 47px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin-top: 3px; font-size: 1rem; letter-spacing: -.025em; }
.panel-body { padding: 11px 12px; }
.panel-actions { display: flex; gap: 7px; padding: 0 12px 12px; }
.panel-actions.triple > * { flex: 1; }
.panel-actions.quad { display: grid; grid-template-columns: 1fr 1fr; }
.count-badge, .status-pill, .connection-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: rgba(4,13,20,.62);
  font-size: .65rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.status-pill.active, .connection-chip.live { color: var(--green); border-color: rgba(86,224,187,.38); }
.status-pill.warning, .connection-chip.starting { color: var(--amber); border-color: rgba(255,199,101,.38); }
.status-pill.error, .connection-chip.error { color: var(--red); border-color: rgba(255,119,133,.42); }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 7px; }
.metric-card {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(18,39,53,.94), rgba(9,22,32,.94));
}
.metric-card strong { font-size: 1.55rem; line-height: 1; letter-spacing: -.05em; }
.metric-card span { margin-top: 5px; color: var(--muted); font-size: .58rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.form-grid { display: grid; gap: 8px; }
.form-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.form-grid.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
.field { min-width: 0; }
.field label { display: block; margin: 0 0 4px; color: var(--muted); font-size: .66rem; font-weight: 700; }
.field-help { margin-top: 3px; color: #718994; font-size: .61rem; line-height: 1.35; }
.input-unit { position: relative; }
.input-unit input { padding-right: 44px; }
.input-unit span { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .66rem; pointer-events: none; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.helper { margin-top: 8px; color: var(--muted); font-size: .65rem; line-height: 1.45; }

.card-list { max-height: 255px; overflow: auto; padding: 8px; }
.emitters-list { max-height: 285px; }
.item-card {
  position: relative;
  margin-bottom: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: linear-gradient(155deg, rgba(22,45,59,.78), rgba(9,22,31,.94));
  cursor: pointer;
}
.item-card:last-child { margin-bottom: 0; }
.item-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; border-radius: 9px 0 0 9px; background: var(--blue); opacity: .8; }
.item-card.sensor::before { background: var(--cyan); }
.item-card.emitter::before { background: var(--red); }
.item-card.selected { border-color: rgba(67,217,230,.72); box-shadow: 0 0 0 1px rgba(67,217,230,.16) inset; }
.item-card:hover { background: linear-gradient(155deg, rgba(29,55,70,.84), rgba(10,25,35,.98)); }
.item-top { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.item-title { min-width: 0; font-size: .83rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { margin-top: 3px; color: var(--muted); font-size: .65rem; line-height: 1.35; overflow-wrap: anywhere; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px; color: var(--muted); font-size: .58rem; }
.item-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 8px currentColor; display: inline-block; }
.status-dot.active { color: var(--green); background: var(--green); }
.status-dot.inactive { color: var(--red); background: var(--red); }
.status-dot.stale { color: var(--amber); background: var(--amber); }
.geo-yes { color: var(--green); }
.geo-lob { color: var(--amber); }
.geo-no { color: var(--muted); }
.empty-state { padding: 18px 12px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 8px; text-align: center; font-size: .72rem; line-height: 1.5; }

.selected-object { min-height: 80px; color: #c8d7de; font-size: .72rem; line-height: 1.5; }
.selected-object dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; margin: 0; }
.selected-object dt { color: var(--muted); }
.selected-object dd { margin: 0; overflow-wrap: anywhere; }
.job-list { max-height: 185px; overflow: auto; padding: 8px; }
.job-row { padding: 7px 5px; border-bottom: 1px solid rgba(255,255,255,.05); font: .64rem ui-monospace,SFMono-Regular,Consolas,monospace; color: var(--muted); }
.job-row:last-child { border-bottom: 0; }

.map-panel, .spectrum-panel { min-height: 0; border-radius: 0; border-width: 0 0 1px 0; margin: 0; box-shadow: none; }
.map-panel { display: grid; grid-template-rows: auto minmax(0,1fr); }
.map-heading, .spectrum-heading { min-height: 48px; padding: 8px 12px; background: rgba(7,18,25,.95); }
.map-heading h2, .spectrum-heading h2 { font-size: .95rem; }
.map-actions { display: flex; align-items: center; gap: 9px; }
.map-key { color: var(--muted); font-size: .62rem; white-space: nowrap; }
.map-key i { width: 8px; height: 8px; display: inline-block; margin: 0 3px 0 7px; border-radius: 50%; }
.key-sensor { background: var(--cyan); }
.key-emitter { background: var(--red); }
.key-lob { background: var(--amber); }
.map-stage { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0a1820; }
.map-flash {
  position: absolute;
  z-index: 600;
  top: 10px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  opacity: 0;
  pointer-events: none;
  max-width: min(680px, 80%);
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: rgba(5,15,21,.94);
  font-size: .72rem;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}
.map-flash.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.map-flash.error { color: #ffd1d6; border-color: rgba(255,119,133,.5); }
.sensor-map-label, .emitter-map-label {
  border: 1px solid rgba(67,217,230,.56) !important;
  border-radius: 5px !important;
  padding: 2px 5px !important;
  color: #eaffff !important;
  background: rgba(3,14,19,.90) !important;
  box-shadow: none !important;
  font: 700 .61rem ui-monospace,SFMono-Regular,Consolas,monospace !important;
  white-space: nowrap;
}
.emitter-map-label { border-color: rgba(255,119,133,.58) !important; }
.sensor-map-label::before, .emitter-map-label::before { display: none !important; }

.spectrum-panel {
  display: grid;
  grid-template-rows: auto auto minmax(150px,1fr) auto;
  border-bottom: 0;
  background: #050d12;
}
.spectrum-title-wrap { min-width: 0; }
.spectrum-heading p { margin-top: 2px; max-width: 760px; color: var(--muted); font-size: .65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.radio-console {
  padding: 8px 10px 9px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11,28,39,.98), rgba(6,18,26,.98));
}
.radio-console-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 7px;
  align-items: end;
}
.radio-console .field label { color: #dbeaf0; font-size: .61rem; letter-spacing: .02em; }
.radio-console input, .radio-console select { height: 34px; font-size: .72rem; }
.radio-console-grid > .field:first-child { grid-column: span 2; }
.radio-actions { display: grid; grid-template-columns: 1fr 1fr; grid-column: span 2; gap: 6px; min-width: 190px; }
.effective-view { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 7px; color: var(--muted); font-size: .62rem; }
.effective-view b { color: var(--text); }
.advanced-settings { margin-top: 7px; border: 1px solid var(--line); border-radius: 8px; background: rgba(3,13,19,.55); }
.advanced-settings summary { padding: 7px 9px; color: var(--muted); font-size: .65rem; font-weight: 750; cursor: pointer; user-select: none; }
.advanced-grid { display: grid; grid-template-columns: repeat(8,minmax(78px,1fr)); gap: 7px; padding: 0 9px 9px; }

.spectrum-stage { min-height: 0; display: grid; grid-template-rows: 43% 57%; padding: 8px 10px 5px; gap: 4px; }
.trace-wrap, .waterfall-wrap { position: relative; min-height: 0; border: 1px solid var(--line); background: #02080c; overflow: hidden; }
#spectrum-canvas, #waterfall-canvas { width: 100%; height: 100%; display: block; }
.spectrum-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, rgba(18,48,61,.44), rgba(2,8,12,.94));
  z-index: 3;
}
.spectrum-empty.hidden { display: none; }
.spectrum-empty b { display: block; color: var(--text); font-size: .82rem; letter-spacing: .06em; }
.spectrum-empty span { display: block; margin-top: 7px; color: var(--muted); font-size: .68rem; line-height: 1.5; max-width: 760px; }
.waterfall-label { position: absolute; left: 6px; top: 4px; color: rgba(237,247,251,.72); font: .56rem ui-monospace,SFMono-Regular,Consolas,monospace; pointer-events: none; }
.spectrum-stats {
  min-height: 29px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 5px 10px 7px;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,.035);
  font: .58rem ui-monospace,SFMono-Regular,Consolas,monospace;
}
.spectrum-stats b { color: #e6f8fb; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  max-width: min(480px, calc(100vw - 40px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  background: #102331;
  box-shadow: var(--shadow);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: .76rem;
}
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { border-color: rgba(255,119,133,.45); background: #321721; }

@media (max-width: 1500px) {
  :root { --sidebar-width: clamp(315px, 24vw, 380px); }
  .radio-console-grid { grid-template-columns: repeat(auto-fit, minmax(105px,1fr)); }
  .advanced-grid { grid-template-columns: repeat(4,minmax(90px,1fr)); }
}
@media (max-width: 1100px) {
  body { overflow: auto; }
  .ssa-app { height: auto; min-height: 100vh; }
  .workspace { grid-template-columns: 1fr; overflow: visible; }
  .sidebar { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .visual-column { min-height: 900px; grid-template-rows: 430px minmax(470px,1fr); }
  .radio-console-grid { grid-template-columns: repeat(4,minmax(110px,1fr)); }
  .radio-actions { min-width: 0; }
  .radio-console-grid .fps-field { display: block; }
  .operator-box { grid-template-columns: minmax(140px,1fr) auto auto; }
}
@media (max-width: 720px) {
  .ssa-topbar { align-items: stretch; flex-direction: column; }
  .brand-block p { white-space: normal; }
  .operator-box { grid-template-columns: 1fr 1fr; }
  .operator-box input { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .radio-console-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .radio-actions { grid-column: 1 / -1; }
  .advanced-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .map-key { display: none; }
  .visual-column { min-height: 980px; grid-template-rows: 400px 580px; }
}
