:root {
  --blue-dark: #1e293b;
  --orange: #10b981;
  --terracotta: #059669;
  --gray-light: #f5f5f5;
  --gray-medium: #e0e0e0;
  --gray-dark: #666666;
  --white: #ffffff;
  --shadow: 0 4px 20px rgba(24, 53, 90, 0.1);
  --shadow-lg: 0 8px 40px rgba(24, 53, 90, 0.15);
  --transition: 0.3s ease;
  --trace-color: #10b981;
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--blue-dark);
  line-height: 1.6;
  background: var(--white);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  text-decoration: none;
  color: inherit;
}

/* Noscript */
.noscript-message {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--blue-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.noscript-content {
  background: var(--white);
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  max-width: 400px;
}

.noscript-content h1 {
  color: var(--blue-dark);
  margin-bottom: 16px;
}

.noscript-content p {
  color: var(--gray-dark);
}

/* Navbar */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  box-shadow: var(--shadow);
  z-index: 1000;
  height: 60px;
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 100%;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo img {
  height: 40px;
  width: auto;
}

.logo-dark {
  display: none;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-text .brand {
  font-size: 1rem;
  font-weight: 800;
  color: var(--blue-dark);
}

.logo-text .brand span {
  color: var(--orange);
}

.logo-text .tagline {
  font-size: 0.65rem;
  color: var(--gray-dark);
}

.nav-title {
  flex: 1;
  text-align: center;
}

.nav-title h1 {
  font-size: 1.25rem;
  color: var(--blue-dark);
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  color: var(--blue-dark);
  transition: all var(--transition);
  background: var(--gray-light);
}

.btn-back:hover {
  background: var(--gray-medium);
  color: var(--orange);
}

/* Main content */
.main-content {
  display: flex;
  flex: 1;
  padding-top: 60px;
  min-height: 100vh;
}

.map-container {
  flex: 1;
  height: calc(100vh - 60px);
  z-index: 1;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--white);
  border-left: 1px solid var(--gray-medium);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.sidebar-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.sidebar-section h2 {
  font-size: 1rem;
  color: var(--blue-dark);
  margin-bottom: 12px;
}

.sidebar-section h3 {
  font-size: 0.9rem;
  color: var(--blue-dark);
  margin-bottom: 10px;
}

/* Stats */
.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--gray-light);
  border-radius: 8px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--gray-dark);
}

.stat-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue-dark);
}

/* Select input */
.select-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-medium);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--blue-dark);
  background: var(--white);
  cursor: pointer;
}

.select-input:focus {
  outline: none;
  border-color: var(--orange);
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  gap: 8px;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border: 2px solid var(--gray-medium);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  transition: all var(--transition);
}

.mode-btn:hover {
  border-color: var(--orange);
  background: rgba(16, 185, 129, 0.05);
}

.mode-btn.active {
  border-color: var(--orange);
  background: rgba(16, 185, 129, 0.1);
}

.mode-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.mode-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--blue-dark);
  margin-bottom: 2px;
}

.mode-desc {
  font-size: 0.7rem;
  color: var(--gray-dark);
}

.mode-btn.active .mode-label {
  color: var(--orange);
}

/* BRouter status */
.brouter-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  flex: 1;
}

.status-indicator .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-indicator.connected {
  background: rgba(16, 185, 129, 0.1);
}

.status-indicator.connected .status-text {
  color: var(--terracotta);
}

.status-indicator.disconnected {
  background: rgba(239, 68, 68, 0.1);
}

.status-indicator.disconnected .status-text {
  color: #b91c1c;
}

.status-indicator.checking {
  background: rgba(245, 158, 11, 0.1);
}

.status-indicator.checking .status-text {
  color: #b45309;
}

.status-indicator.warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid #f59e0b;
}

.status-indicator.warning .status-text {
  color: #b45309;
}

.btn-small {
  padding: 6px 10px;
  background: var(--gray-light);
  border: 1px solid var(--gray-medium);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-small:hover {
  background: var(--gray-medium);
}

.btn-small svg {
  display: block;
}

/* Hint message */
.hint-message {
  padding: 12px;
  background: var(--gray-light);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--gray-dark);
  text-align: center;
}

/* Calculating indicator */
.calculating-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--orange);
  border-radius: 8px;
  color: var(--terracotta);
  font-size: 0.9rem;
  margin-top: 12px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--orange);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error message */
.error-message {
  padding: 12px;
  background: #fee2e2;
  border: 1px solid #ef4444;
  border-radius: 8px;
  color: #b91c1c;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 12px;
}

/* Layer buttons */
.layer-buttons {
  display: flex;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-layer {
  flex: 1;
  background: var(--gray-light);
  color: var(--blue-dark);
}

.btn-layer:hover {
  background: var(--gray-medium);
}

.btn-layer.active {
  background: var(--orange);
  color: var(--white);
}

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

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

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

.btn-secondary {
  background: var(--gray-light);
  color: var(--blue-dark);
}

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

.btn-full {
  width: 100%;
}

/* Export input */
.export-item {
  position: relative;
  margin-bottom: 12px;
}

.export-item label {
  display: block;
  font-size: 0.85rem;
  color: var(--gray-dark);
  margin-bottom: 6px;
}

.export-item input {
  width: 100%;
  padding: 10px 50px 10px 12px;
  border: 1px solid var(--gray-medium);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--blue-dark);
}

.export-item input:focus {
  outline: none;
  border-color: var(--orange);
}

.extension {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 0.85rem;
  color: var(--gray-dark);
}

/* Help section */
.sidebar-help ul {
  list-style: none;
  font-size: 0.85rem;
  color: var(--gray-dark);
}

.sidebar-help li {
  padding: 4px 0;
  padding-left: 16px;
  position: relative;
}

.sidebar-help li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--orange);
}

/* Footer */
.footer {
  background: var(--blue-dark);
  color: var(--white);
  padding: 15px 20px;
  text-align: center;
  font-size: 0.85rem;
}

.footer a {
  color: var(--orange);
}

.footer a:hover {
  text-decoration: underline;
}

/* Leaflet overrides */
.leaflet-container {
  font-family: inherit;
}

.leaflet-tile-pane {
  filter: grayscale(0);
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  background: var(--white) !important;
  color: var(--blue-dark) !important;
  border: none !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--gray-light) !important;
  color: var(--orange) !important;
}

.leaflet-control-zoom-in {
  border-radius: 8px 8px 0 0 !important;
}

.leaflet-control-zoom-out {
  border-radius: 0 0 8px 8px !important;
}

/* Marker styles */
.trace-marker {
  background: var(--orange);
  color: var(--white);
  border: 2px solid var(--white);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.trace-marker-start {
  background: var(--terracotta);
}

/* Trace polyline */
.leaflet-interactive {
  cursor: crosshair;
}

/* Responsive */
@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    max-height: 300px;
    border-left: none;
    border-top: 1px solid var(--gray-medium);
  }
  
  .map-container {
    height: calc(100vh - 60px - 300px);
    min-height: 300px;
  }
  
  .nav-title {
    display: none;
  }
}