/**
 * JFC Product Grid Styles
 *
 * Styles for the Gravity Forms Product Grid field.
 * Displays products in a responsive grid layout with quantity selectors,
 * variant dropdowns, and real-time price calculations.
 *
 * @package     JFC_FogTec_Shop
 * @author      JFconcept
 * @since       1.0.0
 */

/* ==========================================================================
   CSS Custom Properties (Variables)
   ========================================================================== */

:root {
    /* Colors */
    --jfc-border-color: #e0e0e0;
    --jfc-border-color-hover: #c0c0c0;
    --jfc-shadow-color: rgba(0, 0, 0, 0.08);
    --jfc-shadow-color-hover: rgba(0, 0, 0, 0.12);
    --jfc-price-color: #2e7d32;
    --jfc-price-bg: #e8f5e9;
    --jfc-total-bg: #f5f5f5;
    --jfc-total-border: #1976d2;
    --jfc-input-border: #ccc;
    --jfc-input-focus: #1976d2;
    --jfc-text-primary: #333;
    --jfc-text-secondary: #666;

    /* Spacing */
    --jfc-grid-gap: 20px;
    --jfc-card-padding: 16px;
    --jfc-card-radius: 8px;

    /* Typography */
    --jfc-font-size-base: 14px;
    --jfc-font-size-small: 12px;
    --jfc-font-size-large: 16px;
    --jfc-font-size-price: 18px;
    --jfc-font-weight-bold: 600;
}

/* ==========================================================================
   Product Grid Container
   ========================================================================== */

/**
 * Main grid container using CSS Grid for responsive layout.
 * Desktop: 3 columns, Tablet: 2 columns, Mobile: 1 column
 *
 * Note: Using !important to override Gravity Forms theme framework's
 * "display: revert" reset rule that affects all elements inside forms.
 */
.jfc-product-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: var(--jfc-grid-gap) !important;
    padding: var(--jfc-card-padding) !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* ==========================================================================
   Product Item Card
   ========================================================================== */

/**
 * Individual product card with border, padding, and shadow.
 * Includes hover state for better interactivity feedback.
 *
 * Note: Using !important to override Gravity Forms theme framework reset.
 */
.jfc-product-item {
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
    border: 1px solid var(--jfc-border-color) !important;
    border-radius: var(--jfc-card-radius) !important;
    padding: var(--jfc-card-padding) !important;
    box-shadow: 0 2px 4px var(--jfc-shadow-color) !important;
    transition: box-shadow 0.2s ease, border-color 0.2s ease !important;
    box-sizing: border-box !important;
}

.jfc-product-item:hover {
    border-color: var(--jfc-border-color-hover);
    box-shadow: 0 4px 8px var(--jfc-shadow-color-hover);
}

/* ==========================================================================
   Product Image
   ========================================================================== */

/**
 * Responsive image container with aspect ratio preservation.
 * Images scale proportionally within the container.
 */
.jfc-product-image {
    position: relative !important;
    width: 100% !important;
    padding-bottom: 75% !important; /* 4:3 aspect ratio */
    margin-bottom: 12px !important;
    overflow: hidden !important;
    border-radius: calc(var(--jfc-card-radius) - 2px) !important;
    background-color: #f9f9f9 !important;
}

.jfc-product-image img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    transition: transform 0.3s ease !important;
}

.jfc-product-item:hover .jfc-product-image img {
    transform: scale(1.02);
}

/* Placeholder for products without images */
.jfc-product-image--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
}

