/**
 * Categorized Results CSS
 * Styles for categorized product results with toggles
 */

/* Results Layout - Sidebar + Main Content */
.tecalliance-results-layout {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    align-items: flex-start;
}

/* Filter Sidebar - Always visible on desktop, hidden on mobile */
.tecalliance-filter-container {
    flex-shrink: 0;
    width: 280px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    transition: all 0.3s ease;
}

/* Hide filter sidebar on mobile by default */
@media (max-width: 1024px) {
    .tecalliance-filter-container {
        display: none;
    }
    
    .tecalliance-filter-container.tecalliance-sidebar-open {
        display: flex;
    }
}

/* Main Results Area */
.tecalliance-results-main {
    flex: 1;
    min-width: 0;
    width: 100%;
}

/* Categorized Results Container */
.tecalliance-categorized-results {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Category Section */
.tecalliance-category-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
    transition: all 0.3s ease;
}

.tecalliance-category-section:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

/* Category Header */
.tecalliance-category-header {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 14px 20px;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.tecalliance-category-header:hover {
    background: linear-gradient(135deg, #e9ecef, #dee2e6);
    border-left-color: #E94141;
}

.tecalliance-category-header.active {
    background: linear-gradient(135deg, #fff5f5, #ffe5e5);
    border-left-color: #E94141;
}

.tecalliance-category-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 30px !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tecalliance-category-icon {
    font-size: 14px;
    color: #E94141;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.tecalliance-category-header.active .tecalliance-category-icon {
    transform: rotate(90deg);
}

.tecalliance-category-count {
    margin-left: auto;
    background: #E94141;
    color: white;
    padding: 5px;
    border-radius: 100%;
    font-size: 13px;
    font-weight: 600;
    min-width: 35px;
    text-align: center;
    flex-shrink: 0;
    position: absolute;
}

/* Category Content - Start closed by default */
.tecalliance-category-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease;
    opacity: 0;
    padding: 0 20px;
}

.tecalliance-category-header.active + .tecalliance-category-content {
    max-height: 5000px;
    opacity: 1;
    padding: 0 !important;
}

/* Fallback: also open when .show is present (set by JS) */
.tecalliance-category-content.show {
    max-height: 5000px;
    opacity: 1;
    padding: 20px;
}

/* Bounded scroll area for tables: 5 rows visible, vertical scroll inside, page scroll beyond */
.tecalliance-table-scroll {
    max-height: 360px; /* roughly ~5 rows, adjust as needed */
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y pinch-zoom; /* vertical scroll primary, allow zoom */
    overscroll-behavior: contain; /* at edges, don't chain beyond unless scrolled */
}

@media (max-width: 768px) {
    .tecalliance-table-scroll {
        max-height: 320px; /* slightly smaller on mobile */
        overflow-y: auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y pan-x pinch-zoom; /* allow both axes inside */
        overscroll-behavior-y: contain; /* prevent rubber-band pull */
    }
}

.tecalliance-category-content .tecalliance-parts-table {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .tecalliance-results-layout {
        flex-direction: column;
        gap: 0;
        margin-top: 10px;
    }
    
    .tecalliance-results-main {
        width: 100%;
    }
    
    .tecalliance-category-header {
        padding: 12px 16px;
    }
    
    .tecalliance-category-title {
        font-size: 15px;
    }
}

@media (max-width: 768px) {
    .tecalliance-results-layout {
        gap: 0;
        margin-top: 8px;
    }
    
    .tecalliance-category-section {
        border-radius: 8px;
        margin-bottom: 10px;
    }
    
    .tecalliance-category-header {
        padding: 10px 12px;
    }
    
    .tecalliance-category-title {
        font-size: 14px;
        gap: 8px;
    }
    
    .tecalliance-category-count {
        font-size: 11px;
        padding: 2px 8px;
        min-width: 30px;
    }
    
    /* Make tables scrollable on mobile with visible scrollbar */
    .tecalliance-category-content {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }
    
    /* Custom scrollbar for better visibility */
    .tecalliance-category-content::-webkit-scrollbar {
        height: 8px;
    }
    
    .tecalliance-category-content::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 4px;
    }
    
    .tecalliance-category-content::-webkit-scrollbar-thumb {
        background: #E94141;
        border-radius: 4px;
    }
    
    .tecalliance-category-content::-webkit-scrollbar-thumb:hover {
        background: #c93636;
    }
    
    /* For Firefox */
    .tecalliance-category-content {
        scrollbar-width: thin;
        scrollbar-color: #E94141 #f1f1f1;
    }
    
    .tecalliance-parts-table {
        min-width: 600px;
        font-size: 14px;
    }
    
    .tecalliance-parts-table th,
    .tecalliance-parts-table td {
        padding: 10px 8px;
        font-size: 13px;
    }
}

@media (max-width: 576px) {
    .tecalliance-results-container {
        padding: 6px 4px;
    }
    
    .tecalliance-results-layout {
        gap: 0;
        margin-top: 6px;
    }
    
    .tecalliance-categorized-results {
        gap: 8px;
    }
    
    .tecalliance-category-section {
        border-radius: 6px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.08);
        margin-bottom: 8px;
    }
    
    .tecalliance-category-header {
        padding: 8px 10px;
    }
    
    .tecalliance-category-title {
        font-size: 13px;
        gap: 6px;
        flex-wrap: nowrap;
    }
    
    .tecalliance-category-icon {
        font-size: 12px;
        flex-shrink: 0;
    }
    
    .tecalliance-category-count {
        font-size: 10px;
        padding: 3px;
    }
    
    /* Optimize table for very small screens */
    .tecalliance-parts-table {
        min-width: 550px;
        font-size: 13px;
    }
    
    .tecalliance-parts-table th,
    .tecalliance-parts-table td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .tecalliance-parts-table th {
        font-size: 13px;
    }
    
    /* Adjust image sizes for mobile */
    .tecalliance-image-cell {
        width: 50px;
        padding: 6px !important;
    }
    
    .tecalliance-product-gallery,
    .tecalliance-main-thumb {
        width: 45px;
        height: 45px;
    }
    
    .tecalliance-image-count {
        font-size: 9px;
        padding: 1px 3px;
        min-width: 14px;
    }
    
    /* Optimize feature chips for mobile */
    .ta-chip {
        font-size: 11px;
        padding: 3px 6px;
        margin: 1px 2px;
    }
}

