/* ----- palette + global tokens ----- */
:root {
  --brand-red: #ff003b;
  --brand-gold: #e3a535;
  --ink: #231f20;
  --ink-soft: #5a5354;
  --surface: #fffaf3;
  --surface-strong: #ffffff;
  --border-soft: rgba(35, 31, 32, 0.12);
  --shadow-lg: 0 20px 45px rgba(35, 31, 32, 0.12);
  --shadow-sm: 0 8px 20px rgba(35, 31, 32, 0.08);
}

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

body {
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: var(--ink);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(
      circle at 10% 10%,
      rgba(227, 165, 53, 0.22) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 90% 0%,
      rgba(255, 0, 59, 0.16) 0%,
      transparent 36%
    ),
    linear-gradient(160deg, #fffdf8 0%, var(--surface) 55%, #fff7eb 100%);
}

.page-wrapper {
  width: min(94%, 980px);
  margin: 34px auto 28px;
  background: var(--surface-strong);
  border: 1px solid rgba(227, 165, 53, 0.35);
  border-radius: 22px;
  padding: 18px clamp(14px, 2.2vw, 30px) 10px;
  box-shadow: var(--shadow-lg);
}

/* header */
.site-header {
  text-align: center;
  padding: 26px 0 8px;
  position: relative;
}

.site-header::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: min(320px, 68%);
  height: 3px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--brand-gold),
    var(--brand-red),
    transparent
  );
}

.logo {
  width: clamp(180px, 34vw, 260px);
  margin-bottom: 14px;
}

.site-title {
  font-size: clamp(1.2rem, 1rem + 0.85vw, 1.95rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 18px;
}

/* category filter */
.search-section {
  margin: 28px 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.search-section select,
.product-search {
  flex: 1 1 280px;
  padding: 16px 18px;
  font-size: 1.02rem;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.95),
      rgba(255, 255, 255, 0.88)
    ),
    linear-gradient(90deg, rgba(227, 165, 53, 0.1), rgba(255, 0, 59, 0.06));
  font-weight: 600;
  color: var(--ink);
  transition:
    border-color 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.2s ease;
}

.search-section select {
  cursor: pointer;
}

.search-section select:hover,
.product-search:hover {
  border-color: rgba(227, 165, 53, 0.6);
  transform: translateY(-1px);
}

.search-section select:focus,
.product-search:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 4px rgba(255, 0, 59, 0.14);
}

.product-search {
  cursor: text;
}

.product-search::placeholder {
  color: rgba(90, 83, 84, 0.72);
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .page-wrapper {
  direction: rtl;
}

html[dir="rtl"] .site-header::before {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

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

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

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

html[dir="rtl"] .product-card .product-info {
  align-items: flex-end;
}

html[dir="rtl"] .description-toggle {
  align-self: flex-end;
}

html[dir="rtl"] .description-modal-header {
  flex-direction: row-reverse;
  text-align: right;
}

html[dir="rtl"] .description-modal-body {
  text-align: right;
}

html[dir="rtl"] .selected-products {
  text-align: right;
}

html[dir="rtl"] #selectedProductsList {
  direction: rtl;
}

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

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

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

html[dir="rtl"] .chatbox {
  text-align: right;
}

html[dir="rtl"] .chat-window,
html[dir="rtl"] .chat-response,
html[dir="rtl"] .chat-response-text,
html[dir="rtl"] .chat-citations {
  text-align: right;
}

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

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

html[dir="rtl"] .chat-turn--assistant {
  align-self: flex-end;
}

html[dir="rtl"] .chat-citations ul {
  padding-left: 0;
  padding-right: 20px;
}

html[dir="rtl"] .site-footer {
  text-align: right;
}

html[dir="rtl"] .site-footer nav {
  direction: rtl;
}

html[dir="rtl"] .site-footer a {
  display: inline-block;
}

/* products grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 26px 0 32px;
}

.product-card {
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  gap: 14px;
  min-height: 156px;
  background: linear-gradient(
    150deg,
    rgba(255, 255, 255, 0.98),
    rgba(255, 246, 231, 0.9)
  );
  box-shadow: var(--shadow-sm);
  transition:
    transform 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 0, 59, 0.28);
  box-shadow: 0 14px 28px rgba(255, 0, 59, 0.12);
}

.product-card.is-selected {
  border-color: var(--brand-red);
  box-shadow:
    0 0 0 2px rgba(255, 0, 59, 0.22),
    0 14px 28px rgba(255, 0, 59, 0.16);
  background: linear-gradient(
    150deg,
    rgba(255, 255, 255, 0.98),
    rgba(255, 232, 238, 0.92)
  );
}

.product-card:focus-visible {
  outline: 3px solid rgba(227, 165, 53, 0.85);
  outline-offset: 2px;
}

.product-card img {
  width: 108px;
  height: 108px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
}

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

.product-card h3 {
  font-size: 1rem;
  line-height: 1.35;
  margin-bottom: 6px;
  color: var(--ink);
}

.product-card p {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.description-toggle {
  margin-top: 8px;
  align-self: flex-start;
  border: 1px solid rgba(227, 165, 53, 0.6);
  border-radius: 999px;
  background: rgba(227, 165, 53, 0.12);
  color: #5a3f11;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 5px 10px;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.description-toggle:hover {
  background: rgba(227, 165, 53, 0.2);
  border-color: rgba(227, 165, 53, 0.95);
}

.description-toggle:focus-visible {
  outline: 2px solid rgba(255, 0, 59, 0.45);
  outline-offset: 2px;
}

/* description modal */
.description-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(35, 31, 32, 0.55);
  z-index: 1000;
}

