/* Search popup repairs (merchshark.se, 19 Nov 2026). Loaded only with body.ms-sf-fix
   (inc/search-popup-fixes.php). The older popup rules in shared-shell.css, catalog-ux.css
   and the parent theme use #header and !important, so these selectors are deliberately
   one step more specific. */

/* ---------- Window: as tall as its content, never taller than the screen ---------- */
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] {
    --ms-sf-max: min(700px, calc(var(--ms-search-viewport-height, 100dvh) - 16px));
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: 44px auto !important;
    align-content: start !important;
    height: auto !important;
    max-height: var(--ms-sf-max) !important;
    overflow: hidden !important;
}
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > div.aws-search-result,
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > .ms-sf-start {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    max-height: calc(var(--ms-sf-max) - 68px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
/* Before typing the shortcuts show, not an old or empty result list. */
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel.ms-sf-empty[role="dialog"] > div.aws-search-result,
html body.ms-sf-fix #header .ms-search-panel[role="dialog"] > .ms-sf-start[hidden] {
    display: none !important;
}

/* Words typed, list not here yet (slow network). */
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel.ms-sf-loading[role="dialog"]::after {
    content: "Söker …";
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 18px 2px;
    color: #64748b;
    font: 500 15px/1.3 Inter, sans-serif;
}

/* "10 resultat" counted the rows in the window, not all matching products: screen readers only. */
html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > .ms-search-status {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-height: 0 !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
}

/* ---------- Phones and tablets: room for the "Stäng" word ---------- */
@media (max-width: 1199px) {
    html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > .ms-search-dismiss {
        width: auto !important;
        min-width: 44px !important;
        padding: 0 6px !important;
        white-space: nowrap !important;
    }
}

/* ---------- Phones: one full-screen sheet that follows the keyboard ---------- */
@media (max-width: 767px) {
    html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] {
        top: var(--ms-search-viewport-top, 0px) !important;
        left: 0 !important;
        right: auto !important;
        width: 100vw !important;
        max-width: none !important;
        transform: none !important;
        height: var(--ms-search-viewport-height, 100dvh) !important;
        max-height: var(--ms-search-viewport-height, 100dvh) !important;
        grid-template-rows: 44px minmax(0, 1fr) !important;
        gap: 10px 8px !important;
        padding: 12px 14px 0 !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }
    html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > div.aws-search-result,
    html body.ms-sf-fix #header .ms-search-shell.is-open[data-ms-search-shell] .ms-search-panel[role="dialog"] > .ms-sf-start {
        max-height: none !important;
        height: auto !important;
        align-self: stretch !important;
        margin: 0 -14px !important;
        width: auto !important;
        max-width: none !important;
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }
}

/* ---------- "Visa alla resultat" stays in view at the bottom ---------- */
/* The link itself is a white bar across the list; the dark button shape is drawn by ::before inside it. */
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result div.aws_results a.ms-search-more,
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result div.aws_results a.ms-search-more:hover {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 3 !important;
    isolation: isolate;
    flex: 0 0 calc(100% + 32px) !important;
    width: calc(100% + 32px) !important;
    min-height: 70px !important;
    margin: 6px -16px 0 !important;
    padding: 10px 32px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #fff !important;
    box-shadow: 0 -10px 14px -4px rgba(255, 255, 255, .95) !important;
    color: #fff !important;
}
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result div.aws_results a.ms-search-more::before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 10px;
    right: 16px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    border-radius: 14px;
    background: #214249;
}
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result div.aws_results a.ms-search-more:hover::before {
    background: #182f35;
}
/* No results: the button only led to an empty page. */
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result.ms-sf-noresult a.ms-search-more {
    display: none !important;
}

/* ---------- No results: message, tip and shortcuts ---------- */
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result .aws_no_result {
    padding: 20px 0 4px !important;
    font: 700 16px/1.35 Inter, sans-serif !important;
    text-align: left !important;
    overflow-wrap: anywhere !important;
}
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result .ms-sf-tip {
    flex: 0 0 100% !important;
    margin: 0 0 4px !important;
    color: #475569 !important;
    font: 400 14px/1.45 Inter, sans-serif !important;
}
html body.ms-sf-fix.ms-search-open #header .ms-search-panel[role="dialog"] div.aws-search-result .ms-sf-start {
    flex: 0 0 100% !important;
    padding: 0 0 16px !important;
}

/* ---------- Shortcuts ---------- */
html body.ms-sf-fix #header .ms-search-panel .ms-sf-start {
    padding: 4px 16px 20px;
    background: #fff;
}
html body.ms-sf-fix #header .ms-search-panel .ms-sf-start__h {
    margin: 14px 0 10px !important;
    color: #16262a !important;
    font: 700 15px/1.3 Inter, sans-serif !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}
html body.ms-sf-fix #header .ms-search-panel .ms-sf-start__chips {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
}
html body.ms-sf-fix #header .ms-search-panel a.ms-sf-chip {
    display: inline-flex !important;
    align-items: center !important;
    min-height: 40px !important;
    padding: 0 14px !important;
    border-radius: 999px !important;
    background: #eef4f3 !important;
    color: #214249 !important;
    font: 600 14px/1.2 Inter, sans-serif !important;
    text-decoration: none !important;
    white-space: nowrap !important;
}
html body.ms-sf-fix #header .ms-search-panel a.ms-sf-chip:hover,
html body.ms-sf-fix #header .ms-search-panel a.ms-sf-chip:focus-visible {
    background: #dde9e7 !important;
}

/* ---------- Clear button (x) once something is typed ---------- */
html body.ms-sf-fix #header .ms-search-shell.is-open.has-value[data-ms-search-shell] .aws-search-form .aws-search-clear {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: absolute !important;
    top: 0 !important;
    right: 44px !important;
    left: auto !important;
    transform: none !important;
    z-index: 5 !important;
    width: 40px !important;
    height: 44px !important;
    margin: 0 !important;
    padding: 0 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    color: #64748b !important;
    background: none !important;
}
html body.ms-sf-fix #header .ms-search-shell.is-open.has-value[data-ms-search-shell] .aws-search-form .aws-search-clear span {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    background: #e2e8f0 !important;
    color: #334155 !important;
    font: 600 18px/1 Inter, sans-serif !important;
}
html body.ms-sf-fix #header .ms-search-shell.is-open.has-value[data-ms-search-shell] .aws-search-field {
    padding-right: 88px !important;
}
