/* Tokens come from style.css — do not @import tokens.css here; it would reset
   :root custom properties after style.css media queries and break floating actions. */

.gallery-page main {
  overflow-x: clip;
  max-width: 100%;
  width: 100%;
}

.gallery-page-header {
  margin-bottom: var(--space-md);
  max-width: 100%;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.gallery-page-header .gradient-heading {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  margin-bottom: 0.5rem;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

.gallery-page-intro {
  margin-top: 0.75rem;
  max-width: 42rem;
  color: var(--text-muted, var(--text));
  opacity: 0.9;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

.gallery-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-lg);
  padding: var(--space-lg) 0 var(--space-xl);
  max-width: 100%;
  min-width: 0;
}

.gallery-main {
  grid-column: 2;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

.gallery-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 16px);
  align-self: start;
  max-height: calc(100vh - var(--header-height) - 32px);
  overflow-y: auto;
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: var(--space-sm);
  color: var(--rose-deep);
}

.category-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-lg);
}

.category-list li {
  margin-bottom: 0.25rem;
}

.category-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-left: 2px dotted transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.35s var(--ease-premium);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.category-link-label {
  flex: 1;
  min-width: 0;
}

.category-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.625rem;
  height: 1.625rem;
  padding: 0 0.35rem;
  border-radius: var(--radius-pill);
  background: var(--lavender);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(58, 173, 212, 0.35);
}

.category-link:hover,
.category-link.is-active {
  border-left-color: var(--rose);
  background: rgba(224, 24, 32, 0.06);
  color: var(--rose-deep);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.gallery-toolbar {
  margin-bottom: var(--space-md);
}

/* Hide header search on gallery — search lives in mobile drawer only */
.gallery-page #header-search-wrap {
  display: none !important;
}

.gallery-cat-dropdown {
  display: none;
  position: sticky;
  top: var(--header-height);
  z-index: calc(var(--z-header) - 1);
  background: var(--bg-ivory);
  padding-bottom: 0.25rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-bottom: var(--space-sm);
  box-sizing: border-box;
}

.gallery-cat-dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: var(--border-dot-light);
  border-radius: var(--radius-md);
  background: white;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.3s var(--ease-premium), box-shadow 0.3s var(--ease-premium);
}

.gallery-cat-dropdown-toggle:hover,
.gallery-cat-dropdown.is-open .gallery-cat-dropdown-toggle {
  border-color: var(--rose);
  box-shadow: 0 2px 8px rgba(224, 24, 32, 0.08);
}

.gallery-cat-dropdown-label {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-cat-dropdown-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.625rem;
  height: 1.625rem;
  padding: 0 0.35rem;
  border-radius: var(--radius-pill);
  background: var(--lavender);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.gallery-cat-dropdown-chevron {
  color: var(--rose-deep);
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: transform 0.3s var(--ease-premium);
}

.gallery-cat-dropdown.is-open {
  z-index: calc(var(--z-header) + 2);
}

.gallery-cat-dropdown.is-open .gallery-cat-dropdown-chevron {
  transform: rotate(180deg);
}

.gallery-cat-dropdown-inner {
  position: relative;
}

.gallery-cat-dropdown-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: min(50vh, 320px);
  overflow-y: auto;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  background: white;
  border: var(--border-dot-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  z-index: 1;
}

.gallery-cat-dropdown-panel[hidden] {
  display: none !important;
}

.gallery-cat-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.25s var(--ease-premium);
}

.gallery-cat-option:hover,
.gallery-cat-option.is-active {
  background: rgba(224, 24, 32, 0.06);
  color: var(--rose-deep);
}

.gallery-cat-option-label {
  flex: 1;
  min-width: 0;
}

.gallery-result-meta {
  font-size: 0.95rem;
  color: var(--rose-deep);
  margin-bottom: var(--space-md);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--space-md);
  align-items: center;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.filter-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

/* Masonry grid */
.gallery-grid {
  columns: 2;
  column-gap: var(--space-md);
  max-width: 100%;
}

@media (min-width: 640px) {
  .gallery-grid { columns: 3; }
}

@media (min-width: 1024px) {
  .gallery-grid { columns: 3; }
}

@media (min-width: 1280px) {
  .gallery-grid { columns: 4; }
}

