:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --surface-elevated: #ffffff;
  --input-bg: #ffffff;
  --input-soft: #fbfcfe;
  --brand-soft: #edf7f6;
  --brand-active: #d9eeec;
  --danger-soft: #fff7f6;
  --danger-hover: #ffe8e4;
  --danger-active: #ffd7d1;
  --danger-strong: #8f1d13;
  --map-bg: #fbfcfe;
  --map-bg-soft: #eef3f8;
  --map-grid: rgba(22, 106, 106, 0.08);
  --map-overlay: rgba(255, 255, 255, 0.94);
  --line: #d9e1ea;
  --text: #17212f;
  --muted: #66758a;
  --brand: #166a6a;
  --brand-strong: #0d4f4f;
  --accent: #b45f06;
  --danger: #b42318;
  --ok: #12805c;
  --warn: #b54708;
  --shadow: 0 12px 32px rgba(30, 45, 70, 0.12);
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-soft: #1f2937;
  --surface-elevated: #172033;
  --input-bg: #0f172a;
  --input-soft: #111827;
  --brand: #2dd4bf;
  --brand-strong: #5eead4;
  --brand-soft: rgba(45, 212, 191, 0.12);
  --brand-active: rgba(45, 212, 191, 0.2);
  --danger: #f87171;
  --danger-soft: rgba(127, 29, 29, 0.24);
  --danger-hover: rgba(153, 27, 27, 0.34);
  --danger-active: rgba(185, 28, 28, 0.42);
  --danger-strong: #fecaca;
  --map-bg: #0f172a;
  --map-bg-soft: #111827;
  --map-grid: rgba(45, 212, 191, 0.11);
  --map-overlay: rgba(15, 23, 42, 0.92);
  --line: #2b374a;
  --text: #e5edf6;
  --muted: #9aa8ba;
  --accent: #f59e0b;
  --ok: #34d399;
  --warn: #fbbf24;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: linear-gradient(120deg, #ecf4f3 0%, #f8fafc 52%, #f3efe8 100%);
}

[data-theme="dark"] .login-shell {
  background: radial-gradient(circle at top left, rgba(45, 212, 191, 0.14), transparent 34%),
    linear-gradient(120deg, #08111f 0%, #101827 52%, #1c1425 100%);
}

.login-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel h1,
.topbar h2,
.panel h3 {
  margin: 0;
}

.login-panel p,
.panel-header p,
.sidebar-title span,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  border-right: 1px solid var(--line);
  background: var(--input-soft);
  padding: 20px;
}

.sidebar-title {
  display: block;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-item {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  text-align: left;
  transition:
    background-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.08s ease;
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.nav-item:active {
  background: #dde8f0;
  color: var(--brand);
  transform: translateY(1px);
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar,
.panel-header,
.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 18px;
}

.topbar-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
}

.auto-refresh-control,
.theme-toggle-control {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  white-space: nowrap;
  gap: 6px;
  cursor: pointer;
}

.auto-refresh-control input,
.theme-toggle-control input {
  width: auto;
  min-height: 0;
}

#refreshButton {
  min-width: 96px;
}

