html,
body,
#map {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.segmented-menu {
    position: fixed;
    top: 10px;
    right: 10px;
    background: white;
    display: flex;
    border: 1px solid #ccc;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.segmented-menu button {
    flex: 1;
    border: none;
    background: #f2f2f2;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.segmented-menu button:hover {
    background: #e0e0e0;
}

.segmented-menu button.active {
    background: #2563eb;
    color: white;
}

.map-nav-links {
    position: fixed;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    z-index: 1000;
}

.map-nav-links a {
    background: white;
    padding: 8px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    text-decoration: none;
    font-weight: bold;
    font-size: 0.9rem;
}

.map-nav-links a:hover {
    background: #f0f0f0;
}

.backoffice-link {
    color: #2563eb;
}

.bifrost-link {
    color: #888;
}

.track-legend {
    position: fixed;
    bottom: 50px;
    left: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    font-size: 0.85rem;
    display: none;
}

.track-legend.has-tracks {
    display: block;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    gap: 8px;
}

.legend-header h4 {
    margin: 0;
    font-size: 0.9rem;
}

.legend-toggle {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: transform 0.2s;
}

.legend-toggle.collapsed {
    transform: rotate(180deg);
}

.legend-body {
    max-height: 35vh;
    overflow-y: auto;
    padding: 0 12px 10px;
}

.legend-body.hidden {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    cursor: pointer;
}

.legend-item:hover {
    opacity: 0.7;
}

.legend-swatch {
    width: 20px;
    height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

.track-popup h4 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.track-popup .stats {
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 6px;
}

.track-popup .stats span {
    font-weight: 600;
}

.track-popup canvas {
    width: 100%;
    height: 140px;
    display: block;
    border-radius: 4px;
}

@media (max-width: 600px) {
    .legend-body {
        max-height: 25vh;
    }
}

/* Hut marker styling */
.hut-marker {
    background: none !important;
    border: none !important;
}

/* Popup styling */
.leaflet-popup-content-wrapper {
    min-width: 200px;
}

.popup-content h4 {
    margin: 0 0 8px 0;
    font-size: 1rem;
}

.popup-content dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.popup-content dt {
    font-weight: 600;
    color: #666;
    white-space: nowrap;
    grid-column: 1;
}

.popup-content dd {
    margin: 0;
    text-align: right;
    grid-column: 2;
}

.popup-content canvas {
    width: 100%;
    height: 140px;
    display: block;
    border-radius: 4px;
    margin-top: 8px;
}

/* Selection popup */
.selection-popup {
    padding: 8px;
}

.selection-popup h4 {
    margin: 0 0 4px 0;
    font-size: 0.95rem;
}

.selection-popup .subtitle {
    font-size: 0.8rem;
    color: #666;
    margin: 0 0 8px 0;
}

.selection-popup ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.selection-popup li {
    margin: 2px 0;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #000 !important;
}

.selection-popup li:hover {
    background: #f0f0f0;
}

.selection-popup .item-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.selection-popup .track-indicator {
    width: 16px;
    height: 3px;
    border-radius: 2px;
}

/* New Map Library Controls */
.map-base-layer-control {
    position: absolute;
    top: 10px;
    right: 10px;
    background: white;
    display: flex;
    border: 1px solid #ccc;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.map-base-layer-control .base-layer-btn {
    flex: 1;
    border: none;
    background: #f2f2f2;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
    transition: background 0.2s;
    border-right: 1px solid #ccc;
}

.map-base-layer-control .base-layer-btn:last-child {
    border-right: none;
}

.map-base-layer-control .base-layer-btn:hover {
    background: #e0e0e0;
}

.map-base-layer-control .base-layer-btn.active {
    background: #2563eb;
    color: white;
}

.map-layers-control {
    position: absolute;
    top: 50px;
    right: 10px;
    z-index: 1000;
}

.layers-toggle-btn {
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: background 0.2s;
}

.layers-toggle-btn:hover {
    background: #f0f0f0;
}

.layers-panel {
    position: absolute;
    top: 45px;
    right: 0;
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    min-width: 250px;
    max-width: 300px;
}

.layers-panel.hidden {
    display: none;
}

.layers-panel h4 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    font-weight: bold;
}

