/**
 * Dynamic Subfamily Shortcode Styles
 *
 * Styles for level 4 subcategories with product tables
 */

/* Breadcrumb spacing */
.wc-block-breadcrumbs {
    padding-left: 20px;
}

/* === BANNER === */
.dynamic-subfamily-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 20px 48px;
    background-color: #f0f0f0;
    margin-bottom: 0;
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.dynamic-subfamily-banner-image {
    flex-shrink: 0;
    height: 120px !important;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.dynamic-subfamily-banner-title {
    color: var(--category-color, #d4821f);
    font-size: 24px;
    font-weight: 700;
    text-transform: uppercase;
    margin: 0;
    letter-spacing: 0.5px;
}

.level2-products-wrapper {
    display: flex;
    gap: 30px;
    padding: 20px 20px 20px 0;
}

.products-filters-sidebar {
    width: 220px;
    flex-shrink: 0;
}

.filters-inner {
    position: sticky;
    top: 20px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
}

.filters-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.filters-title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin: 0;
}

.clear-all-filters {
    font-size: 13px;
    color: var(--theme-primary, #22424f);
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s ease;
    align-self: flex-start;
}

.clear-all-filters:hover {
    color: var(--theme-primary, #22424f);
    opacity: 0.7;
    text-decoration: underline;
}

.filters-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 5px;
}

.filters-list::-webkit-scrollbar {
    width: 6px;
}

.filters-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.filters-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.filters-list::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    margin-bottom: 0 !important;
    padding: 4px 0;
}

.filter-option.filter-active {
    position: sticky;
    background: white;
    z-index: 10;
}

.filter-option:hover {
    background-color: #f5f5f5;
}

.filter-option.filter-active:hover {
    background-color: #f5f5f5;
}

.filter-option input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--theme-primary, #22424f);
}

.filter-label {
    font-size: 14px;
    color: #333;
    user-select: none;
    margin-bottom: 0;
}

.filters-separator {
    background: white;
    margin: 0;
    padding: 10px 0;
    position: sticky;
    z-index: 9;
}

.filters-separator::after {
    content: '';
    display: block;
    height: 1px;
    background: #e0e0e0;
}

.level2-products-main {
    flex: 1;
    min-width: 0;
}

.level2-products-container {
    padding: 0;
}

.level3-categories-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    margin-bottom: 40px;
}

.category-product-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.category-product-card:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.category-product-card.full-width {
    max-width: 100%;
}

.category-card-header {
    display: flex;
    padding: 15px;
    background: #f8f8f8;
    border-bottom: 1px solid #e0e0e0;
    align-items: center;
    gap: 15px;
}

.category-card-image {
    position: relative;
    width: 90px;
    height: 90px;
    flex-shrink: 0;
}

.category-card-image.placeholder {
    background: #e8e8e8;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.category-card-image.placeholder svg {
    width: 36px;
    height: 36px;
    opacity: 0.3;
}

.category-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.add-to-favorites {
    position: absolute;
    top: 5px;
    right: 5px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.add-to-favorites:hover {
    background: #f0f0f0;
    border-color: #999;
}

.add-to-favorites svg {
    width: 18px;
    height: 18px;
    stroke: #666;
}

.add-to-favorites.active svg {
    fill: #ff4444;
    stroke: #ff4444;
}

.category-card-info {
    flex: 1;
}

.category-label {
    display: block;
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.category-card-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin: 0;
    text-transform: uppercase;
}

.products-table-wrapper {
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
    position: relative;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
}

.products-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.products-table thead tr {
    background: var(--category-color, #d4821f);
    color: white;
}

.products-table th {
    padding: 10px 15px;
    text-align: left;
    font-weight: 500;
    font-size: 14px;
}

.products-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: background-color 0.2s ease;
}

.products-table tbody tr:hover {
    background-color: #f9f9f9;
}

.products-table td {
    padding: 12px 15px;
    font-size: 14px;
}

.col-sku {
    width: 80px;
}

.col-description {
    flex: 1;
}

.col-subcategory {
    width: 90px;
}

.col-stock {
    width: 55px;
}

.col-price,
.products-table th.col-price {
    width: 65px;
    text-align: left;
    white-space: nowrap;
}

.col-price .woocommerce-Price-amount {
    font-weight: 500;
}

.col-actions {
    width: 50px;
    text-align: center;
}

.availability-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    background-color: transparent;
}

.availability-dot.stock-green {
    background-color: #28a745;
}

.availability-dot.stock-yellow {
    background-color: #ffc107;
}

.availability-dot.stock-red {
    background-color: #dc3545;
}

.sku-number {
    font-weight: 500;
    color: #333;
}

