:root {
  color-scheme: dark;
  --bg0: #020913;
  --bg1: #051a36;
  --bg2: #0a2f5c;
  --panel: rgba(8, 23, 49, 0.78);
  --panel-soft: rgba(10, 30, 61, 0.6);
  --line: rgba(112, 185, 255, 0.45);
  --line-soft: rgba(112, 185, 255, 0.22);
  --text: #e2f2ff;
  --muted: #8fb1d4;
  --ok: #4be1bf;
  --warn: #ffc969;
  --bad: #ff7474;
  --accent: #67c7ff;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(circle at 50% -6%, rgba(92, 175, 255, 0.32), transparent 38%),
    linear-gradient(180deg, #071833 0%, #041126 38%, #020913 100%);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(145, 205, 255, 0.06) 0,
      rgba(145, 205, 255, 0.06) 1px,
      transparent 1px,
      transparent 36px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(145, 205, 255, 0.05) 0,
      rgba(145, 205, 255, 0.05) 1px,
      transparent 1px,
      transparent 56px
    );
}
button, input, select { font: inherit; color: var(--text); }
button {
  background: linear-gradient(180deg, rgba(33, 90, 160, 0.7), rgba(13, 39, 84, 0.95));
  border: 1px solid rgba(113, 182, 248, 0.55);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.45; cursor: default; }
.ghost { background: transparent; }
.tiny { padding: 4px 8px; font-size: 12px; }
.hidden { display: none !important; }

.login-page { position: fixed; inset: 0; z-index: 1200; display: none; background: rgba(0, 0, 0, 0.72); }
.login-page.show { display: flex; align-items: center; justify-content: center; }
.login-shell {
  width: min(1080px, 94vw);
  min-height: min(640px, 88vh);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(4, 14, 31, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(89, 171, 255, 0.18);
  display: grid;
  grid-template-columns: 1.2fr 460px;
  overflow: hidden;
}
.login-brand { padding: 54px 56px; display: flex; align-items: center; }
.login-brand h1 { margin: 0; font-size: 44px; text-shadow: 0 0 18px rgba(131, 203, 255, 0.65); }
.login-card {
  background: rgba(7, 19, 40, 0.96);
  border-left: 1px solid var(--line-soft);
  padding: 54px 46px 24px;
  display: flex; flex-direction: column; gap: 14px; justify-content: center;
}
.login-card h2 { margin: 0 0 6px; font-size: 30px; }
.login-card label, .account-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input, .account-form input, .account-form select, .password-form input, .password-form select, .history-toolbar input, .history-toolbar select, #historySearch, .org-form input, .org-form select {
  background: rgba(11, 29, 60, 0.8);
  border: 1px solid rgba(109, 177, 243, 0.45);
  border-radius: 6px;
  padding: 9px 10px;
}

#app { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(5, 18, 41, 0.95), rgba(3, 12, 28, 0.75));
}
.topbar::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  width: min(900px, 72vw);
  height: 100%;
  pointer-events: none;
  border: 1px solid rgba(130, 203, 255, 0.35);
  border-top: 0;
  clip-path: polygon(5% 0, 95% 0, 89% 96%, 11% 96%);
  box-shadow: 0 0 16px rgba(115, 188, 255, 0.26);
}
.topbar::before {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(640px, 54vw);
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(141, 214, 255, 0.8), transparent);
  box-shadow: 0 0 12px rgba(122, 202, 255, 0.45);
}
.topbar-time {
  justify-self: start;
  color: #9bc1e7;
  font-weight: 700;
  font-size: 14px;
}
.title-wrap { justify-self: center; text-align: center; z-index: 1; }
.title-wrap h1 {
  margin: 0;
  font-size: 46px;
  letter-spacing: 0;
  line-height: 1;
  text-shadow: 0 0 16px rgba(148, 214, 255, 0.6);
}
.status { margin: 5px 0 0; font-size: 13px; }
.status.connected { color: var(--ok); }
.status.connecting { color: var(--warn); }
.status.disconnected { color: var(--muted); }
.toolbar {
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  z-index: 1;
}
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.badge {
  padding: 6px 10px;
  border: 1px solid rgba(106, 177, 245, 0.42);
  border-radius: 999px;
  font-size: 12px;
  color: #d0ebff;
  background: rgba(33, 81, 144, 0.28);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 350px 1fr 360px;
  overflow: hidden;
  isolation: isolate;
}
.workspace.detail-closed { grid-template-columns: 350px 1fr; }

