/* Fancy Media Gallery Styles */
.fancy-media-gallery {
    margin: 20px 0;
}

/* Tabs Styles */
.fmg-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.fmg-tab {
    background: none;
    border: none;
    padding: 12px 24px;
    margin-right: 2px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    color: #666;
    background-color: #ebebeb;
    border-radius: 8px 8px 0 0;
    transition: all 0.3s ease;
    position: relative;
}

.fmg-tab:hover {
    background-color: #e8e8e8;
    color: #333;
}

.fmg-tab.active {
    background-color: #ff7a00;
    color: white;
    border-bottom: 2px solid #ff7a00;
}

.fmg-tab.active:hover {
    background-color: #e66a00;
}

/* Tab Content */
.fmg-tab-content {
    display: none;
}

.fmg-tab-content.active {
    display: block;
}

/* Grid Layout - Only apply to videos grid */
.fmg-videos-grid {
    display: grid;
    gap: 20px;
    margin: 0;
    padding: 0;
}

/* Images use WordPress native gallery - no custom grid styles */
.fmg-images-grid {
    /* Let WordPress gallery shortcode handle the layout */
}

/* Desktop: 3 columns for videos only */
.fmg-videos-grid {
    grid-template-columns: repeat(3, 1fr); /* Desktop: 3 cột video */
}

/* Grid Items - Only apply to video items */
.fmg-videos-grid .fmg-item {
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: #f5f5f5;
}

.fmg-videos-grid .fmg-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.fmg-videos-grid .fmg-item a {
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
}

.fmg-videos-grid .fmg-item img,
.fmg-videos-grid .fmg-item picture,
.fmg-videos-grid .fmg-item picture img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.fmg-videos-grid .fmg-item picture {
    height: 200px;
    overflow: hidden;
}

.fmg-videos-grid .fmg-item:hover img {
    transform: scale(1.05);
}

/* Video specific styles */
.fmg-video-item .fmg-play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.fmg-video-item:hover .fmg-play-overlay {
    opacity: 1;
}

.fmg-play-icon {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #333;
    transition: transform 0.3s ease;
}

.fmg-video-item:hover .fmg-play-icon {
    transform: scale(1.1);
}

/* Video format indicator */
.fmg-video-format {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
}

/* Mobile compatibility notice */
.fmg-mobile-notice {
    margin-top: 15px;
    padding: 10px 15px;
    background: #f8f9fa;
    border-left: 4px solid #17a2b8;
    border-radius: 4px;
    font-size: 13px;
    color: #666;
}

/* FIXED: Mobile video overlay - Play icon chỉ hiển thị khi touch/hover */
@media (max-width: 768px) {
    .fmg-mobile-notice {
        display: block !important;
    }
    
    /* Reset overlay cho mobile - Ẩn mặc định */
    .fmg-video-item .fmg-play-overlay {
        background: rgba(0, 0, 0, 0.4); /* Background khi hiển thị */
        opacity: 0; /* Ẩn mặc định */
        align-items: center; /* Căn giữa theo chiều dọc */
        justify-content: center; /* Căn giữa theo chiều ngang */
        transition: opacity 0.3s ease; /* Smooth transition */
    }
    
    /* Hiển thị khi touch/active trên mobile */
    .fmg-video-item:hover .fmg-play-overlay,
    .fmg-video-item:active .fmg-play-overlay,
    .fmg-video-item:focus .fmg-play-overlay {
        opacity: 1;
    }
    
    .fmg-play-icon {
        width: 50px; /* Kích thước vừa phải */
        height: 50px;
        font-size: 18px;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); /* Thêm shadow để nổi bật */
    }
    
    .fmg-video-format {
        font-size: 9px;
        padding: 1px 4px;
    }
}

/* Image specific styles */
.fmg-image-item {
    cursor: pointer;
}

.fmg-image-item::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s ease;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0 0 24 24"><path d="M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.1 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z"/></svg>');
    background-size: 12px;
    background-repeat: no-repeat;
    background-position: center;
}

