/* =========================================================================
   Album extras — port từ EDC.LandingPage.SmartAlbum:
   tự động chạy (autoplay), thông tin / thả tim / lượt xem từng ảnh, ghép ảnh.
   Mọi class có tiền tố "sa-" để không đụng Bootstrap (.modal, .toast ...).
   ========================================================================= */

/* ── Nút trên thanh lọc (cạnh ô sắp xếp) ─────────────────────────────── */
.gallery-filter-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;   /* nằm cùng hàng nút Download, dạt sang phải */
}
.btn-choose { flex-wrap: wrap; gap: 12px 0; }
/* site.css đặt ".btn-choose button, .btn-choose label" min-width 180px + nền trắng + bóng
   (cho nút Download) — trả cụm nút này về kích thước theo nội dung */
.btn-choose .gallery-filter-actions .sa-tool-btn,
.btn-choose .gallery-filter-actions .gallery-sort {
    min-width: 0;
    box-shadow: none;
    border: 0;
    background-color: #f2f2f2;
    color: #333;
}
.btn-choose .gallery-filter-actions .sa-tool-btn.sa-primary {
    background-color: var(--color-button);
    color: var(--color-button-text);
}
.sa-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 0;
    border-radius: 4px;
    padding: 6px 14px;
    font-size: 15px;
    line-height: 1.6;
    background: #f2f2f2;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
}
.sa-tool-btn .mdi { font-size: 20px; line-height: 1; }
.sa-tool-btn.sa-primary {
    background: var(--color-button);
    color: var(--color-button-text);
}
.sa-tool-btn:hover { filter: brightness(.96); }

