:root {
  --ink: #171717;
  --muted: #696762;
  --line: #d8d5ce;
  --gold: #c9a46a;
  --cream: #f7f5f1;
  --white: #fff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: "DM Sans", sans-serif;
}

.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--white);
  border-bottom: 1px solid #ece9e3;
}

.language-control {
  grid-column: 3;
  justify-self: end;
  margin-inline-end: 24px;
}

.language-control select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--ink);
  padding: 7px 30px 7px 12px;
  font: 600 12px "DM Sans", sans-serif;
  cursor: pointer;
}

.language-control select:hover,
.language-control select:focus-visible {
  border-color: var(--ink);
}

.brand {
  grid-column: 2;
  color: var(--ink);
  text-decoration: none;
  font-family: "Italiana", serif;
  font-size: 38px;
  letter-spacing: 1px;
}

.brand span {
  display: block;
  margin-top: -5px;
  text-align: center;
  font-family: "DM Sans", sans-serif;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 5px;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 54px 40px 80px;
}

.hero {
  max-width: 700px;
  margin-bottom: 42px;
}

.eyebrow,
.step {
  margin: 0 0 10px;
  color: #9d7b48;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2.2px;
}

.hero h1 {
  margin: 0;
  font-family: "Italiana", serif;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 400;
  line-height: 1;
}

.intro {
  max-width: 560px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

.builder {
  background: var(--white);
  border: 1px solid #ebe8e1;
  padding: 34px;
  box-shadow: 0 12px 40px rgba(39, 34, 24, 0.04);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 22px;
}

.section-heading h2 {
  margin: 0;
  font-family: "Italiana", serif;
  font-size: 34px;
  font-weight: 400;
}

.selection-count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.clear-selection {
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--muted);
  padding: 2px 0;
  font: 600 12px "DM Sans", sans-serif;
  cursor: pointer;
}

.clear-selection:hover {
  color: var(--ink);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.product-filters {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.search-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.search-field input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 0 12px;
  font: 400 14px "DM Sans", sans-serif;
  text-transform: none;
}

.search-field input:focus {
  border-color: var(--ink);
  outline: 2px solid rgba(201, 164, 106, 0.25);
}

.category-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.category-filter {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  padding: 7px 12px;
  font: 600 12px "DM Sans", sans-serif;
  cursor: pointer;
}

.category-filter:hover,
.category-filter:focus-visible {
  border-color: var(--ink);
  color: var(--ink);
}

.category-filter.active {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.no-results {
  margin: 28px 0 8px;
  color: var(--muted);
  text-align: center;
}

.product-item {
  position: relative;
  min-width: 0;
  min-height: 154px;
  perspective: 1000px;
}

.product-flipper {
  position: relative;
  min-height: 154px;
  transition: transform 420ms ease;
  transform-style: preserve-3d;
}

.product-item.flipped .product-flipper {
  transform: rotateY(180deg);
}

.product-front,
.product-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.product-back {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--ink);
  background: #fbfaf7;
  padding: 20px 58px 20px 20px;
  transform: rotateY(180deg);
  overflow: hidden;
}

.product-back h3 {
  margin: 0 0 8px;
  color: #080808;
  font-family: "Italiana", serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.15;
}

.product-back p {
  margin: 0;
  color: #373632;
  font-size: 12px;
  line-height: 1.55;
}

.details-toggle {
  position: absolute;
  inset-inline-end: 12px;
  bottom: 10px;
  z-index: 2;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--muted);
  padding: 3px 0 1px;
  font: 600 11px "DM Sans", sans-serif;
  cursor: pointer;
}

.product-front .details-toggle {
  position: absolute;
}

.back-toggle {
  width: max-content;
  margin-top: auto;
  align-self: flex-end;
  position: absolute;
  inset-inline-end: 12px;
  bottom: 10px;
}

.details-toggle:hover,
.details-toggle:focus-visible {
  color: var(--ink);
}

