/* Geo Dashboard — Mobile-first styles */
:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --card: #1f2b47;
  --accent: #0f3460;
  --primary: #4fc3f7;
  --primary-dim: #2196f3;
  --green: #66bb6a;
  --orange: #ffa726;
  --red: #ef5350;
  --text: #e0e0e0;
  --text-dim: #9e9e9e;
  --border: #2a3a5c;
  --radius: 8px;
  --topbar-h: 56px;
  --sidebar-w: 380px;
}

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

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

/* ---- Top bar ---- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  position: relative;
}

.topbar .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.search-box {
  flex: 1;
  display: flex;
  gap: 4px;
}

.search-box input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
}

.search-box button, .btn {
  background: var(--primary-dim);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s;
}

.search-box button:hover, .btn:hover {
  background: var(--primary);
}

.btn-icon, #btn-home {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  padding: 0;
}

.btn-icon:hover, #btn-home:hover { background: var(--accent); }
#btn-home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; border-radius: 6px; font-size: 18px; cursor: pointer; }
.btn-icon.active { background: var(--primary-dim); color: #fff; }

/* ---- Main layout ---- */
.main {
  display: flex;
  height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s;
}

.sidebar.collapsed {
  width: 0;
  border: none;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.sidebar-tabs button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 4px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.sidebar-tabs button:hover {
  color: var(--text);
}

.sidebar-tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* ---- Result cards ---- */
.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.result-card:hover {
  border-color: var(--primary);
}

.result-card .name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}

.result-card .meta {
  font-size: 12px;
  color: var(--text-dim);
}

.result-card .distance {
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
}

.result-card .type-badge {
  display: inline-block;
  font-size: 10px;
  background: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 4px;
}

.result-card .stars {
  color: var(--orange);
}

/* ---- Transit schedule ---- */
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
}

