/**
 * WooCommerce Size Chart Frontend Styles
 * Responsive and mobile-friendly table design
 */

/* Main container */
.wsc-size-chart-wrapper {
    margin: 20px 0;
    font-family: inherit;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.wsc-chart-title {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

.wsc-chart-description {
    margin-bottom: 20px;
    color: #666;
    line-height: 1.6;
}

/* Responsive table wrapper */
.wsc-table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
    position: relative;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Table styles */
.wsc-size-chart {
    width: 100%;
    min-width: max-content;
    border-collapse: collapse;
    border-spacing: 0;
    background: #fff;
    box-shadow: none; /* Moved to wrapper */
}

.wsc-size-chart thead {
    background: #f8f9fa;
}

.wsc-size-chart thead th {
    background: var(--wc-primary, #2271b1);
    color: #fff;
    font-weight: 600;
    text-align: center;
    padding: 12px 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.wsc-size-chart tbody td {
    padding: 10px;
    text-align: center;
    border: 1px solid #e1e1e1;
    background: #fff;
}

/* Alternating row colors are now controlled by individual chart settings */

.wsc-size-chart tbody tr:hover td {
    background: #f0f6ff;
    transition: background 0.2s ease;
}

/* Product page integration */
.wsc-product-size-chart {
    margin: 15px 0;
}

.wsc-position-before_add_to_cart {
    margin-bottom: 20px;
}

.wsc-position-after_add_to_cart {
    margin-top: 20px;
}

/* Mobile responsive styles */
@media screen and (max-width: 768px) {
    /* Force container to respect viewport */
    .wsc-size-chart-wrapper {
        width: 100vw;
        max-width: calc(100vw - 40px); /* Account for page margins */
        margin-left: calc(50% - 50vw + 20px);
        margin-right: calc(50% - 50vw + 20px);
    }
    
    .wsc-table-responsive {
        width: 100%;
        max-width: 100%;
        overflow-x: scroll;
        overflow-y: hidden;
        position: relative;
        scroll-behavior: smooth;
        /* Add gradient shadows to indicate scrollable content */
        background: 
            linear-gradient(to right, white 30%, rgba(255,255,255,0)),
            linear-gradient(to right, rgba(255,255,255,0), white 70%),
            linear-gradient(to right, rgba(0,0,0,.15), transparent 30px),
            linear-gradient(to left, rgba(0,0,0,.15), transparent 30px);
        background-position: left center, right center, left center, right center;
        background-repeat: no-repeat;
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-attachment: local, local, scroll, scroll;
    }
    
    .wsc-size-chart {
        width: auto;
        min-width: 500px; /* Force minimum width for readability */
        font-size: 13px;
    }
    
    .wsc-size-chart thead th,
    .wsc-size-chart tbody td {
        padding: 8px 6px;
        white-space: nowrap;
        min-width: 65px;
    }
    
    .wsc-chart-title {
        font-size: 1.1em;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* Visual scroll indicator dots */
    .wsc-table-responsive::before {
        content: '';
        position: absolute;
        top: 50%;
        right: 8px;
        transform: translateY(-50%);
        width: 20px;
        height: 4px;
        background: repeating-linear-gradient(
            to right,
            #999 0,
            #999 3px,
            transparent 3px,
            transparent 7px
        );
        pointer-events: none;
        opacity: 0.6;
        animation: scroll-hint 2s ease-in-out infinite;
        z-index: 10;
    }
    
    /* Hide hint after user scrolls */
    .wsc-table-responsive.has-scrolled::before {
        display: none;
    }
    
    /* Make headers sticky on mobile for better UX */
    .wsc-size-chart thead th {
        position: sticky;
        top: 0;
        z-index: 5;
        background: var(--wc-primary, #2271b1);
    }
}

@media screen and (max-width: 480px) {
    .wsc-size-chart-wrapper {
        width: 100vw;
        max-width: calc(100vw - 20px); /* Less margin on very small screens */
        margin-left: calc(50% - 50vw + 10px);
        margin-right: calc(50% - 50vw + 10px);
    }
    
    .wsc-size-chart {
        font-size: 12px;
        min-width: 400px;
    }
    
    .wsc-size-chart thead th,
    .wsc-size-chart tbody td {
        padding: 6px 4px;
        min-width: 55px;
    }
}

@keyframes scroll-hint {
    0%, 100% {
        transform: translateY(-50%) translateX(0);
    }
    50% {
        transform: translateY(-50%) translateX(5px);
    }
}

/* WooCommerce tab integration */
.woocommerce-tabs .wsc-size-chart-wrapper {
    margin-top: 0;
}

/* Elementor widget specific styles */
.elementor-widget-wsc_size_chart .wsc-size-chart-wrapper {
    margin: 0;
}

/* Print styles */
@media print {
    .wsc-size-chart {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .wsc-size-chart thead th {
        background: #000 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .wsc-size-chart tbody td {
        border: 1px solid #000;
    }
}

/* Accessibility */
.wsc-size-chart:focus {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

.wsc-size-chart tbody tr:focus-within {
    outline: 2px solid #2271b1;
    outline-offset: -2px;
}

/* Inactive chart styles */
.wsc-inactive {
    padding: 20px;
    border-radius: 4px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    text-align: center;
    color: #6c757d;
}

.wsc-inactive p {
    margin: 0;
    font-style: italic;
}

/* Dark mode support (if theme supports it) */
@media (prefers-color-scheme: dark) {
    body.theme-dark .wsc-size-chart {
        background: #1e1e1e;
        color: #e0e0e0;
    }
    
    body.theme-dark .wsc-size-chart tbody td {
        background: #1e1e1e;
        border-color: #444;
    }
    
    /* Alternating row colors in dark mode are now controlled by individual chart settings */
    
    body.theme-dark .wsc-size-chart tbody tr:hover td {
        background: #2a3f5f;
    }
    
    body.theme-dark .wsc-inactive {
        background: #2d2d2d;
        border-color: #444;
        color: #aaa;
    }
}