.product-card {
  break-inside: avoid;
  margin-bottom: var(--space-md);
  border: 1px dotted rgba(224, 24, 32, 0.4);
  border-radius: var(--radius-lg);
  background: var(--bg-ivory);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.4s var(--ease-premium), transform 0.4s var(--ease-premium), box-shadow 0.4s var(--ease-premium);
  position: relative;
}

.product-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(224, 200, 32, 0.15) 50%, transparent 60%);
  transform: translateX(-100%);
  pointer-events: none;
  transition: transform 0.6s var(--ease-premium);
}

.product-card:hover {
  border-color: var(--gold);
  transform: perspective(800px) rotateY(2deg);
  box-shadow: var(--shadow-card);
}

.product-card:hover::after {
  transform: translateX(100%);
}

.product-card.is-exiting {
  opacity: 0;
  transform: scale(0.98);
  transition-duration: 0.2s;
}

.product-card.is-entering {
  opacity: 0;
  transform: translateY(20px) scale(0.98);
}

.product-card.is-entering.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity 0.45s var(--ease-premium), transform 0.45s var(--ease-premium);
}

.product-card .img-tray {
  background: var(--pearl);
  padding: var(--space-sm);
  border-bottom: var(--border-dot-light);
  position: relative;
  min-height: 180px;
  overflow: hidden;
}

.product-card .img-tray::before,
.product-card .img-tray::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--rose);
  border-style: dotted;
  opacity: 0.4;
  pointer-events: none;
}

.product-card .img-tray::before {
  top: 6px;
  left: 6px;
  border-width: 1px 0 0 1px;
}

.product-card .img-tray::after {
  bottom: 6px;
  right: 6px;
  border-width: 0 1px 1px 0;
}

.product-card img {
  width: 100%;
  object-fit: contain;
  transition: transform 0.4s var(--ease-premium);
}

.product-card:hover img {
  transform: scale(1.04);
}

.product-card-body {
  padding: 0.75rem 1rem 1rem;
}

.product-card-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  color: var(--text);
}

.product-card-meta {
  font-size: 0.8rem;
  color: var(--lavender);
  font-weight: 600;
}

.gallery-sentinel {
  height: 1px;
  visibility: hidden;
}

.gallery-end {
  text-align: center;
  padding: var(--space-lg);
  color: var(--rose-deep);
}

.gallery-skeleton {
  break-inside: avoid;
  margin-bottom: var(--space-md);
  border-radius: var(--radius-lg);
  min-height: 240px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(250, 252, 251, 0.92);
  backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm);
  pointer-events: none;
}

.modal-backdrop.is-open {
  pointer-events: auto;
}

.modal-panel {
  width: min(920px, 100%);
  max-height: calc(100vh - var(--space-md));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-ivory);
  border: var(--border-dot-gold);
  border-radius: var(--radius-xl);
  padding: 0.75rem 1rem 0.85rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 30;
  margin: 0;
  flex-shrink: 0;
}

.modal-header {
  flex-shrink: 0;
  padding-right: 2.75rem;
  margin-bottom: 0.5rem;
}

.modal-title {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  line-height: 1.2;
  margin: 0 0 0.15rem;
  color: var(--rose-deep);
}

.modal-category {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--lavender);
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
}

.modal-media {
  display: flex;
  min-height: 0;
}

.modal-image-wrap {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--pearl);
  border: var(--border-dot-light);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image-wrap img {
  max-width: 100%;
  max-height: min(52vh, calc(100vh - 11rem));
  object-fit: contain;
  transition: opacity 0.35s ease;
}

.modal-image-wrap img.is-fading {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .modal-image-wrap img {
    transition: none;
  }
}

.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
}

.modal-nav.prev { left: 4px; }
.modal-nav.next { right: 4px; }

/* Landscape: thumbnails below main image */
.modal-layout-landscape .modal-media {
  flex-direction: column;
  gap: 0.4rem;
}

.modal-layout-landscape .modal-filmstrip {
  flex-direction: row;
  order: 2;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.15rem;
}

.modal-layout-landscape .modal-image-wrap {
  order: 1;
}

/* Portrait: thumbnails in left column */
.modal-layout-portrait .modal-media {
  flex-direction: row;
  align-items: stretch;
  gap: 0.4rem;
}

