/* ==========================================================================
   Error Container and Messages (v3.0)
   ========================================================================== */

.hvp-error-container {
    margin-bottom: 1rem;
}

.hvp-error-container .hvp-error {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--hvp-radius-lg);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Error types */
.hvp-error.hvp-error-network,
.hvp-error.hvp-error-server_error,
.hvp-error.hvp-error-timeout {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #b91c1c;
}

.hvp-error.hvp-error-rate_limited {
    background-color: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #b45309;
}

.hvp-error.hvp-error-cache_miss {
    background-color: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #1d4ed8;
}

.hvp-error.hvp-error-invalid_product {
    background-color: rgba(107, 114, 128, 0.1);
    border: 1px solid rgba(107, 114, 128, 0.2);
    color: #374151;
}

/* Error message */
.hvp-error-message {
    flex: 1;
}

/* Error spinner (for cache building) */
.hvp-error-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: hvp-spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* Retry button */
.hvp-retry-btn {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--hvp-primary);
    border: none;
    border-radius: var(--hvp-radius);
    cursor: pointer;
    transition: background-color var(--hvp-transition);
    flex-shrink: 0;
}

.hvp-retry-btn:hover {
    background-color: var(--hvp-primary-dark);
}

.hvp-retry-btn:focus {
    outline: none;
    box-shadow: var(--hvp-focus-ring);
}

/* ==========================================================================
   Enhanced Loading States (v3.0)
   ========================================================================== */

/* Individual dropdown loading */
.variations_form.hvp-enabled select.hvp-loading {
    background-image:
        url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24'%3e%3ccircle cx='12' cy='12' r='10' stroke='%23e5e7eb' stroke-width='3'/%3e%3cpath fill='%236366f1' d='M12 2a10 10 0 0 1 10 10h-3a7 7 0 0 0-7-7V2z'/%3e%3c/svg%3e"),
        linear-gradient(to right, var(--hvp-gray-50), var(--hvp-gray-100));
    background-position: right 0.75rem center, center;
    background-repeat: no-repeat, no-repeat;
    background-size: 1.25rem 1.25rem, 100% 100%;
    animation: hvp-loading-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes hvp-loading-pulse {
    0%, 100% {
        opacity: 0.8;
    }
    50% {
        opacity: 1;
    }
}

/* Form loading state - disable all interactions */
.variations_form.hvp-enabled select.hvp-form-loading {
    pointer-events: none;
    opacity: 0.7;
}

/* Loading wrapper with spinner */
.variations_form.hvp-enabled .value.hvp-loading-wrapper {
    position: relative;
}

.variations_form.hvp-enabled .value.hvp-loading-wrapper::after {
    content: '';
    position: absolute;
    right: 40px;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid var(--hvp-gray-200);
    border-top-color: var(--hvp-primary);
    border-radius: 50%;
    animation: hvp-spin 0.7s linear infinite;
    z-index: 5;
}

/* ==========================================================================
   Debounce Visual Feedback (v3.0)
   ========================================================================== */

/* Visual indicator that change is being processed */
.variations_form.hvp-enabled select.hvp-processing {
    border-color: var(--hvp-primary-light);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

/* ==========================================================================
   Cache Building State (v3.0)
   ========================================================================== */

.variations_form.hvp-enabled.hvp-cache-building .variations {
    opacity: 0.6;
    pointer-events: none;
}

.variations_form.hvp-enabled.hvp-cache-building::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.5);
    z-index: 10;
}

/* ==========================================================================
   Variation Container Visibility (v3.0)
   ========================================================================== */

.variations_form.hvp-enabled .woocommerce-variation.hvp-visible,
.variations_form.hvp-enabled .single_variation.hvp-visible {
    animation: hvp-fade-in 0.3s ease-out;
}

@keyframes hvp-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Accessibility Improvements (v3.0)
   ========================================================================== */

/* Focus visible for keyboard navigation */
.variations_form.hvp-enabled select:focus-visible {
    outline: 2px solid var(--hvp-primary);
    outline-offset: 2px;
    box-shadow: none;
}

/* Screen reader only text */
.hvp-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure error messages are announced to screen readers */
.hvp-error-container[role="alert"] {
    /* Force screen reader announcement */
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .variations_form.hvp-enabled.hvp-loading::after,
    .variations_form.hvp-enabled.hvp-loading::before,
    .hvp-error-container,
    .hvp-retry-btn {
        display: none !important;
    }
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
    .variations_form.hvp-enabled select {
        border-width: 3px;
    }

    .variations_form.hvp-enabled select:focus {
        outline: 3px solid currentColor;
        outline-offset: 2px;
    }

    .hvp-error {
        border-width: 2px;
    }

    .hvp-retry-btn {
        border: 2px solid currentColor;
    }
}

/* ==========================================================================
   UI Highlighting States (Feature 6)
   Visual feedback for dropdown selection status
   ========================================================================== */

/* Needs Selection - Attention-grabbing pulse animation */
.variations_form.hvp-enabled select.hvp-needs-selection {
    border-color: var(--hvp-info);
    animation: hvpNeedsSelection 2s ease-in-out infinite;
}

@keyframes hvpNeedsSelection {
    0%, 100% {
        border-color: var(--hvp-info);
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.3);
    }
    50% {
        border-color: #60a5fa;
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    }
}

/* Completed - Subtle success indication */
.variations_form.hvp-enabled select.hvp-completed {
    border-color: var(--hvp-success);
    background-color: rgba(34, 197, 94, 0.03);
}

.variations_form.hvp-enabled select.hvp-completed:focus {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

/* Normal - Default state (no special styling) */
.variations_form.hvp-enabled select.hvp-normal {
    border-color: var(--hvp-gray-300);
    background-color: #fff;
}

/* Accessibility: Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .variations_form.hvp-enabled select.hvp-needs-selection {
        animation: none;
        border-color: var(--hvp-info);
        border-width: 2px;
    }
}

/* ==========================================================================
   Hide "Choose an option" Placeholder
   ========================================================================== */

/**
 * Hide the "Choose an option" placeholder from all variation dropdowns.
 * This creates a cleaner UX where users see actual options immediately.
 *
 * The placeholder is identified by its empty value attribute (value="").
 * This is the standard WooCommerce way of creating placeholder options.
 *
 * Note: The placeholder will reappear when the form is reset via the
 * "Clear" link, as WooCommerce re-adds it during reset.
 */
.variations_form.hvp-enabled select[name^="attribute_"] option[value=""] {
    display: none !important;
}

/**
 * Exception: Show placeholder when dropdown has no value selected
 * This ensures users can still see "Choose an option" on initial load
 * or after clearing, but only for dropdowns without a selection.
 *
 * Note: CSS cannot detect :empty on <select> elements, so this is handled
 * via JavaScript by adding/removing a class when selections change.
 */
.variations_form.hvp-enabled select.hvp-show-placeholder option[value=""] {
    display: block !important;
}

