:root {
  color-scheme: dark;
  --page: #111412;
  --surface: #181c19;
  --surface-raised: #202520;
  --surface-soft: #151916;
  --ink: #edf1ec;
  --muted: #98a29a;
  --line: #313832;
  --line-strong: #465048;
  --brand: #2fc7a4;
  --brand-deep: #167c68;
  --brand-soft: rgba(47, 199, 164, .13);
  --amber: #e5ad46;
  --danger: #e45555;
  --danger-dark: #a83030;
  --ok: #45d39b;
  --shadow: 0 14px 34px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--page); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 18px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 64px;
  padding: 9px max(18px, calc((100vw - 1440px) / 2 + 24px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(17, 20, 18, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand-block, .connection-cluster, .status-item, .viewer-tools,
.scale-row, .dialog-heading, .dialog-actions { display: flex; align-items: center; }
.brand-block { gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #081511;
  background: var(--brand);
  border-radius: 5px;
  font-weight: 800;
}
.brand-block p, .section-heading p { margin-top: 3px; color: var(--muted); font-size: 11px; }
.connection-cluster { gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-item {
  gap: 7px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #717a73; }
.status-dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(69, 211, 155, .13); }
.status-dot.error { background: var(--danger); }
.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-soft);
}
.icon-button:hover { border-color: var(--brand); color: var(--brand); }

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
}

.viewer-section { min-width: 0; padding: 24px; }
.control-panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.panel-section { padding: 20px; border-bottom: 1px solid var(--line); }
.section-heading {
  min-height: 38px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 12px;
}
.section-heading.compact { min-height: auto; align-items: center; margin-bottom: 14px; }
.viewer-tools { gap: 9px; color: var(--muted); font-size: 11px; flex-wrap: wrap; justify-content: flex-end; }
.toggle-control { display: flex; align-items: center; gap: 6px; }
.toggle-control input { accent-color: var(--brand); }
.range-control { white-space: nowrap; }
input[type="range"] { accent-color: var(--brand); }
#opacityRange { width: 110px; }

.media-stage {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 180px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #0d110f;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  box-shadow: var(--shadow);
}
.media-stage video, .media-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#cameraVideo { z-index: 1; background: #0d110f; }
#videoPlaceholder { z-index: 2; }
#heatmapCanvas { z-index: 3; pointer-events: none; }
.media-overlay, .peak-readout {
  position: absolute;
  z-index: 4;
  color: #f5f7f5;
  background: rgba(10, 13, 11, .78);
  border: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(5px);
}
.media-overlay { top: 12px; display: flex; gap: 10px; padding: 5px 8px; font-size: 10px; }
.top-left { left: 12px; }
.top-right { right: 12px; }
.peak-readout {
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 7px 9px;
  font-size: 10px;
}
.peak-readout strong { color: #ffd36b; font-size: 20px; }
.video-empty {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 11px;
  color: #dce3dd;
  background: rgba(10, 13, 11, .8);
  border: 1px solid rgba(255, 255, 255, .1);
  text-align: center;
  pointer-events: none;
}
.video-empty strong { font-size: 12px; }
.video-empty span { color: #9fa8a1; font-size: 10px; }
.media-stage.has-video #videoPlaceholder, .media-stage.has-video .video-empty { display: none; }
.scale-row { gap: 8px; margin-top: 10px; color: var(--muted); font-size: 10px; }
.color-scale {
  width: min(260px, 45%);
  height: 6px;
  background: linear-gradient(90deg, #132b8e, #008fd2, #16b779, #f1d43b, #f06b22, #c51d25);
}
.scale-range { margin-left: auto; }

.direction-pad {
  width: 228px;
  margin: 16px auto;
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(3, 58px);
  gap: 8px;
  justify-content: center;
}
.direction-pad button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: #dfe6e0;
  background: var(--surface-raised);
  font-size: 22px;
  user-select: none;
  touch-action: none;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.direction-pad button:hover { border-color: var(--brand); color: var(--brand); }
.direction-pad button:active, .direction-pad button.active {
  transform: translateY(1px);
  color: #081511;
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.direction-pad .drive-stop { color: #fff; background: var(--danger-dark); border-color: var(--danger); font-size: 14px; }
.direction-pad .drive-stop:hover { color: #fff; background: var(--danger); border-color: #ff7474; }
.drive-state {
  min-height: 42px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-left: 3px solid var(--brand);
  background: var(--surface-soft);
  font-size: 12px;
}
.drive-state span { color: var(--muted); }
.drive-state strong { color: var(--brand); font-size: 15px; }
.speed-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.speed-controls button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-raised);
}
.speed-controls button:hover { border-color: var(--brand); color: var(--brand); }

.telemetry-list { margin: 10px 0 0; }
.telemetry-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}
.telemetry-list div:last-child { border-bottom: 0; }
.telemetry-list dt { color: var(--muted); }
.telemetry-list dd { margin: 0; text-align: right; }
.normal-text { color: var(--ok); font-weight: 650; }
.text-button { border: 0; padding: 4px; color: var(--brand); background: transparent; font-size: 11px; }
.event-log { min-height: 70px; max-height: 116px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.event-log li {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 7px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}
.event-log li span:last-child { color: var(--ink); overflow-wrap: anywhere; }

.vehicle-console {
  grid-column: 1 / -1;
  padding: 0 24px 30px;
  border-top: 1px solid var(--line);
}
.console-tabs {
  height: 54px;
  display: flex;
  align-items: end;
  gap: 2px;
  border-bottom: 1px solid var(--line);
}
.console-tabs button {
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}
.console-tabs button:hover { color: var(--ink); }
.console-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.vehicle-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr);
  gap: 12px;
  padding-top: 14px;
}
.tool-panel {
  min-width: 0;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.tool-panel[data-console-panel="mission"],
.tool-panel[data-console-panel="parameters"],
.telemetry-panel { grid-column: 1 / -1; }
.tool-panel button {
  min-height: 38px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-raised);
}
.tool-panel button:hover { border-color: var(--brand); color: var(--brand); }
.tool-panel .primary-command { color: #07130f; border-color: var(--brand); background: var(--brand); font-weight: 650; }
.tool-panel .primary-command:hover { color: #07130f; background: #4ed4b5; }
.tool-panel .danger-command { color: #fff; border-color: var(--danger); background: var(--danger-dark); }
.tool-panel .danger-command:hover { color: #fff; background: var(--danger); }
.command-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.raw-command-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; margin-top: 10px; }
.raw-command-row input {
  min-width: 0;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-soft);
}
.raw-command-row input::placeholder { color: #687169; }
.inline-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }
.inline-actions label { display: flex; align-items: center; gap: 5px; }
.inline-actions input { accent-color: var(--brand); }
.parameter-grid { display: grid; gap: 0; border-top: 1px solid var(--line); }
.parameter-row {
  min-height: 56px;
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(0, 1fr) 58px 60px;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.parameter-label { font-size: 12px; }
.parameter-label small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.parameter-row input[type="range"] { width: 100%; }
.parameter-value { color: var(--brand); text-align: right; font-weight: 700; }
.parameter-row.reserved { opacity: .38; }
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.metric {
  min-width: 0;
  min-height: 78px;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}
.metric small { display: block; color: var(--muted); font-size: 10px; }
.metric strong { display: block; margin-top: 7px; color: var(--ink); overflow-wrap: anywhere; font-size: 17px; }
.route-panel { grid-column: 1; }
.communication-panel { grid-column: 2; }
.route-map-stage {
  position: relative;
  width: 100%;
  height: 360px;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #0d110f;
}
.route-map-stage canvas { display: block; width: 100%; height: 100%; }
.route-map-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #778078; pointer-events: none; font-size: 11px; }
.route-map-empty.hidden { display: none; }
.route-summary { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-top: 0; }
.route-summary div { padding: 9px 11px; border-right: 1px solid var(--line); background: var(--surface-soft); }
.route-summary div:last-child { border-right: 0; }
.route-summary small { display: block; color: var(--muted); font-size: 9px; }
.route-summary strong { display: block; margin-top: 3px; font-size: 13px; }
.route-table-wrap { max-height: 170px; margin-top: 9px; overflow: auto; border: 1px solid var(--line); }
.route-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.route-table th, .route-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.route-table th { position: sticky; top: 0; color: var(--muted); background: var(--surface-raised); font-weight: 500; }
.route-table th:first-child, .route-table td:first-child { text-align: center; }
#vehicleLog {
  width: 100%;
  min-height: 520px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: #cbd5cc;
  background: #0d110f;
  font: 10px/1.55 Consolas, monospace;
}

.field-label { display: flex; justify-content: space-between; margin: 12px 0 7px; color: var(--muted); font-size: 11px; }
dialog {
  width: min(460px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(3, 5, 4, .7); }
dialog form { padding: 20px; }
.dialog-heading { justify-content: space-between; margin-bottom: 16px; }
dialog input {
  width: 100%;
  min-height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: var(--surface-soft);
}
.dialog-actions { justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-actions button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: var(--surface-raised); }
.dialog-actions .primary-button { color: #07130f; border-color: var(--brand); background: var(--brand); font-weight: 650; }

@media (max-width: 1020px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 292px; }
  .viewer-section { padding: 18px; }
  .panel-section { padding: 16px; }
  .direction-pad { width: 204px; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 54px); }
  .command-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .topbar { position: static; }
  .workspace { grid-template-columns: 1fr; }
  .control-panel { border: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; }
  .log-section { grid-column: 1 / -1; }
  .media-stage { max-height: none; }
  .vehicle-grid { grid-template-columns: 1fr; }
  .route-panel, .communication-panel { grid-column: 1; }
  #vehicleLog { min-height: 240px; }
}

@media (max-width: 580px) {
  .topbar { align-items: center; padding: 9px 12px; }
  .brand-block p { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .connection-cluster { gap: 5px; }
  .status-item { padding: 0 7px; }
  .viewer-section { padding: 12px; }
  .section-heading { flex-direction: column; gap: 7px; }
  .viewer-tools { justify-content: flex-start; }
  .control-panel { grid-template-columns: 1fr; }
  .log-section { grid-column: auto; }
  .media-overlay { top: 7px; }
  .top-left { left: 7px; }
  .top-right { right: 7px; }
  .peak-readout { left: 7px; bottom: 7px; }
  .video-empty { display: none; }
  .vehicle-console { padding: 0 12px 20px; }
  .console-tabs { height: auto; align-items: stretch; overflow-x: auto; }
  .console-tabs button { min-width: max-content; height: 44px; padding: 0 13px; }
  .tool-panel { padding: 14px; }
  .command-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .raw-command-row { grid-template-columns: 1fr 1fr; }
  .raw-command-row input { grid-column: 1 / -1; }
  .parameter-row { grid-template-columns: minmax(100px, 1fr) 52px 54px; padding: 8px 0; }
  .parameter-row input[type="range"] { grid-column: 1 / -1; grid-row: 2; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 70px; padding: 11px; }
  .route-map-stage { height: 280px; }
  .route-table-wrap { overflow-x: auto; }
}
