@use 'ui-design-system/src/styles/semantic/index' as *;

.ui-gallery-grid {
  // Core Structure
  display: grid;
  position: relative;
  width: 100%;
  
  // Layout & Spacing
  gap: $semantic-spacing-grid-gap-md;
  padding: $semantic-spacing-component-md;
  
  // Visual Design
  background: $semantic-color-surface-primary;
  border-radius: $semantic-border-radius-md;
  
  // Grid Sizing Variants
  &--columns-1 {
    grid-template-columns: 1fr;
  }
  
  &--columns-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  &--columns-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  &--columns-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  &--columns-5 {
    grid-template-columns: repeat(5, 1fr);
  }
  
  &--columns-6 {
    grid-template-columns: repeat(6, 1fr);
  }
  
  // Gap Size Variants
  &--gap-sm {
    gap: $semantic-spacing-grid-gap-sm;
  }
  
  &--gap-md {
    gap: $semantic-spacing-grid-gap-md;
  }
  
  &--gap-lg {
    gap: $semantic-spacing-grid-gap-lg;
  }
  
  // Responsive Grid Auto-fit
  &--auto-fit {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
  
  // Masonry-style layout option
  &--masonry {
    grid-auto-rows: min-content;
    align-items: start;
  }
  
  // Gallery Item
  &__item {
    position: relative;
    overflow: hidden;
    border-radius: $semantic-border-radius-md;
    background: $semantic-color-surface-secondary;
    border: $semantic-border-width-1 solid $semantic-color-border-subtle;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    cursor: pointer;
    
    // Interactive States
    &:hover {
      transform: translateY(-2px);
      box-shadow: $semantic-shadow-elevation-3;
      border-color: $semantic-color-border-primary;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
    }
    
    &:active {
      transform: translateY(0);
      box-shadow: $semantic-shadow-elevation-1;
    }
    
    // Loading State
    &--loading {
      opacity: $semantic-opacity-subtle;
      pointer-events: none;
      
      &::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 20px;
        height: 20px;
        margin: -10px 0 0 -10px;
        border: 2px solid $semantic-color-border-subtle;
        border-top-color: $semantic-color-primary;
        border-radius: $semantic-border-radius-full;
        animation: ui-gallery-grid-spin 1s linear infinite;
      }
    }
    
    // Selected State
    &--selected {
      border-color: $semantic-color-primary;
      box-shadow: $semantic-shadow-elevation-2;
      
      &::before {
        content: '';
        position: absolute;
        top: $semantic-spacing-component-xs;
        right: $semantic-spacing-component-xs;
        width: 20px;
        height: 20px;
        background: $semantic-color-primary;
        border-radius: $semantic-border-radius-full;
        z-index: 2;
      }
      
      &::after {
        content: '✓';
        position: absolute;
        top: $semantic-spacing-component-xs;
        right: $semantic-spacing-component-xs;
        width: 20px;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: $semantic-color-on-primary;
        font-size: $semantic-typography-font-size-xs;
        font-weight: $semantic-typography-font-weight-bold;
        z-index: 3;
      }
    }
  }
  
  // Image within gallery item
  &__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &--contain {
      object-fit: contain;
    }
    
    &--fill {
      object-fit: fill;
    }
    
    &--scale-down {
      object-fit: scale-down;
    }
  }
  
  // Overlay for additional information
  &__overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    color: $semantic-color-text-inverse;
    padding: $semantic-spacing-component-md;
    opacity: 0;
    transform: translateY(100%);
    transition: all $semantic-motion-duration-normal $semantic-motion-easing-ease;
    
    .ui-gallery-grid__item:hover & {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  // Overlay content
  &__title {
    font-family: map-get($semantic-typography-body-medium, font-family);
    font-size: map-get($semantic-typography-body-medium, font-size);
    font-weight: $semantic-typography-font-weight-semibold;
    line-height: map-get($semantic-typography-body-medium, line-height);
    color: $semantic-color-text-inverse;
    margin-bottom: $semantic-spacing-content-line-tight;
  }
  
  &__caption {
    font-family: map-get($semantic-typography-body-small, font-family);
    font-size: map-get($semantic-typography-body-small, font-size);
    font-weight: map-get($semantic-typography-body-small, font-weight);
    line-height: map-get($semantic-typography-body-small, line-height);
    color: $semantic-color-text-inverse;
    opacity: $semantic-opacity-subtle;
  }
  
  // Lightbox trigger indicator
  &__zoom-indicator {
    position: absolute;
    top: $semantic-spacing-component-xs;
    left: $semantic-spacing-component-xs;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    color: $semantic-color-text-inverse;
    border-radius: $semantic-border-radius-sm;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity $semantic-motion-duration-fast $semantic-motion-easing-ease;
    z-index: 2;
    
    .ui-gallery-grid__item:hover & {
      opacity: 1;
    }
    
    svg {
      width: 16px;
      height: 16px;
      fill: currentColor;
    }
  }
  
  // Empty state
  &__empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: $semantic-spacing-layout-section-lg;
    color: $semantic-color-text-secondary;
    text-align: center;
    
    &-icon {
      width: 48px;
      height: 48px;
      margin-bottom: $semantic-spacing-component-md;
      opacity: $semantic-opacity-subtle;
    }
    
    &-text {
      font-family: map-get($semantic-typography-body-medium, font-family);
      font-size: map-get($semantic-typography-body-medium, font-size);
      font-weight: map-get($semantic-typography-body-medium, font-weight);
      line-height: map-get($semantic-typography-body-medium, line-height);
    }
  }
  
  // Responsive Design
  @media (max-width: $semantic-breakpoint-lg - 1) {
    &--columns-6 {
      grid-template-columns: repeat(4, 1fr);
    }
    
    &--columns-5 {
      grid-template-columns: repeat(3, 1fr);
    }
  }
  
  @media (max-width: $semantic-breakpoint-md - 1) {
    padding: $semantic-spacing-component-sm;
    gap: $semantic-spacing-grid-gap-sm;
    
    &--columns-6,
    &--columns-5,
    &--columns-4 {
      grid-template-columns: repeat(2, 1fr);
    }
    
    &--columns-3 {
      grid-template-columns: repeat(2, 1fr);
    }
  }
  
  @media (max-width: $semantic-breakpoint-sm - 1) {
    padding: $semantic-spacing-component-xs;
    
    &--columns-6,
    &--columns-5,
    &--columns-4,
    &--columns-3,
    &--columns-2 {
      grid-template-columns: 1fr;
    }
    
    &--auto-fit {
      grid-template-columns: 1fr;
    }
  }
}

// Loading animation keyframes
@keyframes ui-gallery-grid-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}