// Chat Component Common Styles

// Message Container Base
.message-container-base {
  display: flex;
  align-items: flex-start;
  border-radius: 8px;
  gap: 8px;
  
  @media (min-width: 640px) {
    gap: 20px;
  }
}

.avatar-container-base {
  border-radius: 50%;
  height: 3rem;
  width: 3rem;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

// Avatar Base Styles
.avatar-base {
  max-width: 100%;
  height: auto;
  width: 24px;
  
  &.avatar-image {
    object-fit: contain;
  }
  
  &.avatar-placeholder {
    background-color: rgba(128, 128, 128, 0.3);
    display: grid;
    place-items: center;
    font-size: 20px;
    font-weight: 500;
    color: var(--text-color);
    width: 100%;
    height: 100%;
  }
}

// Message Content Base Styles
.message-content-base {
  max-width: 90%;
  border-radius: 16px;
  font-size: 16px;
  white-space: pre-wrap;
  position: relative;
  background-color: #fff;
  border: 1px solid var(--light_gray);
  text-align: start;

  &.loading {
    align-self: flex-end;
  }
  
  // User message styling
  &.user-message {
    border-radius: 30px;
    color: var(--color2);
    padding: 12px 20px;
    
    @media (min-width: 640px) {
      padding: 20px 24px;
    }
  }
  
  // System/AI message styling
  &.system-message {
    &:not(.loading) {
      min-width: 100%;
    }

    padding: 16px 20px;
  }
}

// Message Text Content
.message-text-base {
  word-break: auto-phrase;
  
  .message-text-content {
    white-space: pre-wrap;
    font-family: var(--font);
    margin: 0;
    color: inherit;
    background: transparent;
    border: none;
    line-height: 1.6;
  }
}

// Button Base Styles
.btn-base {
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  
  &:disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
  }
  
  &.btn-primary {
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
    
    &:hover:not(:disabled) {
      background: transparent;
      color: var(--primary);
    }
  }
  
  &.btn-secondary {
    background: transparent;
    border: 1px solid var(--gray);
    color: var(--text-color);
    
    &:hover:not(:disabled) {
      background: var(--bg1);
      color: var(--color2);
    }
  }
  
  &.btn-danger {
    background: var(--red);
    color: white;
    border: 1px solid var(--red);
    
    &:hover:not(:disabled) {
      background: rgba(239, 68, 68, 0.8);
    }
  }
  
  &.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: var(--bg1);
    color: var(--gray);
    
    &:hover:not(:disabled) {
      background: var(--bg2);
      border-color: var(--green);
      color: var(--green);
    }
    
    .material-icons {
      font-size: 16px;
    }
  }
}

// Form Input Base
.input-base {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-color);
  font-family: var(--font);
  
  &::placeholder {
    color: var(--gray);
  }
  
  &.textarea-base {
    resize: none;
    min-height: 44px;
    max-height: 200px;
    padding: 12px;
  }
}

// File Attachment Styles
.file-attachment-base {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border: 1px solid #e9edf793;
  box-shadow: 0px 2px 4px 0px rgba(23, 23, 23, 0.1019607843);
  border-radius: 8px;
  overflow: hidden;
  max-width: 600px;
  height: 70px;
  
  .file-icon {
    width: 80px;
    height: 100%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    
    .material-icons {
      font-size: 32px;
      color: white;
    }
  }
  
  .file-info {
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    flex: 1;
    justify-content: center;
    
    .file-name {
      font-size: 15px;
      margin: 0;
      font-weight: 500;
    }
    
    .file-size {
      font-size: 12px;
      color: var(--gray);
    }
  }
}

// Loading States
.loading-base {
  display: flex;
  align-items: center;
  gap: 12px;
  
  .typing-indicator {
    display: flex;
    gap: 4px;
    
    span {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background-color: var(--primary);
      animation: typing 1.4s infinite ease-in-out;
      
      &:nth-child(1) {
        animation-delay: -0.32s;
      }
      
      &:nth-child(2) {
        animation-delay: -0.16s;
      }
    }
  }
  
  .loading-text {
    color: var(--gray);
    font-style: italic;
    margin: 0;
  }
  
  .loading-icon {
    animation: spin 1s linear infinite;
  }
}

// Action Groups
.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  
  &.justify-end {
    justify-content: flex-end;
  }
  
  &.justify-start {
    justify-content: flex-start;
  }
}

// Memory/Details Section
.details-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  
  details {
    summary {
      cursor: pointer;
      font-weight: 600;
      color: var(--green);
      margin-bottom: 8px;
      
      &:hover {
        color: var(--color1);
      }
    }
    
    .details-content {
      background: var(--bg1);
      padding: 12px;
      border-radius: 8px;
      font-size: 14px;
      color: var(--gray);
      white-space: pre-wrap;
      margin: 8px 0 0 0;
      border: none;
    }
  }
}

// Common Animations
@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

// Responsive helpers
@mixin mobile-spacing {
  @media (max-width: 640px) {
    padding: 12px 16px;
    gap: 8px;
  }
}

@mixin desktop-spacing {
  @media (min-width: 640px) {
    padding: 20px 24px;
    gap: 20px;
  }
}

// RTL Support
@mixin rtl-support {
  :global(.rtl) & {
    margin-left: 0;
    margin-right: 20px;
  }
}
