#chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  background: var(--bg-color);
  overflow: hidden;
}

/* Messages Area */
#messages-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Message Bubbles */
.message {
  display: flex;
  margin-bottom: 0.5rem;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  justify-content: flex-end;
}

.message.bot {
  justify-content: flex-start;
}

/* Pending state - faded bubble */
.message.pending .message-bubble {
  opacity: 0.5;
  transition: opacity 0.3s ease;
}

.message-bubble {
  max-width: 70%;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  transition: opacity 0.3s ease;
}

.message.user .message-bubble {
  background: var(--primary-color);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.bot .message-bubble {
  background: white;
  color: var(--text-color);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.message-content {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

.message-time {
  font-size: 0.75rem;
}

.message-status {
  font-size: 0.875rem;
}

.message-status.pending { color: #999; }
.message-status.sending { color: #999; }
.message-status.sent { color: #999; }
.message-status.delivered { color: #4CAF50; }
.message-status.read { color: #2196F3; }

/* Message Error State */
.message.error .message-bubble {
  opacity: 1 !important; /* Override pending opacity */
}

.message-error {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #fff5f5;
  border-radius: 8px;
}

.message-error .retry-message-btn {
  margin-top: 0.25rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.message-error-overlay {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #ffc9c9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.message-error-overlay small {
  font-size: 0.75rem;
  flex: 1;
}

.retry-message-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  text-decoration: none;
}

.retry-message-btn:hover {
  text-decoration: underline;
}

/* Product Card */
.product-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  max-width: 300px;
}

.product-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-card-body {
  padding: 1rem;
}

.product-card-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.product-card-price {
  color: var(--accent-color);
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.product-card-description {
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 1rem;
}

.product-card-actions {
  display: flex;
  gap: 0.5rem;
}

/* Product Message Card (type=product) */
.product-message-card {
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  max-width: 500px;
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
}

.product-message-image {
  position: relative;
  width: 120px;
  height: 120px;
  background: #f5f5f5;
  border-radius: 8px;
  overflow: hidden;
}

.product-message-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-sale-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #ff4444;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
}

.product-message-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.product-message-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: #333;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-message-code {
  font-size: 0.75rem;
  color: #999;
}

.product-message-price {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.product-old-price {
  font-size: 0.875rem;
  color: #999;
  text-decoration: line-through;
}

.product-current-price {
  font-size: 1.125rem;
  font-weight: bold;
  color: #FF8C00;
}

.product-unit {
  font-size: 0.875rem;
  color: #666;
}

.product-message-note {
  grid-column: 1 / 3;
  font-size: 0.875rem;
  color: #666;
  line-height: 1.5;
  margin-top: 0.5rem;
}

.product-note-content {
  display: inline;
}

.product-note-toggle {
  color: #007bff;
  text-decoration: none;
  font-weight: bold;
  margin-left: 0.25rem;
}

.product-note-toggle:hover {
  text-decoration: underline;
}

.product-note-full {
  display: inline;
}

.product-buy-btn {
  align-self: flex-start;
  padding: 0.375rem 1rem;
  font-size: 0.875rem;
}

.product-buy-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.message.bot .product-message-card {
  background: rgba(255, 255, 255, 0.98);
}

.message.user .product-message-card {
  background: rgba(255, 255, 255, 0.95);
}

@media (max-width: 576px) {
  .product-message-card {
    max-width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
  }
  
  .product-message-image {
    width: 100%;
    height: 180px;
  }
  
  .product-message-note {
    margin-top: 0.5rem;
  }
}

/* Media Message */
.message-media {
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin: 0.25rem 0;
}

.message-media img,
.message-image {
  max-width: 100%;
  max-height: 400px;
  height: auto;
  display: block;
  border-radius: 12px;
  cursor: pointer;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.message-media img:hover,
.message-image:hover {
  transform: scale(1.02);
}

/* File Link */
.message-file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  text-decoration: none;
  color: var(--primary-color);
  transition: background 0.2s ease;
}

.message-file-link:hover {
  background: rgba(0, 0, 0, 0.1);
  text-decoration: none;
}

.message-file-link i {
  font-size: 1.2rem;
}

/* Typing Indicator */
#typing-indicator {
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-color);
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.typing-text {
  font-size: 0.875rem;
  color: #666;
}

/* Input Area */
#input-area {
  padding: 1rem 1.5rem;
  background: transparent;
  border-top: none;
}

#message-form {
  display: flex;
  justify-content: center;
}

.input-wrapper {
  position: relative;
  width: 100%;
  max-width: 800px;
  display: flex;
  align-items: flex-end;
  background: white;
  border-radius: 28px;
  padding: 8px 8px 8px 20px;
  box-shadow: 0 4px 16px rgba(0, 100, 0, 0.15),
              0 0 0 1px rgba(0, 100, 0, 0.1);
  transition: all 0.3s ease;
}

.input-wrapper:focus-within {
  box-shadow: 0 6px 24px rgba(0, 100, 0, 0.25),
              0 0 0 2px rgba(0, 100, 0, 0.3),
              0 0 20px rgba(0, 100, 0, 0.1);
  transform: translateY(-2px);
}

#message-input {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  border: none;
  background: transparent;
  padding: 8px 12px 8px 0;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}

#message-input::placeholder {
  color: #999;
}

#action-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-left: 8px;
}

#action-btn:hover {
  background: var(--bg-color);
  color: var(--primary-color);
  transform: scale(1.1);
}

