/* Keep spacing and sizing predictable across the page. */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: light;
  --ink: #211d1a;
  --muted: #716961;
  --gold: #a77b3f;
  --gold-light: #d7bc91;
  --cream: #fbf8f3;
  --blush: #f3e9e2;
  --line: #e8dfd4;
  --white: #fff;
  --shadow: 0 18px 48px rgb(52 39 27 / 8%);
}

body {
  min-height: 100vh;
  padding: 0 24px;
  background:
    radial-gradient(ellipse at 50% 0, rgb(231 212 184 / 25%), transparent 42rem),
    var(--cream);
  color: var(--ink);
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  display: flex;
  justify-content: center;
}

.page-wrapper {
  width: 100%;
  max-width: 960px;
}

/* A quiet, centered brand moment above the product and chat tools. */
.site-header {
  position: relative;
  text-align: center;
  padding: 52px 0 24px;
}

.language-control {
  position: absolute;
  top: 16px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-control label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.language-control select {
  min-height: 38px;
  padding: 7px 32px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.language-control select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

[dir="rtl"] .selected-products-header,
[dir="rtl"] .chat-form {
  direction: rtl;
}

.logo {
  display: block;
  width: min(230px, 65vw);
  height: auto;
  margin: 0 auto 20px;
}

.site-title,
.chatbox h2,
.selected-products h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: 0.015em;
}

.site-title {
  font-size: clamp(1.7rem, 3.5vw, 2.25rem);
  line-height: 1.2;
}

.site-subtitle {
  margin-top: 10px;
  color: var(--muted);
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  font-size: 0.76rem;
  font-weight: 300;
  letter-spacing: 0.16em;
  line-height: 1.6;
  text-transform: uppercase;
}

/* Category filter */
.search-section {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 24px 0 30px;
}

.search-section select {
  width: 100%;
  min-height: 56px;
  padding: 14px 48px 14px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  appearance: none;
  background-color: var(--white);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23a77b3f' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 24px center;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 5px 18px rgb(52 39 27 / 4%);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

[dir="rtl"] .search-section select {
  padding-right: 18px;
  padding-left: 48px;
  background-position: left 24px center;
}

.product-search-control {
  position: relative;
  z-index: 1;
  width: 56px;
  height: 56px;
  transition: width 180ms ease;
}

.product-search-control:focus-within {
  width: min(280px, 45vw);
}

.product-search-control input {
  position: absolute;
  top: 0;
  inset-inline-end: 0;
  width: 100%;
  min-height: 56px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--white);
  color: transparent;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 5px 18px rgb(52 39 27 / 4%);
  transition: width 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.product-search-control input::placeholder {
  color: transparent;
}

.product-search-control input:focus {
  z-index: 2;
  color: var(--ink);
  cursor: text;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgb(167 123 63 / 14%);
}

.product-search-control input:focus::placeholder {
  color: #817a72;
}

.product-search-control input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.product-search-icon {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--gold);
  pointer-events: none;
}

.product-search-control:focus-within .product-search-icon {
  visibility: hidden;
}

.search-section select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-color: var(--gold);
}

/* Product cards */
.products-grid {
  display: grid;
  align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr));
  gap: 18px;
  margin: 28px 0;
}

.product-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  min-height: 185px;
  padding: 16px 16px 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  box-shadow: 0 6px 22px rgb(52 39 27 / 4%);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold-light);
  box-shadow: 0 12px 28px rgb(52 39 27 / 8%);
}

.product-card.is-selected {
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--white), #fbf3e7);
  box-shadow: 0 0 0 2px rgb(167 123 63 / 15%);
}

.product-card-select {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 110px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.product-card-select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 8px;
}

