:root {
  --gallery-bg: #ffffff;
  --gallery-card-bg: #ffffff;
  --gallery-card-border: #e5e7eb;
  --gallery-card-hover-border: #9ca3af;
  --gallery-card-title: #111827;
  --gallery-card-meta: #6b7280;
  --gallery-accent: #4f46e5;
}

/* Strona galerii: naturalna wysokość (bez min-height: 100vh), całość się scrolluje */
.page--gallery {
  min-height: 0;
  display: block;
}

/* Main nie rozciąga się – wysokość = treść, stopka zaraz pod zdjęciami */
.page--gallery main.gallery-layout {
  flex: none;
  min-height: 0;
  position: relative;
  z-index: 0;
}

@media (max-width: 768px) {
  .page--gallery main.gallery-layout {
    grid-template-rows: none;
    min-height: 0;
  }
}

.gallery-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
  padding: 0 1.25rem 2.5rem;
}

@media (min-width: 960px) {
  .gallery-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    align-items: flex-start;
    padding: 0 2.5rem 3rem;
  }
}

.gallery-sidebar {
  display: none;
}

@media (min-width: 960px) {
  .gallery-sidebar {
    display: block;
    max-height: calc(100vh - 220px);
    overflow: auto;
    padding: 1.25rem 1.25rem 1.5rem;
    border-radius: 1rem;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    box-shadow:
      0 4px 10px rgba(15, 23, 42, 0.04),
      0 1px 2px rgba(15, 23, 42, 0.02);
  }
}

.gallery-tree-header {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b5563;
  margin-bottom: 0.75rem;
}

.gallery-tree {
  font-size: 0.85rem;
  color: #374151;
  list-style: none;
  padding: 0;
  margin: 0;
}

.gallery-tree ul {
  list-style: none;
  padding-left: 1rem;
  margin: 0.25rem 0 0.4rem;
  border-left: 1px dashed #e5e7eb;
}

.gallery-tree-node {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  user-select: none;
  color: #374151;
}

.gallery-tree-node:hover {
  background: rgba(129, 140, 248, 0.08);
}

.gallery-tree-node.is-active {
  background: rgba(79, 70, 229, 0.12);
  color: #111827;
  font-weight: 600;
}

.gallery-tree-toggle {
  width: 1.1rem;
  height: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.6rem;
  color: #4b5563;
}

.gallery-tree-toggle::before {
  content: "▾";
}

.gallery-tree-node.is-collapsed > .gallery-tree-toggle::before {
  content: "▸";
}

.gallery-tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-main {
  max-width: 1200px;
  margin: 0 auto;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.gallery-toolbar-left {
  max-width: 640px;
}

.gallery-toolbar-description {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: #d1d5db;
}

.gallery-refresh-button {
  margin-left: auto;
}

.gallery-status {
  margin: 1.5rem 0 1rem;
  font-size: 0.875rem;
  color: #374151;
}

.gallery-status--error {
  color: #b91c1c;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.gallery-pagination {
  grid-column: 1 / -1;
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
}

.gallery-pagination-button {
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  padding: 0.45rem 1.05rem;
  font-size: 0.85rem;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.gallery-pagination-button:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

@media (max-width: 640px) {
  .gallery-grid {
    /* Na telefonach: dwie miniaturki w rzędzie, odrobinę mniejsze odstępy */
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }
}

@media (min-width: 768px) {
  .gallery-grid {
    gap: 1.25rem;
  }
}

@media (min-width: 1200px) {
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.gallery-item {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--gallery-card-bg);
  border-radius: 0.9rem;
  overflow: hidden;
  border: 1px solid var(--gallery-card-border);
  box-shadow:
    0 4px 10px rgba(15, 23, 42, 0.06),
    0 1px 2px rgba(15, 23, 42, 0.04);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.gallery-item:hover {
  transform: translateY(-3px) translateZ(0);
  border-color: var(--gallery-card-hover-border);
  background: #f9fafb;
  box-shadow:
    0 8px 20px rgba(15, 23, 42, 0.12),
    0 2px 4px rgba(15, 23, 42, 0.04);
}

.gallery-item-link {
  display: block;
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #f3f4f6;
}

.gallery-item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition:
    transform 220ms ease,
    filter 220ms ease;
}

.gallery-item:hover .gallery-item-img {
  transform: scale(1.04);
  filter: saturate(1.1);
}

.gallery-item-gradient {
  position: absolute;
  inset: auto 0 0 0;
  height: 40%;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.35), transparent);
  pointer-events: none;
}

/* Loader w okienku każdego ładującego się zdjęcia */
.gallery-item-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  z-index: 1;
  transition: opacity 0.2s ease-out;
}

