/**
 * FNC Fabric Selector - Artisan Heritage Aesthetic
 *
 * A refined fabric swatch selector that evokes the tactile experience
 * of browsing samples in a premium furniture showroom.
 *
 * @package Viztech_Price_Importer
 */

/* ============================================
   CSS Custom Properties - Design Tokens
   ============================================ */

.fnc-fabric-selector {
    /* Warm earth palette */
    --fnc-cream: #FAF8F4;
    --fnc-linen: #F4F1EA;
    --fnc-parchment: #EDE8DD;
    --fnc-taupe: #D4CFC4;
    --fnc-stone: #9E9789;
    --fnc-charcoal: #3C3630;
    --fnc-ink: #2A2520;

    /* Accent - burnished copper */
    --fnc-copper: #A65D3F;
    --fnc-copper-light: rgba(166, 93, 63, 0.12);
    --fnc-copper-glow: rgba(166, 93, 63, 0.25);

    /* Secondary accent - sage for pricing */
    --fnc-sage: #5D7359;
    --fnc-sage-light: rgba(93, 115, 89, 0.1);

    /* Shadows */
    --fnc-shadow-sm: 0 1px 2px rgba(42, 37, 32, 0.06);
    --fnc-shadow-md: 0 4px 12px rgba(42, 37, 32, 0.08);
    --fnc-shadow-lg: 0 8px 24px rgba(42, 37, 32, 0.12);
    --fnc-shadow-inset: inset 0 1px 3px rgba(42, 37, 32, 0.05);

    /* Swatch shadow - realistic fabric sample look */
    --fnc-swatch-shadow:
        0 1px 2px rgba(42, 37, 32, 0.1),
        0 4px 8px rgba(42, 37, 32, 0.08);
    --fnc-swatch-shadow-hover:
        0 2px 4px rgba(42, 37, 32, 0.12),
        0 8px 20px rgba(42, 37, 32, 0.15);

    /* Typography */
    --fnc-font-display: 'Cormorant Garamond', Georgia, serif;
    --fnc-font-body: 'DM Sans', -apple-system, sans-serif;

    /* Spacing */
    --fnc-space-xs: 4px;
    --fnc-space-sm: 8px;
    --fnc-space-md: 16px;
    --fnc-space-lg: 24px;
    --fnc-space-xl: 32px;

    /* Transitions */
    --fnc-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --fnc-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Borders */
    --fnc-radius-sm: 4px;
    --fnc-radius-md: 8px;
    --fnc-radius-lg: 12px;
}


/* ============================================
   Container
   ============================================ */

.fnc-fabric-selector {
    font-family: var(--fnc-font-body);
    color: var(--fnc-charcoal);
    background: var(--fnc-cream);
    border: 1px solid var(--fnc-taupe);
    border-radius: var(--fnc-radius-lg);
    overflow: hidden;
    box-shadow: var(--fnc-shadow-md);

    /* Subtle linen texture overlay */
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-blend-mode: overlay;
    background-size: 200px 200px;
}


/* ============================================
   Fabric Toggle (No Fabric / Add Fabric)
   ============================================ */

.fnc-fabric-toggle {
    padding: var(--fnc-space-md);
    background: var(--fnc-linen);
    border-bottom: 1px solid var(--fnc-taupe);
}

.fnc-toggle-option {
    display: block;
    cursor: pointer;
    margin-bottom: var(--fnc-space-sm);
    transition: all 0.2s var(--fnc-ease-out);
}

.fnc-toggle-option:last-child {
    margin-bottom: 0;
}

.fnc-toggle-content {
    display: flex;
    align-items: center;
    gap: var(--fnc-space-md);
    padding: var(--fnc-space-md);
    background: var(--fnc-cream);
    border: 2px solid transparent;
    border-radius: var(--fnc-radius-md);
    transition: all 0.25s var(--fnc-ease-out);
    box-shadow: var(--fnc-shadow-sm);
}

.fnc-toggle-option:hover .fnc-toggle-content {
    background: #fff;
    border-color: var(--fnc-taupe);
    box-shadow: var(--fnc-shadow-md);
}

.fnc-toggle-option .fnc-toggle-content.is-active {
    background: #fff;
    border-color: var(--fnc-copper);
    box-shadow:
        var(--fnc-shadow-md),
        inset 0 0 0 1px var(--fnc-copper-light);
}

.fnc-toggle-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fnc-parchment);
    border-radius: var(--fnc-radius-md);
    transition: all 0.25s var(--fnc-ease-out);
}

.fnc-toggle-icon svg {
    width: 22px;
    height: 22px;
    color: var(--fnc-stone);
    transition: color 0.25s var(--fnc-ease-out);
}

.fnc-toggle-option .fnc-toggle-content.is-active .fnc-toggle-icon {
    background: var(--fnc-copper-light);
}

