* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #333;
}

body {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 100vh;
}

/* ===== SIDEBAR ===== */

#sidebar {
  background: #fff;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  z-index: 1;
  position: relative;
}

header {
  margin-bottom: 24px;
  border-bottom: 2px solid #f0f0f0;
  padding-bottom: 16px;
}

header h1 {
  margin: 0 0 4px 0;
  font-size: 24px;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  font-size: 12px;
  color: #999;
}

/* ===== CONTROLS ===== */

#controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

label {
  display: block;
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 6px;
  color: #555;
}

#search-group {
  position: relative;
}

#location-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#location-input:focus {
  border-color: #1A73E8;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}

.search-result {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.search-result:hover {
  background: #f5f5f5;
}

.search-result:last-child {
  border-bottom: none;
}

#distance-group {
  display: flex;
  flex-direction: column;
}

#distance-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #e0e0e0;
  outline: none;
  border-radius: 3px;
  accent-color: #1A73E8;
}

#distance-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #1A73E8;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#distance-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #1A73E8;
  cursor: pointer;
  border-radius: 50%;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#mode-group {
  border: none;
  padding: 0;
  margin: 0;
}

#mode-group legend {
  font-weight: 500;
  font-size: 13px;
  color: #555;
  padding: 0;
  margin-bottom: 8px;
  display: block;
}

#mode-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-weight: 400;
}

#mode-group input[type="radio"] {
  margin: 0;
  cursor: pointer;
  accent-color: #1A73E8;
}

/* ===== BUTTONS ===== */

button {
  padding: 10px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-btn {
  width: 100%;
  background: #1A73E8;
  color: white;
}

.primary-btn:hover:not(:disabled) {
  background: #1557b0;
  box-shadow: 0 2px 4px rgba(26, 115, 232, 0.3);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.secondary-btn {
  width: 100%;
  background: #f0f0f0;
  color: #333;
}

.secondary-btn:hover {
  background: #e0e0e0;
}

.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  color: #999;
  font-size: 20px;
  line-height: 1;
}

.close-btn:hover {
  color: #333;
}

/* ===== RESULTS ===== */

#results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: #f9f9f9;
  border: 1px solid #f0f0f0;
  border-radius: 4px;
  padding: 12px;
}

#route-info p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.5;
}

#route-info p:first-child {
  margin-top: 0;
}

#route-info p:last-child {
  margin-bottom: 0;
}

#result-distance {
  font-size: 16px;
  font-weight: 600;
  color: #1A73E8;
}

#result-accuracy {
  font-size: 12px;
  color: #999;
}

#alternate-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alt-btn {
  flex: 1;
  min-width: 80px;
  padding: 8px 12px;
  background: #f0f0f0;
  color: #333;
  font-size: 12px;
  border-radius: 3px;
}

.alt-btn:hover {
  background: #e0e0e0;
}

.alt-btn.active {
  background: #1A73E8;
  color: white;
}

#export-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

#export-btns button {
  width: 100%;
}

/* ===== ERROR ===== */

.error-card {
  position: relative;
  background: #fce4e4;
  border: 1px solid #f5a6a6;
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 16px;
}

#error-message {
  margin: 0;
  font-size: 13px;
  color: #d32f2f;
  line-height: 1.4;
}

/* ===== LOADING OVERLAY ===== */

#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  border-radius: 0;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e0e0e0;
  border-top-color: #1A73E8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loading-text {
  margin-top: 16px;
  font-size: 13px;
  color: #666;
  font-weight: 500;
}

/* ===== MAP ===== */

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

.leaflet-container {
  font-family: inherit;
  font-size: 12px;
}

/* Custom marker styling */

.start-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #4CAF50;
  border: 3px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.start-marker::before {
  content: '📍';
  font-size: 16px;
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  #sidebar {
    grid-column: 1;
    grid-row: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-height: 50vh;
  }

  #map {
    grid-column: 1;
    grid-row: 2;
  }

  header {
    margin-bottom: 16px;
  }

  #controls {
    gap: 12px;
  }

  .subtitle {
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  header h1 {
    font-size: 20px;
  }

  #sidebar {
    padding: 16px;
  }

  button {
    font-size: 13px;
    padding: 9px 12px;
  }
}

/* ===== UTILITIES ===== */

[hidden] {
  display: none !important;
}

/* Scrollbar styling for sidebar */
#sidebar::-webkit-scrollbar {
  width: 6px;
}

#sidebar::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
  background: #999;
}
