:root {
  --bg: #111827;
  --card: #1f2937;
  --accent: #1b6e4f;
  --accent-light: #2f9e6f;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: 88px; /* room for sticky Optimize button */
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 16px) 16px 12px;
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.2rem; margin: 0; }

.icon-btn {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

main { padding: 12px 16px; }

#add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

#address-input {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #374151;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

button, .scan-btn, .primary-btn {
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#add-form button {
  background: var(--accent);
  color: white;
}

.scan-btn {
  display: block;
  text-align: center;
  background: var(--card);
  color: var(--text);
  border: 1px dashed var(--muted);
  margin-bottom: 12px;
}

#status-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}
#status-msg.error { color: #f87171; }
#status-msg.success { color: var(--accent-light); }

#map {
  height: 220px;
  border-radius: 12px;
  margin-bottom: 16px;
}

#end-mode-section {
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#end-mode-section label {
  font-size: 0.85rem;
  color: var(--muted);
}

#end-mode-select, #end-address-input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #374151;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}

#stop-list-section h2 {
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 8px;
}

#stop-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stop-card {
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.stop-card.completed { opacity: 0.45; }

.stop-order {
  background: var(--accent);
  color: white;
  border-radius: 50%;
  min-width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.stop-info { flex: 1; min-width: 0; }
.stop-address { font-weight: 600; word-break: break-word; }
.stop-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.stop-meta .no-geo { color: #f87171; }

.pickup-badge, .eta-badge {
  display: inline-block;
  margin: 4px 4px 0 0;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pickup-badge { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.eta-badge    { background: rgba(156, 163, 175, 0.16); color: var(--muted); }
.infeasible   { color: #f87171; }

/* Tip history from shipt-map — colored by average so a bad address reads at
   a glance while driving, without having to parse the numbers. */
.tip-history {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.4;
}
.tip-good    { background: rgba(39, 174, 96, 0.16);  color: #4ade80; }
.tip-ok      { background: rgba(243, 156, 18, 0.16); color: #fbbf24; }
.tip-bad     { background: rgba(231, 76, 60, 0.16);  color: #f87171; }
.tip-unknown { background: rgba(156, 163, 175, 0.14); color: var(--muted); }

/* Move buttons bracket the order badge, so position and the controls that
   change it sit together instead of competing with Edit/Done/Remove. */
.stop-move {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.stop-move button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1;
  padding: 5px 8px;
  cursor: pointer;
}

.stop-move button:disabled { opacity: 0.25; }

.stop-edit {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stop-edit input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.9rem;
  width: 100%;
}

.edit-actions { display: flex; gap: 8px; }

.edit-actions button {
  flex: 1;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.85rem;
  border: 1px solid #374151;
  background: none;
  color: var(--muted);
}

.edit-actions button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text);
}

.stop-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.stop-actions button, .stop-actions a {
  background: none;
  border: 1px solid #374151;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
  text-decoration: none;
  text-align: center;
}

.stop-actions .danger { border-color: var(--danger); color: #f87171; }

/* Driving mode: one stop, large targets, nothing else competing for a glance. */
#drive-section {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#drive-progress { color: var(--muted); font-size: 0.85rem; }
.drive-address { font-size: 1.35rem; font-weight: 700; line-height: 1.25; word-break: break-word; }
.drive-meta { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.drive-warn { color: #f87171; font-size: 0.85rem; margin-top: 6px; }

.drive-row { display: flex; gap: 10px; }
.drive-row > * { flex: 1; }

#drive-section button, #drive-section select {
  background: var(--card);
  color: var(--text);
  border: 1px solid #374151;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.95rem;
}

#drive-done { background: var(--accent); border-color: var(--accent); font-weight: 600; }
#drive-nav { text-align: center; }

#result-section {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin: 16px 0;
}

#route-summary { margin-bottom: 10px; font-size: 0.95rem; }
#route-summary .estimate-note { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

.primary-btn {
  display: block;
  width: 100%;
  background: var(--accent);
  color: white;
  text-align: center;
  text-decoration: none;
}

.sticky-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 0;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
}

/* Address autocomplete. One dropdown serves every data-autocomplete field,
   and lives directly on <body> so the clipped containers it floats over
   (the edit form, the end-mode section) can't cut it off — hence the
   absolute positioning set in JS and the z-index above the sticky header. */
#suggest-box {
  position: absolute;
  z-index: 50;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 45vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid #374151;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

#suggest-box li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  /* Comfortably tappable with a thumb while the keyboard is up. */
  padding: 10px 10px;
  border-radius: 7px;
  font-size: 0.85rem;
  cursor: pointer;
}

#suggest-box li.active,
#suggest-box li:hover { background: rgba(47, 158, 111, 0.18); }

.suggest-tip {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--accent-light);
}
