/* =========================================================
   PORTFÓLIO
========================================================= */

.portfolio-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 36px 0 42px;
}

.filter-btn,
.view-btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.52);
  color: var(--color-blue-strong);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: background .25s ease, color .25s ease, transform .25s ease;
}

.filter-btn:hover,
.filter-btn.is-active,
.view-btn:hover,
.view-btn.is-active {
  background: var(--color-blue);
  color: #fff;
  transform: translateY(-1px);
}

.portfolio-view-switch {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}

.portfolio-card {
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--color-line);
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease-out), opacity .3s ease;
}

.portfolio-card.is-hidden {
  display: none;
}

.portfolio-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-card);
}

.portfolio-cover {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
}

.portfolio-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 1s var(--ease-out);
}

.portfolio-card:hover .portfolio-cover img {
  transform: scale(1.055);
}

.portfolio-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(20, 28, 35, 0.42), transparent 55%);
}

.portfolio-card-body {
  padding: 22px;
}

.portfolio-card-body span {
  color: var(--color-sage);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.portfolio-card-body h2,
.portfolio-card-body h3 {
  margin: 10px 0 8px;
  color: var(--color-blue-strong);
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 500;
  line-height: 1;
}

.portfolio-card-body p {
  margin: 0 0 18px;
  color: var(--color-muted);
  line-height: 1.65;
}

.portfolio-grid[data-view="masonry"] {
  display: block;
  columns: 3 260px;
  column-gap: 22px;
}

.portfolio-grid[data-view="masonry"] .portfolio-card {
  display: inline-block;
  width: 100%;
  margin: 0 0 22px;
  break-inside: avoid;
}

.portfolio-grid[data-view="masonry"] .portfolio-cover {
  aspect-ratio: var(--masonry-ratio, 4 / 5);
}

.portfolio-grid[data-view="stack3d"] {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 560px;
}

.portfolio-grid[data-view="stack3d"] .portfolio-card {
  display: none;
}

.portfolio-grid[data-view="stack3d"] .portfolio-card:nth-of-type(-n+5) {
  display: block;
  position: absolute;
  width: min(360px, 72vw);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.stack-stage {
  display: none;
  position: relative;
  min-height: 580px;
  perspective: 1300px;
}

.stack-stage.is-active {
  display: block;
}

.stack-photo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(340px, 72vw);
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  transform-style: preserve-3d;
  transition: transform .7s var(--ease-out), opacity .7s var(--ease-out), filter .7s var(--ease-out);
}

.stack-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stack-photo[data-pos="0"] {
  transform: translate(-50%, -50%) translateZ(180px) rotateY(0);
  z-index: 5;
}

.stack-photo[data-pos="1"] {
  transform: translate(calc(-50% + 220px), -50%) rotateY(-38deg) translateZ(20px);
  opacity: .75;
  filter: saturate(.85);
  z-index: 4;
}

.stack-photo[data-pos="2"] {
  transform: translate(calc(-50% + 380px), -50%) rotateY(-54deg) translateZ(-120px);
  opacity: .38;
  filter: saturate(.75);
  z-index: 3;
}

.stack-photo[data-pos="-1"] {
  transform: translate(calc(-50% - 220px), -50%) rotateY(38deg) translateZ(20px);
  opacity: .75;
  filter: saturate(.85);
  z-index: 4;
}

.stack-photo[data-pos="-2"] {
  transform: translate(calc(-50% - 380px), -50%) rotateY(54deg) translateZ(-120px);
  opacity: .38;
  filter: saturate(.75);
  z-index: 3;
}

.stack-controls {
  display: none;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.stack-controls.is-active {
  display: flex;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(14, 23, 31, 0.82);
  backdrop-filter: blur(18px);
}

.lightbox.is-open {
  display: grid;
}

.lightbox-card {
  position: relative;
  width: min(1040px, 100%);
  max-height: min(86vh, 780px);
  display: grid;
  gap: 16px;
}

.lightbox-image-wrap {
  position: relative;
  max-height: 76vh;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: #111;
}

.lightbox-image-wrap img {
  width: 100%;
  max-height: 76vh;
  object-fit: contain;
}

.lightbox-caption {
  color: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  color: var(--color-blue-strong);
  font-size: 1.3rem;
}

.lightbox-close {
  top: -12px;
  right: -12px;
}

.lightbox-nav--prev {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-nav--next {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

@media (max-width: 960px) {
  .portfolio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stack-photo[data-pos="1"] {
    transform: translate(calc(-50% + 120px), -50%) rotateY(-34deg) translateZ(-10px);
  }

  .stack-photo[data-pos="-1"] {
    transform: translate(calc(-50% - 120px), -50%) rotateY(34deg) translateZ(-10px);
  }

  .stack-photo[data-pos="2"],
  .stack-photo[data-pos="-2"] {
    opacity: 0;
  }
}

@media (max-width: 640px) {
  .portfolio-grid {
    grid-template-columns: 1fr;
  }

  .portfolio-filter-bar,
  .portfolio-view-switch {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .filter-btn,
  .view-btn {
    flex: 0 0 auto;
  }

  .stack-stage {
    min-height: 520px;
    overflow: hidden;
  }
}

/* Ajustes V3: o modo 3D usa .stack-stage, então os cards ficam ocultos nesse modo */
.portfolio-cover {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.portfolio-grid[data-view="stack3d"] {
  display: none;
  min-height: 0;
}

.lightbox-footer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}

.lightbox-footer p {
  margin: 0;
  color: rgba(255, 255, 255, 0.86);
  text-align: center;
  line-height: 1.6;
}

.lightbox-footer .lightbox-nav {
  position: relative;
  inset: auto;
  transform: none;
}

/* =========================================================
   PORTFÓLIO — LIGHTBOX HERDANDO VIEW DA GALERIA
========================================================= */

.lightbox {
  overflow-y: auto;
  align-items: start;
}

.lightbox-card--gallery {
  width: min(1180px, 100%);
  max-height: none;
  padding: clamp(18px, 3vw, 28px);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at top right, rgba(107, 112, 92, 0.12), transparent 34%),
    var(--color-paper);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}

.lightbox-gallery-head {
  max-width: 760px;
  margin: 0 auto clamp(18px, 3vw, 30px);
  text-align: center;
}

.lightbox-gallery-head span {
  display: inline-flex;
  color: var(--color-sage);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lightbox-gallery-head h2 {
  margin: 8px 0 0;
  color: var(--color-blue-strong);
  font-family: var(--font-title);
  font-size: clamp(2.4rem, 7vw, 5rem);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.lightbox-gallery-body {
  display: grid;
  gap: 20px;
}

.lightbox-focus {
  overflow: hidden;
  width: min(860px, 100%);
  max-height: 68vh;
  margin: 0 auto;
  border-radius: var(--radius-md);
  background: var(--color-blue-soft);
  box-shadow: var(--shadow-card);
}

.lightbox-focus img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
}

.lightbox-gallery-grid {
  width: min(980px, 100%);
  margin: 0 auto;
}

.lightbox-gallery-grid--cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.lightbox-gallery-grid--masonry {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: dense;
  grid-auto-rows: 96px;
  gap: 12px;
}

.lightbox-thumb {
  position: relative;
  overflow: hidden;
  min-height: 120px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(36, 56, 79, 0.1);
  transition:
    border-color .22s ease,
    transform .22s var(--ease-out),
    opacity .22s ease;
}

.lightbox-gallery-grid--cards .lightbox-thumb {
  aspect-ratio: var(--photo-ratio, 4 / 5);
}

.lightbox-gallery-grid--masonry .lightbox-thumb {
  min-height: 0;
}

.lightbox-gallery-grid--masonry .lightbox-thumb[data-orientation="normal"] {
  grid-row: span 3;
}

.lightbox-gallery-grid--masonry .lightbox-thumb[data-orientation="square"] {
  grid-row: span 2;
}

.lightbox-gallery-grid--masonry .lightbox-thumb[data-orientation="wide"] {
  grid-column: span 2;
  grid-row: span 2;
}

.lightbox-gallery-grid--masonry .lightbox-thumb[data-orientation="tall"] {
  grid-row: span 4;
}

.lightbox-thumb:hover,
.lightbox-thumb.is-selected {
  transform: translateY(-2px);
  border-color: var(--color-sage);
}

.lightbox-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
}

.lightbox-card--gallery .lightbox-footer {
  width: min(860px, 100%);
  margin: 18px auto 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}

.lightbox-card--gallery .lightbox-footer p {
  margin: 0;
  color: var(--color-blue-strong);
  text-align: center;
  line-height: 1.6;
}

.lightbox-card--gallery .lightbox-nav {
  position: relative;
  inset: auto;
  transform: none;
  background: var(--color-blue);
  color: var(--color-ivory);
}

.lightbox-card--gallery .lightbox-close {
  top: 18px;
  right: 18px;
  background: var(--color-blue);
  color: var(--color-ivory);
}

/* =========================================================
   LIGHTBOX — GALERIA 3D INTERNA
========================================================= */

.lightbox-card--stack3d {
  min-height: min(760px, calc(100vh - 48px));
}

.gallery3d-stage {
  position: relative;
  width: 100%;
  height: clamp(420px, 62vh, 640px);
  perspective: 1400px;
  transform-style: preserve-3d;
  overflow: hidden;
}

.gallery3d-photo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(420px, 70vw);
  aspect-ratio: 4 / 5;

  display: block;
  padding: 0;
  border: 0;
  outline: 0;
  overflow: hidden;

  border-radius: var(--radius-md);
  background: transparent;
  box-shadow: 0 24px 70px rgba(36, 56, 79, 0.22);

  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;

  transition:
    transform .58s cubic-bezier(.19, 1, .22, 1),
    opacity .3s ease,
    filter .3s ease;
}

.gallery3d-photo img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  background: transparent;

  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.gallery3d-photo[data-pos="0"] {
  transform: translate(-50%, -50%) rotateY(0deg) translateZ(180px);
  opacity: 1;
  z-index: 7;
}

.gallery3d-photo[data-pos="1"] {
  transform: translate(calc(-50% + 210px), -50%) rotateY(-38deg) translateZ(30px);
  opacity: .76;
  filter: saturate(.86);
  z-index: 6;
}

.gallery3d-photo[data-pos="-1"] {
  transform: translate(calc(-50% - 210px), -50%) rotateY(38deg) translateZ(30px);
  opacity: .76;
  filter: saturate(.86);
  z-index: 6;
}

.gallery3d-photo[data-pos="2"] {
  transform: translate(calc(-50% + 360px), -50%) rotateY(-54deg) translateZ(-120px);
  opacity: .38;
  filter: saturate(.72);
  z-index: 5;
}

.gallery3d-photo[data-pos="-2"] {
  transform: translate(calc(-50% - 360px), -50%) rotateY(54deg) translateZ(-120px);
  opacity: .38;
  filter: saturate(.72);
  z-index: 5;
}

.gallery3d-photo[data-pos="3"],
.gallery3d-photo[data-pos="-3"] {
  opacity: 0;
  pointer-events: none;
}

/* Correção da bordinha branca no 3D da página e do lightbox */
.stack-photo,
.gallery3d-photo {
  border: 0 !important;
  background: transparent !important;
  box-sizing: border-box;
}

.stack-photo img,
.gallery3d-photo img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  background: transparent;
}

@media (max-width: 900px) {
  .lightbox-gallery-grid--cards,
  .lightbox-gallery-grid--masonry {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lightbox-gallery-grid--masonry {
    grid-auto-rows: 86px;
  }

  .gallery3d-photo[data-pos="1"] {
    transform: translate(calc(-50% + 120px), -50%) rotateY(-34deg) translateZ(-20px);
  }

  .gallery3d-photo[data-pos="-1"] {
    transform: translate(calc(-50% - 120px), -50%) rotateY(34deg) translateZ(-20px);
  }

  .gallery3d-photo[data-pos="2"],
  .gallery3d-photo[data-pos="-2"] {
    opacity: 0;
  }
}

@media (max-width: 560px) {
  .lightbox {
    padding: 12px;
  }

  .lightbox-card--gallery {
    padding: 18px 14px;
    border-radius: var(--radius-md);
  }

  .lightbox-gallery-grid--cards,
  .lightbox-gallery-grid--masonry {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .lightbox-gallery-grid--masonry {
    grid-auto-rows: 72px;
  }

  .lightbox-card--gallery .lightbox-footer {
    grid-template-columns: 44px 1fr 44px;
  }
}

/* =========================================================
   PORTFÓLIO — PERSONALIZAÇÃO MASONRY INTERNO
========================================================= */

.lightbox-gallery-grid--masonry {
  gap: var(--gallery-masonry-gap, 4px);
}

.lightbox-gallery-grid--masonry .lightbox-thumb {
  border-radius: var(--gallery-masonry-radius, 4px);
}

.lightbox-footer--masonry {
  grid-template-columns: 1fr !important;
}

.lightbox-footer--masonry .lightbox-caption {
  max-width: 720px;
  margin: 0 auto;
}

/* =========================================================
   PORTFÓLIO — MASONRY INTERNO SEM FOTO DE DESTAQUE
========================================================= */

.lightbox-card--masonry .lightbox-focus {
  display: none;
}

.lightbox-card--masonry .lightbox-gallery-body {
  gap: 0;
}

.lightbox-card--masonry .lightbox-gallery-grid {
  width: 100%;
  margin: 0 auto;
}
