/* Projects: one column on phones, two on tablets, three on desktop. */
.projects-page #proyectos {
  padding-block: clamp(32px, 5vw, 64px);
}

.projects-page #proyectos .section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 28px;
}

.projects-page #proyectos .section-head > * {
  min-width: 0;
}

.projects-page #work-title {
  max-width: 24ch;
  margin-bottom: 0;
  font-size: clamp(28px, 3.6vw, 46px);
  line-height: 1.12;
  text-wrap: balance;
}

.projects-page .portfolio-tabs {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  margin: 0 0 24px;
  padding: 4px 4px 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 4px;
  touch-action: pan-x pan-y pinch-zoom;
  mask-image: none;
}

.projects-page .portfolio-tabs .nav-item {
  flex: 0 0 auto;
  min-width: 0;
  scroll-snap-align: start;
}

.projects-page .portfolio-tabs .nav-link {
  min-height: 46px;
  padding: 12px 18px;
  white-space: nowrap;
  font-size: 14px;
}

.projects-page .portfolio-panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.projects-page .portfolio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2vw, 24px);
  margin: 0;
  padding: 0;
  overflow: visible;
  scroll-snap-type: none;
  touch-action: pan-y pinch-zoom;
  min-width: 0;
}

.projects-page .portfolio-item {
  min-width: 0;
  min-height: 0;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 16px;
  background: #eef1f7;
  cursor: pointer;
  transform: none;
}

.projects-page .portfolio-item > img {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  object-fit: cover;
  object-position: center;
}

.projects-page .portfolio-label {
  max-width: calc(100% - 24px);
  left: 12px;
  bottom: 12px;
  min-height: 38px;
  padding: 8px 14px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
  font-size: 13px;
  background: rgba(6, 24, 49, .82);
}

.projects-page .portfolio-item:focus-visible {
  outline: 3px solid var(--yellow, #f4c430);
  outline-offset: 4px;
}

.projects-page .client-logo.is-unavailable {
  display: grid;
  place-items: center;
  text-align: center;
}

.projects-page .client-logo.is-unavailable img {
  display: none;
}

.projects-page .client-name {
  color: var(--blue, #2c2388);
  font-size: clamp(13px, 1.2vw, 16px);
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.projects-page #projectFeedModal {
  --project-modal-gap: clamp(16px, 4vh, 32px);
  --project-modal-gap: clamp(16px, 4dvh, 32px);
  --gallery-surface: #fff;
  --gallery-stage: #f0f2f6;
  --gallery-text: #15171c;
  --gallery-muted: #5e6472;
  --gallery-line: #e2e6ee;
  --bs-modal-bg: var(--gallery-surface);
  --bs-modal-color: var(--gallery-text);
}

.projects-page #projectFeedModal .modal-dialog {
  width: calc(100% - 24px);
  max-width: 960px;
  min-height: calc(100% - 2 * var(--project-modal-gap));
  margin: var(--project-modal-gap) auto;
}

.projects-page #projectFeedModal .modal-content {
  min-width: 0;
  max-height: calc(100vh - 2 * var(--project-modal-gap));
  max-height: calc(100dvh - 2 * var(--project-modal-gap));
  border-radius: 16px;
  background: var(--gallery-surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .24);
}

.projects-page #projectFeedModal .modal-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  width: 100%;
  flex: 0 0 auto;
  gap: 12px;
  min-height: 62px;
  padding: clamp(16px, 2.5vw, 24px);
  border-color: var(--gallery-line);
}

.projects-page #projectFeedCategory { color: var(--gallery-muted); font-size: 11px; letter-spacing: .12em; }
.projects-page #projectFeedTitle { margin: 0; color: var(--gallery-text); line-height: 1.3; }

.projects-page #projectFeedModal .modal-header > div {
  min-width: 0;
}

.projects-page #projectFeedTitle {
  font-size: clamp(15px, 2vw, 20px) !important;
  overflow-wrap: anywhere;
}

.projects-page #projectFeedModal .btn-close {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  background-position: center;
  background-size: 14px;
  background-color: var(--gallery-stage);
  border-radius: 50%;
  opacity: 1;
}

