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

.ui-modal {
  // Modal Backdrop
  &__backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: $semantic-spacing-layout-md;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity $semantic-motion-duration-normal $semantic-motion-easing-ease;
    
    &--visible {
      opacity: 1;
    }
    
    &--entering {
      animation: backdrop-fade-in $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
    
    &--leaving {
      animation: backdrop-fade-out $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
  }

  // Modal Container
  &__container {
    background: $semantic-color-surface-primary;
    border-radius: $semantic-border-radius-lg;
    box-shadow: $semantic-shadow-elevation-3;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    transition: all $semantic-motion-duration-normal $semantic-motion-easing-ease;
    
    &--visible {
      transform: scale(1) translateY(0);
      opacity: 1;
    }
    
    &--entering {
      animation: modal-slide-in $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
    
    &--leaving {
      animation: modal-slide-out $semantic-motion-duration-normal $semantic-motion-easing-ease;
    }
  }

  // Size Variants
  &--sm {
    .ui-modal__container {
      width: 400px;
    }
  }
  
  &--md {
    .ui-modal__container {
      width: 600px;
    }
  }
  
  &--lg {
    .ui-modal__container {
      width: 800px;
    }
  }
  
  &--xl {
    .ui-modal__container {
      width: 1000px;
    }
  }
  
  &--fullscreen {
    .ui-modal__backdrop {
      padding: 0;
    }
    
    .ui-modal__container {
      width: 100vw;
      height: 100vh;
      max-width: none;
      max-height: none;
      border-radius: 0;
    }
  }

  // Modal Header
  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: $semantic-spacing-component-lg;
    border-bottom: 1px solid $semantic-color-outline;
    background: $semantic-color-surface-primary;
    
    &--no-border {
      border-bottom: none;
    }
  }

  &__title {
    font-size: $semantic-typography-heading-h4-size;
    font-weight: $semantic-typography-font-weight-semibold;
    color: $semantic-color-on-surface;
    margin: 0;
    line-height: 1.4;
  }

  &__close-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: $semantic-border-radius-md;
    color: $semantic-color-on-surface-variant;
    cursor: pointer;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;
    
    &:hover {
      background: $semantic-color-surface-variant;
      color: $semantic-color-on-surface;
    }
    
    &:focus-visible {
      outline: 2px solid $semantic-color-primary;
      outline-offset: 2px;
    }
    
    &:active {
      background: $semantic-color-surface-container;
    }
  }

  // Modal Body
  &__body {
    padding: $semantic-spacing-component-lg;
    overflow-y: auto;
    max-height: calc(90vh - 200px);
    
    &--no-padding {
      padding: 0;
    }
    
    &--scrollable {
      overflow-y: auto;
    }
  }

  &__content {
    color: $semantic-color-on-surface;
    font-size: $semantic-typography-font-size-md;
    line-height: 1.6;
  }

  // Modal Footer
  &__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: $semantic-spacing-component-sm;
    padding: $semantic-spacing-component-lg;
    border-top: 1px solid $semantic-color-outline;
    background: $semantic-color-surface-primary;
    
    &--no-border {
      border-top: none;
    }
    
    &--center {
      justify-content: center;
    }
    
    &--start {
      justify-content: flex-start;
    }
    
    &--between {
      justify-content: space-between;
    }
  }

  // State Variants
  &--loading {
    .ui-modal__body {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 200px;
    }
  }

  &--danger {
    .ui-modal__header {
      background: $semantic-color-container-error;
      border-bottom-color: $semantic-color-error;
    }
    
    .ui-modal__title {
      color: $semantic-color-on-container-error;
    }
  }

  &--warning {
    .ui-modal__header {
      background: rgba($semantic-color-warning, 0.1);
      border-bottom-color: $semantic-color-warning;
    }
    
    .ui-modal__title {
      color: $semantic-color-on-warning;
    }
  }

  &--success {
    .ui-modal__header {
      background: rgba($semantic-color-success, 0.1);
      border-bottom-color: $semantic-color-success;
    }
    
    .ui-modal__title {
      color: $semantic-color-on-success;
    }
  }

  // Loading Spinner
  &__loader {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid $semantic-color-outline;
    border-radius: 50%;
    border-top-color: $semantic-color-primary;
    animation: modal-spin 1s linear infinite;
  }
  
  // Dark Mode Support
  :host-context(.dark-theme) & {
    &__backdrop {
      background: rgba(0, 0, 0, 0.8);
    }
  }
  
  // Responsive Design
  @media (max-width: 768px) {
    &__backdrop {
      padding: $semantic-spacing-component-sm;
    }
    
    &__container {
      width: 100% !important;
      max-width: none;
      margin: 0;
      border-radius: $semantic-border-radius-md;
    }
    
    &__header {
      padding: $semantic-spacing-component-md;
    }
    
    &__body {
      padding: $semantic-spacing-component-md;
      max-height: calc(90vh - 160px);
    }
    
    &__footer {
      padding: $semantic-spacing-component-md;
      flex-direction: column;
      gap: $semantic-spacing-component-xs;
      
      .ui-button {
        width: 100%;
      }
    }
    
    &__title {
      font-size: $semantic-typography-heading-h5-size;
    }
  }
}

// Animations
@keyframes backdrop-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes backdrop-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes modal-slide-in {
  from {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes modal-slide-out {
  from {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  to {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
}

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