.product-card img {
  width: 100px;
  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-name {
  margin-bottom: 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.35;
}

.product-brand {
  color: var(--muted);
  font-size: 0.85rem;
}

.product-description-toggle {
  position: absolute;
  inset-inline-end: 14px;
  bottom: 10px;
  min-height: 28px;
  padding: 3px 4px;
  border: 0;
  background: transparent;
  color: #89704f;
  font: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  transition: color 180ms ease;
}

.product-description-toggle:hover {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.product-description-toggle:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.product-description-panel {
  padding: 10px 2px 2px;
  animation: message-enter 180ms ease both;
}

.product-description-panel[hidden] {
  display: none;
}

.product-description {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.65;
}

.placeholder-message {
  grid-column: 1 / -1;
  width: 100%;
  padding: 32px 20px;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

/* Selected products */
.selected-products {
  margin: 34px 0;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, var(--white), #fcf8f1);
  box-shadow: var(--shadow);
}

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

.selected-products h2,
.chatbox h2 {
  margin-bottom: 18px;
  font-size: clamp(1.35rem, 2.5vw, 1.7rem);
}

.selected-products-header h2 {
  margin-bottom: 0;
}

.clear-selected-btn {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.clear-selected-btn:hover:not(:disabled) {
  border-color: var(--gold-light);
  background: #fbf3e7;
  color: var(--ink);
}

.clear-selected-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

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

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

.selection-storage-status {
  margin-top: 8px;
  color: #7a3025;
  font-size: 0.82rem;
}

.selected-product {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--gold-light);
  border-radius: 999px;
  background: #fbf3e7;
  color: #493a29;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}

.selected-product::after {
  content: "×";
  margin-inline-start: 8px;
  color: var(--gold);
  font-size: 1.1rem;
  line-height: 1;
}

.selected-product:hover {
  border-color: var(--gold);
  background: #f5e8d5;
}

.selected-product:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.generate-btn {
  width: 100%;
  min-height: 54px;
  margin-top: 22px;
  padding: 14px 20px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(110deg, #211d1a, #3c332a);
  color: var(--white);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 7px 18px rgb(33 29 26 / 14%);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.generate-btn:hover {
  transform: translateY(-2px);
  border-color: var(--gold-light);
  box-shadow: 0 10px 24px rgb(167 123 63 / 24%);
}

.generate-btn:focus-visible,
.chat-form button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.generate-btn i {
  margin-inline-end: 8px;
  color: var(--gold-light);
}

/* Chat area */
.chatbox {
  margin: 38px 0;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.chatbox h2 {
  text-align: center;
}

.chat-window {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: clamp(260px, 42vh, 390px);
  margin-bottom: 20px;
  padding: clamp(14px, 3vw, 24px);
  overflow-y: auto;
  border: 1px solid #eee8df;
  border-radius: 14px;
  background: linear-gradient(145deg, #fdfbf8, #faf6f0);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.7;
  text-align: start;
  scrollbar-color: var(--gold-light) transparent;
  scrollbar-width: thin;
}

.chat-window > * {
  animation: message-enter 300ms ease both;
}

/* These message styles are ready for user and assistant chat elements. */
.chat-window .message,
.chat-window .bot-message,
.chat-window .assistant-message,
.chat-window .user-message {
  max-width: min(82%, 620px);
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 3px 12px rgb(52 39 27 / 7%);
  overflow-wrap: anywhere;
}

.chat-window .message,
.chat-window .bot-message,
.chat-window .assistant-message {
  align-self: flex-start;
  border: 1px solid #eadcc7;
  border-end-start-radius: 5px;
  background: #f7efe3;
  color: #382d21;
}

.chat-window .bot-message p,
.chat-window .bot-message h1,
.chat-window .bot-message h2,
.chat-window .bot-message h3,
.chat-window .bot-message h4,
.chat-window .bot-message h5,
.chat-window .bot-message h6,
.chat-window .bot-message ul,
.chat-window .bot-message ol {
  margin: 0;
}

.chat-window .bot-message > * + * {
  margin-top: 0.85em;
}

.chat-window .bot-message h1,
.chat-window .bot-message h2,
.chat-window .bot-message h3,
.chat-window .bot-message h4,
.chat-window .bot-message h5,
.chat-window .bot-message h6 {
  font-size: 1rem;
  line-height: 1.4;
}

.chat-window .bot-message ul,
.chat-window .bot-message ol {
  padding-inline-start: 1.35em;
}

.chat-window .bot-message li + li {
  margin-top: 0.45em;
}

.chat-window .user-message {
  align-self: flex-end;
  border: 1px solid #ded8d0;
  border-end-end-radius: 5px;
  background: #292521;
  color: var(--white);
}

.chat-window .error-message {
  align-self: center;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid #e8c9c1;
  border-radius: 10px;
  background: #fff5f2;
  color: #7a3025;
  font-size: 0.88rem;
  text-align: center;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  padding: 13px 16px;
  border: 1px solid #eadcc7;
  border-radius: 16px;
  border-end-start-radius: 5px;
  background: #f7efe3;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: typing-pulse 1s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 150ms;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 300ms;
}

.chat-form {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fdfcfb;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.chat-form input::placeholder {
  color: #817a72;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgb(167 123 63 / 14%);
}

.chat-form button {
  display: flex;
  flex: 0 0 52px;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 5px 14px rgb(33 29 26 / 12%);
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.chat-form button:hover {
  transform: translateY(-2px);
  background: #40372d;
  box-shadow: 0 8px 18px rgb(167 123 63 / 24%);
}

.chat-form button:disabled,
.generate-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* Visually hidden but still available to screen readers. */
.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: 52px 0 30px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

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

.site-footer a {
  display: inline-block;
  margin: 4px 8px;
  color: var(--ink);
  text-decoration-color: var(--gold-light);
  text-underline-offset: 3px;
  transition: color 180ms ease;
}

.site-footer a:hover {
  color: var(--gold);
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing-pulse {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 600px) {
  body {
    padding: 0 16px;
  }

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

  .language-control {
    top: 14px;
  }

  .logo {
    width: min(190px, 62vw);
  }

  .site-subtitle {
    font-size: 0.67rem;
    letter-spacing: 0.12em;
  }

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

  .search-section {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .product-search-control:focus-within {
    width: min(240px, 62vw);
  }

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

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

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

  .chat-window .message,
  .chat-window .bot-message,
  .chat-window .assistant-message,
  .chat-window .user-message {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