/* ── Nút nổi góc phải dưới (chỉ mobile) — thay cho cụm Sắp xếp / Collage / Autoplay ── */
.sa-fab { display: none; }
@media (max-width: 768px) {
    .gallery-filter-actions { display: none; }
    .sa-fab {
        position: fixed;
        right: 16px;
        bottom: calc(20px + var(--sa-fab-lift, 0px));
        z-index: 1030;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 12px;
        transition: bottom .2s;
    }
    .jigsaw-mode .sa-fab { display: none; }
}
.sa-fab-btn {
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: #fff;
    color: var(--color-button);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.sa-fab-btn[hidden] { display: none; }
.sa-fab-main { background: var(--color-button); color: var(--color-button-text); }
.sa-fab-menu {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity .15s, transform .15s;
}
.sa-fab.open .sa-fab-menu { opacity: 1; transform: none; pointer-events: auto; }
.sa-fab-item {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: 999px;
    padding: 6px 6px 6px 16px;
    background: #fff;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.sa-fab-item i {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: rgba(var(--color-button-rgb), .12);
    color: var(--color-button);
}

/* ── Thanh công cụ có chữ phía dưới (ngay trên dãy ảnh nhỏ) — js/album-viewer.js ── */
/* Không dùng chú thích ảnh: ẩn khung sub-html để thanh nằm sát dãy ảnh */
.sa-viewer .lg-components .lg-sub-html { display: none; }
.sa-lg-actions {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 54px; /* khớp defaultCaptionHeight trong album-viewer.js */
    padding: 10px 12px;
    background: #0d0a0a;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.sa-lg-actions .sa-act {
    float: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    height: 100%;
    padding: 0 20px;
    border: 0;
    border-left: 1px solid rgba(255, 255, 255, .14);
    background: none;
    color: #ddd;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none !important;
    transition: color .2s;
}
.sa-lg-actions > .sa-act:first-child { border-left: 0; }
.sa-lg-actions .sa-act::after { content: none !important; } /* bỏ icon font gốc của LightGallery */
.sa-lg-actions .sa-act:hover { color: #fff; }
.sa-lg-actions .sa-act.active { color: var(--color-button); }
.sa-lg-actions .sa-act .mdi { font-size: 20px; line-height: 1; }
.sa-act-label {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    font-weight: 500;
    line-height: 1;
}
.sa-act-label b { font-variant-numeric: tabular-nums; }
.sa-like-btn.liked .mdi { color: #e53935; }
/* Nút đóng: tròn ở góc phải trên */
.sa-viewer .lg-toolbar .lg-close {
    width: 44px;
    height: 44px;
    margin: 10px 12px 0 0;
    padding: 0;
    line-height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 22px;
    transition: background .2s;
}
.sa-viewer .lg-toolbar .lg-close:hover { background: rgba(255, 255, 255, .26); }
/* Lượt xem của ảnh đang xem (góc trên bên trái) — nút Like nằm ở thanh dưới */
.sa-lg-stats {
    position: absolute;
    top: 56px;
    left: 12px;
    z-index: 1090;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 14px;
}
.sa-lg-views { opacity: .85; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
/* Lượt xem cho mobile — góc trái dưới, ngay trên thanh công cụ */
.sa-views-mobile {
    display: none;
    position: absolute;
    left: 12px;
    bottom: 100%;
    margin-bottom: 12px;
    z-index: 2;
    align-items: center;
    gap: 4px;
    height: 37px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    font-size: 14px;
    opacity: 1;
    text-shadow: none;
}
.sa-views-mobile:empty { visibility: hidden; }
.sa-like-btn.pop .mdi { animation: sa-pop .35s; }
@keyframes sa-pop { 50% { transform: scale(1.4); } }

/* Bảng thông tin ảnh */
.sa-lg-info {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px); /* bật lên phía trên thanh dưới */
    z-index: 1090;
    background: rgba(30, 30, 36, .96);
    color: #fff;
    border-radius: 12px;
    padding: 14px 16px;
    min-width: 250px;
    max-width: calc(100vw - 28px);
    font-size: 14px;
}
.sa-lg-info[hidden] { display: none; }
.sa-lg-info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.sa-lg-info dt { opacity: .6; font-weight: 400; }
.sa-lg-info dd { margin: 0; word-break: break-all; }

@media (max-width: 900px) {
    .sa-lg-actions .lg-actual-size,
    .sa-lg-actions .lg-zoom-out { display: none; }
    .sa-lg-actions .sa-act { padding: 0 12px; }
}

@media (max-width: 576px) {
    /* Điện thoại chụm 2 ngón để zoom — ẩn nút zoom cho đủ chỗ */
    .sa-lg-actions .lg-zoom-in { display: none; }
    /* Màn hẹp: chữ nằm dưới icon, chia đều chiều ngang */
    .sa-lg-actions {
        height: 58px;
        padding: 6px 4px;
        justify-content: space-around;
    }
    .sa-lg-actions .sa-act {
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        padding: 0 6px;
        border-left: 0;
    }
    .sa-lg-actions .sa-act .mdi { font-size: 22px; }
    .sa-act-label { font-size: 11px; }
    .sa-views-desktop { display: none; }
    .sa-views-mobile { display: inline-flex; }
}

/* ── Thông báo nhỏ ───────────────────────────────────────────────────── */
.sa-toast {
    position: fixed;
    left: 50%;
    bottom: 120px;
    transform: translateX(-50%);
    z-index: 2000;
    background: rgba(30, 30, 36, .92);
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    max-width: 90vw;
    text-align: center;
}
.sa-toast[hidden] { display: none; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.sa-modal {
    position: fixed;
    inset: 0;
    z-index: 1500;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.sa-modal[hidden] { display: none; }
.sa-modal-card {
    position: relative;
    width: 100%;
    max-width: 340px;
    background: #fff;
    border-radius: 16px;
    padding: 18px 22px 22px;
    display: grid;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.sa-modal-card h3 { margin: 0; color: #4c4e64; text-align: center; font-weight: 600; font-size: 17px; }
.sa-modal-actions { display: flex; gap: 8px; justify-content: center; }
.sa-close {
    position: absolute;
    top: 8px;
    right: 12px;
    border: 0;
    background: none;
    font-size: 28px;
    line-height: 1;
    color: #999;
}
.sa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    padding: 8px 14px;
    font-weight: 600;
    font-size: 14px;
    border: 1px solid var(--color-button);
    background: var(--color-button);
    color: var(--color-button-text);
    cursor: pointer;
}
.sa-btn:disabled { opacity: .5; cursor: not-allowed; }
.sa-btn.sa-outline { background: #fff; color: var(--color-button); }

/* ── Ghép ảnh ────────────────────────────────────────────────────────── */
.sa-jig-styles { display: grid; grid-template-columns: 1fr 1fr; margin-top: 4px; }
.sa-jig-style {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 8px;
    border: 0;
    background: none;
    color: #d6c3a1;
    border-bottom: 1px solid #f0f0f0;
}
.sa-jig-style:nth-child(odd) { border-right: 1px solid #f0f0f0; }
.sa-jig-style:nth-child(3) { border-bottom: 0; }
.sa-jig-style:hover, .sa-jig-style:active { background: #faf7f2; }
.sa-jig-style svg { width: 54px; height: 54px; }
.sa-jig-style span { color: #333; font-size: 15px; font-weight: 500; }

.jigsaw-mode .pswp-item .check-img,
.jigsaw-mode .download-images.download-fixed { display: none !important; }
.jigsaw-mode .pswp-item { cursor: pointer; }
.pswp-item.jig-picked .img-item { outline: 3px solid var(--color-button); outline-offset: -3px; }
.pswp-item.jig-picked img { opacity: .75; }
.pswp-item .img-item { position: relative; }
.sa-jig-num {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 3;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    background: var(--color-button);
    color: var(--color-button-text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.sa-jig-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, .14);
}
.sa-jig-bar[hidden] { display: none; }
.sa-jig-bar-info { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
.sa-jig-bar-info b { color: #333; font-size: 15px; }
.sa-jig-bar-info small { color: #828393; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sa-jig-count { font-weight: 700; color: var(--color-button); font-variant-numeric: tabular-nums; }
.sa-jig-busy {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(0, 0, 0, .7);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    font-weight: 600;
}
.sa-jig-busy[hidden] { display: none; }
.sa-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    animation: sa-spin .8s linear infinite;
}
@keyframes sa-spin { to { transform: rotate(360deg); } }
.sa-jig-result-card { max-width: 460px; }
.sa-jig-result-img { max-height: 60vh; overflow: auto; border-radius: 10px; background: #f4f4f6; }
.sa-jig-result-img img { display: block; width: 100%; height: auto; }
/* Poster / GIF: thu vừa khung, không cần cuộn (ảnh dài thì vẫn cuộn) */
.sa-jig-result-img.fit img { width: auto; max-width: 100%; max-height: 60vh; margin: 0 auto; }
.sa-jig-tip { margin: 0; font-size: 13px; color: #828393; text-align: center; }

/* ── Lượt xem + tim trên thumbnail (góc phải dưới) ───────────────────── */
.sa-tile-stats {
    position: absolute;
    right: 6px;
    bottom: 6px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    font-size: 12px;
    line-height: 1.6;
    pointer-events: none;
}
.sa-tile-stats > span { display: inline-flex; align-items: center; gap: 3px; }
.sa-tile-stats .mdi { font-size: 14px; line-height: 1; }
.sa-tile-stats .mdi-heart { color: #ff5a5f; }
.sa-tile-stats b { font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 576px) {
    .sa-tile-stats { right: 4px; bottom: 4px; gap: 6px; padding: 1px 6px; font-size: 11px; }
    .sa-tile-stats .mdi { font-size: 12px; }
}

/* ── Mobile: thanh Download gọn 1 hàng ───────────────────────────────────
   responsive-layout-user.css / user.css cũ xếp dọc .btn-choose, đệm 15px cho mọi div con và
   margin-top cho nút → khoảng trống lớn dưới tab folder. Chỉ áp khi thanh CHƯA nổi
   (.download-fixed có style riêng trong user.css). !important để thắng style inline. */
@media (max-width: 768px) {
    .folder-tabs { padding-bottom: 10px; }
    .btn-choose {
        flex-direction: row;
        gap: 0;
        padding-bottom: 12px !important;
    }
    .btn-choose > .download-images:not(.download-fixed) {
        flex-direction: row !important;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        padding-top: 0;
    }
    .btn-choose > .download-images:not(.download-fixed) .btn {
        margin-top: 0 !important;
        min-width: 0 !important;
        max-width: none;
        flex-shrink: 0;
        padding: 7px 16px;
        font-size: 14px;
    }
    .btn-choose > .download-images:not(.download-fixed) > div {
        padding-top: 0;
        align-items: center;
        min-width: 0;
    }
    .btn-choose > .download-images:not(.download-fixed) > div > input {
        margin: 0 6px 0 0 !important;
        flex-shrink: 0;
    }
    .btn-choose > .download-images:not(.download-fixed) > div > span {
        margin: 0 !important;
        font-size: 13px;
        line-height: 1.3;
    }
}
