:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #dbe3ef;
  --text: #18212f;
  --muted: #637085;
  --primary: #1f6feb;
  --primary-soft: #e8f0ff;
  --danger: #d93f3f;
  --success: #1b9c5a;
  --shadow: 0 10px 30px rgba(24, 33, 47, 0.08);
  --radius: 20px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
.app-shell { max-width: 1600px; margin: 0 auto; padding: 20px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.topbar h1 { margin: 0 0 6px; font-size: 2rem; }
.topbar p { margin: 0; color: var(--muted); max-width: 800px; }
.badge-group { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 10px 14px;
  background: var(--primary); color: #fff; font-weight: 600;
}
.badge-soft { background: var(--primary-soft); color: var(--primary); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls { padding: 18px; margin-bottom: 16px; }
.control-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 0.92rem; font-weight: 600; }
.field input, .field select, .route-list-header input, .note-input {
  width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fff; color: var(--text);
}
.two-up { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; background: var(--primary); color: #fff; font-weight: 700; cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: #eef3fb; color: var(--text); }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-success { background: #e8fff3; color: var(--success); }
.btn-live { background: #0f172a; color: #fff; }
.helper-text { margin: 12px 2px 0; color: var(--muted); font-size: 0.92rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.95fr); gap: 16px; }
.map-panel { padding: 14px; }
#map { height: calc(100vh - 270px); min-height: 620px; border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
.sidebar { display: flex; flex-direction: column; min-height: calc(100vh - 270px); }
.summary, .next-stop, .route-list-wrap { padding: 18px; border-bottom: 1px solid var(--line); }
.route-list-wrap { border-bottom: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.summary h2, .next-stop h2, .route-list-wrap h2 { margin: 0 0 14px; font-size: 1.1rem; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.summary-grid div { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: #fbfcff; }
.summary-label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.summary-grid strong { font-size: 1.2rem; }
.next-stop-card { border: 1px solid var(--line); border-radius: 18px; padding: 16px; background: linear-gradient(180deg, #fbfdff, #f1f7ff); }
.next-stop-card.empty, .route-list.empty { color: var(--muted); }
.route-list-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.route-list-header input { max-width: 220px; }
.route-list { overflow: auto; padding-right: 2px; }
.route-item {
  border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; background: #fff; transition: 0.2s ease;
}
.route-item.current { border-color: var(--primary); box-shadow: inset 0 0 0 1px rgba(31,111,235,0.08); background: #f8fbff; }
.route-item.visited { background: #f9fbff; }
.route-item.sold { background: #f3fff8; }
.route-title { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 10px; }
.route-title strong { font-size: 1.05rem; }
.status-pill { border-radius: 999px; padding: 8px 12px; font-size: 0.85rem; font-weight: 700; background: #edf2fb; color: #57708c; }
.status-pill.pending { background: #edf2fb; color: #57708c; }
.status-pill.visited { background: #fff6df; color: #a56a00; }
.status-pill.sold { background: #e8fff3; color: var(--success); }
.status-pill.closed { background: #fdecec; color: var(--danger); }
.route-meta { display: grid; gap: 6px; color: var(--muted); font-size: 0.95rem; margin-bottom: 12px; }
.route-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.route-actions button, .route-actions a {
  border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); padding: 10px 14px; text-decoration: none; cursor: pointer; font-weight: 600;
}
.route-actions .active-status { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.route-actions .primary-action { background: var(--primary); color: #fff; border-color: var(--primary); }
.note-input { min-height: 72px; resize: vertical; }
.marker-pin {
  width: 30px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-weight: 800; border: 2px solid #fff; box-shadow: 0 6px 20px rgba(31,111,235,0.35);
}
.marker-pin.nearby-marker { background: #4f8cff; }
.marker-pin.next-marker { background: #0f172a; transform: scale(1.12); }
.live-location-pin {
  width: 18px; height: 18px; border-radius: 999px; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 8px rgba(37,99,235,0.18);
}
.popup-title { font-weight: 800; margin-bottom: 6px; }
.popup-meta { color: var(--muted); display: grid; gap: 3px; }
@media (max-width: 1080px) {
  .control-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout { grid-template-columns: 1fr; }
  #map { height: 420px; min-height: 420px; }
  .sidebar { min-height: auto; }
}
@media (max-width: 640px) {
  .app-shell { padding: 12px; }
  .topbar { flex-direction: column; }
  .topbar h1 { font-size: 1.8rem; }
  .control-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .route-list-header { flex-direction: column; align-items: stretch; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .btn { width: 100%; }
}
