/* Mamaegima AI Chat Window - WhatsApp Green Theme */

:root {
  --whatsapp-primary: #25D366;
  --whatsapp-light: #DCF8C6;
  --whatsapp-dark: #128C7E;
  --white: #FFFFFF;
  --off-white: #FAFAFA;
  --gray-light: #F5F5F5;
  --gray-medium: #E0E0E0;
  --gray-dark: #757575;
  --text-primary: #212121;
  --text-secondary: #616161;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-hover: rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
}

#mamaegima-chat-container {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
}

/* Floating Chat Icon */
.chat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--whatsapp-primary) 0%, var(--whatsapp-dark) 100%);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--shadow);
  transition: all 0.3s ease;
}

.chat-icon:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px var(--shadow-hover);
}

.chat-icon svg {
  width: 32px;
  height: 32px;
}

.chat-icon.hidden {
  display: none;
}

/* Chat Window */
.chat-window {
  width: 380px;
  height: 600px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}

.chat-window.hidden {
  display: none;
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, var(--whatsapp-primary) 0%, var(--whatsapp-dark) 100%);
  color: var(--white);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px var(--shadow);
  position: relative; /* For agent indicator positioning */
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.assistant-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--white);
  color: var(--whatsapp-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.assistant-avatar svg {
  width: 24px;
  height: 24px;
}

.assistant-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.assistant-status {
  margin: 2px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: var(--white);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--off-white);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--gray-light);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--gray-medium);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--gray-dark);
}

/* Message Bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-self: flex-end;
  position: relative;
}

.message.assistant {
  align-self: flex-start;
  position: relative;
}

/* Message Tools Menu */
.message-tools {
  position: absolute;
  right: -220px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: row;
  gap: 6px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  background: var(--white);
  border-radius: 20px;
  padding: 6px 10px;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 10;
  min-width: 200px;
  flex-wrap: nowrap;
}

.message.user .message-tools {
  right: auto;
  left: -220px;
}

/* Desktop hover */
.message:hover .message-tools {
  opacity: 1;
  visibility: visible;
}

/* Mobile long-press - tools will be shown via JavaScript */
.message-tools.show-mobile {
  opacity: 1;
  visibility: visible;
}

/* Always visible on mobile */
@media (max-width: 768px) {
  .message-tools {
    position: relative;
    right: auto;
    left: auto;
    top: auto;
    transform: none;
    opacity: 1;
    visibility: visible;
    margin-top: 4px;
    justify-content: flex-start;
  }
  
  .message.user .message-tools {
    left: auto;
    right: auto;
    justify-content: flex-end;
  }
}

/* Swipe reply indicator */
.swipe-reply-indicator {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 24px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.message.user .swipe-reply-indicator {
  left: auto;
  right: 10px;
}

.message-tool-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-dark);
  transition: all 0.2s ease;
  padding: 0;
  font-size: 16px;
}

.message-tool-btn:hover {
  background: var(--gray-light);
  transform: scale(1.1);
}

.message-tool-btn:active {
  transform: scale(0.95);
}

.message-tool-btn.active {
  background: var(--whatsapp-light);
  color: var(--whatsapp-primary);
}

/* Reply Preview */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #f0f2f5;
  border-left: 3px solid var(--whatsapp-primary);
  margin: 0 12px 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  position: relative;
}

.reply-preview .reply-icon {
  font-size: 16px;
  color: var(--whatsapp-primary);
}

.reply-preview .reply-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #667781;
}

.reply-preview .reply-cancel {
  background: none;
  border: none;
  color: #8696a0;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s ease;
}

.reply-preview .reply-cancel:hover {
  color: var(--text-primary);
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  box-shadow: 0 1px 2px var(--shadow);
  line-height: 1.5;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--whatsapp-primary) 0%, var(--whatsapp-dark) 100%);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--white);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--gray-medium);
}

/* Message Content Formatting */
.message-content p {
  margin: 0 0 10px 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 600;
  color: var(--whatsapp-dark);
}

.message.user .message-content strong {
  color: var(--white);
}

.message-content em {
  font-style: italic;
}

