
html, body {
    margin: 0;
    padding: 0;
    /* FIX 25: Use 100dvh (dynamic viewport height) instead of 100% so the
       height doesn't jump when the mobile browser toolbar appears/disappears. */
    height: 100dvh;
    font-family: Arial, sans-serif;
    /* Lock the body so it never scrolls — the mobile toolbar then has nothing
       to react to and stays out of the way. */
    overflow: hidden;
    overscroll-behavior: none;
}

.input-area {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-grow: 1;
    gap: 10px;
}

.normal-group,
.search-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}

.hidden { display: none !important; }

.search-icon {
    cursor: pointer;
    border: none;
    background: none;
    font-size: 1.2rem;
    margin: 0;
}

/* FIX 29b: Both containers are position:absolute within #headerWrapper and
   occupy EXACTLY the same space (top:22px to bottom:0). Toggling between
   them with display:none/flex is now invisible to the layout engine — the
   wrapper never changes size, no fixed-position recalculation, no drift. */
.top-container,
#searchContainer {
    position: absolute;
    top: 22px;      /* below the .counter line */
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: none; /* absolute positioning makes max-width on container redundant */
    margin: 0;
    padding: 0 16px;
    box-sizing: border-box;
}

.top-container select,
.top-container input[type="text"] {
    width: 140px;
    min-width: 140px;
    max-width: 140px;
    height: 32px;
    padding: 2px 6px;
    font-size: 0.92rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    flex: 0 0 140px;
}

#searchContainer form {
    display: flex;
    align-items: center;
    gap: 10px;
}

#searchContainer .search-form > * { flex-shrink: 0; }

#slider {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: auto;
    margin: 1rem auto;
    /* FIX 25e: Push slider below the fixed header (counter ~16px + menu ~52px) */
    margin-top: 0;
    padding-top: 70px;
    box-sizing: border-box;
}

#slider a {
    display: block;
    width: 100%;
    text-align: center;
}

#slider img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    /* FIX 25f: dvh stays stable when the mobile toolbar shows/hides */
    max-height: calc(100dvh - 195px);
    object-fit: contain;
    margin: 0 auto;
}

#fixedBottomWrapper {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 20px;
    padding: 10px;
    /* FIX 25d: Safe-area inset keeps the arrows above the iPhone home bar */
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

#arrowContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.counter {
    text-align: left;
    margin-left: 60px;
    margin-top: 0;
    font-size: 9px;
}

.arrow-disabled {
    opacity: 0.3;
    pointer-events: none;
    cursor: default;
}

#prevArrow, #nextArrow { cursor: pointer; }

/* Navnespørsmål: én linje rett over pilene. Fast posisjon, så bildet og pilene ikke flytter seg.
   z-index 400 ligger under KI-søk-modalen (500) og bunnlinjen (1000). */
#nameBanner {
    position: fixed;
    left: 50%;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    width: min(640px, calc(100% - 16px));
    z-index: 400;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 8px;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #cfd8da;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
    font-family: Arial, sans-serif;
}
#nameBanner[hidden] { display: none; }
#nameBanner #nameBannerHint { flex: 0 0 100%; margin-top: 2px; font: bold 11px/1.35 Arial, sans-serif; color: #222; text-align: center; }
#nameBanner input { flex: 1 1 0; min-width: 0; box-sizing: border-box; height: 22px; font: 16px/18px Arial, sans-serif; padding: 0 8px; border: 1px solid #ccc; border-radius: 4px; text-overflow: ellipsis; }
#nameBanner input::placeholder { font-size: 9.5px !important; }
#nameBanner button { flex: 0 0 auto; box-sizing: border-box; height: 22px; font: 11px/1.1 Arial, sans-serif; padding: 0 6px; border: 1px solid #bbb; border-radius: 4px; background: #f4f4f4; color: #222; cursor: pointer; white-space: nowrap; }
#nameBanner button.primary { background: #03a9fc; border-color: #03a9fc; color: #fff; font-weight: bold; }
#nameBanner button:disabled { opacity: .4; cursor: not-allowed; }
/* Mobil: mindre knapper og mer plass til navnefeltet. Feltet beholder 16px skrift
   (ellers zoomer iPhone ved fokus), men hjelpeteksten i det er mindre. */
@media (max-width: 600px) {
    #nameBanner { gap: 3px; padding: 5px; }
    #nameBanner button { font-size: 10.5px; padding: 0 5px; }
    #nameBanner input::placeholder { font-size: 9.5px !important; }
    #nameBanner #nameBannerHint { font-size: 9px; }
}
@media (max-width: 340px) {
    #nameBanner #nameBannerHint { font-size: 8.5px; }
}
.logo a { display: inline-block; padding-left: 6px; }
.photo-total-count { position: absolute; top: 0; right: 0; font-size: 9px; text-align: left; z-index: 201; }


