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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f0f2f5;
  color: #1a1a1a;
}

header {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 0.6rem 1.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 1000;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* ── Banners ─────────────────────────────────────────────────────────────── */
#error-banner {
  background: #d32f2f;
  color: #fff;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  z-index: 999;
}

#error-banner.hidden {
  display: none;
}

#mode-banner {
  background: #2e7d32;
  color: #fff;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  z-index: 998;
  animation: pulse 1.5s ease-in-out infinite;
}

#mode-banner.hidden {
  display: none;
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#sidebar {
  width: 380px;
  min-width: 300px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: #fff;
  box-shadow: 2px 0 10px rgba(0,0,0,0.08);
  overflow-y: auto;
  z-index: 500;
}

#sidebar label {
  font-weight: 600;
  font-size: 0.9rem;
}

.section-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

.divider {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 0.3rem 0;
}

#gpx-input {
  flex: 1;
  min-height: 150px;
  resize: vertical;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  padding: 0.6rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  line-height: 1.4;
}

#import-mode {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font-size: 0.85rem;
}

.import-mode-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.import-mode-row label {
  font-size: 0.8rem;
  color: #4a5565;
  font-weight: 700;
}

#btn-browse {
  background: #455a64;
  color: #fff;
}

#btn-browse:hover:not(:disabled) {
  background: #37474f;
}

.import-status {
  font-size: 0.78rem;
  color: #54606e;
  background: #f6f8fb;
  border: 1px solid #d9e1ea;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  line-height: 1.35;
}

.import-status[data-state="success"] {
  color: #2e7d32;
  background: #eef7f0;
  border-color: #b9dbc0;
}

.import-status[data-state="error"] {
  color: #b71c1c;
  background: #fff1f1;
  border-color: #f0c1c1;
}

#sidebar.drop-target,
#map.drop-target {
  outline: 2px dashed #00897b;
  outline-offset: -8px;
  background: linear-gradient(180deg, rgba(0, 137, 123, 0.08), rgba(0, 137, 123, 0.03));
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.button-row button {
  flex: 1;
  min-width: 80px;
  padding: 0.5rem 0.4rem;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.button-row button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#btn-load { background: #4caf50; color: #fff; }
#btn-load:hover:not(:disabled) { background: #43a047; }

#btn-clear { background: #ff9800; color: #fff; }
#btn-clear:hover:not(:disabled) { background: #f57c00; }

#btn-export { background: #2196f3; color: #fff; }
#btn-export:hover:not(:disabled) { background: #1976d2; }

#btn-geojson { background: #2e7d32; color: #fff; }
#btn-geojson:hover:not(:disabled) { background: #1b5e20; }

#btn-validate { background: #9c27b0; color: #fff; }
#btn-validate:hover:not(:disabled) { background: #7b1fa2; }

#btn-densify { background: #6d4c41; color: #fff; }
#btn-densify:hover:not(:disabled) { background: #5d4037; }

#btn-elevation { background: #00695c; color: #fff; }
#btn-elevation:hover:not(:disabled) { background: #004d40; }

#btn-new-route { background: #00897b; color: #fff; }
#btn-new-route:hover:not(:disabled) { background: #00796b; }

#btn-undo-point { background: #ef6c00; color: #fff; }
#btn-undo-point:hover:not(:disabled) { background: #e65100; }

#btn-finish-route { background: #1565c0; color: #fff; }
#btn-finish-route:hover:not(:disabled) { background: #0d47a1; }

#btn-cancel-route { background: #c62828; color: #fff; }
#btn-cancel-route:hover:not(:disabled) { background: #b71c1c; }

/* ── Progress Bar ────────────────────────────────────────────────────────── */
#elevation-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #555;
}

#elevation-progress.hidden {
  display: none;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: #00897b;
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ── Elevation Stats ─────────────────────────────────────────────────────── */
#elevation-stats {
  font-size: 0.82rem;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  line-height: 1.5;
}

#elevation-stats.hidden {
  display: none;
}

