/* ==========================================================================
   WPCM Search 4.0 — Front-end Styles
   ========================================================================== */

.wpcm-search4 {
    position: relative;
    max-width: 100%;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    box-sizing: border-box;
}

.wpcm-search4 *,
.wpcm-search4 *::before,
.wpcm-search4 *::after {
    box-sizing: inherit;
}

/* Form */
.wpcm-search4__form {
    position: relative;
}

/* Bar */
.wpcm-search4__bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 999px;
    padding: 6px 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wpcm-search4__bar:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15), 0 4px 16px rgba(0, 0, 0, 0.06);
}

/* Input */
.wpcm-search4__input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    font-size: 16px;
    line-height: 1.5;
    padding: 8px 12px;
    color: #1e293b;
}

.wpcm-search4__input::placeholder {
    color: #94a3b8;
}

/* Voice button */
.wpcm-search4__voice {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: #f1f5f9;
    color: #64748b;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.wpcm-search4__voice:hover {
    background: #e2e8f0;
    color: #334155;
}

.wpcm-search4__voice:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.wpcm-search4__voice[aria-pressed="true"] {
    background: #fecaca;
    color: #dc2626;
    animation: wpcm-pulse 1.2s infinite;
}

@keyframes wpcm-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Submit */
.wpcm-search4__submit {
    border: 0;
    border-radius: 999px;
    padding: 10px 20px;
    background: #3b82f6;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
    line-height: 1.4;
}

.wpcm-search4__submit:hover {
    background: #2563eb;
}

.wpcm-search4__submit:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Suggestions dropdown */
.wpcm-search4__suggestions {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    z-index: 9999;
    max-height: 480px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.wpcm-search4__suggestions[hidden] {
    display: none;
}

/* Individual item */
.wpcm-search4__item {
    display: block;
    padding: 14px 20px;
    text-decoration: none;
    color: inherit;
    border-top: 1px solid #f1f5f9;
    transition: background 0.1s ease;
    outline: none;
}

.wpcm-search4__item:first-child {
    border-top: 0;
}

.wpcm-search4__item:hover,
.wpcm-search4__item:focus,
.wpcm-search4__item[aria-selected="true"] {
    background: #f8fafc;
}

.wpcm-search4__item:focus-visible {
    box-shadow: inset 3px 0 0 #3b82f6;
}

.wpcm-search4__item-title {
    display: block;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.4;
    color: #1e293b;
}

.wpcm-search4__item-excerpt {
    display: block;
    font-size: 13px;
    line-height: 1.5;
    color: #64748b;
    margin-top: 3px;
}

.wpcm-search4__item-meta {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-top: 4px;
}

/* Highlight */
.wpcm-search4__highlight {
    background: #fef08a;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* States */
.wpcm-search4__empty,
.wpcm-search4__loading,
.wpcm-search4__error {
    padding: 18px 20px;
    font-size: 14px;
    color: #64748b;
    text-align: center;
}

.wpcm-search4__loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: wpcm-spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes wpcm-spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 640px) {
    .wpcm-search4__bar {
        gap: 6px;
        padding: 4px 6px;
    }

    .wpcm-search4__input {
        font-size: 15px;
        padding: 6px 8px;
    }

    .wpcm-search4__submit {
        padding: 8px 14px;
        font-size: 14px;
    }

    .wpcm-search4__voice {
        width: 36px;
        height: 36px;
    }

    .wpcm-search4__suggestions {
        border-radius: 12px;
        max-height: 60vh;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .wpcm-search4__voice[aria-pressed="true"],
    .wpcm-search4__loading::after {
        animation: none;
    }

    .wpcm-search4__bar,
    .wpcm-search4__voice,
    .wpcm-search4__submit,
    .wpcm-search4__item {
        transition: none;
    }
}

/* Screen reader only */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    word-wrap: normal !important;
}