/* FIX 25b: Fixed header wrapper — locks the logo, selects and search icon in
   place on both desktop and mobile. Uses safe-area insets so iPhone notch and
   home-bar don't push it around. */
/* FIX 29: #headerWrapper has a FIXED height (70px — matching #slider's
   padding-top). This is the key to stable menus on iOS Safari:
   - When height is 'auto', swapping .top-container / #searchContainer
     changes the wrapper's rendered height, which forces Safari to
     recalculate all position:fixed coordinates → elements visibly drift.
   - With a fixed height, the wrapper NEVER changes size during the swap,
     so Safari has nothing to recalculate. */
#headerWrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    z-index: 200;
    background: #fff;
    overflow: hidden;
    /* iPhone notch / status bar */
    padding-top: env(safe-area-inset-top, 0px);
    /* Android/iPhone side insets (landscape) */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    will-change: transform;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
}

.logo-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    max-width: 680px;
    margin: 0 auto;
    position: relative;
    z-index: 5;
}

.logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.logo img { display: block; vertical-align: middle; }

.logo-input-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.search-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

@media (max-width: 768px) {
    #slider img {
        max-width: 100%;
        max-height: 100dvh;
        object-fit: cover;
    }
}

@media (max-width: 600px) {
    .input-area,
    .normal-group,
    .search-group { gap: 3px; }

    .logo-bar         { padding: 4px 6px; }
    .logo-input-group { gap: 3px; }
    .logo img         { height: 24px; }

    .top-container { padding: 0 4px; }

    .top-container select,
    .top-container input[type="text"] {
        width: 90px;
        min-width: 90px;
        max-width: 90px;
        flex: 0 0 90px;
        font-size: 0.85rem;
        padding: 2px 4px;
    }

    /* År-feltet smalere og månedsfeltet bredere (samme samlede bredde som før) */
    .top-container #year {
        width: 66px; min-width: 66px; max-width: 66px; flex: 0 0 66px;
    }
    .top-container #monthOrCategory {
        width: 114px; min-width: 114px; max-width: 114px; flex: 0 0 114px;
    }

    .search-icon { font-size: 1rem; padding: 2px 4px; margin: 0; }

    .ai-search-btn {
        padding: 2px 5px;
        font-size: 10px;
        height: 32px; /* samme som år/måned-feltene (JS under justerer også for Edge mobil) */
    }
}

/* FIX 27: iOS Safari zooms the page when any text input has font-size < 16px.
   This zoom shifts all fixed/absolute elements, making the menu look like it
   moved. The fix targets only real touchscreen devices (not Windows Chrome)
   via the pointer:coarse media feature, so desktop layout is untouched. */
@media (hover: none) and (pointer: coarse) {
    .top-container input[type="text"] { font-size: 16px; }
}

@media (max-width: 580px) {
    .search-icon { margin: 0 4px; padding: 2px 6px; font-size: 1rem; }

    .search-form {
        justify-content: center;
        gap: 8px;
        flex-wrap: nowrap;
        margin-top: 10px;
    }

    .search-form select,
    .search-form input[type="text"] {
        height: 26px;
        font-size: 0.85rem;
        padding: 2px 6px;
        width: 72px;
    }

    .search-form input[type="text"] { width: 80px; }
    .logo img { height: 30px; }
}

/* ── AI-søk knapp ────────────────────────────────────────────────────────── */
.ai-search-btn {
    background: #fff;
    border: 1px solid #ccc;
    cursor: pointer;
    border-radius: 4px;
    padding: 3px 8px;
    color: #444;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    height: 32px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1;
    vertical-align: middle;
    box-sizing: border-box;
}
.ai-search-btn:hover { border-color: #9988cc; color: #6c5ce7; }
.ai-search-btn:active { background: #f5f4ff; }
.ai-search-btn .ai-star { font-size: 13px; line-height: 1; color: #7c6cdc; }

/* ── AI-søk modal ────────────────────────────────────────────────────────── */
#aiModal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.38);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 500;
    align-items: flex-start;
    justify-content: center;
    padding-top: 90px;
    box-sizing: border-box;
}
#aiModal.open { display: flex; }

#aiModalBox {
    width: min(620px, 94vw);
    background: #fff;
    border-radius: 12px;
    border: 1px solid #d8d8d8;
    box-shadow: 0 8px 40px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
    overflow: hidden;
}

#aiModalHeader {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
}

#aiSearchModalInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 16px;
    color: #222;
    caret-color: #6c5ce7;
    font-family: Arial, sans-serif;
    min-width: 0;
}
#aiSearchModalInput::placeholder { color: #aaa; }

