:root {
    --bg: #f8f9fa;
    --fg: #212529;
    --muted: #6c757d;
    --accent: #007bff;
    --accent-light: rgba(0, 123, 255, 0.15);
    --border-color: #dee2e6;
    --card-bg: rgba(255, 255, 255, 0.9);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --border-radius-sm: 6px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease-in-out;
    opacity: 1;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
}

#loading-overlay p {
    margin-top: 16px;
    font-size: 16px;
    color: var(--muted);
}

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

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

#search-container {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 400px;
    z-index: 1000;
    padding: 0 10px;
}

#search-bar {
    position: relative;
    width: 100%;
    background: #fff;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

#search-bar .lucide-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    width: 20px;
    height: 20px;
    pointer-events: none;
}

#search-bar input {
    width: 100%;
    height: 44px;
    border: none;
    background: transparent;
    padding: 0 16px 0 44px;
    font-size: 15px;
    font-family: inherit;
    border-radius: var(--border-radius-md);
}
#search-bar input:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-light);
}

#search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 100%;
    background: #fff;
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    max-height: 250px;
    overflow-y: auto;
    display: none;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
}

.search-result-item:hover {
    background: var(--accent-light);
}
.search-result-item:first-child {
    border-top-left-radius: var(--border-radius-md);
    border-top-right-radius: var(--border-radius-md);
}
.search-result-item:last-child {
    border-bottom-left-radius: var(--border-radius-md);
    border-bottom-right-radius: var(--border-radius-md);
}


#controls-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--card-bg);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0,0,0,0.05);
    z-index: 1000;
    width: 360px;
    transition: all 0.2s ease-out;
    display: flex;
    flex-direction: column;
}

#controls-panel h1 {
    font-size: 20px;
    margin: 0 0 16px;
    font-weight: 600;
}

.control-group {
    margin-bottom: 20px;
}
.control-group:last-child {
    margin-bottom: 0;
}

.label-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.control-group label {
    display: block;
    font-size: 14px;
    color: var(--muted);
    font-weight: 500;
}

.text-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    margin: -4px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.15s ease-in-out;
}
.text-btn:hover {
    background: var(--accent-light);
}

.text-btn .lucide-icon {
    width: 14px;
    height: 14px;
    stroke-width: 2.5px;
}

.icon-btn {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 14px;
    line-height: 30px;
    text-align: center;
    padding: 0;
    flex-shrink: 0;
    color: var(--fg);
    transition: background-color 0.2s, border-color 0.2s;
}
.icon-btn:hover {
    background-color: #e0e0e0;
}
.icon-btn.active {
    background-color: var(--accent);
    color: white;
    border-color: var(--accent);
}
.icon-btn.active:hover {
    background-color: #0056d6;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
}
/* Small value shown to the right of sliders */
.slider-value {
    min-width: 56px;
    text-align: right;
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* --- Custom Slider Styles --- */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  flex: 1;
  margin: 0;
}

input[type=range]:focus {
  outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 8px;
  cursor: pointer;
  background: #e9ecef;
  border-radius: 4px;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -6px; /* (thumb height - track height) / 2 */
  border: 3px solid #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease-in-out;
}

input[type=range]:active::-webkit-slider-thumb {
    transform: scale(1.1);
}

input[type=range]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px var(--accent-light);
}

input[type=range]::-moz-range-track {
  width: 100%;
  height: 8px;
  cursor: pointer;
  background: #e9ecef;
  border-radius: 4px;
}

input[type=range]::-moz-range-thumb {
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: var(--shadow-sm);
}

#level {
    width: 100%;
    flex: 1;
    margin: 0;
}

