/* Full CSS for category catalog */

/* Styles for catalog section */
.catalog-section {
    text-align: center;
    padding: 20px 0;
}

.catalog-section h2 {
    font-size: 26px;
    color: #2a7a9e;
    margin: 20px 0;
    padding: 0 15px;
}

/* Container - remove extra padding */
.container {
    padding: 0 10px;
}

/* Grid for categories */
.category-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns on mobile */
    gap: 12px;
    padding: 0 12px;
    max-width: 100%;
    margin: 0 auto 30px;
}

/* Styles for category cards */
.category-card {
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-bottom: 0; /* Remove random margins */
}

.category-card a {
    text-decoration: none;
    color: #2a7a9e;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.category-card img {
    width: 100%;
    height: 140px;
    object-fit: contain;
    padding: 10px;
    background-color: white;
}

.category-card .card-title {
    text-align: center;
    padding: 10px 8px;
    color: #2a7a9e;
    font-weight: bold;
    font-size: 15px;
    line-height: 1.3;
    border-top: 1px solid #eee;
    margin: 0;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50px; /* Minimum height for title */
}

/* Prevent card overlapping */
.category-card * {
    margin: 0;
    box-sizing: border-box;
}

/* Styles for regular product cards */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns on mobile */
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

.catalog-item {
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    text-align: center;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: auto;
    max-width: 100%;
    position: relative;
    overflow: hidden;
}

.catalog-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.catalog-item img {
    max-width: 100%;
    height: auto;
    max-height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
}

.catalog-item a {
    text-decoration: none;
    color: #2a7a9e;
    font-weight: bold;
    font-size: 14px;
    margin-top: auto;
    display: block;
    padding: 5px 0;
    line-height: 1.3;
    word-break: break-word;
}

.catalog-item span.item-name {
    width: 100%;
    text-align: center;
    margin-top: auto;
}

/* Responsive styles for different screen sizes */
@media (min-width: 576px) {
    .catalog-grid,
    .category-grid {
        gap: 15px;
    }
    
    .catalog-item img {
        height: 110px;
    }
    
    .catalog-item a {
        font-size: 15px;
    }
}

@media (min-width: 768px) {
    .category-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 columns on tablets */
        padding: 0 15px;
    }
    
    .catalog-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .category-card .card-title {
        font-size: 16px;
    }
    
    .catalog-section h2 {
        font-size: 24px;
    }
}

/* Desktop alignment fixes for catalog items */
@media (min-width: 992px) {
    /* Fix the grid layout */
    .catalog-grid {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 20px;
    }

    /* Make all items same height with fixed structure */
    .catalog-item {
        height: 220px;
        display: flex;
        flex-direction: column;
        padding: 15px;
    }

        /* Make all links fill the container */
        .catalog-item a {
            display: flex;
            flex-direction: column;
            height: 100%;
            width: 100%;
        }

        /* Fix image alignment to top */
        .catalog-item img {
            height: 125px;
            object-fit: contain;
            margin-bottom: 15px;
        }

        /* Fix text alignment to bottom with proper wrapping */
        .catalog-item .item-name,
        .catalog-item span {
            margin-top: auto;
            text-align: center;
            word-wrap: break-word;
            overflow-wrap: break-word;
            hyphens: auto;
            font-size: 15px;
            line-height: 1.3;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
}

@media (max-width: 480px) {
    .category-grid,
    .catalog-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .catalog-item {
        padding: 5px;
        height: 120px; /* Reduced height */
        display: flex;
        flex-direction: column;
        justify-content: flex-start; /* Align from top */
        align-items: center;
    }
    
    .catalog-item a {
        font-size: 10px;
        line-height: 1.2;
        padding: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: 100%;
        height: 100%; /* Take full height */
    }
    
    .catalog-item img {
        width: auto;
        height: 60px;
        max-width: 95%;
        margin: 0 0 5px 0; /* No top margin */
        object-fit: contain;
    }
    
    .catalog-item span.item-name {
        margin-top: 5px;
        font-size: 10px;
    }
    
    .category-card .card-title {
        font-size: 12px;
        padding: 5px;
        min-height: 40px;
    }
    
    .catalog-section h2 {
        font-size: 20px;
        margin-bottom: 15px;
    }
}

/* New styles for categories layout */
.categories-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Animation for category rows */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-row {
    display: flex;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s ease;
    animation: fadeInUp 0.6s ease-out;
    animation-fill-mode: both;
}

/* Stagger animation for each row */
.category-row:nth-child(1) { animation-delay: 0.1s; }
.category-row:nth-child(2) { animation-delay: 0.2s; }
.category-row:nth-child(3) { animation-delay: 0.3s; }
.category-row:nth-child(4) { animation-delay: 0.4s; }
.category-row:nth-child(5) { animation-delay: 0.5s; }
.category-row:nth-child(6) { animation-delay: 0.6s; }
.category-row:nth-child(7) { animation-delay: 0.7s; }
.category-row:nth-child(8) { animation-delay: 0.8s; }
.category-row:nth-child(9) { animation-delay: 0.9s; }
.category-row:nth-child(10) { animation-delay: 1.0s; }

.category-row:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Main category styles */
.main-category {
    width: 220px;
    background: #f9fafb;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-right: none;
    position: relative;
}

.main-category .category-image {
    display: block;
    width: 120px;
    height: 120px;
    margin-bottom: 15px;
    transition: transform 0.3s ease;
}

.main-category .category-image:hover {
    transform: scale(1.05);
}

.main-category .category-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    border-radius: 10px;
    padding: 10px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s ease;
}

