/* AGAFORT Header Search V1 — pill bar, camera, compact submit, suggestions, visual modal */
/* Search Bar Visual Refinement V1: input | camera | submit; beat phase4a/marketplace orange slabs */

.ag-dh-search.ag-hs-v1,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] {
    position: relative;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    height: var(--ag-hs-bar-height, 44px) !important;
    min-height: var(--ag-hs-bar-height, 44px) !important;
    max-height: var(--ag-hs-bar-height, 44px) !important;
    padding-inline: var(--ag-hs-bar-pad-x, 14px) 4px !important;
    padding-block: 0 !important;
    background: var(--ag-hs-bar-bg, #fff) !important;
    border: 1px solid var(--ag-hs-bar-border, #e5e7eb) !important;
    border-width: 1px !important;
    border-radius: var(--ag-hs-bar-radius, 999px) !important;
    box-shadow: var(--ag-hs-bar-shadow, none) !important;
    gap: 2px !important;
    max-width: var(--ag-dh-search-max, 720px);
    overflow: hidden;
    box-sizing: border-box !important;
}

.ag-dh-search.ag-hs-v1:focus-within,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1]:focus-within {
    border-color: var(--ag-hs-bar-border-focus, color-mix(in srgb, var(--ag-p4a-orange, #f68b1e) 55%, #e5e7eb)) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ag-p4a-orange, #f68b1e) 18%, transparent) !important;
}

.ag-dh-search.ag-hs-v1 > i.bi-search {
    display: none;
}

/* Integrated camera — never inherit phase4a orange slab / min-width */
.ag-dh-search.ag-hs-v1 > .ag-hs-camera,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-hs-camera {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: var(--ag-hs-camera-hit, 32px) !important;
    min-width: var(--ag-hs-camera-hit, 32px) !important;
    max-width: var(--ag-hs-camera-hit, 32px) !important;
    height: var(--ag-hs-camera-hit, 32px) !important;
    min-height: var(--ag-hs-camera-hit, 32px) !important;
    max-height: var(--ag-hs-camera-hit, 32px) !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: transparent !important;
    color: var(--ag-hs-camera-color, #6b7280) !important;
    font-weight: 400 !important;
    cursor: pointer;
    box-shadow: none !important;
    align-self: center !important;
}

.ag-dh-search.ag-hs-v1 > .ag-hs-camera i,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-hs-camera i {
    font-size: var(--ag-hs-camera-size, 18px) !important;
    line-height: 1 !important;
    color: inherit !important;
}

.ag-dh-search.ag-hs-v1 > .ag-hs-camera:hover,
.ag-dh-search.ag-hs-v1 > .ag-hs-camera:focus-visible,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-hs-camera:hover,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-hs-camera:focus-visible {
    color: var(--ag-hs-camera-hover, #0f172a) !important;
    background: color-mix(in srgb, var(--ag-p4a-orange, #f68b1e) 10%, transparent) !important;
    outline: none;
}

.ag-dh-search.ag-hs-v1 input[type="search"],
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] input[type="search"] {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding-inline: 2px 4px !important;
    padding-block: 0 !important;
    border: 0 !important;
    background: transparent !important;
    color: var(--ag-hs-bar-text, #0f172a) !important;
    font-size: 0.9375rem;
    font-weight: 400;
    outline: none !important;
    box-shadow: none !important;
}

.ag-dh-search.ag-hs-v1 input[type="search"]::placeholder {
    color: var(--ag-hs-bar-placeholder, #9ca3af);
}

/* Compact AGAFORT-orange pill submit — not a wide marketplace slab */
.ag-dh-search.ag-hs-v1 > .ag-dh-search-submit,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-dh-search-submit,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > [type="submit"].ag-dh-search-submit {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: var(--ag-hs-btn-width, 40px) !important;
    min-width: var(--ag-hs-btn-width, 40px) !important;
    max-width: var(--ag-hs-btn-width, 40px) !important;
    height: calc(var(--ag-hs-bar-height, 44px) - 8px) !important;
    min-height: 0 !important;
    max-height: calc(var(--ag-hs-bar-height, 44px) - 8px) !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: var(--ag-hs-btn-radius, 999px) !important;
    background: var(--ag-hs-btn-bg, var(--ag-p4a-orange, #f68b1e)) !important;
    color: var(--ag-hs-btn-text, #fff) !important;
    font-weight: 600 !important;
    cursor: pointer;
    box-shadow: none !important;
    align-self: center !important;
}

.ag-dh-search.ag-hs-v1 > .ag-dh-search-submit:hover,
.ag-dh-search.ag-hs-v1 > .ag-dh-search-submit:focus-visible,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-dh-search-submit:hover,
form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] > .ag-dh-search-submit:focus-visible {
    background: var(--ag-hs-btn-hover-bg, color-mix(in srgb, var(--ag-p4a-orange, #f68b1e) 82%, #0f172a)) !important;
    color: var(--ag-hs-btn-hover-text, #fff) !important;
    outline: none;
}

.ag-dh-search.ag-hs-v1 > .ag-dh-search-submit i {
    font-size: 1rem;
    line-height: 1;
}

/* RTL: rely on document direction + DOM order (input | camera | submit) — no transform fakes */
[dir="rtl"] .ag-dh-search.ag-hs-v1,
html[dir="rtl"] .ag-dh-search.ag-hs-v1 {
    flex-direction: row !important;
}

.ag-dh-search.ag-hs-v1 .ag-hs-panel,
.ag-dh-search.ag-hs-v1 .ag-dh-search-panel {
    position: absolute;
    inset-inline: 0;
    top: calc(100% + 8px);
    z-index: 80;
    max-height: var(--ag-hs-dd-max-h, 420px);
    overflow: auto;
    background: var(--ag-hs-dd-bg, #fff);
    border: 1px solid var(--ag-hs-dd-border, #e5e7eb);
    border-radius: var(--ag-hs-dd-radius, 12px);
    box-shadow: var(--ag-hs-dd-shadow, 0 12px 32px rgba(17, 24, 39, 0.12));
    padding: 10px 0;
}

.ag-hs-panel .ag-dh-search-panel-section strong {
    display: block;
    padding: 6px 14px 4px;
    font-size: 12px;
    color: var(--ag-hs-sug-muted, #6b7280);
    text-transform: none;
}

.ag-hs-panel a,
.ag-hs-panel button.ag-dh-search-recent,
.ag-hs-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    border: 0;
    background: transparent;
    color: var(--ag-hs-sug-text, #111827);
    text-align: start;
    text-decoration: none;
    cursor: pointer;
}

.ag-hs-panel a:hover,
.ag-hs-panel a.is-active,
.ag-hs-panel button.ag-dh-search-recent:hover,
.ag-hs-panel button.ag-dh-search-recent.is-active,
.ag-hs-product-card:hover,
.ag-hs-product-card.is-active {
    background: var(--ag-hs-sug-hover, #f3f4f6);
}

.ag-hs-product-card img {
    width: var(--ag-hs-thumb-size, 40px);
    height: var(--ag-hs-thumb-size, 40px);
    object-fit: cover;
    border-radius: var(--ag-hs-thumb-radius, 8px);
    flex: 0 0 auto;
}

.ag-hs-product-card span {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ag-hs-view-all {
    display: block;
    margin: 6px 14px 4px;
    padding: 8px 0;
    font-weight: 600;
    color: var(--ag-hs-sug-text, #111827);
    text-decoration: none;
    border-top: 1px solid var(--ag-hs-dd-border, #e5e7eb);
}

/* Visual search modal — viewport-bounded shell; sticky head; body scrolls */
.ag-hs-visual-modal {
    position: fixed;
    inset: 0;
    z-index: var(--ag-z-modal, 1055);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px))
        max(12px, env(safe-area-inset-right, 0px))
        max(12px, env(safe-area-inset-bottom, 0px))
        max(12px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
}

.ag-hs-visual-modal[hidden] {
    display: none !important;
}

.ag-hs-visual-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
}

.ag-hs-visual-dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(520px, 100%);
    max-height: min(92dvh, 720px);
    max-height: min(92vh, 720px);
    overflow: hidden;
    background: #fff;
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.ag-hs-visual-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.ag-hs-visual-head strong {
    font-size: 1.05rem;
    line-height: 1.3;
}

.ag-hs-visual-close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #111827;
    cursor: pointer;
    line-height: 1;
}

.ag-hs-visual-close:hover,
.ag-hs-visual-close:focus-visible {
    background: #f3f4f6;
    outline: 2px solid #111827;
    outline-offset: 1px;
}

.ag-hs-visual-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 12px 18px 20px;
}

.ag-hs-visual-hint {
    margin: 0 0 14px;
    color: #6b7280;
    font-size: 14px;
}

.ag-hs-visual-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 120px;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    color: #6b7280;
    cursor: pointer;
    padding: 20px;
}

.ag-hs-visual-dropzone.is-dragover {
    border-color: #111827;
    background: #f9fafb;
}

.ag-hs-visual-actions {
    margin-top: 12px;
}

.ag-hs-visual-capture-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    font-size: 14px;
}

.ag-hs-visual-status {
    margin-top: 12px;
    font-size: 14px;
    color: #6b7280;
}

.ag-hs-visual-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.ag-hs-visual-results a {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-decoration: none;
    color: #111827;
    font-size: 13px;
    min-width: 0;
}

.ag-hs-visual-results img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 10px;
    background: #f3f4f6;
}

.ag-hs-visual-preview {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.ag-hs-visual-preview[hidden] {
    display: none !important;
}

.ag-hs-visual-preview img {
    max-width: 100%;
    max-height: min(180px, 28vh);
    border-radius: 10px;
    object-fit: contain;
    background: #f3f4f6;
}

.ag-hs-visual-camera {
    margin-top: 12px;
}

.ag-hs-visual-camera[hidden] {
    display: none !important;
}

.ag-hs-visual-camera video {
    width: 100%;
    max-height: min(240px, 36vh);
    border-radius: 10px;
    background: #111;
    object-fit: cover;
}

.ag-hs-visual-camera-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.ag-hs-visual-capture-mobile {
    display: none;
}

@media (max-width: 767.98px) {
    .ag-hs-visual-modal {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }

    .ag-hs-visual-dialog {
        width: 100%;
        height: 100%;
        max-height: 100dvh;
        max-height: 100vh;
        border-radius: 0;
    }

    .ag-hs-visual-capture-btn[data-visual-camera-start] {
        display: none;
    }

    .ag-hs-visual-capture-mobile {
        display: inline-flex;
    }

    .ag-hs-visual-preview img {
        max-height: min(160px, 26vh);
    }
}

body.ag-hs-visual-search-open,
html.ag-hs-visual-search-open {
    overflow: hidden;
}

@media (max-width: 991.98px) {
    form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] {
        --ag-hs-btn-width: 36px;
        --ag-hs-camera-hit: 30px;
        --ag-hs-camera-size: 17px;
        --ag-hs-bar-pad-x: 10px;
    }
}

@media (max-width: 767.98px) {
    form.ag-dh-search.ag-hs-v1[data-ag-header-search-v1] {
        --ag-hs-bar-height: 40px;
        --ag-hs-btn-width: 34px;
        --ag-hs-camera-hit: 28px;
        max-width: 100%;
        flex: 1 1 100%;
    }

    body.ag-hs-mobile-search-open .ag-dh-search.ag-hs-v1 .ag-hs-panel {
        position: fixed;
        inset: 0;
        top: 0;
        max-height: none;
        border-radius: 0;
        z-index: 1100;
        padding-top: 56px;
    }
}
