/* ===== 全局 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  overflow: hidden;
}
body {
  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", sans-serif;
  color: #1f2937;
  background: #f3f4f6;
}

#app {
  display: flex;
  height: 100%;
}

/* ===== 侧栏 ===== */
#panel {
  width: 380px;
  min-width: 380px;
  height: 100%;
  background: #fff;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
  position: relative;
  transition: margin-left 0.25s ease;
}
#panel.collapsed {
  margin-left: -380px;
}

#panel-toggle {
  position: absolute;
  right: -30px;
  top: 14px;
  width: 30px;
  height: 56px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-left: none;
  border-radius: 0 8px 8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6b7280;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
}
#panel-toggle svg {
  transition: transform 0.25s;
}
#panel.collapsed #panel-toggle svg {
  transform: rotate(180deg);
}

.panel-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
}
.panel-header h1 {
  font-size: 19px;
  font-weight: 700;
  color: #111827;
}
.subtitle {
  font-size: 12px;
  color: #6b7280;
  margin-top: 3px;
}

/* ===== 表单 ===== */
.form-section {
  padding: 14px 18px 6px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.dot.start {
  background: #10b981;
}
.dot.end {
  background: #ef4444;
}

.input-wrap {
  flex: 1;
  position: relative;
}
.input-wrap input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
}
.input-wrap input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input.tangram-suggestion {
  border-radius: 8px;
}

/* ===== 输入提示下拉（地点检索，服务端 AK） ===== */
.ak-sug {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  /* 高于 #btn-plan/#btn-swap(1001) 与旧版百度下拉(1000)，展开时正常覆盖按钮 */
  z-index: 1002;
  max-height: 240px;
  overflow-y: auto;
  display: none;
}
.ak-sug-item {
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}
.ak-sug-item:hover {
  background: #f0f7ff;
}
.ak-sug-name {
  display: block;
  color: #1f2937;
  font-weight: 500;
}
.ak-sug-addr {
  display: block;
  color: #9ca3af;
  font-size: 11px;
  margin-top: 1px;
}

.pick-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pick-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
}
.pick-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

#btn-swap {
  width: 100%;
  padding: 6px;
  font-size: 12px;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
  text-align: center;
}
#btn-swap:hover {
  color: #2563eb;
}

/* ===== 手动输入途经点 ===== */
.dot.wp {
  background: #0d9488;
}
.wp-grip {
  cursor: grab;
  touch-action: none; /* 触屏长按拖动不被面板滚动打断 */
  color: #9ca3af;
  font-size: 14px;
  line-height: 1;
  letter-spacing: -2px;
  padding: 0 2px;
  flex-shrink: 0;
  user-select: none;
}
.wp-grip:active {
  cursor: grabbing;
  color: #0d9488;
}
.wp-row.dragging {
  opacity: 0.55;
  outline: 2px dashed #0d9488;
  border-radius: 8px;
}
body.wp-dragging {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}
#btn-add-wp {
  width: 100%;
  padding: 7px;
  font-size: 12px;
  color: #0d9488;
  background: none;
  border: 1px dashed #99f6e4;
  border-radius: 8px;
  cursor: pointer;
}
#btn-add-wp:hover {
  background: #f0fdfa;
  border-color: #0d9488;
}
.wp-del {
  width: 32px;
  height: 38px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff;
  color: #ef4444;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.wp-del:hover {
  background: #fef2f2;
}

/* ===== 选项 ===== */
.options-section {
  padding: 6px 18px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}
.option-row label {
  width: 60px;
  color: #374151;
  flex-shrink: 0;
}
.option-row input[type="range"] {
  flex: 1;
  accent-color: #2563eb;
}
#threshold-val {
  width: 46px;
  text-align: right;
  color: #2563eb;
  font-weight: 600;
  font-size: 12px;
}
.option-row select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  outline: none;
}
.checkbox-row {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #4b5563;
  flex-wrap: wrap;
}
.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.checkbox-row input {
  accent-color: #2563eb;
}

/* ===== 规划按钮 ===== */
#btn-plan {
  margin: 12px 18px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #2563eb;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
#btn-plan:hover:not(:disabled) {
  background: #1d4ed8;
}
#btn-plan:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}
#btn-plan.loading {
  background: #60a5fa;
  cursor: wait;
}

/* ===== 状态 ===== */
.status {
  margin: 0 18px 10px;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.6;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  max-height: 110px;
  overflow-y: auto;
}