.panel {
  position: relative;
  z-index: 2;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
  box-shadow: inset 0 0 24px rgba(80, 153, 230, 0.18);
}
.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-soft);
  pointer-events: none;
}
.panel::before { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }
.list-panel { background: linear-gradient(180deg, rgba(7, 24, 52, 0.86), rgba(4, 14, 35, 0.76)); }
.detail-panel { border-right: 0; border-left: 1px solid var(--line-soft); }
.workspace.detail-closed .detail-panel { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(90deg, rgba(28, 78, 141, 0.5), rgba(13, 37, 74, 0.12));
}
.panel-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  position: relative;
  padding-left: 18px;
}
.panel-head h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid rgba(142, 210, 255, 0.9);
  filter: drop-shadow(0 0 4px rgba(131, 206, 255, 0.6));
}
.detail-head-right { display: flex; align-items: center; gap: 8px; }
#listCount, #lastUpdate { color: var(--muted); font-size: 12px; }

.list-stats {
  display: grid;
  gap: 8px;
  padding: 10px 12px 0;
  color: var(--muted);
  font-size: 12px;
}

.map-panel {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(7, 22, 47, 0.6), rgba(5, 15, 31, 0.6)),
    radial-gradient(circle at 50% 50%, rgba(87, 160, 236, 0.14), transparent 70%);
}
.map-panel::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  width: min(520px, 42vw);
  height: 22px;
  border-top: 1px solid rgba(120, 196, 255, 0.5);
  border-radius: 999px;
  box-shadow: 0 -4px 14px rgba(93, 178, 255, 0.25);
  pointer-events: none;
  z-index: 2;
}
.map-frame {
  position: absolute;
  inset: 12px;
  z-index: 0;
  border: 1px solid rgba(110, 183, 250, 0.36);
  box-shadow: inset 0 0 20px rgba(98, 173, 243, 0.18);
  pointer-events: none;
}
.map-frame::before,
.map-frame::after {
  content: "";
  position: absolute;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(135, 206, 255, 0.55);
}
.map-frame::before {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
}
.map-frame::after {
  right: -1px;
  bottom: -1px;
  border-left: 0;
  border-top: 0;
}
#map, #historyMap {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0a1018;
}

