/* ================================================
   Admiral Portrait Gallery v2.0.0 — Frontend CSS
   Themes: dark | light | minimal | slate
   admiralsentinel.com
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Shared token defaults (dark theme) ── */
.apg-gallery-wrapper {
  --apg-bg:           #0e0e0e;
  --apg-surface:      #161616;
  --apg-border:       rgba(255,255,255,.08);
  --apg-accent:       #c9a96e;
  --apg-accent-dim:   rgba(201,169,110,.14);
  --apg-text:         #f0ede8;
  --apg-muted:        rgba(240,237,232,.45);
  --apg-overlay-from: rgba(0,0,0,.92);
  --apg-overlay-mid:  rgba(0,0,0,.38);
  --apg-lb-bg:        rgba(0,0,0,.94);
  --apg-lb-blur:      blur(8px);
  --apg-radius:       4px;
  --apg-ratio:        133.33%; /* 3:4 portrait */
  --apg-transition:   .36s cubic-bezier(.4,0,.2,1);
  --apg-font-head:    'Cormorant Garamond', Georgia, serif;
  --apg-font-body:    'DM Sans', system-ui, sans-serif;
  --apg-cat-color:    var(--apg-accent);
  --apg-pag-active-bg: var(--apg-accent);
  --apg-pag-active-fg: #000;
  /* Spacing & size — overridden per-gallery via inline style */
  --apg-padding-x:    40px;   /* side padding */
  --apg-gap:          12px;   /* gap between thumbnails */
  --apg-thumb-max:    300px;  /* max thumbnail width */
}

/* ── THEME: Light ── */
.apg-theme-light {
  --apg-bg:           #f8f6f2;
  --apg-surface:      #ffffff;
  --apg-border:       rgba(0,0,0,.1);
  --apg-accent:       #b8893a;
  --apg-accent-dim:   rgba(184,137,58,.12);
  --apg-text:         #1a1a1a;
  --apg-muted:        rgba(26,26,26,.5);
  --apg-overlay-from: rgba(0,0,0,.82);
  --apg-overlay-mid:  rgba(0,0,0,.25);
  --apg-lb-bg:        rgba(245,243,240,.96);
  --apg-lb-blur:      blur(12px);
  --apg-cat-color:    var(--apg-accent);
  --apg-pag-active-bg: var(--apg-accent);
  --apg-pag-active-fg: #fff;
}

/* ── THEME: Minimal ── */
.apg-theme-minimal {
  --apg-bg:           #ffffff;
  --apg-surface:      #fafafa;
  --apg-border:       rgba(0,0,0,.07);
  --apg-accent:       #111111;
  --apg-accent-dim:   rgba(17,17,17,.06);
  --apg-text:         #111111;
  --apg-muted:        rgba(17,17,17,.45);
  --apg-overlay-from: rgba(17,17,17,.88);
  --apg-overlay-mid:  rgba(17,17,17,.2);
  --apg-lb-bg:        rgba(255,255,255,.97);
  --apg-lb-blur:      blur(10px);
  --apg-cat-color:    rgba(17,17,17,.5);
  --apg-pag-active-bg: #111;
  --apg-pag-active-fg: #fff;
}

/* ── THEME: Slate ── */
.apg-theme-slate {
  --apg-bg:           #1e2433;
  --apg-surface:      #252d3d;
  --apg-border:       rgba(255,255,255,.08);
  --apg-accent:       #7eb3e8;
  --apg-accent-dim:   rgba(126,179,232,.14);
  --apg-text:         #e8edf5;
  --apg-muted:        rgba(232,237,245,.45);
  --apg-overlay-from: rgba(10,15,30,.92);
  --apg-overlay-mid:  rgba(10,15,30,.35);
  --apg-lb-bg:        rgba(20,26,40,.96);
  --apg-lb-blur:      blur(8px);
  --apg-cat-color:    var(--apg-accent);
  --apg-pag-active-bg: var(--apg-accent);
  --apg-pag-active-fg: #111;
}

/* ══════════════════════════════════════════════
   WRAPPER
══════════════════════════════════════════════ */
.apg-gallery-wrapper {
  position: relative;
  width: 100%;
  background: var(--apg-bg);
  /* Side padding uses the configurable variable */
  padding: 2.5rem var(--apg-padding-x) 1.5rem;
  box-sizing: border-box;
  font-family: var(--apg-font-body);
  color: var(--apg-text);
  border-radius: 6px;
  transition: background .3s;
}

/* ── Header ── */
.apg-header {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 2rem;
}
.apg-header__line {
  flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--apg-accent), transparent);
}
.apg-header__label {
  font-family: var(--apg-font-head);
  font-size: 1rem; font-style: italic;
  letter-spacing: .35em; text-transform: uppercase;
  color: var(--apg-accent); white-space: nowrap;
}