/* ── Route Inspector ─────────────────────────────────────────────────────── */
.route-inspector {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.route-inspector-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid #d8e1ec;
  border-radius: 10px;
  background: linear-gradient(180deg, #f8fbff, #edf3f9);
}

.route-inspector-toolbar-copy strong {
  display: block;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4a5565;
  margin-bottom: 0.15rem;
}

.route-inspector-toolbar-copy span {
  display: block;
  font-size: 0.82rem;
  color: #54606e;
  line-height: 1.45;
}

.route-inspector-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.route-inspector-button {
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  color: #1a1a1a;
  background: #dde6ef;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.route-inspector-button:hover:not(:disabled) {
  background: #ccd8e5;
}

.route-inspector-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.route-inspector-button-danger {
  background: #c62828;
  color: #fff;
}

.route-inspector-button-danger:hover:not(:disabled) {
  background: #b71c1c;
}

.route-inspector-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.route-inspector-empty {
  font-size: 0.82rem;
  color: #54606e;
  background: linear-gradient(180deg, #f8fbff, #f3f7fc);
  border: 1px dashed #c9d5e3;
  border-radius: 8px;
  padding: 0.8rem;
  line-height: 1.45;
}

.route-inspector-empty strong {
  display: block;
  margin-bottom: 0.25rem;
  color: #1a1a1a;
}

.route-inspector-empty p {
  margin: 0;
}

.route-card {
  border: 1px solid #d8e1ec;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.route-card.selected {
  border-color: #00897b;
  box-shadow:
    0 0 0 1px rgba(0, 137, 123, 0.14),
    0 8px 18px rgba(0, 137, 123, 0.12);
}

.route-card.bulk-selected {
  border-color: #c62828;
  box-shadow:
    0 0 0 1px rgba(198, 40, 40, 0.14),
    0 8px 18px rgba(198, 40, 40, 0.12);
}

.route-card.bulk-selected.selected {
  border-color: #00897b;
  box-shadow:
    0 0 0 1px rgba(0, 137, 123, 0.14),
    0 0 0 3px rgba(198, 40, 40, 0.1),
    0 8px 18px rgba(0, 137, 123, 0.12);
}

.route-card-header {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  padding: 0.65rem;
  background: linear-gradient(180deg, #f8fbff, #f3f7fc);
  border-bottom: 1px solid #e4ebf3;
}

.route-card-selector {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.route-card-selector:hover {
  opacity: 0.92;
}

.route-card-select,
.point-row-select {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex: 0 0 auto;
}

.route-card-select {
  padding-top: 0.25rem;
}

.point-row-select {
  padding-top: 0.15rem;
}

.route-card-select input,
.point-row-select input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #c62828;
  cursor: pointer;
}

.route-card-select input:disabled,
.point-row-select input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.route-card-selector:focus-visible,
.route-card-action:focus-visible,
.point-row-delete:focus-visible {
  outline: 2px solid #00897b;
  outline-offset: 2px;
}

.route-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #17202a;
  line-height: 1.3;
}

.route-card-subtitle {
  font-size: 0.75rem;
  color: #5b6876;
  line-height: 1.35;
}

.route-card-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.route-card-action {
  border: none;
  border-radius: 6px;
  min-width: 92px;
  padding: 0.42rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.route-card-action:hover:not(:disabled) {
  opacity: 0.92;
}

.route-card-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.route-card-toggle {
  background: #455a64;
}

.route-card-delete {
  background: #c62828;
}

.route-card-delete-note {
  font-size: 0.76rem;
  font-weight: 700;
  color: #b71c1c;
  background: #fff1f1;
  border: 1px solid #f0c1c1;
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}

.route-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.7rem;
  background: #fff;
}

.route-card-body.hidden {
  display: none;
}

.route-card-summary {
  font-size: 0.78rem;
  color: #54606e;
  line-height: 1.45;
}

.route-card-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.route-card-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #4a5565;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.route-card-empty-section {
  font-size: 0.76rem;
  color: #6b7280;
  font-style: italic;
  padding: 0.15rem 0;
}

.point-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.point-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fafcff;
}

.point-row.bulk-selected {
  background: #fff3f3;
  border-color: #efb7b7;
}

.point-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.point-row-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.35;
}

.point-row-meta {
  font-size: 0.75rem;
  color: #5b6876;
  line-height: 1.35;
  word-break: break-word;
}

.point-row-delete {
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  background: #ef6c00;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.point-row-delete:hover:not(:disabled) {
  background: #e65100;
}

.point-row-delete:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Info Panel ──────────────────────────────────────────────────────────── */
#info-panel {
  font-size: 0.82rem;
  background: #f9f9fb;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

#info-panel ul {
  margin: 0.3rem 0 0.5rem 1.2rem;
}

#info-panel li {
  margin-bottom: 0.2rem;
}

#point-count {
  font-weight: 600;
  color: #555;
  margin-top: 0.3rem;
}

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  flex: 1;
}

#map.crosshair-mode {
  cursor: crosshair !important;
}

/* Leaflet popup overrides */
.edit-name-input {
  border: 1px solid #aaa;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.85rem;
  width: 160px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }
  #sidebar {
    width: 100%;
    min-width: unset;
    max-height: 40vh;
  }
}
