* { box-sizing: border-box; }

:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1c2434;
  --muted: #7d8799;
  --line: #e7ebf2;
  --brand: #3b6df6;
  --brand-soft: #eaf0ff;
  --accent: #ff7a59;
  --shadow: 0 12px 32px rgba(31, 45, 75, .10);
  --radius: 16px;
}

html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  min-height: 560px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 20px 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 500;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px 6px; }
.brand-mark {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, #4f7cff, #7a54f0);
  box-shadow: 0 8px 18px rgba(79, 124, 255, .3);
}
.brand-mark svg { width: 24px; height: 24px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #fcfdff);
}

.field-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.count {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  margin-left: 4px; border-radius: 10px;
  font-size: 11px; color: var(--brand); background: var(--brand-soft);
}

.search-box { position: relative; display: flex; align-items: center; gap: 8px; }
.search-icon { position: absolute; left: 12px; width: 17px; height: 17px; color: #98a2b5; pointer-events: none; }
.search-box input {
  flex: 1; min-width: 0; height: 42px;
  padding: 0 72px 0 36px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.search-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59, 109, 246, .12); }
.add-btn {
  position: absolute; right: 5px; top: 5px;
  height: 32px; padding: 0 12px;
  border: 0; border-radius: 8px;
  color: #fff; font-size: 12px; font-weight: 700;
  background: var(--brand);
}
.add-btn:disabled { opacity: .45; cursor: not-allowed; }

.suggestions {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 6px);
  max-height: 230px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; box-shadow: var(--shadow);
}
.suggestion {
  display: flex; align-items: flex-start; gap: 9px;
  width: 100%; padding: 10px 12px;
  border: 0; border-bottom: 1px solid #f1f3f7;
  background: transparent; text-align: left; color: var(--ink);
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion.active { background: var(--brand-soft); }
.suggestion svg { width: 15px; height: 15px; flex: none; margin-top: 2px; color: var(--brand); }
.suggestion b { display: block; font-size: 13px; font-weight: 600; }
.suggestion small { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); line-height: 1.4; }

.hint { margin: 8px 2px 0; font-size: 11px; color: var(--muted); }
.quick-places { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.quick-place {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: #5d6a80; font-size: 11px; font-weight: 600;
}
.quick-place:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.pick-option { border-top: 1px dashed var(--line) !important; }
.pick-option svg { color: var(--accent); }
.text-btn {
  padding: 4px 0; border: 0; background: none;
  font-size: 12px; font-weight: 600; color: var(--brand);
}
.text-btn:hover { text-decoration: underline; }
.text-btn.danger { color: #ef5b5b; }

.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head .field-label { margin-bottom: 10px; }

.stop-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.stop-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 11px;
  background: #fff;
  transition: border-color .18s, background .18s, opacity .18s;
}
.stop-item.dragging { opacity: .45; border-color: var(--brand); }
.stop-item.drop-target { border-color: var(--brand); background: var(--brand-soft); }
.stop-index {
  width: 25px; height: 25px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 12px; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, #4f7cff, #7a54f0);
}
.stop-item:last-child .stop-index { background: linear-gradient(135deg, #ff8f6b, #ff6a88); }
.stop-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: transparent; color: #97a1b3;
}
.icon-btn:hover { background: #f0f3f9; color: var(--brand); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.icon-btn.remove:hover { background: #fff0f0; color: #ef5b5b; }
.icon-btn svg { width: 14px; height: 14px; }
.drag-handle { cursor: grab; }

.empty-state { padding: 18px 8px 10px; text-align: center; color: var(--muted); }
.empty-state svg { width: 32px; height: 32px; opacity: .5; }
.empty-state p { margin: 6px 0 2px; font-size: 13px; font-weight: 600; color: #98a2b5; }
.empty-state span { font-size: 11px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.primary-btn, .secondary-btn {
  height: 42px; display: flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 10px; font-size: 13px; font-weight: 700;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.primary-btn { border: 0; color: #fff; background: linear-gradient(135deg, #4f7cff, #6f5cf0); box-shadow: 0 8px 18px rgba(79, 124, 255, .28); }
.secondary-btn { border: 1px solid var(--brand); color: var(--brand); background: #fff; }
.primary-btn:hover:not(:disabled), .secondary-btn:hover:not(:disabled) { transform: translateY(-1px); }
.primary-btn:disabled, .secondary-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.primary-btn svg, .secondary-btn svg { width: 16px; height: 16px; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-item {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.summary-item span { display: block; font-size: 11px; color: var(--muted); }
.summary-item strong { display: block; margin-top: 4px; font-size: 16px; color: var(--ink); }

.route-switcher {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.route-switcher button {
  flex: none; padding: 6px 11px; border: 1px solid var(--brand); border-radius: 8px;
  color: var(--brand); background: #fff; font-size: 12px; font-weight: 700;
}
.route-switcher button:hover:not(:disabled) { background: var(--brand-soft); }
.route-switcher button:disabled { opacity: .4; cursor: not-allowed; }
.route-switcher span { font-size: 12px; font-weight: 700; color: var(--ink); }

.sidebar-footer { margin-top: auto; padding: 10px 4px 0; font-size: 10px; color: #a6afbf; text-align: center; }

.map-wrap { position: relative; min-width: 0; height: 100%; }
.map { width: 100%; height: 100%; background: #e9eef5; }
.leaflet-container { font-family: inherit; }
.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-control-zoom a { width: 32px !important; height: 32px !important; line-height: 30px !important; color: var(--ink) !important; }
.leaflet-control-attribution { font-size: 10px !important; background: rgba(255,255,255,.75) !important; }

.map-topbar {
  position: absolute; z-index: 500; top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; gap: 10px; pointer-events: none;
}
.map-badge, .map-status {
  padding: 8px 13px; border: 1px solid rgba(255,255,255,.7); border-radius: 999px;
  background: rgba(255,255,255,.88); box-shadow: 0 6px 18px rgba(31,45,75,.1);
  backdrop-filter: blur(8px); font-size: 12px;
}
.map-badge { display: flex; align-items: center; gap: 7px; font-weight: 700; }
.map-badge i { width: 8px; height: 8px; border-radius: 50%; background: #35c88a; box-shadow: 0 0 0 4px rgba(53,200,138,.16); }
.map-status { color: var(--muted); }

.toast {
  position: absolute; z-index: 1200; left: 50%; bottom: 28px;
  transform: translate(-50%, 16px); opacity: 0;
  padding: 10px 18px; border-radius: 10px;
  color: #fff; font-size: 13px; background: rgba(28,36,52,.92);
  box-shadow: var(--shadow); pointer-events: none;
  transition: opacity .22s, transform .22s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(220, 70, 70, .94); }

.stop-marker {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 2px solid #fff; border-radius: 50%;
  color: #fff; font-size: 12px; font-weight: 700;
  background: linear-gradient(135deg, #4f7cff, #7a54f0);
  box-shadow: 0 4px 10px rgba(31,45,75,.3);
}
.stop-marker.end { background: linear-gradient(135deg, #ff8f6b, #ff6a88); }
.moving-marker {
  width: 16px; height: 16px; border: 3px solid #fff; border-radius: 50%;
  background: #ff7a59; box-shadow: 0 0 0 6px rgba(255,122,89,.25), 0 3px 8px rgba(0,0,0,.25);
}
.route-line { stroke-dasharray: 10 8; animation: dashFlow 1s linear infinite; }
.route-line.fallback { stroke-dasharray: 4 8; }
@keyframes dashFlow { to { stroke-dashoffset: -18; } }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: 100dvh; }
  .sidebar { max-height: 46vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand p { display: none; }
}