/* ===== 结果 ===== */
.results {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px;
}
.stat-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.stat-card {
  flex: 1;
  background: #f9fafb;
  border: 1px solid #f0f0f0;
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}
.stat-card.highlight {
  background: #fef2f2;
  border-color: #fecaca;
}
.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}
.stat-card.highlight .stat-value {
  color: #dc2626;
}
.stat-label {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

.compare-bar {
  background: #f9fafb;
  border: 1px solid #f0f0f0;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.compare-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: #4b5563;
}
.compare-row .orig {
  font-weight: 700;
  color: #9ca3af;
}
.compare-row .final {
  font-weight: 700;
  color: #16a34a;
}

.camera-list-header {
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  margin-bottom: 6px;
}
.camera-list {
  list-style: none;
  margin-bottom: 12px;
}
.camera-list li {
  font-size: 12px;
  color: #374151;
  padding: 7px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  line-height: 1.5;
}
.camera-list li:hover {
  background: #fee2e2;
}
.camera-list .cam-type {
  display: inline-block;
  font-size: 10px;
  padding: 0 6px;
  border-radius: 8px;
  background: #dc2626;
  color: #fff;
  margin-right: 6px;
  vertical-align: 1px;
}
.camera-list .cam-dist {
  color: #9ca3af;
}
.camera-list .force-failed {
  display: inline-block;
  font-size: 10px;
  padding: 0 6px;
  border-radius: 8px;
  background: #f59e0b;
  color: #fff;
  margin-left: 6px;
  vertical-align: 1px;
}
.camera-list .force-btn {
  float: right;
  font-size: 11px;
  padding: 2px 8px;
  margin-left: 8px;
  border: 1px solid #f97316;
  border-radius: 10px;
  background: #fff7ed;
  color: #c2410c;
  cursor: pointer;
  flex-shrink: 0;
}
.camera-list .force-btn:hover {
  background: #ffedd5;
}

.panel-footer {
  padding: 10px 18px;
  font-size: 11px;
  color: #9ca3af;
  border-top: 1px solid #f0f0f0;
  text-align: center;
}

/* ===== 地图 ===== */
#map {
  flex: 1;
  height: 100%;
  min-width: 0;
}
#map.pick-mode {
  cursor: crosshair !important;
}

/* ===== 图例 ===== */
#legend {
  position: absolute;
  right: 12px;
  bottom: 30px;
  z-index: 9;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  color: #374151;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#legend .lg {
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: 2px;
}
.lg-route {
  background: #2563eb;
}
.lg-orig {
  background: repeating-linear-gradient(
    90deg,
    #9ca3af 0 4px,
    transparent 4px 7px
  );
}
.lg-cam {
  background: #ef4444;
  border-radius: 50%;
  height: 8px;
  width: 8px;
}
.lg-hit {
  background: #ef4444;
  border-radius: 50%;
  height: 8px;
  width: 8px;
}
.lg-waypoint {
  background: #0d9488;
  border-radius: 50%;
  height: 8px;
  width: 8px;
}
.lg-ring {
  background: rgba(147, 51, 234, 0.15);
  border: 1px solid rgba(147, 51, 234, 0.45);
  height: 10px;
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  width: 100%;
  max-width: 420px;
}
.modal-box h2 {
  font-size: 18px;
  margin-bottom: 10px;
}
.modal-tip {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.7;
  margin-bottom: 14px;
}
.modal-tip a {
  color: #2563eb;
}
#ak-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
#ak-input:focus {
  border-color: #2563eb;
}
.ak-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 6px;
}
.modal-btns {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}
.modal-btns button {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
}
#ak-save {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
#ak-save:hover {
  background: #1d4ed8;
}

.hidden {
  display: none !important;
}

/* 百度自动补全下拉 */
.tangram-suggestion-main {
  z-index: 1000 !important;
  max-height: 176px; /* 限制高度，减少对面板的遮挡 */
  overflow-y: auto;
}
/* 规划/交换按钮始终位于下拉层之上（下拉为绝对定位覆盖层，会盖住按钮导致点击失效） */
#btn-plan,
#btn-swap {
  position: relative;
  z-index: 1001;
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }
  #panel {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 62vh;
    overflow-y: auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    order: 0;
    transition: max-height 0.25s ease;
  }
  #panel.collapsed {
    margin-left: 0;
    max-height: 52px;
    overflow: hidden;
  }
  #panel-toggle {
    right: 10px;
    top: 8px;
    width: 34px;
    height: 36px;
    border: none;
    border-radius: 8px;
    box-shadow: none;
    background: #f3f4f6;
  }
  #panel.collapsed #panel-toggle svg {
    transform: rotate(-90deg);
  }
  #panel:not(.collapsed) #panel-toggle svg {
    transform: rotate(90deg);
  }
  #map {
    order: 1;
    height: 38vh;
    min-height: 240px;
    flex: none;
  }
  .panel-header {
    padding: 12px 50px 10px 16px;
  }
  .panel-header h1 {
    font-size: 16px;
  }
  .subtitle {
    display: none;
  }
  .form-section {
    padding: 10px 14px 4px;
  }
  .options-section {
    padding: 4px 14px 10px;
  }
  #btn-plan {
    margin: 10px 14px;
    padding: 11px;
  }
  .status {
    margin: 0 14px 8px;
  }
  .results {
    padding: 0 14px;
  }
  .stat-value {
    font-size: 14px;
  }
  #legend {
    bottom: 10px;
    right: 8px;
    padding: 8px 10px;
    font-size: 11px;
    gap: 4px;
  }
  .panel-footer {
    padding: 8px 14px;
  }
}
