/* ===== Ghép ảnh vào frame: dùng chung cho trang quản lý và trang khách =====
   Tên lớp đều có tiền tố fr- để không đụng kiểu sẵn có của hai trang. */

/* Hộp hỏi của thư viện phải nổi trên khung ghép frame (khung ghép nằm trên album) */
.swal2-container { z-index: 5000 !important; }

.fr-modal { position: fixed; inset: 0; background: #fafafa; z-index: 3200; display: flex; flex-direction: column; font-family: 'Inter', sans-serif; color: #111; }
.fr-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: #fff; border-bottom: 1px solid #e5e5e5; flex: none; }
.fr-head h3 { flex: 1; margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.fr-x { background: none; border: none; font-size: 26px; line-height: 1; color: #666; cursor: pointer; padding: 4px 12px; min-width: 44px; min-height: 44px; font-family: 'Inter', sans-serif; }
.fr-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.fr-wrap { max-width: 980px; margin: 0 auto; padding: 16px; box-sizing: border-box; }

.fr-card { background: #fff; border: 1px solid #e5e5e5; border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.fr-card h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; margin: 0 0 12px; }
.fr-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fr-btn { padding: 10px 14px; border-radius: 10px; border: 1px solid #e5e5e5; background: #fff; font: 600 12px 'Inter', sans-serif; cursor: pointer; color: #111; white-space: nowrap; }
.fr-btn.solid { background: #111; color: #fff; border-color: #111; }
.fr-btn.danger { color: #ef4444; border-color: #e5e5e5; }
.fr-btn:disabled { opacity: .45; cursor: not-allowed; }
.fr-big { width: 100%; padding: 15px; font-size: 13px; text-transform: uppercase; letter-spacing: .3px; }
.fr-hint { font-size: 12px; color: #666; line-height: 1.6; margin: 8px 0 0; }
.fr-card input[type=text], .fr-card input[type=number] { padding: 9px 10px; border: 1px solid #e5e5e5; border-radius: 8px; font: 13px 'Inter', sans-serif; width: 100%; box-sizing: border-box; }
.fr-label { font-size: 11px; font-weight: 600; color: #666; display: block; margin-bottom: 4px; }
.fr-grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
/* Nút bật/tắt cơ sở: dùng nút thay ô tích vì trang khách có kiểu chung cho mọi
   ô nhập (đệm 14px, cách dưới 15px), ô tích dính kiểu đó là lệch hẳn */
.fr-chip.on { background: #111; color: #fff; border-color: #111; }
.fr-chip.on::before { content: '✓ '; }
/* Gỡ kiểu ô nhập chung của trang khách khỏi thanh phóng to */
.fr-modal input[type=range] { padding: 0; margin: 0; border: none; box-shadow: none; height: auto; background: none; }

/* Danh sách frame */
.fr-flist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fr-fwrap { position: relative; }
.fr-fitem { width: 100%; border: 1px solid #e5e5e5; border-radius: 12px; padding: 8px; background: #fff; cursor: pointer; text-align: left; font-family: 'Inter', sans-serif; color: #111; display: block; box-sizing: border-box; }
.fr-fitem .fr-fimg { display: block; width: 100%; aspect-ratio: 3/2; border-radius: 8px; overflow: hidden;
                     background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/16px 16px; }
/* isolation: các lớp ảnh chỉ xếp chồng với nhau trong khung, không đè lên nút ✕ / ⠿ */
.fr-fitem .fr-fimg { position: relative; isolation: isolate; }
.fr-fdel { z-index: 5; }
/* Frame cao cấp: nhãn bên admin, khoá bên khách */
.fr-cao { display: inline-block; margin-left: 4px; padding: 1px 6px; border-radius: 6px; background: #111; color: #fff; font-size: 10px; font-weight: 700; vertical-align: middle; }
.fr-fitem.khoa { cursor: default; }
.fr-fitem.khoa .fr-fimg img { opacity: .45; }
.fr-lock { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; }
/* Ổ khoá co theo ảnh thu nhỏ: khoảng 1/5 bề ngang, không quá to trên điện thoại nhỏ */
.fr-lock svg { width: clamp(26px, 20%, 44px); height: auto; aspect-ratio: 1; padding: clamp(6px, 4%, 10px); box-sizing: border-box; border-radius: 50%; background: rgba(17,17,17,.82); stroke: #fff; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fr-fitem .fr-fimg img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
/* Kéo ⠿ để xếp thứ tự frame khách thấy */
.fr-fgrip { position: absolute; top: 6px; left: 6px; z-index: 3; width: 30px; height: 30px; border-radius: 8px; border: 1px solid #e5e5e5; background: #fff;
            display: flex; align-items: center; justify-content: center; font-size: 16px; color: #666; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.fr-fwrap.drag .fr-fitem { border-color: #111; box-shadow: 0 6px 18px rgba(0,0,0,.15); }
.fr-fitem b { display: block; font-size: 12px; margin-top: 6px; }
.fr-fitem span.fr-meta { display: block; font-size: 11px; color: #666; }
.fr-fitem.off { opacity: .5; }
.fr-fdel { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid #e5e5e5; background: #fff;
           color: #ef4444; font: 700 16px 'Inter', sans-serif; cursor: pointer; line-height: 1; }

/* Khung làm việc: chặn cuộn trang khi kéo trên khung */
.fr-stage { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none;
            background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/20px 20px; border-radius: 8px; overflow: hidden; }
.fr-stage img.fr-frame { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Ô bên quản lý: ảnh giả (để thấy frame nằm trên hay dưới ảnh), frame, khung điều khiển */
.fr-efill { position: absolute; background: repeating-linear-gradient(45deg, #a1a1aa 0 14px, #d4d4d8 14px 28px); }
.fr-eslot { position: absolute; border: 2px dashed #18181b; cursor: move; --hs: 16px; box-sizing: border-box; }
/* Ô đang chọn nổi lên trên: ô to ra chạm ô bên cạnh thì chấm kéo không bị che */
.fr-eslot.sel { border-style: solid; z-index: 2; }
.fr-eslot .fr-num { position: absolute; left: 4px; top: 4px; background: #18181b; color: #fff; font: 700 11px 'Inter', sans-serif; padding: 2px 6px; border-radius: 6px; }
/* Chấm kéo như Canva: 4 góc đổi cả hai chiều, 4 cạnh chỉ đổi một chiều */
.fr-h { position: absolute; width: var(--hs); height: var(--hs); background: #fff; border: 2px solid #18181b; border-radius: 50%;
        margin: calc(var(--hs) / -2) 0 0 calc(var(--hs) / -2); touch-action: none; box-sizing: border-box; }
.fr-h.side { border-radius: 4px; }
.fr-h.n, .fr-h.s { width: calc(var(--hs) * 1.6); margin-left: calc(var(--hs) * -0.8); }
.fr-h.e, .fr-h.w { height: calc(var(--hs) * 1.6); margin-top: calc(var(--hs) * -0.8); }
.fr-h.rt { cursor: grab; background: #18181b; }
.fr-h.rt::before { content: ''; position: absolute; left: 50%; bottom: 100%; width: 2px; height: 14px; margin-left: -1px; background: #18181b; }

/* Ô bên khách: không viền, ô trống có nền xám và dấu cộng */
.fr-cslot { position: absolute; overflow: hidden; background: #e5e5e5; box-sizing: border-box; }
.fr-cslot img { position: absolute; left: 50%; top: 50%; max-width: none; pointer-events: none; }
.fr-cmark { position: absolute; pointer-events: none; display: flex; align-items: center; justify-content: center; }
.fr-plus { color: #777; font-family: 'Inter', sans-serif; font-weight: 200; line-height: 1; display: flex; align-items: center; justify-content: center; }

.fr-tool { display: none; margin-top: 12px; }
.fr-tool.on { display: block; }
.fr-modal input[type=range] { width: 100%; accent-color: #111; }

/* Bảng chọn ảnh trong lượt chụp */
.fr-pk { position: fixed; inset: 0; background: #fff; z-index: 3300; display: flex; flex-direction: column; font-family: 'Inter', sans-serif; color: #111; }
/* Frame thu nhỏ có số ô: chỉ hiện khi đang chọn ảnh, để khách biết số nào là ô nào */
.fr-mini { position: relative; width: min(100%, 300px); margin: 10px auto 0; border-radius: 6px; overflow: hidden; flex: none;
           background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/12px 12px; }
.fr-mini img { position: absolute; inset: 0; width: 100%; height: 100%; }
.fr-mini .fr-mslot { position: absolute; display: flex; align-items: center; justify-content: center; box-sizing: border-box; }
.fr-mini .fr-mslot b { background: #fff; color: #111; border: 1px solid #111; font: 700 11px/1 'Inter', sans-serif; min-width: 20px; height: 20px; padding: 0 5px;
                       border-radius: 10px; display: flex; align-items: center; justify-content: center; box-sizing: border-box; }
/* Ô đang chọn: chỉ vòng số chuyển đen, không tô tối cả ô */
.fr-mini .fr-mslot.on b { background: #111; color: #fff; }
.fr-pk-grid { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(3, 1fr);
              grid-auto-rows: max-content; gap: 10px; padding: 12px; align-content: start; }
@media (min-width: 560px) { .fr-pk-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .fr-pk-grid { grid-template-columns: repeat(5, 1fr); } }
/* Ô ảnh không tự cắt phần thừa: bảng bị ép vừa chiều cao màn hình, ô có cắt
   thừa thì trình duyệt được bóp hàng lại, ảnh chồng lên nhau và chạm ảnh này
   trúng ảnh kia. Phần cắt để cho khung ảnh bên trong. */
.fr-pk-item { position: relative; display: block; width: 100%; padding: 0; border: 2px solid transparent; border-radius: 12px; background: #fafafa; cursor: pointer; }
.fr-pk-ph { display: block; width: 100%; aspect-ratio: 3/2; border-radius: 10px; overflow: hidden; }
.fr-pk-ph img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* Ảnh đã chọn: chỉ vòng số ô chuyển đen, không viền đen quanh ảnh */
.fr-pk-tick { position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; border: 2px solid #fff; box-sizing: border-box;
              background: rgba(0,0,0,.25); color: #fff; font: 700 12px/22px 'Inter', sans-serif; text-align: center; }
.fr-pk-item.on .fr-pk-tick { background: #111; }
.fr-pk-used { position: absolute; left: 6px; bottom: 6px; background: #111; color: #fff; font: 700 11px 'Inter', sans-serif; padding: 3px 8px; border-radius: 10px; }
/* Hai nguồn ảnh: lượt chụp và ảnh trong máy */
.fr-tabs { display: flex; gap: 8px; padding: 10px 12px 0; flex: none; }
.fr-tab { flex: 1; padding: 10px; border: 1px solid #e5e5e5; border-radius: 10px; background: #fff; font: 600 12px 'Inter', sans-serif; color: #111; cursor: pointer; min-height: 44px; }
.fr-tab.on { background: #111; color: #fff; border-color: #111; }
.fr-pk-add { border: 2px dashed #d4d4d8; cursor: pointer; }
.fr-pk-add .fr-pk-ph { display: flex; align-items: center; justify-content: center; font: 600 13px 'Inter', sans-serif; color: #111; }
.fr-pk-foot { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid #e5e5e5; }
.fr-pk-foot span { flex: 1; font-size: 13px; color: #666; }

.fr-res img { width: 100%; border-radius: 8px; border: 1px solid #e5e5e5; display: block; }
.fr-bar { height: 8px; background: #f4f4f5; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.fr-bar span { display: block; height: 100%; width: 0; background: #111; transition: width .3s; }
.fr-hidden { display: none !important; }

/* Bảng lớp của frame (admin): trên cùng ở đầu danh sách, kéo ⠿ để đổi thứ tự */
.fa-layers { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.fa-lrow { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #e5e5e5; border-radius: 10px; padding: 6px 8px; }
.fa-lrow.drag { border-color: #111; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.fa-lh { cursor: grab; touch-action: none; font-size: 18px; color: #888; padding: 6px 4px; user-select: none; -webkit-user-select: none; }
.fa-lthumb { width: 46px; height: 34px; border-radius: 6px; flex: none; overflow: hidden; display: flex; align-items: center; justify-content: center;
             background: repeating-conic-gradient(#e5e5e5 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.fa-lthumb img { width: 100%; height: 100%; object-fit: contain; }
.fa-lthumb.ph { background: repeating-linear-gradient(45deg, #a1a1aa 0 6px, #d4d4d8 6px 12px); }
.fa-lname { flex: 1; min-width: 60px; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fa-layers input.fa-lop { width: 90px; flex: none; accent-color: #111; }
.fa-lpct { font-size: 11px; color: #666; width: 34px; text-align: right; }
.fa-lbtn { padding: 6px 9px; font-size: 12px; }
@media (max-width: 560px) { .fa-layers input.fa-lop { width: 60px; } }

/* ===== Màn ghép bên khách: dồn chỗ cho frame trên điện thoại ===== */
.fk-hbtn { padding: 7px 12px; font-size: 12px; }
#fk-modal[data-step=comp] .fr-wrap { padding: 8px 8px 0; }
.fk-comp { padding: 0 !important; border: 0 !important; background: transparent !important; margin: 0 !important; }
.fk-comp .fr-stage { margin: 0 auto; touch-action: manipulation; }
.fk-tip { text-align: center; margin: 8px 0 0; }
.fk-rot { text-align: center; font-size: 12px; font-weight: 600; color: #111; background: #fff; border: 1px dashed #d4d4d8; border-radius: 10px; padding: 8px; margin-bottom: 8px; }
/* Thanh dưới luôn hiện: tiến độ + Ghép xong, không phải cuộn tìm nút */
/* Thanh dưới dính sát đáy màn hình */
.fk-foot { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e5e5e5; z-index: 6; }
#fk-modal[data-step=comp] .fr-body { padding-bottom: 90px; }
.fk-foot span { flex: 1; font-size: 13px; font-weight: 600; color: #444; }
.fk-foot .fr-btn { padding: 14px 22px; font-size: 13px; text-transform: uppercase; }

/* Màn chỉnh một ô: ô to giữa màn, frame xung quanh mờ đi */
.fk-ed { position: fixed; inset: 0; z-index: 3250; background: #fafafa; display: none; flex-direction: column; font-family: 'Inter', sans-serif; color: #111; }
.fk-ed.on { display: flex; }
.fk-nav { padding: 8px 14px; font-size: 18px; line-height: 1; }
.fk-ed-view { flex: 1; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: #e5e5e5; min-height: 200px; }
.fk-ed-in { position: absolute; }
.fk-ed-in .fr-frame { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fk-ed-hole { position: absolute; z-index: 50; pointer-events: none; box-shadow: 0 0 0 9999px rgba(250, 250, 250, .62); }
.fk-ed-tools { flex: none; background: #fff; border-top: 1px solid #e5e5e5; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.fk-ed-tools input[type=range] { width: 100%; accent-color: #111; }
/* Xoay ngang: công cụ sang bên phải, ô ảnh chiếm phần còn lại */
@media (orientation: landscape) and (max-height: 520px) {
    .fk-ed.on { display: grid; grid-template-columns: 1fr 260px; grid-template-rows: auto 1fr; }
    .fk-ed .fr-head { grid-column: 1 / -1; padding: 6px 12px; }
    .fk-ed-tools { border-top: 0; border-left: 1px solid #e5e5e5; overflow-y: auto; }
    /* Màn ghép xoay ngang: thanh đầu gọn, frame bên trái cao hết cỡ, nút bên phải */
    #fk-modal .fr-head { padding: 6px 12px; }
    #fk-modal[data-step=comp] .fr-wrap { max-width: none; padding: 8px 10px 0; }
    #fk-modal[data-step=comp] .fk-comp { display: flex; align-items: flex-start; gap: 10px; }
    .fk-comp .fr-stage { margin: 0; flex: none; }
    #fk-modal[data-step=comp] .fr-body { padding-bottom: 0; }
    .fk-foot { position: static; flex-direction: column; align-items: stretch; width: 160px; flex: none; margin: 0; border: 1px solid #e5e5e5; border-radius: 12px; padding: 12px; }
    .fk-tip, .fk-rot { display: none !important; }
}

/* Bộ lọc màu (admin) */
.fr-select { height: 38px; border: 1px solid #d4d4d8; border-radius: 8px; padding: 0 10px; font: 500 13px 'Inter', sans-serif; background: #fff; max-width: 180px; }
.ft-prev { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.ft-prev canvas { width: 100%; height: auto; border-radius: 8px; display: block; background: #e5e5e5; }
.ft-sl { margin-bottom: 8px; }
.ft-sl input[type=range] { width: 100%; }
@media (max-width: 600px) { .ft-prev { grid-template-columns: 1fr; } }

/* Bên khách: chỗ trong suốt của frame hiện nền xám trơn thay cho ô lưới.
   Ô lưới chỉ có ích cho quản lý nhìn chỗ nào trong suốt; khách nhìn rối mắt. */
#fk-modal .fr-fimg, #fk-modal .fr-stage, #fk-pk .fr-mini { background: #e5e5e5; }

@media (hover: none) and (pointer: coarse) {
    .fr-btn { min-height: 44px; }
    .fr-card input[type=text], .fr-card input[type=number] { font-size: 16px; }
    .fr-eslot { --hs: 26px; }
}
@media (max-width: 560px) { .fr-grid5 { grid-template-columns: repeat(3, 1fr); } }

/* Tiêu đề nhóm frame trong danh sách khách chọn */
.fr-nhom-ti { grid-column: 1 / -1; font: 700 12px 'Inter', sans-serif; text-transform: uppercase; letter-spacing: .5px; color: #111; margin: 6px 0 -2px; }
.fr-nhom-ti span { font-weight: 500; text-transform: none; letter-spacing: 0; color: #71717a; }

/* Đang ghép frame: không cho chụm phóng cả trang (frame-khach.js fkKhoaPhong) */
body.fk-mo, body.fk-mo .fr-modal, body.fk-mo .fk-ed, body.fk-mo .fr-pk { touch-action: pan-x pan-y; }
