/**
 * SS WooCommerce Gift Cards - Storefront Styles
 *
 * Design selector styling for gift card product pages.
 * Provides a responsive grid layout with accessibility support.
 */

/**
 * CSS Custom Properties (Design Tokens)
 *
 * Override these in your theme to customize the design selector appearance.
 * Example: :root { --sswcgc-primary: #your-color; }
 */
:root {
    /* Primary color for selected state */
    --sswcgc-primary: #0073aa;
    --sswcgc-primary-rgb: 0, 115, 170;
    --sswcgc-selected-bg: #1a4d2e;
    --sswcgc-selected-text: #ffffff;

    /* Border and background colors */
    --sswcgc-border: #ddd;
    --sswcgc-border-hover: #999;
    --sswcgc-background: #fff;
    --sswcgc-text: #333;
    --sswcgc-section-bg: #f9f9f9;

    /* Spacing and sizing */
    --sswcgc-card-min-width: 150px;
    --sswcgc-card-gap: 1rem;
    --sswcgc-card-border-radius: 8px;
    --sswcgc-card-image-height: 120px;
}

/**
 * Form Section Container
 *
 * Each section is a fieldset for semantic grouping and accessibility.
 * Styled with padding and margin for clear separation.
 */
.sswcgc-form-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--sswcgc-section-bg);
    border-radius: var(--sswcgc-card-border-radius);
    border: none; /* Remove default fieldset border */
    min-width: 0; /* Fix fieldset width bug in some browsers */
}

/**
 * Section Title (Legend)
 *
 * Styled to match the build-your-own-box page with uppercase, bold text.
 * Using legend element for semantic HTML and screen reader support.
 */
.sswcgc-section-title {
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 1rem 0;
    padding: 0;
    color: var(--sswcgc-text);
}

/**
 * Form Fields
 *
 * Clean, consistent styling for all form inputs.
 */
.sswcgc-gift-card-form input[type="text"],
.sswcgc-gift-card-form input[type="email"],
.sswcgc-gift-card-form input[type="number"],
.sswcgc-gift-card-form input[type="date"],
.sswcgc-gift-card-form textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--sswcgc-border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.sswcgc-gift-card-form input[type="text"]:focus,
.sswcgc-gift-card-form input[type="email"]:focus,
.sswcgc-gift-card-form input[type="number"]:focus,
.sswcgc-gift-card-form input[type="date"]:focus,
.sswcgc-gift-card-form textarea:focus {
    outline: none;
    border-color: var(--sswcgc-primary);
    box-shadow: 0 0 0 1px var(--sswcgc-primary);
}

.sswcgc-gift-card-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sswcgc-text);
}

.sswcgc-gift-card-form .form-row {
    margin-bottom: 1rem;
}

.sswcgc-gift-card-form .form-row-first,
.sswcgc-gift-card-form .form-row-last {
    width: 48%;
    float: left;
}

.sswcgc-gift-card-form .form-row-first {
    margin-right: 4%;
}

.sswcgc-gift-card-form .form-row-wide {
    width: 100%;
    clear: both;
}

/**
 * Amount Selection
 *
 * Radio button styling for denomination selection.
 * Styled as button-like boxes to match site design.
 */
.sswcgc-denominations {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.sswcgc-denomination {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0.625rem 1.25rem;
    border: 2px solid var(--sswcgc-border);
    border-radius: 4px;
    background: var(--sswcgc-background);
    transition: all 0.2s ease;
    min-width: 90px;
}

.sswcgc-denomination:hover {
    border-color: var(--sswcgc-border-hover);
}

.sswcgc-denomination input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.sswcgc-denomination input[type="radio"]:checked + span {
    color: var(--sswcgc-selected-text) !important;
}

/* Target WooCommerce price formatting spans specifically (instead of universal selector) */
.sswcgc-denomination input[type="radio"]:checked + span .woocommerce-Price-amount,
.sswcgc-denomination input[type="radio"]:checked + span .woocommerce-Price-currencySymbol {
    color: inherit !important;
}

/* Modern browsers with :has() support */
.sswcgc-denomination:has(input[type="radio"]:checked) {
    background: var(--sswcgc-selected-bg);
    border-color: var(--sswcgc-selected-bg);
}

/* Fallback for browsers without :has() support (Firefox <121) */
.sswcgc-denomination.selected {
    background: var(--sswcgc-selected-bg);
    border-color: var(--sswcgc-selected-bg);
}

.sswcgc-denomination input[type="radio"]:focus + span {
    outline: 2px solid var(--sswcgc-primary);
    outline-offset: 2px;
}

.sswcgc-denomination span {
    font-size: 1rem;
    color: var(--sswcgc-text);
    font-weight: 500;
    transition: color 0.2s, font-weight 0.2s;
}

/**
 * Custom Amount Input
 *
 * Styling for the custom amount option.
 */
.sswcgc-custom-amount {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    margin-top: 0;
}

.sswcgc-custom-amount label {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    cursor: pointer;
    padding: 0.625rem 1.25rem;
    border: 2px solid var(--sswcgc-border);
    border-radius: 4px;
    background: var(--sswcgc-background);
    transition: all 0.2s ease;
    white-space: nowrap;
    flex: 0 0 auto;
    font-weight: 500;
    color: var(--sswcgc-text);
}

.sswcgc-custom-amount label:hover {
    border-color: var(--sswcgc-border-hover);
}

.sswcgc-custom-amount input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* Modern browsers with :has() support */
.sswcgc-custom-amount label:has(input[type="radio"]:checked) {
    background: var(--sswcgc-selected-bg);
    border-color: var(--sswcgc-selected-bg);
    color: var(--sswcgc-selected-text) !important;
    font-weight: 500;
}

/* Fallback for browsers without :has() support (Firefox <121) */
.sswcgc-custom-amount label.selected {
    background: var(--sswcgc-selected-bg);
    border-color: var(--sswcgc-selected-bg);
    color: var(--sswcgc-selected-text) !important;
    font-weight: 500;
}

.sswcgc-custom-input-wrapper {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    max-width: 300px;
}

.sswcgc-custom-amount input[type="number"] {
    width: 100%;
    min-width: 150px;
    padding: 0.625rem 0.75rem;
    border: 2px solid var(--sswcgc-border);
    border-radius: 4px;
    font-size: 1rem;
}

.sswcgc-custom-amount input[type="number"]:focus-visible {
    outline: 2px solid var(--sswcgc-primary);
    outline-offset: 2px;
    border-color: var(--sswcgc-primary);
}

.sswcgc-custom-amount-hint {
    font-size: 0.75rem;
    color: #666;
    line-height: 1.3;
    margin: 0;
    padding: 0;
}

/* Hide custom amount input by default (prevent FOUC) */
.sswcgc-custom-input-hidden {
    display: none;
}

/**
 * Checkbox Styling
 *
 * Clean checkbox styling for send copy option.
 */
.sswcgc-send-copy label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.sswcgc-send-copy input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
}

