/* css/navigation.css
 * Dynamiske navigasjonsstiler: klassisk topp-meny vs moderne bunn-meny.
 */

/*
 * Bunnmeny-bar: egen «sandkasse» – skal aldri arve left/transform fra sidebar/off-canvas.
 * (Når body får menyklasser kan andre regler lekke; !important låser bar til viewport-bunn.)
 */
/* Full bredde kun når ikke flytende «pill»-variant (se mobile-nav.css) */
#bottom-nav-bar.bottom-nav-bar:not(.bottom-nav-bar--floating),
nav#bottom-nav-bar:not(.bottom-nav-bar--floating) {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0;
    transform: none !important;
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

/* --- KLASSISK (standard) --- */
body.nav-style-classic .bottom-nav-bar {
    display: none !important;
}

/* --- BUNN-MENY (kun på mobil) --- */
@media (max-width: 768px) {
    /*
     * Vis kun page-toolbar øverst: logo-rad (#headerInner) skjules, ikke hele headeren
     * (slik at tabs + action-meny fortsatt er tilgjengelige).
     */
    body.nav-style-bottom #header-container,
    body.nav-style-bottom #mainHeader,
    body.nav-style-bottom header#mainHeader {
        display: flex !important;
        visibility: visible !important;
    }
    body.nav-style-bottom #header-container {
        flex-direction: column;
        padding-top: env(safe-area-inset-top);
    }
    body.nav-style-bottom #mainHeader {
        flex-direction: column;
        padding: 0 !important;
        background: var(--card-bg);
        box-shadow: var(--shadow-sm);
    }
    body.nav-style-bottom #mainHeader #headerInner {
        display: none !important;
    }
    /* Brødsmuler skjules på mobil med bunnmeny */
    body.nav-style-bottom #mainHeader .toolbar-left,
    body.nav-style-bottom #mainHeader #breadcrumbs,
    body.nav-style-bottom #mainHeader .breadcrumbs {
        display: none !important;
    }
    /* Én rad: horisontalt scrollbare faner + filter/handlinger-knapp */
    body.nav-style-bottom #page-toolbar.page-toolbar,
    body.nav-style-bottom nav#page-toolbar.page-toolbar {
        flex-wrap: nowrap !important;
        align-items: center !important;
        height: 44px !important;
        min-height: 44px !important;
        padding: 0 8px 0 12px !important;
        gap: 8px !important;
    }
    body.nav-style-bottom #page-toolbar .toolbar-center,
    body.nav-style-bottom nav#page-toolbar .toolbar-center {
        order: 0 !important;
        flex: 1 1 auto !important;
        flex-basis: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 0 !important;
        justify-content: flex-start !important;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        touch-action: pan-x;
    }
    body.nav-style-bottom #page-toolbar .toolbar-center::-webkit-scrollbar {
        display: none;
    }
    body.nav-style-bottom #page-toolbar #toolbar-tabs-slot {
        flex-wrap: nowrap;
        width: max-content;
        max-width: none;
        padding-right: 4px;
    }
    body.nav-style-bottom #page-toolbar .toolbar-right {
        order: 1 !important;
        flex: 0 0 auto !important;
        flex-shrink: 0;
    }

    body.nav-style-bottom .bottom-nav-bar:not(.bottom-nav-bar--floating) {
        display: flex !important;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: var(--brand);
        border-top: 1px solid var(--brand-muted);
        z-index: 1000;
        align-items: center;
        justify-content: space-between;
    }

    body.nav-style-bottom #main-viewport-container {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    .bottom-nav-action-slot {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
    }

    .bottom-nav-icon-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: transparent;
        color: var(--white);
        border: none;
        cursor: pointer;
    }

    .bottom-nav-icon-btn:hover {
        background: var(--brand-muted);
    }

    .bottom-nav-icon-btn [data-lucide],
    .bottom-nav-icon-btn svg {
        width: 24px;
        height: 24px;
    }

    .bottom-nav-action-btn {
        width: 56px;
        height: 56px;
        min-width: 56px;
        min-height: 56px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: var(--action);
        color: var(--white);
        border: none;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .bottom-nav-action-btn:hover {
        background: var(--action-hover);
    }

    .bottom-nav-action-btn [data-lucide],
    .bottom-nav-action-btn svg {
        width: 24px;
        height: 24px;
    }

    /* Bottom-nav dropdown/sheet når Action-knappen åpner menyen */
    .bottom-nav-menu {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        background: var(--brand);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        z-index: 1001;
        transition: none;
        transform-origin: center bottom;
    }

    .bottom-nav-menu.hidden {
        display: none !important;
    }

    .bottom-nav-menu:not(.hidden) {
        display: block !important;
        animation: bottomNavSheetSlideUp 0.25s ease-out forwards;
    }

    .bottom-nav-menu a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 20px;
        min-height: 48px;
        color: var(--white);
        text-decoration: none;
        border-radius: var(--radius);
        text-align: left;
    }

    .bottom-nav-menu a:hover {
        background: var(--brand-muted);
    }

    .bottom-nav-menu a [data-lucide],
    .bottom-nav-menu a svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
        opacity: 0.9;
    }

    #bottom-nav-user-menu {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        background: var(--brand);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        z-index: 1001;
    }

    #bottom-nav-user-menu.hidden {
        display: none !important;
    }

    #bottom-nav-user-menu:not(.hidden) {
        display: block !important;
        animation: bottomNavSheetSlideUp 0.25s ease-out forwards;
    }

    @keyframes bottomNavSheetSlideUp {
        from { transform: translate3d(0, 100%, 0); }
        to { transform: translate3d(0, 0, 0); }
    }

    #bottom-nav-user-menu a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 20px;
        min-height: 48px;
        color: var(--white);
        text-decoration: none;
        border-radius: var(--radius);
    }

    #bottom-nav-user-menu a:hover {
        background: var(--brand-muted);
    }
}

