/* Enhanced Live Search — Frontend Styles v1.7.0 */

/* Block wrapper — full width in editor and frontend */
.wp-block-enhanced-search-search-block {
    width: 100%;
    box-sizing: border-box;
}

/* In inline or overlay mode the block is icon-only — shrink to fit */
.wp-block-enhanced-search-search-block:has(.es-inline-container),
.wp-block-enhanced-search-search-block:has(.es-overlay-trigger) {
    width: auto;
}

.es-search-wrapper {
    position: relative;
    font-family: inherit;
    font-size: inherit;
    width: 100%;
    box-sizing: border-box;
}

/* Inline and overlay wrappers shrink to icon size */
.es-search-wrapper:has(.es-inline-container),
.es-search-wrapper:has(.es-overlay-trigger) {
    width: auto;
}

/* Input wrapper */
.es-input-container {
    position: relative;
    display: flex;
    align-items: center;
}

.es-search-input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    font-size: inherit;
    border: 1px solid #ddd;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.es-search-input:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
}

.es-search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #888;
    pointer-events: none;
    display: flex;
    align-items: center;
}

.es-search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
}

.es-search-clear:hover { color: #333; }

/* Label */
.es-search-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

/* Button variants */
.es-button-wrapper {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.es-search-button {
    padding: 10px 18px;
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
    transition: background 0.2s;
}

.es-search-button:hover { background: #135e96; }

/* Category pills — full reset so theme button styles don't interfere */
.es-category-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.es-category-pill {
    /* Reset theme button styles */
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
    text-shadow: none;
    text-transform: none;
    letter-spacing: normal;
    font-family: inherit;
    cursor: pointer;
    /* Our styles — read from CSS custom properties set per-instance, falling back to theme colors */
    padding: 6px 16px;
    border: 1px solid var(--es-pill-text, var(--wp--preset--color--contrast, #1d2327));
    border-radius: var(--es-pill-radius, 20px);
    background: var(--es-pill-bg, transparent);
    color: var(--es-pill-text, var(--wp--preset--color--contrast, #1d2327));
    font-size: 14px;
    transition: all 0.15s;
    line-height: 1.4;
    display: inline-block;
}

.es-category-pill:hover,
.es-category-pill.active {
    background: var(--es-pill-active-bg, var(--wp--preset--color--contrast, #1d2327));
    color: var(--es-pill-active-text, var(--wp--preset--color--base, #ffffff));
    border-color: var(--es-pill-active-bg, var(--wp--preset--color--contrast, #1d2327));
    box-shadow: none;
}

/* Dropdown */
.es-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 9999;
    max-height: 480px;
    overflow-y: auto;
}

/* Status messages */
.es-status {
    padding: 12px 16px;
    font-size: 14px;
    color: #666;
}

/* Results header */
.es-results-header {
    padding: 8px 16px;
    font-size: 14px;
    color: #555;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}

/* Result item */
/* Result item is the clickable link */
.es-result-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    padding: 16px !important;
    text-decoration: none !important;
    color: inherit !important;
    gap: 16px !important;
    border-bottom: 1px solid #f0f0f0 !important;
    padding-bottom: 20px !important;
}

.es-result-item:last-child { border-bottom: none !important; }
.es-result-item:hover { background: #f8f9fa; text-decoration: none; }

.es-result-thumbnail {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.es-result-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.es-result-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1d2327;
}

.es-result-title mark {
    background: #fff3cd;
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

.es-result-excerpt {
    font-size: 14px;
    color: #666;
    margin: 0 !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Responsive */
@media (max-width: 480px) {
    .es-result-thumbnail { display: none; }
    .es-result-item { padding: 10px 12px; }
}

/* WC actions inside result content */
.es-wc-actions {
    margin-top: 4px !important;
}

.es-wc-price {
    margin: 0 !important;
}

/* WooCommerce — price */
.es-wc-price {
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.es-wc-price del {
    color: #999;
    font-weight: 400;
    margin-right: 4px;
}

.es-wc-price ins {
    text-decoration: none;
    color: #c0392b;
}

/* WooCommerce — stock badge */
.es-stock-badge {
    display: inline-block;
    font-size: 11px; /* FONT-OK: badge label, not body text */
    padding: 2px 7px;
    border-radius: 3px;
    margin-top: 3px;
}

.es-stock-badge.out-of-stock {
    background: #fce8e6;
    color: #c0392b;
}

/* WooCommerce — action buttons */
.es-add-to-cart-btn,
.es-view-product-btn {
    font-size: 13px;
    padding: 5px 12px;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.es-add-to-cart-btn {
    background: var(--wp--preset--color--contrast, #1d2327);
    color: var(--wp--preset--color--base, #ffffff);
    border: none;
    font-size: 14px;
    padding: 8px 18px;
}

.es-add-to-cart-btn:hover { opacity: 0.85; }

.es-add-to-cart-btn.es-added {
    background: #2d7a2d;
    color: #fff;
}

.es-add-to-cart-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.es-view-product-btn {
    background: transparent;
    color: var(--wp--preset--color--contrast, #1d2327);
    border: 1px solid var(--wp--preset--color--contrast, #1d2327);
}

.es-view-product-btn:hover { opacity: 0.7; }

/* Footer */
.es-results-footer {
    padding: 10px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
    text-align: center;
}

.es-view-all-link {
    font-size: 13px;
    color: #2271b1;
    text-decoration: none;
}

.es-view-all-link:hover { text-decoration: underline; }

/* ---- Overlay mode ---- */
.es-overlay-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: opacity 0.15s;
}
.es-overlay-trigger:hover { opacity: 0.7; }

.es-overlay-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 99999;
    transition: background 0.2s;
}
.es-overlay-backdrop.es-overlay-open {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: rgba(0,0,0,0.55);
    animation: es-backdrop-in 0.2s ease forwards;
}

@keyframes es-backdrop-in {
    from { background: rgba(0,0,0,0); }
    to   { background: rgba(0,0,0,0.55); }
}

.es-overlay-panel {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 640px;
    margin-top: 80px;
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    animation: es-panel-in 0.2s ease forwards;
}

@keyframes es-panel-in {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.es-overlay-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
}
.es-overlay-close:hover { color: #333; background: #f0f0f0; }

.es-overlay-dropdown {
    position: static !important;
    border-radius: 0 0 4px 4px !important;
    border: 1px solid #2271b1 !important;
    border-top: none !important;
    margin-top: 0 !important;
    box-shadow: none !important;
}

/* Overlay input — remove bottom radius when history/dropdown is visible */
.es-overlay-panel .es-search-input {
    border-radius: 4px;
    transition: border-radius 0s;
}
.es-overlay-panel .es-search-input:focus {
    border-color: #2271b1;
    border-radius: 4px 4px 0 0;
    border-bottom-color: transparent;
}

/* ---- Loading skeleton ---- */
.es-skeleton { padding: 8px 0; }

.es-skeleton-item {
    display: flex;
    gap: 14px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}
.es-skeleton-item:last-child { border-bottom: none; }

.es-skeleton-thumb {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: es-shimmer 1.2s infinite;
    flex-shrink: 0;
}

.es-skeleton-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.es-skeleton-line {
    height: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: es-shimmer 1.2s infinite;
}
.es-skeleton-title { width: 55%; height: 14px; }
.es-skeleton-excerpt { width: 85%; }

@keyframes es-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Keyboard focused result */
.es-result-item.es-result-focused {
    background: #f0f4f8 !important;
    outline: 2px solid #2271b1;
    outline-offset: -2px;
}

/* Overlay close button — sits above search field, not overlapping it */
.es-overlay-panel {
    position: relative;
    overflow: hidden;
}
.es-overlay-close {
    display: block !important;
    position: relative !important;
    top: auto !important;
    right: auto !important;
    margin-left: auto;
    margin-bottom: 10px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
}
.es-overlay-close:hover { color: #333; background: #f0f0f0; }

/* Search History */
.es-history-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
    z-index: 9999;
    max-height: 300px;
    overflow-y: auto;
}
.es-history-header {
    padding: 8px 12px 4px;
    font-size: 11px; /* FONT-OK: uppercase eyebrow label */
    color: #888;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid #f0f0f0;
}
.es-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    color: #333;
    font-size: 14px;
    transition: background .15s;
}
.es-history-item:hover { background: #f6f6f6; }
.es-history-term { flex: 1; }
.es-history-remove {
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}
.es-history-remove:hover { color: #666; }

/* Go to cart button */
.es-go-to-cart-btn {
    display: inline-block;
    margin-left: 12px;
    padding: 6px 14px;
    font-size: 13px;
    color: #2271b1;
    background: #fff;
    border: 1px solid #2271b1;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    vertical-align: middle;
}
.es-go-to-cart-btn:hover { background: #f0f6fc; color: #135e96; border-color: #135e96; }

/* ── Inline Expand Mode ── */
.es-inline-container {
    display: inline-flex;
    align-items: center;
    position: relative;
    line-height: 1;
    width: auto;
}
/* Trigger — position relative so container gets width from it */
.es-inline-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: currentColor;
    padding: 6px;
    flex-shrink: 0;
    z-index: 2;
    position: relative;
    vertical-align: middle;
}
.es-inline-trigger:hover { opacity: 0.7; }
.es-inline-trigger-active { opacity: 1; }

/* Wrapper — width animated via JS inline style when open */
.es-inline-wrapper {
    display: inline-flex;
    width: 0;
    height: 36px;
    align-items: center;
    overflow: hidden;
    opacity: 0;
    position: static;
    transition: width 0.3s ease, opacity 0.2s ease;
    vertical-align: middle;
}
.es-inline-wrapper.es-inline-open {
    opacity: 1;
    /* width is set via JS inline style to respect inlineExpandWidth config */
}
/* Expand left: icon on right, field grows left */
.es-inline-left  { flex-direction: row-reverse; }
/* Expand right: icon on left, field grows right */
.es-inline-right { flex-direction: row; }

.es-inline-input {
    width: 100%;
    min-width: 0;
    height: 36px;
    box-sizing: border-box;
}

/* Inline dropdown — positioned via JS ref */
.es-inline-dropdown {
    position: absolute;
    z-index: 99999;
}
.es-inline-dropdown .es-results-dropdown {
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    border-radius: 4px;
}

@media (max-width: 600px) {
    .es-inline-wrapper.es-inline-open {
        width: calc(100vw - 80px) !important;
    }
    .es-inline-dropdown {
        width: calc(100vw - 20px) !important;
        left: 10px !important;
    }
}

/* ── Block Alignment ── */
/* WP adds .alignleft/.aligncenter etc. to the outer block wrapper via get_block_wrapper_attributes() */
.wp-block-enhanced-search-search-block.alignleft,
.es-search-wrapper.alignleft {
    float: left;
    width: fit-content;
    margin-right: 2em;
    margin-bottom: 1em;
}
.wp-block-enhanced-search-search-block.alignright,
.es-search-wrapper.alignright {
    float: right;
    width: fit-content;
    margin-left: 2em;
    margin-bottom: 1em;
}
.wp-block-enhanced-search-search-block.aligncenter,
.es-search-wrapper.aligncenter {
    margin-left: auto;
    margin-right: auto;
    display: block;
}
.wp-block-enhanced-search-search-block.alignwide,
.es-search-wrapper.alignwide {
    max-width: var(--wp--style--global--wide-size, 1200px);
    margin-left: auto;
    margin-right: auto;
}
.wp-block-enhanced-search-search-block.alignfull,
.es-search-wrapper.alignfull {
    max-width: 100%;
    width: 100%;
}

/* History dropdown — static in overlay context so panel expands */
.es-overlay-panel .es-history-dropdown {
    position: static;
    border-radius: 0 0 4px 4px;
    border: 1px solid #2271b1;
    border-top: none;
    box-shadow: none;
    margin-top: 0;
}

/* Clear all history button */
.es-history-clear-all {
    font-size: 13px !important;
    color: #666 !important;
    text-decoration: none;
    cursor: pointer;
}
.es-history-clear-all:hover { color: #333 !important; text-decoration: underline; }
