/* ============================================================
   GALLERY-EDITOR.CSS — dùng chung cho Kho Ảnh Trang Chủ, Album lớp,
   và Trang Phục khi Admin/Thành viên bật "Chế độ sửa ảnh".
   ============================================================ */

.outfit-card-item { position: relative; }

.gallery-edit-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 5;
}

.gallery-edit-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--gold, #B84A2B);
    background: rgba(255, 255, 255, 0.8);
    color: var(--gold, #B84A2B);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: 0.2s ease;
}
.gallery-edit-btn:hover { background: var(--gold, #B84A2B); color: #ffffff; }

.gallery-edit-btn-danger { border-color: #dc2626; color: #dc2626; }
.gallery-edit-btn-danger:hover { background: #dc2626; color: #ffffff; }

.gallery-add-tile {
    cursor: pointer;
    border: 2px dashed rgba(184,74,43,0.5);
    background: rgba(184,74,43,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s ease;
}
.gallery-add-tile:hover {
    border-color: var(--gold, #B84A2B);
    background: rgba(184,74,43,0.12);
}
.gallery-add-tile-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--gold, #B84A2B);
    font-weight: bold;
    font-size: 0.9rem;
    text-align: center;
    padding: 10px;
}
.gallery-add-tile-inner i { font-size: 1.6rem; }

/* ===== MODAL CHỌN KHUNG ẢNH (ngang / dọc / vuông / lớn) ===== */
.gallery-size-picker-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(245,239,226,0.85);
    backdrop-filter: blur(3px);
    z-index: 4000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.gallery-size-picker-overlay.show { display: flex; }

.gallery-size-picker-box {
    background: var(--bg-card, #FFFDF7);
    border: 1px solid var(--gold, #B84A2B);
    border-radius: 12px;
    padding: 25px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.gallery-size-picker-box h4 {
    color: var(--gold, #B84A2B);
    margin: 0 0 8px 0;
    font-size: 1.1rem;
}
.gallery-size-picker-hint {
    color: var(--text-muted, #4A3429);
    font-size: 0.85rem;
    margin: 0 0 18px 0;
    line-height: 1.5;
}
.gallery-size-picker-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.gallery-size-option {
    background: transparent;
    border: 1px solid var(--border-color, #E6D7BC);
    color: var(--text-main);
    padding: 12px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: 0.2s ease;
}
.gallery-size-option.active,
.gallery-size-option:hover {
    border-color: var(--gold, #B84A2B);
    background: rgba(184,74,43,0.15);
    color: var(--gold, #B84A2B);
}
.gallery-size-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.gallery-size-picker-cancel,
.gallery-size-picker-confirm {
    padding: 8px 18px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
}
.gallery-size-picker-cancel {
    background: transparent;
    color: var(--text-muted, #4A3429);
    border: 1px solid var(--border-color, #E6D7BC);
}
.gallery-size-picker-confirm { background: var(--gold, #B84A2B); color: #ffffff; }
/* ---------- Tải nhiều ảnh / cả thư mục ---------- */
.gallery-bulk-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; padding: 10px 12px; background: rgba(184,74,43,0.06); border: 1px dashed rgba(184,74,43,0.5); border-radius: 10px; }
.gallery-bulk-toolbar button { background: var(--gold, #B84A2B); color: #FFFDF7; border: none; padding: 8px 14px; border-radius: 20px; font-weight: 700; font-size: 0.85rem; cursor: pointer; font-family: inherit; }
.gallery-bulk-toolbar button[data-act="layout"] { background: transparent; color: var(--gold, #B84A2B); border: 1px solid var(--gold, #B84A2B); }
.gallery-bulk-toolbar button:hover { filter: brightness(1.08); }
.gallery-bulk-hint { font-size: 0.78rem; color: var(--text-muted, #4A3429); font-style: italic; }

.gallery-batch-overlay { position: fixed; inset: 0; z-index: 100002; background: rgba(23,21,19,0.6); display: none; align-items: center; justify-content: center; padding: 20px; }
.gallery-batch-overlay.show { display: flex; }
.gallery-batch-box { background: var(--c-surface, #FFFDF7); border-radius: 12px; padding: 24px; width: min(420px, 100%); box-shadow: 0 20px 40px rgba(0,0,0,0.3); }
.gallery-batch-box h4 { margin: 0 0 10px; color: var(--gold, #B84A2B); }
.gallery-batch-text { margin: 0 0 12px; font-weight: 700; color: var(--c-text, #171513); }
.gallery-batch-bar { height: 10px; background: var(--c-sand, #E6D7BC); border-radius: 6px; overflow: hidden; }
.gallery-batch-fill { height: 100%; width: 0; background: var(--gold, #B84A2B); transition: width 0.3s ease; }
.gallery-batch-hint { margin: 12px 0 0; font-size: 0.8rem; color: var(--text-muted, #4A3429); }

/* Ảnh lỗi (file mất) — chỉ hiện khi đang bật Chế độ chỉnh sửa, khách không thấy */
.gallery-broken { min-height: 140px; border: 2px dashed #681F1B !important; background: rgba(104,31,27,0.06); }
.gallery-broken img { display: none !important; }
.gallery-broken::before { content: "Ảnh lỗi — bấm 🗑 để xoá hoặc dùng \"Dọn ảnh lỗi\""; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; font-size: 0.85rem; font-weight: 700; color: #681F1B; }

/* ---------- Vùng kéo thả thư mục / ảnh ---------- */
.gallery-drop-zone { position: relative; }
.gallery-drop-zone.drag-over { outline: 3px dashed var(--gold, #B84A2B); outline-offset: 6px; border-radius: 12px; }
.gallery-drop-zone.drag-over::after {
    content: attr(data-drop-label);
    position: absolute; inset: 0; z-index: 50;
    display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px;
    background: rgba(184,74,43,0.14); backdrop-filter: blur(2px);
    color: var(--gold, #B84A2B); font-size: 1.3rem; font-weight: 800; border-radius: 12px; pointer-events: none;
}

/* ---------- Hộp chọn ảnh (ảnh bìa album...) ---------- */
.image-picker-overlay { position: fixed; inset: 0; z-index: 100003; background: rgba(23,21,19,0.65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.image-picker-box { background: var(--c-surface, #FFFDF7); border-radius: 12px; width: min(900px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,0.35); }
.image-picker-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--c-line, #E6D7BC); }
.image-picker-head h4 { margin: 0; color: var(--gold, #B84A2B); }
.image-picker-head button { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--c-muted, #4A3429); }
.image-picker-grid { padding: 14px 18px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.image-picker-cell { position: relative; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; aspect-ratio: 1; background: var(--c-sand, #E6D7BC); }
.image-picker-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-picker-cell:hover { border-color: var(--gold, #B84A2B); }
.image-picker-cell.current { border-color: #686B4D; }
.image-picker-cell span { position: absolute; left: 6px; bottom: 6px; background: #686B4D; color: #FFFDF7; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.image-picker-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--c-line, #E6D7BC); font-size: 0.85rem; color: var(--c-muted, #4A3429); }
.image-picker-foot button { background: var(--gold, #B84A2B); color: #FFFDF7; border: none; padding: 9px 16px; border-radius: 20px; font-weight: 700; cursor: pointer; font-family: inherit; }

/* ---------- Nhập ảnh từ Google Drive ---------- */
.drive-picker-link { display: flex; gap: 8px; padding: 14px 18px 0; flex-wrap: wrap; }
.drive-picker-link input { flex: 1; min-width: 220px; padding: 10px 12px; border: 1px solid var(--c-line, #E6D7BC); border-radius: 8px; font-family: inherit; font-size: 0.9rem; }
.drive-picker-link button { background: var(--gold, #B84A2B); color: #FFFDF7; border: none; padding: 10px 16px; border-radius: 8px; font-weight: 700; cursor: pointer; font-family: inherit; }
.drive-picker-status { margin: 10px 18px 0; font-size: 0.85rem; color: var(--c-muted, #4A3429); }
.drive-picker { width: min(1100px, 100%); min-width: 0; max-height: 92vh; }
.drive-picker-link input { min-width: 0; }
.drive-picker .image-picker-grid { flex: 1 1 auto; min-height: 120px; display: flex; flex-wrap: wrap; align-content: flex-start; align-items: flex-start; gap: 8px; }
.drive-picker .image-picker-grid::after { content: ''; flex: 999 1 0; } /* hàng cuối không bị kéo giãn */
.drive-picker .image-picker-cell { max-width: 100%; min-width: 0; border-width: 3px; transition: transform 0.12s; user-select: none; }
.drive-picker .image-picker-cell.selected { border-color: var(--gold, #B84A2B); transform: scale(0.95); }
.drive-check { position: absolute; top: 6px; right: 6px; color: rgba(255,253,247,0.9); background: rgba(23,21,19,0.35); border-radius: 50%; font-size: 1.3rem; }
.drive-picker .image-picker-cell.selected .drive-check { color: var(--gold, #B84A2B); background: var(--c-surface, #FFFDF7); }
.drive-zoom { position: absolute; bottom: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: none; background: rgba(23,21,19,0.6); color: #FFFDF7; cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.image-picker-cell:hover .drive-zoom, .drive-zoom:focus { opacity: 1; }
@media (hover: none) { .drive-zoom { opacity: 1; } }

/* Xem ảnh Drive cỡ lớn */
.drive-viewer { position: fixed; inset: 0; z-index: 100004; background: rgba(12,11,10,0.94); display: flex; align-items: center; justify-content: center; }
.drive-viewer[hidden] { display: none; }
.drive-viewer img { max-width: calc(100vw - 140px); max-height: calc(100vh - 110px); object-fit: contain; border-radius: 4px; }
.drive-viewer button { border: none; cursor: pointer; font-family: inherit; }
.drive-viewer-close { position: absolute; top: 14px; right: 16px; background: none; color: #FFFDF7; font-size: 1.6rem; }
.drive-viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; background: rgba(255,253,247,0.15); color: #FFFDF7; font-size: 1.2rem; }
.drive-viewer-nav.prev { left: 16px; }
.drive-viewer-nav.next { right: 16px; }
.drive-viewer-bar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; width: calc(100% - 32px); }
.drive-viewer-name { color: #E6D7BC; font-size: 0.85rem; }
.drive-viewer-toggle { background: var(--c-surface, #FFFDF7); color: var(--c-muted, #4A3429); padding: 9px 18px; border-radius: 20px; font-weight: 700; }
.drive-viewer-toggle.on { background: var(--gold, #B84A2B); color: #FFFDF7; }
@media (max-width: 600px) {
    .drive-viewer img { max-width: 100vw; max-height: calc(100vh - 130px); }
    .drive-viewer-nav { top: auto; bottom: 64px; transform: none; }
}
.drive-noimg { display: flex; align-items: center; justify-content: center; height: 100%; padding: 6px; font-size: 0.7rem; color: var(--c-muted, #4A3429); word-break: break-all; }
.drive-select-all { display: flex; align-items: center; gap: 6px; font-weight: 700; cursor: pointer; }
.drive-select-all[hidden] { display: none; }
.image-picker-foot button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Thông báo "Đã sắp xếp" + Hoàn tác */
.gallery-undo-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100005; display: flex; align-items: center; gap: 14px; background: #2B2522; color: #FFFDF7; padding: 12px 16px 12px 20px; border-radius: 30px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); font-size: 0.9rem; max-width: calc(100% - 32px); }
.gallery-undo-toast button { background: var(--gold, #B84A2B); color: #FFFDF7; border: none; padding: 8px 14px; border-radius: 20px; font-weight: 700; cursor: pointer; font-family: inherit; white-space: nowrap; }

/* Hộp chọn ảnh (ảnh bìa…): ảnh đúng tỉ lệ gốc, xếp so le */
.image-picker-grid.picker-masonry { display: block; column-count: 5; column-gap: 10px; flex: 1 1 auto; min-height: 0; }
.picker-masonry .image-picker-cell { display: block; width: 100%; aspect-ratio: auto; margin: 0 0 10px; break-inside: avoid; }
.picker-masonry .image-picker-cell img { height: auto; }
@media (max-width: 900px) { .image-picker-grid.picker-masonry { column-count: 3; } }
@media (max-width: 500px) { .image-picker-grid.picker-masonry { column-count: 2; } }

/* Xem lại ảnh trùng */
.dup-review { width: min(1000px, 100%); }
.dup-hint { margin: 10px 18px 0; font-size: 0.85rem; color: var(--c-muted, #4A3429); }
.dup-groups { padding: 12px 18px; overflow-y: auto; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.dup-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px dashed var(--c-line, #E6D7BC); }
.dup-row-label { font-size: 0.8rem; font-weight: 700; color: #686B4D; min-width: 60px; }
.dup-cell { position: relative; padding: 0; border: 3px solid #686B4D; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--c-sand, #E6D7BC); height: 130px; }
.dup-cell img { height: 100%; width: auto; display: block; }
.dup-cell.del { border-color: #B84A2B; }
.dup-cell.del img { opacity: 0.45; }
.dup-tag { position: absolute; left: 6px; bottom: 6px; background: #686B4D; color: #FFFDF7; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.dup-cell.del .dup-tag { background: #B84A2B; }
@media (max-width: 600px) { .dup-cell { height: 90px; } }

/* Chọn nguồn ảnh */
.source-picker { width: min(420px, 100%); }
.source-picker-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 18px; }
.source-picker-options button { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 10px; border: 2px solid var(--c-line, #E6D7BC); border-radius: 12px; background: var(--c-surface, #FFFDF7); color: var(--c-muted, #4A3429); font-family: inherit; font-weight: 700; cursor: pointer; transition: 0.15s; }
.source-picker-options button i { font-size: 1.8rem; color: var(--gold, #B84A2B); }
.source-picker-options button:hover { border-color: var(--gold, #B84A2B); background: var(--c-soft, #FBF3E6); }

/* Cắt khung ảnh bìa */
.crop-editor { width: min(420px, 100%); }
.crop-hint { margin: 10px 18px 0; font-size: 0.82rem; color: var(--c-muted, #4A3429); text-align: center; }
.crop-frame { position: relative; width: min(300px, 80vw); margin: 14px auto 0; overflow: hidden; border-radius: 8px; background: #111; cursor: grab; touch-action: none; box-shadow: 0 0 0 3px var(--gold, #B84A2B); }
.crop-frame.dragging { cursor: grabbing; }
.crop-frame img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; pointer-events: none; }
.crop-zoom { display: flex; align-items: center; gap: 10px; margin: 14px 18px 4px; color: var(--c-muted, #4A3429); }
.crop-zoom input { flex: 1; accent-color: var(--gold, #B84A2B); }
.image-picker-foot .crop-secondary { background: var(--c-sand, #E6D7BC); color: var(--c-muted, #4A3429); }

/* Lưới ảnh nhiều (kho ảnh trang chủ, album): ảnh chưa tải có khung giữ chỗ 3:4
   -> trình duyệt chỉ tải ảnh sắp cuộn tới, không tải cả trăm ảnh một lúc (tránh nghẽn mạng khi chuyển trang) */
.masonry-item img[data-full]:not([data-loaded]),
.albumdetail-item img[data-full]:not([data-loaded]) { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; background: var(--c-sand, #E6D7BC); }
