/* ═══════════════════════════════════════════
   gallery.css — Góc ảnh kỷ niệm 📸
   Khu vực riêng: đăng ảnh, xem, xoá trực tiếp qua server
   ═══════════════════════════════════════════ */

#gallery {
  position: relative;
  padding: 4rem 1rem 5rem;
  background: transparent;
  z-index: 4;
}

/* Backdrop mờ để chữ dễ đọc trên nền động (đồng nhất với các section khác) */
#gallery::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,250,247,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 0;
  transition: background 0.4s ease;
}
html.dark #gallery::before {
  background: rgba(10,6,8,0.62);
}
html.dark #gallery { background: transparent; }
#gallery > * { position: relative; z-index: 1; }

.gallery-wrap {
  max-width: 980px;
  margin: 0 auto;
}

/* ─── Dropzone đăng ảnh ─── */
.gallery-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2.2rem 1.5rem;
  border: 1.5px dashed var(--petal);
  border-radius: 20px;
  background: rgba(255,192,203,0.06);
  cursor: pointer;
  text-align: center;
  transition: background 0.25s, border-color 0.25s, transform 0.2s;
  margin-bottom: 2.2rem;
}
.gallery-dropzone:hover {
  background: rgba(255,192,203,0.14);
  border-color: var(--blush);
  transform: translateY(-2px);
}
.gallery-dropzone.drag-over {
  background: rgba(242,167,187,0.22);
  border-color: var(--blush);
  transform: scale(1.01);
}
.gallery-dropzone-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(255,192,203,0.35), rgba(242,167,187,0.45));
  color: var(--rose-gold);
  flex-shrink: 0;
}
.gallery-dropzone-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.1rem;
  font-style: italic;
  color: var(--rose-gold);
}
.gallery-dropzone-sub {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--mauve);
  opacity: 0.75;
}
html.dark .gallery-dropzone {
  background: rgba(242,167,187,0.05);
}
html.dark .gallery-dropzone:hover,
html.dark .gallery-dropzone.drag-over {
  background: rgba(242,167,187,0.12);
}

