/**
 * Lightbox / Modal Image Viewer Styles
 * ====================================
 * 
 * Styles for simple-lightbox.js with CSS-first progressive enhancement.
 * No-JS fallback: overlay hidden, no animations.
 */

/* ==========================================================================
   CSS-First Progressive Enhancement for Simple Lightbox
   ========================================================================== */

/* Default: Hidden, no animation (no-JS fallback) */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(var(--shadow-color), 0.92);
  z-index: var(--z-modal, 500);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  /* No transitions by default (no-JS fallback) */
}

/* Progressive enhancement: Enable transitions after fonts load */
.js-ready .lightbox-overlay {
  transition: opacity var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0, 0, 0.2, 1)),
              visibility var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0, 0, 0.2, 1));
}

.js-ready .lightbox-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Lightbox container */
.lightbox-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

/* Close button */
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 48px;
  height: 48px;
  background: transparent;
  border: 1px solid rgba(var(--shadow-color-light), var(--alpha-30));
  border-radius: 50%;
  color: rgb(var(--shadow-color-light));
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--duration-fast, 150ms) ease,
              border-color var(--duration-fast, 150ms) ease,
              transform var(--duration-fast, 150ms) ease;
  z-index: var(--z-dropdown);
}

.lightbox-close:hover {
  background: rgba(var(--shadow-color-light), var(--alpha-10));
  border-color: rgba(var(--shadow-color-light), var(--alpha-50));
  transform: scale(1.1);
}

.lightbox-close:focus-visible {
  outline: 2px solid rgb(var(--shadow-color-light));
  outline-offset: 2px;
}

/* Navigation buttons */
.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(var(--shadow-color-light), var(--alpha-10));
  border: 1px solid rgba(var(--shadow-color-light), var(--alpha-30));
  border-radius: 50%;
  color: rgb(var(--shadow-color-light));
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--duration-fast, 150ms) ease,
              border-color var(--duration-fast, 150ms) ease,
              transform var(--duration-fast, 150ms) ease;
  z-index: var(--z-dropdown);
}

.lightbox-prev {
  left: 1rem;
}

.lightbox-next {
  right: 1rem;
}

.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(var(--shadow-color-light), var(--alpha-20));
  border-color: rgba(var(--shadow-color-light), var(--alpha-50));
  transform: translateY(-50%) scale(1.1);
}

.lightbox-prev:focus-visible,
.lightbox-next:focus-visible {
  outline: 2px solid rgb(var(--shadow-color-light));
  outline-offset: 2px;
}

/* Content area */
.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Image loading state */
.lightbox-image {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  opacity: 0;
  transition: opacity var(--duration-fast, 150ms) var(--ease-out, cubic-bezier(0, 0, 0.2, 1));
  border-radius: var(--radius-md, 6px);
  box-shadow: 0 10px 40px rgba(var(--shadow-color), var(--alpha-50));
}

.lightbox-image.loaded {
  opacity: 1;
}

/* Loading spinner */
.lightbox-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid rgba(var(--shadow-color-light), var(--alpha-20));
  border-top-color: rgb(var(--shadow-color-light));
  border-radius: 50%;
  opacity: 0;
  transition: opacity var(--duration-fast, 150ms) ease;
  animation: lightbox-spin 1s linear infinite;
}

/* Show loading when image is not loaded */
.lightbox-overlay.active .lightbox-image:not(.loaded) + .lightbox-loading,
.lightbox-overlay.active .lightbox-content:not(:has(.lightbox-image.loaded)) .lightbox-loading {
  opacity: 1;
}

@keyframes lightbox-spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* Caption */
.lightbox-caption {
  color: rgb(var(--shadow-color-light));
  font-size: var(--text-sm, 1rem);
  text-align: center;
  margin-top: 1rem;
  max-width: 600px;
  line-height: 1.5;
  opacity: 0.9;
  text-shadow: 0 1px 3px rgba(var(--shadow-color), var(--alpha-50));
}

/* Counter */
.lightbox-counter {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgb(var(--shadow-color-light));
  font-size: var(--text-sm, 1rem);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .lightbox-overlay,
  .js-ready .lightbox-overlay,
  .lightbox-image,
  .lightbox-close,
  .lightbox-prev,
  .lightbox-next {
    transition: none !important;
    animation: none !important;
  }

  .lightbox-loading {
    animation: none !important;
    opacity: 0 !important;
  }

  /* Show image immediately without fade */
  .lightbox-image {
    opacity: 1 !important;
  }
}

/* ==========================================================================
   Mobile Optimizations
   ========================================================================== */

