/* Generell styling */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    display: flex;
    flex-direction: column;
    background-color: #f4f6f9;
}

/* Header og navigasjon */
header {
    background-color: #ffffff;
    color: #333;
    padding: 12px 25px;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-bottom: 1px solid #e9ecef;
    z-index: 1001;
    position: relative;
}

header nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

header h1 {
    margin: 0;
    font-size: 1.6em;
    font-weight: 600;
}

header h1 a {
    color: #212529;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.header-logo {
    height: 1em;
    width: 1em;
    margin-right: 0.5em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-links a {
    color: #495057;
    text-decoration: none;
    font-size: 0.95em;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.nav-links a:hover {
    background-color: #f1f3f5;
    color: #000;
}

.nav-links .nav-button {
    background-color: #007bff;
    color: #ffffff;
    font-weight: 500;
}

.nav-links .nav-button:hover {
    background-color: #0056b3;
    color: #ffffff;
}

/* Styling for nedtrekksmeny */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropbtn.nav-button {
    border: none;
    margin: 0;
    font-family: inherit;
    line-height: inherit;
    cursor: pointer;
    display: inline-block;
    font-size: 0.95em;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    background-color: #007bff;
    color: #ffffff;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.dropbtn.nav-button:hover {
    background-color: #0056b3;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #ffffff;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1002;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

.dropdown-content a {
    color: #333;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
}

.dropdown-content a:hover {
    background-color: #f1f3f5;
    color: #000;
}

.show {
    display: block;
}

/* Hovedinnhold og kart */
main {
    flex-grow: 1;
    position: relative;
}

#kart {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background-color: #e6e6e6;
}

/* Leaflet popups */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
    font-size: 14px;
    line-height: 1.5;
    margin: 15px !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.leaflet-popup-content b {
    color: #1a1a1a;
    font-size: 16px;
}

.leaflet-popup-content a {
    color: #007bff;
    text-decoration: none;
    font-weight: bold;
}

.leaflet-popup-content a:hover {
    text-decoration: underline;
}

/* Info-boks (øverst til høyre) */
.leaflet-control-container .info-boks {
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    line-height: 1.5;
    font-size: 13px;
    max-width: 350px;
    box-sizing: border-box;
}

.info-boks h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    padding-bottom: 5px;
    border-bottom: 1px solid #e0e0e0;
}

.info-boks ul {
    list-style-type: none;
    padding-left: 0;
    margin: 0;
}

.info-boks li {
    padding: 3px 0;
}

/* Disclaimer-tekstboksen */
.leaflet-control-container .disclaimer {
    background: rgba(255, 255, 255, 0.9);
    padding: 5px 10px;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
    box-shadow: 0 -1px 5px rgba(0,0,0,0.1);
}

.leaflet-container .leaflet-bottom.leaflet-left {
    width: 100%;
    bottom: 0;
    left: 0;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Styling for filtervindu (Layer Control) */
.leaflet-control-layers-expanded {
    max-height: calc(100vh - 250px);
    overflow-y: auto;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    background: white;
    border: 1px solid #ddd;
    transition: all 0.3s ease-in-out;
    box-sizing: border-box;
}

/* KUN når JS sier at boksen kan scrolles: legg til mer rom i bunnen og myk scroll */
.leaflet-control-layers.is-scrollable .leaflet-control-layers-expanded {
    padding-bottom: 60px; /* Økt for å gi god plass */
    scroll-behavior: smooth;
}

.leaflet-control-layers-group-label {
    font-size: 1em;
    font-weight: 700;
    color: #212529;
    margin: 0;
    padding: 0 5px;
    height: 28px;
    line-height: 28px;
    border-bottom: 1px solid #dcdfe3;
    cursor: pointer;
    display: block;
    transition: background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}

.leaflet-control-layers-group:not(:first-child) {
    margin-top: 15px;
}

.leaflet-control-layers-overlays label {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 5px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
    -webkit-tap-highlight-color: transparent;
}

.leaflet-control-layers-expanded .leaflet-control-layers-group:nth-of-type(1) label {
    background-color: #FFECEC;
}
.leaflet-control-layers-expanded .leaflet-control-layers-group:nth-of-type(1) label:hover {
    background-color: #FFDCDC;
}

.leaflet-control-layers-expanded .leaflet-control-layers-group:nth-of-type(2) label {
    background-color: #FFF7E6;
}
.leaflet-control-layers-expanded .leaflet-control-layers-group:nth-of-type(2) label:hover {
    background-color: #FFF0CC;
}

.leaflet-control-layers-selector {
    margin-right: 10px;
    transform: scale(1.1);
    flex-shrink: 0;
}

.layer-icon {
    font-size: 20px;
    margin-right: 8px;
    vertical-align: middle;
    position: relative;
    top: -2px;
}

.leaflet-control-layers-overlays label span {
    line-height: 1.3;
}

/* Felles stil for egendefinerte knapper */
.leaflet-control-custom {
    background: white;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}

.leaflet-control-custom:hover {
    background-color: #f4f4f4;
}

/* Styling for brukerens posisjonsikon */
.custom-user-icon div {
    width:10px;
    height:10px;
    background:#007bff;
    border-radius:50%;
    border:2px solid white;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

/* Stil for modal-vindu (Om siden) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    color: #888;
    cursor: pointer;
}

/* Stil for kartvelger */
.custom-basemap-wrapper {
    position: relative;
}
.custom-basemap-panel {
    display: none;
    position: absolute;
    bottom: 50px;
    right: 0;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    padding: 12px;
    display: flex;
    gap: 12px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.custom-basemap-panel.show {
    display: flex;
    visibility: visible;
    opacity: 1;
}

.custom-basemap-choice {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #333;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    width: 75px;
}

.custom-basemap-choice:hover {
    background-color: #f1f3f5;
    transform: scale(1.05);
}

.custom-basemap-choice img {
    width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    border-radius: 4px;
    border: 1px solid #ddd;
    object-fit: cover;
    margin-bottom: 6px;
}

.custom-basemap-choice span {
    font-size: 12px;
    font-weight: 500;
}

.custom-basemap-choice.active-basemap {
    border-color: #007bff;
    background-color: #e7f1ff;
}

/* Styling for søkefelt */
#search-container {
    position: relative;
    flex-grow: 1;
    max-width: 450px;
    margin: 0 20px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

#search-input {
    width: 100%;
    height: 40px;
    padding: 0 45px 0 45px;
    font-size: 15px;
    border: 1px solid #ccc;
    border-radius: 20px;
    box-sizing: border-box;
    transition: all 0.2s ease-in-out;
    background-color: #f4f6f9;
}

#search-input:focus {
    outline: none;
    border-color: #007bff;
    background-color: #ffffff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #888;
    pointer-events: none;
}

#search-results {
    display: none;
    position: absolute;
    width: 100%;
    background-color: white;
    border: 1px solid #ddd;
    border-top: none;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1003;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    border-radius: 0 0 8px 8px;
}

.search-result-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: #f1f3f5;
}

