/**
 * Single Product Page Styles
 *
 * Correct B2B layout:
 * 1. Top: Gallery (left) + Basic Info (right)
 * 2. Below: Price + Order Form (full width)
 * 3. Below: Tabs (Description, Details)
 * 4. Below: Related Products
 *
 * @package B2B_Spokar_Theme
 */

/* ==========================================================================
   Breadcrumb Navigation
   ========================================================================== */

.woocommerce-breadcrumb {
    padding: var(--spacing-md) 0;
    margin-bottom: var(--spacing-lg);
    font-size: var(--font-size-small);
    color: var(--color-text-light);
}

.woocommerce-breadcrumb a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-base);
}

.woocommerce-breadcrumb a:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

/* ==========================================================================
   Main Product Container
   ========================================================================== */

.single-product div.product {
    display: block; /* Not grid! We'll structure it differently */
    margin-bottom: var(--spacing-xl);
}

/* ==========================================================================
   Top Section: Gallery + Basic Info (Side by Side)
   ========================================================================== */

.product-top-section {
    display: grid;
    grid-template-columns: 500px 1fr;
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-xl);
    border-bottom: 2px solid var(--color-border);
}

/* We'll move gallery and entry-summary into this section using flexbox order */
.single-product div.product {
    display: flex;
    flex-wrap: wrap;
}

.woocommerce-product-gallery {
    order: 1;
    flex: 0 0 500px;
    margin-right: var(--spacing-xl);
}

.summary.entry-summary {
    order: 2;
    flex: 1;
    min-width: 300px;
}

/* ==========================================================================
   Product Gallery (Large Image + Small Thumbnails)
   ========================================================================== */

.woocommerce-product-gallery {
    position: relative;
}

.woocommerce-product-gallery__wrapper {
    margin-bottom: var(--spacing-md);
}

/* Product Gallery: First image large, others as small thumbnails */
.woocommerce-product-gallery__wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

/* First image - LARGE */
.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child {
    flex: 0 0 100%;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    margin-bottom: var(--spacing-sm);
}

.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:first-child img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

/* Other images - SMALL THUMBNAILS (horizontal) */
.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:not(:first-child) {
    flex: 0 0 auto;
    width: 80px;
    height: 80px;
    overflow: hidden;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
    transition: all var(--transition-base);
}

.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:not(:first-child) img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image:not(:first-child):hover {
    border-color: var(--color-primary);
}

/* FlexSlider thumbnails (if they appear) */
.flex-control-thumbs {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    list-style: none;
    margin: 0;
    padding: 0;
}

.flex-control-thumbs li {
    margin: 0;
    flex: 0 0 auto;
    width: 80px;
    height: 80px;
}

.flex-control-thumbs li img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    background: #fff;
}

.flex-control-thumbs li img:hover,
.flex-control-thumbs li img.flex-active {
    border-color: var(--color-primary);
}

/* ==========================================================================
   Product Summary (Right Column - Basic Info Only)
   ========================================================================== */

.summary.entry-summary {
    /* Just basic info at top: title, SKU, category */
}

.product_title {
    font-size: var(--font-size-h2);
    margin-bottom: var(--spacing-md);
    font-weight: 700;
    line-height: 1.3;
}

.product_meta {
    font-size: var(--font-size-small);
    color: var(--color-text-light);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--color-border);
}

.product_meta > span {
    display: block;
    margin-bottom: var(--spacing-xs);
}

.product_meta a {
    color: var(--color-primary);
    text-decoration: none;
}

.product_meta a:hover {
    text-decoration: underline;
}

/* Short description in summary */
.woocommerce-product-details__short-description {
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-text);
    margin-bottom: var(--spacing-lg);
}

/* ==========================================================================
   Order Form (Full Width Below Gallery+Info)
   ========================================================================== */