#levelValue {
    min-width: 60px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.input-with-unit {
    position: relative;
    min-width: 80px;
    flex-shrink: 0;
}
.input-with-unit input {
    width: 100%;
    padding: 8px 24px 8px 12px; /* leave space for unit */
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-family: inherit;
    font-size: 14px;
    -moz-appearance: textfield;
    background-color: #fff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.input-with-unit input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
.input-with-unit input::-webkit-outer-spin-button,
.input-with-unit input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input-with-unit span {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    font-size: 14px;
}

/* --- Segmented Control --- */
.segmented-control {
    display: flex;
    width: 100%;
    background-color: #e9ecef;
    border-radius: var(--border-radius-md);
    padding: 4px;
    font-size: 14px;
}
.segmented-control input[type="radio"] {
    display: none;
}
.segmented-control label {
    flex: 1;
    text-align: center;
    padding: 6px 10px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    color: var(--muted);
    font-weight: 500;
}
.segmented-control input[type="radio"]:checked + label {
    background-color: #fff;
    color: var(--fg);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.units-toggle {
    font-size: 14px;
}

.legend {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* Only show the compact sea-level label in the controls panel */
.legend-only {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* LEAFLET CONTROL OVERRIDES */
.leaflet-bar, .leaflet-control-geocoder, .leaflet-control-layers {
    border: 1px solid var(--border-color) !important;
    box-shadow: var(--shadow-md) !important;
    border-radius: var(--border-radius-md) !important;
}

.leaflet-bar a, .leaflet-control-layers-toggle {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
    color: var(--fg) !important;
    background-color: #fff !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    transition: background-color 0.15s ease-in-out !important;
}

.leaflet-bar a:hover, .leaflet-control-layers-toggle:hover {
    background-color: #f8f9fa !important;
}

.leaflet-bar a.leaflet-disabled {
    cursor: not-allowed !important;
    background-color: #f8f8f8 !important;
    color: #bbb !important;
}

.leaflet-bar a:first-child {
    border-top-left-radius: var(--border-radius-md) !important;
    border-top-right-radius: var(--border-radius-md) !important;
}
.leaflet-bar a:last-child {
    border-bottom-left-radius: var(--border-radius-md) !important;
    border-bottom-right-radius: var(--border-radius-md) !important;
    border-bottom: none !important;
}
.leaflet-touch .leaflet-bar a:first-child {
  border-top-left-radius: var(--border-radius-md) !important;
  border-top-right-radius: var(--border-radius-md) !important;
}
.leaflet-touch .leaflet-bar a:last-child {
  border-bottom-left-radius: var(--border-radius-md) !important;
  border-bottom-right-radius: var(--border-radius-md) !important;
}

.leaflet-control-zoom-in, .leaflet-control-zoom-out {
    font-size: 24px !important;
    font-weight: 500 !important;
}

/* Custom icon controls */
.leaflet-control-custom a {
    padding: 0;
    line-height: 1;
}
.leaflet-control-custom a.active {
    background-color: var(--accent) !important;
    color: #fff !important;
}

.leaflet-control-custom .lucide-icon {
    width: 20px;
    height: 20px;
}

.leaflet-control-layers-toggle {
    border-radius: var(--border-radius-md) !important;
}

/* Info Modal */
#info-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.2s ease;
}
#info-modal.modal-hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-content {
    background: #fff;
    padding: 24px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 400px;
    position: relative;
}
.modal-content h2 {
    margin: 0 0 16px;
    font-size: 18px;
}
.modal-content p {
    margin: 0 0 12px;
    line-height: 1.6;
    font-size: 14px;
    color: #333;
}
.close-button {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--muted);
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}
.close-button:hover {
    background-color: #f0f0f0;
    color: var(--fg);
}

.close-button .lucide {
    width: 22px;
    height: 22px;
}

/* Info button on map */
.leaflet-control-info a {
    font-size: 1.4em;
    font-weight: bold;
    line-height: 28px;
    width: 30px;
    height: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
}

#elevation-display {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    padding: 6px 10px;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(0,0,0,0.05);
    font-size: 13px;
    color: var(--fg);
    min-width: 150px;
    text-align: left;
    font-variant-numeric: tabular-nums;
    margin-bottom: 10px;
}

#elevation-display div:last-child {
    font-size: 12px;
    color: var(--muted);
}

.leaflet-control-layers {
    box-shadow: var(--shadow-md);
    border-radius: var(--border-radius-md);
}

@media (max-width: 600px) {
    #search-container {
        left: 52px;
        right: 52px;
        width: auto;
        transform: none;
        max-width: none;
        padding: 0;
    }
    #search-bar input {
        height: 36px;
        font-size: 14px;
        padding-left: 40px;
    }
    #search-bar .lucide-search {
        left: 12px;
        width: 18px;
        height: 18px;
    }

    #controls-panel {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
        padding: 16px;
    }
    #controls-panel h1 {
        display: none;
    }
    .control-group {
        margin-bottom: 12px;
    }
    .control-group label {
        font-size: 13px;
    }
    .text-btn {
        font-size: 12px;
    }
    .text-btn .lucide-icon {
        width: 12px;
        height: 12px;
    }
    .slider-container {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    input[type=range]::-webkit-slider-runnable-track {
      height: 4px;
    }
    input[type=range]::-webkit-slider-thumb {
      height: 16px;
      width: 16px;
      margin-top: -6px;
    }
    input[type=range]::-moz-range-track {
      height: 4px;
    }
    input[type=range]::-moz-range-thumb {
      height: 16px;
      width: 16px;
    }
    .input-with-unit {
        min-width: 0;
    }
    .input-with-unit input {
        font-size: 13px;
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .input-with-unit span {
        font-size: 13px;
    }
    .segmented-control {
        font-size: 13px;
    }
    .segmented-control label {
        padding: 5px 8px;
    }
    .legend {
        margin-top: 12px;
        padding-top: 12px;
        font-size: 12px;
        gap: 6px;
    }
    .gradient-bar {
        height: 10px;
    }
    .gradient-labels {
        font-size: 11px;
    }
    #elevation-display {
        display: none;
    }
    .leaflet-bar a, .leaflet-control-layers-toggle {
        width: 32px !important;
        height: 32px !important;
        line-height: 32px !important;
    }
    .leaflet-control-zoom-in, .leaflet-control-zoom-out {
        font-size: 20px !important;
    }
    .leaflet-control-custom .lucide-icon {
        width: 16px;
        height: 16px;
    }
}

.controls-footer {
    margin-top: -15px;
    font-size: 13px;
    color: var(--muted);
    text-align: left;
    align-self: flex-start;
}
.controls-footer a {
    color: var(--accent);
    text-decoration: none;
}
.controls-footer a:hover {
    text-decoration: underline;
}