.search-result-item .material-symbols-outlined {
    margin-right: 12px;
    color: #555;
}

.result-text-main {
    font-weight: 500;
}
.result-text-secondary {
    font-size: 0.9em;
    color: #666;
    margin-left: 5px;
}

/* Mobilvisning for søk */
#search-toggle-btn, #search-close-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: #333;
    padding: 5px;
    border-radius: 50%;
}
#search-toggle-btn:hover, #search-close-btn:hover {
    background-color: #f1f3f5;
}

/* --- START: STYLING FOR VERKTØYPANEL --- */
.leaflet-top.leaflet-left:has(.population-control-container.expanded) {
    z-index: 1002;
}

.population-control-container {
    background: white;
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: width 0.2s ease, height 0.2s ease, box-shadow 0.2s ease;
}

.population-control-button {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
}

.population-control-button .material-symbols-outlined {
    font-size: 22px;
}

.population-panel {
    display: none;
    padding: 15px;
    padding-top: 35px;
    width: 320px;
    box-sizing: border-box;
}

.population-control-container.expanded .population-panel {
    display: block;
}

.population-control-container.expanded .population-control-button {
    display: none;
}

.population-control-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.population-control-header label {
    font-weight: 500;
    font-size: 15px;
    color: #333;
    cursor: pointer;
}

