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

/* —— body + fonts —— */
body {
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: #333;
  display: flex;
  justify-content: center;
  background-color: #fafafa;
}

.page-wrapper {
  width: 90%;
  max-width: 900px;
  background-color: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* header */
.site-header {
  text-align: center;
  padding-top: 30px;
  padding-bottom: 10px;
  position: relative;
}

.rtl-toggle {
  position: absolute;
  top: 30px;
  right: 0;
  background: #ff003b;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.3s;
}

.rtl-toggle:hover {
  background: #d4002e;
}

.rtl-toggle i {
  margin-right: 5px;
}

.logo {
  width: 250px;
  margin-bottom: 15px;
}

.site-title {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 10px;
  color: #ff003b;
}

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

.search-section select,
.search-section input {
  flex: 1;
  padding: 16px;
  font-size: 18px;
  border: 2px solid #ff003b;
  border-radius: 8px;
  background-color: white;
  font-weight: 500;
  color: #333;
}

.search-section select {
  cursor: pointer;
}

.search-section select:focus,
.search-section input:focus {
  outline: none;
  border-color: #e3a535;
  box-shadow: 0 0 0 3px rgba(227, 165, 53, 0.2);
}

#productSearch::placeholder {
  color: #999;
  font-weight: 400;
}

/* products grid */
.products-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 30px 0;
}

.product-card {
  flex: 0 1 calc(33.333% - 14px);
  border: 2px solid #ddd;
  padding: 15px;
  border-radius: 12px;
  display: flex;
  gap: 15px;
  min-height: 160px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: white;
  position: relative;
}

.product-card:hover {
  border-color: #ff003b;
  box-shadow: 0 4px 15px rgba(255, 0, 59, 0.2);
  transform: translateY(-2px);
}

.product-card.selected {
  border-color: #e3a535;
  background-color: #fff9e6;
  box-shadow: 0 4px 15px rgba(227, 165, 53, 0.3);
}

.product-card.selected::after {
  content: "✓";
  position: absolute;
  top: 10px;
  right: 10px;
  background: #e3a535;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
}

.product-card img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  flex-shrink: 0;
}

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

.product-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: #333;
}

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

.description-toggle {
  background: #ff003b;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.3s;
  margin-bottom: 10px;
  align-self: flex-start;
}

.description-toggle:hover {
  background: #d4002e;
}

.product-description {
  font-size: 12px;
  color: #555;
  line-height: 1.4;
  padding: 10px;
  background: #f8f8f8;
  border-radius: 6px;
  border-left: 3px solid #ff003b;
}

/* selected products */
.selected-products {
  margin: 40px 0;
  padding: 20px;
  border: 2px solid #e3a535;
  border-radius: 12px;
  background: #fff9e6;
}

.selected-products-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.selected-products h2 {
  font-size: 20px;
  color: #ff003b;
  margin: 0;
}

#selectedProductsList {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.selected-products-empty {
  text-align: center;
  color: #666;
  font-style: italic;
  padding: 20px;
}

.selected-product-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 10px;
  background: white;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.selected-product-item img {
  width: 50px;
  height: 50px;
  object-fit: contain;
  flex-shrink: 0;
}

.selected-product-info {
  flex: 1;
}

.selected-product-info h4 {
  font-size: 14px;
  margin-bottom: 4px;
  color: #333;
}

.selected-product-info p {
  font-size: 12px;
  color: #666;
}

.remove-product-btn {
  background: #ff003b;
  color: white;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}

.remove-product-btn:hover {
  background: #d4002e;
}

.clear-all-btn {
  background: #666;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  margin-top: 10px;
  transition: background 0.3s;
}

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