.gallery-item.is-loaded .gallery-item-loader {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.gallery-item-loader .gallery-item-spinner {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 3px solid #e5e7eb;
  border-top-color: #4f46e5;
  animation: gallery-spin 0.8s linear infinite;
}

.gallery-item-meta {
  padding: 0.6rem 0.85rem 0.85rem;
}

.gallery-item-title {
  margin: 0 0 0.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--gallery-card-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-item-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--gallery-card-meta);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.gallery-item-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: radial-gradient(circle at center, #a5b4fc, #4f46e5);
}

.gallery-item-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.6rem;
  padding: 0.12rem 0.5rem;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 999px;
  color: #f9fafb;
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.9), rgba(79, 70, 229, 0.9));
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.9);
}

.gallery-item-badge--new {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.95), rgba(22, 163, 74, 0.95));
}

.gallery-empty {
  margin-top: 1.75rem;
  padding: 1.25rem 1.4rem;
  border-radius: 0.9rem;
  border: 1px dashed #e5e7eb;
  background: #f9fafb;
  color: #374151;
  font-size: 0.9rem;
}

.gallery-empty strong {
  font-weight: 600;
}

.gallery-empty a {
  color: #a5b4fc;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.gallery-empty a:hover {
  color: #c4b5fd;
}

.gallery-folder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  background: var(--gallery-card-bg);
  border-radius: 0.9rem;
  border: 2px dashed var(--gallery-card-border);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
  text-align: center;
  min-height: 180px;
}

.gallery-folder-card:hover {
  transform: translateY(-3px) translateZ(0);
  border-color: var(--gallery-card-hover-border);
  background: #f9fafb;
  border-style: solid;
}

.gallery-folder-icon {
  width: 4rem;
  height: 4rem;
  margin-bottom: 0.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394a82a'%3E%3Cpath d='M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  flex-shrink: 0;
}


.gallery-folder-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gallery-card-title);
  margin-bottom: 0.4rem;
}

.gallery-folder-count {
  font-size: 0.85rem;
  color: var(--gallery-card-meta);
}

/* Lightbox */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.gallery-lightbox.is-visible {
  display: flex;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
}

.gallery-lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  z-index: 1;
  box-shadow:
    0 20px 40px rgba(15, 23, 42, 0.45),
    0 0 0 1px rgba(15, 23, 42, 0.9);
  border-radius: 0.75rem;
  overflow: hidden;
}

.gallery-lightbox-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020617;
  z-index: 2;
  transition: opacity 0.2s ease-out;
}

.gallery-lightbox-content.is-loaded .gallery-lightbox-loader {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.gallery-lightbox-spinner {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #e5e7eb;
  animation: gallery-spin 0.8s linear infinite;
}

.gallery-lightbox-img {
  display: block;
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  background: #020617;
  transition: opacity 0.2s ease-out;
}

.gallery-lightbox-img.is-changing {
  opacity: 0;
}

/* Global loader */
.gallery-loading {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(249, 250, 251, 0.75);
  z-index: 9000;
}

.gallery-loading.is-visible {
  display: flex;
}

.gallery-spinner {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 4px solid #e5e7eb;
  border-top-color: #4f46e5;
  animation: gallery-spin 0.8s linear infinite;
}

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

/* Lightbox navigation arrows */
.gallery-lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.75);
  color: #e5e7eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
}

.gallery-lightbox-arrow:hover {
  background: rgba(55, 65, 81, 0.9);
}

.gallery-lightbox-arrow--prev {
  left: 1.5rem;
}

.gallery-lightbox-arrow--next {
  right: 1.5rem;
}

/* Nagłówek – tytuł jako link do strony głównej narzędzia */
.page--gallery .page-header-title-link {
  color: inherit;
  text-decoration: none;
}

.page--gallery .page-header-title-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Logo ZHP nad stopką */
.page--gallery .page-footer-logo-wrap {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}

.page--gallery .page-footer-logo-wrap .page-footer-logo-link {
  display: inline-block;
  line-height: 0;
}

.page--gallery .page-footer-zhp-logo {
  max-height: 48px;
  width: auto;
  display: block;
  opacity: 0.85;
}

.page--gallery .page-footer-logo-wrap .page-footer-logo-link:hover .page-footer-zhp-logo {
  opacity: 1;
}

/* Stopka na końcu przewijalnej treści, nie przykryta przez zdjęcia */
.page--gallery .page-footer {
  margin-top: 0.5rem;
  padding: 2rem 1.5rem 2.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: #6b7280;
  border-top: 1px solid #e5e7eb;
  background: var(--gallery-bg);
  position: relative;
  z-index: 10;
}

@media (max-width: 768px) {
  .page--gallery .page-header {
    padding: 14px;
  }

  .page--gallery .page-header-content {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  .page--gallery .page-header-content > div {
    flex: 1 1 auto;
    min-width: 0;
  }

  .page--gallery .page-header-logo-link {
    flex: 0 0 auto;
    order: 2;
    margin-left: auto;
  }

  .page--gallery .page-header-logo {
    max-height: 52px;
  }
}