/* Segmented control for navigasjonsstil (profil-innstillinger) */
.nav-style-segmented {
    display: flex;
    gap: 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
.nav-style-segmented .nav-style-opt {
    flex: 1;
    padding: 8px 16px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.nav-style-segmented .nav-style-opt:hover {
    background: var(--border);
    color: var(--text);
}
.nav-style-segmented .nav-style-opt.active {
    background: var(--action);
    color: var(--white);
}
.nav-style-segmented .nav-style-opt + .nav-style-opt {
    border-left: 1px solid var(--border);
}

/* Desktop: bunn-meny skjules alltid, nav-stil-valg skjules i brukermeny */
@media (min-width: 769px) {
    body.nav-style-bottom .bottom-nav-bar {
        display: none !important;
    }

    body.nav-style-bottom #header-container {
        display: flex !important;
    }

    body.nav-style-bottom #main-viewport-container {
        padding-bottom: 0;
    }

    .nav-style-menu-item {
        display: none !important;
    }
}

/* --- Header: toppnivå som ikoner (gruppe = dropdown, lenke = direkte) — én rad fra editor --- */
#mainHeader #headerInner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

#mainHeader #logoWrapper {
    flex-shrink: 0;
}

#mainHeader .header-primary-nav {
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/*
 * Viktig: ikke overflow:auto/scroll på denne beholderen — da klippes absolutt-
 * posisjonerte dropdown-paneler vertikalt (overflow-x:auto tvinger overflow-y
 * til auto i praksis). Bruk flex-wrap ved mange ikoner; horisontal scroll kan
 * legges på en egen indre boks uten dropdown-barn senere om nødvendig.
 */
#mainHeader .header-menu-links {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
    overflow: visible;
    max-width: 100%;
}

#mainHeader .header-nav-dropdown {
    position: relative;
    flex-shrink: 0;
}

#mainHeader .header-nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--white);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

#mainHeader .header-nav-icon-btn:hover,
#mainHeader .header-nav-icon-btn:focus-visible {
    background: var(--brand-muted);
    outline: none;
}

#mainHeader .header-nav-icon-btn .lucide,
#mainHeader .header-nav-icon-btn svg {
    width: 24px;
    height: 24px;
    stroke: var(--white);
}

#mainHeader .header-nav-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    min-width: 220px;
    max-width: min(320px, 90vw);
    max-height: min(70vh, 480px);
    overflow-y: auto;
    background: var(--brand);
    border: 1px solid var(--brand-muted);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    /* Over page-toolbar (z-index ~100) og innhold under header */
    z-index: 10050;
    padding: 6px 0;
}

#mainHeader .header-nav-panel.hidden {
    display: none !important;
}

#mainHeader .header-nav-panel-link {
    display: block;
    padding: 12px 18px;
    font-size: 0.9rem;
    color: var(--white);
    text-decoration: none;
    border-bottom: 1px solid var(--brand-muted);
    transition: background 0.2s;
}

#mainHeader .header-nav-panel-link:last-child {
    border-bottom: none;
}

#mainHeader .header-nav-panel-link:hover {
    background: var(--brand-muted);
}

#mainHeader .header-nav-panel-action {
    width: 100%;
    box-sizing: border-box;
    display: block;
    text-align: left;
    font: inherit;
    font-size: 0.9rem;
    color: var(--white);
    cursor: pointer;
    border: none;
    border-bottom: 1px solid var(--brand-muted);
    background: transparent;
    padding: 12px 20px;
    transition: background 0.2s;
}

#mainHeader .header-nav-panel-action:last-child {
    border-bottom: none;
}

#mainHeader .header-nav-panel-action:hover {
    background: var(--brand-muted);
}

@media (max-width: 768px) {
    #mainHeader .header-nav-panel {
        width: min(100vw - 24px, 320px);
    }
}
