/* ==========================================================================
   CIM Gallery — "The Registry" archive module
   Institutional photo-archive treatment: navy / brass / warm paper,
   Fraunces display + IBM Plex Sans body, stamped corner-bracket cards.
   Drop in alongside the homepage stylesheet — reuses the same tokens.
   ========================================================================== */

:root {
  --cim-navy:        #1a2744;
  --cim-navy-deep:   #0f1830;
  --cim-brass:       #ff3019;
  --cim-brass-light: #d4b483;
  --cim-paper:       #fff;
  --cim-paper-dim:   #efe8d8;
  --cim-ink:         #2a2a28;
  --cim-ink-soft:    #5c5a52;
  --cim-border:      rgba(26, 39, 68, 0.14);
  --cim-gap: clamp(1rem, 2vw, 1.75rem);
  --cim-radius: 2px;
  --cim-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Grid shell ---------- */

.cim-gallery-grid-container {
  background: var(--cim-paper);
  padding: clamp(2rem, 5vw, 4.5rem) clamp(1.25rem, 5vw, 3rem);
}

.cim-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(220px, 26vw, 340px), 1fr));
  gap: var(--cim-gap);
  max-width: 1440px;
  margin: 0 auto;
}

/* ---------- Card ---------- */

.cim-gallery-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--cim-border);
  border-radius: var(--cim-radius);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.35s var(--cim-ease), box-shadow 0.35s var(--cim-ease);
}

.cim-gallery-card:hover,
.cim-gallery-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 18px 34px -18px rgba(15, 24, 48, 0.35);
}

.cim-gallery-card:focus-visible {
  outline: 2px solid var(--cim-brass);
  outline-offset: 3px;
}

/* stamped corner-bracket motif — real elements so GSAP can choreograph the
   "stamp" entrance (scale + rotate) instead of a flat CSS opacity fade. */
.cim-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--cim-brass);
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}

.cim-corner-tl {
  top: 8px;
  left: 8px;
  border-right: none;
  border-bottom: none;
}

.cim-corner-br {
  bottom: 8px;
  right: 8px;
  border-left: none;
  border-top: none;
}

/* Fallback if GSAP fails to load or JS is disabled: plain CSS fade.
   Once GSAP runs it sets inline styles on these elements, which take
   over from this rule automatically (inline style specificity wins). */
.cim-gallery-card:hover .cim-corner,
.cim-gallery-card:focus-visible .cim-corner {
  opacity: 1;
  transition: opacity 0.3s var(--cim-ease);
}

/* ---------- Image + overlay ---------- */

.cim-gallery-image-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--cim-paper-dim);
}

.cim-gallery-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s var(--cim-ease);
}

.cim-gallery-card:hover .cim-gallery-image-wrap img {
  transform: scale(1.06);
}

.cim-gallery-count {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: rgba(15, 24, 48, 0.72);
  backdrop-filter: blur(3px);
  color: var(--cim-paper);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 0.3em 0.65em;
  border-radius: 999px;
  z-index: 2;
}

.cim-gallery-count i {
  font-size: 0.85em;
  color: var(--cim-brass-light);
}

.cim-gallery-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 1.5rem;
  background: linear-gradient(
    to top,
    rgba(15, 24, 48, 0.82) 0%,
    rgba(15, 24, 48, 0.25) 45%,
    transparent 75%
  );
  opacity: 0;
  transition: opacity 0.35s var(--cim-ease);
}

.cim-gallery-card:hover .cim-gallery-overlay,
.cim-gallery-card:focus-visible .cim-gallery-overlay {
  opacity: 1;
}

.cim-gallery-view-btn {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cim-paper);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.55em 1.1em;
  border: 1px solid var(--cim-brass-light);
  border-radius: 999px;
  transform: translateY(8px);
  transition: transform 0.35s var(--cim-ease), background 0.25s var(--cim-ease);
}

.cim-gallery-card:hover .cim-gallery-view-btn {
  transform: translateY(0);
}

.cim-gallery-view-btn:hover {
  background: var(--cim-brass);
  border-color: var(--cim-brass);
}

.cim-gallery-view-btn i {
  font-size: 0.75em;
  transition: transform 0.25s var(--cim-ease);
}

.cim-gallery-card:hover .cim-gallery-view-btn i {
  transform: translateX(3px);
}

/* ---------- Caption ---------- */

.cim-gallery-caption {
  padding: 1.1rem 1.25rem 1.3rem;
  border-top: 1px solid var(--cim-border);
}

.cim-gallery-caption h3 {
  font-size: clamp(1rem, 1.4vw, 1.15rem);
  font-weight: 500;
  line-height: 1.3;
  color: var(--cim-navy);
  margin: 0;
}

/* ---------- Empty state ---------- */

.cim-gallery-empty {
  max-width: 560px;
  margin: 3rem auto;
  text-align: center;
  color: var(--cim-ink-soft);
  padding: 2.5rem;
  border: 1px dashed var(--cim-border);
  border-radius: var(--cim-radius);
}

.cim-gallery-empty a {
  color: var(--cim-navy);
  font-weight: 600;
  border-bottom: 1px solid var(--cim-brass);
}


.cim-gallery-hidden-slide {
  display: none;
}

.glightbox-clean .gslide-title,
.gslide-title {
  font-weight: 500 !important;
  color: var(--cim-paper) !important;
}

.gslide-description {
  background: var(--cim-navy) !important;
}

.glightbox-container {
  background: rgba(10, 15, 28, 0.94) !important;
}

.gslide-media {
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.5);
}

.glightbox-container .gnext,
.glightbox-container .gprev,
.glightbox-container .gclose {
  background: rgba(247, 243, 234, 0.1) !important;
  border: 1px solid rgba(247, 243, 234, 0.25) !important;
  border-radius: 50%;
  transition: background 0.2s var(--cim-ease), border-color 0.2s var(--cim-ease);
}

.glightbox-container .gnext:hover,
.glightbox-container .gprev:hover,
.glightbox-container .gclose:hover {
  background: var(--cim-brass) !important;
  border-color: var(--cim-brass) !important;
}

.gnext svg,
.gprev svg,
.gclose svg {
  fill: var(--cim-paper) !important;
}

/* thin brass progress rule under the toolbar, echoes the modal header
   treatment from the previous hand-rolled version */
.glightbox-container .gbtn.gclose {
  top: 1rem;
  right: 1rem;
}

/* ---------- Autoplay toggle ---------- */

.cim-autoplay-toggle {
  position: absolute;
  bottom: clamp(1rem, 4vw, 2rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 243, 234, 0.1);
  border: 1px solid var(--cim-brass-light);
  color: var(--cim-paper);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.2s var(--cim-ease), border-color 0.2s var(--cim-ease);
}

.cim-autoplay-toggle:hover,
.cim-autoplay-toggle:focus-visible {
  background: var(--cim-brass);
  border-color: var(--cim-brass);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .cim-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

@media (max-width: 560px) {
  .cim-gallery-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
  .cim-autoplay-toggle {
    width: 38px;
    height: 38px;
    bottom: 0.75rem;
  }
}

@media (max-width: 400px) {
  .cim-gallery-grid { grid-template-columns: 1fr; }
}

/* ---------- Motion & focus accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  .cim-gallery-card,
  .cim-gallery-image-wrap img,
  .cim-gallery-overlay,
  .cim-gallery-view-btn,
  .cim-gallery-view-btn i,
  .cim-autoplay-toggle {
    transition: none !important;
  }
}

:focus-visible {
  outline: 2px solid var(--cim-brass);
  outline-offset: 2px;
}