/*
 * AP Drive Comic Gallery — Frontend Styles
 * Gallery grid + lightbox viewer
 */

/* ── Custom Properties ─────────────────────────────────────────────────────── */
.apdg-gallery,
.apdg-lightbox {
  --apdg-accent:     #4F6EF7;
  --apdg-accent-alt: #00C2FF;
  --apdg-dark:       #0d1117;
  --apdg-overlay:    rgba(0, 0, 0, 0.92);
  --apdg-radius:     12px;
  --apdg-gap:        16px;
  --apdg-transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --apdg-font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Gallery Grid ──────────────────────────────────────────────────────────── */
.apdg-gallery {
  display: grid;
  grid-template-columns: repeat(var(--apdg-cols, 4), 1fr);
  gap: var(--apdg-gap);
  width: 100%;
  padding: 0;
  margin: 0;
}

/* Responsive columns — set via CSS custom properties from JS */
@media (max-width: 900px) {
  .apdg-gallery {
    grid-template-columns: repeat(var(--apdg-cols-tablet, 3), 1fr);
  }
}

@media (max-width: 600px) {
  .apdg-gallery {
    grid-template-columns: repeat(var(--apdg-cols-mobile, 2), 1fr);
    gap: 10px;
  }
}

/* ── Gallery Item ──────────────────────────────────────────────────────────── */
.apdg-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  background: #fff;
  border: none;
  border-radius: var(--apdg-radius);
  padding: 0;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition:
    transform var(--apdg-transition),
    box-shadow var(--apdg-transition);
  overflow: hidden;
  outline: none;
}

.apdg-item:hover,
.apdg-item:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(79, 110, 247, 0.18);
}

.apdg-item:focus-visible {
  outline: 3px solid var(--apdg-accent);
  outline-offset: 2px;
}

/* ── Thumbnail wrap ────────────────────────────────────────────────────────── */
.apdg-thumb-wrap {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;  /* portrait comic ratio */
  overflow: hidden;
  background: #f0f4ff;
}

.apdg-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--apdg-transition);
}

.apdg-item:hover .apdg-thumb {
  transform: scale(1.04);
}

/* ── Hover overlay ─────────────────────────────────────────────────────────── */
.apdg-hover-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(79, 110, 247, 0.72);
  opacity: 0;
  transition: opacity var(--apdg-transition);
}

.apdg-item:hover .apdg-hover-overlay,
.apdg-item:focus-visible .apdg-hover-overlay {
  opacity: 1;
}