.generate-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  font-size: 18px;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(135deg, #ff003b, #e3a535);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.generate-btn:hover {
  background: linear-gradient(135deg, #d4002e, #c8912b);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 0, 59, 0.3);
}

.generate-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

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

/* chat section */
.chatbox {
  margin: 40px 0;
  border: 2px solid #ff003b;
  border-radius: 12px;
  padding: 26px;
  background: white;
}

.chatbox h2 {
  font-size: 20px;
  margin-bottom: 20px;
  color: #ff003b;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Search indicator */
.search-indicator {
  font-size: 16px;
  opacity: 0.7;
  animation: pulse 2s ease-in-out infinite;
  cursor: help;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

.chat-window {
  padding: 20px;
  font-size: 16px;
  line-height: 1.6;
  height: 300px;
  overflow-y: auto;
  background: #fafafa;
  margin-bottom: 20px;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.chat-message {
  margin-bottom: 15px;
  padding: 12px;
  border-radius: 8px;
  animation: fadeIn 0.3s ease;
}

.chat-message.user {
  background: #e3f2fd;
  border-left: 4px solid #2196f3;
}

.chat-message.assistant {
  background: #fff3e0;
  border-left: 4px solid #ff9800;
}

.chat-message strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
  color: #555;
}

/* Web search results formatting */
.chat-message.assistant a {
  color: #ff003b;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: all 0.2s ease;
}

.chat-message.assistant a:hover {
  border-bottom-color: #ff003b;
  background: rgba(255, 0, 59, 0.05);
  padding: 2px 4px;
  border-radius: 3px;
}

/* Loading message styles */
.loading-message {
  opacity: 0.7;
  font-style: italic;
}

/* Search source indicator */
.chat-message.assistant em {
  color: #666;
  font-size: 0.9em;
}

/* Highlight search-enhanced responses */
.chat-message.assistant:has(a) {
  border-left-color: #e3a535;
  position: relative;
}

.chat-message.assistant:has(a)::before {
  content: "🔍";
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 12px;
  opacity: 0.6;
}

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

/* placeholder message */
.placeholder-message {
  width: 100%;
  text-align: center;
  padding: 40px;
  color: #666;
  font-size: 18px;
  background: #f8f8f8;
  border-radius: 8px;
  border: 2px dashed #ddd;
}

/* input row */
.chat-form {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.chat-form input {
  flex: 1;
  padding: 12px 16px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  transition: border-color 0.3s;
}

.chat-form input:focus {
  outline: none;
  border-color: #ff003b;
  box-shadow: 0 0 0 3px rgba(255, 0, 59, 0.1);
}

.chat-form button {
  font-size: 18px;
  background: #ff003b;
  color: #fff;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-form button:hover {
  background: #d4002e;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(255, 0, 59, 0.3);
}

.chat-form button:focus {
  outline: 2px solid #ff003b;
  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: 60px 0 40px;
  text-align: center;
  font-size: 14px;
  color: #666;
  border-top: 1px solid #eee;
  padding-top: 20px;
}

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

.site-footer a {
  margin: 0 8px;
  color: #ff003b;
  text-decoration: none;
  transition: color 0.3s;
}

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

/* Responsive design */
@media (max-width: 768px) {
  .page-wrapper {
    width: 95%;
    padding: 15px;
  }

  .product-card {
    flex: 0 1 100%;
  }

  .logo {
    width: 200px;
  }

  .site-title {
    font-size: 18px;
  }

  .search-section select {
    font-size: 16px;
    padding: 14px;
  }

  .generate-btn {
    font-size: 16px;
    padding: 14px;
  }

  .chat-window {
    height: 250px;
  }

  .rtl-toggle {
    position: static;
    margin-bottom: 15px;
  }
}

/* RTL (Right-to-Left) Language Support */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .site-header {
  text-align: center;
}

[dir="rtl"] .rtl-toggle {
  right: auto;
  left: 0;
}

[dir="rtl"] .rtl-toggle i {
  margin-right: 0;
  margin-left: 5px;
}

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

[dir="rtl"] .products-grid {
  direction: rtl;
}

[dir="rtl"] .product-card {
  text-align: right;
  flex-direction: row-reverse;
}

[dir="rtl"] .product-card.selected::after {
  right: auto;
  left: 10px;
}

[dir="rtl"] .description-toggle i {
  margin-right: 0;
  margin-left: 5px;
}

[dir="rtl"] .selected-products-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .selected-product-item {
  flex-direction: row-reverse;
  text-align: right;
}

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

[dir="rtl"] .chat-message.user {
  border-left: none;
  border-right: 4px solid #2196f3;
}

[dir="rtl"] .chat-message.assistant {
  border-left: none;
  border-right: 4px solid #ff9800;
}

[dir="rtl"] .product-description {
  border-left: none;
  border-right: 3px solid #ff003b;
}

[dir="rtl"] .generate-btn i {
  margin-right: 0;
  margin-left: 8px;
}

/* —— Product Modal Styles —— */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.8) translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #eee;
  background: linear-gradient(135deg, #ff003b, #ff4569);
  color: white;
  border-radius: 16px 16px 0 0;
}

.modal-header h3 {
  font-size: 1.4em;
  font-weight: 700;
  margin: 0;
}

.modal-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.modal-body {
  padding: 24px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.modal-product-image {
  flex: 0 0 150px;
  text-align: center;
}

.modal-product-image img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.modal-product-details {
  flex: 1;
  min-width: 250px;
}

.product-brand,
.product-category {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: #666;
  font-size: 0.9em;
}

.product-brand i,
.product-category i {
  color: #ff003b;
}

.product-description-full h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #333;
  margin-bottom: 12px;
  font-size: 1.1em;
}

.product-description-full i {
  color: #ff003b;
}

.product-description-full p {
  line-height: 1.6;
  color: #555;
  background: #f8f9fa;
  padding: 16px;
  border-radius: 8px;
  border-left: 4px solid #ff003b;
}

.modal-actions {
  margin-top: 20px;
  text-align: center;
}

.select-product-btn {
  background: linear-gradient(135deg, #ff003b, #ff4569);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 0, 59, 0.3);
}

.select-product-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 0, 59, 0.4);
}

.select-product-btn:active {
  transform: translateY(0);
}

/* Mobile responsive */
@media (max-width: 600px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .modal-body {
    flex-direction: column;
    padding: 16px;
  }

  .modal-product-image {
    flex: none;
  }

  .modal-header {
    padding: 16px 20px;
  }
}
