/* CSS Variables */
.catalog-page {
    --primary: #ff7f50;
    --primary-light: rgba(255, 127, 80, 0.1);
    --border-radius: 8px;
    --transition: 0.3s ease;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.15);
}

/* RTL Support */
[dir="rtl"] .catalog-page {
    font-family: 'Cairo', 'Tajawal', 'Almarai', sans-serif;
}

[dir="rtl"] .filter-title,
[dir="rtl"] .filter-option,
[dir="rtl"] .active-filter,
[dir="rtl"] .card-overlay,
[dir="rtl"] .stat-item,
[dir="rtl"] .card-meta,
[dir="rtl"] .results-header .d-flex,
[dir="rtl"] .pagination {
    flex-direction: row-reverse;
}

[dir="rtl"] .tag-filters,
[dir="rtl"] .active-filters,
[dir="rtl"] .card-tags {
    justify-content: flex-end;
}

[dir="rtl"] .results-header,
[dir="rtl"] .card-content,
[dir="rtl"] .card-title,
[dir="rtl"] .card-description,
[dir="rtl"] .empty-state,
[dir="rtl"] .loading {
    text-align: right;
}

[dir="rtl"] .featured-badge {
    right: auto;
    left: 0.75rem;
}

[dir="rtl"] .filter-title i,
[dir="rtl"] .featured-badge i,
[dir="rtl"] .stat-item i {
    margin-left: 0.5rem;
    margin-right: 0;
}

/* Badge Styles - Circular Count Indicators */
.badge.bg-light.text-primary {
    background: rgba(255, 255, 255, 0.9) !important;
    color: var(--primary) !important;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0;
    border-radius: 50%;
    min-width: 1.5rem;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    text-align: center;
    vertical-align: middle;
}

