/* ========================================
   GALLERY PAGE STYLES
   RTL | Mobile-First | Pixel Grid
   ======================================== */

/* ---- PAGE LAYOUT ---- */
.page-gallery {
  background: var(--c-bg);
}

/* ========================================
   TOOLBAR
   ======================================== */
.toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--c-bg-card);
  border-bottom: var(--px-border) solid var(--c-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.toolbar-inner {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 var(--px-gap-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

/* ---- FILTERS ---- */
.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  padding: 10px 0;
  -webkit-overflow-scrolling: touch;
}

.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  flex-shrink: 0;
  background: transparent;
  border: var(--px-border) solid var(--c-border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: var(--fw-med);
  color: var(--c-text-muted);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.filter-btn:active {
  transform: scale(0.95);
}

.filter-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
  font-weight: var(--fw-bold);
}

/* ---- SELECT MODE BUTTON ---- */
.btn-select-mode {
  flex-shrink: 0;
  background: transparent;
  border: var(--px-border) solid var(--c-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: var(--fw-med);
  color: var(--c-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  margin-left: 12px; /* يبعد عن حافة الشاشة يسار */
}

.btn-select-mode.active {
  background: var(--c-primary-dk);
  border-color: var(--c-primary-dk);
  color: #fff;
}

/* ---- BULK BAR ---- */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 0;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bulk-count {
  font-size: 0.85rem;
  font-weight: var(--fw-bold);
  color: var(--c-primary);
  min-width: 60px;
}

.btn-bulk-dl {
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: var(--fw-bold);
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  transition: background 0.15s;
}

.btn-bulk-dl:active { background: var(--c-primary-dk); }

.btn-bulk-cancel {
  background: transparent;
  border: var(--px-border) solid var(--c-border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--c-text-muted);
}

/* ========================================
   GALLERY MAIN
   ======================================== */
.gallery-main {
  max-width: 700px;
  margin: 0 auto;
  padding: var(--px-gap-lg) var(--px-gap) 80px;
}

/* ========================================
   GALLERY GRID
   ======================================== */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--px-border); /* pixel-thin gap */
  background: var(--c-border); /* border shows between cells */
  border: var(--px-border) solid var(--c-border);
  border-radius: var(--px-radius);
  overflow: hidden;
}

/* ---- GRID ITEM ---- */
.grid-item {
  background: var(--c-bg-card);
  position: relative;
  aspect-ratio: 1 / 1; /* SQUARE — same size always */
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.grid-item:active { opacity: 0.8; }

/* Image inside */
.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  pointer-events: none;
}

@media (hover: hover) {
  .grid-item:hover img {
    transform: scale(1.06);
  }
}

/* ---- SKELETON LOADER ---- */
.grid-item.skeleton {
  background: linear-gradient(90deg, #E4E7F0 25%, #F0F2F8 50%, #E4E7F0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  cursor: default;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- FADE-IN عند تحميل الصورة ---- */
.grid-item img {
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.3s ease;
}

.grid-item img.loaded {
  opacity: 1;
}

/* ---- CHECKBOX OVERLAY (select mode) ---- */
.item-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: var(--px-border) solid rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 2;
}

.item-check::after {
  content: '✓';
  color: #fff;
  font-size: 0.75rem;
  font-weight: var(--fw-bold);
  opacity: 0;
  transition: opacity 0.1s;
}

/* SELECT MODE — show checkboxes */
.select-mode .item-check {
  opacity: 1;
}

.grid-item.selected .item-check {
  background: var(--c-primary);
  border-color: var(--c-primary);
}

.grid-item.selected .item-check::after {
  opacity: 1;
}

/* Selected glow */
.grid-item.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(79,91,213,0.22);
  pointer-events: none;
  z-index: 1;
}

/* ---- DOWNLOAD QUICK BTN (shows on hover desktop) ---- */
.item-quick-dl {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: var(--px-border) solid rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 3;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

@media (hover: hover) {
  .grid-item:hover .item-quick-dl { opacity: 1; }
}

/* ---- TAG CHIP ---- */
.item-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--c-primary);
  color: #fff;
  font-size: 0.6rem;
  font-weight: var(--fw-bold);
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 2;
  opacity: 0.9;
}

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--c-text-muted);
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

/* ========================================
   LIGHTBOX
   ======================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.lightbox.open {
  opacity: 1;
  pointer-events: all;
}

.lb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12,8,4,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lb-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 500px;
  padding: 0 var(--px-gap-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Close */
.lb-close {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: var(--px-border) solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.15s;
}

.lb-close:active { background: rgba(255,255,255,0.25); }

/* Nav arrows */
.lb-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: var(--px-border) solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.15s;
}

.lb-nav:active { background: rgba(255,255,255,0.25); }

.lb-prev { right: 8px; }
.lb-next { left: 8px; }

/* Image */
.lb-img-wrap {
  width: 100%;
  max-height: 65dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.lb-img {
  width: 100%;
  max-height: 65dvh;
  object-fit: contain;
  border-radius: 10px;
  border: var(--px-border) solid rgba(255,255,255,0.1);
  transition: opacity 0.2s;
}

.lb-img.loading { opacity: 0; }

/* Loader */
.lb-loader {
  position: absolute;
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.lb-loader.show { display: block; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Footer */
.lb-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lb-label {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  font-weight: var(--fw-med);
}

.lb-actions {
  display: flex;
  gap: 8px;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: var(--fw-bold);
  border: var(--px-border) solid;
  transition: all 0.15s;
}

.btn-action:active { transform: scale(0.96); }

.btn-share {
  background: #2EAA72;
  border-color: #1E8A58;
  color: #fff;
}

.btn-share:active { background: #1E8A58; }

/* على الكمبيوتر نخفي Share ونظهر Download */
.btn-share { display: none; }
.btn-dl    { display: flex; }

/* على الجوال نعكس */
@media (hover: none) and (pointer: coarse) {
  .btn-share { display: flex; }
  .btn-dl    { display: none; }
}

.btn-dl {
  background: var(--c-primary);
  border-color: var(--c-primary-dk);
  color: #fff;
}

.btn-dl:active { background: var(--c-primary-dk); }

.btn-copy {
  background: transparent;
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}

.btn-copy:active { background: rgba(255,255,255,0.1); }

.btn-icon { font-size: 1rem; }
.btn-text { font-size: 0.88rem; }

/* ========================================
   RESPONSIVE
   ======================================== */
@media (min-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 700px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .lb-container { max-width: 560px; }
}

/* Touch swipe hint on mobile */
@media (max-width: 480px) {
  .lb-nav { display: none; }
  .lb-img-wrap { touch-action: pan-y; }
}
