* {
  box-sizing: border-box;
}

:root {
  --bg: #07111e;
  --panel: #0d1b2a;
  --panel-strong: #10243a;
  --border: #1c3650;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --success: #34d399;
  --danger: #f87171;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.14), transparent 30%),
    radial-gradient(circle at top right, rgba(245, 158, 11, 0.16), transparent 24%),
    var(--bg);
  color: var(--text);
}

.app {
  --sidebar-width: 344px;
  display: flex;
  height: 100dvh;
  width: 100vw;
  position: relative;
}

.sidebar {
  position: relative;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  min-width: 0;
  max-width: var(--sidebar-width);
  padding: 14px;
  border-right: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(7, 17, 30, 0.88);
  backdrop-filter: blur(12px);
  overflow: visible;
  transition:
    flex-basis 0.24s ease,
    width 0.24s ease,
    max-width 0.24s ease,
    padding 0.24s ease,
    border-color 0.24s ease,
    background 0.24s ease;
}

.sidebar__content {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.16s ease, transform 0.24s ease;
}

.sidebar-toggle {
  position: absolute;
  bottom: 14px;
  left: calc(var(--sidebar-width) - 14px);
  z-index: 700;
  width: 30px;
  height: 46px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.2);
  background: rgba(7, 17, 30, 0.92);
  color: #dbeafe;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.24);
}

.app.sidebar-collapsed .sidebar {
  flex-basis: 0;
  width: 0;
  max-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  background: transparent;
  backdrop-filter: none;
}

.app.sidebar-collapsed .sidebar__content {
  opacity: 0;
  transform: translateX(-18px);
  pointer-events: none;
}

.app.sidebar-collapsed .sidebar-toggle {
  left: 10px;
}

h1 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: 0.02em;
}

h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.muted {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.35;
}

.card {
  background: linear-gradient(180deg, rgba(16, 36, 58, 0.96), rgba(10, 22, 36, 0.95));
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: 0 14px 36px rgba(2, 6, 23, 0.22);
}

.row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
  flex-wrap: wrap;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.field-note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.field-full {
  grid-column: 1 / -1;
}

.dual-range {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dual-range__values {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.dual-range__chip {
  min-width: 68px;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.18);
  background: rgba(2, 6, 23, 0.62);
  color: var(--text);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

.dual-range__slider {
  --range-start: 0%;
  --range-end: 100%;
  position: relative;
  height: 28px;
}

.dual-range__track,
.dual-range__fill {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  border-radius: 999px;
}

.dual-range__track {
  background: rgba(148, 163, 184, 0.18);
}

.dual-range__fill {
  left: var(--range-start);
  right: calc(100% - var(--range-end));
  background: linear-gradient(90deg, #38bdf8, #f59e0b);
}

button,
input,
select {
  font: inherit;
}

button {
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  transition: transform 0.14s ease, opacity 0.14s ease, background 0.14s ease;
}

button:hover {
  transform: translateY(-1px);
}

button,
select,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

button.primary {
  background: linear-gradient(135deg, #f59e0b, #fb7185);
  color: #08111d;
  font-weight: 700;
}

button.secondary,
.file-label {
  background: rgba(56, 189, 248, 0.14);
  color: #dbeafe;
  border: 1px solid rgba(56, 189, 248, 0.28);
}

button.ghost {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

input[type="number"],
select {
  width: 100%;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 23, 0.65);
  color: var(--text);
}

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

.dual-range__slider input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  appearance: none;
  background: none;
  pointer-events: none;
}

.dual-range__slider input[type="range"]::-webkit-slider-runnable-track {
  appearance: none;
  height: 6px;
  background: transparent;
}

.dual-range__slider input[type="range"]::-moz-range-track {
  height: 6px;
  background: transparent;
  border: none;
}

.dual-range__slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 999px;
  border: 2px solid #08111d;
  background: #f8fafc;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
  cursor: pointer;
  pointer-events: auto;
}

.dual-range__slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid #08111d;
  background: #f8fafc;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
  cursor: pointer;
  pointer-events: auto;
}

.stat {
  font-size: 12px;
  margin-top: 6px;
  padding: 7px 9px;
  background: rgba(2, 6, 23, 0.55);
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  line-height: 1.35;
}

.sidebar-inline-range {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.sidebar-inline-range__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.sidebar-inline-range__label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.sidebar-inline-range__value {
  font-size: 11px;
  font-weight: 800;
  color: #dbeafe;
}

.stat-strong {
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.22);
  background: rgba(245, 158, 11, 0.08);
}

#contourDatasetStats {
  color: var(--accent-2);
  border-color: rgba(56, 189, 248, 0.24);
  background: rgba(56, 189, 248, 0.08);
}

