/**
 * StackPrompt Gallery (Folder Tree + Image Grid)
 */
.gallery-page {
  --g-bg: #0f172a;
  --g-card: #1e293b;
  --g-border: #334155;
  --g-text: #e2e8f0;
  --g-muted: #94a3b8;
  --g-accent: #3b82f6;
  min-height: 100vh;
  background: var(--g-bg);
  color: var(--g-text);
  padding: 1rem;
}
.gallery-page .gallery-inner {
  max-width: 1400px;
  margin: 0 auto;
}
.gallery-page h1 {
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
}

.gallery-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
}
.gallery-tree-pane,
.gallery-main-pane {
  background: var(--g-card);
  border: 1px solid var(--g-border);
  border-radius: 8px;
}
.gallery-tree-pane {
  padding: 0.75rem;
  min-height: 70vh;
}
.gallery-main-pane {
  padding: 0.75rem;
}
.gallery-tree-header,
.gallery-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.gallery-tree-header h2,
.gallery-main-header h2 {
  margin: 0;
  font-size: 1rem;
}
.gallery-shortcut-hint {
  margin: -0.1rem 0 0.55rem;
  color: var(--g-muted);
  font-size: 0.74rem;
  line-height: 1.45;
}
.gallery-shortcut-hint kbd {
  display: inline-block;
  padding: 0.02rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--g-border);
  background: rgba(15, 23, 42, 0.65);
  color: var(--g-text);
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.gallery-folder-tree {
  max-height: calc(70vh - 2.5rem);
  overflow: auto;
}
.gallery-tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.gallery-tree-item {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--g-muted);
  user-select: none;
}
.gallery-tree-item .folder-name {
  display: inline-block;
  max-width: 100%;
}
.gallery-tree-item.is-renaming {
  background: rgba(59, 130, 246, 0.15);
}
.gallery-tree-item.renamed {
  animation: galleryRenameFlash 0.25s ease;
}
@keyframes galleryRenameFlash {
  0% { background: #1e293b; }
  100% { background: rgba(59, 130, 246, 0.15); }
}
.folder-rename-input {
  width: 100%;
  padding: 0.25rem 0.4rem;
  border: 1px solid #60a5fa;
  border-radius: 4px;
  background: #0f172a;
  color: #fff;
  font-size: 0.85rem;
  box-sizing: border-box;
}
.folder-rename-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}
.gallery-tree-item:hover {
  color: var(--g-text);
  background: rgba(59, 130, 246, 0.15);
}
.gallery-tree-item.active {
  color: #fff;
  background: rgba(59, 130, 246, 0.35);
}
.gallery-tree-item.gallery-tree-item-drag-over {
  color: #fff;
  background: #334155;
  outline: 2px dashed var(--g-accent);
  outline-offset: 2px;
}

.gallery-tree-section-label {
  list-style: none;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--g-muted);
  padding: 0.55rem 0.5rem 0.2rem;
  margin-top: 0.15rem;
  pointer-events: none;
  user-select: none;
  opacity: 0.85;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.9rem;
}
.gallery-card {
  background: var(--g-card);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.gallery-card[draggable="true"] {
  cursor: grab;
}
.gallery-card[draggable="true"]:active {
  cursor: grabbing;
}
.gallery-card.gallery-card-dragging {
  opacity: 0.55;
}

.gallery-card.gallery-card-selected {
  outline: 2px solid var(--g-accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}
.gallery-card-thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  background: var(--g-bg);
}
.gallery-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}
.gallery-card-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem;
  border-top: 1px solid var(--g-border);
}
.gallery-card-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: var(--g-bg);
  color: var(--g-text);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-card-btn:hover { background: var(--g-border); }
.gallery-card-btn.fav.active { color: #f43f5e; }
.gallery-card-meta {
  padding: 0.35rem 0.5rem 0.5rem;
  font-size: 0.78rem;
  color: var(--g-muted);
  text-align: center;
}
.gallery-seed-link { cursor: pointer; user-select: none; }
.gallery-seed-link:hover { color: var(--g-text); }
.gallery-empty {
  text-align: center;
  color: var(--g-muted);
  padding: 3rem 1rem;
}

.gallery-context-menu {
  position: fixed;
  z-index: 2000;
  background: var(--g-card);
  border: 1px solid var(--g-border);
  border-radius: 6px;
  min-width: 140px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.gallery-context-menu button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--g-text);
  cursor: pointer;
  padding: 0.55rem 0.7rem;
}
.gallery-context-menu button:hover {
  background: rgba(59, 130, 246, 0.2);
}
.gallery-context-menu button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.gallery-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.gallery-modal-overlay[hidden] {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
}
.gallery-modal {
  background: var(--g-card);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  padding: 1rem;
}
.gallery-modal-img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
  margin: 0 auto 1rem;
}
.gallery-modal-meta {
  font-size: 0.85rem;
  color: var(--g-muted);
  margin-bottom: 0.5rem;
  word-break: break-word;
}
.gallery-modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.gallery-modal-actions .btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--g-border);
  background: var(--g-bg);
  color: var(--g-text);
  cursor: pointer;
  font-size: 0.9rem;
}
.gallery-modal-actions .btn:hover { background: var(--g-border); }
.gallery-modal-actions .btn-primary { background: var(--g-accent); border-color: var(--g-accent); }
.gallery-move-box { width: 420px; max-width: 92vw; }
.gallery-move-select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--g-border);
  border-radius: 6px;
  color: var(--g-text);
  background: var(--g-bg);
}
.gallery-move-label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--g-muted);
}
.gallery-move-levels {
  margin-top: 0.4rem;
}
.gallery-move-level-row + .gallery-move-level-row {
  margin-top: 0.35rem;
}

.gallery-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 10050;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  background: var(--g-card);
  border: 1px solid var(--g-accent);
  color: var(--g-text);
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.gallery-toast.gallery-toast-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.gallery-scroll-top-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1200;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--g-border);
  background: rgba(15, 23, 42, 0.92);
  color: var(--g-text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.gallery-scroll-top-btn:hover {
  border-color: var(--g-accent);
  background: rgba(30, 41, 59, 0.96);
}

@media (max-width: 900px) {
  .gallery-layout { grid-template-columns: 1fr; }
  .gallery-tree-pane { min-height: auto; }
  .gallery-folder-tree { max-height: 220px; }
}