.description-modal.is-open {
  display: flex;
}

.description-modal-content {
  width: min(92vw, 620px);
  max-height: 84vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid rgba(227, 165, 53, 0.45);
  border-radius: 16px;
  box-shadow: 0 24px 40px rgba(35, 31, 32, 0.28);
  padding: 18px;
}

.description-modal-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.description-modal-header h3 {
  font-size: 1.08rem;
  color: var(--ink);
  line-height: 1.35;
}

.description-modal-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 0, 59, 0.28);
  background: rgba(255, 0, 59, 0.08);
  color: var(--brand-red);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.description-modal-close:hover {
  background: rgba(255, 0, 59, 0.16);
}

.description-modal-close:focus-visible {
  outline: 2px solid rgba(227, 165, 53, 0.85);
  outline-offset: 2px;
}

.description-modal-image {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 12px;
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.98),
    rgba(255, 245, 228, 0.95)
  );
  border: 1px solid rgba(227, 165, 53, 0.32);
  padding: 10px;
  margin-bottom: 14px;
}

.description-modal-body {
  color: #433f40;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* placeholder message */
.placeholder-message {
  width: 100%;
  text-align: center;
  padding: 42px;
  color: var(--ink-soft);
  font-size: 1.05rem;
  border: 1px dashed rgba(227, 165, 53, 0.7);
  border-radius: 14px;
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.9),
    rgba(255, 243, 220, 0.7)
  );
}

/* selected products */
.selected-products {
  margin: 36px 0 18px;
  padding: 24px;
  border: 1px solid rgba(227, 165, 53, 0.5);
  border-radius: 18px;
  background: linear-gradient(
    135deg,
    rgba(255, 253, 248, 0.96),
    rgba(255, 245, 228, 0.95)
  );
  box-shadow: var(--shadow-sm);
}

.selected-products h2,
.chatbox h2 {
  font-size: clamp(1.1rem, 1rem + 0.48vw, 1.4rem);
  margin-bottom: 16px;
  color: var(--ink);
  letter-spacing: 0.01em;
}

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

.selected-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

/* Handles selected items even if JS inserts generic span/div/button nodes */
#selectedProductsList > * {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 0, 59, 0.22);
  background: rgba(255, 0, 59, 0.08);
  color: var(--ink);
  font-size: 0.9rem;
}

.selected-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background-color 0.2s ease;
}

.selected-item:hover {
  transform: translateY(-1px);
  background: rgba(255, 0, 59, 0.14);
}

.selected-item:focus-visible {
  outline: 2px solid rgba(227, 165, 53, 0.9);
  outline-offset: 2px;
}