.leaflet-container { position: relative; overflow: hidden; width: 100%; height: 100%; outline: 0; touch-action: pan-x pan-y; }
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow, .leaflet-tile-container, .leaflet-pane > svg, .leaflet-pane > canvas, .leaflet-zoom-box, .leaflet-image-layer, .leaflet-layer { position: absolute; left: 0; top: 0; }
.leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow { user-select: none; -webkit-user-drag: none; }
.leaflet-tile { border: 0; visibility: hidden; }
.leaflet-tile-loaded { visibility: inherit; }
.leaflet-map-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-control-container { position: absolute; inset: 0; z-index: 800; pointer-events: none; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; float: left; clear: both; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 800; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-right { right: 0; }
.leaflet-top .leaflet-control { margin-top: 10px; }
.leaflet-left .leaflet-control { margin-left: 10px; }
.leaflet-bottom .leaflet-control { margin-bottom: 10px; }
.leaflet-right .leaflet-control { margin-right: 10px; }
.leaflet-control-zoom a { display: block; width: 30px; height: 30px; line-height: 30px; text-align: center; text-decoration: none; color: var(--text); background: #101826; border-bottom: 1px solid var(--line); }
.leaflet-control-zoom a:last-child { border-bottom: 0; }
.leaflet-control-zoom { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
.leaflet-control-attribution, .leaflet-control-scale-line { color: var(--muted); background: rgba(10, 16, 24, 0.76); border: 1px solid var(--line); font-size: 11px; padding: 2px 5px; }

.drone-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 10px 0;
}
.drone-item {
  border-bottom: 1px solid rgba(103, 171, 235, 0.2);
  padding: 10px 12px;
  cursor: pointer;
  background: rgba(22, 53, 98, 0.24);
}
.drone-item.active { background: rgba(53, 113, 188, 0.32); }
.drone-item .id {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drone-item .brand {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drone-item .meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}
.meta .online { color: var(--ok); }
.meta .offline { color: var(--muted); }

.detail-view { padding: 12px; overflow: auto; }
.placeholder { margin: 0; color: var(--muted); font-size: 13px; }
.detail-grid {
  display: grid;
  grid-template-columns: 96px 1fr;
  row-gap: 8px;
  column-gap: 10px;
  font-size: 13px;
}
.detail-grid .k { color: var(--muted); }
.detail-grid .v { color: var(--text); word-break: break-all; }
.detail-list-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 12, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 18px;
}
.overlay.show { display: flex; }
.account-card, .history-card {
  width: min(1240px, 96vw);
  max-height: 94vh;
  overflow: hidden;
  background: rgba(8, 20, 43, 0.96);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
}
.auth-msg, .account-msg { min-height: 18px; margin: 0; font-size: 12px; color: var(--warn); }
.account-card { width: min(1080px, 96vw); padding: 14px; gap: 12px; }
.account-head, .history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.account-head-right { display: flex; align-items: center; gap: 8px; }

.org-panel {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(11, 27, 56, 0.72);
  padding: 10px;
}
.org-head h3 { margin: 0 0 8px; font-size: 14px; }
.org-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.org-tree {
  margin-top: 10px;
  border: 1px solid rgba(90, 156, 227, 0.35);
  border-radius: 8px;
  background: rgba(9, 22, 46, 0.72);
  padding: 8px;
  max-height: 180px;
  overflow: auto;
}
.org-node { display: flex; align-items: center; gap: 6px; padding: 4px 2px; font-size: 12px; }
.org-toggle {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(114, 178, 247, 0.45);
  border-radius: 4px;
  background: rgba(31, 69, 121, 0.65);
  color: #cfe8ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.org-leaf-pad { display: inline-block; width: 18px; height: 18px; }
.org-name { cursor: pointer; color: #d8ecff; }
.org-name.active { color: #7fd1ff; text-shadow: 0 0 8px rgba(102, 190, 255, 0.6); }

.account-form { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 170px auto; gap: 10px; align-items: end; }
.password-panel { border: 1px solid var(--line-soft); border-radius: 8px; background: rgba(12, 30, 60, 0.6); padding: 10px; }
.password-head h3 { margin: 0 0 10px; font-size: 14px; }
.password-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: center; }
.serial-list-panel { border: 1px solid var(--line-soft); border-radius: 8px; background: rgba(10, 28, 56, 0.66); padding: 10px; display: grid; gap: 10px; }
.serial-list-head h3 { margin: 0; font-size: 14px; }
.serial-list-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto auto; gap: 8px; align-items: center; }
.serial-list-form input {
  background: rgba(11, 29, 60, 0.8);
  border: 1px solid rgba(109, 177, 243, 0.45);
  border-radius: 6px;
  padding: 9px 10px;
  min-width: 0;
}
.serial-list-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.serial-list-box {
  border: 1px solid rgba(90, 156, 227, 0.35);
  border-radius: 8px;
  background: rgba(9, 22, 46, 0.72);
  padding: 8px;
  display: grid;
  gap: 8px;
}
.serial-list-box h4 { margin: 0; font-size: 13px; color: #d6ecff; }
.serial-list-items { display: grid; gap: 6px; max-height: 160px; overflow: auto; }
.serial-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid rgba(95, 159, 229, 0.3);
  border-radius: 6px;
  background: rgba(13, 32, 64, 0.7);
}
.serial-list-item .serial-text {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.serial-list-item .serial-actions { display: flex; gap: 6px; }
.serial-list-item .serial-actions button { padding: 4px 8px; font-size: 12px; }
.serial-list-empty {
  border: 1px dashed rgba(95, 159, 229, 0.4);
  border-radius: 6px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  padding: 10px 8px;
}

.account-list {
  overflow: auto;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}
.account-row {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1fr 1fr 1.1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(11, 27, 56, 0.65);
  font-size: 13px;
}
.account-row.account-row-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(20, 47, 89, 0.96);
  border-color: rgba(117, 187, 252, 0.42);
  font-weight: 600;
}
.account-row .muted { color: var(--muted); }

.history-card { width: min(1680px, 98vw); }
.history-body { min-height: 0; display: grid; grid-template-columns: 420px 1fr; height: 82vh; }
.history-left, .history-right { min-height: 0; }
.history-left {
  border-right: 1px solid var(--line-soft);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-toolbar { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; }
.history-list { min-height: 0; overflow: auto; display: grid; gap: 8px; }
.history-item {
  border: 1px solid var(--line-soft);
  background: rgba(11, 27, 56, 0.7);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.history-item.active { border-color: var(--accent); }
.history-item .title { font-weight: 700; font-size: 13px; }
.history-item .meta { margin-top: 6px; color: var(--muted); font-size: 12px; }
.history-right { display: grid; grid-template-rows: 1fr auto; min-height: 0; }
.history-map-wrap { min-height: 0; }
.history-preview {
  border-top: 1px solid var(--line-soft);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.map-popup { min-width: 180px; max-width: 220px; font-size: 12px; line-height: 1.35; }
.leaflet-tooltip.map-popup {
  background: #0f1620;
  border: 1px solid #304258;
  color: var(--text);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
}
.leaflet-tooltip-top.map-popup:before { border-top-color: #304258; }
.map-popup h4 { margin: 0 0 6px; font-size: 13px; color: var(--text); }
.map-popup .row { display: flex; justify-content: space-between; gap: 10px; }
.map-popup .label { color: var(--muted); }
.map-popup .value { color: var(--text); text-align: right; word-break: break-all; }

.rid-marker-icon { background: transparent; border: 0; }
.rid-marker-icon > div {
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.45));
}
.rid-marker-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}
.rid-marker-icon.active > div {
  filter:
    drop-shadow(0 0 3px rgba(255, 255, 255, 0.96))
    drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

.powered-by { color: var(--muted); font-size: 12px; line-height: 1.4; }
.powered-by-login { margin: auto 0 0; padding-top: 24px; text-align: center; }
.powered-by-list { flex: 0 0 auto; padding: 10px 12px; border-top: 1px solid var(--line-soft); text-align: left; }

@media (max-width: 1400px) {
  .history-body { grid-template-columns: 360px 1fr; }
}
@media (max-width: 1200px) {
  .workspace { grid-template-columns: 300px 1fr; grid-template-rows: 1fr 260px; }
  .workspace.detail-closed { grid-template-columns: 300px 1fr; }
  .detail-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line-soft); }
  .login-shell { grid-template-columns: 1fr 420px; }
  .title-wrap h1 { font-size: 38px; }
}
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr; gap: 8px; }
  .topbar-time, .title-wrap, .toolbar { justify-self: stretch; text-align: center; justify-content: center; }
  .workspace, .workspace.detail-closed { grid-template-columns: 1fr; grid-template-rows: 250px 1fr auto; }
  .list-panel { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .map-panel { min-height: 300px; }
  .detail-panel { border-left: 0; border-top: 1px solid var(--line-soft); }
  .history-card { width: min(98vw, 98vw); }
  .history-body { grid-template-columns: 1fr; grid-template-rows: 340px 1fr; height: 86vh; }
  .history-left { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .account-form { grid-template-columns: 1fr 1fr; }
  .password-form { grid-template-columns: 1fr; }
  .serial-list-form { grid-template-columns: 1fr 1fr; }
  .serial-list-grid { grid-template-columns: 1fr; }
  .account-row { grid-template-columns: 1fr 1fr; }
  .login-shell { grid-template-columns: 1fr; min-height: auto; }
  .login-brand { padding: 28px 24px 8px; }
  .login-brand h1 { font-size: 30px; }
  .login-card { border-left: 0; border-top: 1px solid var(--line-soft); padding: 24px; }
}