.jfc-product-image--placeholder::after {
    content: '';
    position: absolute;
    width: 48px;
    height: 48px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ccc'%3E%3Cpath d='M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

/* ==========================================================================
   Product Title
   ========================================================================== */

/**
 * Product name styling with text truncation for long names.
 */
.jfc-product-title {
    font-size: var(--jfc-font-size-large);
    font-weight: var(--jfc-font-weight-bold);
    color: var(--jfc-text-primary);
    margin: 0 0 8px 0;
    line-height: 1.3;
    /* Limit to 2 lines with ellipsis */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================================================
   Product Price
   ========================================================================== */

/**
 * Price display with highlighted background for visibility.
 * The price updates dynamically when variants are selected.
 */
.jfc-product-price {
    display: block !important;
    width: fit-content !important;
    font-size: var(--jfc-font-size-price) !important;
    font-weight: var(--jfc-font-weight-bold) !important;
    color: var(--jfc-price-color) !important;
    background-color: var(--jfc-price-bg) !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    margin-bottom: 16px !important;
    white-space: nowrap !important;
}

/* Price currency symbol styling */
.jfc-product-price .jfc-currency {
    font-size: 0.85em;
    margin-left: 2px;
}

/* Strikethrough for original price when variant has different price */
.jfc-product-price--original {
    font-size: var(--jfc-font-size-small);
    color: var(--jfc-text-secondary);
    text-decoration: line-through;
    background: none;
    padding: 0;
    margin-right: 8px;
}

/* ==========================================================================
   Product Variants Dropdown
   ========================================================================== */

/**
 * Variant selection container.
 * Contains price, quantity, and variant selector.
 */
.jfc-product-variants {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
}

.jfc-product-variants label {
    display: block;
    font-size: var(--jfc-font-size-small);
    font-weight: var(--jfc-font-weight-bold);
    color: var(--jfc-text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.jfc-product-variants select {
    width: 100%;
    padding: 10px 12px;
    font-size: var(--jfc-font-size-base);
    border: 1px solid var(--jfc-input-border);
    border-radius: 4px;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 20px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.jfc-product-variants select:hover {
    border-color: var(--jfc-border-color-hover);
}

.jfc-product-variants select:focus {
    outline: none;
    border-color: var(--jfc-input-focus);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}

/* Variant selector dropdown - comes after quantity */
.jfc-variant-selector {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin-top: 16px !important;
}

.jfc-variant-selector label {
    font-size: var(--jfc-font-size-small) !important;
    font-weight: var(--jfc-font-weight-bold) !important;
    color: var(--jfc-text-secondary) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

/* Select element - cross-browser styling */
.jfc-variant-select,
.jfc-product-grid select.jfc-variant-select,
.ginput_container select.jfc-variant-select {
    width: 100% !important;
    height: auto !important;
    min-height: 42px !important;
    padding: 10px 40px 10px 12px !important;
    font-size: var(--jfc-font-size-base) !important;
    line-height: 1.4 !important;
    color: var(--jfc-text-primary) !important;
    border: 1px solid var(--jfc-input-border) !important;
    border-radius: 4px !important;
    background-color: #ffffff !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 12px !important;
    cursor: pointer !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    box-sizing: border-box !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
}

.jfc-variant-select:hover {
    border-color: var(--jfc-border-color-hover) !important;
}

.jfc-variant-select:focus {
    outline: none !important;
    border-color: var(--jfc-input-focus) !important;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15) !important;
}

/* ==========================================================================
   Quantity Input
   ========================================================================== */

/**
 * Quantity input with styled number input appearance.
 * Includes wrapper for potential +/- button additions.
 */
.jfc-product-quantity {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin-bottom: 0 !important;
}

.jfc-product-quantity label {
    font-size: var(--jfc-font-size-small) !important;
    font-weight: var(--jfc-font-weight-bold) !important;
    color: var(--jfc-text-secondary) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    white-space: nowrap !important;
}

.jfc-product-quantity-wrapper {
    display: flex;
    align-items: center;
    border: 1px solid var(--jfc-input-border);
    border-radius: 4px;
    overflow: hidden;
}

.jfc-product-quantity input[type="number"] {
    width: 100% !important;
    padding: 10px 12px !important;
    font-size: var(--jfc-font-size-base) !important;
    text-align: left !important;
    border: 1px solid var(--jfc-input-border) !important;
    border-radius: 4px !important;
    background: #fff !important;
    -moz-appearance: textfield !important; /* Firefox: hide spinners */
    box-sizing: border-box !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
}

/* Hide default number input spinners */
.jfc-product-quantity input[type="number"]::-webkit-outer-spin-button,
.jfc-product-quantity input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.jfc-product-quantity input[type="number"]:hover {
    border-color: var(--jfc-border-color-hover) !important;
}

.jfc-product-quantity input[type="number"]:focus {
    outline: none !important;
    border-color: var(--jfc-input-focus) !important;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15) !important;
}

.jfc-product-quantity-wrapper:focus-within {
    border-color: var(--jfc-input-focus);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}

/* Quantity increment/decrement buttons */
.jfc-qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 36px;
    padding: 0;
    font-size: 18px;
    font-weight: bold;
    color: var(--jfc-text-secondary);
    background: #f5f5f5;
    border: none;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.jfc-qty-btn:hover {
    background-color: #e0e0e0;
    color: var(--jfc-text-primary);
}

.jfc-qty-btn:active {
    background-color: #d0d0d0;
}

.jfc-qty-btn--minus {
    border-right: 1px solid var(--jfc-input-border);
}

.jfc-qty-btn--plus {
    border-left: 1px solid var(--jfc-input-border);
}

/* ==========================================================================
   Line Total (Per Product)
   ========================================================================== */

/**
 * Line total display showing qty * price for each product.
 * Updates dynamically when quantity or variant changes.
 */
.jfc-product-line-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    margin-top: auto; /* Push to bottom of card */
    border-top: 1px dashed var(--jfc-border-color);
    font-size: var(--jfc-font-size-base);
}

.jfc-product-line-total-label {
    color: var(--jfc-text-secondary);
    font-weight: normal;
}

.jfc-product-line-total-value {
    font-size: var(--jfc-font-size-large);
    font-weight: var(--jfc-font-weight-bold);
    color: var(--jfc-price-color);
}

/* Hide line total when quantity is 0 */
.jfc-product-item[data-quantity="0"] .jfc-product-line-total-value {
    color: var(--jfc-text-secondary);
}

/* ==========================================================================
   Cart Total
   ========================================================================== */

/**
 * Sticky/prominent total at the bottom of the grid.
 * Shows the sum of all line totals.
 *
 * Note: Using !important to override Gravity Forms theme framework reset.
 */
.jfc-cart-total {
    grid-column: 1 / -1 !important; /* Span all columns */
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 20px 24px !important;
    margin-top: var(--jfc-grid-gap) !important;
    background-color: var(--jfc-total-bg) !important;
    border: 2px solid var(--jfc-total-border) !important;
    border-radius: var(--jfc-card-radius) !important;
    position: sticky !important;
    bottom: 20px !important;
    z-index: 10 !important;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1) !important;
}

.jfc-cart-total-label {
    font-size: var(--jfc-font-size-large);
    font-weight: var(--jfc-font-weight-bold);
    color: var(--jfc-text-primary);
}

.jfc-cart-total-value {
    font-size: 24px;
    font-weight: var(--jfc-font-weight-bold);
    color: var(--jfc-total-border);
}

/* Items count badge */
.jfc-cart-total-items {
    font-size: var(--jfc-font-size-small);
    color: var(--jfc-text-secondary);
    margin-left: 8px;
    font-weight: normal;
}

/* ==========================================================================
   Hidden Inputs (Form Submission Data)
   ========================================================================== */

/**
 * Hidden inputs that store selected product data for form submission.
 */
.jfc-product-data-input {
    display: none !important;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.jfc-product-grid--loading {
    opacity: 0.6;
    pointer-events: none;
}

.jfc-product-grid--loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--jfc-input-focus);
    border-radius: 50%;
    animation: jfc-spin 1s linear infinite;
}

@keyframes jfc-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Tablet: 2 columns */
@media screen and (max-width: 992px) {
    .jfc-product-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
        padding: 12px !important;
    }

    .jfc-product-item {
        padding: 14px;
    }

    .jfc-cart-total {
        padding: 16px 20px;
    }

    .jfc-cart-total-value {
        font-size: 22px;
    }
}