.apdg-zoom-icon {
  width: 36px;
  height: 36px;
  color: #fff;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* ── Item label ────────────────────────────────────────────────────────────── */
.apdg-item-label { color: var(--apdg-card-label, #1A2340);
  font-family: var(--apdg-font);
  font-size: 12px;
  font-weight: 500;
  color: #333;
  padding: 6px 10px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

/* ── Empty / error states ──────────────────────────────────────────────────── */
.apdg-empty,
.apdg-admin-notice,
.apdg-error-notice {
  font-family: var(--apdg-font);
  font-size: 14px;
  color: #555;
  padding: 12px 16px;
  background: #f8f9ff;
  border-left: 4px solid var(--apdg-accent);
  border-radius: 6px;
  margin: 8px 0;
}

.apdg-admin-notice a {
  color: var(--apdg-accent);
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/*  LIGHTBOX                                                                   */
/* ═══════════════════════════════════════════════════════════════════════════ */

.apdg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

/* Hidden state — using both [hidden] and class for reliable hiding */
.apdg-lightbox[hidden],
.apdg-lightbox.apdg-lb-hidden {
  display: none !important;
}

/* ── Overlay ───────────────────────────────────────────────────────────────── */
.apdg-lb-overlay {
  position: fixed;
  inset: 0;
  background: var(--apdg-overlay);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  cursor: zoom-out;
}

/* ── Inner (above overlay) ─────────────────────────────────────────────────── */
.apdg-lb-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  pointer-events: none; /* children opt-in */
}

/* ── Toolbar ───────────────────────────────────────────────────────────────── */
.apdg-lb-toolbar {
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  gap: 12px;
}

.apdg-lb-counter {
  font-family: var(--apdg-font);
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.04em;
  min-width: 60px;
}

.apdg-lb-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.apdg-lb-title-bar {
  font-family: var(--apdg-font);
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: center;
  padding: 0 8px;
}

/* ── Icon buttons ──────────────────────────────────────────────────────────── */
.apdg-lb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  transition:
    background var(--apdg-transition),
    color var(--apdg-transition);
  padding: 0;
}

.apdg-lb-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  pointer-events: none;
}

.apdg-lb-btn:hover,
.apdg-lb-btn:focus-visible {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.apdg-lb-btn:focus-visible {
  outline: 2px solid var(--apdg-accent-alt);
  outline-offset: 2px;
}

.apdg-lb-btn-close {
  background: rgba(239, 68, 68, 0.2);
  color: rgba(255,120,120,0.9);
}

.apdg-lb-btn-close:hover {
  background: rgba(239, 68, 68, 0.5);
  color: #fff;
}

/* ── Stage (image area + nav) ──────────────────────────────────────────────── */
.apdg-lb-stage {
  pointer-events: all;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Image container ───────────────────────────────────────────────────────── */
.apdg-lb-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: auto;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
}

.apdg-lb-img-wrap.is-dragging {
  cursor: grabbing;
}

.apdg-lb-img-wrap.zoom-1x {
  cursor: zoom-in;
}

/* ── Lightbox image ────────────────────────────────────────────────────────── */
.apdg-lb-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  transform-origin: center center;
  transition: opacity 0.2s ease;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 4px;
}

.apdg-lb-img.loading {
  opacity: 0;
}

.apdg-lb-img.loaded {
  opacity: 1;
}

/* ── Loader / Spinner ──────────────────────────────────────────────────────── */
.apdg-lb-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.apdg-lb-loader.hidden {
  display: none;
}

.apdg-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--apdg-accent-alt);
  border-radius: 50%;
  animation: apdg-spin 0.7s linear infinite;
}

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

/* ── Nav buttons ───────────────────────────────────────────────────────────── */
.apdg-lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 64px;
  border: none;
  background: rgba(0,0,0,0.4);
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  border-radius: 8px;
  transition:
    background var(--apdg-transition),
    color var(--apdg-transition),
    transform var(--apdg-transition);
  pointer-events: all;
  padding: 0;
}

.apdg-lb-nav:hover,
.apdg-lb-nav:focus-visible {
  background: rgba(79, 110, 247, 0.6);
  color: #fff;
}

.apdg-lb-nav:focus-visible {
  outline: 2px solid var(--apdg-accent-alt);
  outline-offset: 2px;
}

.apdg-lb-nav svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.apdg-lb-prev {
  left: 12px;
}

.apdg-lb-next {
  right: 12px;
}

.apdg-lb-nav:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* ── Zoom level indicator ──────────────────────────────────────────────────── */
.apdg-lb-zoom-level {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--apdg-font);
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  pointer-events: none;
  background: rgba(0,0,0,0.4);
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s;
}

.apdg-lb-zoom-level.visible {
  opacity: 1;
}

/* ── Mobile adjustments ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .apdg-lb-toolbar {
    padding: 8px 10px;
  }

  .apdg-lb-btn {
    width: 34px;
    height: 34px;
  }

  .apdg-lb-btn svg {
    width: 16px;
    height: 16px;
  }

  .apdg-lb-nav {
    width: 40px;
    height: 56px;
  }

  .apdg-lb-prev {
    left: 4px;
  }

  .apdg-lb-next {
    right: 4px;
  }

  .apdg-lb-title-bar {
    display: none; /* save space on mobile */
  }
}

