/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
  --sidebar-width: 320px;
}

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

/* ===== Layout ===== */
#app {
  display: flex;
  height: 100vh;
}

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: margin-left 0.3s ease, min-width 0.3s ease, width 0.3s ease;
  z-index: 1000;
}

#sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  min-width: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  z-index: 1;
}

.sidebar-header h1 {
  font-size: 1.2rem;
  white-space: nowrap;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s;
  width: 100%;
  margin-bottom: 6px;
}
.btn-outline:hover {
  background: var(--bg);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius);
  color: var(--text-muted);
}
.btn-icon:hover {
  background: var(--bg);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* ===== Spot List ===== */
.spot-list {
  max-height: 250px;
  overflow-y: auto;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
}

.spot-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.spot-item:hover {
  background: var(--bg);
}

.spot-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.spot-info {
  flex: 1;
  min-width: 0;
}

.spot-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spot-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.spot-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ===== Route Controls ===== */
.route-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.route-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: white;
  cursor: pointer;
}

.route-btn-group {
  display: flex;
  gap: 8px;
}

.route-btn-group .btn {
  flex: 1;
}

.route-info {
  margin-top: 8px;
  padding: 10px;
  background: #eff6ff;
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: none;
}

.route-info.visible {
  display: block;
}

.route-info strong {
  color: var(--primary);
}

/* ===== Tool Buttons ===== */
.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ===== Offline Status ===== */
.offline-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.offline-status.online {
  background: #f0fdf4;
  color: #166534;
}

.offline-status.offline {
  background: #fef2f2;
  color: #991b1b;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.cache-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Map ===== */
#map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal-content label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.modal-content input[type="text"],
.modal-content select,
.modal-content textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 12px;
  font-family: inherit;
}

.modal-content textarea {
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ===== Rating Input ===== */
.rating-input {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 2px;
  margin-bottom: 12px;
}

.rating-input input {
  display: none;
}

.rating-input label {
  font-size: 1.5rem;
  color: #cbd5e1;
  cursor: pointer;
  transition: color 0.15s;
  margin-bottom: 0;
}

.rating-input label:hover,
.rating-input label:hover ~ label,
.rating-input input:checked ~ label {
  color: #f59e0b;
}

/* ===== Custom Leaflet Popup ===== */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.popup-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.popup-type {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.popup-rating {
  color: #f59e0b;
  margin: 4px 0;
}

.popup-notes {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

/* ===== Toggle Map Button (when sidebar collapsed) ===== */
#expand-sidebar {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  background: white;
  border: 2px solid rgba(0,0,0,0.2);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  display: none;
}

#sidebar.collapsed ~ #map-container #expand-sidebar {
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
  }

  #app {
    flex-direction: column;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1500;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  }

  #sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
  }

  #map-container {
    width: 100%;
    height: 100vh;
  }
}

/* ===== Leaflet routing machine override ===== */
.leaflet-routing-container {
  display: none !important;
}