.fmg-image-item:hover::after {
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 768px) {
    .fmg-videos-grid {
        gap: 15px;
        /* Mobile/Tablet: 2 columns for videos */
        grid-template-columns: repeat(2, 1fr);
    }
    
    .fmg-videos-grid .fmg-item img,
    .fmg-videos-grid .fmg-item picture,
    .fmg-videos-grid .fmg-item picture img {
        height: 150px;
    }
    
    .fmg-tab {
        padding: 10px 16px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .fmg-videos-grid {
        gap: 10px;
        /* Small mobile: Keep 2 columns for videos */
        grid-template-columns: repeat(2, 1fr);
    }
    
    .fmg-videos-grid .fmg-item img,
    .fmg-videos-grid .fmg-item picture,
    .fmg-videos-grid .fmg-item picture img {
        height: 120px;
    }
    
    .fmg-tabs {
        margin-bottom: 15px;
    }
    
    .fmg-tab {
        padding: 8px 12px;
        font-size: 13px;
        flex: 1;
        text-align: center;
        margin-right: 1px;
    }
    
    /* Mobile - Play icon còn nhỏ hơn nữa */
    .fmg-play-icon {
        width: 35px !important;
        height: 35px !important;
        font-size: 14px !important;
    }
}

/* Fancybox Video Customizations - Override default sizing */
.fancybox-content {
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.fancybox-slide--video .fancybox-content {
    background: #000;
}

/* Fix video iframe sizing issues */
.fancybox-slide--iframe .fancybox-content {
    padding: 0 !important;
    margin: 0 !important;
    background: #000;
}

.fancybox-slide--iframe iframe {
    background: #000;
    border: none !important;
    border-radius: 0 !important;
}

/* Override default 80% sizing for better fit */
.fancybox-slide--iframe .fancybox-content {
    width: auto !important;
    height: auto !important;
    max-width: 90vw !important;
    max-height: 90vh !important;
}

/* Ensure video maintains aspect ratio */
.fancybox-slide--iframe iframe {
    width: 80vw !important;
    height: 45vw !important; /* 16:9 aspect ratio */
    max-width: 1200px !important;
    max-height: 675px !important; /* 1200px * 9/16 */
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .fancybox-slide--iframe iframe {
        width: 95vw !important;
        height: 53.4375vw !important; /* 16:9 aspect ratio */
        max-width: none !important;
        max-height: 90vh !important;
    }
    
    .fancybox-slide--iframe .fancybox-content {
        max-width: 95vw !important;
        max-height: 90vh !important;
    }
}

/* Portrait mobile optimization */
@media (max-width: 480px) and (orientation: portrait) {
    .fancybox-slide--iframe iframe {
        width: 100vw !important;
        height: 56.25vw !important; /* 16:9 aspect ratio */
        max-height: 70vh !important;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .fancybox-slide--iframe iframe {
        width: 90vh * 16/9 !important; /* Fit by height in landscape */
        height: 90vh !important;
        max-width: 95vw !important;
    }
}

/* Remove any unwanted spacing */
.fancybox-stage {
    padding: 0 !important;
}

.fancybox-slide {
    padding: 20px !important;
}

@media (max-width: 768px) {
    .fancybox-slide {
        padding: 10px !important;
    }
}

/* Mobile video error handling */
.fancybox-slide--iframe .fancybox-content iframe {
    /* Improve video loading on mobile */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Alternative video display for mobile compatibility */
@media (max-width: 768px) {
    .fmg-video-item a {
        position: relative;
    }
    
    .fmg-video-item a::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.1);
        pointer-events: none;
    }
}

/* Fallback video player styles */
.fancybox-slide--html5video video {
    width: 100% !important;
    height: auto !important;
    max-width: 90vw;
    max-height: 90vh;
    background: #000;
}

/* Error state styling */
.fancybox-error {
    background: #000 !important;
    color: #fff;
    text-align: center;
    padding: 40px 20px;
}

.fancybox-error::before {
    content: "⚠️ Video không thể phát trên thiết bị này";
    display: block;
    font-size: 16px;
    margin-bottom: 10px;
}

.fancybox-error::after {
    content: "Vui lòng thử mở video trong trình duyệt khác hoặc tải ứng dụng video";
    display: block;
    font-size: 14px;
    opacity: 0.8;
}

/* Fix aspect ratio issues */
.fancybox-slide--iframe .fancybox-content iframe {
    aspect-ratio: 16/9;
    max-width: 90vw;
    max-height: 90vh;
}

/* Mobile video optimization */
@media (max-width: 768px) {
    .fancybox-slide--video {
        padding: 10px;
    }
    
    .fancybox-slide--iframe .fancybox-content iframe {
        width: 100vw !important;
        height: 56.25vw !important; /* 16:9 aspect ratio */
        max-height: 90vh;
    }
    
    .fancybox-slide--video .fancybox-content {
        width: 100% !important;
        height: auto !important;
    }
}

/* Loading indicator for videos */
.fmg-loading .fancybox-content::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1000;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Loading states */
.fmg-item img[src=""] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Tab transition animations */
.fmg-tab-content {
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Active tab indicator */
.fmg-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background-color: #ff7a00;
}

/* Empty state */
.fmg-grid:empty::after {
    content: 'Không có nội dung để hiển thị';
    display: block;
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 40px;
}

/***** Thêm CSS cho count trong tabs - thêm vào file style.css ******/

/* Styling cho count number */
.fmg-count {
    font-size: 0.85em; /* Nhỏ hơn text chính */
    opacity: 0.8; /* Mờ hơn một chút */
    font-weight: normal; /* Không đậm như text chính */
    margin-left: 4px; /* Khoảng cách với text chính */
    color: inherit; /* Kế thừa màu từ parent */
}

/* Count khi tab active */
.fmg-tab.active .fmg-count {
    opacity: 0.9; /* Đậm hơn khi active */
    color: rgba(255, 255, 255, 0.9); /* Trắng mờ khi active */
}

/* Count khi hover */
.fmg-tab:hover .fmg-count {
    opacity: 1;
}

/* Responsive - nhỏ hơn trên mobile */
@media (max-width: 768px) {
    .fmg-count {
        font-size: 0.8em;
        margin-left: 2px;
    }
}

@media (max-width: 480px) {
    .fmg-count {
        font-size: 0.75em;
        margin-left: 1px;
    }
    
    /* Có thể ẩn count trên mobile rất nhỏ nếu cần */
    /* .fmg-count { display: none; } */
}

/* Tùy chọn: Style đẹp hơn cho count */
.fmg-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 1px 4px;
    border-radius: 10px;
    font-size: 0.8em;
    margin-left: 6px;
    display: inline-block;
    min-width: 18px;
    text-align: center;
}

.fmg-tab.active .fmg-count {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

/* Hoặc style badge đẹp */
.fmg-count {
    background: #666;
    color: white;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.75em;
    margin-left: 8px;
    font-weight: 500;
    line-height: 1;
    vertical-align: middle;
}

.fmg-tab.active .fmg-count {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.fmg-tab:hover .fmg-count {
    background: #555;
}

.fmg-tab.active:hover .fmg-count {
    background: rgba(255, 255, 255, 0.4);
}