@media (max-width: 400px) {
    .tecalliance-results-container {
        padding: 4px 2px;
    }
    
    .tecalliance-category-header {
        padding: 8px;
    }
    
    .tecalliance-category-title {
        font-size: 12px;
        gap: 5px;
    }
    
    .tecalliance-category-count {
        font-size: 9px;
        padding: 1px 5px;
        min-width: 20px;
    }
    
    /* Ultra-compact table for very small screens */
    .tecalliance-parts-table {
        min-width: 500px;
        font-size: 12px;
    }
    
    .tecalliance-parts-table th,
    .tecalliance-parts-table td {
        padding: 6px 4px;
        font-size: 11px;
    }
    
    .tecalliance-parts-table th {
        font-size: 12px;
    }
    
    .tecalliance-image-cell {
        width: 40px;
        padding: 4px !important;
    }
    
    .tecalliance-product-gallery,
    .tecalliance-main-thumb {
        width: 38px;
        height: 38px;
    }
}

/* Scroll indicator for mobile */
@media (max-width: 768px) {
    .tecalliance-category-content::after {
        content: '→';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        background: linear-gradient(to left, rgba(233,65,65,0.9), transparent);
        color: white;
        padding: 20px 10px;
        font-size: 20px;
        font-weight: bold;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
        z-index: 5;
    }
    
    .tecalliance-category-content:not(.scrolled-end)::after {
        opacity: 1;
        animation: scrollPulse 2s ease-in-out infinite;
    }
    
    @keyframes scrollPulse {
        0%, 100% {
            opacity: 0.7;
            transform: translateY(-50%) translateX(0);
        }
        50% {
            opacity: 1;
            transform: translateY(-50%) translateX(-5px);
        }
    }
}

/* Animation for category opening */
@keyframes categorySlideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tecalliance-category-header.active + .tecalliance-category-content {
    animation: categorySlideDown 0.3s ease;
}

/* Accessibility */
.tecalliance-category-header:focus {
    outline: 2px solid #E94141;
    outline-offset: 2px;
}

/* ========== Lightbox (Product Gallery) ========== */
.ta-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 20, 0.88);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 20px;
}
.ta-lightbox-overlay.show { display: flex; }
.ta-no-scroll { overflow: hidden; }

.ta-lightbox {
    position: relative;
    width: 100%;
    max-width: 1100px;
    max-height: 90vh;
    display: grid;
    grid-template-columns: 56px 1fr 56px;
    grid-template-rows: 1fr auto;
    gap: 10px;
}
.ta-lightbox-stage {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ta-lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    background: #111;
}
.ta-lightbox-caption {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
    color: #f2f2f2;
    text-align: center;
    font: 500 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    opacity: .9;
    min-height: 1.4em;
}

.ta-lightbox-close {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: #111;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
    cursor: pointer;
    transition: transform .15s ease;
}
.ta-lightbox-close:hover { transform: scale(1.05); }

.ta-lightbox-nav {
    align-self: center;
    justify-self: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.92);
    color: #111;
    font-size: 28px;
    line-height: 48px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
    transition: transform .15s ease, background .2s ease;
}
.ta-lightbox-nav:hover { background: #fff; transform: scale(1.05); }
.ta-lightbox-nav.ta-prev { grid-column: 1 / 2; }
.ta-lightbox-nav.ta-next { grid-column: 3 / 4; }

/* Product gallery main thumb */
.tecalliance-product-gallery .tecalliance-main-thumb {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: zoom-in;
}
.tecalliance-product-gallery .tecalliance-main-thumb img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}
.tecalliance-image-count {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0,0,0,.65);
    color: #fff;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

@media (max-width: 640px) {
    .ta-lightbox { grid-template-columns: 44px 1fr 44px; }
    .ta-lightbox-nav { width: 40px; height: 40px; line-height: 40px; font-size: 24px; }
    .ta-lightbox-img { max-height: 70vh; }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .tecalliance-category-section,
    .tecalliance-category-header,
    .tecalliance-category-content,
    .tecalliance-category-icon {
        transition: none !important;
        animation: none !important;
    }
}

/* Print Styles */
@media print {
    .tecalliance-filter-container {
        display: none;
    }
    
    .tecalliance-results-layout {
        display: block;
    }
    
    .tecalliance-category-content {
        max-height: none !important;
        opacity: 1 !important;
    }
    
    .tecalliance-category-header {
        page-break-after: avoid;
    }
}
