.opsim-header {
    --header-bg: var(--opsim-bg-primary);
    --header-border: var(--opsim-border);
    --search-border: var(--opsim-brand);
    --accent-color: var(--opsim-brand);
    background: var(--header-bg);
    position: sticky;
    /* Sticks below #wpadminbar when logged in, at 0 otherwise.
     * See --opsim-admin-bar in assets/css/base.css. */
    top: var(--opsim-admin-bar, 0px);
    z-index: 1000;
    width: 100%;
    border-bottom: 1px solid var(--opsim-border);
}
.header-container-full {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}
.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    gap: 12px;
}
button.mobile-menu-toggle {
    display: none;
}
.mobile-menu-toggle .action-icon svg {
    color: var(--opsim-brand);
}
.site-branding {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding-right: 16px;
    position: relative;
}
.site-branding::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 18px;
    background: rgba(var(--opsim-brand-rgb), 0.2);
}
/* The brand wrapper is an <h1> on the home page: it must look like the <div> it is elsewhere. */
.site-branding .site-title {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
    font: inherit;
    line-height: 1;
    color: inherit;
}
.opsim-logo-text { color: inherit; text-decoration: none; }
.opsim-logo-placeholder {
    width: 40px;
    height: 40px;
    background: var(--accent-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.7rem;
}
.opsim-logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}
.logo-top { font-family: var(--opsim-font-primary); font-size: 0.65rem; }
.logo-main { font-weight: 900; font-size: 0.95rem; letter-spacing: -0.5px; }
.logo-bottom { font-family: var(--opsim-font-primary); font-size: 0.6rem; align-self: flex-end; }

.header-desktop-nav {
    flex-shrink: 1;
    min-width: 0;
    overflow: visible;
    margin-left: 6px;
}
.header-desktop-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    white-space: nowrap;
}
.header-desktop-nav li {
    position: relative;
    padding: 8px 0;
}
.header-desktop-nav a {
    text-decoration: none;
    color: #111827;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}
.header-desktop-nav li.menu-item-has-children > a::after {
    content: '';
    width: 11px;
    height: 11px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 9L12 15L5 9' stroke='%23111827' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    display: inline-block;
    transition: transform 0.2s ease;
}
.header-desktop-nav a:hover {
    color: var(--opsim-brand);
}
.header-desktop-nav li.menu-item-has-children:hover > a::after {
    transform: rotate(180deg);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 9L12 15L5 9' stroke='%23531628' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.header-desktop-nav ul ul,
.header-desktop-nav .sub-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 210px;
    background: #ffffff;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
    border: 1px solid #e5e7eb;
    border-radius: var(--opsim-radius, 5px);
    padding: 6px 0;
    z-index: 10000;
    list-style: none;
    margin: 0;
    flex-direction: column;
    gap: 0;
}

.header-desktop-nav ul ul::before,
.header-desktop-nav .sub-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
    background: transparent;
}

.header-desktop-nav li:hover > ul,
.header-desktop-nav li:focus-within > ul,
.header-desktop-nav li.menu-item-has-children:hover > .sub-menu {
    display: flex !important;
}

.header-desktop-nav ul ul li,
.header-desktop-nav .sub-menu li {
    padding: 0;
    margin: 0;
    width: 100%;
}

