/* ==========================================================================
   MT Academy Advanced Grid & Carousel CSS
   Includes: AJAX Tabs, CSS Grid, Swiper Overlays, Skeleton Loading (YouTube Style), 
   Dominant Color Hover, and Mobile Bottom Sheets.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. General Wrappers & Headers
   -------------------------------------------------------------------------- */
.mta-advanced-grid-wrapper {
    position: relative;
    width: 100%;
    display: block;
    font-family: inherit;
    direction: rtl;
}

.mta-grid-header {
    display: flex;
    flex-direction: column;
}

.mta-grid-title {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: var(--ap-text, #1e293b);
}

.mta-grid-subtitle {
    margin: 0;
    line-height: 1.6;
}

/* --------------------------------------------------------------------------
   2. AJAX Tabs (Horizontal Scrollable)
   -------------------------------------------------------------------------- */
.mta-ajax-tabs {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
    white-space: nowrap;
    scroll-behavior: smooth;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.mta-ajax-tabs::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.mta-tab-btn {
    appearance: none;
    outline: none;
    background: var(--ap-hover, #f1f5f9);
    border: 1px solid transparent;
    color: var(--ap-text-muted, #64748b);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    flex-shrink: 0;
}

.mta-tab-btn:hover {
    background: var(--ap-border, #e2e8f0);
    color: var(--ap-text, #1e293b);
}

.mta-tab-btn.active {
    background: var(--ap-text, #1e293b);
    color: var(--ap-bg, #ffffff);
}

.mta-dark-theme .mta-tab-btn.active {
    background: #ffffff;
    color: #0f172a;
}

/* --------------------------------------------------------------------------
   3. Grid Layout System (Fixed CSS Grid)
   -------------------------------------------------------------------------- */
.mta-css-grid .mta-grid-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
}

.mta-css-grid .mta-grid-item {
    flex: 1 1 calc((100% / var(--grid-cols-desk, 4)) - (20px * (var(--grid-cols-desk, 4) - 1) / var(--grid-cols-desk, 4)));
    max-width: calc((100% / var(--grid-cols-desk, 4)) - (20px * (var(--grid-cols-desk, 4) - 1) / var(--grid-cols-desk, 4)));
    box-sizing: border-box;
}

@media (max-width: 1024px) {
    .mta-css-grid .mta-grid-item {
        flex: 1 1 calc((100% / var(--grid-cols-tab, 2)) - (20px * (var(--grid-cols-tab, 2) - 1) / var(--grid-cols-tab, 2)));
        max-width: calc((100% / var(--grid-cols-tab, 2)) - (20px * (var(--grid-cols-tab, 2) - 1) / var(--grid-cols-tab, 2)));
    }
}

@media (max-width: 767px) {
    .mta-css-grid .mta-grid-item {
        flex: 1 1 100%;
        max-width: 100%;
    }
}

/* Swiper Overrides */
.mta-swiper {
    position: relative;
    padding-bottom: 20px; /* Safe area for shadows and hover glow */
    width: 100%;
    overflow: hidden;
}

.mta-swiper .swiper-wrapper {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
}

.mta-swiper-next, .mta-swiper-prev {
    width: 40px !important;
    height: 40px !important;
    background-color: var(--ap-surface, #ffffff) !important;
    border: 1px solid var(--ap-border, #e2e8f0) !important;
    border-radius: 50% !important;
    color: var(--ap-text, #1e293b) !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08) !important;
    transition: all 0.3s ease !important;
}

.mta-swiper-next::after, .mta-swiper-prev::after {
    display: none !important;
}

.mta-swiper-next svg, .mta-swiper-prev svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.mta-swiper-next:hover, .mta-swiper-prev:hover {
    background-color: var(--ap-hover, #f1f5f9) !important;
    transform: scale(1.05) translateY(-50%) !important;
}

.mta-swiper-next.swiper-button-disabled, .mta-swiper-prev.swiper-button-disabled {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* --------------------------------------------------------------------------
   4. Base Card Styles & Dominant Color Hover (YouTube Style)
   -------------------------------------------------------------------------- */
.ap-card {
    display: flex;
    flex-direction: column;
    text-decoration: none !important;
    color: inherit;
    border-radius: 12px;
    padding: 10px;
    margin: -10px; /* Offset for padding */
    background-color: transparent;
    transition: background-color 0.4s ease, transform 0.4s ease, box-shadow 0.4s ease, border-radius 0.4s ease;
    will-change: transform, background-color, box-shadow;
    width: 100%;
}

.ap-card:hover {
    text-decoration: none !important;
    color: inherit;
}

.ap-card-title a {
    text-decoration: none !important;
    transition: color 0.2s ease !important;
}

/* Magic class added by JS once dominant color is extracted */
.ap-card.is-hovered-colored {
    background-color: var(--hover-bg-color, rgba(0,0,0,0.03));
    border-radius: 16px;
    transform: translateY(-2px);
    /* Box shadow uses the glowing color extracted from image */
    box-shadow: 0 10px 30px var(--hover-glow-color, rgba(0,0,0,0.05));
}

.mta-dark-theme .ap-card.is-hovered-colored {
    background-color: var(--hover-bg-color, rgba(255,255,255,0.05));
    box-shadow: 0 10px 30px var(--hover-glow-color, rgba(0,0,0,0.3));
}

.ap-card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 8px;
    overflow: hidden;
    background: var(--ap-hover, #f1f5f9);
    z-index: 1;
}

.ap-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    transform-origin: center center;
}

.ap-card.is-hovered-colored .ap-card-thumb img {
    transform: scale(1.05); /* Smooth zoom on hover */
}

.ap-badge-time {
    position: absolute;
    bottom: 6px;
    left: 6px;
    background: rgba(0,0,0,0.85);
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 3px 6px;
    border-radius: 4px;
    z-index: 10;
    line-height: 1;
    backdrop-filter: blur(4px);
}

.ap-card-info {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-top: 12px;
}

.ap-card-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--ap-border, #e2e8f0);
}

.ap-card-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ap-card-title {
    margin: 0;
}

.ap-card-title span {
    font-size: 14px;
    font-weight: bold;
    color: var(--ap-text, #1e293b);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.6;
}

.ap-card-channel span,
.ap-card-stats span,
.ap-card-stats time {
    font-size: 12px;
    color: var(--ap-text-muted, #64748b);
}

.ap-card-stats {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ap-dot {
    width: 3px;
    height: 3px;
    background: var(--ap-text-muted, #94a3b8);
    border-radius: 50%;
    display: inline-block;
}

/* --------------------------------------------------------------------------
   5. YouTube-Style Skeleton Loading (3 Shades of Gray)
   -------------------------------------------------------------------------- */
@keyframes mtaShimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}

.shimmer {
    background: #e5e5e5;
    /* Three shades of gray for exactly YouTube's effect */
    background-image: linear-gradient(to right, #e5e5e5 8%, #f0f0f0 18%, #e5e5e5 33%);
    background-size: 800px 100%;
    animation: mtaShimmer 1.5s infinite linear forwards;
}

.mta-dark-theme .shimmer {
    background: #272727;
    background-image: linear-gradient(to right, #272727 8%, #3f3f3f 18%, #272727 33%);
}

.mta-skeleton-wrapper {
    display: flex; 
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
    background: transparent !important;
}

.swiper-container .mta-skeleton-wrapper {
    flex-wrap: nowrap;
    gap: 0;
}

.mta-skeleton-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    
    flex: 1 1 calc((100% / var(--grid-cols-desk, 4)) - (20px * (var(--grid-cols-desk, 4) - 1) / var(--grid-cols-desk, 4)));
    max-width: calc((100% / var(--grid-cols-desk, 4)) - (20px * (var(--grid-cols-desk, 4) - 1) / var(--grid-cols-desk, 4)));
    box-sizing: border-box;
}

@media (max-width: 1024px) {
    .mta-skeleton-card {
        flex: 1 1 calc((100% / var(--grid-cols-tab, 2)) - (20px * (var(--grid-cols-tab, 2) - 1) / var(--grid-cols-tab, 2)));
        max-width: calc((100% / var(--grid-cols-tab, 2)) - (20px * (var(--grid-cols-tab, 2) - 1) / var(--grid-cols-tab, 2)));
    }
}

@media (max-width: 767px) {
    .mta-skeleton-card {
        flex: 1 1 100%;
        max-width: 100%;
    }
}

.swiper-container .mta-skeleton-card {
    padding: 0 10px; /* Swiper gap equivalent */
    flex: 1 0 auto; 
}

.mta-sk-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 8px;
}

.mta-sk-content {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.mta-sk-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.mta-sk-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 4px;
}

.mta-sk-line {
    height: 14px;
    border-radius: 4px;
}