/* NovaFolio – Gallery G2 (corrected + hardened)
   Changes vs original:
   - Scope modifier selectors to .nvf-gallery.nvf-gallery-g2 to avoid leaking to other blocks.
   - Accessibility: overlay appears on :focus-visible (keyboard) as well as :hover.
   - Safer title wrapping fallback (text-wrap: balance is not universal).
   - Optional: hide overlay when hover effect is set to "none".
*/

.nvf-gallery.nvf-gallery-g2{
  width: 100%;
  max-width: var(--nvf-layout-max-width, 1440px);
  margin-inline: auto;
}

/* Grid */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-inner{
  display: grid;
  grid-template-columns: repeat(var(--nvf-gallery-cols, 3), minmax(0, 1fr));
  gap: var(--nvf-gallery-gap, 20px);
}

/* Item */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-item{
  position: relative;
  overflow: hidden;
  border-radius: var(--nvf-gallery-radius, 10px);
  background: rgba(0,0,0,.02);
}

/* Link wrapper (a or div) */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-link{
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
}

/* Image */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-img{
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
  transition: transform .35s ease, opacity .35s ease, box-shadow .35s ease, filter .35s ease;
}

/* ---------------------------------------------
   Crop / ratio (premium grid)
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--crop .nvf-gallery-item{
  aspect-ratio: var(--nvf-gallery-ratio, auto);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--crop .nvf-gallery-link{
  height: 100%;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--crop .nvf-gallery-img{
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* Ratio lock without crop: keep frame ratio while preserving full image */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--has-ratio:not(.nvf-gallery--crop) .nvf-gallery-item{
  aspect-ratio: var(--nvf-gallery-ratio, auto);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--has-ratio:not(.nvf-gallery--crop) .nvf-gallery-link{
  height: 100%;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--has-ratio:not(.nvf-gallery--crop) .nvf-gallery-img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

/* ---------------------------------------------
   Hover overlay (premium title)
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-overlay{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  opacity: 0;
  transition: opacity .28s ease;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 10, 10, .08) 0%, rgba(10, 10, 10, .72) 100%);
}

.nvf-gallery.nvf-gallery-g2 .nvf-gallery-content--overlay{
  align-items: center;
  box-sizing: border-box;
  color: var(--nvf-portfolio-overlay-color, #fff);
  display: flex;
  flex-direction: column;
  gap: 6px;
  inset: 0;
  justify-content: center;
  opacity: 0;
  padding: clamp(18px, 2.2vw, 26px);
  position: absolute;
  text-align: center;
  transform: translateY(10px);
  transition: opacity .28s ease, transform .28s ease;
}

.nvf-gallery.nvf-gallery-g2 .nvf-gallery-title,
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-subtitle{
  color: #fff;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.nvf-gallery.nvf-gallery-g2 .nvf-gallery-title{
  font-family: var(--nvf-headings-font, var(--nvf-headings-font-family, var(--nvf-body-font, var(--nvf-body-font-family, inherit))));
  font-size: var(--nvf-gallery-title-size, var(--nvf-portfolio-card-title-size, var(--nvf-pf-card-title-size, var(--nvf-gallery-title-fs, 14px))));
  font-weight: var(--nvf-headings-weight, var(--nvf-headings-font-weight, 600));
  line-height: 1.2;
  letter-spacing: var(--nvf-gallery-title-letter-spacing, var(--nvf-portfolio-card-title-letter-spacing, var(--nvf-headings-letter-spacing, .04em)));
  max-width: 100%;
  text-transform: none;
  text-wrap: balance;
}

.nvf-gallery.nvf-gallery-g2 .nvf-gallery-subtitle{
  font-size: clamp(11px, 0.85vw, 13px);
  letter-spacing: .04em;
  line-height: 1.4;
  opacity: .82;
}

/* Show overlay on hover + keyboard focus */
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-item:hover .nvf-gallery-overlay,
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-link:focus-visible .nvf-gallery-overlay{
  opacity: 1;
}

.nvf-gallery.nvf-gallery-g2 .nvf-gallery-item:hover .nvf-gallery-content--overlay,
.nvf-gallery.nvf-gallery-g2 .nvf-gallery-link:focus-visible .nvf-gallery-content--overlay{
  opacity: 1;
  transform: translateY(0);
}

/* Optional: if user selects hoverEffect = none */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-none .nvf-gallery-overlay{
  display: none;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay.nvf-gallery--caption-align-center .nvf-gallery-content--overlay{
  align-items: center;
  text-align: center;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay.nvf-gallery--caption-align-left .nvf-gallery-content--overlay{
  align-items: flex-start;
  text-align: left;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay.nvf-gallery--caption-align-right .nvf-gallery-content--overlay{
  align-items: flex-end;
  text-align: right;
}

/* ---------------------------------------------
   Hover variants (image + frame)
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-zoom .nvf-gallery-item:hover .nvf-gallery-img{
  transform: scale(1.04);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-fade .nvf-gallery-item:hover .nvf-gallery-img{
  opacity: .7;
  filter: brightness(.88) saturate(.75);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-lift .nvf-gallery-item{
  transition: transform .25s ease, box-shadow .25s ease;
}
.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-lift .nvf-gallery-item:hover{
  transform: translateY(-4px);
  box-shadow: 0 16px 45px rgba(0,0,0,.18);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-frame .nvf-gallery-item{
  box-shadow: 0 0 0 1.5px rgba(0,0,0,.18);
  transition: box-shadow .25s ease;
}
.nvf-gallery.nvf-gallery-g2.nvf-gallery--hover-frame .nvf-gallery-item:hover{
  box-shadow: 0 0 0 2.5px rgba(0,0,0,.75);
}

/* ---------------------------------------------
   Reveal animation (no JS, stagger by --nvf-i)
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--anim-fade .nvf-gallery-item{
  opacity: 0;
  transform: translateY(10px);
  animation: nvfGalleryFade .6s ease forwards;
  animation-delay: calc(var(--nvf-i, 0) * 70ms);
}

@keyframes nvfGalleryFade{
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce){
  .nvf-gallery.nvf-gallery-g2 .nvf-gallery-img{
    transition: none;
  }
  .nvf-gallery.nvf-gallery-g2.nvf-gallery--anim-fade .nvf-gallery-item{
    opacity: 1;
    transform: none;
    animation: none;
  }
  .nvf-gallery.nvf-gallery-g2 .nvf-gallery-overlay{
    transition: none;
  }
}

/* ---------------------------------------------
   Preview editor
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview .nvf-gallery-img-placeholder{
  background: #f3f4f6;
  border-radius: var(--nvf-radius-sm, 8px);
  padding: 26px 12px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
}

.nvf-gallery-placeholder{
  margin: 0;
  padding: 12px 0;
  opacity: .75;
}

/* Helper: cols en CSS custom property */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-1 .nvf-gallery-inner{ --nvf-gallery-cols: 1; }
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-2 .nvf-gallery-inner{ --nvf-gallery-cols: 2; }
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-3 .nvf-gallery-inner{ --nvf-gallery-cols: 3; }
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-4 .nvf-gallery-inner{ --nvf-gallery-cols: 4; }
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-5 .nvf-gallery-inner{ --nvf-gallery-cols: 5; }
.nvf-gallery.nvf-gallery-g2.nvf-gallery--cols-6 .nvf-gallery-inner{ --nvf-gallery-cols: 6; }

/* EDITOR: make ratio visible with placeholders */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview.nvf-gallery--crop .nvf-gallery-item{
  aspect-ratio: var(--nvf-gallery-ratio, auto);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview.nvf-gallery--crop .nvf-gallery-link{
  height: 100%;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview.nvf-gallery--crop .nvf-gallery-img-placeholder{
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

/* EDITOR: real images in preview mode */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview .nvf-gallery-img{
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--nvf-gallery-radius, 8px);
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2 .nvf-gallery-overlay,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2 .nvf-gallery-overlay,
.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2 .nvf-gallery-content--overlay,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2 .nvf-gallery-content--overlay{
  inset: 0;
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2 .nvf-gallery-link,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2 .nvf-gallery-link{
  overflow: hidden;
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-overlay,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-overlay{
  opacity: 1;
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-content--overlay,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-content--overlay{
  opacity: 1;
  transform: translateY(0);
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-item,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-item{
  min-height: 120px;
}

.editor-styles-wrapper .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-content--overlay,
.block-editor-block-preview__content .nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-style-overlay .nvf-gallery-content--overlay{
  justify-content: center;
  align-items: center;
  text-align: center;
}
.nvf-gallery.nvf-gallery-g2.nvf-gallery--is-preview.nvf-gallery--crop .nvf-gallery-img{
  height: 100%;
  object-fit: cover;
  object-position: center;
}

/* RESPONSIVE RULES NOW IN: galleries-responsive.css */
/* This file only contains the base Gallery G2 layout and styling */
/* Media queries for responsive column stacking are in the dedicated responsive file */

/* ---------------------------------------------
   Captions below image (Mariane Ibrahim style)
   Activated by .nvf-gallery--captions class.
   --------------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-item {
  display: flex;
  flex-direction: column;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-figcaption {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 2px 6px;
  text-align: left;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-center .nvf-gallery-figcaption {
  text-align: center;
  align-items: center;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-center .nvf-gallery-figcaption__title,
.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-center .nvf-gallery-figcaption__caption,
.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-center .nvf-gallery-figcaption__desc {
  text-align: center;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-right .nvf-gallery-figcaption {
  text-align: right;
  align-items: flex-end;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-right .nvf-gallery-figcaption__title,
.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-right .nvf-gallery-figcaption__caption,
.nvf-gallery.nvf-gallery-g2.nvf-gallery--caption-align-right .nvf-gallery-figcaption__desc {
  text-align: right;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-figcaption__title {
  font-family: var(--nvf-headings-font-family, inherit);
  font-weight: var(--nvf-headings-font-weight, 600);
  font-size: clamp(12px, 1vw, 15px);
  line-height: 1.3;
  letter-spacing: 0.06em;
  color: var(--nvf-color-headings, #111);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-figcaption__caption {
  font-size: clamp(11px, 0.85vw, 13px);
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--nvf-color-text, #555);
  opacity: 0.75;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-figcaption__desc {
  font-size: clamp(11px, 0.8vw, 12px);
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--nvf-color-text, #555);
  opacity: 0.6;
}

/* When captions + crop, ratio applies only to the image wrapper, not the whole figure */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions.nvf-gallery--crop .nvf-gallery-item {
  aspect-ratio: auto;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions.nvf-gallery--crop .nvf-gallery-link {
  aspect-ratio: var(--nvf-gallery-ratio, auto);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions.nvf-gallery--has-ratio:not(.nvf-gallery--crop) .nvf-gallery-item {
  aspect-ratio: auto;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions.nvf-gallery--has-ratio:not(.nvf-gallery--crop) .nvf-gallery-link {
  aspect-ratio: var(--nvf-gallery-ratio, auto);
}

/* Hide on-image overlay when captions are below */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--captions .nvf-gallery-overlay {
  display: none;
}

/* -----------------------------------------
   WordPress blockGap reset
   is-layout-flow / is-layout-constrained inject margin-block-start
   on children. Gallery G2 manages its own spacing.
----------------------------------------- */
:where(.is-layout-flow) > .wp-block-novafolio-gallery-g2,
:where(.is-layout-constrained) > .wp-block-novafolio-gallery-g2 {
  margin-block-start: 0;
  margin-block-end: 0;
}

/* -----------------------------------------
   Defensive horizontal padding
   When placed directly in post content (not inside a Section),
   provide horizontal safety margin on narrow viewports.
----------------------------------------- */
:is(.entry-content, .nvf-prose) > .wp-block-novafolio-gallery-g2 {
  box-sizing: border-box;
}

/* -----------------------------------------
   MASONRY MODE (Auto-activated: crop=false + ratio=original)
   Uses CSS column-count for natural aspect ratio layout
----------------------------------------- */
.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry .nvf-gallery-inner {
  display: block;
  column-gap: var(--nvf-gallery-gap, 20px);
  column-fill: balance;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-1 .nvf-gallery-inner {
  column-count: 1;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-2 .nvf-gallery-inner {
  column-count: 2;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-3 .nvf-gallery-inner {
  column-count: 3;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-4 .nvf-gallery-inner {
  column-count: 4;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-6 .nvf-gallery-inner {
  column-count: 6;
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry .nvf-gallery-item {
  break-inside: avoid;
  width: 100%;
  margin-bottom: var(--nvf-gallery-gap, 20px);
}

.nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry .nvf-gallery-img {
  width: 100%;
  height: auto;
  object-fit: contain;
  object-position: center;
  display: block;
}

/* Masonry responsive: 3 cols → 2 cols at 900px */
@media (max-width: 900px) {
  .nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-3 .nvf-gallery-inner,
  .nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-4 .nvf-gallery-inner,
  .nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry.nvf-gallery--cols-6 .nvf-gallery-inner {
    column-count: 2;
  }
}

/* Masonry responsive: any → 1 col at 600px */
@media (max-width: 600px) {
  .nvf-gallery.nvf-gallery-g2.nvf-gallery--masonry .nvf-gallery-inner {
    column-count: 1;
  }
}