.fnc-toggle-option .fnc-toggle-content.is-active .fnc-toggle-icon svg {
    color: var(--fnc-copper);
}

.fnc-toggle-text {
    flex: 1;
    min-width: 0;
}

.fnc-toggle-title {
    display: block;
    font-family: var(--fnc-font-display);
    font-size: 17px;
    font-weight: 500;
    color: var(--fnc-ink);
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}

.fnc-toggle-desc {
    display: block;
    font-size: 13px;
    color: var(--fnc-stone);
    line-height: 1.4;
}

.fnc-toggle-price {
    flex-shrink: 0;
    font-family: var(--fnc-font-display);
    font-size: 14px;
    font-weight: 500;
    color: var(--fnc-sage);
    padding: 4px 10px;
    background: var(--fnc-sage-light);
    border-radius: 20px;
}

.fnc-toggle-arrow {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fnc-stone);
    transition: all 0.25s var(--fnc-ease-out);
}

.fnc-toggle-arrow svg {
    width: 18px;
    height: 18px;
}

.fnc-toggle-option .fnc-toggle-content.is-active .fnc-toggle-arrow {
    color: var(--fnc-copper);
    transform: rotate(90deg);
}


/* ============================================
   Required Fabric Header (no toggle, info only)
   ============================================ */

.fnc-fabric-required-header {
    padding: var(--fnc-space-md);
    background: var(--fnc-linen);
    border-bottom: 1px solid var(--fnc-taupe);
}

.fnc-required-message {
    display: flex;
    align-items: center;
    gap: var(--fnc-space-md);
    padding: var(--fnc-space-md);
    background: var(--fnc-cream);
    border: 2px solid var(--fnc-copper);
    border-radius: var(--fnc-radius-md);
    box-shadow:
        var(--fnc-shadow-md),
        inset 0 0 0 1px var(--fnc-copper-light);
}

.fnc-required-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fnc-copper-light);
    border-radius: var(--fnc-radius-md);
}

.fnc-required-icon svg {
    width: 22px;
    height: 22px;
    color: var(--fnc-copper);
}

.fnc-required-text {
    flex: 1;
    min-width: 0;
}

.fnc-required-title {
    display: block;
    font-family: var(--fnc-font-display);
    font-size: 17px;
    font-weight: 500;
    color: var(--fnc-ink);
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}

.fnc-required-desc {
    display: block;
    font-size: 13px;
    color: var(--fnc-stone);
    line-height: 1.4;
}

.fnc-fabric-error {
    margin-top: var(--fnc-space-sm);
    padding: var(--fnc-space-sm) var(--fnc-space-md);
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--fnc-radius-sm);
    display: flex;
    align-items: center;
    gap: var(--fnc-space-sm);
    color: #991b1b;
    font-size: 13px;
}

.fnc-error-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dc2626;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
}


/* ============================================
   Categories Container
   ============================================ */

.fnc-fabric-categories {
    /* Animation handled by JS */
}


/* ============================================
   Category Accordion
   ============================================ */

.fnc-fabric-category {
    border-bottom: 1px solid var(--fnc-taupe);
}

.fnc-fabric-category:last-child {
    border-bottom: none;
}

.fnc-fabric-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--fnc-space-md) var(--fnc-space-lg);
    background: var(--fnc-cream);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s var(--fnc-ease-out);

    /* Subtle texture */
    background-image: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(212, 207, 196, 0.15) 100%
    );
}

.fnc-fabric-category-header:hover {
    background-color: var(--fnc-linen);
}

.fnc-fabric-category.is-open .fnc-fabric-category-header {
    background-color: var(--fnc-parchment);
}

.fnc-fabric-category-name {
    display: flex;
    align-items: center;
    gap: var(--fnc-space-sm);
    font-family: var(--fnc-font-display);
    font-size: 16px;
    font-weight: 500;
    color: var(--fnc-ink);
    letter-spacing: 0.01em;
}

.fnc-fabric-category-name .arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--fnc-stone);
    transition: all 0.3s var(--fnc-ease-out);
}

.fnc-fabric-category-name .arrow svg {
    width: 16px;
    height: 16px;
}

.fnc-fabric-category.is-open .fnc-fabric-category-name .arrow {
    color: var(--fnc-copper);
    transform: rotate(90deg);
}

.fnc-fabric-category-count {
    font-family: var(--fnc-font-body);
    font-size: 13px;
    font-weight: 400;
    color: var(--fnc-stone);
    margin-left: 2px;
}

.fnc-fabric-category-price {
    font-family: var(--fnc-font-display);
    font-size: 13px;
    font-weight: 500;
    color: var(--fnc-sage);
    padding: 3px 10px;
    background: var(--fnc-sage-light);
    border-radius: 16px;
    transition: all 0.2s var(--fnc-ease-out);
}