#action-btn[data-action="send"] {
  background: var(--primary-color);
  color: white;
}

#action-btn[data-action="send"]:hover {
  background: #004d00;
  transform: scale(1.1);
}

#action-btn i {
  font-size: 22px;
  transition: transform 0.3s ease;
}

#action-btn[data-action="send"] i {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Order Info Card */
.order-info-card {
  background: #fff3cd;
  border-left: 4px solid var(--accent-color);
  padding: 1rem;
  border-radius: 8px;
}

.order-info-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--accent-color);
}

.order-item {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.875rem;
}

.order-total {
  font-weight: bold;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #ddd;
}

/* Upload Preview & Progress */
.upload-preview {
  position: relative;
  width: 300px;
  max-width: 100%;
}

.upload-preview-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
}

.upload-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.upload-progress-wrapper {
  width: 80%;
  text-align: center;
}

.upload-progress-wrapper .progress {
  height: 20px;
  background-color: rgba(255, 255, 255, 0.3);
}

.upload-progress-wrapper .progress-bar {
  background-color: var(--primary-color);
  font-size: 0.75rem;
  line-height: 20px;
}

.upload-error {
  text-align: center;
  padding: 1rem;
}

.upload-error i {
  font-size: 2rem;
}

.upload-error p {
  font-size: 0.875rem;
  margin: 0;
}

.retry-upload-btn {
  margin-top: 0.5rem;
}

.message.uploading .message-bubble {
  background: transparent;
  padding: 0;
}

/* Image Lightbox */
.image-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.image-lightbox.active {
  display: flex;
  animation: lightboxFadeIn 0.2s ease;
}

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

.lightbox-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  cursor: pointer;
  animation: overlayFadeIn 0.2s ease;
}

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

.lightbox-content {
  position: relative;
  z-index: 10000;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 80px;
}

.lightbox-image-wrapper {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-image-wrapper.loading::before {
  content: '';
  position: absolute;
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: lightboxSpinner 0.8s linear infinite;
  z-index: 1;
}

@keyframes lightboxSpinner {
  to { transform: rotate(360deg); }
}

.lightbox-image-wrapper.loading .lightbox-image {
  opacity: 0.3;
}

.lightbox-image {
  max-width: 100%;
  max-height: 85vh;
  height: auto;
  width: auto;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  animation: imageZoomIn 0.3s ease;
}

@keyframes imageZoomIn {
  from { 
    opacity: 0;
    transform: scale(0.9);
  }
  to { 
    opacity: 1;
    transform: scale(1);
  }
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: all 0.2s ease;
  z-index: 10001;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1) rotate(90deg);
}

.lightbox-close i {
  pointer-events: none;
}

/* Navigation Buttons */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  transition: all 0.2s ease;
  z-index: 10001;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-50%) scale(1.1);
}

.lightbox-nav.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.lightbox-prev {
  left: 20px;
}

.lightbox-next {
  right: 20px;
}

.lightbox-nav i {
  pointer-events: none;
}

/* Image Counter */
.lightbox-counter {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 10001;
  backdrop-filter: blur(10px);
}

/* Help Text */
.lightbox-help-text {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
  text-align: center;
  z-index: 10001;
}

.lightbox-help-text .mobile-help {
  display: none;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .lightbox-content {
    padding: 60px 20px 80px;
  }
  
  .lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }
  
  .lightbox-prev {
    left: 10px;
  }
  
  .lightbox-next {
    right: 10px;
  }
  
  .lightbox-close {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }
  
  .lightbox-counter {
    bottom: 50px;
    font-size: 0.85rem;
    padding: 6px 12px;
  }
  
  .lightbox-image {
    max-height: 75vh;
  }
  
  .lightbox-help-text .desktop-help {
    display: none;
  }
  
  .lightbox-help-text .mobile-help {
    display: inline;
  }
}

/* Link Preview Styles */
.link-preview-container {
  margin-top: 0.5rem;
}

.link-preview-loading {
  padding: 0.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.link-preview {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: var(--card-bg);
  transition: all 0.2s ease;
  max-width: 400px;
}

.link-preview:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.link-preview-image {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.link-preview-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.link-preview-content {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.link-preview-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.link-preview-description {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.link-preview-url {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: auto;
}

.link-preview-url i {
  font-size: 0.875rem;
}

/* Bot message link preview styling */
.message.bot .link-preview {
  background: rgba(255, 255, 255, 0.05);
}

.message.user .link-preview {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 768px) {
  .link-preview {
    max-width: 100%;
  }
  
  .link-preview-image {
    width: 100px;
    height: 100px;
  }
  
  .link-preview-content {
    padding: 0.5rem;
  }
  
  .link-preview-title {
    font-size: 0.85rem;
  }
  
  .link-preview-description {
    font-size: 0.75rem;
  }
}

/* Toast Notification */
.chat-toast {
  position: fixed;
  top: 80px;
  right: 20px;
  background-color: #28a745;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  transform: translateX(400px);
  transition: all 0.3s ease;
  max-width: 350px;
  word-wrap: break-word;
}

.chat-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.chat-toast i {
  font-size: 1.25rem;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .chat-toast {
    top: 70px;
    right: 10px;
    left: 10px;
    max-width: none;
    font-size: 0.85rem;
  }
}
