:root {
  --primary: #2f6fed;
  --bg: #f5f6f8;
  --card: #fff;
  --line: #e3e6ea;
  --text: #1f2933;
  --muted: #7b8794;
  --danger: #d64545;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
}

/* 头部 */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.header-actions { display: flex; gap: 8px; }

/* 按钮 */
button {
  font: inherit; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; padding: 7px 14px; cursor: pointer;
}
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger-ghost { color: var(--danger); background: transparent; }
button:hover { filter: brightness(0.96); }

/* 主区：地图填满 header 以下 */
main { position: relative; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
#map { position: absolute; inset: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); }
a { color: var(--primary); }

/* 令牌弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--card); border-radius: 14px; padding: 26px; width: 320px;
  box-shadow: 0 10px 40px rgba(0,0,0,.18);
}
.modal-card h2 { margin: 0 0 6px; }
.modal-card input {
  width: 100%; margin: 14px 0; padding: 10px; font: inherit;
  border: 1px solid var(--line); border-radius: 8px;
}
.modal-card button { width: 100%; }

/* 行程列表 */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
}
.card .name { font-weight: 600; margin-bottom: 4px; }
.card .meta { font-size: 13px; }
.card .km { font-size: 22px; font-weight: 700; color: var(--primary); white-space: nowrap; }
.card .km small { font-size: 12px; color: var(--muted); font-weight: 400; }

/* 空行程提示横幅 */
.empty-banner {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.96); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 18px; z-index: 1000; text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.12); font-size: 14px; max-width: 92vw;
}
.empty-banner b { color: var(--primary); }
.empty-banner p { margin: 6px 0 0; color: var(--muted); line-height: 1.6; }
.empty-banner code { background: #f0f2f5; border-radius: 4px; padding: 1px 6px; }

/* 停靠点弹窗 */
.pop b { display: block; margin-bottom: 2px; }
.pop .meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pop .note { margin: 6px 0; white-space: pre-wrap; word-break: break-word; }
.pop .thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pop .thumbs img { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.pop .ops { margin-top: 8px; font-size: 12px; }

/* 停靠点标记 */
.stop-pin {
  background: var(--primary); color: #fff; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.35); font-size: 12px;
}
.stop-pin span { transform: rotate(45deg); }
.pick-pin { filter: hue-rotate(120deg); }

/* 侧边面板（左侧行程列表 / 右侧记录+时间线） */
.side-panel {
  position: absolute; top: 10px; max-height: calc(100% - 20px);
  overflow-y: auto; background: rgba(255,255,255,.97);
  border-radius: 12px; z-index: 1000; box-shadow: 0 4px 18px rgba(0,0,0,.16);
  padding: 10px 12px;
}
.side-panel.left { left: 10px; right: auto; width: 300px; max-width: calc(100vw - 20px); }
.side-panel.right { right: 10px; left: auto; width: 340px; max-width: calc(100vw - 20px); }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#trip-cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
#trip-cards .card { cursor: pointer; padding: 10px 12px; }
#trip-cards .card:hover { background: #f4f7fc; }
#trip-cards .card.sel { border-color: var(--primary); background: #eef4ff; }
.card.sel .name { color: var(--primary); }
#trip-cards .card .km { font-size: 18px; }
/* 左侧顶部操作行（置顶于行程列表上方） */
.left-actions {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}

/* 添加停靠记录：紧凑、置顶 */
.panel { position: static; width: auto; background: transparent; border: none; box-shadow: none; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0 8px; border-bottom: 1px solid var(--line);
}
.panel-body { padding: 8px 0; }
.pos-row { display: flex; gap: 14px; margin-bottom: 8px; }
.panel-body label.radio {
  color: var(--text); font-weight: 400; display: inline-flex; align-items: center;
  gap: 4px; margin: 0; font-size: 13px; cursor: pointer;
}
.rec-row { display: flex; gap: 6px; align-items: center; }
.rec-row #note-input {
  flex: 1; min-width: 0; font: inherit; font-size: 13px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
}
.rec-row #btn-photo, .rec-row #btn-save { white-space: nowrap; }
#photo-count { font-size: 12px; }
#anchor-hint { margin-top: 6px; }

/* 时间线（绳记）：从出发到结束 */
.timeline {
  border: 1px solid var(--line); border-radius: 10px; margin-top: 8px;
  background: #fff; padding: 10px 12px;
}
#timeline-list { max-height: 46vh; overflow-y: auto; margin-top: 6px; padding-right: 4px; }
.tl { position: relative; padding-left: 20px; }
.tl::before {
  content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 2px; background: #d4dbe4; border-radius: 2px;
}
.node { position: relative; padding: 6px 0 6px 6px; cursor: pointer; border-radius: 8px; }
.node:hover { background: #f4f7fc; }
.node::before {
  content: ''; position: absolute; left: -17px; top: 12px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--primary); border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}
.node.start::before { background: #23a55a; box-shadow: 0 0 0 2px #23a55a; }
.node.end::before { background: #8a94a1; box-shadow: 0 0 0 2px #8a94a1; }
.node-title { font-size: 13px; font-weight: 600; }
.node-time { font-weight: 400; color: var(--muted); font-size: 12px; }
.node-note {
  margin-top: 3px; font-size: 13px; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.node-photos { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.node-photos img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--line); cursor: pointer;
}
.node-photos img:hover { outline: 2px solid var(--primary); }

/* 图片查看器 */
#lightbox { position: fixed; inset: 0; z-index: 3000; }
.lb-bg { position: absolute; inset: 0; background: rgba(0,0,0,.88); }
#lb-img {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  max-width: 92vw; max-height: 88vh; border-radius: 6px;
  box-shadow: 0 6px 30px rgba(0,0,0,.5);
}
.lb-btn {
  position: absolute; z-index: 3001; border: none; background: rgba(0,0,0,.55); color: #fff;
  font-size: 28px; line-height: 1; border-radius: 50%; width: 46px; height: 46px; cursor: pointer;
}
.lb-btn:hover { background: rgba(0,0,0,.8); }
#lb-close { top: 14px; right: 14px; }
#lb-prev { top: 50%; left: 14px; transform: translateY(-50%); }
#lb-next { top: 50%; right: 14px; transform: translateY(-50%); }
.lb-count {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 13px; background: rgba(0,0,0,.55);
  padding: 4px 12px; border-radius: 20px;
}

/* 手机适配 */
@media (max-width: 640px) {
  .side-panel { top: 8px; max-height: calc(100% - 56px); }
  .side-panel.left { left: 8px; width: min(300px, calc(100vw - 16px)); }
  .side-panel.right { right: 8px; width: min(340px, calc(100vw - 16px)); }
  .card { flex-wrap: wrap; }
  .card .actions { width: 100%; margin-left: 0; justify-content: flex-end; }
  .rec-row { flex-wrap: wrap; }
}