.fnc-fabric-category-price.has-upcharge {
    color: var(--fnc-copper);
    background: var(--fnc-copper-light);
}


/* ============================================
   Swatch Container - Accordion Animation
   ============================================ */

.fnc-fabric-swatches {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.35s var(--fnc-ease-out);
    background: var(--fnc-linen);
    box-shadow: var(--fnc-shadow-inset);
}

.fnc-fabric-category.is-open .fnc-fabric-swatches {
    grid-template-rows: 1fr;
}

.fnc-fabric-swatch-grid {
    overflow: hidden;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: var(--fnc-space-md);
    padding: 0;
    max-height: 0;
    opacity: 0;
    transition:
        padding 0.3s var(--fnc-ease-out),
        max-height 0.4s var(--fnc-ease-out),
        opacity 0.25s ease;
}

.fnc-fabric-category.is-open .fnc-fabric-swatch-grid {
    padding: var(--fnc-space-lg);
    padding-top: var(--fnc-space-md);
    max-height: 500px;
    opacity: 1;
    overflow-y: auto;
}

/* Custom scrollbar for swatch grid */
.fnc-fabric-swatch-grid::-webkit-scrollbar {
    width: 8px;
}

.fnc-fabric-swatch-grid::-webkit-scrollbar-track {
    background: var(--fnc-parchment);
    border-radius: 4px;
}

.fnc-fabric-swatch-grid::-webkit-scrollbar-thumb {
    background: var(--fnc-taupe);
    border-radius: 4px;
}

.fnc-fabric-swatch-grid::-webkit-scrollbar-thumb:hover {
    background: var(--fnc-stone);
}


/* ============================================
   Individual Swatch - The Star of the Show
   ============================================ */

.fnc-fabric-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s var(--fnc-ease-out);
    position: relative;
}

.fnc-fabric-swatch img,
.fnc-fabric-swatch .fnc-no-image {
    width: 84px;
    height: 84px;
    object-fit: cover;
    border-radius: var(--fnc-radius-md);
    box-shadow: var(--fnc-swatch-shadow);
    transition: all 0.3s var(--fnc-ease-spring);

    /* Subtle border like a fabric sample card */
    border: 3px solid #fff;
    outline: 1px solid var(--fnc-taupe);
    outline-offset: -1px;

    /* Slight fabric texture effect */
    background: var(--fnc-parchment);
}

.fnc-fabric-swatch .fnc-no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fnc-stone);
}

.fnc-fabric-swatch .fnc-no-image::before {
    content: '?';
    font-family: var(--fnc-font-display);
    font-size: 24px;
    opacity: 0.5;
}

/* Hover state - lift and scale */
.fnc-fabric-swatch:hover img,
.fnc-fabric-swatch:hover .fnc-no-image {
    transform: scale(1.08) translateY(-4px);
    box-shadow: var(--fnc-swatch-shadow-hover);
    outline-color: var(--fnc-stone);
}

/* Selected state - copper accent with glow */
.fnc-fabric-swatch.is-selected img,
.fnc-fabric-swatch.is-selected .fnc-no-image {
    border-color: var(--fnc-copper);
    outline: 2px solid var(--fnc-copper);
    outline-offset: 0;
    box-shadow:
        var(--fnc-swatch-shadow),
        0 0 0 4px var(--fnc-copper-glow);
}