@media (max-width: 768px) {
  .lightbox-container {
    padding: 1rem;
  }

  .lightbox-close {
    top: 0.5rem;
    right: 0.5rem;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  .lightbox-prev,
  .lightbox-next {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  .lightbox-prev {
    left: 0.5rem;
  }

  .lightbox-next {
    right: 0.5rem;
  }

  .lightbox-image {
    max-height: 80vh;
  }

  .lightbox-caption {
    font-size: 0.875rem;
    padding: 0 1rem;
  }
}

/* ==========================================================================
   PhotoSwipe Customization (Legacy Support)
   ========================================================================== */

/* Custom background opacity */
.pswp__bg {
  background: var(--pswp-bg-color, rgba(0, 0, 0, 0.9));
}

/* Custom caption styles */
.pswp__caption {
  background: linear-gradient(to top, rgba(var(--shadow-color), var(--alpha-80)), transparent);
  padding: 1rem 1.5rem 2rem;
}

.pswp__caption__center {
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 600px;
  margin: 0 auto;
}

/* Custom button styles */
.pswp__button {
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.pswp__button:hover {
  opacity: 1;
}

/* Custom top bar */
.pswp__top-bar {
  background: linear-gradient(to bottom, rgba(var(--shadow-color), var(--alpha-50)), transparent);
  padding-top: 0.5rem;
}

/* Counter text */
.pswp__counter {
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
}

/* ==========================================================================
   Responsive Image Figures
   ========================================================================== */

.responsive-figure {
  margin: 2rem 0;
  text-align: center;
}

.responsive-figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.responsive-figcaption {
  font-size: 0.9rem;
  color: var(--text-muted, #666);
  margin-top: 0.75rem;
  font-style: italic;
  line-height: 1.5;
}

.responsive-figcaption p {
  margin: 0;
}

/* ==========================================================================
   Lightbox Trigger
   ========================================================================== */

.lightbox-trigger {
  cursor: zoom-in;
}

.lightbox-trigger a {
  display: inline-block;
  text-decoration: none;
}

/* Standard hover effect: Lift + subtle shadow (200ms) */
.lightbox-trigger img {
  transition: transform 0.2s var(--ease-out, cubic-bezier(0, 0, 0.2, 1)),
              box-shadow 0.2s var(--ease-out, cubic-bezier(0, 0, 0.2, 1));
}

.lightbox-trigger:hover img {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(var(--shadow-color), var(--alpha-15));
}

/* Reduced motion for trigger */
@media (prefers-reduced-motion: reduce) {
  .lightbox-trigger img {
    transition: none !important;
    transform: none !important;
  }
}

/* ==========================================================================
   Gallery Styles
   ========================================================================== */

/* Base gallery class used by gallery shortcode */
.gallery {
  margin: 2rem 0;
}

/* Grid layout with CSS custom property support for dynamic columns */
.gallery--grid {
  display: grid;
  grid-template-columns: repeat(var(--gallery-cols, auto-fit), 1fr);
  gap: 1rem;
}

/* Legacy gallery-grid class for backwards compatibility */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.gallery-grid .responsive-figure {
  margin: 0;
}

.gallery-grid img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

/* Masonry layout option */
.gallery-masonry {
  column-count: 3;
  column-gap: 1rem;
}

.gallery-masonry .responsive-figure {
  break-inside: avoid;
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .gallery-masonry {
    column-count: 2;
  }
}

@media (max-width: 480px) {
  .gallery-masonry {
    column-count: 1;
  }
}

/* ==========================================================================
   Card / Callout Styles
   ========================================================================== */

.content-card {
  margin: 1.5rem 0;
  padding: 1.25rem;
  border-radius: 8px;
  border-left: 4px solid;
  background: var(--card-bg, #f8f9fa);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.card-content {
  line-height: 1.6;
}

.card-content > *:first-child {
  margin-top: 0;
}

.card-content > *:last-child {
  margin-bottom: 0;
}

/* Card type variants - using design system colors */
.card-info,
.card-note {
  border-color: var(--color-info);
  background: var(--color-info-bg);
}

.card-info .card-icon,
.card-note .card-icon {
  color: var(--color-info);
}

.card-tip,
.card-success {
  border-color: var(--color-success);
  background: var(--color-success-bg);
}

.card-tip .card-icon,
.card-success .card-icon {
  color: var(--color-success);
}

.card-warning {
  border-color: var(--color-warning);
  background: var(--color-warning-bg);
}

.card-warning .card-icon {
  color: var(--color-warning);
}

.card-danger {
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

.card-danger .card-icon {
  color: var(--color-error);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .content-card {
    background: var(--card-bg-dark, #1a1a1a);
  }
  
  .card-info {
    background: rgba(0, 102, 204, 0.1);
  }
  
  .card-tip {
    background: rgba(0, 168, 84, 0.1);
  }
  
  .card-warning {
    background: rgba(250, 173, 20, 0.1);
  }
  
  .card-danger {
    background: rgba(245, 34, 45, 0.1);
  }
  
  .card-success {
    background: rgba(82, 196, 26, 0.1);
  }
}

/* ==========================================================================
   Table Wrapper (responsive tables)
   ========================================================================== */

.table-wrapper {
  overflow-x: auto;
  margin: 1.5rem 0;
  border-radius: 8px;
  border: 1px solid var(--border-color, #e0e0e0);
}

.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

.table-wrapper th,
.table-wrapper td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.table-wrapper th {
  background: var(--table-header-bg, #f5f5f5);
  font-weight: 600;
}

.table-wrapper tr:last-child td {
  border-bottom: none;
}

/* ==========================================================================
   Anchor Links
   ========================================================================== */


h2:hover .anchor-link,
h3:hover .anchor-link,
h4:hover .anchor-link,
h5:hover .anchor-link,
h6:hover .anchor-link {
  opacity: 1;
}

/* ==========================================================================
   Focus styles for accessibility
   ========================================================================== */

.lightbox-trigger:focus {
  outline: 2px solid var(--focus-color, #0066cc);
  outline-offset: 2px;
}

.pswp__button:focus {
  outline: 2px solid white;
  outline-offset: -2px;
}

/* ==========================================================================
   Animation for lightbox open/close (PhotoSwipe legacy)
   ========================================================================== */

@keyframes lightboxFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.pswp--open {
  animation: lightboxFadeIn 0.3s ease;
}

/* ==========================================================================
   Loading state for images
   ========================================================================== */

.responsive-img {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.responsive-img[src] {
  animation: none;
  background: transparent;
}

