:root {
  --bg: #07111d;
  --bg-soft: #0d1d2c;
  --panel: rgba(11, 24, 39, 0.86);
  --line: rgba(130, 167, 201, 0.18);
  --text: #eef6ff;
  --muted: #98adc0;
  --accent: #46d8a8;
  --warning: #ff5b57;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  --radius: 22px;
  --page-gap: clamp(6px, 0.7vw, 10px);
  --panel-pad-y: clamp(5px, 0.9vh, 8px);
  --panel-pad-x: clamp(8px, 0.9vw, 12px);
  --hero-height: clamp(360px, 48dvh, 410px);
  --top6-width: clamp(250px, 23vw, 320px);
  --text-sm: clamp(12px, 0.86vw, 13px);
  --text-md: clamp(13px, 0.96vw, 14px);
  --text-lg: clamp(18px, 1.45vw, 24px);
  --button-height: clamp(28px, 3.5vh, 34px);
  --compact-row-height: clamp(34px, 4.4vh, 40px);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(70, 216, 168, 0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(58, 180, 255, 0.18), transparent 34%),
    linear-gradient(180deg, #07111d 0%, #061018 100%);
  overflow-x: hidden;
  overflow-y: auto;
}

.page {
  width: min(100%, 1280px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--page-gap);
  display: grid;
  gap: var(--page-gap);
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto var(--hero-height) auto auto auto auto auto;
  overflow: visible;
}
.page > * {
  min-width: 0;
  min-height: 0;
}
.panel, .status-card, .video-placeholder {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel, .status-card { padding: var(--panel-pad-y) var(--panel-pad-x); }
.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 10px;
  line-height: 1;
}
.muted, .placeholder-line { color: var(--muted); }
.error { color: #ffb4b1; }
.masthead, .emergency-panel, .panel-head, .list-head, .masthead-links {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.masthead-links { align-items: flex-start; }
.masthead {
  min-height: 40px;
}
.masthead h1 {
  margin: 0;
  font-size: var(--text-lg);
  line-height: 1;
}
.masthead .muted,
.masthead-links .text-link {
  font-size: var(--text-sm);
  line-height: 1.1;
}
.text-link { color: var(--accent); text-decoration: none; }
.status-grid, .controls, .hero {
  display: grid;
  gap: var(--page-gap);
  min-width: 0;
  min-height: 0;
}
.status-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.controls { grid-template-columns: 1fr 1fr; }
.hero-top-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}
.video-placeholder {
  position: relative;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}
.cloud-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.video-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(6, 16, 24, 0.48), rgba(6, 16, 24, 0.78));
}
.video-overlay span {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(7, 17, 29, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: var(--text-sm);
}
.status-card h2, .panel h2 {
  margin: 0 0 2px;
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 600;
  line-height: 1.1;
}
.status-card p, .panel p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.1;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(70, 216, 168, 0.12);
  color: var(--accent);
  font-weight: 700;
  font-size: var(--text-sm);
}
.rssi-track, .mini-rssi-track { border-radius: 999px; overflow: hidden; background: rgba(255, 255, 255, 0.08); }
.rssi-track { height: 8px; }
.mini-rssi-track { height: 4px; }
.rssi-fill, .mini-rssi-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #ff8c42 0%, #46d8a8 100%); transition: width 0.18s ease-out; }
.button-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
button {
  appearance: none;
  min-height: var(--button-height);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(58, 180, 255, 0.15), rgba(58, 180, 255, 0.04));
  color: var(--text);
  padding: 4px 8px;
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1.1;
  cursor: pointer;
}
button.danger { background: linear-gradient(180deg, rgba(255, 91, 87, 0.25), rgba(190, 28, 28, 0.12)); border-color: rgba(255, 91, 87, 0.38); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.list-block, .scanner-list, .event-log, .list-meta { display: grid; gap: 4px; }
.scanner-card, .list-item, .event-line {
  padding: 4px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-decoration: none;
}
.scanner-card span, .list-item span, .event-line { color: var(--muted); }
.list-item.selected strong { color: #00ff00; }
.list-head { align-items: center; gap: 8px; }
.top6-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}
.top6-panel .list-block {
  min-height: 0;
  overflow: visible;
  align-content: start;
}
.event-log {
  max-height: 96px;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
}
.controls .panel { min-height: 0; }
.emergency-panel { padding-top: 4px; padding-bottom: 4px; }
.emergency-panel .masthead-links { gap: 4px; }
.inline-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--compact-row-height);
}
.inline-card h2 {
  margin: 0;
  flex: 0 0 auto;
}
.inline-card p {
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.span-2 {
  grid-column: span 2;
}
.rssi-panel {
  padding-top: 4px;
  padding-bottom: 4px;
}
.transport-hidden {
  display: none;
}
.controls .panel h2,
.top6-panel h2,
.panel-head h2 { margin-bottom: 4px; }
.top6-panel .list-item strong,
.event-line,
.list-item span { font-size: var(--text-sm); }
#control-state,
#video-state-detail { font-size: var(--text-sm); }
.top6-panel .list-head {
  align-items: flex-start;
}
.top6-panel .list-head strong {
  font-size: var(--text-sm);
}
.top6-panel .list-head span {
  font-size: var(--text-sm);
}
.top6-panel .list-item {
  padding-top: 4px;
  padding-bottom: 4px;
}
.top6-panel .mini-rssi-track { height: 3px; }
.panel-head button, #reset-button, #ping-button, #start-video-button, #stop-video-button, #reconnect-video-button { white-space: nowrap; }
.login-page { place-items: center; min-height: 100vh; }
.login-card { width: min(420px, 100%); }
.login-form { display: grid; gap: 12px; margin-top: 12px; }
.login-form label { display: grid; gap: 6px; color: var(--muted); }
.login-form input { border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text); padding: 10px 12px; }

@media (max-width: 980px) {
  .page {
    width: min(100%, 1120px);
    height: auto;
    min-height: 100dvh;
    padding: 12px;
    grid-template-rows: none;
  }
  .hero, .controls { grid-template-columns: 1fr; }
  .hero-top-layout { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .button-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top6-panel {
    height: auto;
  }
  .top6-panel .list-block, .event-log { max-height: none; }
  .span-2 { grid-column: span 1; }
}

@media (max-width: 640px) {
  .status-grid, .button-grid { grid-template-columns: 1fr; }
  .masthead, .emergency-panel {
    flex-direction: column;
    align-items: flex-start;
  }
}