/* Checkmark overlay for selected - matches stain swatches */
.fnc-fabric-swatch.is-selected::before {
    content: '';
    position: absolute;
    top: 42px;  /* Center of 84px image */
    left: 50%;
    transform: translate(-50%, -50%);
    width: 84px;
    height: 84px;
    z-index: 10;
    pointer-events: none;

    /* White checkmark SVG with drop shadow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='26px' viewBox='0 -960 960 960' width='26px' fill='white'%3E%3Cpath d='M382-221.91 135.91-468l75.66-75.65L382-373.22l366.43-366.43L824.09-664 382-221.91Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 26px 26px;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));

    animation: fnc-pop-in 0.35s var(--fnc-ease-spring) forwards;
}

/* Remove the old after pseudo-element */
.fnc-fabric-swatch.is-selected::after {
    display: none;
}

/* Swatch name */
.fnc-fabric-swatch-name {
    font-size: 11px;
    font-weight: 500;
    color: var(--fnc-charcoal);
    text-align: center;
    margin-top: var(--fnc-space-sm);
    max-width: 90px;
    line-height: 1.3;

    /* Elegant text truncation */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;

    transition: color 0.2s ease;
}

.fnc-fabric-swatch:hover .fnc-fabric-swatch-name {
    color: var(--fnc-ink);
}

.fnc-fabric-swatch.is-selected .fnc-fabric-swatch-name {
    color: var(--fnc-copper);
    font-weight: 600;
}

/* Swatch price - shown below each swatch */
.fnc-fabric-swatch-price {
    font-family: var(--fnc-font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--fnc-sage);
    text-align: center;
    margin-top: 2px;
    padding: 2px 6px;
    background: var(--fnc-sage-light);
    border-radius: 10px;
    transition: all 0.2s ease;
}

/* Highlight price for upcharge fabrics */
.fnc-fabric-swatch-price:not(:empty) {
    /* Only show background if there's content */
}

.fnc-fabric-swatch:hover .fnc-fabric-swatch-price {
    background: var(--fnc-copper-light);
    color: var(--fnc-copper);
}

.fnc-fabric-swatch.is-selected .fnc-fabric-swatch-price {
    background: var(--fnc-copper);
    color: #fff;
}


/* ============================================
   Animations
   ============================================ */

@keyframes fnc-pop-in {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    60% {
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes fnc-checkmark-pop {
    0% {
        transform: rotate(45deg) scale(0);
    }
    60% {
        transform: rotate(45deg) scale(1.2);
    }
    100% {
        transform: rotate(45deg) scale(1);
    }
}


/* ============================================
   Hide Swatches Without Images
   ============================================ */

.fnc-fabric-swatch:has(.fnc-no-image) {
    display: none !important;
}

/* Also hide if the img src is empty */
.fnc-fabric-swatch:has(img[src=""]),
.fnc-fabric-swatch:has(img:not([src])) {
    display: none !important;
}


/* ============================================
   Hide Original WPO Choices (keep for form)
   ============================================ */

.wpo-field.fnc-fabric .wpo-image-buttons.fnc-original-choices {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
    .fnc-fabric-selector {
        border-radius: var(--fnc-radius-md);
    }

    .fnc-toggle-content {
        padding: var(--fnc-space-sm) var(--fnc-space-md);
        gap: var(--fnc-space-sm);
    }

    .fnc-toggle-icon {
        width: 36px;
        height: 36px;
    }

    .fnc-toggle-icon svg {
        width: 18px;
        height: 18px;
    }

    .fnc-toggle-title {
        font-size: 15px;
    }

    .fnc-toggle-desc {
        font-size: 12px;
    }

    .fnc-toggle-price {
        font-size: 12px;
        padding: 3px 8px;
    }

    .fnc-fabric-category-header {
        padding: var(--fnc-space-sm) var(--fnc-space-md);
    }

    .fnc-fabric-category-name {
        font-size: 14px;
    }

    .fnc-fabric-swatch-grid {
        grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
        gap: var(--fnc-space-sm);
    }

    .fnc-fabric-category.is-open .fnc-fabric-swatch-grid {
        padding: var(--fnc-space-md);
    }

    .fnc-fabric-swatch img,
    .fnc-fabric-swatch .fnc-no-image {
        width: 70px;
        height: 70px;
    }

    .fnc-fabric-swatch-name {
        font-size: 10px;
        max-width: 75px;
    }

    .fnc-fabric-swatch-price {
        font-size: 10px;
        padding: 1px 5px;
    }

    /* Adjust checkmark for smaller swatches */
    .fnc-fabric-swatch.is-selected::before {
        top: 35px;  /* Center of 70px image */
        width: 70px;
        height: 70px;
        background-size: 22px 22px;
    }
}

@media (max-width: 480px) {
    .fnc-toggle-arrow {
        display: none;
    }

    .fnc-fabric-swatch-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .fnc-fabric-swatch img,
    .fnc-fabric-swatch .fnc-no-image {
        width: 64px;
        height: 64px;
    }

    .fnc-fabric-category.is-open .fnc-fabric-swatch-grid {
        max-height: 400px;
    }

    /* Adjust checkmark for smallest swatches */
    .fnc-fabric-swatch.is-selected::before {
        top: 32px;  /* Center of 64px image */
        width: 64px;
        height: 64px;
        background-size: 20px 20px;
    }
}


/* ============================================
   Dark Mode Support (optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    .fnc-fabric-selector {
        /* Keep light theme for fabric viewing accuracy */
        /* Fabrics need to be seen in true color */
    }
}


/* ============================================
   Print Styles
   ============================================ */

@media print {
    .fnc-fabric-selector {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .fnc-fabric-swatches {
        display: block !important;
    }

    .fnc-fabric-swatch-grid {
        max-height: none !important;
        opacity: 1 !important;
        padding: 16px !important;
    }

    .fnc-fabric-category.is-open .fnc-fabric-swatch-grid,
    .fnc-fabric-swatch-grid {
        display: grid !important;
        grid-template-columns: repeat(6, 1fr) !important;
    }
}