.view-pane {
  display: grid;
  gap: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card,
.panel,
.item-card,
.device-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-card {
  padding: 16px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.content-grid,
.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.projects-three-column {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(240px, 0.95fr) minmax(320px, 1.35fr);
  gap: 12px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.projects-compact-view {
  gap: 12px;
}

.projects-compact-view .panel {
  padding: 12px;
}

.projects-compact-view .panel-header {
  gap: 8px;
}

.projects-compact-view .panel-header h3 {
  font-size: 16px;
}

.projects-compact-view .panel-header p {
  margin-top: 3px;
  font-size: 12px;
}

.projects-compact-view .panel-search {
  min-height: 32px;
  margin-top: 10px;
  padding: 6px 9px;
  font-size: 13px;
}

.projects-compact-view .scroll-panel {
  max-height: 430px;
  margin-top: 10px;
}

.projects-compact-view .device-scroll-panel {
  max-height: 430px;
}

.projects-compact-view .list-stack,
.projects-compact-view .compact-device-grid {
  gap: 8px;
}

.projects-compact-view .item-card,
.projects-compact-view .device-card {
  gap: 8px;
  padding: 10px;
}

.compact-device-grid {
  grid-template-columns: 1fr;
}

.panel-search {
  width: 100%;
  min-height: 36px;
  margin-top: 14px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-soft);
  color: var(--text);
}

.panel-search:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(22, 106, 106, 0.12);
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 8px;
  align-items: center;
}

.filter-row .panel-search,
.filter-row .panel-filter {
  margin-top: 14px;
}

.panel-filter {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-soft);
  color: var(--text);
}

.panel-filter:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(22, 106, 106, 0.12);
}

.scroll-panel {
  max-height: 360px;
  margin-top: 14px;
  padding-right: 4px;
  overflow-y: auto;
}

.device-scroll-panel {
  max-height: 460px;
}

.trash-scroll-panel {
  max-height: 560px;
}

.scroll-panel .list-stack,
.scroll-panel .device-grid {
  margin-top: 0;
}

.scroll-panel::-webkit-scrollbar {
  width: 8px;
}

.scroll-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.35);
}

.scroll-panel::-webkit-scrollbar-track {
  background: transparent;
}

.list-stack {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.item-card,
.device-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.item-card.selected {
  border-color: var(--brand);
  box-shadow: inset 3px 0 0 var(--brand);
}

/* Reserve an independent right rail: telemetry and action wrapping never move it. */
.device-card.has-order-controls {
  position: relative;
  padding-right: 64px;
  min-height: 100px;
}

.device-order-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-order-controls > button {
  width: 36px;
  height: 32px;
  padding: 0;
}

.trash-card {
  border-color: rgba(180, 35, 24, 0.16);
  background: var(--surface-elevated);
}

.item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.meta-row,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.meta-row {
  color: var(--muted);
  font-size: 12px;
}

.error-line {
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.error-card {
  border-color: rgba(180, 35, 24, 0.28);
  background: var(--danger-soft);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.map-card {
  position: relative;
  min-height: 180px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--map-grid) 1px, transparent 1px),
    linear-gradient(var(--map-grid) 1px, transparent 1px),
    var(--map-bg);
  background-size: 28px 28px;
  padding: 12px;
}

.map-point {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 6px;
  background: var(--map-overlay);
  padding: 9px;
}

.dashboard-map-panel {
  min-height: calc(100vh - 220px);
}

.scenario-map-panel {
  min-height: 460px;
}

.amap-map {
  width: 100%;
  min-height: calc(100vh - 300px);
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--map-grid) 1px, transparent 1px),
    linear-gradient(var(--map-grid) 1px, transparent 1px),
    var(--map-bg-soft);
}

.scenario-map {
  min-height: 380px;
}

.map-hint {
  margin-top: 10px;
}

.map-fallback-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.map-info {
  display: grid;
  gap: 4px;
  min-width: 220px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.amap-label {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--map-overlay);
  color: var(--text);
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}

.map-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 4px;
  background: var(--brand);
  box-shadow: 0 5px 14px rgba(15, 23, 42, 0.25);
  color: #fff;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  user-select: none;
  transform: rotate(-45deg);
}

.map-marker::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.map-marker span {
  position: relative;
  z-index: 1;
  transform: rotate(45deg);
}

.map-marker-scenario {
  background: #7c3aed;
}

.map-marker-bdps {
  background: var(--brand);
}

.map-marker-rru {
  background: var(--accent);
}

.satellite-update-row {
  margin: 6px 0 -4px;
}

.json-preview {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px;
  white-space: pre-wrap;
}

.status-pill.online {
  border-color: rgba(18, 128, 92, 0.3);
  color: var(--ok);
}