.remove-icon {
  font-weight: 700;
  line-height: 1;
}

.selected-empty {
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-style: italic;
}

.clear-btn {
  flex: 0 0 auto;
  padding: 14px 18px;
  border: 1px solid rgba(35, 31, 32, 0.12);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.clear-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(255, 0, 59, 0.32);
  background: rgba(255, 0, 59, 0.05);
  color: var(--brand-red);
}

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

.generate-btn {
  flex: 1 1 220px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(100deg, var(--brand-red), #dc1f4e 55%, #b50028);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    filter 0.2s ease;
}

.generate-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 10px 20px rgba(255, 0, 59, 0.22);
}

.generate-btn:focus-visible {
  outline: 3px solid rgba(227, 165, 53, 0.8);
  outline-offset: 2px;
}

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

/* chat section */
.chatbox {
  margin: 24px 0;
  border: 1px solid rgba(35, 31, 32, 0.12);
  border-radius: 18px;
  padding: 24px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.chat-window {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  font-size: 1rem;
  line-height: 1.6;
  white-space: normal;
  height: 250px;
  overflow-y: auto;
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.95),
    rgba(255, 255, 255, 0.95) 34px,
    rgba(227, 165, 53, 0.06) 34px,
    rgba(227, 165, 53, 0.06) 35px
  );
  border: 1px solid rgba(227, 165, 53, 0.32);
  border-radius: 12px;
  margin-bottom: 16px;
}

.chat-turn {
  max-width: 92%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.chat-turn--assistant {
  align-self: flex-start;
}

.chat-turn-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.chat-turn-panel {
  border: 1px solid rgba(35, 31, 32, 0.12);
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 18px rgba(35, 31, 32, 0.08);
}

.chat-turn--user .chat-turn-panel {
  background: linear-gradient(
    145deg,
    rgba(227, 165, 53, 0.16),
    rgba(255, 255, 255, 0.98)
  );
  border-color: rgba(227, 165, 53, 0.4);
}

.chat-turn--assistant .chat-turn-panel {
  border-color: rgba(255, 0, 59, 0.14);
}

.chat-turn-title {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--brand-red);
}

.chat-turn-text {
  white-space: pre-wrap;
}

.chat-citations {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(35, 31, 32, 0.12);
}

.chat-citations h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--ink);
}

.chat-citations ul {
  margin: 0;
  padding-left: 20px;
}

.chat-citations li + li {
  margin-top: 8px;
}

.chat-citations a {
  color: var(--brand-red);
  text-decoration: none;
}

.chat-citations a:hover {
  text-decoration: underline;
}

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

.chat-form input {
  flex: 1;
  padding: 12px 2px;
  font-size: 1rem;
  border: none;
  border-bottom: 2px solid rgba(35, 31, 32, 0.2);
  background: transparent;
  color: var(--ink);
}

.chat-form input::placeholder {
  color: rgba(90, 83, 84, 0.8);
}

.chat-form input:focus {
  outline: none;
  border-bottom-color: var(--brand-gold);
}

.chat-form button {
  font-size: 1rem;
  background: linear-gradient(140deg, var(--brand-gold), #c88b1f);
  color: #fff;
  border: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.chat-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(227, 165, 53, 0.36);
}

.chat-form button:focus-visible {
  outline: 3px solid rgba(255, 0, 59, 0.4);
  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: 44px 0 28px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

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

.site-footer a {
  margin: 0 7px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition:
    color 0.2s ease,
    border-color 0.2s ease;
}

.site-footer a:hover {
  color: var(--brand-red);
  border-color: rgba(255, 0, 59, 0.45);
}

/* responsive layout */
@media (max-width: 940px) {
  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .page-wrapper {
    width: 96%;
    margin-top: 18px;
    border-radius: 16px;
    padding: 12px;
  }

  .site-header {
    padding-top: 18px;
  }

  .products-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .product-card {
    min-height: 144px;
  }

  .product-card img {
    width: 92px;
    height: 92px;
  }

  .chatbox,
  .selected-products {
    padding: 16px;
  }

  .chat-window {
    height: 220px;
  }
}