.modal-layout-portrait .modal-filmstrip {
  flex-direction: column;
  flex: 0 0 auto;
  order: -1;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: min(52vh, calc(100vh - 11rem));
  padding-right: 0.15rem;
}

.modal-layout-portrait .modal-thumb {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
}

.modal-filmstrip {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.modal-filmstrip[hidden] {
  display: none !important;
}

.modal-thumb {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border: var(--border-dot-light);
  border-radius: var(--radius-sm);
  background: var(--pearl);
  cursor: pointer;
  overflow: hidden;
  opacity: 0.7;
  padding: 0;
  transition: all 0.3s var(--ease-premium);
}

.modal-thumb.is-active {
  border-color: var(--rose-deep);
  opacity: 1;
}

.modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px dotted rgba(224, 24, 32, 0.15);
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
}

.modal-tag {
  padding: 0.2rem 0.6rem;
  border: 1px dotted var(--sage);
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--sage);
  background: rgba(8, 120, 40, 0.1);
}

.modal-tag:nth-child(even) {
  border-color: var(--rose-deep);
  color: var(--rose-deep);
  background: rgba(160, 24, 32, 0.08);
}

.modal-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
  align-items: center;
}

.modal-actions .btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.search-highlight {
  font-weight: 700;
  color: var(--rose-deep);
}

.gallery-empty {
  text-align: center;
  padding: var(--space-2xl) var(--space-md);
}

.gallery-empty .chip {
  margin: 0.25rem;
}

@media (max-width: 900px) {
  /* Block layout avoids grid placing .gallery-main in the 260px column when sidebar is hidden */
  .gallery-layout {
    display: block;
    padding: var(--space-md) 0 var(--space-lg);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .gallery-sidebar {
    display: none;
  }

  .gallery-main {
    grid-column: auto;
    width: 100%;
    max-width: 100%;
  }

  .gallery-cat-dropdown {
    display: block;
    position: sticky;
    top: var(--header-height);
  }

  .gallery-page-header .gradient-heading {
    font-size: clamp(1.25rem, 5.8vw, 1.65rem);
    line-height: 1.3;
  }

  .gallery-page-intro {
    max-width: 100%;
    font-size: 0.95rem;
    line-height: 1.55;
  }

  .gallery-result-meta {
    overflow-wrap: break-word;
  }

  .gallery-page .site-header .header-inner {
    flex-wrap: wrap;
    row-gap: var(--space-xs);
    align-items: center;
    min-height: auto;
    padding-block: var(--space-xs);
  }

  .gallery-page .logo-link {
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 52px);
  }

  .gallery-page .logo-link img {
    height: 40px;
    width: auto;
  }

  .gallery-page .logo-brand {
    min-width: 0;
    overflow: visible;
    padding-left: 0.5rem;
  }

  .gallery-page .logo-title {
    white-space: normal;
    font-size: 1rem;
    line-height: 1.15;
  }

  .gallery-page .logo-tagline {
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
    font-size: 0.58rem;
    line-height: 1.25;
    letter-spacing: 0.03em;
  }

  .gallery-page .container-wide.gallery-layout {
    width: 100%;
    max-width: 100%;
    padding-inline: var(--space-sm);
    box-sizing: border-box;
  }

  .product-card:hover {
    transform: none;
  }

  .modal-backdrop {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .modal-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.65rem 0.75rem 0.75rem;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    border-inline: none;
    box-sizing: border-box;
  }

  .modal-image-wrap img {
    max-height: min(42vh, calc(100dvh - 13rem));
  }

  .modal-layout-portrait .modal-filmstrip {
    max-height: min(42vh, calc(100dvh - 13rem));
  }

  .modal-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .modal-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .modal-actions .btn-sm {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  .gallery-page-header .gradient-heading {
    font-size: clamp(1.15rem, 5.2vw, 1.45rem);
  }

  .gallery-page-intro {
    font-size: 0.9rem;
  }

  .gallery-grid {
    column-gap: var(--space-sm);
  }

  .product-card-body {
    padding: 0.65rem 0.75rem 0.85rem;
  }

  .product-card-title {
    font-size: 1rem;
  }

  .modal-header {
    padding-right: 2.5rem;
  }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-actions {
    flex-direction: column;
    width: 100%;
  }

  .modal-actions .btn-sm {
    width: 100%;
    justify-content: center;
  }
}
