:root{
  --bg:#0b0e11; 
  --panel:#12161a; 
  --elev:#171c21; 
  --text:#e9eef3; 
  --muted:#93a1af;
  --border:#28313a; 
  --ok:#44d07a; 
  --warn:#ffd166; 
  --bad:#ff6b6b; 
  --accent:#2aa3ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 5px 6px;
  background: var(--panel);
  background-color: #1e8fd9;
  border-bottom: 1px solid var(--border);
}

.title {
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn {
  background: var(--elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

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

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

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 56px);
}

aside {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow: auto;
}

.card {
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.card h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 6px 0;
  align-items: center;
}

label.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 6px 0;
}

label.checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
}

#map {
  position: relative;
}

#leaflet {
  position: absolute;
  inset: 0;
}

.legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  z-index: 999;
}

.legend h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--muted);
}

.legend .line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0;
}

.swatch {
  width: 60px;
  height: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.progress {
  height: 6px;
  width: 120px;
  background: #0f1419;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  display: inline-block;
}

.bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  display: block;
  transition: width 0.3s;
}

input[type="number"], 
input[type="file"] {
  width: 100%;
  background: #0f1419;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

input[type="number"] {
  width: 90px;
}

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

/* Segment Table Overlay */
.segment-overlay {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  max-height: 50vh;
  background: rgba(23, 28, 33, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.segment-overlay.minimized {
  max-height: 52px;
}

.overlay-header {
  padding: 14px 18px;
  background: rgba(124, 58, 237, 0.15);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.overlay-header:hover {
  background: rgba(124, 58, 237, 0.25);
}

.overlay-title {
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-icon {
  font-size: 12px;
  transition: transform 0.2s;
}

.segment-overlay.minimized .toggle-icon {
  transform: rotate(180deg);
}

.filter-bar {
  padding: 12px 18px;
  background: rgba(10, 14, 19, 0.6);
  border-bottom: 1px solid var(--border);
}

.filter-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(15, 20, 25, 0.8);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
}

.filter-input::placeholder {
  color: var(--muted);
}

.segment-list {
  overflow-y: auto;
  max-height: calc(50vh - 120px);
}

.segment-item {
  padding: 12px 18px;
  border-bottom: 1px solid rgba(37, 45, 56, 0.5);
  display: grid;
  grid-template-columns: 70px 1fr 100px 120px;
  gap: 16px;
  align-items: center;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.segment-item:hover {
  background: rgba(124, 58, 237, 0.1);
  border-left: 3px solid var(--accent);
}

.segment-num {
  font-weight: 700;
  color: var(--muted);
}

.segment-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.segment-road {
  font-weight: 600;
  color: var(--text);
}

.segment-infra {
  font-size: 11px;
  color: var(--muted);
  text-transform: capitalize;
}

.segment-distance {
  color: var(--muted);
  font-size: 12px;
}

.segment-score {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-badge {
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 14px;
  min-width: 50px;
  text-align: center;
}

.score-bar {
  flex: 1;
  height: 6px;
  background: rgba(15, 20, 25, 0.5);
  border-radius: 3px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  transition: width 0.3s;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(10, 14, 19, 0.5);
}

::-webkit-scrollbar-thumb {
  background: rgba(139, 149, 165, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 149, 165, 0.5);
}

/* Mobile Results View - Hidden by default */
.mobile-results {
  display: none;
}

/* Mobile Styles */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 8px 12px;
  }
  
  .title {
    font-size: 16px;
  }
  
  header .muted {
    display: none;
  }
  
  .actions {
    width: 100%;
    margin-top: 8px;
    justify-content: flex-end;
  }
  
  #app {
    display: block;
    height: calc(100vh - 60px);
  }
  
  aside {
    display: none;
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    border-right: none;
  }
  
  aside:not(.mobile-hidden) {
    display: block;
  }
  
  aside.mobile-hidden {
    display: none !important;
  }
  
  #map {
    height: 40vh;
    position: relative;
  }
  
  #leaflet {
    height: 100%;
  }
  
  .legend {
    display: none;
  }
  
  .segment-overlay {
    display: none !important;
  }
  
  /* Mobile Results View */
  .mobile-results {
    height: 60vh;
    overflow-y: auto;
    background: var(--bg);
    display: flex;
    flex-direction: column;
  }
  
  .mobile-back-btn {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--accent);
    color: #061a2b;
    border: none;
    padding: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
  }
  
  .mobile-back-btn:active {
    background: #1e8fd9;
  }
  
  .mobile-score-card {
    background: var(--panel);
    padding: 20px;
    border-bottom: 2px solid var(--border);
    text-align: center;
    position: sticky;
    top: 48px;
    z-index: 10;
  }
  
  .mobile-score-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
    margin-bottom: 8px;
  }
  
  .mobile-score {
    font-size: 64px;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 8px;
  }
  
  .mobile-score-text {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
  }
  
  .mobile-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
  }
  
  .mobile-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  .stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
  }
  
  .stat-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  
  .mobile-segment-header {
    background: var(--panel);
    padding: 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 48px;
    z-index: 9;
  }
  
  .mobile-segment-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
  }
  
  .mobile-count {
    font-size: 11px;
    color: var(--muted);
    font-weight: 400;
  }
  
  .mobile-filter {
    width: 100%;
    padding: 8px 12px;
    background: var(--elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
  }
  
  .mobile-segment-list {
    flex: 1;
    overflow-y: auto;
  }
  
  .mobile-segment-list .segment-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--panel);
    grid-template-columns: none;
  }
  
  .mobile-segment-list .segment-item:active {
    background: rgba(42, 163, 255, 0.1);
  }
  
  .mobile-segment-list .segment-num {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
  }
  
  .mobile-segment-list .segment-details {
    flex: 1;
  }
  
  .mobile-segment-list .segment-road {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
  }
  
  .mobile-segment-list .segment-infra {
    font-size: 12px;
    color: var(--muted);
  }
  
  .mobile-segment-list .segment-score {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  
  .mobile-segment-list .score-badge {
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 16px;
  }
  
  .mobile-segment-list .score-bar {
    flex: 1;
    height: 8px;
    background: rgba(15, 20, 25, 0.5);
    border-radius: 4px;
    overflow: hidden;
  }
  
  .mobile-segment-list .segment-distance {
    font-size: 12px;
    font-weight: 600;
  }
}