/*
 * Gallery UX Refinements
 * Improves clarity, orientation, and rhythm while maintaining calm aesthetic
 */

/* ==========================================================================
   CSS CUSTOM PROPERTIES
   ========================================================================== */

:root {
  /* Gallery grid layout */
  --gallery-card-aspect-ratio: 4 / 3;

  /* Gallery filter animations */
  --gallery-filter-stagger-delay: 50ms;
  --gallery-filter-fade-duration: 200ms;
}

/* ==========================================================================
   AVAILABLE VS SOLD SEPARATION
   ========================================================================== */

/* Section divider between available and sold works */
.gallery-section-divider {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-6);
  margin: var(--space-12) 0 var(--space-8);
  opacity: 0;
  animation: fadeIn 0.6s ease forwards;
}

.gallery-section-divider__line {
  flex: 1;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent 0%,
    var(--border-subtle) 20%,
    var(--border-subtle) 80%,
    transparent 100%
  );
}

.gallery-section-divider__label {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  opacity: 0.7;
  padding: 0 var(--space-3);
  white-space: nowrap;
}

[data-theme="dark"] .gallery-section-divider__label {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Subtle label for section headers */
.gallery-section-label {
  grid-column: 1 / -1;
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  opacity: 0.6;
  margin-bottom: var(--space-2);
  padding-left: var(--space-2);
}

/* Hide section label on mobile — vertical space is premium, and the
   filter bar already communicates that visible cards are available. */
@media (max-width: 767px) {
  .gallery-section-label {
    display: none;
  }
}

/* ==========================================================================
   COLLECTION FILTER REFINEMENTS
   ========================================================================== */

/* Reduce visual weight of filter UI — desktop only.
   Mobile uses Liquid Glass (semi-transparent bg + backdrop-filter)
   defined in mobile-gallery-improvements.css. Applying an opaque
   background here at all widths defeats the glass blur on mobile. */
@media (min-width: 768px) {
  .filter-bar {
    padding: var(--space-3) 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-default);
  }

  [data-theme="dark"] .filter-bar {
    background: var(--bg-primary);
    border-bottom-color: var(--border-default);
  }
}

.filter-controls {
  gap: var(--space-2);
}

/* Desktop-only pill refinements — mobile owns its own Liquid Glass
   styles in mobile-gallery-improvements.css. Without this guard the
   later-loading rules here override the mobile min-height / padding,
   shrinking pills below the WCAG 2.5.8 44px touch-target minimum. */
@media (min-width: 768px) {
  .filter-controls .tag {
    font-size: var(--text-xs);
    font-weight: 500;
    padding: var(--space-2) var(--space-3);
    min-height: 36px;
    border: 1px solid var(--border-default);
    background: var(--bg-primary);
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    transition: background-color 0.2s ease,
                border-color 0.2s ease,
                color 0.2s ease;
  }

  .filter-controls .tag:hover {
    border-color: var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
  }

  .filter-controls .tag.is-active,
  .filter-controls .tag-active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    font-weight: 600;
  }
}

/* ==========================================================================
   GALLERY SECTION STACK
   ========================================================================== */

.gallery-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
}