/* Mobile: 1 column */
@media screen and (max-width: 600px) {
    .jfc-product-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        padding: 8px !important;
    }

    .jfc-product-item {
        padding: 12px;
    }

    .jfc-product-title {
        font-size: var(--jfc-font-size-base);
    }

    .jfc-product-price {
        font-size: var(--jfc-font-size-large);
        padding: 5px 10px;
    }

    .jfc-product-variants select {
        padding: 8px 10px;
    }

    .jfc-product-quantity {
        flex-direction: column !important;
        gap: 4px !important;
    }

    .jfc-product-quantity input[type="number"] {
        width: 100% !important;
    }

    .jfc-variant-selector {
        margin-top: 8px !important;
    }

    .jfc-cart-total {
        flex-direction: column;
        gap: 8px;
        padding: 14px 16px;
        position: sticky;
        bottom: 10px;
    }

    .jfc-cart-total-label {
        font-size: var(--jfc-font-size-base);
    }

    .jfc-cart-total-value {
        font-size: 20px;
    }
}

/* Small mobile adjustments */
@media screen and (max-width: 400px) {
    .jfc-product-grid {
        padding: 4px;
    }

    .jfc-product-item {
        padding: 10px;
    }

    .jfc-product-image {
        padding-bottom: 66.67%; /* 3:2 aspect ratio for smaller screens */
    }

    .jfc-qty-btn {
        width: 40px;
        height: 40px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .jfc-product-grid {
        display: block;
    }

    .jfc-product-item {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
        margin-bottom: 10px;
    }

    .jfc-cart-total {
        position: static;
        box-shadow: none;
    }

    .jfc-qty-btn {
        display: none;
    }
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

/* Focus visible for keyboard navigation */
.jfc-product-item:focus-within {
    outline: 2px solid var(--jfc-input-focus);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .jfc-product-item,
    .jfc-product-image img,
    .jfc-product-variants select,
    .jfc-qty-btn {
        transition: none;
    }

    .jfc-product-grid--loading::after {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .jfc-product-item {
        border-width: 2px;
    }

    .jfc-cart-total {
        border-width: 3px;
    }

    .jfc-product-variants select,
    .jfc-product-quantity-wrapper {
        border-width: 2px;
    }
}
