/* ─────────────────────────────────────────
   L'Oréal Routine Builder — Stylesheet
   Brand colors: #ff003b (red), #e3a535 (gold)
───────────────────────────────────────── */

/* ── Reset ── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Body & fonts ── */
body {
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: #222;
  background: #fafafa;
  display: flex;
  justify-content: center;
}

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

/* ─────────────────────────────────────────
   Header
───────────────────────────────────────── */
.site-header {
  position: relative;   /* anchor for the RTL toggle button */
  text-align: center;
  padding: 48px 0 24px;
  border-bottom: 3px solid #ff003b;
  margin-bottom: 36px;
}

.logo {
  width: 220px;
  margin-bottom: 14px;
}

.site-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #111;
}

.site-subtitle {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 300;
  color: #888;
  letter-spacing: 0.06em;
}

/* RTL toggle button — top-right corner of the header */
.rtl-toggle {
  position: absolute;
  top: 16px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #888;
  background: none;
  border: 1.5px solid #ddd;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.rtl-toggle:hover {
  color: #ff003b;
  border-color: #ff003b;
}

/* Active state — when RTL mode is ON */
.rtl-toggle.active {
  color: #fff;
  background: #ff003b;
  border-color: #ff003b;
}

/* ─────────────────────────────────────────
   Category filter + product search row
───────────────────────────────────────── */
.search-section {
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}

/* Category dropdown wrapper */
.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
}

.select-icon {
  position: absolute;
  left: 16px;
  color: #ff003b;
  font-size: 15px;
  pointer-events: none;
  z-index: 1;
}

.search-section select {
  width: 100%;
  padding: 13px 16px 13px 44px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  border: 2px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  appearance: none;
  transition: border-color 0.2s;
}

.search-section select:hover,
.search-section select:focus {
  border-color: #ff003b;
  outline: none;
}

/* Product search input wrapper */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
}

.search-input-icon {
  position: absolute;
  left: 14px;
  color: #bbb;
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
  transition: color 0.2s;
}

.search-input-wrapper input {
  width: 100%;
  padding: 13px 16px 13px 40px;
  font-family: inherit;
  font-size: 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.2s;
}

.search-input-wrapper input:hover,
.search-input-wrapper input:focus {
  border-color: #e3a535;
  outline: none;
}

.search-input-wrapper input:focus + .search-input-icon,
.search-input-wrapper:focus-within .search-input-icon {
  color: #e3a535;
}

/* ─────────────────────────────────────────
   Products grid
───────────────────────────────────────── */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  margin-bottom: 36px;
}

/* Placeholder message */
.placeholder-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: #aaa;
  font-size: 15px;
  font-weight: 300;
  letter-spacing: 0.02em;
}

/* ── Product card ── */
.product-card {
  position: relative;
  background: #fff;
  border: 2px solid #e8e8e8;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  min-height: 160px;
}

.product-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.09);
}

/* Card inner: image on left, info on right */
.card-inner {
  display: flex;
  gap: 14px;
  padding: 16px;
  flex: 1;
}

.product-card img {
  width: 95px;
  height: 95px;
  object-fit: contain;
  flex-shrink: 0;
  align-self: center;
}

.product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.product-info h3 {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  color: #111;
}

.brand-name {
  font-size: 11px;
  font-weight: 600;
  color: #e3a535;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.desc-hint {
  font-size: 11px;
  color: #ccc;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Description overlay (appears on hover) ── */
.product-desc-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.91);
  color: #f0f0f0;
  padding: 16px;
  font-size: 12px;
  line-height: 1.65;
  display: flex;
  align-items: center;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: none;
  z-index: 5;
  overflow-y: auto;
}

.product-card:hover .product-desc-overlay {
  opacity: 1;
}

/* ── Selected state ── */
.product-card.selected {
  border-color: #ff003b;
  background: #fff7f8;
}

/* Check badge: animates in when card is selected */
.selected-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  background: #ff003b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10px;
  z-index: 10;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.product-card.selected .selected-badge {
  opacity: 1;
  transform: scale(1);
}