#contourStats {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.24);
  background: rgba(52, 211, 153, 0.08);
}

#contourInfo {
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.24);
  background: rgba(245, 158, 11, 0.08);
}

.preload {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 23, 0.55);
}

.preload-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 10px;
}

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

.preload-idle .preload-dot {
  background: #64748b;
}

.preload-loading {
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.28);
  background: rgba(245, 158, 11, 0.08);
}

.preload-loading .preload-dot {
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}

.preload-ready {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.24);
  background: rgba(52, 211, 153, 0.08);
}

.preload-ready .preload-dot {
  background: var(--success);
}

.preload-error {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.1);
}

.preload-error .preload-dot {
  background: var(--danger);
}

@keyframes pulse {
  0% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.6; }
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 4px 7px;
  border-radius: 999px;
  margin-right: 4px;
  margin-bottom: 4px;
  color: #0f172a;
  font-weight: 700;
}

.badge-compacta {
  background: #fdba74;
}

.badge-veril {
  background: #7dd3fc;
}

.badge-mixta {
  background: #86efac;
}

.list {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 10px;
}

.list-item {
  padding: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}

.list-item:hover {
  background: rgba(56, 189, 248, 0.08);
  transform: translateX(2px);
}

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.list-score {
  font-size: 12px;
  color: #fde68a;
  white-space: nowrap;
}

.list-subtitle {
  display: block;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.spot-popup-shell .leaflet-popup-content-wrapper {
  background: rgba(7, 17, 30, 0.97);
  color: var(--text);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(2, 6, 23, 0.28);
}

.spot-popup-shell .leaflet-popup-content {
  margin: 10px 12px;
}

.spot-popup-shell .leaflet-popup-tip {
  background: rgba(7, 17, 30, 0.97);
}

.spot-popup {
  min-width: 280px;
  max-width: 320px;
}

.spot-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 8px;
}

.spot-popup__subtitle {
  font-size: 11px;
  color: var(--muted);
}

.spot-popup__coords-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.spot-popup__badge {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  color: #08111d;
  white-space: nowrap;
}

.spot-popup__badge--compacta {
  background: #f97316;
}

.spot-popup__badge--veril {
  background: #38bdf8;
}

.spot-popup__badge--mixta {
  background: #34d399;
}

.spot-popup__badge--costera {
  background: #f59e0b;
}

.spot-popup__badge--fondo {
  background: #22c55e;
}

.spot-popup__badge--default {
  background: #facc15;
}

.spot-popup__copy-btn {
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.26);
  background: rgba(56, 189, 248, 0.12);
  color: #dbeafe;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

.spot-popup__copy-btn:hover {
  background: rgba(56, 189, 248, 0.2);
}

.spot-popup__metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  font-size: 11px;
}

.spot-popup__metric {
  min-width: 0;
  padding: 6px 7px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(2, 6, 23, 0.42);
}

.spot-popup__metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.spot-popup__label-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.spot-popup__label {
  color: var(--muted);
  font-size: 10px;
}

.spot-popup__info-btn {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.34);
  background: rgba(56, 189, 248, 0.12);
  color: #dbeafe;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.spot-popup__info-btn:hover {
  background: rgba(56, 189, 248, 0.22);
}

.spot-popup__value {
  text-align: right;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  font-size: 11px;
}

.spot-popup__help {
  display: none;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(148, 163, 184, 0.16);
  line-height: 1.35;
  font-size: 11px;
  color: #cbd5e1;
}

.spot-popup__metric--open .spot-popup__help {
  display: block;
}

.spot-popup__note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.map-shell {
  position: relative;
  flex: 1;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.zoom-level-control {
  min-width: 68px;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.18);
  background: rgba(7, 17, 30, 0.88);
  color: #dbeafe;
  box-shadow: 0 12px 24px rgba(2, 6, 23, 0.2);
  text-align: center;
}

.zoom-level-control__label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.zoom-level-control__value {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.scale-bar-control {
  padding: 7px 9px 8px;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.18);
  background: rgba(7, 17, 30, 0.88);
  color: #dbeafe;
  box-shadow: 0 12px 24px rgba(2, 6, 23, 0.2);
}

.scale-bar-control__label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.scale-bar-control__label {
  color: #e2e8f0;
}

.scale-bar-control__bar-wrap {
  display: flex;
}