/* ══════════════════════════════════════════════
   GRID  (columns driven by class; gap & max-width from CSS vars)
══════════════════════════════════════════════ */
.apg-grid {
  display: grid;
  gap: var(--apg-gap);           /* configurable gap between thumbnails */
  transition: opacity .28s ease;
}

/* Column widths: use minmax so thumb-max caps the column width */
.apg-grid--cols-2 { grid-template-columns: repeat(2, minmax(0, var(--apg-thumb-max))); justify-content: center; }
.apg-grid--cols-3 { grid-template-columns: repeat(3, minmax(0, var(--apg-thumb-max))); justify-content: center; }
.apg-grid--cols-4 { grid-template-columns: repeat(4, minmax(0, var(--apg-thumb-max))); justify-content: center; }
.apg-grid--cols-5 { grid-template-columns: repeat(5, minmax(0, var(--apg-thumb-max))); justify-content: center; }

@media (max-width: 960px) {
  .apg-grid--cols-4,.apg-grid--cols-5 { grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 640px) {
  .apg-grid--cols-3,.apg-grid--cols-4,.apg-grid--cols-5 { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 380px) { .apg-grid { grid-template-columns: 1fr !important; } }

/* ══════════════════════════════════════════════
   ITEM
══════════════════════════════════════════════ */
.apg-item {
  position: relative;
  border-radius: var(--apg-radius);
  overflow: hidden;
  background: var(--apg-surface);
}

/* shared link / button reset */
.apg-item__link {
  display: block; text-decoration: none; color: inherit;
  width: 100%; border: none; padding: 0; margin: 0;
  cursor: pointer; background: none;
}

/* Portrait figure — 3:4 */
.apg-item__figure {
  position: relative; margin: 0; padding: 0;
  padding-top: var(--apg-ratio);
  overflow: hidden; background: color-mix(in srgb, var(--apg-surface) 80%, black);
}
.apg-item__img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center top;
  display: block;
  transition: transform var(--apg-transition), filter var(--apg-transition);
  will-change: transform;
}

/* Overlay */
.apg-item__overlay {
  position: absolute; inset: 0;
  background: linear-gradient(
    to top,
    var(--apg-overlay-from) 0%,
    var(--apg-overlay-mid)  45%,
    transparent 70%
  );
  display: flex; flex-direction: column; justify-content: flex-end;
  opacity: 0;
  transition: opacity var(--apg-transition);
}
.apg-item__overlay-inner {
  padding: 1rem .9rem .8rem;
  transform: translateY(6px);
  transition: transform var(--apg-transition);
}
.apg-item__cat {
  display: inline-block;
  font-size: .6rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--apg-cat-color); font-weight: 500; margin-bottom: .2rem;
}
.apg-item__title {
  font-family: var(--apg-font-head);
  font-size: clamp(.82rem, 1.5vw, 1.05rem);
  font-weight: 400; color: #fff;
  margin: 0 0 .2rem; line-height: 1.25;
}
.apg-item__excerpt {
  font-size: .72rem; color: rgba(255,255,255,.65);
  margin: .2rem 0 0; line-height: 1.5;
}
.apg-item__date {
  display: block; font-size: .58rem;
  color: rgba(255,255,255,.4); margin-top: .28rem;
}
.apg-item__action-icon {
  position: absolute; top: .65rem; right: .65rem;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(.65);
  transition: opacity .22s, transform .22s, background .2s;
  pointer-events: none;
}
.apg-item__action-icon svg { width: 13px; height: 13px; color: #fff; }

/* Top accent bar */
.apg-item::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--apg-accent);
  transform: scaleX(0); transform-origin: left;
  transition: transform var(--apg-transition); z-index: 2;
}

/* Hover states */
.apg-item:hover .apg-item__img        { transform: scale(1.055); filter: brightness(.85); }
.apg-item:hover .apg-item__overlay    { opacity: 1; }
.apg-item:hover .apg-item__overlay-inner { transform: translateY(0); }
.apg-item:hover .apg-item__action-icon {
  opacity: 1; transform: scale(1);
  background: var(--apg-accent); border-color: var(--apg-accent);
}
.apg-item:hover::after                { transform: scaleX(1); }
.apg-item.is-pressed .apg-item__img   { filter: brightness(.65); }

/* ── No posts ── */
.apg-no-posts {
  grid-column: 1/-1; padding: 3rem; text-align: center;
  color: var(--apg-muted); font-style: italic;
}