/* ─────────────────────────────────────────
   Selected Products Panel
───────────────────────────────────────── */
.selected-products {
  background: #fff;
  border: 2px solid #e8e8e8;
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 36px;
}

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

.selected-header h2 {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
}

.selected-header h2 i {
  color: #ff003b;
}

/* Count badge */
.selected-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ff003b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 5px;
}

/* Clear All button */
.clear-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: #999;
  background: none;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s, border-color 0.2s;
}

.clear-btn:hover {
  color: #ff003b;
  border-color: #ff003b;
}

/* Empty state */
.no-selection {
  font-size: 13px;
  color: #bbb;
  font-weight: 300;
  text-align: center;
  padding: 12px 0;
}

/* Selected product chips */
#selectedProductsList {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 40px;
}

.selected-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px 5px 7px;
  background: #fffbf2;
  border: 1.5px solid #e3a535;
  border-radius: 24px;
  font-size: 12px;
  font-weight: 500;
  color: #333;
  max-width: 230px;
}

.chip-img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}

.chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-chip {
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 12px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.18s;
}

.remove-chip:hover {
  color: #ff003b;
}

/* Generate Routine button */
.generate-btn {
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #fff;
  background: #ff003b;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.22s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

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

.generate-btn:active {
  transform: scale(0.98);
}

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

/* ─────────────────────────────────────────
   Chat Area
───────────────────────────────────────── */
.chatbox {
  background: #fff;
  border: 2px solid #e8e8e8;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 48px;
}

/* Header bar */
.chatbox-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #111 0%, #2a2a2a 100%);
  color: #fff;
}

.advisor-avatar {
  width: 42px;
  height: 42px;
  background: #ff003b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.advisor-info h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.advisor-status {
  font-size: 11px;
  color: #999;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #4caf50;
  border-radius: 50%;
}

/* Chat window */
.chat-window {
  padding: 20px 20px 10px;
  height: 340px;
  overflow-y: auto;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

/* Label above AI bubble */
.msg-label {
  font-size: 10px;
  font-weight: 700;
  color: #e3a535;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-top: 10px;
  align-self: flex-start;
}

/* Chat bubbles */
.msg {
  max-width: 76%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: #ff003b;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.ai {
  align-self: flex-start;
  background: #fff;
  color: #222;
  border: 1.5px solid #eee;
  border-bottom-left-radius: 4px;
}

/* Thinking / loading state */
.msg.thinking {
  color: #bbb;
  font-style: italic;
}

/* Web search indicator shown when a response includes citations */
.web-search-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  color: #e3a535;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 4px;
}

/* Citations list below a web-search AI bubble */
.citation-list {
  align-self: flex-start;
  max-width: 76%;
  margin-top: 4px;
  margin-bottom: 6px;
  padding: 10px 14px;
  background: #fffbf2;
  border: 1px solid #f0dfa0;
  border-radius: 10px;
  font-size: 12px;
}

.citation-list p {
  font-weight: 700;
  color: #b88000;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.citation-list ol {
  padding-left: 16px;
}

.citation-list li {
  margin-bottom: 3px;
  line-height: 1.4;
}

.citation-list a {
  color: #cc8800;
  text-decoration: none;
  word-break: break-word;
}

.citation-list a:hover {
  text-decoration: underline;
}

/* Chat input row */
.chat-form {
  display: flex;
  gap: 0;
  border-top: 1.5px solid #ececec;
  background: #fff;
}

.chat-form input {
  flex: 1;
  padding: 15px 16px;
  font-family: inherit;
  font-size: 14px;
  border: none;
  background: transparent;
  color: #222;
  min-width: 0;
}

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

.chat-form input:focus {
  outline: none;
}