/* ── No-motion preference ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .apdg-item,
  .apdg-thumb,
  .apdg-hover-overlay,
  .apdg-lb-img,
  .apdg-lb-btn,
  .apdg-lb-nav {
    transition: none !important;
  }
  .apdg-spinner {
    animation-duration: 1.5s;
  }
}

/* ════════════════════════════════════════════════════════════════
   v2 additions — Synced-mode cards, Pagination
   ════════════════════════════════════════════════════════════════ */

/* Synced gallery wrap */
.apdg-gallery-wrap {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* Synced mode: cards are <a> links */
.apdg-item.apdg-item--link {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    width: 100%;
    border-radius: var(--apdg-radius, 12px);
}

.apdg-item.apdg-item--link:hover .apdg-hover-overlay,
.apdg-item.apdg-item--link:focus-visible .apdg-hover-overlay {
    opacity: 1;
}

.apdg-item.apdg-item--link:focus-visible {
    outline: 3px solid var(--apdg-accent, #4F6EF7);
    outline-offset: 3px;
}

/* Pagination nav */
.apdg-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.apdg-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--apdg-text, #1a2340);
    background: #f3f4f6;
    border: 1px solid #e5e9f5;
    transition: all 0.15s ease;
}

.apdg-pagination .page-numbers:hover {
    background: #e8edff;
    border-color: var(--apdg-accent, #4F6EF7);
    color: var(--apdg-accent, #4F6EF7);
}

.apdg-pagination .page-numbers.current {
    background: var(--apdg-accent, #4F6EF7);
    border-color: var(--apdg-accent, #4F6EF7);
    color: #fff;
    font-weight: 700;
    pointer-events: none;
}

.apdg-pagination .page-numbers.dots {
    background: transparent;
    border-color: transparent;
    pointer-events: none;
    color: #9ca3af;
}

@media (max-width: 480px) {
    .apdg-pagination .page-numbers { min-width: 32px; height: 32px; font-size: 12px; }
}

/* ════════════════════════════════════════════════════════════════
   AJAX Pagination — loading overlay + button styles
   ════════════════════════════════════════════════════════════════ */

/* Gallery wrap relative for loading overlay */
.apdg-gallery-wrap { position: relative; }

/* Loading overlay */
.apdg-pager-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 8px;
  pointer-events: none;
}

/* Spinner */
.apdg-pager-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(244,123,32,0.2);
  border-top-color: #F47B20;
  border-radius: 50%;
  animation: apdg-spin 0.7s linear infinite;
}

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

/* Gallery fade transition */
#apdg-gallery-pager {
  transition: opacity 0.2s ease;
}

/* Pagination buttons (AJAX — no href, all colors via CSS vars) */
.apdg-pagination .apdg-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--apdg-page-btn-txt, #1a2340);
  background: var(--apdg-page-btn-bg, #F3F4F6);
  border: 1px solid var(--apdg-page-btn-border, #E5E9F5);
  transition: all 0.15s ease;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}

.apdg-pagination .apdg-page-btn:hover {
  background: var(--apdg-page-btn-hover, #E8EDFF);
  border-color: var(--apdg-primary, #F47B20);
  color: var(--apdg-primary, #F47B20);
}

.apdg-pagination .apdg-page-btn.current {
  background: var(--apdg-page-active-bg, #F47B20);
  border-color: var(--apdg-page-active-bg, #F47B20);
  color: var(--apdg-page-active-txt, #FFFFFF);
  font-weight: 700;
  cursor: default;
  pointer-events: none;
}

.apdg-pagination .apdg-page-btn.prev,
.apdg-pagination .apdg-page-btn.next {
  padding: 0 14px;
  font-weight: 600;
}

@media (max-width: 480px) {
  .apdg-pagination .apdg-page-btn { min-width: 32px; height: 32px; font-size: 12px; }
  .apdg-pagination .apdg-page-btn.prev,
  .apdg-pagination .apdg-page-btn.next { padding: 0 10px; }
}