/* ─── Grid ảnh ─── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.gallery-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  box-shadow: 0 4px 20px rgba(201,132,142,0.12);
  cursor: pointer;
  transition: transform 0.25s, box-shadow 0.25s;
  animation: fadeUp 0.5s ease both;
}
.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(201,132,142,0.24);
}
.gallery-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
.gallery-card:hover img { transform: scale(1.06); }

/* Overlay gradient + caption khi hover */
.gallery-card-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 0.8rem 0.6rem;
  background: linear-gradient(0deg, rgba(20,8,12,0.75) 0%, rgba(20,8,12,0) 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.gallery-card:hover .gallery-card-overlay { opacity: 1; }
.gallery-card-caption {
  font-family: 'Lora', serif;
  font-size: 0.76rem;
  color: #fff;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Nút xoá — luôn nằm góc trên phải, hiện rõ khi hover */
.gallery-delete-btn {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(20,8,12,0.5);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.2s, transform 0.2s, background 0.2s;
  z-index: 2;
}
.gallery-card:hover .gallery-delete-btn {
  opacity: 1;
  transform: scale(1);
}
.gallery-delete-btn:hover {
  background: rgba(224,60,90,0.85);
}

/* Badge tác giả nhỏ góc trên trái */
.gallery-author-badge {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  font-size: 0.62rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  color: #fff;
  background: rgba(20,8,12,0.45);
  padding: 2px 8px;
  border-radius: 50px;
  letter-spacing: 0.03em;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.gallery-card:hover .gallery-author-badge { opacity: 1; }

/* Uploading placeholder card */
.gallery-card.uploading {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}
.gallery-card.uploading .gallery-spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid rgba(242,167,187,0.3);
  border-top-color: var(--blush);
  animation: gallery-spin 0.8s linear infinite;
}
@keyframes gallery-spin { to { transform: rotate(360deg); } }

/* Empty state */
.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2.5rem 0;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.9rem;
  color: var(--mauve);
  opacity: 0.75;
}

/* ─── Upload composer modal (giống ngôn ngữ thiết kế Write Letter) ─── */
.gallery-upload-overlay {
  position: fixed;
  inset: 0;
  z-index: 2200;
  background: rgba(30, 8, 16, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.gallery-upload-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.gallery-upload-board {
  position: relative;
  width: min(560px, calc(100vw - 2.4rem));
  max-height: 88vh;
  background: var(--bg-letter-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  box-shadow:
    0 12px 60px rgba(201,132,142,0.22),
    0 2px 12px rgba(201,132,142,0.12),
    inset 0 0 0 1px rgba(255,255,255,0.55);
  padding: 1.8rem 1.8rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow: hidden;

  opacity: 0;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.35s cubic-bezier(0.4,0,0.2,1),
              transform 0.35s cubic-bezier(0.34,1.3,0.64,1);
}
.gallery-upload-overlay.active .gallery-upload-board {
  opacity: 1;
  transform: translateY(0) scale(1);
}
html.dark .gallery-upload-board {
  background: var(--bg-letter-card);
  border-color: rgba(242,167,187,0.14);
  box-shadow: 0 12px 60px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(242,167,187,0.06);
}

/* Previews của các ảnh sắp đăng */
.gallery-preview-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.5rem;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 0.2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--petal) transparent;
}
.gallery-preview-list::-webkit-scrollbar { width: 3px; }
.gallery-preview-list::-webkit-scrollbar-thumb { background: var(--petal); border-radius: 2px; }

.gallery-preview-item {
  position: relative;
  aspect-ratio: 1/1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-card);
}
.gallery-preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-preview-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(20,8,12,0.6);
  color: #fff;
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

/* Author pills tái dùng ngôn ngữ .write-author-pill nhưng namespaced riêng để tránh xung đột style */
.gallery-author-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.gallery-author-label {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--mauve);
  letter-spacing: 0.04em;
  opacity: 0.85;
  white-space: nowrap;
}
.gallery-author-pills { display: flex; gap: 0.5rem; }
.gallery-author-pill {
  display: flex;
  align-items: center;
  gap: 0.38rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.8rem;
  color: var(--soft-ink);
  background: rgba(255,192,203,0.08);
  border: 1.5px solid var(--border-card);
  border-radius: 50px;
  padding: 0.3rem 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.gallery-author-pill:hover {
  background: rgba(255,192,203,0.18);
  border-color: rgba(242,167,187,0.5);
  color: var(--rose-gold);
}
.gallery-author-pill.active {
  background: rgba(242,167,187,0.18);
  border-color: var(--blush);
  color: var(--rose-gold);
}

.gallery-caption-input {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  background: rgba(255,192,203,0.04);
  border: 1.5px solid var(--border-card);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  font-family: 'Lora', serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s, background 0.2s;
}
.gallery-caption-input::placeholder { color: var(--mauve); opacity: 0.5; font-style: italic; }
.gallery-caption-input:focus {
  border-color: rgba(242,167,187,0.6);
  background: rgba(255,192,203,0.06);
}
html.dark .gallery-caption-input { background: rgba(255,192,203,0.03); color: var(--ink); }

.gallery-upload-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.2rem;
}
.gallery-upload-progress {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.72rem;
  color: var(--mauve);
  opacity: 0.8;
}
.gallery-btn-cancel {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--mauve);
  background: none;
  border: 1px solid var(--border-card);
  border-radius: 50px;
  padding: 0.42rem 1rem;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s, background 0.2s;
}
.gallery-btn-cancel:hover { opacity: 1; background: rgba(255,192,203,0.1); }
.gallery-btn-submit {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  color: var(--bg-letter-card);
  background: var(--rose-gold);
  border: 1px solid transparent;
  border-radius: 50px;
  padding: 0.42rem 1.15rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}
.gallery-btn-submit:hover { background: var(--blush); transform: translateY(-1px); }
.gallery-btn-submit[disabled] { opacity: 0.6; cursor: wait; }

/* ─── Lightbox xem ảnh full ─── */
.gallery-lightbox-overlay {
  position: fixed; inset: 0;
  background: rgba(20,8,12,0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10050;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.gallery-lightbox-overlay.active { opacity: 1; pointer-events: auto; }
.gallery-lightbox-card {
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  transform: scale(0.94);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.gallery-lightbox-overlay.active .gallery-lightbox-card { transform: scale(1); }
.gallery-lightbox-card img {
  max-width: 92vw;
  max-height: 70vh;
  border-radius: 16px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.4);
  object-fit: contain;
}
.gallery-lightbox-caption {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
  font-style: italic;
  color: #fff;
  text-align: center;
  max-width: 560px;
}
.gallery-lightbox-meta {
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.gallery-lightbox-actions {
  display: flex;
  gap: 0.6rem;
}
.gallery-lightbox-delete,
.gallery-lightbox-close {
  display: flex; align-items: center; gap: 0.35rem;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.78rem;
  padding: 0.4rem 1rem;
  border-radius: 50px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: #fff;
  transition: background 0.2s, transform 0.15s;
}
.gallery-lightbox-delete:hover { background: rgba(224,60,90,0.75); }
.gallery-lightbox-close:hover  { background: rgba(255,255,255,0.22); }
.gallery-lightbox-delete:hover, .gallery-lightbox-close:hover { transform: translateY(-1px); }

@media (max-width: 480px) {
  .gallery-upload-board { padding: 1.4rem 1.2rem 1.1rem; border-radius: 18px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.7rem; }
}