/* Common Interactive Elements */
.btn-primary-custom {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary-custom:hover {
    background: #e55a2b;
    transform: translateY(-1px);
}

/* Hero & Search Section */
.hero {
    background: linear-gradient(135deg, var(--primary), #fdcb6e);
    padding: 4rem 0 2rem;
    color: white;
    text-align: center;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 700;
    margin-bottom: 1rem;
}

.hero p {
    font-size: 1.1rem;
    opacity: 0.9;
    max-width: 600px;
    margin: 0 auto 2rem;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.stat-item {
    background: rgba(255,255,255,0.2);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-section {
    margin: -2rem auto 3rem;
    max-width: 600px;
    padding: 0 1rem;
}

.search-box {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-hover);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    pointer-events: none;
}

.search-input {
    border: none;
    outline: none;
    padding: 0.75rem 1rem 0.75rem 3rem;
    font-size: 1rem;
    flex: 1;
    background: transparent;
}

.search-btn {
    padding: 0.75rem 1.5rem;
}

/* Layout & Filters */
.catalog-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

.catalog-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    align-items: start;
}

.filters {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.filter-group {
    margin-bottom: 1.5rem;
}

.filter-title {
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    padding: 0.25rem 0;
    transition: var(--transition);
}

.filter-option:hover {
    color: var(--primary);
}

/* Filter Tags & Pills */
.tag-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag-filter,
.active-filter {
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tag-filter {
    background: #f8f9fa;
    border: 2px solid transparent;
    padding: 0.4rem 0.8rem;
}

.tag-filter:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.tag-filter.active {
    background: var(--primary);
    color: white;
}

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.active-filter {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
}

.active-filter button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
}

/* Results Header & Grid */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.sort-select {
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    padding: 0.5rem;
    background: white;
    cursor: pointer;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Cards */
.catalog-card {
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition);
    cursor: pointer;
    animation: fadeInUp 0.3s ease-out;
}

.catalog-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.card-image {
    position: relative;
    aspect-ratio: 4/3;
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

.responsive-image {
    image-rendering: auto;
    image-rendering: crisp-edges;
    image-rendering: -webkit-optimize-contrast;
}

.catalog-card:hover .card-image img {
    transform: scale(1.05);
}

.image-link {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

.card-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    opacity: 0;
    transition: var(--transition);
}

.catalog-card:hover .card-overlay {
    opacity: 1;
}

/* Circular Action Buttons */
.overlay-btn,
.filters-close {
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.overlay-btn {
    color: var(--dark-color);
}

.overlay-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
    text-decoration: none;
}

.featured-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
    font-size: 0.75rem;
    font-weight: 600;
}

.card-content {
    padding: 1rem;
}

.card-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
    line-height: 1.3;
}

.card-description {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.card-tag {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #999;
}

/* Utility States & Animations */
.loading, 
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.empty-state i {
    font-size: 3rem;
    color: #ddd;
    margin-bottom: 1rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 2rem;
    padding: 1rem;
}

.page-btn {
    border: 1px solid #ddd;
    background: white;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

.page-btn:hover, 
.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Keyframe Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Lightbox2 Enhancements */
.lightbox {
    z-index: 9999 !important;
}

.lightbox .lb-image {
    border-radius: 12px;
    box-shadow: 0 25px 80px rgba(0,0,0,0.6);
    max-width: 90vw !important;
    max-height: 80vh !important;
    object-fit: contain;
}

.lightbox .lb-container {
    padding: 20px !important;
}

.lightbox .lb-outerContainer {
    background: rgba(0,0,0,0.95) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    box-shadow: 0 25px 80px rgba(0,0,0,0.8) !important;
}

.lightbox .lb-nav {
    opacity: 1 !important;
    height: 100% !important;
}

.lightbox .lb-nav a {
    background: rgba(255,255,255,0.15) !important;
    backdrop-filter: blur(20px);
    border-radius: 50% !important;
    width: 60px !important;
    height: 60px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.3s ease !important;
    border: 2px solid rgba(255,255,255,0.3) !important;
    outline: none !important;
    opacity: 0.8 !important;
    text-decoration: none !important;
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
    margin-top: 0 !important;
}

.lightbox .lb-nav a:hover {
    background: var(--primary) !important;
    transform: translateY(-50%) scale(1.1) !important;
    text-decoration: none !important;
    opacity: 1 !important;
    border-color: var(--primary) !important;
    box-shadow: 0 8px 25px rgba(255, 127, 80, 0.4) !important;
}

.lightbox .lb-nav a.lb-prev {
    left: 30px !important;
    right: auto !important;
}

.lightbox .lb-nav a.lb-next {
    right: 30px !important;
    left: auto !important;
}

/* Add arrow icons for navigation */
.lightbox .lb-nav a.lb-prev::before {
    content: "‹" !important;
    font-size: 28px !important;
    color: white !important;
    font-weight: 300 !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
}

.lightbox .lb-nav a.lb-next::before {
    content: "›" !important;
    font-size: 28px !important;
    color: white !important;
    font-weight: 300 !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
}

.lightbox .lb-close {
    background: rgba(255,255,255,0.15) !important;
    backdrop-filter: blur(20px);
    border-radius: 50% !important;
    width: 60px !important;
    height: 60px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.3s ease !important;
    right: 30px !important;
    top: 30px !important;
    border: 2px solid rgba(255,255,255,0.3) !important;
    outline: none !important;
    opacity: 0.8 !important;
    text-decoration: none !important;
}

/* Add close icon */
.lightbox .lb-close::before {
    content: "×" !important;
    font-size: 32px !important;
    color: white !important;
    font-weight: 300 !important;
    line-height: 1 !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.lightbox .lb-close:hover {
    background: #dc3545 !important;
    transform: scale(1.1) !important;
    text-decoration: none !important;
    opacity: 1 !important;
    border-color: #dc3545 !important;
    box-shadow: 0 8px 25px rgba(220, 53, 69, 0.4) !important;
}

.lightbox .lb-dataContainer {
    background: rgba(0,0,0,0.85) !important;
    backdrop-filter: blur(30px);
    border-radius: 0 0 12px 12px !important;
    margin: 0 auto !important;
    padding: 2rem 2.5rem !important;
    width: auto !important;
    max-width: 95% !important;
    border-top: 1px solid rgba(255,255,255,0.1) !important;
}

.lightbox .lb-data .lb-caption {
    font-size: 1.2rem !important;
    font-weight: 600 !important;
    color: white !important;
    margin-bottom: 0.8rem !important;
    line-height: 1.5 !important;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5) !important;
}

.lightbox .lb-data .lb-number {
    background: rgba(255,255,255,0.1) !important;
    color: rgba(255,255,255,0.9) !important;
    font-size: 0.9rem !important;
    padding: 0.5rem 1rem !important;
    border-radius: 20px !important;
    margin: 0 !important;
    display: inline-block !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
}

/* RTL Lightbox Adjustments */
[dir="rtl"] .lightbox .lb-nav a.lb-prev {
    left: auto !important;
    right: 30px !important;
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

[dir="rtl"] .lightbox .lb-nav a.lb-next {
    right: auto !important;
    left: 30px !important;
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

[dir="rtl"] .lightbox .lb-nav a.lb-prev:hover {
    transform: translateY(-50%) scale(1.1) !important;
}

[dir="rtl"] .lightbox .lb-nav a.lb-next:hover {
    transform: translateY(-50%) scale(1.1) !important;
}

/* Swap arrow directions for RTL */
[dir="rtl"] .lightbox .lb-nav a.lb-prev::before {
    content: "›" !important;
}

[dir="rtl"] .lightbox .lb-nav a.lb-next::before {
    content: "‹" !important;
}

[dir="rtl"] .lightbox .lb-close {
    right: auto !important;
    left: 30px !important;
}

[dir="rtl"] .lightbox .lb-data .lb-details {
    text-align: right !important;
}

[dir="rtl"] .lightbox .lb-data .lb-caption {
    font-family: 'Cairo', 'Tajawal', 'Almarai', sans-serif !important;
    text-align: right !important;
    line-height: 1.6 !important;
}

[dir="rtl"] .lightbox .lb-data .lb-number {
    text-align: right !important;
    font-family: 'Cairo', 'Tajawal', 'Almarai', sans-serif !important;
}

/* Lightbox Mobile Improvements */
@media (max-width: 768px) {
    .lightbox .lb-image {
        max-width: 95vw !important;
        max-height: 75vh !important;
    }
    
    .lightbox .lb-nav a {
        width: 50px !important;
        height: 50px !important;
    }
    
    .lightbox .lb-nav a.lb-prev {
        left: 15px !important;
    }
    
    .lightbox .lb-nav a.lb-next {
        right: 15px !important;
    }
    
    .lightbox .lb-close {
        width: 50px !important;
        height: 50px !important;
        right: 15px !important;
        top: 15px !important;
    }
    
    .lightbox .lb-dataContainer {
        padding: 1.5rem 1rem !important;
    }
    
    .lightbox .lb-data .lb-caption {
        font-size: 1rem !important;
    }
    
    [dir="rtl"] .lightbox .lb-nav a.lb-prev {
        right: 15px !important;
    }
    
    [dir="rtl"] .lightbox .lb-nav a.lb-next {
        left: 15px !important;
    }
    
    [dir="rtl"] .lightbox .lb-close {
        left: 15px !important;
    }
}

@media (max-width: 480px) {
    .lightbox .lb-image {
        max-width: 98vw !important;
        max-height: 70vh !important;
    }
    
    .lightbox .lb-nav a {
        width: 45px !important;
        height: 45px !important;
    }
    
    .lightbox .lb-nav a::before {
        font-size: 24px !important;
    }
    
    .lightbox .lb-close {
        width: 45px !important;
        height: 45px !important;
    }
    
    .lightbox .lb-close::before {
        font-size: 28px !important;
    }
    
    .lightbox .lb-dataContainer {
        padding: 1rem 0.75rem !important;
    }
    
    .lightbox .lb-data .lb-caption {
        font-size: 0.9rem !important;
    }
    
    .lightbox .lb-data .lb-number {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
    }
}

/* Mobile Responsive Design (992px and below) */
@media (max-width: 992px) {
    .catalog-layout {
        grid-template-columns: 1fr;
    }
    
    .filters {
        position: fixed !important;
        top: 0 !important;
        left: -320px;
        width: 320px;
        height: 100vh;
        background: white;
        z-index: 10050;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding: 1rem;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        max-height: none !important;
    }
    
    .filters.show {
        left: 0 !important;
    }
    
    .filters-backdrop {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(0,0,0,0.5) !important;
        z-index: 10040 !important;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .filters-backdrop.show {
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* Filter Buttons */
    .hero-filter-btn {
        background: rgba(255, 255, 255, 0.15) !important;
        backdrop-filter: blur(10px);
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
        color: white !important;
        font-weight: 600;
        font-size: 1rem;
        padding: 1rem 1.5rem;
        border-radius: 50px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        margin-bottom: 0 !important;
        min-width: 160px;
    }
    
    .hero-filter-btn:hover {
        background: rgba(255, 255, 255, 0.25) !important;
        transform: translateY(-2px);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 255, 255, 0.5) !important;
    }
    
    .hero-filter-btn .badge {
        background: rgba(255, 255, 255, 0.9) !important;
        color: var(--primary) !important;
        font-size: 0.75rem;
        font-weight: 700;
        padding: 0;
        border-radius: 50%;
        min-width: 1.5rem;
        width: 1.5rem;
        height: 1.5rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        line-height: 1;
        animation: pulse 2s infinite;
    }

    /* Mobile Filter Header */
    .filters-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid #eee;
    }

    /* Mobile Layout Adjustments */
    .hero {
        padding: 2rem 0 1rem;
    }
    
    .stats {
        gap: 1rem;
    }
    
    body.filters-open {
        overflow: hidden;
    }
}

/* Desktop Hide Mobile Elements */
@media (min-width: 993px) {
    .filters-toggle,
    .hero-filter-btn,
    .filters-backdrop,
    .filters-header {
        display: none;
    }
}

/* Tablet Adjustments (768px and below) */
@media (max-width: 768px) {
    .catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    .results-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .search-section {
        margin: -1rem auto 2rem;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
}

/* Mobile Adjustments (576px and below) */
@media (max-width: 576px) {
    .catalog-grid {
        grid-template-columns: 1fr;
    }
    
    .search-box {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .search-input, 
    .search-btn {
        width: 100%;
    }
    
    .catalog-container {
        padding: 0 0.5rem;
    }
    
    /* Ensure sidebar is completely hidden on very small screens */
    .filters {
        left: -100vw !important;
        width: 90vw;
        max-width: 300px;
    }
    
    /* Badge refinements for very small screens */
    .hero-filter-btn .badge,
    .badge.bg-light.text-primary {
        min-width: 1.25rem;
        width: 1.25rem;
        height: 1.25rem;
        font-size: 0.7rem;
        padding: 0;
        flex-shrink: 0;
    }
    
    .hero-filter-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
}

/* RTL Specific Adjustments */
[dir="rtl"] .filters {
    left: auto;
    right: -320px;
    transition: right 0.3s ease;
}

[dir="rtl"] .filters.show {
    right: 0 !important;
}

@media (max-width: 576px) {
    [dir="rtl"] .filters {
        right: -100vw !important;
        left: auto;
    }
    
    [dir="rtl"] .search-input {
        text-align: center;
    }
}