:root {
  --bg: #f5f6f8;
  --panel-bg: #ffffff;
  --text: #1c2128;
  --muted: #5b6472;
  --accent: #2b6cb0;
  --accent-dark: #1f4e80;
  --border: #d7dbe0;
  --error: #c0392b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 1rem 1.25rem;
  background: var(--accent);
  color: white;
}
.app-header h1 { margin: 0; font-size: 1.4rem; }
.app-header .tagline { margin: 0.25rem 0 0; font-size: 0.9rem; opacity: 0.9; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto auto;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.form-panel { grid-row: 1 / 3; }
.map-panel { grid-column: 2; grid-row: 1; }
.results-panel { grid-column: 2; grid-row: 2; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; }

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.55rem 0.6rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 44px;
}

input[type="range"] { width: 100%; height: 44px; }

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg-btn {
  flex: 1;
  padding: 0.6rem 0.4rem;
  border: none;
  background: var(--panel-bg);
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 44px;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--accent); color: white; }

.location-row { display: flex; gap: 0.5rem; }
.location-row input { flex: 1; }
#use-location-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-bg);
  cursor: pointer;
  font-size: 1.1rem;
}

.hint { font-size: 0.8rem; color: var(--muted); margin: 0.35rem 0 0; }
.status-line { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; margin-top: 0.35rem; }
.error-line { color: var(--error); font-size: 0.9rem; margin-top: 0.5rem; }

.primary-btn {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 46px;
}
.primary-btn:hover { background: var(--accent-dark); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

#map { height: 420px; width: 100%; border-radius: var(--radius); z-index: 0; }

.route-stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}
.route-stats strong { display: block; font-size: 1.1rem; }

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.candidate-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  cursor: pointer;
}
.candidate-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(43,108,176,0.25); }
.candidate-card .cand-stats { font-size: 0.9rem; color: var(--muted); }
.candidate-card .cand-elev-chart { width: 100px; height: 30px; }

.export-actions {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.export-actions button, .export-actions a {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-bg);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .form-panel, .map-panel, .results-panel {
    grid-column: 1;
    grid-row: auto;
  }
  #map { height: 300px; }
}