/**
 * Design Grid Layout
 *
 * - auto-fill creates responsive columns without media queries
 * - minmax(150px, 1fr) ensures minimum card width while filling space
 * - 150px chosen to accommodate typical thumbnail sizes
 * - gap provides consistent spacing between cards
 */
.sswcgc-design-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--sswcgc-card-min-width), 1fr));
    gap: var(--sswcgc-card-gap);
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

/**
 * Design Card Container
 *
 * Each card is a clickable label containing a radio input, image, and text.
 * Uses flexbox for vertical layout with image above label.
 */
.sswcgc-design-card {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 2px solid var(--sswcgc-border);
    border-radius: var(--sswcgc-card-border-radius);
    padding: 0.5rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--sswcgc-background);
}

/**
 * Card Hover State
 *
 * Provides visual feedback when user hovers over a design option.
 */
.sswcgc-design-card:hover {
    border-color: var(--sswcgc-border-hover);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/**
 * Hidden Radio Input
 *
 * Radio inputs are visually hidden but remain accessible to screen readers
 * and keyboard navigation. Position absolute with zero dimensions ensures
 * the label remains clickable.
 */
.sswcgc-design-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/**
 * Selected State - Image
 *
 * When a design is selected, the image receives a prominent border and glow
 * effect using the primary color. The box-shadow creates a "focus ring" effect.
 */
.sswcgc-design-card input[type="radio"]:checked ~ img {
    border-color: var(--sswcgc-primary);
    box-shadow: 0 0 0 3px rgba(var(--sswcgc-primary-rgb), 0.3);
}

/**
 * Selected State - Label
 *
 * The design label becomes bold and colored when selected.
 */
.sswcgc-design-card input[type="radio"]:checked ~ .sswcgc-design-label {
    font-weight: 600;
    color: var(--sswcgc-primary);
}

/**
 * Keyboard Focus State
 *
 * Provides clear visual feedback when navigating with keyboard (Tab key).
 * Outline offset creates spacing between border and outline.
 */
.sswcgc-design-card input[type="radio"]:focus ~ img {
    outline: 2px solid var(--sswcgc-primary);
    outline-offset: 2px;
}

/**
 * Design Image
 *
 * Fixed aspect ratio (120px height) with object-fit: cover ensures images
 * maintain their aspect ratio while filling the space. Transparent border
 * prevents layout shift when selected border is applied.
 */
.sswcgc-design-card img {
    width: 100%;
    height: var(--sswcgc-card-image-height);
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/**
 * Design Label
 *
 * Centered text below the image displaying the design name.
 * Transitions ensure smooth color/weight changes on selection.
 */
.sswcgc-design-label {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sswcgc-text);
    transition: color 0.2s, font-weight 0.2s;
}

/**
 * Clearfix for Form Rows
 *
 * Ensures floated form elements don't overflow their container.
 */
.sswcgc-gift-card-form .form-row::after {
    content: "";
    display: table;
    clear: both;
}

/**
 * Mobile Responsive Adjustments
 *
 * On smaller screens (≤768px):
 * - Stack form fields vertically
 * - Force 2-column grid for better touch targets
 * - Reduce image height to fit smaller viewports
 * - Slightly smaller font size for labels
 */
@media (max-width: 768px) {
    .sswcgc-gift-card-form .form-row-first,
    .sswcgc-gift-card-form .form-row-last {
        width: 100%;
        float: none;
        margin-right: 0;
    }

    .sswcgc-custom-amount {
        flex-direction: column;
        align-items: flex-start;
    }

    .sswcgc-custom-input-wrapper {
        max-width: 100%;
    }
}

@media (max-width: 640px) {
    .sswcgc-design-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .sswcgc-design-card img {
        height: 100px;
    }

    .sswcgc-design-label {
        font-size: 0.75rem;
    }

    .sswcgc-form-section {
        padding: 1rem;
    }

    .sswcgc-denominations {
        gap: 0.5rem;
    }

    .sswcgc-denomination {
        flex: 1 1 auto;
        min-width: calc(50% - 0.25rem);
    }

    .sswcgc-custom-amount label {
        width: 100%;
    }
}

/**
 * Accessibility: High Contrast Mode
 *
 * Increases border widths when Windows High Contrast mode is active
 * to improve visibility for users with low vision.
 */
@media (prefers-contrast: high) {
    .sswcgc-design-card {
        border-width: 3px;
    }

    .sswcgc-design-card input[type="radio"]:checked ~ img {
        border-width: 3px;
    }
}