.scale-bar-control__bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 10px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  overflow: hidden;
}

.scale-bar-control__segment {
  background: rgba(226, 232, 240, 0.92);
}

.scale-bar-control__segment--light {
  background: rgba(56, 189, 248, 0.22);
}

.leaflet-bottom.leaflet-right .leaflet-control {
  margin-bottom: 10px;
}

@media (max-width: 980px) {
  .app {
    height: 100dvh;
    min-height: 100dvh;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 650;
    flex-basis: auto;
    width: min(calc(100vw - 20px), 430px);
    max-width: min(calc(100vw - 20px), 430px);
    padding:
      max(10px, env(safe-area-inset-top))
      10px
      10px
      max(10px, env(safe-area-inset-left));
    border-right: none;
    border-bottom: none;
    background: linear-gradient(180deg, rgba(7, 17, 30, 0.78), rgba(7, 17, 30, 0));
    backdrop-filter: none;
  }

  .sidebar__content {
    max-height: min(72dvh, 560px);
  }

  .sidebar .card {
    margin-bottom: 0;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 20px 40px rgba(2, 6, 23, 0.26);
  }

  .field-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .field {
    font-size: 12px;
    gap: 6px;
  }

  .row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #searchBtn {
    grid-column: 1 / -1;
    min-height: 46px;
  }

  #fitBtn,
  #clearBtn {
    min-height: 42px;
  }

  select {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 13px;
  }

  .dual-range {
    gap: 10px;
  }

  .dual-range__chip {
    min-width: 74px;
    padding: 6px 9px;
    font-size: 12px;
  }

  .dual-range__slider {
    height: 34px;
  }

  .dual-range__slider input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -8px;
  }

  .dual-range__slider input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .stat {
    font-size: 12px;
    padding: 9px 10px;
  }

  .sidebar-inline-range {
    margin-top: 10px;
    padding-top: 10px;
  }

  .sidebar-toggle {
    top: max(12px, env(safe-area-inset-top));
    bottom: auto;
    left: auto;
    right: max(12px, env(safe-area-inset-right));
    width: auto;
    min-width: 84px;
    height: 42px;
    padding: 0 12px;
    border-radius: 14px;
    font-size: 12px;
    backdrop-filter: blur(12px);
    box-shadow: 0 14px 28px rgba(2, 6, 23, 0.24);
  }

  .app.sidebar-collapsed .sidebar {
    width: 0;
    max-width: 0;
    padding: 0;
    background: transparent;
  }

  .app.sidebar-collapsed .sidebar-toggle {
    left: auto;
    right: max(12px, env(safe-area-inset-right));
  }

  .map-shell {
    min-height: 100dvh;
  }

  #map {
    min-height: 100dvh;
  }

  .spot-popup-shell .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 44px);
  }

  .spot-popup-shell .leaflet-popup-content {
    margin: 9px 10px;
  }

  .spot-popup {
    min-width: min(248px, calc(100vw - 72px));
    max-width: min(280px, calc(100vw - 72px));
  }

  .spot-popup__metrics {
    grid-template-columns: 1fr;
  }

  .zoom-level-control {
    min-width: 60px;
    padding: 6px 7px;
  }

  .zoom-level-control__value {
    font-size: 16px;
  }

  .scale-bar-control {
    padding: 6px 7px 7px;
  }

  .scale-bar-control__bar {
    height: 8px;
  }

  .leaflet-left .leaflet-control {
    margin-left: 10px;
    margin-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .leaflet-bottom.leaflet-right .leaflet-control {
    margin-right: 10px;
    margin-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .leaflet-control-zoom a {
    width: 40px;
    height: 40px;
    line-height: 40px;
    font-size: 22px;
  }

  .leaflet-touch .leaflet-bar a {
    width: 40px;
    height: 40px;
    line-height: 40px;
  }

  .leaflet-control-zoom {
    box-shadow: 0 12px 24px rgba(2, 6, 23, 0.2);
  }

  .leaflet-bottom .leaflet-control-scale,
  .leaflet-bottom .zoom-level-control {
    margin-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 560px) {
  .sidebar {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    padding-inline: 8px;
  }

  .sidebar .card {
    border-radius: 14px;
    padding: 12px;
  }

  .spot-popup {
    min-width: min(232px, calc(100vw - 60px));
    max-width: min(264px, calc(100vw - 60px));
  }

  .spot-popup__coords-row {
    gap: 5px;
  }

  .scale-bar-control__label-row {
    gap: 8px;
    font-size: 9px;
  }
}