.message-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin: 4px 0;
  list-style-type: disc;
}

.message-content br {
  line-height: 1.8;
}

.message-timestamp {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 8px;
}

.message.user .message-timestamp {
  text-align: right;
}

.message.assistant .message-timestamp {
  text-align: left;
}

/* Message Image Preview */
.message-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 8px;
  cursor: pointer;
}

.message-image img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Reply Thumbnail - Small version of image when replying */
.message-image-thumbnail {
  max-width: 120px;
  border-radius: 8px;
  margin-top: 8px;
  cursor: pointer;
  border: 2px solid var(--whatsapp-primary);
  opacity: 0.9;
}

.message-image-thumbnail img {
  width: 100%;
  height: auto;
  max-height: 120px;
  object-fit: cover;
  border-radius: 6px;
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  font-size: 14px;
}

.welcome-message h4 {
  color: var(--whatsapp-primary);
  margin: 0 0 8px 0;
  font-size: 16px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--white);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px var(--shadow);
  gap: 4px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-dark);
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Attachment Preview */
.attachment-preview {
  padding: 8px 16px;
  background: var(--whatsapp-light);
  border-top: 1px solid var(--gray-medium);
}

.attachment-preview.hidden {
  display: none;
}

.attachment-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-primary);
}

.remove-attachment-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.remove-attachment-btn:hover {
  color: var(--text-primary);
}

/* Chat Input Area */
.chat-input-area {
  background: var(--white);
  border-top: 1px solid var(--gray-medium);
}

.chat-input-controls {
  display: flex;
  align-items: center;
  padding: 12px;
  gap: 8px;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--gray-medium);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--whatsapp-primary);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: linear-gradient(135deg, var(--whatsapp-primary) 0%, var(--whatsapp-dark) 100%);
  color: var(--white);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.1);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

.chat-input-controls .icon-btn {
  background: transparent;
  color: var(--whatsapp-primary);
}

.chat-input-controls .icon-btn:hover {
  background: var(--whatsapp-light);
}

.hidden {
  display: none !important;
}

/* File Inputs - Ensure they're completely hidden */
input[type="file"] {
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  z-index: -1 !important;
  left: -9999px !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Product Card Styles */
.product-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid var(--whatsapp-primary);
  border-radius: 12px;
  padding: 16px;
  margin: 8px 0;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.15);
  max-width: 100%;
}

.product-card-header {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--whatsapp-light);
}

.product-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-detail {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.5;
}

.product-label {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 100px;
}

.product-value {
  color: var(--text-primary);
  text-align: right;
  flex: 1;
}

.product-value.in-stock {
  color: #28a745;
  font-weight: 600;
}

.product-value.out-of-stock {
  color: #dc3545;
  font-weight: 600;
}

/* Product Gallery Styles */
.product-gallery {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid var(--whatsapp-primary);
  border-radius: 12px;
  padding: 20px;
  margin: 10px 0;
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.15);
}

.gallery-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--whatsapp-light);
}

.gallery-header h4 {
  color: var(--whatsapp-primary);
  font-size: 20px;
  margin: 0 0 8px 0;
  font-weight: 700;
}

.gallery-header p {
  color: #666;
  font-size: 14px;
  margin: 0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.gallery-item {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.gallery-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.25);
  border-color: var(--whatsapp-primary);
}

.gallery-item-image {
  position: relative;
  width: 100%;
  padding-top: 100%; /* 1:1 Aspect Ratio */
  background: #f5f5f5;
  overflow: hidden;
}

.gallery-item-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.gallery-item:hover .gallery-item-image img {
  transform: scale(1.1);
}

.stock-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.stock-badge.low {
  background: #fff3cd;
  color: #856404;
}

.stock-badge.out {
  background: #f8d7da;
  color: #721c24;
}

.variations-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
  display: flex;
  align-items: center;
  gap: 4px;
}

.variations-badge::before {
  content: '🎨';
  font-size: 12px;
}

.gallery-item-details {
  padding: 12px;
}

.gallery-item-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin: 0 0 6px 0;
  line-height: 1.3;
  height: 36px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.gallery-item-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--whatsapp-primary);
  margin: 0 0 4px 0;
}