.status-pill.offline,
.status-pill.failed {
  border-color: rgba(180, 35, 24, 0.28);
  color: var(--danger);
}

.status-pill.pending,
.status-pill.mismatch {
  border-color: rgba(181, 71, 8, 0.28);
  color: var(--warn);
}

.primary-action,
.secondary-action,
.ghost-action,
.danger-action,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 13px;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.08s ease;
}

.primary-action {
  background: var(--brand);
  color: white;
}

.primary-action:hover:not(:disabled) {
  background: var(--brand-strong);
  box-shadow: 0 7px 16px rgba(22, 106, 106, 0.22);
}

.primary-action:active:not(:disabled) {
  background: #083f3f;
  box-shadow: 0 3px 8px rgba(22, 106, 106, 0.2);
  transform: translateY(1px);
}

.secondary-action {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-action:hover:not(:disabled) {
  border-color: rgba(22, 106, 106, 0.35);
  background: var(--brand-soft);
  color: var(--brand-strong);
  box-shadow: 0 5px 12px rgba(30, 45, 70, 0.08);
}

.secondary-action:active:not(:disabled) {
  border-color: rgba(22, 106, 106, 0.5);
  background: var(--brand-active);
  color: var(--brand);
  box-shadow: none;
  transform: translateY(1px);
}

.ghost-action {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.ghost-action:hover:not(:disabled) {
  background: var(--surface-soft);
  color: var(--brand-strong);
}

.ghost-action:active:not(:disabled) {
  background: #dde8f0;
  color: var(--brand);
  transform: translateY(1px);
}

.danger-action {
  border-color: rgba(180, 35, 24, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}

.danger-action:hover:not(:disabled) {
  border-color: rgba(180, 35, 24, 0.45);
  background: var(--danger-hover);
  color: var(--danger-strong);
  box-shadow: 0 5px 12px rgba(180, 35, 24, 0.12);
}

.danger-action:active:not(:disabled) {
  border-color: rgba(180, 35, 24, 0.55);
  background: var(--danger-active);
  color: var(--danger-strong);
  box-shadow: none;
  transform: translateY(1px);
}

.icon-button:hover:not(:disabled) {
  border-color: rgba(22, 106, 106, 0.35);
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.icon-button:active:not(:disabled) {
  background: var(--brand-active);
  color: var(--brand);
  transform: translateY(1px);
}

.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.form-error,
.toast {
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 10px 12px;
  font-size: 13px;
}

.toast {
  position: sticky;
  top: 10px;
  z-index: 3;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.modal-panel {
  margin: 0;
}

.modal-header,
.modal-footer {
  padding: 14px 16px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  border-top: 1px solid var(--line);
}

.modal-body {
  display: grid;
  gap: 12px;
  max-height: min(68vh, 680px);
  overflow: auto;
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.compact-grid {
  gap: 10px;
}

.form-section {
  display: grid;
  gap: 12px;
}

.form-section + .form-section {
  margin-top: 6px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.form-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-help {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-collapse {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 94%, var(--accent) 6%);
}

.form-collapse summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  user-select: none;
}

.form-collapse summary:hover {
  color: var(--text);
  background: var(--hover);
}

.form-collapse[open] summary {
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.form-collapse .form-grid {
  padding: 12px;
}

.inline-check {
  display: inline-flex;
  grid-auto-flow: column;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.inline-check input {
  width: auto;
  min-height: 0;
}

.bdps-output-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.bdps-output-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 88%, var(--accent) 12%);
}

.bdps-output-card legend {
  padding: 0 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.icon-button {
  width: 34px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  font-size: 20px;
}

.table-wrap {
  overflow: auto;
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: 1fr;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .metric-grid,
  .content-grid,
  .split-layout,
  .projects-three-column,
  .bdps-output-groups,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .scroll-panel,
  .device-scroll-panel {
    max-height: 320px;
  }
}