/* Variations form - full width */
.summary.entry-summary form.cart {
    order: 11;
    flex: 0 0 100%;
    background: var(--color-bg-light);
    padding: var(--spacing-lg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    margin-bottom: var(--spacing-xl);
}

.variations {
    margin-bottom: var(--spacing-md);
}

.variations tr {
    display: flex;
    flex-direction: column;
    margin-bottom: var(--spacing-md);
}

.variations label {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
    font-size: var(--font-size-base);
}

.variations select {
    width: 100%;
    max-width: 400px;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
}

.variations select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.reset_variations {
    margin-top: var(--spacing-sm);
    font-size: var(--font-size-small);
    color: var(--color-primary);
    text-decoration: none;
}

.reset_variations:hover {
    text-decoration: underline;
}

/* Quantity + Add to Cart Button */
.quantity {
    display: inline-flex;
    align-items: center;
    margin-right: var(--spacing-md);
}

.quantity input.qty {
    width: 80px;
    padding: var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: var(--font-size-base);
}

.single_add_to_cart_button {
    padding: 12px 32px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-base);
}

.single_add_to_cart_button:hover {
    background: var(--color-primary-dark);
}

.single_add_to_cart_button:disabled {
    background: var(--color-text-light);
    cursor: not-allowed;
}

/* Favorites button */
.b2b-add-to-favorites {
    margin-left: var(--spacing-md);
    padding: 10px 20px;
    background: transparent;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-base);
    cursor: pointer;
    transition: all var(--transition-base);
}

.b2b-add-to-favorites:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ==========================================================================
   Product Tabs (Description, Additional Info)
   ========================================================================== */

.woocommerce-tabs {
    order: 20;
    flex: 0 0 100%;
    margin-bottom: var(--spacing-xl);
}

.woocommerce-tabs ul.tabs {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    border-bottom: 2px solid var(--color-border);
    gap: var(--spacing-sm);
}

.woocommerce-tabs ul.tabs li {
    margin: 0;
}

.woocommerce-tabs ul.tabs li a {
    display: block;
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--color-text-light);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--font-size-base);
    border-bottom: 3px solid transparent;
    transition: all var(--transition-base);
}

.woocommerce-tabs ul.tabs li a:hover {
    color: var(--color-primary);
}

.woocommerce-tabs ul.tabs li.active a {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.woocommerce-Tabs-panel {
    padding: var(--spacing-lg) 0;
}

.woocommerce-Tabs-panel h2 {
    font-size: var(--font-size-h3);
    margin-bottom: var(--spacing-md);
}

.woocommerce-Tabs-panel p {
    line-height: 1.7;
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-base);
}

.woocommerce-Tabs-panel ul,
.woocommerce-Tabs-panel ol {
    margin-left: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
}

.woocommerce-Tabs-panel li {
    margin-bottom: var(--spacing-xs);
    line-height: 1.6;
}

/* Additional information table */
.woocommerce-product-attributes {
    width: 100%;
    border-collapse: collapse;
}

.woocommerce-product-attributes tr {
    border-bottom: 1px solid var(--color-border);
}

.woocommerce-product-attributes th {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    font-weight: 600;
    background: var(--color-bg-light);
    width: 200px;
}

.woocommerce-product-attributes td {
    padding: var(--spacing-sm) var(--spacing-md);
}

/* ==========================================================================
   Related Products (MUST BE BELOW TABS!)
   ========================================================================== */

.related.products {
    order: 30;
    flex: 0 0 100%;
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-xl);
    border-top: 2px solid var(--color-border);
}

.related.products > h2 {
    font-size: var(--font-size-h2);
    margin-bottom: var(--spacing-lg);
}