.gallery-item-color {
  font-size: 12px;
  color: #666;
  margin: 0 0 4px 0;
}

.gallery-item-sku {
  font-size: 11px;
  color: #999;
  margin: 0;
}

/* Responsive Gallery */
@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }
  
  .gallery-item-details {
    padding: 10px;
  }
  
  .gallery-item-name {
    font-size: 13px;
    height: 34px;
  }
  
  .gallery-item-price {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .product-gallery {
    padding: 15px;
  }
  
  .gallery-header h4 {
    font-size: 18px;
  }
}

/* Responsive Design - WhatsApp-like Mobile Experience */
@media (max-width: 768px) {
  #mamaegima-chat-container {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  .chat-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    border-radius: 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 100vh;
    max-height: 100dvh;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }

  .chat-input-area {
    flex-shrink: 0;
    position: relative;
    background: var(--white);
  }

  .chat-header {
    flex-shrink: 0;
    padding: 16px;
  }

  .chat-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10000;
  }

  .chat-icon svg {
    width: 32px;
    height: 32px;
  }

  .message {
    max-width: 85%;
  }

  .product-card {
    font-size: 14px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  body.chat-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  .chat-window {
    height: 100vh;
    height: 100dvh;
  }

  .chat-icon {
    width: 56px;
    height: 56px;
    bottom: 16px;
    right: 16px;
  }

  .chat-icon svg {
    width: 28px;
    height: 28px;
  }

  .chat-header {
    padding: 14px 12px;
    flex-shrink: 0;
  }

  .assistant-name {
    font-size: 15px;
  }

  .assistant-status {
    font-size: 11px;
  }

  .message-bubble {
    padding: 10px 14px;
    font-size: 15px;
  }

  .chat-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 12px 16px;
    max-height: 120px;
    overflow-y: auto;
  }

  .chat-input-controls {
    padding: 10px 12px;
  }

  .product-gallery {
    padding: 12px;
  }

  .gallery-header h4 {
    font-size: 16px;
  }
}

/* Voice Recording & Playback */
.icon-btn.recording {
  background-color: var(--whatsapp-primary) !important;
  color: var(--white) !important;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(212, 175, 55, 0);
  }
}

.voice-message {
  background-color: var(--gray-light) !important;
  padding: 12px !important;
}

.voice-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.message.user .voice-message {
  background: linear-gradient(135deg, var(--whatsapp-light) 0%, var(--whatsapp-primary) 100%) !important;
}

.message.user .voice-label {
  color: var(--whatsapp-dark);
}

audio {
  outline: none;
  border-radius: 20px;
}

audio::-webkit-media-controls-panel {
  background-color: var(--white);
  border-radius: 20px;
}

.speaking-indicator {
  text-align: center;
  padding: 12px;
  background: linear-gradient(135deg, var(--whatsapp-light) 0%, var(--white) 100%);
  border-radius: 12px;
  margin: 10px auto;
  max-width: 200px;
  font-weight: 500;
  color: var(--whatsapp-dark);
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Push Notification Prompt */
.push-prompt {
  position: fixed;
  bottom: 100px;
  right: 20px;
  z-index: 10000;
  animation: slideInUp 0.3s ease-out;
}

.push-prompt-content {
  background: var(--white);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 20px var(--shadow-hover);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  border: 2px solid var(--whatsapp-primary);
}

.push-prompt-content span {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.push-prompt-content button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

#enable-push-btn {
  background: linear-gradient(135deg, var(--whatsapp-primary) 0%, var(--whatsapp-dark) 100%);
  color: var(--white);
}

#enable-push-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

#dismiss-push-btn {
  background: var(--gray-light);
  color: var(--text-secondary);
}

#dismiss-push-btn:hover {
  background: var(--gray-medium);
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Agent Active Indicator */
.agent-active-indicator {
  display: none;
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #7C3AED 0%, #5B21B6 100%);
  color: var(--white);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
  50% {
    opacity: 0.8;
    transform: translateX(-50%) scale(1.05);
  }
}
