/* AI Product Assistant Styles */

.ai-page {
  background: #f0f2f5;
  padding-top: calc(var(--header-height, 120px) + 24px);
  padding-bottom: 40px;
  min-height: auto;
}

.ai-container {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  height: 75vh;
  min-height: 500px;
  max-height: 800px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 24px rgba(0,0,0,0.08);
  border: 1px solid #e5e7eb;
}

/* ---- Chat Panel ---- */
.ai-chat-panel {
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.ai-chat-panel.drag-over {
  background: rgba(196,30,58,0.03);
  outline: 2px dashed var(--accent, #c41e3a);
  outline-offset: -4px;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
  color: white;
  flex-shrink: 0;
}

.ai-chat-header-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent, #c41e3a);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-chat-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}

.ai-chat-subtitle {
  font-size: 0.82rem;
  opacity: 0.7;
  margin: 0;
}

/* ---- Messages ---- */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  min-height: 0;
}

.ai-msg {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: msgIn 0.3s ease;
  flex-shrink: 0;
}

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

.ai-msg-user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.ai-msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ai-msg-avatar img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.ai-msg-content {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.65;
}

.ai-msg-assistant .ai-msg-content {
  background: #f5f5f5;
  border-bottom-left-radius: 4px;
  color: #1a1a1a;
}

.ai-msg-user .ai-msg-content {
  background: var(--accent, #c41e3a);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-msg-content p { margin: 0 0 10px; }
.ai-msg-content p:last-child { margin-bottom: 0; }
.ai-msg-content ul { margin: 8px 0; padding-left: 18px; }
.ai-msg-content li { margin-bottom: 4px; }
.ai-msg-content strong { font-weight: 700; }
.ai-msg-content code { background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

/* User attached image in chat */
.ai-msg-image {
  max-width: 240px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  margin-bottom: 6px;
}

.ai-msg-image img {
  width: 100%;
  display: block;
}

.ai-msg-user .ai-msg-image {
  margin-left: auto;
}

/* ---- Suggestions ---- */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.ai-suggestion {
  padding: 8px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  color: #555;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.ai-suggestion:hover {
  border-color: var(--accent, #c41e3a);
  color: var(--accent, #c41e3a);
  background: rgba(196,30,58,0.04);
}

/* ---- Typing indicator ---- */
.ai-typing {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.ai-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #aaa;
  animation: typeBounce 1.4s infinite ease-in-out;
}

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

@keyframes typeBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- Input Area ---- */
.ai-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

/* Image preview above input */
.ai-image-preview {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px;
  background: #f9f9f9;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
}

.ai-image-preview img {
  max-height: 80px;
  max-width: 140px;
  border-radius: 8px;
  object-fit: contain;
}

.ai-remove-image {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: #e5e7eb;
  color: #666;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.ai-remove-image:hover { background: #d00; color: white; }

.ai-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #f5f5f5;
  border: 2px solid #e5e7eb;
  border-radius: 16px;
  padding: 8px;
  transition: border-color 0.2s;
}

.ai-input-wrapper:focus-within {
  border-color: var(--accent, #c41e3a);
}

.ai-attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.ai-attach-btn:hover { color: var(--accent, #c41e3a); background: rgba(196,30,58,0.06); }

#ai-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 120px;
  font-family: inherit;
  padding: 4px 0;
}

.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--accent, #c41e3a);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.ai-send-btn:hover { background: #a01830; transform: scale(1.05); }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ai-disclaimer {
  font-size: 0.72rem;
  color: #aaa;
  text-align: center;
  margin: 8px 0 0;
}

/* ---- Products Panel (Desktop sidebar) ---- */
.ai-products-panel {
  display: flex;
  flex-direction: column;
  background: #fafafa;
  border-left: 1px solid #e5e7eb;
  overflow: hidden;
  transition: box-shadow 0.3s;
}

.ai-products-panel.ai-panel-flash {
  box-shadow: inset 0 0 0 3px var(--accent, #c41e3a);
}

.ai-products-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: white;
  flex-shrink: 0;
}

.ai-products-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0;
  color: #1a1a1a;
}

.ai-products-count {
  font-size: 0.78rem;
  color: #999;
}

.ai-products-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.ai-products-empty {
  text-align: center;
  padding: 60px 20px;
  color: #bbb;
}

.ai-products-empty p {
  margin-top: 12px;
  font-size: 0.85rem;
}

/* ---- Product Card ---- */
.ai-product-card {
  display: flex;
  gap: 12px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ai-product-card:hover {
  border-color: var(--accent, #c41e3a);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.ai-card-new {
  animation: cardSlide 0.4s ease;
}

@keyframes cardSlide {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.ai-card-img {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.ai-card-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ai-card-body {
  flex: 1;
  min-width: 0;
}

.ai-card-partno {
  font-size: 0.7rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.ai-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  color: #1a1a1a;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-card-price {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent, #c41e3a);
}

.ai-card-reason {
  font-size: 0.73rem;
  color: #777;
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Inline Cards (Mobile) ---- */
.ai-msg-products {
  max-width: 100% !important;
  display: none;
}

.ai-inline-cards {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 0 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.ai-inline-card {
  flex-shrink: 0;
  width: 160px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  scroll-snap-align: start;
  transition: all 0.2s;
}

.ai-inline-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.ai-inline-card img {
  width: 100%;
  height: 100px;
  object-fit: contain;
  background: #f5f5f5;
  padding: 8px;
}

.ai-inline-card-info {
  padding: 8px 10px 10px;
}

.ai-inline-card-pn {
  display: block;
  font-size: 0.65rem;
  color: #999;
  text-transform: uppercase;
}

.ai-inline-card-title {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 2px 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-inline-card-price {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
}

/* ---- Mobile Responsive ---- */
@media (max-width: 900px) {
  .ai-page {
    padding-top: calc(var(--header-height, 120px) + 12px);
    padding-bottom: 24px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .ai-container {
    grid-template-columns: 1fr;
    height: 70vh;
    min-height: 400px;
    max-height: 600px;
    border-radius: 12px;
  }

  .ai-products-panel {
    display: none;
  }

  .ai-msg-products {
    display: block !important;
  }

  .ai-msg {
    max-width: 92%;
  }

  .ai-chat-header {
    padding: 14px 16px;
  }

  .ai-input-area {
    padding: 12px 16px 14px;
  }

  .ai-messages {
    padding: 16px;
  }

  .ai-disclaimer {
    font-size: 0.65rem;
  }
}

@media (max-width: 480px) {
  .ai-chat-title { font-size: 1rem; }
  .ai-chat-subtitle { font-size: 0.75rem; }
  .ai-suggestion { font-size: 0.78rem; padding: 6px 12px; }
  .ai-chat-header-icon { width: 36px; height: 36px; }
  .ai-chat-header-icon svg { width: 22px; height: 22px; }
  .ai-chat-header { gap: 10px; }
}

/* Scrollbar styling */
.ai-messages::-webkit-scrollbar,
.ai-products-grid::-webkit-scrollbar {
  width: 6px;
}

.ai-messages::-webkit-scrollbar-track,
.ai-products-grid::-webkit-scrollbar-track {
  background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb,
.ai-products-grid::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

.ai-messages::-webkit-scrollbar-thumb:hover,
.ai-products-grid::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}
