/*
 * Homestay Rooms Gallery + Tabs Lightbox - CSS
 * Version: 12.7.0 (Optimized + Sharp Image Fix)
 * ✅ Tối ưu: Critical CSS, Image sharpness, Performance
 */

/* --- PHẦN 1: CSS Cốt lõi của Gallery --- */
.homestay-gallery.v4 .gallery-grid {
    display: grid;
    gap: var(--hg-gap, 8px);
    height: var(--hg-height, 480px);
    /* ✅ Tối ưu rendering performance */
    will-change: contents;
}

.homestay-gallery.v4.layout-7 .gallery-grid {
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.homestay-gallery.v4.layout-5 .gallery-grid {
    grid-template-columns: 1.45fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.homestay-gallery.v4 .gallery-tile {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer;
    /* ✅ Cô lập rendering để tăng performance */
    contain: layout style paint;
}

.homestay-gallery.v4 .gallery-tile.big {
    grid-row: 1/3;
    grid-column: 1/2;
}

.homestay-gallery.v4 .img-wrap,
.homestay-gallery.v4 .img-wrap img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 10px;
    transition: transform .3s ease;
    /* ✅ FIX 1: Tăng độ sắc nét cho ảnh thumbnail */
    image-rendering: -webkit-optimize-contrast; /* Chrome/Safari */
    image-rendering: crisp-edges; /* Firefox */
    image-rendering: high-quality; /* IE/Edge */
}

.homestay-gallery.v4 .gallery-tile:hover .img-wrap img {
    transform: scale(1.05);
}

.homestay-gallery.v4 .gallery-more-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 8px 12px;
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: saturate(160%) blur(6px);
    cursor: pointer;
    transition: all .2s ease;
}

.homestay-gallery.v4 .gallery-more-btn:hover {
    background: rgba(0, 0, 0, .8);
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* --- PHẦN 2: Responsive Mobile --- */
@media (max-width: 768px) {
    .homestay-gallery.v4 .gallery-grid {
        grid-template-columns: 1fr 1fr !important;
        height: auto;
        grid-auto-rows: 180px;
    }
    
    .homestay-gallery.v4 .gallery-tile.big {
        grid-column: 1/-1;
        min-height: 240px;
    }
    
    .homestay-gallery.v4 .hide-on-mobile {
        display: none;
    }
    
    .homestay-gallery.v4 .desktop-only {
        display: none;
    }
    
    .homestay-gallery.v4 .hg-tab {
        padding: 6px 10px;
        font-size: 13px;
    }
}

@media (min-width: 769px) {
    .homestay-gallery.v4 .mobile-only {
        display: none;
    }
}

/* --- PHẦN 3: Lightbox Overlay --- */
.homestay-gallery.v4 .hg-overlay[hidden] {
    display: none !important;
}

.homestay-gallery.v4 .hg-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    /* ✅ Tối ưu animation performance */
    will-change: opacity;
}

.homestay-gallery.v4 .hg-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 10, .95); /* ✅ Tăng độ tối để ảnh nổi bật hơn */
    backdrop-filter: blur(8px); /* ✅ Tăng blur để focus vào ảnh */
}

.homestay-gallery.v4 .hg-panel {
    position: relative;
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    background: #0b0b0b;
    color: #fff;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}

@media (max-width: 768px) {
    .homestay-gallery.v4 .hg-panel {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}

.homestay-gallery.v4 .hg-header {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #111;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.homestay-gallery.v4 .hg-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    flex-grow: 1;
    /* ✅ Smooth scrolling cho tabs */
    scroll-behavior: smooth;
}

.homestay-gallery.v4 .hg-tab {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: transparent;
    color: #f0f0f0;
    cursor: pointer;
    white-space: nowrap;
    font-size: 14px;
    transition: all .2s ease;
}

.homestay-gallery.v4 .hg-tab:hover {
    background: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .25);
}

.homestay-gallery.v4 .hg-tab[aria-selected="true"] {
    background: #fff;
    color: #111;
    border-color: #fff;
    font-weight: 600;
}

.homestay-gallery.v4 .hg-close,
.homestay-gallery.v4 .hg-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    padding: 0;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    transition: all .2s ease;
    line-height: 1;
}

.homestay-gallery.v4 .hg-close:hover,
.homestay-gallery.v4 .hg-nav:hover {
    background: rgba(255, 255, 255, .25);
    transform: scale(1.05);
}