.header-desktop-nav ul ul a,
.header-desktop-nav .sub-menu a {
    display: block;
    padding: 9px 18px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #374151;
    text-transform: capitalize;
    letter-spacing: 0.2px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.header-desktop-nav ul ul a:hover,
.header-desktop-nav .sub-menu a:hover {
    background-color: rgba(var(--opsim-brand-rgb, 83, 22, 40), 0.07);
    color: var(--opsim-brand, #531628);
    padding-left: 22px;
}

.header-desktop-nav li:hover > a {
    transform: none !important;
    color: var(--opsim-brand);
}

.header-search-container {
    flex-shrink: 1;
    max-width: 340px;
    width: 100%;
    position: relative;
    margin-left: auto;
}
.header-search-form {
    position: relative;
    display: flex;
    align-items: center;
}
.search-field {
    width: 100%;
    padding: 10px 40px 10px 44px;
    border: 1px solid var(--opsim-border);
    border-radius: var(--opsim-radius);
    font-size: 0.85rem;
    height: 40px;
    background: transparent;
}
.search-field:focus {
    outline: none;
    border-color: var(--search-border);
}
/*
 * type="search" gets a browser-drawn clear button (the blue × in WebKit/Blink)
 * and, in WebKit, extra decoration padding. The theme already has its own
 * .search-close, so the native one was a second, differently styled ×.
 */
.search-field {
    -webkit-appearance: none;
    appearance: none;
}
.search-field::-webkit-search-cancel-button,
.search-field::-webkit-search-decoration,
.search-field::-webkit-search-results-button,
.search-field::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}
.search-field::-ms-clear {
    display: none;
}
/* iOS/iPadOS zooms the page into any field under 16px on focus. */
@media (pointer: coarse) {
    .search-field {
        font-size: 16px;
    }
}
.search-submit {
    position: absolute;
    /* 24px hit target (WCAG 2.5.8), centred where the 20px box was centred. */
    left: 10px;
    background: none;
    border: none;
    color: var(--opsim-brand);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 24px;
    height: 24px;
}
.search-submit svg {
    width: 18px;
    height: 18px;
    display: block;
    transition: opacity 0.2s ease;
}
.search-close {
    position: absolute;
    right: 10px;
    background: rgba(0, 0, 0, 0.06);
    border: none;
    color: var(--opsim-brand);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: var(--opsim-radius);
    opacity: 0.6;
    transition: opacity 0.2s ease;
}
.search-close:hover {
    opacity: 1;
}
.search-close svg {
    width: 16px;
    height: 16px;
    display: block;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}
.header-action-item {
    background: none;
    border: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: #374151;
    text-decoration: none;
}
.action-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}
.action-icon svg { 
    width: 30px; 
    height: 30px; 
    color: var(--opsim-brand);
}
.action-label {
    display: none;
}
.cart-count {
    position: absolute;
    top: -2px;
    right: -6px;
    background: var(--opsim-brand);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    /* Cart count dot — intentionally exempt from --opsim-radius. */
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 1.5px solid white;
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--opsim-border);
    border-radius: var(--opsim-radius);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    max-height: 500px;
    overflow-y: auto;
}
.search-results-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 40px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-top: 1px solid var(--opsim-border);
    border-left: 1px solid var(--opsim-border);
    transform: rotate(45deg);
}
.search-results-dropdown.is-active {
    display: block;
}
.search-results-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    z-index: 1;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    text-decoration: none;
    border-radius: var(--opsim-radius);
    transition: all 0.2s ease;
    border: 1px solid transparent;
}
.search-result-item:hover {
    background: #f9fafb;
    border-color: rgba(var(--opsim-brand-rgb), 0.1);
}
.result-image {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    border-radius: var(--opsim-radius);
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid #f0f0f0;
}
.result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.result-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.result-title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}
.result-price {
    display: flex;
    align-items: center;
    gap: 8px;
}
.result-price del {
    font-size: 0.65rem;
    color: #687079;
    text-decoration: line-through;
    font-weight: 300;
    opacity: 0.6;
    margin-right: 4px;
}
.result-price ins, 
.result-price > .amount,
.result-price ins .amount {
    font-size: 0.85rem;
    color: #111827 !important;
    font-weight: 700;
    text-decoration: none !important;
}
.search-results-footer {
    padding: 12px;
    border-top: 1px solid var(--opsim-border);
    text-align: center;
    background: #fcfcfc;
    border-radius: 0 0 var(--opsim-radius) var(--opsim-radius);
}
.view-all-results {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--opsim-brand);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.no-results {
    padding: 30px 20px;
    text-align: center;
    font-size: 0.85rem;
    color: #6b7280;
}
.search-results-dropdown.is-loading .search-results-content {
    opacity: 0.5;
}

@media (max-width: 1023px) {
    .header-desktop-nav,
    .header-search-container {
        display: none;
    }
    button.mobile-menu-toggle {
        display: flex;
    }
    /*
     * The toggle button (1 icon) and the actions block (2 icons) never have
     * equal widths, so centering the logo with justify-content:space-between
     * on 3 flex siblings always drifts it toward whichever side is narrower.
     * A 1fr/auto/1fr grid keeps the two side columns equal by definition, so
     * the logo column is always dead-center regardless of icon count.
     */
    .header-main-row {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        padding: 4px 0;
        /* No border-bottom here. .header-main-row is the only child of
         * .header-container-full, which is the only child of .opsim-header, so
         * a border here lands on the exact same line as .opsim-header's own
         * border-bottom and renders as a doubled 2px rule. The header keeps
         * the single border for every breakpoint. */
        box-shadow: var(--opsim-shadow-sm);
    }
    .header-main-row > .mobile-menu-toggle {
        justify-self: start;
    }
    .header-main-row > .site-branding {
        justify-self: center;
        padding-right: 0;
    }
    .header-main-row > .site-branding::after {
        display: none;
    }
    .header-main-row > .header-actions {
        justify-self: end;
    }
    .action-label { display: none; }
    .action-icon svg { 
        width: 32px;
        height: 32px; 
    }
    .search-results-dropdown {
        position: fixed;
        top: calc(60px + var(--opsim-admin-bar, 0px));
        left: 10px;
        right: 10px;
        width: auto;
        border-radius: var(--opsim-radius);
        border: 1px solid var(--opsim-border);
    }
}
@media (max-width: 767px) {
    .header-container-full { padding: 0 10px; }
    .header-main-row { 
        gap: 6px;
        padding: 2px 0;
    }
    .site-branding { gap: 4px; padding-right: 0; }
    .site-branding::after { display: none; }
    .opsim-logo-placeholder { 
        width: 28px;
        height: 28px; 
        font-size: 0.55rem;
    }
    .logo-main { font-size: 0.8rem; }
    .header-actions { gap: 10px; }
    .action-icon svg { 
        width: 30px;
        height: 30px; 
    }
    .cart-count { min-width: 14px; height: 14px; font-size: 8px; right: -4px; top: -1px; }
}