.related.products .product-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-lg);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media screen and (max-width: 1199px) {
    .woocommerce-product-gallery {
        flex: 0 0 400px;
    }

    .related.products .product-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media screen and (max-width: 991px) {
    .single-product div.product {
        flex-direction: column;
    }

    .woocommerce-product-gallery {
        flex: 0 0 auto;
        width: 100%;
        max-width: 500px;
        margin: 0 auto var(--spacing-lg) auto;
    }

    .summary.entry-summary {
        width: 100%;
    }

    .related.products .product-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media screen and (max-width: 767px) {
    .woocommerce-product-gallery {
        max-width: 100%;
    }

    .flex-control-thumbs li {
        width: 60px;
        height: 60px;
    }

    .related.products .product-grid {
        grid-template-columns: 1fr;
    }

    .summary.entry-summary form.cart {
        padding: var(--spacing-md);
    }

    .variations select {
        max-width: 100%;
    }
}

/* ==========================================================================
   Custom Product Gallery - Horizontal Thumbnails with Lightbox
   ========================================================================== */

/* Main gallery container */
.b2b-product-gallery {
    position: relative;
    width: 100%;
    margin-bottom: var(--spacing-md);
    padding: 30px 0;
}

/* Horizontal thumbnails wrapper */
.b2b-gallery-thumbnails {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    /* Hide default scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-bottom: 20px; /* Gap before indicator */
}

.b2b-gallery-thumbnails::-webkit-scrollbar {
    display: none;
}

/* Custom scroll indicator */
.b2b-scroll-indicator {
    position: absolute;
    bottom: 10px; /* Position above bottom of gallery container */
    left: 0;
    right: 0;
    height: 2px;
    background: #e0e0e0; /* Light grey background */
    border-radius: 1px;
    pointer-events: none; /* Don't block mouse events */
}

.b2b-scroll-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #757575; /* Dark grey progress */
    border-radius: 1px;
    transition: left 0.1s ease-out, width 0.1s ease-out;
    pointer-events: none; /* Don't block mouse events on thumbnails */
}

/* Thumbnails track (draggable) */
.b2b-thumbnails-track {
    display: flex;
    gap: var(--spacing-sm);
    min-width: min-content;
    cursor: grab;
    user-select: none;
}

.b2b-thumbnails-track.dragging {
    cursor: grabbing;
}

/* Individual thumbnail item */
.b2b-thumbnail-item {
    flex: 0 0 150px;
    width: 150px;
    height: 150px;
    overflow: hidden;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
    transition: all var(--transition-base);
}

.b2b-thumbnail-item:hover {
    border-color: var(--color-primary);
    transform: scale(1.02);
}

.b2b-thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    /* Prevent native image drag */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none; /* Let parent handle drag */
}

/* ==========================================================================
   Lightbox Overlay
   ========================================================================== */

.b2b-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.b2b-lightbox.active {
    display: flex;
    opacity: 1;
}

/* Lightbox content container */
.b2b-lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Lightbox slider (2 img elements for smooth transitions) */
.b2b-lightbox-slider {
    position: relative;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.b2b-lightbox-img {
    position: absolute;
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    transition: transform 0.5s ease, opacity 0.5s ease;
    opacity: 0;
}

.b2b-lightbox-img.active {
    opacity: 1;
}

/* Lightbox navigation buttons */
.b2b-lightbox-close,
.b2b-lightbox-prev,
.b2b-lightbox-next {
    position: absolute;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100000;
}

.b2b-lightbox-close:hover,
.b2b-lightbox-prev:hover,
.b2b-lightbox-next:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.b2b-lightbox-close {
    top: 20px;
    right: 20px;
}

.b2b-lightbox-prev {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.b2b-lightbox-prev:hover {
    transform: translateY(-50%) scale(1.1);
}

.b2b-lightbox-next {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.b2b-lightbox-next:hover {
    transform: translateY(-50%) scale(1.1);
}

.b2b-lightbox-close svg,
.b2b-lightbox-prev svg,
.b2b-lightbox-next svg {
    width: 24px;
    height: 24px;
}

/* Loading state */
.b2b-lightbox-img[src=""] {
    opacity: 0;
}

/* ==========================================================================
   Responsive Gallery Adjustments
   ========================================================================== */

@media screen and (max-width: 767px) {
    .b2b-thumbnail-item {
        flex: 0 0 120px;
        width: 120px;
        height: 120px;
    }

    .b2b-lightbox-slider {
        width: 95%;
        height: 80vh;
    }

    .b2b-lightbox-img {
        max-height: 80vh;
    }

    .b2b-lightbox-close,
    .b2b-lightbox-prev,
    .b2b-lightbox-next {
        width: 40px;
        height: 40px;
    }

    .b2b-lightbox-close {
        top: 10px;
        right: 10px;
    }

    .b2b-lightbox-prev {
        left: 10px;
    }

    .b2b-lightbox-next {
        right: 10px;
    }

    .b2b-lightbox-close svg,
    .b2b-lightbox-prev svg,
    .b2b-lightbox-next svg {
        width: 20px;
        height: 20px;
    }
}
