:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1d2939;
  --muted: #475467;
  --line: #d0d5dd;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --error-bg: #fef3f2;
  --error-text: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #edf2f7 0%, #f8fafc 100%);
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

.container {
  max-width: 1080px;
  margin: 24px auto;
  padding: 0 16px 24px;
}

.header h1 {
  margin: 0;
  font-size: 1.7rem;
}

.header p {
  margin: 8px 0 20px;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 18px rgba(16, 24, 40, 0.05);
}

.grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
}

small {
  color: var(--muted);
  font-size: 0.78rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

button {
  border: 0;
  border-radius: 10px;
  height: 42px;
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--primary-hover);
}

.alert.error {
  margin-bottom: 14px;
  border: 1px solid #fecdca;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--error-bg);
  color: var(--error-text);
}

.optional-field {
  display: flex;
}

#custom_quality_group {
  display: none;
}

/* Resultados y mapa */
.results-card {
  margin-top: 16px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.results-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.stats-text {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.results-actions {
  display: flex;
  gap: 8px;
}

.map-legend {
  display: flex;
  gap: 18px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.legend-line {
  display: inline-block;
  width: 28px;
  height: 3px;
  border-radius: 2px;
}

.legend-guide {
  background: #e67e22;
  border-top: 2px dashed #e67e22;
  background: transparent;
  height: 0;
}

.legend-track {
  background: #2563eb;
}

#map {
  width: 100%;
  height: 450px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

/* Spinner de carga */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
  gap: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 980px) {
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .results-header {
    flex-direction: column;
    gap: 10px;
  }

  #map {
    height: 350px;
  }
}