/* ══════════════════════════════════════════════
   LOADING
══════════════════════════════════════════════ */
.apg-loading {
  display: none; position: absolute; inset: 0;
  background: color-mix(in srgb, var(--apg-bg) 80%, transparent);
  z-index: 10; align-items: center; justify-content: center; border-radius: 6px;
}
.apg-gallery-wrapper.is-loading .apg-loading { display: flex; }
.apg-gallery-wrapper.is-loading .apg-grid    { opacity: .25; pointer-events: none; }
.apg-loading__spinner { display: flex; gap: 7px; }
.apg-loading__spinner span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--apg-accent);
  animation: apg-bounce .9s ease-in-out infinite;
}
.apg-loading__spinner span:nth-child(2) { animation-delay: .15s; }
.apg-loading__spinner span:nth-child(3) { animation-delay: .30s; }
@keyframes apg-bounce {
  0%,80%,100% { transform: scale(.7); opacity: .35; }
  40%          { transform: scale(1.1); opacity: 1; }
}

/* ══════════════════════════════════════════════
   PAGINATION
══════════════════════════════════════════════ */
.apg-pagination {
  display: flex; align-items: center; justify-content: center;
  gap: .45rem; margin-top: 2rem; flex-wrap: wrap;
}
.apg-pagination__btn {
  width: 40px; height: 40px; border-radius: var(--apg-radius);
  background: var(--apg-surface); border: 1px solid var(--apg-border);
  color: var(--apg-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, border-color .2s, color .2s;
}
.apg-pagination__btn svg { width: 16px; height: 16px; }
.apg-pagination__btn:hover:not(:disabled) {
  background: var(--apg-accent-dim); border-color: var(--apg-accent); color: var(--apg-accent);
}
.apg-pagination__btn:disabled { opacity: .28; cursor: not-allowed; }
.apg-pagination__pages { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: center; }
.apg-pagination__page {
  min-width: 40px; height: 40px; padding: 0 .5rem;
  border-radius: var(--apg-radius); background: var(--apg-surface);
  border: 1px solid var(--apg-border); color: var(--apg-muted);
  font-family: var(--apg-font-body); font-size: .82rem; cursor: pointer;
  transition: all .18s;
}
.apg-pagination__page:hover {
  background: var(--apg-accent-dim); border-color: var(--apg-accent); color: var(--apg-accent);
}
.apg-pagination__page.is-active {
  background: var(--apg-pag-active-bg); border-color: var(--apg-pag-active-bg);
  color: var(--apg-pag-active-fg); font-weight: 600;
}

/* ══════════════════════════════════════════════
   LIGHTBOX
══════════════════════════════════════════════ */
.apg-lightbox {
  position: fixed; inset: 0; z-index: 99999;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; box-sizing: border-box;
  animation: apg-lb-in .28s ease both;
}
.apg-lightbox[hidden] { display: none; }

@keyframes apg-lb-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.apg-lightbox__backdrop {
  position: fixed; inset: 0; z-index: 99998;
  background: var(--apg-lb-bg);
  backdrop-filter: var(--apg-lb-blur);
  display: none;
}
.apg-lightbox__backdrop.is-open { display: block; }

/* Stage */
.apg-lightbox__stage {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  max-height: 90vh;
  animation: apg-lb-scale .3s cubic-bezier(.4,0,.2,1) both;
}
@keyframes apg-lb-scale {
  from { transform: scale(.94); }
  to   { transform: scale(1); }
}

.apg-lightbox__img-wrap {
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.apg-lightbox__img {
  max-height: 72vh;
  max-width: min(680px, 90vw);
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 3px;
  box-shadow: 0 32px 80px rgba(0,0,0,.6);
  display: block;
}

/* Caption */
.apg-lightbox__caption {
  margin-top: .85rem; text-align: center; max-width: 520px; width: 100%;
}
.apg-lightbox__title {
  font-family: var(--apg-font-head);
  font-size: 1.1rem; font-weight: 400; color: var(--apg-text);
  margin: 0 0 .3rem; line-height: 1.2;
}
.apg-lightbox__meta {
  display: flex; align-items: center; justify-content: center;
  gap: .6rem; flex-wrap: wrap;
}
.apg-lightbox__cat {
  font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--apg-cat-color); font-weight: 500;
}
.apg-lightbox__date { font-size: .68rem; color: var(--apg-muted); }
.apg-lightbox__post-link {
  display: inline-flex; align-items: center; gap: .4rem;
  margin-top: .6rem; font-size: .78rem; color: var(--apg-accent);
  text-decoration: none; border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.apg-lightbox__post-link:hover { border-color: var(--apg-accent); }
.apg-lightbox__post-link svg { width: 13px; height: 13px; }

.apg-lightbox__counter {
  position: absolute; top: -1.8rem; left: 50%; transform: translateX(-50%);
  font-size: .68rem; color: var(--apg-muted); letter-spacing: .08em; white-space: nowrap;
}

/* Close button */
.apg-lightbox__close {
  position: fixed; top: 1.2rem; right: 1.5rem; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(128,128,128,.12); border: 1px solid rgba(128,128,128,.2);
  color: var(--apg-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .22s;
}
.apg-lightbox__close:hover { background: rgba(128,128,128,.25); transform: rotate(90deg); }
.apg-lightbox__close svg { width: 18px; height: 18px; }

/* Nav buttons */
.apg-lightbox__nav {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(128,128,128,.1); border: 1px solid rgba(128,128,128,.18);
  color: var(--apg-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, border-color .2s;
}
.apg-lightbox__nav svg { width: 20px; height: 20px; }
.apg-lightbox__nav:hover { background: var(--apg-accent-dim); border-color: var(--apg-accent); color: var(--apg-accent); }
.apg-lightbox__nav:disabled { opacity: .2; cursor: not-allowed; }
.apg-lightbox__nav--prev { left: 1.2rem; }
.apg-lightbox__nav--next { right: 1.2rem; }

/* Light-theme lightbox text overrides */
.apg-theme-light .apg-lightbox__title,
.apg-theme-minimal .apg-lightbox__title { color: #111; }

/* ── Brand footer ── */
.apg-brand {
  text-align: center; margin: 1.4rem 0 0;
  font-size: .63rem; letter-spacing: .08em; text-transform: uppercase;
}
.apg-brand a { color: color-mix(in srgb, var(--apg-accent) 40%, transparent); text-decoration: none; transition: color .2s; }
.apg-brand a:hover { color: var(--apg-accent); }

/* ══════════════════════════════════════════════
   v2.1 — FILTER BAR
══════════════════════════════════════════════ */
.apg-filter {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--apg-border);
}

.apg-filter__pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .38rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--apg-border);
  background: var(--apg-surface);
  color: var(--apg-muted);
  font-family: var(--apg-font-body);
  font-size: .78rem;
  font-weight: 400;
  letter-spacing: .02em;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.apg-filter__pill:hover {
  border-color: var(--apg-accent);
  color: var(--apg-accent);
  background: var(--apg-accent-dim);
}

.apg-filter__pill.is-active {
  background: var(--apg-accent);
  border-color: var(--apg-accent);
  color: var(--apg-pag-active-fg, #000);
  font-weight: 500;
}

.apg-filter__count {
  font-size: .68rem;
  opacity: .65;
  background: rgba(128,128,128,.15);
  padding: .05rem .35rem;
  border-radius: 999px;
  line-height: 1.4;
}

.apg-filter__pill.is-active .apg-filter__count {
  background: rgba(0,0,0,.15);
  opacity: .8;
}

/* Filter transition: fade grid on filter change */
.apg-gallery-wrapper.is-loading .apg-filter { opacity: .5; pointer-events: none; }

/* ── Minimal/Light theme pill text ── */
.apg-theme-minimal .apg-filter__pill.is-active,
.apg-theme-light   .apg-filter__pill.is-active {
  color: #fff;
}

/* ══════════════════════════════════════════════
   v2.1 — PAGINATION: ellipsis
══════════════════════════════════════════════ */
.apg-pagination__ellipsis {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  color: var(--apg-muted);
  font-size: .85rem;
  user-select: none;
}

/* ══════════════════════════════════════════════
   v2.1 — LOAD MORE
══════════════════════════════════════════════ */
.apg-load-more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .85rem;
  margin-top: 2rem;
}

.apg-load-more {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .75rem 2.5rem;
  border-radius: var(--apg-radius);
  background: transparent;
  border: 1px solid var(--apg-accent);
  color: var(--apg-accent);
  font-family: var(--apg-font-body);
  font-size: .88rem;
  font-weight: 500;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background .22s, color .22s, transform .18s;
  min-width: 160px;
  overflow: hidden;
}

.apg-load-more:hover {
  background: var(--apg-accent);
  color: var(--apg-pag-active-fg, #000);
  transform: translateY(-1px);
}

.apg-load-more__spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: apg-spin .7s linear infinite;
}

@keyframes apg-spin { to { transform: rotate(360deg); } }

.apg-load-more.is-loading .apg-load-more__label  { opacity: 0; }
.apg-load-more.is-loading .apg-load-more__spinner { display: block; position: absolute; }

.apg-load-more__info {
  font-size: .75rem;
  color: var(--apg-muted);
  letter-spacing: .04em;
  text-align: center;
  margin: 0;
}

.apg-load-more__info--done {
  margin-top: 2rem;
  font-style: italic;
}

/* ══════════════════════════════════════════════
   v2.1 — INFINITE SCROLL SENTINEL
══════════════════════════════════════════════ */
.apg-infinite-sentinel {
  display: flex;
  justify-content: center;
  padding: 2rem 0 1rem;
  opacity: 0;
  transition: opacity .3s;
}
.apg-infinite-sentinel.is-loading { opacity: 1; }
