/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2196F3;
  --primary-dark: #1976D2;
  --success-color: #4CAF50;
  --warning-color: #FF9800;
  --danger-color: #F44336;
  --text-primary: #212121;
  --text-secondary: #757575;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F5F5F5;
  --border-color: #E0E0E0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.2);
  --header-height: 60px;
  --drawer-height: 400px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg-secondary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--primary-color);
  color: white;
  box-shadow: var(--shadow);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.route-name {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success-color);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Map Container */
.map-container {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: var(--drawer-height);
  z-index: 1;
}

/* Bottom Drawer */
.bottom-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--drawer-height);
  background: var(--bg-primary);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  overflow: hidden;
  transition: var(--transition);
}

.drawer-handle {
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 8px auto;
  cursor: grab;
}

.drawer-content {
  height: calc(100% - 20px);
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}

/* Sections */
.progress-section,
.controls-section,
.layers-section,
.milestones-section {
  margin-bottom: 24px;
}

.progress-section h3,
.controls-section h3,
.layers-section h3,
.milestones-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* Progress */
.milestone-progress {
  margin-bottom: 12px;
}

.progress-text {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--primary-dark));
  transition: width 0.5s ease;
}

.next-milestone {
  font-size: 14px;
  color: var(--text-primary);
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.next-milestone strong {
  color: var(--primary-color);
}

/* Controls */
.control-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.control-item:last-child {
  border-bottom: none;
}

.control-label {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.control-info {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: var(--transition);
  border-radius: 28px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* Layer Toggles */
.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.layer-item:hover {
  background: var(--border-color);
}

.layer-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.layer-name {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.layer-color {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Milestones List */
.milestones-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.milestone-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  transition: var(--transition);
}

.milestone-item.visited {
  background: rgba(76, 175, 80, 0.1);
  border-left: 4px solid var(--success-color);
}

.milestone-item.active {
  background: rgba(33, 150, 243, 0.1);
  border-left: 4px solid var(--primary-color);
}

.milestone-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.milestone-item.visited .milestone-number {
  background: var(--success-color);
}

.milestone-info {
  flex: 1;
}

.milestone-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.milestone-details {
  font-size: 12px;
  color: var(--text-secondary);
}

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

/* Map Control Buttons */
.map-controls {
  position: fixed;
  bottom: calc(var(--drawer-height) + 16px);
  right: 76px; /* Shifted left to avoid zoom controls */
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 998;
}

.map-control-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.map-control-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.map-control-btn:active {
  transform: scale(0.95);
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-overlay p {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 768px) {
  .route-name {
    font-size: 16px;
  }

  .bottom-drawer {
    --drawer-height: 350px;
  }
}

@media (max-width: 480px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .route-name {
    max-width: 100%;
  }

  .status-indicator {
    font-size: 11px;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-primary: #E0E0E0;
    --text-secondary: #B0B0B0;
    --bg-primary: #1E1E1E;
    --bg-secondary: #2D2D2D;
    --border-color: #404040;
  }

  .status-indicator {
    background: rgba(0, 0, 0, 0.3);
  }

  .toggle-slider {
    background-color: #555;
  }

  .trip-card {
    background: #2A2A2A;
  }

  .modal-content {
    background: var(--bg-primary);
  }

  .form-control {
    background: #2A2A2A;
    border-color: var(--border-color);
    color: var(--text-primary);
  }
}

/* ========================================
   TRIP SELECTION UI
   ======================================== */

/* Trip Selection Screen */
.trip-selection-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-secondary);
  z-index: 2000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.trip-selection-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.trip-selection-header {
  text-align: center;
  padding: 40px 0 20px;
}

.trip-selection-header h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.trip-selection-header .subtitle {
  font-size: 16px;
  color: var(--text-secondary);
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  margin-bottom: 24px;
  opacity: 0.3;
}

.empty-icon svg {
  stroke: var(--text-secondary);
}

.empty-state h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 16px;
  color: var(--text-secondary);
}

/* Trips List */
.trips-list {
  flex: 1;
  padding: 20px 0;
}

/* Trip Card */
.trip-card {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
}

.trip-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-color);
}

.trip-card:active {
  transform: translateY(0);
}

.trip-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.trip-card-title {
  flex: 1;
}

.trip-card-title h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.trip-card-title p {
  font-size: 14px;
  color: var(--text-secondary);
}

.trip-status-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.trip-status-badge.planned {
  background: #E3F2FD;
  color: #1976D2;
}

.trip-status-badge.in-progress {
  background: #FFF3E0;
  color: #F57C00;
}

.trip-status-badge.completed {
  background: #E8F5E9;
  color: #388E3C;
}

.trip-status-badge.archived {
  background: #F5F5F5;
  color: #757575;
}

.trip-card-meta {
  display: flex;
  gap: 16px;
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 12px;
}

.trip-card-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trip-card-meta-item svg {
  width: 16px;
  height: 16px;
  stroke: var(--text-secondary);
}

/* Create Trip Button */
.btn-create-trip {
  position: sticky;
  bottom: 20px;
  width: 100%;
  padding: 16px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: auto;
}

.btn-create-trip:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

.btn-create-trip:active {
  transform: translateY(0);
}

.btn-create-trip svg {
  width: 24px;
  height: 24px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
  color: var(--text-secondary);
}

.modal-close:hover {
  background: var(--bg-secondary);
}

.modal-close svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  padding: 24px;
  border-top: 1px solid var(--border-color);
}

/* Form Elements */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form-hint {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  flex: 1;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
}

/* Back Button in Header */
.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-right: 12px;
  border-radius: 8px;
  transition: var(--transition);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-back svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.header-info {
  flex: 1;
}

.trip-name {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 2px;
}

/* Switch Route Button */
.btn-switch-route {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-left: 8px;
  border-radius: 8px;
  transition: var(--transition);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-switch-route:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-switch-route svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

