/**
 * DMDC — Ảnh So sánh Trước/Sau (Before / After)
 * Dùng CHUNG cho: vùng soạn thảo CKEditor (contentsCss) và giao diện người dùng (theme master).
 * Khối do CKEditor chèn ra là HTML thuần + data-attr, runtime JS chỉ gắn hành vi kéo.
 * Không phụ thuộc Bootstrap để chạy được cả trong iframe editor.
 */

.dmdc-ba {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 20px auto;
  border-radius: 10px;
  overflow: hidden;
  background: #f1f1f1;
  /* chống kéo-chọn văn bản khi rê thanh trượt */
  user-select: none;
  -webkit-user-select: none;
}

.dmdc-ba-wrap {
  position: relative;
  width: 100%;
  line-height: 0;          /* bỏ khoảng trắng dưới ảnh */
  overflow: hidden;
  touch-action: pan-y;      /* cho cuộn dọc, chặn cuộn ngang khi kéo */
}

/* Ảnh nền = ảnh TRƯỚC: quyết định chiều cao khối */
.dmdc-ba-before {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

/* Lớp phủ = ảnh SAU, bị cắt theo vị trí thanh trượt */
.dmdc-ba-after-wrap {
  position: absolute;
  inset: 0;
  width: 50%;              /* JS cập nhật; 50% là mặc định khi chưa có JS */
  overflow: hidden;
  will-change: width;
}

/* Ảnh SAU phải rộng đúng bằng khối cha để không bị co khi cắt */
.dmdc-ba-after {
  display: block;
  height: 100%;
  width: auto;
  max-width: none;
  object-fit: cover;
  pointer-events: none;
}

/* Thanh kéo */
.dmdc-ba-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;               /* JS cập nhật */
  width: 2px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
  transform: translateX(-1px);
  cursor: ew-resize;
  z-index: 3;
}

.dmdc-ba-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border-radius: 50%;
  background: #fff url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='15 18 9 12 15 6'/%3E%3C/svg%3E") no-repeat 2px center,
              #fff url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E") no-repeat 14px center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

/* Nhãn Trước / Sau */
.dmdc-ba-label {
  position: absolute;
  bottom: 12px;
  z-index: 2;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .2px;
  pointer-events: none;
}

.dmdc-ba-label--before { left: 12px; }
.dmdc-ba-label--after  { right: 12px; }

.dmdc-ba-caption {
  margin: 8px 2px 0;
  font-size: 14px;
  color: #666;
  text-align: center;
  line-height: 1.5;
}

/* Trong vùng soạn thảo: viền nhắc đây là 1 khối, click đúp để sửa */
.cke_editable .dmdc-ba {
  outline: 2px dashed #c7d2fe;
  outline-offset: 2px;
  cursor: pointer;
}

@media (max-width: 575.98px) {
  .dmdc-ba-label { font-size: 12px; padding: 3px 10px; bottom: 8px; }
  .dmdc-ba-handle::after { width: 32px; height: 32px; margin: -16px 0 0 -16px; background-size: 18px, 18px; }
}