/* Web search toggle button */
.web-search-btn {
  font-size: 15px;
  background: none;
  border: none;
  border-left: 1.5px solid #ececec;
  color: #ccc;
  padding: 0 16px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.web-search-btn:hover {
  color: #e3a535;
}

/* Active state: web search is ON */
.web-search-btn.active {
  color: #e3a535;
  background: #fffbf2;
}

/* Send button */
.chat-form button[type="submit"] {
  font-size: 15px;
  background: #ff003b;
  color: #fff;
  border: none;
  padding: 15px 18px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-form button[type="submit"]:hover {
  background: #cc0030;
}

.chat-form button[type="submit"]:disabled,
.web-search-btn:disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
}

/* ─────────────────────────────────────────
   Footer
───────────────────────────────────────── */
.site-footer {
  margin-bottom: 48px;
  text-align: center;
  font-size: 13px;
  color: #aaa;
}

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

.site-footer a {
  margin: 0 10px;
  color: #888;
  text-decoration: none;
  transition: color 0.2s;
}

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

/* ─────────────────────────────────────────
   Accessibility
───────────────────────────────────────── */
.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;
}

/* ─────────────────────────────────────────
   RTL overrides — applied when <html dir="rtl">
   In RTL: flex-start = right edge, flex-end = left edge.
   We swap values to keep the visual layout intact
   (user bubbles right, AI bubbles left) while
   reversing all other flex rows so content flows
   right-to-left as expected.
───────────────────────────────────────── */

/* Keep the RTL toggle button on the left in RTL mode */
[dir="rtl"] .rtl-toggle {
  right: auto;
  left: 0;
}

/* Reverse the two-column search row */
[dir="rtl"] .search-section {
  flex-direction: row-reverse;
}

/* Move the category icon to the right side of the dropdown */
[dir="rtl"] .select-icon {
  left: auto;
  right: 16px;
}

[dir="rtl"] .search-section select {
  padding: 13px 44px 13px 16px;
}

/* Move the search icon to the right side of the input */
[dir="rtl"] .search-input-icon {
  left: auto;
  right: 14px;
}

[dir="rtl"] .search-input-wrapper input {
  padding: 13px 40px 13px 16px;
}

/* Flip card inner: image moves to the right, text to the left */
[dir="rtl"] .card-inner {
  flex-direction: row-reverse;
}

/* Right-align product text */
[dir="rtl"] .product-info {
  text-align: right;
}

/* desc-hint arrow aligns right */
[dir="rtl"] .desc-hint {
  flex-direction: row-reverse;
}

/* Move the selected-badge check to the left */
[dir="rtl"] .selected-badge {
  right: auto;
  left: 10px;
}

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

/* Reverse chip content */
[dir="rtl"] .selected-chip {
  flex-direction: row-reverse;
}

/* Reverse chatbox header (avatar moves to right) */
[dir="rtl"] .chatbox-header {
  flex-direction: row-reverse;
}

/* Reverse the online status row */
[dir="rtl"] .advisor-status {
  flex-direction: row-reverse;
}

/* ── RTL chat bubbles ──
   In RTL flex-start is the right edge, flex-end is the left edge.
   We swap align-self so the visual positions remain the same:
   user messages stay on the right, AI messages on the left. */
[dir="rtl"] .msg.user {
  align-self: flex-start;   /* flex-start = right edge in RTL */
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .msg.ai {
  align-self: flex-end;     /* flex-end = left edge in RTL */
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .msg-label {
  align-self: flex-end;     /* stays on the left (flex-end in RTL) */
}

[dir="rtl"] .web-search-indicator {
  align-self: flex-end;
}

[dir="rtl"] .citation-list {
  align-self: flex-end;
}

/* Reverse the chat input row */
[dir="rtl"] .chat-form {
  flex-direction: row-reverse;
}

[dir="rtl"] .web-search-btn {
  border-left: none;
  border-right: 1.5px solid #ececec;
}

/* ─────────────────────────────────────────
   Responsive
───────────────────────────────────────── */
@media (max-width: 600px) {
  .search-section {
    flex-direction: column;
  }

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

  .card-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12px;
  }

  [dir="rtl"] .card-inner {
    flex-direction: column;
  }

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

  .msg {
    max-width: 92%;
  }
}