.projects-page #projectFeedModal .btn-close:is(:hover, :active, :focus) {
  background-color: var(--gallery-stage);
  box-shadow: none;
  opacity: 1;
}
.projects-page #projectFeedModal :is(button, a):focus-visible { outline: 3px solid #ffc200; outline-offset: 3px; }
.projects-page #projectFeedModal [hidden] { display: none !important; }
.projects-page #projectFeedModal .feed-carousel { background: var(--gallery-surface); }
.projects-page #projectFeedModal .feed-media { position: relative; background: var(--gallery-stage); }
.projects-page #projectFeedModal :is(.carousel-inner, .feed-slide) { background: var(--gallery-stage); }

.projects-page #projectFeedModal .modal-body {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.projects-page #projectFeedModal .feed-slide img {
  display: block;
  width: 100%;
  height: min(62vh, 680px);
  height: min(62dvh, 680px);
  max-height: calc(100vh - 200px);
  max-height: calc(100dvh - 200px);
  aspect-ratio: auto;
  object-fit: contain;
  background: var(--gallery-stage);
}

.projects-page #projectFeedModal .feed-details {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 2.5vw, 24px);
  border-top: 1px solid var(--gallery-line);
}

.projects-page #projectFeedModal .feed-caption {
  min-height: 0;
  padding: 0;
  color: var(--gallery-muted);
  overflow-wrap: anywhere;
}

.projects-page #projectFeedModal .feed-counter {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--gallery-stage);
  color: var(--gallery-text);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.projects-page #projectFeedModal .carousel-control-prev,
.projects-page #projectFeedModal .carousel-control-next {
  bottom: 0;
  min-width: 48px;
  width: 12%;
}

.projects-page #projectFeedModal .carousel-control-prev-icon,
.projects-page #projectFeedModal .carousel-control-next-icon {
  width: 44px;
  height: 44px;
  background-color: rgba(12, 18, 32, .8);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .15);
}

.projects-page #projectFeedModal .carousel-indicators {
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 10px;
  padding: 4px clamp(16px, 2.5vw, 24px) 20px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  background: var(--gallery-surface);
}

.projects-page #projectFeedModal .carousel-indicators [data-bs-target] {
  box-sizing: border-box;
  flex: 0 0 auto;
  width: 60px;
  height: 52px;
  margin: 0;
  border: 2px solid transparent;
  padding: 3px;
  border-radius: 8px;
  background: var(--gallery-stage);
  text-indent: 0;
  opacity: .65;
  overflow: hidden;
}

.projects-page #projectFeedModal .carousel-indicators img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; }

.projects-page #projectFeedModal .carousel-indicators .active {
  width: 60px;
  border-color: #ffc200;
  background: var(--gallery-stage);
  opacity: 1;
}

html[data-theme="dark"] .projects-page #projectFeedModal {
  --gallery-surface: #1c2232;
  --gallery-stage: #111520;
  --gallery-text: #f1f3fa;
  --gallery-muted: #b5bfd2;
  --gallery-line: #353d51;
}
html[data-theme="dark"] .projects-page #projectFeedModal .btn-close,
html[data-theme="dark"] .projects-page #projectFeedModal .btn-close:is(:hover, :active, :focus) { filter: invert(1); background-color: #dce2ef; }

@media (min-width: 576px) {
  .projects-page .portfolio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .projects-page .portfolio-tabs .nav-item {
    flex: 1 1 0;
  }
}

@media (min-width: 992px) {
  .projects-page .portfolio-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .projects-page #proyectos .section-head {
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    gap: 36px;
  }

  .projects-page .portfolio-tabs {
    max-width: 720px;
    margin-inline: auto;
  }
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .projects-page .portfolio-tabs .nav-link {
    transition: background-color .2s ease, color .2s ease, transform .2s ease, box-shadow .2s ease;
  }

  .projects-page .portfolio-tabs .nav-link:is(:hover, :focus-visible) {
    transform: translateY(-1px);
    background: #00007c;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 124, .12);
  }

  .projects-page .portfolio-tabs .nav-link:is(:hover, :focus-visible)::before {
    transform: scale(1.1);
  }

  .projects-page .portfolio-item {
    transition: transform .24s ease, box-shadow .24s ease;
  }

  .projects-page .portfolio-item > img { transition: transform .3s ease; }

  .projects-page .portfolio-item:hover {
    transform: translateY(-2px);
  }

  .projects-page .portfolio-item:is(:hover, :focus-visible) > img { transform: scale(1.02); }
}

