/* ==========================================================================
   FILE: style_final_6.css
   VERSION: FINAL FIX - VIEW TRACKING UI
   ========================================================================== */
:root {
    --yiml-primary: #16867b;
    --sidebar-width: 260px;
    --lb-right-width: 580px; 
    --lb-img-max-width: 850px;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

body.yiml-no-scroll { 
    overflow: hidden !important; 
    height: 100vh; 
    position: fixed; 
    width: 100%; 
}

.yiml-gallery-wrapper { display: flex; width: 100%; min-height: 100vh; background: #fff; }

/* --- DESKTOP CSS --- */
.yiml-sidebar { width: var(--sidebar-width); height: 100vh; position: sticky; top: 0; left: 0; background: #fff; border-right: 1px solid #eee; padding: 100px 16px; overflow-y: auto; z-index: 100; flex-shrink: 0; display: flex; flex-direction: column; }
.yiml-mini-header { margin-bottom: 24px; text-align: center; }
.yiml-mini-logo { font-size: 22px; font-weight: 800; color: var(--yiml-primary); margin: 0; }
.yiml-mini-desc { font-size: 13px; color: #777; margin-top: 4px; }
.yiml-search-box { margin-bottom: 20px; }
.yiml-search-box input { width: 100%; padding: 12px 16px 12px 40px; border: none; background: #efefef; border-radius: 24px; outline: none; font-size: 15px; color: #111; }
.yiml-cat-btn { width: 100%; text-align: left; padding: 12px 16px; border-radius: 8px; border: none; background: transparent; color: #111; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 12px; margin-bottom: 2px; font-size: 15px; }
.yiml-cat-btn:hover { background: #f2f2f2; }
.yiml-cat-btn.active { background: #111; color: #fff; }

/* [NEW] STATS BOX SIDEBAR */
.yiml-stats-box { margin-top: auto; padding-top: 20px; border-top: 1px solid #f0f0f0; }
.yiml-stat-item { background: #f9f9f9; padding: 8px 12px; border-radius: 6px; font-size: 13px; color: #555; display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.yiml-stat-item b { color: #111; font-weight: 700; }
.yiml-copyright { font-size: 11px; color: #999; text-align: center; margin-top: 10px; }

.yiml-content { flex-grow: 1; padding: 20px 30px; background: #fff; }
.yiml-grid { column-count: 6; column-gap: 16px; }
@media (max-width: 1600px) { .yiml-grid { column-count: 5; } }
@media (max-width: 1400px) { .yiml-grid { column-count: 4; } }
@media (max-width: 1100px) { .yiml-grid { column-count: 3; } }
.yiml-item { break-inside: avoid; margin-bottom: 5px; }
.yiml-card { border-radius: 16px; overflow: hidden; position: relative; cursor: zoom-in; }
.yiml-card:hover { filter: brightness(0.9); }
.yiml-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 16px; }

/* LIGHTBOX */
.yiml-lightbox { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: #fff; z-index: 9999999; display: none; overflow: hidden; }
.yiml-lightbox.active { display: flex; animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.yiml-lb-content { width: 100%; height: 100%; display: flex; flex-direction: row; }
.yiml-lb-left { flex-grow: 1; height: 100vh; overflow-y: auto; background: #f5f5f5; position: relative; display: flex; flex-direction: column; align-items: center; }
.yiml-lb-img-wrap-inner { width: 100%; max-width: var(--lb-img-max-width); background: #fff; margin-top: 20px; box-shadow: 0 5px 25px rgba(0,0,0,0.08); }
#yiml-lb-img { display: block; width: 100%; height: auto !important; }
.yiml-lb-info-area { width: 100%; max-width: var(--lb-img-max-width); padding: 30px; background: #fff; margin-bottom: 50px; }
#yiml-lb-title { font-size: 24px; font-weight: 800; color: #111; margin: 0 0 10px 0; line-height: 1.3; }

/* [NEW] LIGHTBOX VIEW COUNTER */
.yiml-lb-meta { margin-bottom: 20px; font-size: 14px; color: #666; display: flex; align-items: center; gap: 15px; }
.yiml-view-badge { background: #f0f0f0; padding: 4px 10px; border-radius: 4px; font-size: 12px; font-weight: 600; color: #444; }

.yiml-lb-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 25px; align-items: center; }
.yiml-action-btn { height: 40px; padding: 0 18px; border-radius: 20px; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; text-decoration: none; transition: 0.2s; cursor: pointer; border: 1px solid transparent; }
.yiml-action-btn.dl { background: #111; color: #fff; flex-grow: 1; justify-content: center; max-width: 200px; }
.yiml-action-btn.read { background: #fff; color: #111; border: 1px solid #ddd; }
.yiml-action-btn.icon { width: 40px; padding: 0; background: #115bcd; border-radius: 50%; color: #ffffff; font-size: 0; }
.yiml-action-btn.icon::after { font-size: 14px; }
.yiml-action-btn.icon.fb::after { content: 'FB'; font-weight:900; }
.yiml-action-btn.icon.pin { background: #e60023; color:#fff; }
.yiml-action-btn.icon.pin::after { content: 'P'; font-weight:900; }
.yiml-action-btn:hover { opacity: 0.8; transform: translateY(-1px); }
#yiml-lb-desc { font-size: 15px; line-height: 1.6; color: #444; }
.yiml-lb-right { width: var(--lb-right-width); height: 100vh; overflow-y: auto; background: #fff; border-left: 1px solid #e0e0e0; padding: 20px; flex-shrink: 0; }
.yiml-related-heading { font-size: 16px; font-weight: 700; margin: 0 0 15px 0; color: #111; }
.yiml-lb-related-grid { column-count: 2; column-gap: 10px; display: block; }
.yiml-rel-item { break-inside: avoid; margin-bottom: 10px; border-radius: 8px; overflow: hidden; cursor: pointer; background: #eee; height: auto !important; }
.yiml-rel-item img { width: 100%; height: auto !important; object-fit: contain; display: block; }

.yiml-nav-btn {
    position: fixed; top: 50%; transform: translateY(-50%);
    width: 50px; height: 50px; background: #fff; color: #111;
    border: 1px solid #ddd; border-radius: 50%; font-size: 20px; cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 99999999;
    display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.yiml-nav-btn:hover { background: #111; color: #fff; border-color: #111; }
.yiml-nav-btn.prev { left: 20px; }
.yiml-nav-btn.next { right: calc(var(--lb-right-width) + 20px); }

.yiml-lb-close {
    position: fixed; top: 15px; left: 15px; height: 40px; background: #fff; color: #333;
    border: none; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    cursor: pointer; z-index: 1000000; display: flex; align-items: center; justify-content: center;
}

/* MOBILE */
@media (max-width: 1024px) {
    :root { --lb-right-width: 300px; --lb-img-max-width: 100%; }
    .yiml-grid { column-count: 3; }
}

@media (max-width: 900px) {
    .yiml-nav-btn { display: none !important; }
    .yiml-lightbox {
        position: fixed; top: 0; left: 0; width: 100%; height: 100dvh;
        background: #fff; overflow-y: auto; overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch; display: none; flex-direction: column; padding-bottom: 0;
    }
    .yiml-lightbox.active { display: block; }
    .yiml-lb-content { display: block; width: 100%; height: auto; }
    .yiml-lb-left { width: 100%; height: auto; display: block; overflow: visible; background: #fff; padding: 0; margin: 0; }
    .yiml-lb-img-wrap-inner { margin: 0; box-shadow: none; max-width: 100%; }
    .yiml-lb-info-area { width: 100%; padding: 20px 15px 10px 15px; margin: 0; background: #fff; }
    .yiml-lb-right { width: 100%; height: auto; border: none; margin: 0; padding: 0 15px 100px 15px; overflow: visible; background: #fff; }
    .yiml-related-heading { margin-top: 15px; margin-bottom: 10px; }
    .yiml-lb-actions { flex-wrap: wrap; gap: 8px; }
    .yiml-action-btn.read { order: 1; flex: 0 0 100%; background: #023f71; color: #ffffff; border: none; margin-bottom: 5px; justify-content: center; height: 48px; font-size: 16px; }
    .yiml-action-btn.dl { order: 2; flex: 1; background: #fff; color: #111; border: 1px solid #ddd; max-width: none; }
    .yiml-action-btn.icon { order: 3; }
    .yiml-gallery-wrapper { flex-direction: column; }
    .yiml-sidebar { width: 100%; height: auto; padding: 10px; z-index: 90; display: flex; flex-direction: column; }
    .yiml-mini-header { display: none; }
    .yiml-cats-list { order: 1; display: flex; overflow-x: auto; padding-bottom: 5px; margin-bottom: 10px; }
    .yiml-search-box { display: block !important; order: 2; margin-bottom: 10px; width: 100%; margin-top: 20px;}
    .yiml-search-box input { padding: 8px 12px 8px 35px; font-size: 14px; }
    .yiml-cat-btn { white-space: nowrap; margin-right: 5px; padding: 6px 14px;margin-top: 10px; border: 1px solid #eee; }
    .yiml-content { padding: 0; }
    .yiml-grid { column-count: 2; column-gap: 5px;}
    .yiml-loader { border: 3px solid #f3f3f3; border-top: 3px solid var(--yiml-primary); border-radius: 50%; width: 30px; height: 30px; animation: spin 0.8s linear infinite; margin: 30px auto; display: none; }
    @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
    .yiml-pagination { display: flex; justify-content: center; gap: 8px; margin-top: 40px; padding-bottom: 40px; }
    .yiml-pg-btn { width: 40px; height: 40px; border: none; background: #f0f0f0; color: #111; border-radius: 50%; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; }
    .yiml-pg-btn.active { background: #111; color: #fff; }
    
    .yiml-stats-box { flex-direction: row; display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; justify-content: center; border-top: none; padding-top: 0; order: 3; }
    .yiml-stat-item { flex-grow: 1; justify-content: center; gap: 5px; margin: 0; }
}

#yiml-back-top {
    display: none;
    position: fixed;
    bottom: 30px; left: 30px;
    width: 50px; height: 50px;
    background: #0f988b; 
    color: #fff;
    border-radius: 50%; 
    text-align: center;
    line-height: 50px; 
    font-size: 24px; font-weight: bold;
    cursor: pointer; z-index: 99999999;
    box-shadow: 0 4px 10px rgba(15, 152, 139, 0.4);
    transition: all 0.3s ease;
    align-items: center; justify-content: center;
}
#yiml-back-top:hover {
    transform: translateY(-5px);
    background: #0d8276;
}
/* --- STATS BOX GỌN GÀNG (2 CỘT) --- */
.yiml-stats-box {
    margin-top: auto;           /* Đẩy xuống đáy sidebar */
    padding: 15px 10px;         /* Padding vừa phải */
    border-top: 1px solid #f0f0f0;
    background: #fff;           /* Nền trắng sạch sẽ */
    display: flex;              /* Dùng Flex để chia cột */
    flex-wrap: wrap;            /* Cho phép xuống dòng */
    gap: 8px;                   /* Khoảng cách giữa các ô */
}

.yiml-stat-item {
    flex: 1 1 40%;              /* Chia đều 2 bên (gần 50%) */
    background: #f7f9fc;        /* Màu nền xám xanh nhạt sang trọng */
    padding: 10px 5px;
    border-radius: 8px;         /* Bo góc mềm mại */
    font-size: 11px;
    color: #666;
    display: flex;
    flex-direction: column;     /* Icon/Label ở trên, số ở dưới */
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: 0.2s;
    cursor: default;
    border: 1px solid transparent;
}

.yiml-stat-item:hover {
    background: #fff;
    border-color: #eee;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Style cho số liệu (đậm, to hơn chút) */
.yiml-stat-item b {
    font-size: 13px;
    color: #16867b; /* Màu chủ đạo (xanh) */
    font-weight: 700;
    margin-top: 3px;
    display: block;
}

/* Phần bản quyền nhỏ xíu ở dưới cùng */
.yiml-copyright {
    width: 100%;                /* Chiếm hết chiều ngang */
    text-align: center;
    font-size: 10px;
    color: #bbb;
    margin-top: 5px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* --- MOBILE FIX (Giữ nguyên giao diện ngang cho mobile) --- */
@media (max-width: 900px) {
    .yiml-stats-box {
        background: transparent;
        border: none;
        padding: 0 0px 0px 5px;
        margin-top: 5px;
    }
    .yiml-stat-item {
        background: #fff;
        border: 1px solid #eee;
        flex-direction: row; /* Mobile thì để ngang cho gọn dòng */
        gap: 6px;
        padding: 6px 10px;
    }
    .yiml-stat-item b {
        margin-top: 0;
        font-size: 12px;
    }
    .yiml-copyright {
        display: none; /* Ẩn copyright trên mobile cho đỡ rối */
    }
}
/* --- THÊM VÀO CSS --- */
.yiml-sort-box {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px dashed #eee;
}

.yiml-sort-btn {
    flex: 1;
    padding: 8px 0;
    border: 1px solid #ddd;
    background: #fff;
    color: #555;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.yiml-sort-btn:hover {
    background: #f9f9f9;
    border-color: #ccc;
}

.yiml-sort-btn.active {
    background: var(--yiml-primary); /* Màu xanh chủ đạo */
    color: #fff;
    border-color: var(--yiml-primary);
    box-shadow: 0 2px 6px rgba(22, 134, 123, 0.2);
}

/* Mobile responsive */
@media (max-width: 900px) {
    .yiml-sort-box {
        margin-top: 10px;
        margin-bottom: 10px;
        width: 100%;
    }
}
/* --- MOBILE SIDEBAR OVERLAY STYLE --- */
.yiml-mobile-bar { display: none; } /* Ẩn trên Desktop */
.yiml-sidebar-overlay { display: none; }
.yiml-close-sidebar-btn { display: none; }

@media (max-width: 900px) {
    /* 1. Thanh Header Mobile chứa nút Lọc */
    .yiml-mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 15px;
        position: sticky;
        top: 78px;
        z-index: 900;
        width: 100%;
    }
    
    .yiml-toggle-btn {
        padding: 8px 16px;
        background: #178c80;
        color: #fff;
        border: none;
        border-radius: 20px;
        font-weight: 600;
        font-size: 13px;
        cursor: pointer;
        display: flex; align-items: center; gap: 5px;
    }
    
    .yiml-mobile-logo {
        font-weight: 800;
        color: var(--yiml-primary);
        font-size: 18px;
    }

    /* 2. Sidebar dạng Trượt (Overlay) */
    .yiml-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px; /* Chiều rộng sidebar mobile */
        height: 100vh;
        background: #fff;
        z-index: 10000; /* Cao hơn mọi thứ */
        padding: 60px 20px 20px 20px; /* Padding top để tránh nút đóng */
        box-shadow: 2px 0 20px rgba(0,0,0,0.1);
        transform: translateX(-100%); /* Giấu sang trái */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        display: block !important; /* Ghi đè các style cũ */
    }

    /* Class này được JS thêm vào để hiện Sidebar */
    .yiml-sidebar.active {
        transform: translateX(0);
    }

    /* 3. Lớp nền đen mờ */
    .yiml-sidebar-overlay {
        display: block;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9999; /* Thấp hơn sidebar 1 chút */
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }
    .yiml-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* 4. Nút đóng Sidebar (dấu X) */
    .yiml-close-sidebar-btn {
        display: block;
        position: absolute;
        top: 15px;
        right: 15px;
        background: transparent;
        border: none;
        font-size: 30px;
        line-height: 1;
        cursor: pointer;
        color: #333;
    }

    /* Reset lại các style cũ làm vỡ layout */
    .yiml-gallery-wrapper { flex-direction: column; }
    .yiml-content { width: 100%; }
    
    /* Ẩn các thành phần không cần thiết trong sidebar mobile cũ */
    .yiml-mini-header { display: block; margin-bottom: 20px; } /* Hiện lại logo trong sidebar */
    .yiml-cats-list { flex-direction: column; overflow-x: visible; } /* List dọc */
    .yiml-sort-box { width: 100%; }
}
