/* ================= GỬI ẢNH: NÚT, BONG BÓNG ẢNH, TIẾN TRÌNH, XEM TOÀN MÀN HÌNH ================= */

/* ---------- Nút gửi ảnh trong ô nhập ---------- */
.image-btn {
  background: transparent;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 21px;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 1px;
  margin-left: -4px;
}
.image-btn:hover { color: var(--primary-color); background: #eef4ff; }
.image-btn:disabled { opacity: 0.5; cursor: default; background: transparent; color: var(--text-muted); }

/* ---------- Bong bóng ảnh ---------- */
.msg-item.has-image .msg-bubble {
  padding: 4px;
  gap: 4px;
}
.msg-item.has-image .msg-orig,
.msg-item.has-image .msg-trans-row {
  padding: 2px 8px 0;
}
.msg-item.has-image .msg-trans-row { margin: 0 0 2px; }
.msg-item.has-image .msg-time-bottom { padding: 0 6px 2px; }

.msg-image-link {
  position: relative;
  display: block;
  max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(110deg, #eef2f7 8%, #f8fafc 18%, #eef2f7 33%);
  background-size: 200% 100%;
  animation: imgShimmer 1.3s linear infinite;
  cursor: zoom-in;
  line-height: 0;
}
.msg-image-link.no-size {
  width: 240px;
  min-height: 140px;
}
@keyframes imgShimmer { to { background-position-x: -200%; } }
.msg-image-link.loaded { animation: none; background: transparent; }

.msg-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease, filter 0.2s ease;
}
.msg-image-link.no-size .msg-image { height: auto; max-height: 340px; }
.msg-image-link:hover .msg-image { transform: scale(1.02); }

/* Ảnh hỏng / không còn trên máy chủ */
.msg-image-link.broken {
  animation: none;
  background: #f1f5f9;
  cursor: default;
  min-height: 90px;
}
.msg-image-link.broken .msg-image { visibility: hidden; }
.msg-image-link.broken::after {
  content: "Ảnh không còn khả dụng";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--text-muted);
}

/* Đang tải lên */
.msg-image-link.uploading { cursor: progress; animation: none; }
.msg-image-link.uploading .msg-image { filter: brightness(0.72) saturate(0.9); }
.msg-image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.2;
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.msg-image-progress {
  width: 62%;
  max-width: 160px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  overflow: hidden;
}
.msg-image-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #ffffff;
  transition: width 0.2s ease;
}

/* Gửi thất bại */
.msg-image-link.failed { cursor: pointer; animation: none; }
.msg-image-link.failed .msg-image { filter: grayscale(0.6) brightness(0.55); }
.msg-image-failed {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: 0 10px;
}
.msg-image-failed i { font-size: 26px; color: #fecaca; }
.msg-image-failed-hint { font-size: 11px; font-weight: 500; opacity: 0.85; }

/* ---------- Kéo thả ảnh vào khung chat ---------- */
.message-feed-scroll.drag-over {
  position: relative;
  outline: 2px dashed var(--primary-color);
  outline-offset: -10px;
  background-color: rgba(37, 99, 235, 0.04);
}
.message-feed-scroll.drag-over::after {
  content: "Thả ảnh vào đây để gửi";
  position: sticky;
  bottom: 18px;
  align-self: center;
  margin-top: auto;
  background: var(--primary-color);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  pointer-events: none;
}

/* ---------- Xem ảnh toàn màn hình ---------- */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  cursor: zoom-out;
  animation: ivFadeIn 0.18s ease;
}
.image-viewer.hidden { display: none; }
@keyframes ivFadeIn { from { opacity: 0; } to { opacity: 1; } }

.iv-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
  animation: ivZoomIn 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
}
@keyframes ivZoomIn { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }

.iv-toolbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 14px;
  display: flex;
  gap: 8px;
}
.iv-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.15s;
}
.iv-btn:hover { background: rgba(255, 255, 255, 0.24); transform: scale(1.05); }

body.image-viewer-open { overflow: hidden; }

/* ---------- Điện thoại ---------- */
@media (max-width: 768px) {
  .image-btn { width: 32px; height: 32px; font-size: 20px; margin-left: -6px; }
  .msg-image-link { max-width: min(100%, 68vw); }
  .msg-image-link.no-size { width: 62vw; }
}
