/* =========================================================
   Udir-kart v2.0.2 – FINAL WORKING STRUCTURE
   =======================================================*/

:root {
    --bg: #eef1f3;
    --panel-bg: #ffffff;
    --text: #2f3b45;
    --muted: #65727e;
    --line: #e0e6eb;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    --accent-600: #0b5c86;
    --focus: #ff9f1c;
    --overlay-fill: rgba(255, 159, 28, .05);
    --overlay-stroke: #c56a00;
    --overlay-hover: rgba(255, 159, 28, .25);
    --z-map: 0;
    --z-ui-panel: 200;
    --z-ui-buttons: 100;
    --z-tooltip: 1000;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body:not(.info-page) {
    overflow: hidden;
}

/* --------------------------- */
/* LAG 1: Kartet (Bakgrunn)    */
/* --------------------------- */
#map-layer {
    position: absolute;
    inset: 0;
    z-index: var(--z-map);
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    /* FIKS: Tillat at kartlaget mottar events, som er nødvendig for pan/zoom */
    pointer-events: auto;
}

#map-layer:active {
    cursor: grabbing;
}

#canvasWrap {
    position: absolute;
    transform-origin: 0 0;
    transition: transform 0.1s linear;
}

#floorImg {
    display: block;
    max-width: none;
    pointer-events: none;
    user-select: none;
}

#overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

/* Polygon styles */
.room-zone {
    fill: var(--overlay-fill);
    stroke: none;
    stroke-width: 0;
    cursor: pointer;
    transition: all 0.1s ease;
    pointer-events: auto;
}

.room-zone:hover {
    fill: var(--overlay-hover);
}

.room-zone.is-active {
    fill: rgba(255, 159, 28, 0.45);
    stroke: #ff9f1c;
    stroke-width: 4;
}

.room-zone.is-dimmed {
    opacity: 0.3;
    pointer-events: none;
}

.is-local-override {
    stroke: blue !important;
    stroke-dasharray: 5 5;
}

.admin-preview {
    fill: rgba(255, 0, 0, 0.2);
    stroke: red;
    stroke-width: 2;
}

body.draw-mode .room-zone {
    pointer-events: none !important;
    cursor: crosshair !important;
}

/* --------------------------- */
/* LAG 2: UI (Flytende)        */
/* --------------------------- */
#ui-layer {
    position: absolute;
    inset: 0;
    /* Tvinger UI-laget til å vinne Z-index krigen over kartet */
    z-index: 50;
    pointer-events: none;
    /* Lar klikk passere gjennom til kart hvis ingen UI-element er der */
}

.floating-panel {
    position: absolute;
    background: var(--panel-bg);
    /* FIKS: Tvinger menu-panelet til å fange klikk */
    pointer-events: auto !important;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    z-index: 60;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* --- ADMIN UI TOOLBAR --- */
.admin-toolbar {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 450px;
    background: #fff;
    border: 1px solid #ccc;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    pointer-events: auto !important;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

body:not(.admin) .admin-toolbar {
    display: none !important;
}

/* --- DESKTOP VIEW (> 800px) --- */
@media (min-width: 801px) {
    .floating-panel {
        top: 20px;
        left: 20px;
        width: 380px;
        max-height: calc(100vh - 40px);
        border-radius: 8px;
        border: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
        background: #fff;
        flex-shrink: 0;
        display: flex !important;
        z-index: 60;
        right: 20px;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    body.menu-open .zoom-controls {
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
    }
}

/* --- [UI Komponenter, Lister, etc.] --- */
.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    flex-shrink: 0;
}

.pillbar {
    display: flex;
    align-items: center;
    background: #f0f4f7;
    border-radius: 8px;
    padding: 4px;
}

.pill-select {
    background: transparent;
    border: none;
    font-weight: 600;
    color: var(--accent-600);
    padding: 0 8px;
    height: 36px;
    cursor: pointer;
    font-size: 15px;
}

.pill-search {
    flex: 1;
    display: flex;
    align-items: center;
    border-left: 1px solid #dce2e8;
    padding-left: 8px;
}

.pill-search input {
    width: 100%;
    border: none;
    background: transparent;
    height: 36px;
    outline: none;
    font-size: 15px;
    color: var(--text);
}

.pill-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--muted);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.pill-icon:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text);
}