#aiModalSuggestions {
    padding: 10px 16px 14px;
    background: #fafafa;
}

.ai-sug-label,
#aiModalStatus {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.ai-sug-label { margin-bottom: 8px; }

.ai-nb-warning {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    font-weight: bold;
    color: #c0392b;
    background: #fff3f3;
    border-left: 3px solid #e74c3c;
    padding: 2px 7px;
    border-radius: 0 4px 4px 0;
    letter-spacing: normal;
    text-transform: none;
}

.ai-sug-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.ai-chip {
    background: #f0eeff;
    border: 1px solid #c8b8f8;
    border-radius: 20px;
    padding: 3px 11px;
    color: #6c5ce7;
    font-size: 13px;
    cursor: pointer;
    font-family: Arial, sans-serif;
}
.ai-chip:hover,
.ai-vis-alle:hover { background: #e0d8ff; }

#aiModalStatus {
    padding: 7px 16px 3px;
    display: none;
    background: #fafafa;
    border-bottom: 1px solid #f0f0f0;
}

#aiModalResults { max-height: 350px; overflow-y: auto; background: #fff; }

.ai-res-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid #f4f4f4;
}
.ai-res-item:hover,
.ai-res-item.ai-active { background: #f5f2ff; }

.ai-res-thumb {
    width: 56px;
    height: 42px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
    background: #e8e8e8;
}

.ai-res-title { color: #222; font-size: 14px; font-weight: 600; line-height: 1.3; }
.ai-res-meta  { color: #888; font-size: 12px; margin-top: 1px; }
.ai-res-enter { color: #bbb; font-size: 12px; margin-left: auto;
                flex-shrink: 0; display: none; }
.ai-res-item.ai-active .ai-res-enter { display: inline; }

#aiModalFooter {
    border-top: 1px solid #eee;
    padding: 8px 14px;
    display: flex;
    gap: 14px;
    font-size: 11px;
    color: #bbb;
    flex-wrap: wrap;
    background: #fafafa;
}
.ai-footer-badge { margin-left: auto; color: #9988cc; }

.ai-res-desc {
    color: #666;
    font-size: 12px;
    margin-top: 2px;
    font-style: italic;
    line-height: 1.35;
}

.ai-vis-alle {
    display: inline-block;
    background: #f0eeff;
    border: 1px solid #c8b8f8;
    border-radius: 5px;
    padding: 3px 8px;
    color: #6c5ce7;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.5;
    cursor: pointer;
}
.ai-vis-alle:hover { color: #4a3ab0; }

.ai-modal-vis-alle-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #f5f2ff;
    border-bottom: 2px solid #c8b8f8;
}
.ai-modal-vis-alle-btn {
    background: #6c5ce7;
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    font-family: Arial, sans-serif;
}
.ai-modal-vis-alle-btn:hover { background: #5a4dd6; }
.ai-modal-vis-alle-hint {
    font-size: 11px;
    color: #9988cc;
    white-space: nowrap;
}

/* ── AI-søk resultatbanner ───────────────────────────────────────────────── */
#aiResultBanner {
    display: none;
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    background: #f0eeff;
    border: 1px solid #c8b8f8;
    border-radius: 20px;
    padding: 5px 14px 5px 12px;
    font-size: 12px;
    color: #6c5ce7;
    font-weight: 600;
    z-index: 200;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(108,92,231,.18);
    white-space: nowrap;
    pointer-events: all;
}
#aiResultBanner.visible { display: flex; }
#aiResultBanner button {
    background: none;
    border: none;
    color: #9988cc;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    padding: 0;
    line-height: 1;
}
#aiResultBanner button:hover { color: #6c5ce7; }


@media (max-width: 600px) {
    #aiModal { padding-top: 16px; }
    .ai-search-btn .ai-label { display: inline; font-size: 10px; }
}

@media (max-width: 480px) {
    /* FIX 25g: keep body locked — overriding to 'auto' re-enables scrolling and
       causes the mobile toolbar to shift fixed elements again. */

    #slider { margin-top: 4px !important; padding-top: 70px !important; height: auto !important; }

    #slider img {
        display: block;
        margin: 0 auto;
        max-width: 100%;
        max-height: calc(90dvh - 70px);
        height: auto;
        object-fit: contain;
    }

}

.ai-kbd { background: rgba(255,255,255,.06); border-radius: 6px; padding: 2px 7px; font-size: 12px; color: rgba(255,255,255,.4); border: 1px solid rgba(255,255,255,.12); flex-shrink: 0; white-space: nowrap; font-family: Arial, sans-serif; }