.add-to-cart-btn {
    background: none;
    border: none;
    border-radius: 4px;
    width: 36px;
    height: 36px;
    padding: 0;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.add-to-cart-btn:hover {
    transform: scale(1.1);
    filter: brightness(1.2);
}

.add-to-cart-btn.loading {
    opacity: 0.6;
    cursor: wait;
    pointer-events: none;
}

.add-to-cart-btn.added {
    filter: brightness(1.3);
}

.qty-controller {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 2px;
    background: white;
}

.qty-controller.updating {
    opacity: 0.6;
    pointer-events: none;
}

.qty-controller .qty-minus,
.qty-controller .qty-plus {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 3px;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #666;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

.qty-controller .qty-minus:hover,
.qty-controller .qty-plus:hover {
    background: #e5e5e5;
    border-color: #bbb;
}

.qty-controller .qty-input {
    width: 40px;
    height: 20px;
    border: none;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    padding: 0;
    background: transparent;
    -moz-appearance: textfield;
}

.qty-controller .qty-input::-webkit-outer-spin-button,
.qty-controller .qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.qty-controller .qty-input:focus {
    outline: none;
}

.add-to-cart-btn img {
    width: 100%;
    height: 100%;
    max-width: none;
    display: block;
}

/* Responsive */
@media (max-width: 1200px) {
    .level3-categories-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile Filter Toggle Button */
.mobile-filter-toggle {
    display: none;
    position: fixed;
    top: calc(100vh - 70px);
    right: 20px;
    background: var(--category-color, #d4821f);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 999;
    cursor: pointer;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mobile-filter-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.mobile-filter-toggle svg {
    width: 20px;
    height: 20px;
}

/* Mobile Filter Close Button */
.mobile-filter-close {
    display: none;
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: #666;
    transition: color 0.2s ease;
}

.mobile-filter-close:hover {
    color: #333;
}

/* Mobile Filter Overlay */
.mobile-filter-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-filter-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 770px) {
    .dynamic-subfamily-banner {
        flex-direction: column;
        padding: 16px 24px;
    }

    .dynamic-subfamily-banner-image {
        height: 90px;
    }

    .dynamic-subfamily-banner-title {
        font-size: 20px;
    }

    .level2-products-wrapper {
        flex-direction: column;
        padding-left: 10px;
    }

    /* Show mobile filter button */
    .mobile-filter-toggle {
        display: inline-flex;
    }

    /* Show mobile close button */
    .mobile-filter-close {
        display: block;
    }

    /* Show mobile overlay */
    .mobile-filter-overlay {
        display: block;
    }

    /* Transform sidebar into slide-in drawer */
    .products-filters-sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 999;
        background: white;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
        transition: left 0.3s ease;
    }

    .products-filters-sidebar.active {
        left: 0;
    }

    .filters-inner {
        position: relative;
        height: 100vh;
        display: flex;
        flex-direction: column;
        border: none;
        border-radius: 0;
        padding: 60px 20px 20px 20px;
        overflow: hidden;
    }

    .filters-header {
        flex-shrink: 0;
    }

    .filters-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        flex-direction: column;
        min-height: 0;
    }

    .category-card-header {
        flex-direction: column;
        text-align: center;
    }

    .products-table {
        font-size: 12px;
    }

    .products-table th,
    .products-table td {
        padding: 8px 10px;
    }

    .col-sku {
        width: 70px;
    }

    .col-subcategory {
        width: 80px;
    }

    .col-stock {
        width: 50px;
    }

    .col-price {
        width: 55px;
    }
}

@media (max-width: 480px) {
    /* Compact banner */
    .dynamic-subfamily-banner {
        padding: 12px 16px;
        gap: 12px;
    }

    .dynamic-subfamily-banner-image {
        height: 70px !important;
    }

    .dynamic-subfamily-banner-title {
        font-size: 17px;
    }

    /* Compact grid spacing */
    .level3-categories-grid {
        gap: 15px;
        margin-bottom: 20px;
    }

    /* === Collapsible cards === */
    .category-product-card .products-table-wrapper {
        display: none;
    }

    .category-product-card.expanded .products-table-wrapper {
        display: block;
    }

    /* Horizontal card header (override 770px vertical) */
    .category-card-header {
        flex-direction: row;
        text-align: left;
        padding: 10px 12px;
        gap: 10px;
        cursor: pointer;
        position: relative;
        padding-right: 36px;
    }

    .category-card-header .add-to-favorites {
        display: none;
    }

    .category-card-image {
        width: 50px;
        height: 50px;
    }

    .category-card-info {
        min-width: 0;
    }

    .category-label {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .category-card-title {
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Chevron indicator */
    .category-card-header::after {
        content: '';
        position: absolute;
        right: 14px;
        top: 50%;
        width: 8px;
        height: 8px;
        border-right: 2px solid #999;
        border-bottom: 2px solid #999;
        transform: translateY(-60%) rotate(45deg);
        transition: transform 0.2s ease;
        z-index: 1;
    }

    .category-product-card.expanded .category-card-header::after {
        transform: translateY(-40%) rotate(-135deg);
    }

    /* === Transform table into product cards === */
    .products-table-wrapper {
        overflow-x: visible;
    }

    .products-table thead {
        display: none;
    }

    .products-table,
    .products-table tbody {
        display: block;
    }

    .products-table tbody tr {
        display: grid;
        grid-template-columns: auto 1fr auto auto;
        grid-template-areas:
            "sku desc desc desc"
            "subcat stock price actions";
        gap: 2px 8px;
        padding: 8px 10px;
        align-items: center;
    }

    .products-table td {
        padding: 0;
        font-size: 13px;
    }

    .products-table td.col-sku {
        grid-area: sku;
        width: auto;
    }

    .products-table td.col-description {
        grid-area: desc;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .products-table td.col-subcategory {
        grid-area: subcat;
        width: auto;
        font-size: 12px;
        color: #888;
    }

    .products-table td.col-stock {
        grid-area: stock;
        width: auto;
        font-size: 12px;
        color: #888;
    }

    .products-table td.col-price {
        grid-area: price;
        width: auto;
        text-align: right;
    }

    .products-table td.col-actions {
        grid-area: actions;
        width: auto;
    }
}