.pill-icon:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.pill-icon.copied {
    color: #fff !important;
    background: #28a745 !important;
    opacity: 1 !important;
}

.pill-clear {
    margin-right: 4px;
}

/* Lister */
#listsPane {
    pointer-events: auto !important;
    z-index: 61;
    flex: 1;
    overflow-y: auto;
    background: #fff;
    position: relative;
}

.lists-scroll-area {
    padding: 12px 16px;
}

.list-block {
    margin-bottom: 12px;
}

.section-header {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin: 0 0 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    user-select: none;
}

.section-header:hover {
    color: var(--text);
}

.chevron {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.list-content {
    display: block;
}

.list-block.is-collapsed .list-content {
    display: none;
}

.list-block.is-collapsed .chevron {
    transform: rotate(-90deg);
}

.list-item {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid #f0f2f4;
    cursor: pointer;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: #fafbfc;
    margin: 0 -10px;
    padding: 10px 10px;
    border-radius: 4px;
}

.list-item.is-active {
    background: #e1f0f7;
    margin: 0 -16px;
    padding: 10px 16px;
    border-color: transparent;
}

.item-main {
    font-weight: 500;
    font-size: 15px;
}

.item-idname {
    display: block;
}

.item-tags {
    margin-top: 4px;
    display: flex;
    gap: 6px;
}

.tag {
    font-size: 11px;
    background: #f0f4f7;
    padding: 2px 6px;
    border-radius: 4px;
    color: #666;
}

.panel-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.panel-footer a {
    color: var(--accent-600);
    text-decoration: none;
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
    z-index: var(--z-ui-buttons);
    transform: translateZ(0);
    will-change: transform, bottom;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.zoom-controls button {
    width: 40px;
    height: 40px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 20px;
    color: var(--text);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.1s;
}

.zoom-controls button:hover {
    background: #f0f4f7;
}

.zoom-controls button:active {
    background: #e1f0f7;
}

/* Map Tooltip (Hover) */
.map-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    pointer-events: none;
    z-index: var(--z-tooltip);
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: none;
}

@media (hover: hover) {
    .map-tooltip.is-visible {
        display: block;
    }
}

/* SR-only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Spesialregler for info.html */
.info-page .container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Permanent Label (Aktivt rom på mobil) */
.map-active-label {
    position: absolute;
    background: var(--accent-600);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    transform: translate(-50%, -120%);
    pointer-events: none;
    white-space: nowrap;
    z-index: 50;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    will-change: transform;
}

/* Fjerner all interaksjon fra polygoner i tegnemodus */
body.draw-mode .room-zone {
    pointer-events: none !important;
    cursor: crosshair !important;
}

/* Overstyrer standard grab-ikonet for tegning når modusen er aktiv */
body.draw-mode #map-layer {
    cursor: crosshair !important;
}

#are-pin {
    /* Juster bredden her for å endre ikonets størrelse */
    width: 300px;
    height: auto;
    /* ... andre stiler ... */
}

/* --- MOBILE VIEW (<= 800px) --- */
@media (max-width: 800px) {
    .floating-panel {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 65vh;
        max-height: 65vh;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        border-top: 1px solid var(--line);
        display: flex !important;
        z-index: 60;
        /* Justert: 95px skal matche ny høyde på header (32px padding + søkefelt + 12px padding) */
        transform: translateY(calc(100% - 95px));
        will-change: transform;
    }

    .floating-panel.is-expanded {
        transform: translateY(0);
    }

    .panel-header {
        position: relative;
        cursor: grab;
        touch-action: none;
        /* Økt padding-top for å gi plass til håndtaket OVER søkefeltet */
        padding-top: 32px;
        padding-bottom: 12px;
        min-height: auto;
        /* Lar innholdet styre høyden */
        z-index: 70;
        background: #fff;
        border-bottom: 1px solid var(--line);
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
    }

    .panel-header::before {
        content: '';
        display: block;
        position: absolute;
        /* Plassert midt i den nye padding-top sonen */
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: 60px;
        /* Litt smalere for et renere uttrykk */
        height: 5px;
        background-color: #cbd5e1;
        /* Litt lysere farge */
        border-radius: 100px;
        z-index: 75;
        pointer-events: none;
    }

    .zoom-controls {
        bottom: auto;
        top: 20px;
        right: 20px;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    body.menu-open .zoom-controls {
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
    }
}