:root {
  --bg: #0b1220;
  --bg2: #111a2e;
  --bg3: #1a2742;
  --border: #24344f;
  --text: #dbe4f3;
  --muted: #7c8db0;
  --accent: #38bdf8;
  --accent2: #22d3ee;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font: 13px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

/* ===== 顶栏 ===== */
.topbar {
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: linear-gradient(90deg, #0d1526, #12203a);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.topbar .title { font-size: 15px; font-weight: 600; letter-spacing: .5px; }
.topbar .subtitle { color: var(--muted); font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar .status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.dot.ok { background: #34d399; }
.dot.err { background: var(--danger); }

/* ===== 主体 ===== */
#main { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

/* ===== 左侧控制面板 ===== */
.sidebar {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 12px;
  width: 300px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: rgba(13, 21, 38, .94);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  overflow: hidden;
  backdrop-filter: blur(8px);
  transition: transform .25s ease;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, #0d1526, #12203a);
}
.panel-title { font-size: 13px; font-weight: 700; letter-spacing: 1px; color: #fff; }
.panel-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 6px;
}
.panel-toggle:hover { color: #fff; background: var(--bg3); }

.panel-body { flex: 1; overflow-y: auto; }
.section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: none; }
.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent2);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.panel-foot {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: rgba(10, 16, 30, .6);
}
.sidebar.collapsed { transform: translateX(-115%); }
.sidebar.collapsed ~ .legend { left: 12px; }

/* 展开面板的悬浮按钮 */
.panel-fab {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.panel-fab:hover { color: #fff; border-color: var(--accent); }

/* 统计 */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.stat .v { font-size: 18px; font-weight: 700; color: #fff; }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* 图层开关 */
.layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 13px;
}
.layer-item + .layer-item { border-top: 1px dashed rgba(36, 52, 79, .5); }
.layer-item .name { display: flex; align-items: center; gap: 8px; }
.layer-item .ico { width: 14px; height: 14px; border-radius: 3px; }
.switch { position: relative; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #33415e;
  border-radius: 20px;
  transition: .2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* 滑块 */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.range-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.range-label b { color: var(--accent2); font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* 数据上传 */
.upload-btn {
  width: 100%;
  background: var(--bg3);
  color: var(--text);
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}
.upload-btn:hover { background: var(--bg2); }
.upload-hint { font-size: 11px; color: var(--muted); margin-top: 6px; word-break: break-all; }

/* 下拉选择器 */
.select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text);
  outline: none;
  font-size: 12px;
}
.select:focus { border-color: var(--accent); }

/* 配色 */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.color-label { font-size: 12px; color: var(--muted); }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 4px 11px;
  font-size: 11px;
  cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #04121f; font-weight: 600; }
.seg.wide { width: 100%; }
.seg.wide .seg-btn { flex: 1; text-align: center; padding: 6px 0; }
input[type=color] {
  width: 44px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg2);
  cursor: pointer;
}

/* 查询 */
.search { display: flex; gap: 6px; }
.search input {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text);
  outline: none;
}
.search input:focus { border-color: var(--accent); }
button {
  background: var(--accent);
  color: #04121f;
  border: none;
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }

/* ===== 右侧属性面板 ===== */
.attr-panel {
  position: absolute;
  top: 12px;
  bottom: 12px;
  right: 12px;
  width: 340px;
  z-index: 11;
  background: rgba(13, 21, 38, .95);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  transform: translateX(120%);
  transition: transform .25s ease;
}
.attr-panel.open { transform: translateX(0); }
.attr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.attr-head .t { font-weight: 700; font-size: 14px; color: #fff; }
.attr-head .bid { font-size: 12px; color: var(--accent2); }
.attr-head .close { cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }
.attr-head .close:hover { color: #fff; }
.attr-scroll { flex: 1; overflow-y: auto; padding: 12px 14px; }
.attr-group { margin-bottom: 14px; }
.attr-group .gtitle {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.kv {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px dashed rgba(36, 52, 79, .6);
}
.kv .key { color: var(--muted); }
.kv .val { color: #fff; font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }
.raw-toggle { width: 100%; margin-top: 8px; }
.raw {
  display: none;
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font: 11px/1.5 monospace;
  white-space: pre-wrap;
  word-break: break-all;
  color: #9fb3d1;
}
.raw.show { display: block; }

/* ===== 图例（浮层） ===== */
.legend {
  position: absolute;
  bottom: 24px;
  left: 324px;
  z-index: 10;
  background: rgba(13, 21, 38, .92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 230px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
}
.legend .lt { font-size: 12px; font-weight: 600; color: var(--accent2); margin-bottom: 6px; letter-spacing: 1px; }
.legend .bar {
  height: 12px;
  border-radius: 3px;
  margin: 6px 0 4px;
  background: linear-gradient(to right, #2563eb, #ef4444);
}
.legend .ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.legend .note { margin-top: 8px; font-size: 11px; color: var(--muted); }
.legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #00e5ff;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ===== 悬浮提示 ===== */
#tooltip {
  position: absolute;
  z-index: 15;
  pointer-events: none;
  background: rgba(8, 14, 26, .95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
  color: #fff;
  display: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  max-width: 260px;
}
#tooltip .b { color: var(--accent2); font-weight: 600; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #2b3b5c; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* 隐藏 Mapbox 品牌标识 */
.mapboxgl-ctrl-logo, .mapboxgl-ctrl-attrib { display: none !important; }

/* 加载进度遮罩 */
.loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, .88);
  backdrop-filter: blur(3px);
}
.loading-box {
  width: 340px;
  padding: 28px 30px;
  background: linear-gradient(160deg, #15223f, #0d1628);
  border: 1px solid #2c4266;
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .6);
}
.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 4px solid #2b3b5c;
  border-top-color: #22d3ee;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 15px; font-weight: 600; color: #fff; margin-bottom: 16px; }
.progress { height: 12px; background: #0a1428; border: 1px solid #24344f; border-radius: 8px; overflow: hidden; }
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22d3ee, #38bdf8, #818cf8);
  border-radius: 8px;
  transition: width .15s ease;
  box-shadow: 0 0 12px rgba(56, 189, 248, .8);
}
.loading-pct { font-size: 13px; font-weight: 700; color: #22d3ee; margin-top: 10px; }

/* ===== 移动端适配 ===== */
.menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.menu-btn:hover { background: var(--bg3); }
#backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 9;
}

@media (max-width: 768px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .title { font-size: 14px; }
  .topbar .subtitle { display: none; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .panel-toggle { display: none; }
  .status-text { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .sidebar {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 300px;
    max-width: 86vw;
    border-radius: 0;
    transform: translateX(-105%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  #backdrop.show { display: block; }

  .attr-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 75%;
    border-radius: 14px 14px 0 0;
    transform: translateY(110%);
    transition: transform .25s ease;
  }
  .attr-panel.open { transform: translateY(0); }

  .legend { width: 150px; bottom: 12px; left: 8px; padding: 8px 10px; }
  .sidebar.open ~ .legend { display: none; }
  .legend .lt { font-size: 11px; }
  .legend .ticks { font-size: 9px; }
  .loading-box { width: 82vw; max-width: 320px; }
}