.population-toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.population-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.population-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}
.population-toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
input:checked + .population-toggle-slider {
    background-color: #54278f;
}
input[id="measurement-toggle"]:checked + .population-toggle-slider {
    background-color: #007bff;
}
input:checked + .population-toggle-slider:before {
    transform: translateX(20px);
}

.population-slider-wrapper {
    display: none;
}

.population-slider-wrapper.visible {
    display: block;
}

.population-slider-area {
    position: relative;
    padding: 10px 0;
}

.population-slider {
    width: 100%;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    z-index: 2;
}
.population-slider::-webkit-slider-runnable-track {
    background: #e0e0e0;
    height: 4px;
    border-radius: 4px;
}
.population-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -8px;
    background: #756bb1;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.population-slider::-moz-range-track {
    background: #e0e0e0;
    height: 4px;
    border-radius: 4px;
}
.population-slider::-moz-range-thumb {
    background: #756bb1;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.population-slider-ticks {
    display: flex;
    justify-content: space-between;
    position: absolute;
    width: 100%;
    left: 0;
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    z-index: 1;
}

.population-slider-ticks .tick {
    width: 2px;
    height: 100%;
    background-color: #b0b0b0;
    position: absolute;
}

.population-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    padding-top: 5px;
}

.population-slider-labels span {
    cursor: pointer;
    user-select: none;
    flex: 1 1 0;
    text-align: center;
    padding: 4px 0;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.population-slider-labels span:first-child { text-align: left; }
.population-slider-labels span:last-child { text-align: right; }

.population-slider-labels span:hover {
    background-color: #f0f0f0;
}

/* Mykere zooming av soner */
.leaflet-zoom-anim .leaflet-interactive {
    transition: opacity 0.2s ease;
}

.leaflet-zooming .leaflet-interactive {
    opacity: 0.1;
}

/* --- START: STYLING FOR MÅLEVERKTØY --- */
.measurement-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.measurement-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.measurement-header label {
    font-weight: 500;
    font-size: 15px;
    color: #333;
    cursor: pointer;
}

.measure-buttons-container {
    display: flex;
    gap: 10px;
}

.measure-btn {
    flex-grow: 1;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: #004085;
    background-color: #cce5ff;
    border: 1px solid #b8daff;
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease;
}

.measure-btn:hover {
    background-color: #b8daff;
}

.delete-drawings-btn {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: #c82333;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease;
}

.delete-drawings-btn:hover {
    background-color: #f1b0b7;
}

/* --- FORBEDRINGER FOR VERKTØYPANEL --- */
.population-panel {
    position: relative;
}

.panel-close-btn {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 24px;
    color: #888;
    cursor: pointer;
    line-height: 1;
    font-weight: bold;
    z-index: 10;
}
.panel-close-btn:hover {
    color: #333;
}

/* NYTT: Stil for aktiv verktøyknapp */
.measure-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}


/* --- START: KORRIGERT STYLING FOR INFO-BOKS OG MOBIL --- */

/* Skjul mobil-spesifikke knapper på PC som standard */
.info-boks .info-minimize-btn,
.info-boks .info-toggle-icon {
    display: none;
}