.schedule-table th, .schedule-table td {
  padding: 4px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.schedule-table th {
  color: var(--primary);
  font-weight: 600;
}

/* ---- Trail card extras ---- */
.trail-difficulty {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.trail-difficulty.t1 { background: #2e7d32; }
.trail-difficulty.t2 { background: #558b2f; }
.trail-difficulty.t3 { background: #f9a825; color: #000; }
.trail-difficulty.t4 { background: #e65100; }
.trail-difficulty.t5 { background: #b71c1c; }
.trail-difficulty.t6 { background: #4a148c; }

/* ---- Map ---- */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* ---- Map overlays ---- */
.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 800;
}

.layer-toggle {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-toggle:hover { background: var(--accent); }
.layer-toggle.active { border-color: var(--primary); color: var(--primary); }

/* ---- Tile switcher ---- */
.tile-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 200px;
}
.tile-switcher button {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
}
.tile-switcher button:hover { background: var(--accent); color: var(--text); }
.tile-switcher button.active { border-color: var(--primary); color: var(--primary); }

/* ---- Popup ---- */
.leaflet-popup-content-wrapper {
  background: var(--card) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
}

.leaflet-popup-tip { background: var(--card) !important; }

.leaflet-popup-content { font-size: 13px; line-height: 1.4; }
.leaflet-popup-content .popup-title { font-weight: 700; font-size: 14px; }
.leaflet-popup-content .popup-meta { color: var(--text-dim); font-size: 11px; }
.leaflet-popup-content a { color: var(--primary); }

/* ---- Status bar ---- */
.status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(22, 33, 62, 0.9);
  padding: 4px 12px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  z-index: 800;
}

/* ---- Loading ---- */
.loading {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-dim);
}

.empty-state .icon { font-size: 36px; margin-bottom: 8px; }

/* ---- Custom place form (modal) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 90%;
  max-width: 400px;
}

.modal h3 { margin-bottom: 12px; }

.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  margin-bottom: 2px;
}

.modal input, .modal select, .modal textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: 4px;
  font-size: 14px;
}

.modal textarea { height: 60px; resize: vertical; }

.modal .btn-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
}

.modal .btn-secondary {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* ---- Responsive ---- */
/* ---- Floating GPS button ---- */
.gps-float {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: var(--primary-dim);
  color: #fff;
  border: 2px solid var(--primary);
  border-radius: 50px;
  padding: 12px 28px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: background 0.15s, transform 0.1s;
}
.gps-float:hover { background: var(--primary); }
.gps-float:active { transform: translateX(-50%) scale(0.95); }
.gps-flob.active { opacity: 0.7; }

/* ---- Radius control ---- */
.radius-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.radius-control label {
  display: none; /* hide label on mobile, show on desktop */
}
.radius-control input[type=range] {
  width: 70px;
  height: 4px;
  accent-color: var(--primary);
}
.radius-control span {
  min-width: 35px;
  font-size: 11px;
}

/* ---- Search this area button ---- */
.search-area-btn {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: var(--card);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: background 0.15s;
}
.search-area-btn:hover {
  background: var(--accent);
}

/* Elevation panel */
.elevation-panel {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 420px;
  max-width: 90vw;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.elevation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.elevation-title { font-weight: 600; font-size: 14px; }
.elevation-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 0 4px;
}
.elevation-close:hover { color: var(--text); }
.elevation-stats {
  display: flex; gap: 12px; justify-content: center;
  font-size: 12px; color: var(--text-muted); margin-top: 6px;
}
#el-gain { color: #4caf50; }
#el-loss { color: #f44336; }

/* Route controls */
.route-controls {
  margin-bottom: 10px;
}
.mode-toggle {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.mode-toggle label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.route-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.btn-small {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-small:hover {
  background: var(--accent);
}
.measure-stats {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.measure-stats div {
  margin-bottom: 2px;
}
.measure-stats span {
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 900;
  }
  .sidebar.collapsed { width: 0; }
  .topbar .logo { display: none; }
}

/* ---------------------------------------------------------------------------
   Light Theme
   --------------------------------------------------------------------------- */
:root[data-theme="light"] {
  --bg: #f5f5f5;
  --bg2: #ffffff;
  --card: #ffffff;
  --accent: #e3f2fd;
  --border: #e0e0e0;
  --text: #212121;
  --text-dim: #757575;
}

:root[data-theme="light"] .sidebar { background: var(--bg2); border-color: var(--border); }
:root[data-theme="light"] .topbar { background: var(--bg2); border-color: var(--border); }
:root[data-theme="light"] .search-box input { background: var(--card); color: var(--text); border-color: var(--border); }
:root[data-theme="light"] .result-card { background: var(--card); border-color: var(--border); }
:root[data-theme="light"] .btn-icon { background: var(--card); color: var(--text); }
:root[data-theme="light"] .layer-toggle { background: var(--card); color: var(--text); border-color: var(--border); }
:root[data-theme="light"] .layer-toggle.active { background: var(--accent); color: var(--primary-dim); }
:root[data-theme="light"] .status-bar { background: var(--bg2); color: var(--text-dim); }
:root[data-theme="light"] .modal { background: var(--bg2); color: var(--text); }

/* ---------------------------------------------------------------------------
   Legend Modal
   --------------------------------------------------------------------------- */
.legend-modal-content {
  max-width: 420px;
  width: 90vw;
}
.legend-grid {
  display: grid;
  gap: 12px;
  padding: 16px 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--card);
}
.legend-icon {
  font-size: 24px;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}
.legend-info {
  display: flex;
  flex-direction: column;
}
.legend-info strong { font-size: 14px; }
.legend-info span { font-size: 12px; color: var(--text-dim); }

/* ---------------------------------------------------------------------------
   Search History Dropdown
   --------------------------------------------------------------------------- */
.search-history-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
}
.search-box { position: relative; }
.history-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text);
}
.history-item:hover { background: var(--accent); }
.history-query { flex: 1; }
.history-time { color: var(--text-dim); font-size: 11px; }
.history-clear { justify-content: center; color: var(--red); }

/* ---------------------------------------------------------------------------
   Category Filter
   --------------------------------------------------------------------------- */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.cat-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.cat-btn:hover { border-color: var(--primary); }
.cat-btn.active {
  background: var(--accent);
  border-color: var(--primary);
  color: var(--primary);
}
.cat-count { font-size: 10px; opacity: 0.6; }