.layer-item {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eee;
}

.layer-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.layer-item .opacity-slider.hidden {
    display: none;
}

.layer-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.layer-header input[type="checkbox"] {
    cursor: pointer;
    margin-right: 0;
}

.opacity-slider {
    width: 100%;
    cursor: pointer;
}

/* Settings and Elements Controls */
.map-settings-control,
.map-elements-control,
.map-legend-control {
    position: absolute;
    top: 10px;
    z-index: 1000;
}

.map-settings-control {
    right: 10px;
}

.map-elements-control {
    right: 64px;
}

.map-legend-control {
    right: 118px;
}

.map-menu-btn {
    background: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 1.3rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: background 0.2s;
    line-height: 1;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;

    /* glass effect */
    backdrop-filter: blur(5px);
    background: rgba(235, 235, 235, 0.75);
}

.map-menu-btn .icon {
    filter: grayscale(100%) brightness(0);
}

.settings-btn {
    font-weight: 900;
    font-size: 1.5rem;
    letter-spacing: -0.05em;
}

.map-menu-btn:hover {
    background: #f0f0f0;
}

.map-menu-btn.active {
    border-radius: 8px 8px 0 0;
    height: calc(44px + 11px);
    padding-bottom: 20px;
    z-index: 1002;
    /* this mitigates almost the missing transparency effect on the border of the popup */
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
    box-shadow: none;
}

.map-menu-btn.active:hover {
    backdrop-filter: blur(5px);
    background: rgba(235, 235, 235, 0.75);
}

/*settings button is the right most one, we hide the border-radius in the top right corner if it is opened (and button is active) to let the extended button be visually adjecent to the popup*/
.map-settings-control .map-menu-btn.settings-btn.active+.settings-popup {
    border-radius: 8px 0 8px 8px;
}

.settings-popup,
.elements-popup,
.legend-popup {
    position: absolute;
    top: 54px;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1001;

    /* glass effect */
    backdrop-filter: blur(5px);
    background: rgba(235, 235, 235, 0.75);
}

.map-elements-control .elements-popup {
    right: -54px;
}

.map-legend-control .legend-popup {
    right: -108px;
}

.settings-popup.hidden,
.elements-popup.hidden,
.legend-popup.hidden {
    display: none;
}

.settings-content,
.elements-content,
.legend-content {
    padding: 16px;
    min-width: 280px;
    max-width: 350px;
}

.settings-content h3,
.elements-content h3,
.legend-content h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    font-weight: bold;
}

.settings-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.settings-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.settings-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
}

.settings-section label {
    display: block;
    margin: 6px 0;
    font-size: 0.9rem;
    cursor: pointer;
}

.settings-section input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.base-layer-buttons {
    display: flex;
    border: 1px solid #ccc;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.base-layer-buttons .base-layer-btn {
    flex: 1;
    min-width: 80px;
    border: none;
    border-right: 1px solid #ccc;
    background: #f2f2f2;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.2s;
}

.base-layer-buttons .base-layer-btn:last-child {
    border-right: none;
}

.base-layer-buttons .base-layer-btn:hover {
    background: #e0e0e0;
}

.base-layer-buttons .base-layer-btn.active {
    background: #2563eb;
    color: white;
}

.elements-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.elements-list li {
    margin: 4px 0;
    border-radius: 4px;
}

.elements-list li label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.elements-list li label:hover {
    background: rgba(0, 0, 0, 0.05);
}

.elements-list .element-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.elements-list li span {
    flex: 1;
    font-size: 0.9rem;
}

.elements-list input[type="checkbox"] {
    cursor: pointer;
}

.elements-list .empty-message {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 0.9rem;
}

/* Legend styles */
.cabin-legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
    font-size: 0.9rem;
}

.cabin-legend-item img {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.cabin-legend-item .legend-label {
    flex: 1;
}

.cabin-legend-item .legend-sublabel {
    font-size: 0.8rem;
    color: #666;
    margin-top: 2px;
}

.legend-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.legend-section h4 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
}

.leaflet-attribution-flag{
    display: none !important;
}