.galleryManager {
  display: flex;
  height: 100%;
  min-height: 0;
  position: relative;
  background: #f8f9fa;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.galleryManager #menu-toggle {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1002;
}

.galleryManager #overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

/* ====================== Container ====================== */
.gallery-container {
  display: flex;
  flex-direction: row-reverse;
  overflow: hidden;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

/* ====================== Photo Panel ====================== */
.photo-panel {
  flex: 3;
  display: flex;
  flex-direction: column;
  background: #fff;
  min-height: 0;
  position: relative;
}

.headerPanel {
  padding: 16px 20px;
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.folder-title {
  margin: 0;
  font-weight: 600;
  color: #2c3e50;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.photo-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 14px; /* فاصله یکسان سطر و ستون */
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
  align-content: start; /* مهم: جلوگیری از پخش شدن فاصله */
  justify-content: start;
}

.photo-grid img {
  width: 100%;
  height: 165px;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.photo-grid img:hover {
  transform: scale(1.04);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.photo-grid img.selected {
  border: 3px solid #3498db;
  padding: 4px;
}

/* ====================== Folder Panel ====================== */
.folder-panel {
  flex: 1.1;
  background: #2c3e50;
  color: #ecf0f1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid #34495e;
}

.folder-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #34495e;
  flex-shrink: 0;
}

.folder-header h5 {
  margin: 0;
  color: #fff;
  font-weight: 600;
}

.folder-search {
  padding: 16px 20px;
  flex-shrink: 0;
}

.folder-search input {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
}

.folder-search input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.folder-list-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 8px 12px;
}

.folder-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.folder-item {
  padding: 14px 16px;
  margin: 6px 4px;
  background: #34495e;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  position: relative;
}

.folder-item:hover {
  background: #3d566e;
  transform: translateX(-4px);
}

.folder-item.selectedFolder {
  background: #3498db;
  color: white;
}

.delete-btn {
  opacity: 0.7;
  transition: all 0.2s;
}

.folder-item:hover .delete-btn {
  opacity: 1;
}

/* Footer */
.footerPanel {
  padding: 16px 20px;
  background: #fff;
  border-top: 1px solid #e9ecef;
  text-align: center;
  flex-shrink: 0;
}

/* Empty & Loading */
.empty-state,
.loading-text {
  text-align: center;
  color: #888;
  padding: 60px 20px;
  font-size: 1.1rem;
}

.progress-text {
  display: block;
  text-align: center;
  color: #28a745;
  font-size: 0.9rem;
  margin-top: 6px;
}

/* ====================== Responsive ====================== */
@media (max-width: 992px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding: 16px;
  }

  .photo-grid img {
    height: 140px;
  }
}

.imageViewer {
  width: 128px;
  height: 158px;
  position: relative;
  background-color: darkolivegreen;
  border-radius: 0.267rem;
}

.imageViewer .loadfromgallery {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.imageViewer img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.imageViewer img {
  height: 124px;
}

.leftButton {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 48px;
  background-color: #444;
  opacity: 0.6;
  border: none !important;
}

.rightButton {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 48px;
  background-color: #444;
  opacity: 0.6;
  border: none !important;
}

@media (max-width: 768px) {
  .galleryManager #menu-toggle {
    display: block;
  }

  .gallery-container {
    flex-direction: column;
  }

  .folder-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    z-index: 1001;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.3);
  }

  .folder-panel.open {
    transform: translateX(0);
  }

  .photo-panel {
    width: 100%;
  }
  .leftButton,
  .rightButton {
    display: none;
  }
}