/* Media queries for mobil */
@media (max-width: 768px) {
    header {
        padding: 10px 15px;
    }
    header h1 {
        font-size: 1.2em;
    }
    .nav-links {
        gap: 8px;
    }
    .nav-links a, .nav-links .nav-button {
        padding: 6px 8px;
        font-size: 0.8em;
        white-space: nowrap; /* Forhindrer at knapper brekker */
    }
    .leaflet-control-layers-expanded {
        min-width: 220px;
        padding: 10px;
        max-height: 40vh;
    }
    
    .leaflet-control-layers.is-scrollable .leaflet-control-layers-expanded {
        padding-bottom: 60px;
    }
    
    .leaflet-bottom.leaflet-right {
        margin-bottom: 40px;
    }

    .leaflet-top.leaflet-left {
        top: 10px;
    }

    .population-panel {
        width: calc(100vw - 40px);
        max-width: 320px;
    }

    #search-toggle-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-right: 5px;
    }

    #search-container {
        display: none;
    }

    header.search-active #search-container {
        display: flex;
        align-items: center;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: white;
        padding: 0 10px;
        box-sizing: border-box;
        z-index: 1003;
    }

    header.search-active #search-close-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
    }

    header.search-active h1,
    header.search-active .nav-links {
        opacity: 0;
        pointer-events: none;
    }

     /* Styling for minimerbar info-boks (kun mobil) */
    .info-boks {
        position: relative;
        transition: all 0.2s ease-in-out;
        overflow: hidden;
        box-sizing: border-box;
    }

    .info-boks-content {
        transition: opacity 0.1s ease;
    }

    /* "X"-knappen for å minimere - KORRIGERT */
    .info-boks .info-minimize-btn { /* <--- VIKTIG ENDRING HER */
        display: block; /* Vises på mobil når utvidet */
        position: absolute;
        top: 2px;
        right: 5px;
        font-size: 24px;
        font-weight: bold;
        color: #aaa;
        cursor: pointer;
        line-height: 1;
    }
    .info-boks .info-minimize-btn:hover {
        color: #333;
    }

    /* Den minimerte tilstanden (rund "i"-knapp) */
    .info-boks.minimized {
        width: 40px;
        height: 40px;
        padding: 0;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #fff;
        border: 1px solid #ccc;
    }

    /* Gjem innhold og "X" når boksen er minimert */
    .info-boks.minimized .info-boks-content,
    .info-boks.minimized .info-minimize-btn {
        display: none;
    }
    
    /* Vis "i"-ikonet når boksen er minimert */
    .info-boks.minimized .info-toggle-icon {
        display: block;
        font-size: 24px;
        color: #333;
    }

    /* Sørg for at "i"-ikonet er skjult når boksen er utvidet */
    .info-boks .info-toggle-icon {
        display: none;
    }
}

/* Stil for modal-vindu (Om siden & Endringslogg) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 25px 30px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    line-height: 1.5;
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    color: #888;
    cursor: pointer;
}
.modal-close-button:hover {
    color: #333;
}

/* Felles stil for innhold i modal-vinduer */
.modal-content h1,
.modal-content h2,
.modal-content h3,
.modal-content h4 {
    color: #212529; /* Svart overskrift */
    margin-top: 15px;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.modal-content h2:first-child,
.modal-content h1:first-child {
    margin-top: 0;
}

.modal-content h4 {
    margin-top: 20px;
    border-bottom: none; /* Kompakt visning */
}

.modal-content p {
    margin: 0 0 10px 0;
}

.modal-content a {
    color: #007bff;
}

.modal-content .button-link {
    display: inline-block;
    padding: 10px 18px;
    background-color: #007bff;
    color: white !important; /* Overstyrer .modal-content a */
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    margin-top: 5px;
    border: none;
    cursor: pointer;
    font-size: 1em;
}

.modal-content .button-link:hover {
    background-color: #0056b3;
    color: white !important;
}

/* Endringslogg-spesifikk stil */
#endringslogg-container .change-entry {
    margin-bottom: 20px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 15px;
}
#endringslogg-container .change-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
#endringslogg-container .change-entry h2 {
    border-bottom: none;
    margin-bottom: 10px;
    font-size: 1.2em;
}
#endringslogg-container ul {
    margin-top: 0;
    padding-left: 25px;
    margin-bottom: 0;
}
#endringslogg-container li {
    margin-bottom: 8px;
}