@media (max-height: 480px) and (orientation: landscape) {
  .projects-page #projectFeedModal {
    --project-modal-gap: 8px;
  }

  .projects-page #projectFeedModal .modal-dialog {
    width: calc(100% - 16px);
    margin-block: 8px;
  }

  .projects-page #projectFeedModal .modal-content {
    max-height: calc(100dvh - 16px);
  }

  .projects-page #projectFeedModal .modal-header .kicker {
    display: none;
  }
}

/* Mobile gallery follows the image's natural ratio without empty vertical bands. */
@media (max-width: 767.98px), (max-height: 480px) and (pointer: coarse) {
  .projects-page #projectFeedModal {
    --gallery-top: max(12px, env(safe-area-inset-top, 0px));
    --gallery-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }

  .projects-page #projectFeedModal .modal-dialog {
    width: calc(100% - 16px);
    min-height: calc(100vh - var(--gallery-top) - var(--gallery-bottom));
    min-height: calc(100dvh - var(--gallery-top) - var(--gallery-bottom));
    height: auto;
    margin: var(--gallery-top) auto var(--gallery-bottom);
  }

  .projects-page #projectFeedModal .modal-content {
    height: auto;
    max-height: calc(100vh - var(--gallery-top) - var(--gallery-bottom));
    max-height: calc(100dvh - var(--gallery-top) - var(--gallery-bottom));
    border-radius: 18px;
  }

  .projects-page #projectFeedModal .modal-header {
    min-height: 68px;
    padding: 12px 14px;
    gap: 10px;
  }

  .projects-page #projectFeedTitle {
    max-height: 2.6em;
    overflow-y: auto;
    font-size: 16px !important;
  }

  .projects-page #projectFeedCategory { font-size: 10px; }
  .projects-page #projectFeedModal .btn-close { margin-left: auto; }

  .projects-page #projectFeedModal .modal-body {
    display: block;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .projects-page #projectFeedModal .feed-carousel {
    min-height: 0;
    display: block;
  }

  .projects-page #projectFeedModal .feed-media {
    min-height: 0;
    overflow: hidden;
    touch-action: pan-y pinch-zoom;
  }

  .projects-page #projectFeedModal :is(.carousel-inner, .carousel-item, .feed-slide) { height: auto; }

  .projects-page #projectFeedModal .feed-slide img,
  .projects-page #projectFeedModal .feed-placeholder {
    height: auto;
    max-height: none;
    aspect-ratio: auto;
    object-fit: contain;
  }

  .projects-page #projectFeedModal .feed-placeholder { aspect-ratio: 4 / 3; }

  .projects-page #projectFeedModal .feed-details {
    flex: 0 0 auto;
    gap: 12px;
    padding: 12px 14px;
  }

  .projects-page #projectFeedModal .feed-caption {
    min-width: 0;
    max-height: 3.9em;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.3;
  }

  .projects-page #projectFeedModal .feed-counter { padding: 6px 10px; }

  .projects-page #projectFeedModal .carousel-control-prev,
  .projects-page #projectFeedModal .carousel-control-next { width: 52px; }

  .projects-page #projectFeedModal .carousel-indicators {
    flex: 0 0 auto;
    gap: 8px;
    padding: 2px 14px 12px;
    scroll-padding-inline: 14px;
    touch-action: pan-x;
  }

  .projects-page #projectFeedModal .carousel-indicators [data-bs-target] {
    width: 56px;
    height: 48px;
  }
}

@media (max-height: 480px) and (pointer: coarse) {
  .projects-page #projectFeedModal .modal-header { min-height: 52px; padding-block: 4px; }
  .projects-page #projectFeedModal .feed-details { padding-block: 6px; }
  .projects-page #projectFeedModal .feed-caption { max-height: 2.6em; }
  .projects-page #projectFeedModal .carousel-indicators { padding-bottom: 8px; }
  .projects-page #projectFeedModal .carousel-indicators [data-bs-target] { width: 48px; height: 44px; }
}
