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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1a252f;
  color: #ecf0f1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
#header {
  background: #2c3e50;
  padding: 10px 20px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  border-bottom: 3px solid #3498db;
  z-index: 1000;
}

#header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ecf0f1;
}

#header .subtitle {
  font-size: 0.85rem;
  color: #95a5a6;
}

/* Main container */
#main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: 360px;
  min-width: 360px;
  background: #2c3e50;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: margin-left 0.3s ease;
  z-index: 900;
  overflow: hidden;
}

#sidebar.collapsed {
  margin-left: -360px;
}

#sidebar-toggle {
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 60px;
  background: #2c3e50;
  color: #ecf0f1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 0 6px 6px 0;
  z-index: 1001;
}

/* Search */
.search-container {
  position: relative;
  padding: 8px 12px;
  border-bottom: 1px solid #34495e;
}

#settlement-search {
  width: 100%;
  padding: 8px 12px;
  background: #34495e;
  color: #ecf0f1;
  border: 1px solid #4a6278;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}

#settlement-search:focus {
  border-color: #3498db;
}

#search-results {
  list-style: none;
  position: absolute;
  left: 12px;
  right: 12px;
  top: 100%;
  background: #34495e;
  border-radius: 0 0 6px 6px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

#search-results.active {
  display: block;
}

#search-results li {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid #2c3e50;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#search-results li:hover {
  background: #2c3e50;
}

#search-results li .search-score {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
}

/* Tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 2px solid #34495e;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: transparent;
  border: none;
  color: #95a5a6;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #ecf0f1;
  background: #34495e;
}

.tab-btn.active {
  color: #3498db;
  border-bottom: 2px solid #3498db;
}

.tab-content {
  display: none;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.tab-content.active {
  display: block;
}

/* Stat cards */
.stat-card {
  background: #34495e;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: #ecf0f1;
}

.stat-label {
  font-size: 0.75rem;
  color: #95a5a6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Stat rows */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #34495e;
}

.stat-row .stat-label {
  text-transform: none;
  font-size: 0.85rem;
}

/* Collapsible more details */
.more-details {
  margin: 12px 0;
  border: 1px solid #34495e;
  border-radius: 6px;
  background: #34495e;
}

.more-details summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #95a5a6;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, color 0.2s;
}

.more-details summary:hover {
  background: #3d566e;
  color: #ecf0f1;
}

.more-details summary::marker {
  color: #3498db;
}

.more-details[open] summary {
  border-bottom: 1px solid #2c3e50;
}

.more-details .stat-row {
  padding: 8px 14px;
  border-bottom: 1px solid #2c3e50;
}

.more-details .stat-row:last-child {
  border-bottom: none;
}

/* Detail section */
#settlement-detail h3 {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.detail-municipality,
.detail-population {
  font-size: 0.85rem;
  color: #95a5a6;
  margin-bottom: 4px;
}

.score-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 1.1rem;
  margin: 10px 0;
}

.score-badge.good { background: #2ecc71; color: #fff; }
.score-badge.fair { background: #f1c40f; color: #fff; }
.score-badge.moderate { background: #f39c12; color: #fff; }
.score-badge.poor { background: #e74c3c; color: #fff; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.82rem;
}

th, td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid #34495e;
}

th {
  color: #95a5a6;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

td {
  color: #ecf0f1;
}

.sortable {
  cursor: pointer;
}

.sortable:hover {
  color: #3498db;
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 12px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #2980b9;
}

.btn-primary:disabled {
  background: #7f8c8d;
  cursor: not-allowed;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid #95a5a6;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

/* Loading indicator */
#loading-indicator {
  text-align: center;
  padding: 40px 20px;
  color: #95a5a6;
}

/* Select */
select {
  width: 100%;
  padding: 8px 12px;
  background: #34495e;
  color: #ecf0f1;
  border: 1px solid #4a6278;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

select option {
  background: #2c3e50;
}

/* Chart */
.bar-chart {
  margin-top: 16px;
}

.bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.75rem;
}

.bar-label {
  width: 100px;
  text-align: right;
  padding-right: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #bdc3c7;
}

.bar-track {
  flex: 1;
  height: 16px;
  background: #34495e;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.bar-value {
  width: 36px;
  text-align: right;
  padding-left: 6px;
  font-weight: 600;
  font-size: 0.72rem;
}

/* Settlement list clickable rows */
.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #3d566e;
}

/* Desert indicator */
.desert-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.desert-indicator.good { background: #2ecc71; }
.desert-indicator.fair { background: #f1c40f; }
.desert-indicator.moderate { background: #f39c12; }
.desert-indicator.poor { background: #e74c3c; }

/* Map */
#map {
  flex: 1;
  z-index: 1;
}

/* Leaflet legend */
.legend {
  background: rgba(44, 62, 80, 0.92);
  padding: 10px 14px;
  border-radius: 8px;
  color: #ecf0f1;
  font-size: 0.78rem;
  line-height: 1.8;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-circle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.legend-line {
  width: 20px;
  height: 3px;
  background: #2980b9;
  display: inline-block;
  flex-shrink: 0;
}

/* Isochrone results */
#isochrone-breakdown table {
  margin-top: 8px;
}

#isochrone-loading {
  text-align: center;
  padding: 12px;
  color: #95a5a6;
}

/* Pulse animation for desert markers */
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(231, 76, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.desert-pulse {
  animation: pulse 2s infinite;
  border-radius: 50%;
}

/* Responsive */
@media (max-width: 768px) {
  #sidebar {
    width: 280px;
    min-width: 280px;
  }
  #sidebar.collapsed {
    margin-left: -280px;
  }
  #header h1 {
    font-size: 1rem;
  }
}