.homestay-gallery.v4 .hg-close {
    margin-left: auto;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.homestay-gallery.v4 .hg-nav {
    position: absolute;
    top: 50%;
    width: 44px;
    height: 44px;
    transform: translateY(-50%);
    z-index: 10;
}

.homestay-gallery.v4 .hg-nav:hover {
    transform: translateY(-50%) scale(1.1);
}

.homestay-gallery.v4 .hg-nav.prev {
    left: 15px;
}

.homestay-gallery.v4 .hg-nav.next {
    right: 15px;
}

.homestay-gallery.v4 .hg-close svg,
.homestay-gallery.v4 .hg-nav svg {
    width: 50%;
    height: 50%;
    fill: currentColor;
}

/* --- PHẦN 4: Stage (Khu vực hiển thị ảnh chính) --- */
.homestay-gallery.v4 .hg-stage {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0b0b0b;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

/* ✅ FIX 2: ĐÂY LÀ KEY FIX CHO ẢNH RÕ NÉT */
.homestay-gallery.v4 .hg-stage-img {
    max-width: 98%;
    max-height: 98%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    transition: opacity .3s ease-in-out;
    pointer-events: none;
    
    /* ✅ QUAN TRỌNG: Tăng độ sắc nét cho ảnh full size */
    image-rendering: -webkit-optimize-contrast; /* Safari/Chrome */
    image-rendering: crisp-edges; /* Firefox/Edge */
    image-rendering: high-quality; /* Fallback */
    
    /* ✅ Tắt anti-aliasing để ảnh sắc nét hơn */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* ✅ Hardware acceleration */
    transform: translateZ(0);
    backface-visibility: hidden;
}

.homestay-gallery.v4 .hg-stage-img.is-loading {
    opacity: .5;
}

/* --- PHẦN 5: Thumbnails --- */
.homestay-gallery.v4 .hg-thumbs {
    padding: 10px;
    display: flex;
    gap: 10px;
    overflow: auto;
    background: #0f0f0f;
    border-top: 1px solid rgba(255, 255, 255, .06);
    /* ✅ Smooth scrolling */
    scroll-behavior: smooth;
}

.homestay-gallery.v4 .hg-thumb {
    position: relative;
    width: 96px;
    height: 72px;
    flex: 0 0 auto;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    /* ✅ Tối ưu rendering */
    contain: layout style paint;
}

.homestay-gallery.v4 .hg-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: #2a2a2a;
    transition: opacity .2s ease;
}

.homestay-gallery.v4 .hg-thumb:hover img {
    opacity: .8;
}

.homestay-gallery.v4 .hg-thumb.is-active::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 3px solid #fff;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(255, 255, 255, .5);
}

/* --- PHẦN 6: Info Box --- */
.homestay-gallery.v4 .hg-infobox {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 40px);
    padding: 10px 14px;
    border-radius: 10px;
    color: #fff;
    background: rgba(0, 0, 0, .7); /* ✅ Tăng opacity để dễ đọc hơn */
    backdrop-filter: saturate(150%) blur(8px);
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    width: max-content;
}

/* --- PHẦN 7: Focus Styles (Accessibility) --- */
.homestay-gallery.v4 .gallery-tile:focus-visible,
.homestay-gallery.v4 .hg-tab:focus-visible,
.homestay-gallery.v4 .hg-close:focus-visible,
.homestay-gallery.v4 .hg-nav:focus-visible,
.homestay-gallery.v4 .hg-thumb:focus-visible {
    outline: 2px solid #00AEEF;
    outline-offset: 2px;
}

.homestay-gallery.v4 .hg-overlay:focus-visible {
    outline: none;
}

/* --- PHẦN 8: Button Style (Explore Gallery) --- */
.btn-explore-gallery {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 30px;
    border: 1px solid #dddddd;
    color: #222222 !important;
    background-color: #f7f7f7;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
    line-height: 1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.btn-explore-gallery:hover {
    background-color: #ffffff;
    border-color: #cccccc;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
}

.btn-explore-gallery .icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

@keyframes subtle-nudge {
    0%, 5%, 100% { transform: translateX(0); }
    1%, 3% { transform: translateX(3px); }
    2%, 4% { transform: translateX(-3px); }
}

.btn-explore-gallery .icon {
    animation: subtle-nudge 10s ease-in-out infinite;
}

.btn-explore-gallery:focus-visible {
    outline: 1px solid #00AEEF;
    outline-offset: 2px;
}
