/* ============================================================
   Benny Trip Planner — mobile-first dark theme
   ============================================================ */

:root {
  --bg:        #1a1a2e;
  --surface:   #16213e;
  --surface2:  #0f3460;
  --accent:    #f0a500;
  --accent2:   #e94560;
  --text:      #eaeaea;
  --muted:     #8892a4;
  --radius:    12px;
  --score-hi:  #4caf50;
  --score-mid: #ff9800;
  --score-lo:  #607d8b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  z-index: 10;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.badge {
  font-size: 0.78rem;
  background: var(--surface2);
  border-radius: 20px;
  padding: 4px 10px;
  color: var(--muted);
}
.badge.located { color: var(--accent); }
.badge.stale   { color: var(--accent2); }

/* ── Map ── */
#map {
  flex: 0 0 42dvh;
  min-height: 180px;
}

/* ── Shortlist ── */
#shortlist {
  flex: 1 1 auto;
  overflow-y: auto;
  background: var(--bg);
  padding-bottom: 4px;
}

.shortlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.shortlist-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#rescore-btn {
  background: none;
  border: 1px solid var(--surface2);
  color: var(--accent);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
#rescore-btn:active { opacity: 0.7; }

/* ── Stop cards ── */
#stop-cards { padding: 0 12px; }

.stop-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  border-left: 4px solid var(--score-lo);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.stop-card:active { background: var(--surface2); }
.stop-card.rank-1 { border-left-color: var(--score-hi); }
.stop-card.rank-2 { border-left-color: var(--score-mid); }
.stop-card.rank-3 { border-left-color: var(--score-mid); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.rank-1 .card-rank { background: var(--score-hi); color: #000; }
.rank-2 .card-rank { background: var(--score-mid); color: #000; }

.card-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}

.card-score {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  font-size: 0.72rem;
  background: var(--surface2);
  border-radius: 6px;
  padding: 2px 8px;
  color: var(--muted);
}
.chip.accent { color: var(--accent); }
.chip.bad    { color: var(--accent2); }

.card-footer {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-nav {
  flex: 1;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.btn-nav:active { opacity: 0.8; }

.btn-detail {
  background: var(--surface2);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Controls panel ── */
#controls-panel {
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  flex-shrink: 0;
  max-height: 52px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
#controls-panel.open { max-height: 70dvh; overflow-y: auto; }

.panel-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.04em;
}
.panel-toggle .toggle-arrow { margin-left: auto; transition: transform 0.3s; }
#controls-panel.open .toggle-arrow { transform: rotate(180deg); }

.panel-body {
  padding: 0 16px 16px;
}

.control-row {
  margin-bottom: 16px;
}

.control-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-row label span {
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface2);
  border-radius: 4px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
}
.slider-row input { flex: 1; }

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toggle-row label:first-child { margin-bottom: 0; }

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track::before { transform: translateX(20px); }

/* ── Night log ── */
.section-title {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--surface2);
  padding-top: 14px;
}

.night-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 0.82rem;
}
.night-entry .night-name { flex: 1; }
.night-entry .night-date { color: var(--muted); font-size: 0.75rem; margin-right: 8px; }
.night-entry button {
  background: none;
  border: none;
  color: var(--accent2);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 4px;
}

.btn-add-night {
  background: none;
  border: 1px dashed var(--surface2);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
}

/* ── Detour search ── */
.detour-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.detour-row input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.85rem;
  outline: none;
}
.detour-row input:focus { border-color: var(--accent); }
.detour-row button {
  background: var(--surface2);
  border: none;
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#clear-detour-btn {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 0;
  display: none;
}
#clear-detour-btn.visible { display: block; }

.detour-results {
  background: var(--surface2);
  border-radius: 8px;
  margin-top: 6px;
  overflow: hidden;
  display: none;
}
.detour-results.visible { display: block; }
.detour-result-item {
  padding: 9px 12px;
  font-size: 0.83rem;
  cursor: pointer;
  border-bottom: 1px solid var(--surface);
}
.detour-result-item:last-child { border-bottom: none; }
.detour-result-item:active { background: var(--surface); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
}
.modal-overlay.hidden { display: none; }

.modal-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 20px 16px 32px;
}

.modal-close {
  position: absolute;
  right: 16px;
  top: 16px;
  background: var(--surface2);
  border: none;
  color: var(--text);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
}

.modal-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.modal-location { color: var(--muted); font-size: 0.85rem; margin-bottom: 12px; }

.score-bar {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.score-bar-title { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.score-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 3px;
}
.score-row span:last-child {
  font-weight: 600;
  color: var(--accent);
}
.score-row span.neg { color: var(--accent2); }

.modal-notes {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 12px;
}
.modal-pois {
  font-size: 0.82rem;
  margin-bottom: 16px;
}
.modal-pois span { color: var(--muted); }

.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn-nav { font-size: 0.9rem; padding: 12px; }
.btn-sleep-here {
  background: var(--surface2);
  border: none;
  color: var(--text);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ── Loading overlay ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  gap: 16px;
  transition: opacity 0.4s;
}
#loading.hidden { opacity: 0; pointer-events: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { color: var(--muted); font-size: 0.85rem; }

/* ── MapLibre overrides ── */
.maplibregl-map { font-family: inherit; }
.maplibregl-ctrl-logo { display: none !important; }

/* ── Position marker ── */
.pos-marker {
  width: 16px;
  height: 16px;
  background: #4fc3f7;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(79,195,247,0.3);
}

/* ── Stop markers ── */
.stop-marker {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.stop-marker-inner {
  transform: rotate(45deg);
  font-size: 0.75rem;
  font-weight: 700;
  color: #000;
}
.stop-marker.hi  { background: var(--score-hi); }
.stop-marker.mid { background: var(--score-mid); }
.stop-marker.lo  { background: var(--score-lo); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }

/* ============================================================
   V2 additions — trip bar + trip setup
   ============================================================ */

/* ── Trip bar ── */
.trip-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: var(--surface2);
  font-size: 0.82rem;
  font-weight: 600;
  flex-shrink: 0;
}
.trip-bar.hidden { display: none; }
.trip-bar .trip-stats {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.75rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trip-bar button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
}

/* ── Trip setup overlay ── */
#trip-setup { align-items: center; }
#trip-setup .modal-sheet {
  border-radius: var(--radius);
  max-width: 440px;
  margin: 0 16px;
}

.trip-field { margin-bottom: 14px; position: relative; }
.trip-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.trip-field input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 0.95rem;
  outline: none;
}
.trip-field input:focus { border-color: var(--accent); }
.trip-field .detour-results { margin-top: 4px; }

.btn-inline {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 6px 0 0;
}

.trip-status {
  min-height: 20px;
  font-size: 0.82rem;
  color: var(--accent);
  margin-bottom: 10px;
}
.trip-status.error { color: var(--accent2); }

.btn-nav:disabled { opacity: 0.4; cursor: default; }