.product-card {
  position: relative;
  width: 100%;
  height: 154px;
  min-height: 154px;
  display: grid;
  grid-template-columns: 112px 1fr;
  align-items: center;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

.product-card:hover {
  border-color: #aaa49a;
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(39, 34, 24, 0.08);
}

.product-card:focus-visible {
  outline: 3px solid rgba(201, 164, 106, 0.35);
  outline-offset: 3px;
}

.product-card.selected {
  border: 2px solid var(--ink);
  padding: 13px;
  background: #fbfaf7;
  box-shadow: 0 8px 24px rgba(39, 34, 24, 0.08);
}

.product-card.selected::after {
  content: "✓";
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.product-image {
  width: 112px;
  height: 126px;
  object-fit: contain;
  background: #f2efe8;
}

.product-meta {
  min-width: 0;
  padding-inline-end: 4px;
}

.product-category {
  display: block;
  margin-bottom: 8px;
  color: #684b20;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.product-name {
  display: block;
  color: #080808;
  font-family: "Italiana", serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.routine-action {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: end;
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid #e7e4dd;
}

.summary-label {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.selected-list {
  min-height: 36px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.empty-selection {
  margin: 0;
  color: #aaa69e;
  font-size: 13px;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding-block: 6px;
  padding-inline: 12px 9px;
  border: 1px solid #d3cfc5;
  border-radius: 999px;
  background: #faf9f6;
  font-size: 12px;
}

.chip-remove {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 18px;
}

.chip-remove:hover {
  background: #e9e6df;
  color: var(--ink);
}

.generate-button {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  padding: 0 20px 0 22px;
  background: var(--ink);
  color: white;
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, opacity 160ms ease;
}

.generate-button:not(:disabled):hover {
  background: #393939;
}

.generate-button:disabled {
  background: #d5d2cb;
  color: #89877f;
  cursor: not-allowed;
}

.product-dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid #ddd8cd;
  padding: 0;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(39, 34, 24, 0.22);
}

.product-dialog::backdrop {
  background: rgba(23, 23, 23, 0.48);
}

.dialog-content {
  position: relative;
  padding: 34px 38px 38px;
}

.dialog-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid #ddd8cd;
  border-radius: 50%;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
}

.dialog-category {
  margin: 0 0 10px;
  color: #9d7b48;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}

.dialog-content h2 {
  margin-block: 0 16px;
  margin-inline: 0 42px;
  font-family: "Italiana", serif;
  font-size: 34px;
  font-weight: 400;
  line-height: 1.15;
}

.dialog-content p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.chat {
  margin-top: 28px;
  border: 1px solid #e3dfd5;
  background: #fbfaf7;
}

.chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
  border-bottom: 1px solid #e3dfd5;
}

.chat-heading h2 {
  margin: 0;
  font-family: "Italiana", serif;
  font-size: 28px;
  font-weight: 400;
}

.close-chat {
  width: 34px;
  height: 34px;
  border: 1px solid #ddd8cd;
  border-radius: 50%;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
}

.chat-messages {
  max-height: 420px;
  overflow-y: auto;
  padding: 22px;
}

.chat-message {
  max-width: 820px;
  margin: 0;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.chat-turn {
  margin-bottom: 14px;
}

.chat-turn:last-child {
  margin-bottom: 0;
}

.chat-sender {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.chat-turn.user .chat-sender {
  color: #9d7b48;
}

.chat-message.loading {
  color: var(--muted);
}

.chat-message.error {
  color: #9b2c2c;
}

.chat-citations {
  max-width: 820px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e3dfd5;
  color: var(--muted);
  font-size: 13px;
}

.chat-citations-heading {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.chat-citations ol {
  margin: 0;
  padding-inline-start: 20px;
}

.chat-citations li {
  margin: 4px 0;
}

.chat-citations a {
  color: #6f5530;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px 22px 22px;
  border-top: 1px solid #e3dfd5;
}

.chat-form input {
  min-width: 0;
  height: 44px;
  border: 1px solid #d4cfc3;
  background: white;
  padding: 0 14px;
  color: var(--ink);
  font: 14px "DM Sans", sans-serif;
}

.chat-form input:focus {
  border-color: var(--ink);
  outline: 2px solid rgba(201, 164, 106, 0.25);
}

.chat-form button {
  height: 44px;
  border: 0;
  background: var(--ink);
  color: white;
  padding: 0 18px;
  font: 700 13px "DM Sans", sans-serif;
  cursor: pointer;
}

.chat-form button:disabled {
  background: #d5d2cb;
  cursor: wait;
}

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

[dir="rtl"] .generate-button span {
  transform: scaleX(-1);
}


.floating-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.floating-chat-toggle {
  height: 54px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  box-shadow: 0 10px 30px rgba(23, 23, 23, 0.22);
  padding: 0 18px;
  font: 700 14px "DM Sans", sans-serif;
  cursor: pointer;
}

.floating-chat-toggle[aria-expanded="true"] {
  background: #393939;
}

.floating-chat-panel {
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 110px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  border: 1px solid #ddd8cd;
  background: white;
  box-shadow: 0 18px 55px rgba(39, 34, 24, 0.18);
  overflow: hidden;
}

.floating-chat-panel[hidden] {
  display: none;
}

.floating-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #e7e4dd;
}

.floating-chat-header p {
  margin: 0 0 3px;
  color: #9d7b48;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.floating-chat-header h2 {
  margin: 0;
  font-family: "Italiana", serif;
  font-size: 20px;
  font-weight: 400;
}

.floating-chat-close {
  width: 32px;
  height: 32px;
  border: 1px solid #ddd8cd;
  border-radius: 50%;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
}

.floating-chat-messages {
  overflow-y: auto;
  padding: 16px;
  background: #fbfaf7;
}

.floating-chat-message {
  max-width: 88%;
  margin: 0 0 10px;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.floating-chat-turn {
  margin-bottom: 12px;
}

.floating-chat-sender {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.floating-chat-turn.user {
  text-align: end;
}

.floating-chat-message.assistant {
  border-bottom-left-radius: 4px;
  background: #eeeae2;
  color: var(--ink);
}

.floating-chat-message.user {
  margin-inline-start: auto;
  border-bottom-right-radius: 4px;
  background: var(--ink);
  color: white;
}

.floating-chat-message.loading,
.floating-chat-message.error {
  color: var(--muted);
  font-style: italic;
}

.floating-chat-form {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e7e4dd;
}

.floating-chat-form input {
  min-width: 0;
  height: 42px;
  border: 1px solid #d4cfc3;
  padding: 0 12px;
  color: var(--ink);
  font: 14px "DM Sans", sans-serif;
}

.floating-chat-form input:focus {
  border-color: var(--ink);
  outline: 2px solid rgba(201, 164, 106, 0.25);
}

.floating-chat-form button {
  height: 42px;
  border: 0;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font-size: 16px;
}

[dir="rtl"] .floating-chat-message.assistant {
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}

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

@media (max-width: 900px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .product-filters {
    grid-template-columns: 1fr;
  }

  .category-filters {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  main {
    padding: 38px 16px 50px;
  }

  .floating-chat {
    right: 16px;
    bottom: 16px;
  }

  .floating-chat-panel {
    width: calc(100vw - 32px);
    height: min(520px, calc(100vh - 100px));
  }

  .topbar {
    height: 64px;
  }

  .hero {
    margin-bottom: 28px;
  }

  .hero h1 {
    font-size: 46px;
  }

  .builder {
    padding: 20px 16px;
  }

  .section-heading {
    align-items: start;
  }

  .section-heading h2 {
    font-size: 28px;
  }

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

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

  .product-item,
  .product-flipper {
    min-height: 140px;
  }

  .routine-action {
    grid-template-columns: 1fr;
  }

  .generate-button {
    width: 100%;
  }

  .chat-messages {
    max-height: 520px;
  }
}
