/* —— basic reset —— */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* —— RTL Support —— */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .main-content {
  flex-direction: row-reverse;
}

[dir="rtl"] .search-section {
  flex-direction: row-reverse;
}

[dir="rtl"] .chat-form {
  flex-direction: row-reverse;
}

[dir="rtl"] .chat-message.user-message {
  align-self: flex-start;
}

[dir="rtl"] .chat-message.ai-message {
  align-self: flex-end;
}

[dir="rtl"] .user-message .message-content {
  border-bottom-right-radius: 18px;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .ai-message .message-content {
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .user-message .message-time {
  text-align: left;
}

[dir="rtl"] .ai-message .message-time {
  text-align: right;
}

[dir="rtl"] .selected-products-list {
  padding-right: 0;
  padding-left: 20px;
}

[dir="rtl"] .product-card .more-info-btn {
  text-align: left;
}

[dir="rtl"] .fa-external-link {
  margin-right: 2px;
  margin-left: 0;
}

/* —— body + fonts —— */
body {
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: #333;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

.page-wrapper {
  width: 95%;
  overflow: visible; /* Allow tooltips to extend outside wrapper */
}

/* Main content layout for wider screens */
@media (min-width: 1024px) {
  .main-content {
    display: flex;
    gap: 30px;
  align-items: flex-start;
  overflow: hidden; /* Prevent main content from scrolling */
  }
  
  .products-section {
    flex: 1;
    min-width: 0;
    overflow: visible; /* Allow tooltips to show above and outside */
    padding-right: 10px; /* Extra padding to prevent overflow */
  }
  
  [dir="rtl"] .products-section {
    padding-right: 0;
    padding-left: 10px;
  }
  
  .chat-section {
    flex: 0 0 600px; /* Increased from 480px to make chat wider */
    display: flex;
    flex-direction: column;
    /* overflow-x: hidden; */
    max-height: 90vh;
    overflow-y: auto;
    padding: 0.5em;
  }
  
  .selected-products {
    flex-shrink: 0;
    margin-bottom: 20px;
    margin-top: 0;
  }
  
  .chatbox {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 0;
    border-radius: 8px;
  }
  
  .chat-window {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 400px;
  }
  .products-section {
    position: relative;
  }
  .site-footer {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 20px 0;
    background: #fff;
    border-top: 1px solid #eee;
    z-index: 1;
    box-sizing: border-box;
  }
}

/* header */
.site-header {
  padding-top: 50px;
  padding-bottom: 2em;
  background-color: #000;
  color: #fff;
  width: 100%;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 20px;
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.logo {
  width: 200px;
  filter: invert(1);
}

.site-title {
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  flex: 1;
  min-width: 200px;
}

/* Mobile responsive header */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 15px;
  }
  
  .logo {
    width: 150px;
  }
  
  .site-title {
    font-size: 18px;
  }
}

/* category filter and search */
.search-section {
  margin: 30px 0;
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.search-section .search-input {
  flex: 2;
  min-width: 250px;
  padding: 16px;
  font-size: 18px;
  border: 2px solid #000;
  border-radius: 8px;
  background-color: white;
  font-weight: 500;
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
}

.search-section .search-input:focus {
  outline: none;
  border-color: #e91e63;
  box-shadow: 0 0 0 3px rgba(233, 30, 99, 0.1);
}

.search-section .search-input::placeholder {
  color: #999;
  font-weight: 400;
}

.search-section select {
  flex: 1;
  min-width: 200px;
  padding: 16px;
  font-size: 18px;
  border: 2px solid #000;
  border-radius: 8px;
  cursor: pointer;
  background-color: white;
  font-weight: 500;
}

.search-section select:focus {
  outline: none;
  border-color: #666;
}

/* Responsive adjustments for search section */
@media (max-width: 768px) {
  .search-section {
    flex-direction: column;
    gap: 10px;
  }
  
  .search-section .search-input,
  .search-section select {
    flex: none;
    width: 100%;
  }
}

/* chat section */
.chatbox {
  border: 2px solid #000;
  border-radius: 8px;
  padding: 26px;
  background: #f8f9fa;
}

.chatbox h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.chat-window {
  font-size: 16px;
  line-height: 1.5;
  height: 500px;
  overflow-y: auto;
  margin-bottom: 20px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Chat message styles */
.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  margin-bottom: 8px;
  animation: slideIn 0.3s ease-out;
}

.chat-message.user-message {
  align-self: flex-end;
}

.chat-message.ai-message {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.4;
}

.user-message .message-content {
  background: #e91e63;
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-message .message-content {
  background: #f1f3f5;
  color: #333;
  border: 2px solid #000;
  border-bottom-left-radius: 4px;
}

.ai-message.error .message-content {
  background: #ffebee;
  color: #d32f2f;
  border-color: #ffcdd2;
}

.message-time {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
  padding: 0 4px;
}

.user-message .message-time {
  text-align: right;
}

.ai-message .message-time {
  text-align: left;
}

/* Chat message links */
.chat-message a {
  color: #e91e63;
  text-decoration: none;
  border-bottom: 1px dotted #e91e63;
  transition: all 0.2s ease;
  font-weight: 500;
}

.chat-message a:hover {
  color: #ad1457;
  border-bottom-color: #ad1457;
  background-color: rgba(233, 30, 99, 0.1);
  padding: 1px 3px;
  border-radius: 3px;
}

.chat-message a i {
  font-size: 0.8em;
  margin-left: 2px;
  opacity: 0.7;
}

[dir="rtl"] .chat-message a i {
  margin-left: 0;
  margin-right: 2px;
}

.user-message a {
  color: rgba(255, 255, 255, 0.9);
  border-bottom-color: rgba(255, 255, 255, 0.7);
}

.user-message a:hover {
  color: white;
  border-bottom-color: white;
  background-color: rgba(255, 255, 255, 0.2);
}

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

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #999;
  animation: bounce 1.4s infinite ease-in-out both;
}

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

/* Chat prompt */
.chat-prompt {
  text-align: center;
  padding: 12px;
  color: #999;
  font-size: 14px;
  font-style: italic;
  border-top: 1px solid #eee;
  margin-top: 10px;
}

/* Markdown formatting in chat */
.message-content strong {
  font-weight: 600;
}

.message-content em {
  font-style: italic;
}

.message-content .inline-code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.user-message .message-content .inline-code {
  background: rgba(255, 255, 255, 0.2);
}

.message-content .code-block {
  display: block;
  background: rgba(0, 0, 0, 0.05);
  padding: 8px;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  margin: 8px 0;
  white-space: pre-wrap;
  overflow-x: auto;
}

.user-message .message-content .code-block {
  background: rgba(255, 255, 255, 0.1);
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* placeholder message */
.placeholder-message {
  width: 100%;
  text-align: center;
  padding: 40px;
  color: #666;
  font-size: 18px;
}

/* product notification area */
.product-notification {
  text-align: center;
  margin-bottom: 15px;
  min-height: 0; /* No reserved space */
}

/* search results info and featured products */
.search-results-info, .featured-products-info {
  width: auto;
  max-width: 400px;
  margin: 0;
  text-align: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  display: inline-block;
  line-height: 1.3;
  white-space: normal;
}

.search-results-info {
  background-color: #e8f5e8;
  border: 1px solid #4caf50;
  color: #2e7d32;
}

.search-results-info i {
  margin-right: 2px;
  color: #4caf50;
  font-size: 9px;
}

[dir="rtl"] .search-results-info i {
  margin-right: 0;
  margin-left: 2px;
}

.featured-products-info {
  background-color: #fff3e0;
  border: 2px solid #ff9800;
  color: #e65100;
}

.featured-products-info i {
  margin-right: 6px;
  color: #ff9800;
  font-size: 14px;
}

[dir="rtl"] .featured-products-info i {
  margin-right: 0;
  margin-left: 6px;
}

/* input row */
.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  align-items: flex-end;
}

.chat-form input {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  background: white;
  outline: none;
  transition: border-color 0.2s;
}

.chat-form input:focus {
  border-color: #e91e63;
  box-shadow: 0 0 0 2px rgba(233, 30, 99, 0.1);
}

.chat-form button {
  font-size: 16px;
  background: #e91e63;
  color: #fff;
  border: none;
  padding: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.chat-form button:hover {
  background: #c2185b;
  transform: scale(1.05);
}

.chat-form button:active {
  transform: scale(0.95);
}

.chat-form button:focus {
  outline: 2px solid #e91e63;
  outline-offset: 2px;
}

/* visually hidden */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* footer */
.site-footer {
  margin: 80px 0 20px; /* Increased top margin, reduced bottom margin */
  text-align: center;
  font-size: 14px;
  color: #666;
}

.site-footer nav {
  margin-top: 12px;
}

.site-footer a {
  margin: 0 8px;
  color: #000;
  text-decoration: none;
}

.site-footer a:hover {
  color: #666666;
}

/* products grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 15px;
  margin: 1em 0; /* Removed horizontal margin to prevent overflow */
  padding: 0 5px; /* Small padding instead */
  overflow: visible; /* Allow tooltips to extend outside grid */
}

.product-card {
  border: 1px solid #ccc;
  padding: 12px;
  border-radius: 4px;
  display: flex;
  gap: 12px;
  min-height: 140px;
  cursor: pointer;
  transition: border-color 0.3s, box-shadow 0.3s;
  position: relative;
  z-index: 10; /* Add z-index to product cards */
}

.product-card:hover {
  border-color: #666;
}

.product-card.selected {
  border: 2px solid #000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Product info tooltip */
.product-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 2px solid #000;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 99999; /* Extremely high z-index */
  width: 280px;
  margin-bottom: 8px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.product-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

.product-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #000;
}

.product-tooltip h4 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 8px;
  color: #000;
}

.product-tooltip .tooltip-brand {
  font-size: 14px;
  color: #666;
  margin-bottom: 10px;
}

.product-tooltip .tooltip-description {
  font-size: 14px;
  line-height: 1.4;
  color: #333;
}

/* RTL support for tooltips */
[dir="rtl"] .product-tooltip {
  text-align: right;
}

[dir="rtl"] .product-tooltip h4,
[dir="rtl"] .product-tooltip .tooltip-brand,
[dir="rtl"] .product-tooltip .tooltip-description {
  text-align: right;
}

.product-card img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  flex-shrink: 0;
  background: #fafafa;
  border-radius: 4px;
}

.product-card .image-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.product-card .brand-name {
  font-size: 11px;
  color: #666;
  font-weight: 500;
  margin-top: 6px;
  text-align: center;
  line-height: 1.2;
}

.product-card .product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 80px;
}

.product-card h3 {
  font-size: 14px;
  margin-bottom: 10px;
  font-weight: 600;
  line-height: 1.3;
}

.product-card p {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  font-weight: 500;
}

.more-info-btn {
  background: #000;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.3s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  align-self: flex-start;
}

.more-info-btn:hover {
  background: #666;
}

.more-info-btn i {
  margin-right: 4px;
}

/* selected products */
.selected-products {
  margin: 40px 0;
  padding: 20px;
  border: 2px solid #000;
  border-radius: 8px;
}

.selected-products h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

#selectedProductsList {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.selected-product-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f5f5f5;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 14px;
}

.selected-product-item .product-name {
  font-weight: 500;
}

.delete-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 2px;
  font-size: 14px;
  transition: color 0.3s;
}

.delete-btn:hover {
  color: #000;
}

.clear-all-btn {
  background: #dc3545;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.3s;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
}

.clear-all-btn:hover {
  background: #c82333;
}

.clear-all-btn i {
  font-size: 11px;
}

.generate-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  font-size: 18px;
  font-weight: 500;
  color: #fff;
  background: #000;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s;
}

.generate-btn:hover {
  background: #666;
}

.generate-btn i {
  margin-right: 8px;
}
