/* ── CSS custom properties ─────────────────────────────────────────────── */
:root {
  --primary:        #1a73e8;
  --primary-dark:   #1557b0;
  --success:        #34a853;
  --warning:        #fbbc04;
  --danger:         #ea4335;
  --spot-color:     #ff6b35;
  --bg:             #f8f9fa;
  --surface:        #ffffff;
  --border:         #dadce0;
  --text:           #202124;
  --text-muted:     #5f6368;
  --sidebar-w:      360px;
  --topbar-h:       56px;
  --radius:         8px;
  --shadow:         0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,.15);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 200;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}
.topbar-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { color: var(--primary); background: #e8f0fe; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* ── Sidebar sections ──────────────────────────────────────────────────── */
.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; flex: 1; overflow-y: auto; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.section-count {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }
.btn-icon {
  padding: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 4px;
  line-height: 1;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Spot list ─────────────────────────────────────────────────────────── */
.spot-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.spot-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
  border: 1px solid transparent;
}
.spot-item:hover { background: var(--bg); }
.spot-item.selected {
  background: #fff3ee;
  border-color: var(--spot-color);
}
.spot-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--spot-color);
  flex-shrink: 0;
}
.spot-item.selected .spot-icon { width: 10px; height: 10px; }
.spot-name { flex: 1; font-weight: 500; font-size: 13px; }
.spot-addr { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.spot-del { opacity: 0; }
.spot-item:hover .spot-del { opacity: 1; }

/* ── Distance panel ────────────────────────────────────────────────────── */
.distance-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 16px;
}
.distance-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}
.distance-title { font-weight: 600; font-size: 14px; }
.distance-addr { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Mode bar */
.mode-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 3px;
}
.mode-btn {
  flex: 1;
  padding: 5px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 16px;
  transition: background .12s;
}
.mode-btn.active { background: var(--surface); box-shadow: var(--shadow); }
.mode-btn:hover:not(.active) { background: var(--border); }

/* Departure */
.depart-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.depart-row label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.depart-row input[type="datetime-local"] {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
}

/* Distance table */
.distance-table-wrap { flex: 1; overflow-y: auto; }
table.dist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.dist-table th {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.dist-table th:hover { color: var(--text); }
.dist-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.dist-table tbody tr:hover { background: var(--bg); }
.dist-table .friend-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.cache-badge {
  font-size: 9px;
  background: #e8f0fe;
  color: var(--primary);
  border-radius: 3px;
  padding: 1px 4px;
  vertical-align: middle;
}
.no-route { color: var(--text-muted); font-style: italic; }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.stat-item { display: flex; flex-direction: column; }
.stat-label { color: var(--text-muted); font-size: 11px; }
.stat-value { font-weight: 600; font-size: 13px; }

/* Spinner */
.spinner-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 10px;
  color: var(--text-muted);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Compare button */
.compare-btn {
  margin-top: 6px;
  width: 100%;
}

/* ── Map overlay ───────────────────────────────────────────────────────── */
.search-box-wrap {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(420px, calc(100% - 32px));
}
#searchInput {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  outline: none;
  background: #fff;
}
#searchInput:focus { box-shadow: 0 0 0 3px rgba(26,115,232,.3), var(--shadow-md); }

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 24px;
  width: min(440px, calc(100vw - 32px));
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in .18s ease;
}
.modal-wide { width: min(900px, calc(100vw - 32px)); }
@keyframes modal-in {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.modal-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,.2);
}
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
  background: none;
}

/* ── Friends page ──────────────────────────────────────────────────────── */
.friends-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.friends-list-panel {
  width: 400px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
  flex-shrink: 0;
}
.friends-form-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}
.friend-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  cursor: pointer;
}
.friend-card:hover { background: var(--bg); }
.friend-card.selected { background: #e8f0fe; }
.friend-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
}
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-weight: 500; font-size: 14px; }
.friend-addr { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friends-form-panel h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
}
.list-header-title { font-weight: 600; font-size: 15px; }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}
.empty-state svg { opacity: .3; }

/* ── Compare modal ─────────────────────────────────────────────────────── */
.compare-table-wrap { overflow-x: auto; }
.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 400px;
}
.compare-table th, .compare-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
.compare-table th:first-child,
.compare-table td:first-child { text-align: left; }
.compare-table th { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--text-muted); }
.row-fairest td { background: #f0faf4; font-weight: 500; }
.row-fairest td:first-child { color: var(--success); }
.col-stat { background: var(--bg) !important; font-weight: 600 !important; }
.fairest-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e6f4ea;
  color: var(--success);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ── Toasts ────────────────────────────────────────────────────────────── */
#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #323232;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  max-width: 320px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: auto;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.toast-error   { background: #b3261e; }
.toast.toast-success { background: var(--success); }
.toast.toast-warning { background: #8c6300; }

/* ── Rideshare columns ─────────────────────────────────────────────────── */
.th-uber { color: #000 !important; }
.th-lyft { color: #ff00bf !important; }
.ride-cell { font-size: 12px; white-space: nowrap; }
.ride-uber { color: #000; font-weight: 500; }
.ride-lyft { color: #c00891; font-weight: 500; }
.ride-loading { color: var(--text-muted); font-style: italic; }

/* ── Toll column ───────────────────────────────────────────────────────── */
.th-tolls { color: #b45309 !important; }
.toll-cell { font-size: 12px; white-space: nowrap; }
.toll-loading { color: var(--text-muted); font-style: italic; }
.no-tolls  { color: var(--success); font-weight: 500; }
.has-tolls { color: #b45309; font-weight: 500; }

/* ── Utility ───────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