.main-category .category-image:hover img {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.main-category::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(to bottom, transparent, #e0e0e0 20%, #e0e0e0 80%, transparent);
}

.main-category h3 {
    margin: 0 0 20px 0;
    font-size: 18px;
    font-weight: 600;
}

.main-category h3 a {
    color: #333;
    text-decoration: none;
    transition: color 0.3s ease;
    display: block;
    padding: 5px 0;
}

.main-category h3 a:hover {
    color: #2a7a9e;
}

.main-category .source-now {
    background: #ff5c39;
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-block;
}

.main-category .source-now:hover {
    background: #e54a2f;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 92, 57, 0.3);
}

/* Subcategories grid */
.subcategories {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0;
    padding: 0;
    border-left: 1px solid #eee;
}

.subcat-item {
    position: relative;
    border-right: 1px solid #eee;
    border-bottom: 1px solid #eee;
}

/* Remove borders for edge items */
.subcat-item:nth-child(4n) {
    border-right: none;
}

.subcat-item:nth-child(n+5) {
    border-bottom: none;
}

/* Ensure last row items don't have bottom border */
.subcat-item:last-child,
.subcat-item:nth-last-child(2):nth-child(4n-1),
.subcat-item:nth-last-child(3):nth-child(4n-2),
.subcat-item:nth-last-child(4):nth-child(4n-3) {
    border-bottom: none;
}

.subcat-item a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    min-height: 160px;
    padding: 15px 10px;
    text-decoration: none;
    color: #333;
    transition: background-color 0.2s ease;
    overflow: hidden;
}

.subcat-item a:hover {
    background-color: #f7f9fa;
    box-shadow: 0 0 0 1px rgba(42, 122, 158, 0.1) inset;
}

.subcat-item img {
    width: 90px;
    height: 90px;
    object-fit: contain;
    margin-bottom: 10px;
    transition: transform 0.2s ease;

}

.subcat-item a:hover img {
    transform: scale(1.05);
}

.subcat-item span {
    display: block;
    font-size: 13px;
    line-height: 1.3;
    color: #333;
    font-weight: 500;
    margin-bottom: 3px;
    word-wrap: break-word;
    max-width: 100%;
}

.subcat-item a:hover span {
    color: #2a7a9e;
}

.subcat-item .item-count {
    font-size: 10px;
    color: #aaa;
    display: block;
    font-weight: normal;
    margin-top: 2px;
}

.subcat-item a:hover .item-count {
    color: #888;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .category-row {
        flex-direction: column;
    }
    
    .main-category {
        width: 100%;
        padding: 20px;
        border-right: none;
        border-bottom: none;
    }
    
    .main-category .category-image {
        width: 100px;
        height: 100px;
    }
    
    .subcategories {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
    }
    
    .subcat-item:nth-child(4n) {
        border-right: 1px solid #eee;
    }
    
    .subcat-item:nth-child(2n) {
        border-right: none;
    }
    
    .subcat-item a {
        min-height: 120px;
    }
    
    .subcat-item img {
        width: 70px;
        height: 70px;
        margin-bottom: 8px;
    }
    
    /* RTL adjustments for mobile */
    .rtl-content .subcat-item:nth-child(2n) {
        border-left: none;
        border-right: none;
    }
    
    .rtl-content .subcat-item:nth-child(2n-1) {
        border-left: 1px solid #eee;
    }
}

@media (max-width: 480px) {
    .main-category .category-image {
        width: 80px;
        height: 80px;
        margin-bottom: 10px;
    }
    
    .main-category .category-image img {
        padding: 8px;
    }
    
    .subcategories {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .subcat-item a {
        min-height: 100px;
        padding: 10px 8px;
    }
    
    .subcat-item img {
        width: 55px;
        height: 55px;
        margin-bottom: 6px;
    }
    
    .subcat-item span {
        font-size: 11px;
    }
    
    .main-category h3 {
        font-size: 16px;
        margin-bottom: 15px;
    }
    
    .main-category .source-now {
        padding: 6px 16px;
        font-size: 12px;
    }
}

/* RTL support for Arabic */
.rtl-content .category-row {
    direction: rtl;
}

.rtl-content .main-category {
    border-right: none;
    border-left: none;
}

.rtl-content .subcategories {
    direction: rtl;
    border-left: none;
    border-right: 1px solid #eee;
}

.rtl-content .subcat-item {
    border-right: none;
    border-left: 1px solid #eee;
}

.rtl-content .subcat-item:nth-child(4n) {
    border-left: none;
}

.rtl-content .subcat-item:nth-child(4n-3) {
    border-left: 1px solid #eee;
}

.rtl-content .subcat-item a {
    text-align: center;
}

/* Desktop styles for better presentation */
@media (min-width: 992px) {
    .categories-container {
        padding: 0 30px;
    }
    
    .category-row {
        margin-bottom: 25px;
    }
    
    .main-category {
        width: 250px;
        padding: 30px 25px;
    }
    
    .main-category .category-image {
        width: 140px;
        height: 140px;
        margin-bottom: 20px;
    }
    
    .main-category h3 {
        font-size: 20px;
        margin-bottom: 20px;
    }
    
    .main-category .source-now {
        padding: 10px 25px;
        font-size: 15px;
    }
    
    .subcategories {
        /* Keep grid without gap */
    }
    
    .subcat-item a {
        min-height: 150px;
        padding: 20px 15px;
    }
    
    .subcat-item img {
        width: 100px;
        height: 100px;
        margin-bottom: 12px;
    }
    
    .subcat-item span {
        font-size: 14px;
    }
}

/* Hide old catalog grid on pages with new category layout */
.categories-container + .catalog-grid {
    display: none;
}