.gallery-group,
.gallery-archive {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.gallery-archive {
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}

.gallery-archive__note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.gallery-archive__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: linear-gradient(
    135deg,
    rgba(245, 236, 228, 0.72) 0%,
    rgba(255, 255, 255, 0.92) 100%
  );
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(26, 24, 22, 0.06);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.gallery-archive__toggle:hover {
  border-color: var(--copper-300);
  box-shadow: 0 12px 28px rgba(26, 24, 22, 0.08);
}

.gallery-archive__toggle:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

.gallery-archive__toggle-label {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
}

.gallery-archive__toggle-icon {
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1;
}

.gallery-archive__grid[hidden] {
  display: none !important;
}

[data-theme="dark"] .gallery-archive__toggle {
  background: linear-gradient(
    135deg,
    rgba(26, 24, 22, 0.92) 0%,
    rgba(45, 31, 23, 0.88) 100%
  );
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .gallery-archive__toggle:hover {
  border-color: rgba(217, 173, 143, 0.35);
}

/* ==========================================================================
   GRID LAYOUT IMPROVEMENTS - STABLE UNIFORM GRID
   ========================================================================== */

/*
 * Stable Grid Strategy:
 * - Use uniform aspect-ratio on all cards (prevents overlap)
 * - Consistent gaps and padding
 * - Prevent layout shift during image load
 * - Hover effects contained within card bounds
 */

/* Ensure stable layout with consistent gaps */
@media (min-width: 640px) {
  .bento-grid {
    column-gap: 16px;  /* 16px tight gap on tablet */
    row-gap: var(--space-4);
  }
}

@media (min-width: 1024px) {
  .bento-grid {
    column-gap: 16px;  /* Tighter gap for denser gallery feel */
    row-gap: var(--space-4);
  }
}

/* Prevent layout shift during image loading */
.artwork-card__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Prevent flicker on load */
  background: var(--bg-tertiary);
}

/* Loading state placeholder */
.artwork-card__image[data-loading] {
  background: var(--bg-elevated);
  min-height: 200px;
}

/* Collection divider captions for orientation */
.collection-divider {
  grid-column: 1 / -1;
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  opacity: 0.5;
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
  padding-left: var(--space-1);
  position: relative;
}

.collection-divider::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: -8px;
  width: 32px;
  height: 1px;
  background: var(--accent-primary);
  opacity: 0.3;
}

/* ==========================================================================
   HOVER INFORMATION ENHANCEMENT
   ========================================================================== */

/* Add dimensions to hover overlay */
.artwork-card__overlay-dimensions {
  font-size: var(--text-sm);
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
  margin: var(--space-1) 0 var(--space-2);
  letter-spacing: 0.02em;
}

/* Improved hierarchy: Title → Dimensions → Collection */
.artwork-card__overlay {
  position: absolute;
  inset: 0;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  /* Prevent layout reflow on hover */
  pointer-events: none;
  will-change: opacity, transform;
  /* Gradient background for readability */
  background: linear-gradient(
    to top,
    rgba(26, 24, 22, 0.92) 0%,
    rgba(26, 24, 22, 0.65) 40%,
    rgba(26, 24, 22, 0.25) 70%,
    transparent 100%
  );
}

[data-theme="dark"] .artwork-card__overlay {
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(0, 0, 0, 0.6) 40%,
    rgba(0, 0, 0, 0.2) 70%,
    transparent 100%
  );
}

.artwork-card__overlay-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: white;
  margin: 0 0 var(--space-2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.artwork-card__overlay-collection {
  font-size: var(--text-xs);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

/* Ensure CTA is clickable */
.artwork-card__overlay-cta {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
}

/* ==========================================================================
   MOBILE OPTIMIZATIONS
   ========================================================================== */

@media (max-width: 767px) {
  /* Simpler divider on mobile */
  .gallery-section-divider {
    margin: var(--space-8) 0 var(--space-6);
    gap: var(--space-4);
  }

  .gallery-section-divider__label {
    font-size: 0.75rem;
  }

  /* Hide collection dividers on mobile for cleaner look */
  .collection-divider {
    display: none;
  }

  /* Tighter grid on mobile */
  .bento-grid {
    gap: var(--space-3);
    row-gap: var(--space-4);
  }

  .gallery-groups {
    gap: var(--space-8);
  }

  .gallery-archive__toggle {
    padding: var(--space-3) var(--space-4);
  }

  .gallery-archive__toggle-label {
    font-size: var(--text-base);
  }
}

/* ==========================================================================
   ACCESSIBILITY & ANIMATIONS
   ========================================================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-section-divider {
    animation: none;
    opacity: 1;
  }

  .collection-divider {
    animation: none;
  }
}

/* Focus states for accessibility */
.filter-controls .tag:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   SOLD WORKS VISUAL TREATMENT
   ========================================================================== */

/* Subtle visual distinction for sold works */
.artwork-card--sold {
  opacity: 0.88;
}

.artwork-card--sold:hover {
  opacity: 1;
}

/* Ensure sold badge is prominent but not aggressive */
.artwork-card__badge--sold {
  background: rgba(26, 24, 22, 0.75);
  color: white;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

[data-theme="dark"] .artwork-card__badge--sold {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

/* ==========================================================================
   PRICE VISIBILITY (HIDDEN IN MAIN GRID)
   ========================================================================== */

/* Hide price in main gallery grid as per requirements */
.artwork-card__price {
  display: none !important;
}
