/* ─────────────────────────────────────────────────────────────────────────
 * Wara Commerce Agent — Chat widget styles.
 *
 * Editorial-oxblood palette (oxblood #6E1F1F, saffron #C8973D, bone #F7F2EA,
 * ink #1C1C1C). Self-contained: no external CSS deps. Fonts (Cairo / IBM Plex
 * Sans Arabic / IBM Plex Sans) are assumed loaded by the site; sane fallbacks
 * are provided here. RTL-correct and mobile-responsive.
 *
 * All selectors are namespaced under .wara-chat and tokens under --wac-* so
 * nothing leaks into / from the host page.
 * ───────────────────────────────────────────────────────────────────────── */

.wara-chat {
  /* Local tokens — mirror the Wara editorial-oxblood palette. */
  --wac-ox:        #6E1F1F;
  --wac-ox-deep:   #5A1818;
  --wac-ox-soft:   #F1DCDA;
  --wac-gold:      #C8973D;
  --wac-gold-deep: #9A6F23;
  --wac-gold-soft: #F1E0B5;
  --wac-bone:      #F7F2EA;
  --wac-bone-deep: #EFE7D8;
  --wac-surface:   #FFFFFF;
  --wac-line:      #E6DECC;
  --wac-ink:       #1C1C1C;
  --wac-ink-2:     #57534A;
  --wac-ink-3:     #7A746A;

  --wac-r-md:   12px;
  --wac-r-lg:   20px;
  --wac-r-pill: 999px;

  --wac-shadow-pop: 0 10px 28px rgba(15, 14, 12, 0.18), 0 4px 10px rgba(15, 14, 12, 0.10);
  --wac-shadow-card: 0 4px 12px rgba(15, 14, 12, 0.10), 0 2px 4px rgba(15, 14, 12, 0.06);

  --wac-font: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;

  position: fixed;
  bottom: 20px;
  z-index: 2147483000;            /* above most site chrome */
  font-family: var(--wac-font);
  line-height: 1.5;
  color: var(--wac-ink);
  -webkit-font-smoothing: antialiased;
}

/* Corner placement is direction-aware: LTR -> right, RTL -> left. */
.wara-chat[dir="ltr"] { right: 20px; left: auto; }
.wara-chat[dir="rtl"] {
  left: 20px;
  right: auto;
  --wac-font: 'IBM Plex Sans Arabic', 'Cairo', system-ui, sans-serif;
}

.wara-chat *,
.wara-chat *::before,
.wara-chat *::after { box-sizing: border-box; }

/* ── Launcher ──────────────────────────────────────────────────────────── */
.wara-chat__launcher {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 60px;
  height: 60px;
  border-radius: var(--wac-r-pill);
  background: var(--wac-ox);
  color: var(--wac-bone);
  box-shadow: var(--wac-shadow-pop);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms cubic-bezier(.34, 1.56, .64, 1),
              background-color 150ms ease;
  border: 2px solid var(--wac-gold);
}
.wara-chat__launcher:hover { background: var(--wac-ox-deep); transform: translateY(-2px); }
.wara-chat__launcher:focus-visible {
  outline: 3px solid var(--wac-gold);
  outline-offset: 2px;
}
.wara-chat__launcher svg { width: 28px; height: 28px; fill: currentColor; }

/* Hide the launcher while the panel is open (panel has its own close). */
.wara-chat--open .wara-chat__launcher { transform: scale(0); pointer-events: none; }

/* ── Panel ─────────────────────────────────────────────────────────────── */
.wara-chat__panel {
  position: absolute;
  bottom: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 40px);
  background: var(--wac-bone);
  border: 1px solid var(--wac-line);
  border-radius: var(--wac-r-lg);
  box-shadow: var(--wac-shadow-pop);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms cubic-bezier(.16, 1, .3, 1);
}
.wara-chat[dir="rtl"] .wara-chat__panel { transform-origin: bottom left; }
.wara-chat[dir="ltr"] .wara-chat__panel { right: 0; }
.wara-chat[dir="rtl"] .wara-chat__panel { left: 0; }

.wara-chat--open .wara-chat__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.wara-chat__header {
  background: var(--wac-ox);
  color: var(--wac-bone);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 3px solid var(--wac-gold);
  flex: 0 0 auto;
}
.wara-chat__header-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wara-chat__title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
}
.wara-chat[dir="rtl"] .wara-chat__title { font-family: 'Cairo', 'IBM Plex Sans Arabic', system-ui, sans-serif; }
.wara-chat__subtitle { font-size: 12px; color: var(--wac-gold-soft); }

.wara-chat__close {
  appearance: none;
  border: none;
  background: rgba(247, 242, 234, .12);
  color: var(--wac-bone);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--wac-r-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background-color 150ms ease;
}
.wara-chat__close:hover { background: rgba(247, 242, 234, .24); }
.wara-chat__close:focus-visible { outline: 2px solid var(--wac-gold); outline-offset: 2px; }
.wara-chat__close svg { width: 18px; height: 18px; }

/* ── Log ───────────────────────────────────────────────────────────────── */
.wara-chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.wara-chat__log:focus-visible { outline: none; }

.wara-chat__row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}
/* user -> own side (end), assistant -> opposite (start). dir handles RTL. */
.wara-chat__row--user { align-self: flex-end; align-items: flex-end; }
.wara-chat__row--assistant { align-self: flex-start; align-items: flex-start; }

.wara-chat__bubble {
  padding: 9px 13px;
  border-radius: var(--wac-r-md);
  font-size: 14.5px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--wac-shadow-card);
}
.wara-chat__bubble--assistant {
  background: var(--wac-surface);
  color: var(--wac-ink);
  border: 1px solid var(--wac-line);
  border-start-start-radius: 4px;
}
.wara-chat__bubble--user {
  background: var(--wac-ox);
  color: var(--wac-bone);
  border-end-end-radius: 4px;
}

/* ── Cart link button ──────────────────────────────────────────────────── */
.wara-chat__cart {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  background: var(--wac-gold);
  color: var(--wac-ink);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  border-radius: var(--wac-r-pill);
  box-shadow: var(--wac-shadow-card);
  transition: background-color 150ms ease, transform 150ms ease;
}
.wara-chat__cart:hover { background: var(--wac-gold-deep); color: var(--wac-bone); transform: translateY(-1px); }
.wara-chat__cart:focus-visible { outline: 2px solid var(--wac-ox); outline-offset: 2px; }

/* ── Handoff note ──────────────────────────────────────────────────────── */
.wara-chat__handoff {
  margin-top: 8px;
  padding: 7px 11px;
  font-size: 12.5px;
  color: var(--wac-ox-deep);
  background: var(--wac-ox-soft);
  border: 1px solid var(--wac-ox);
  border-radius: var(--wac-r-md);
}

/* ── Typing indicator ──────────────────────────────────────────────────── */
.wara-chat__typing .wara-chat__bubble {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
}
.wara-chat__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wac-ink-3);
  animation: wara-chat-bounce 1.2s infinite ease-in-out;
}
.wara-chat__dot:nth-child(2) { animation-delay: .15s; }
.wara-chat__dot:nth-child(3) { animation-delay: .3s; }
@keyframes wara-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Form ──────────────────────────────────────────────────────────────── */
.wara-chat__form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  background: var(--wac-surface);
  border-top: 1px solid var(--wac-line);
}
.wara-chat__input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--wac-line);
  background: var(--wac-bone);
  color: var(--wac-ink);
  border-radius: var(--wac-r-md);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.wara-chat__input::placeholder { color: var(--wac-ink-3); }
.wara-chat__input:focus {
  border-color: var(--wac-ox);
  box-shadow: 0 0 0 2px var(--wac-ox-soft);
}

.wara-chat__send {
  appearance: none;
  border: none;
  cursor: pointer;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--wac-r-pill);
  background: var(--wac-ox);
  color: var(--wac-bone);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease, opacity 150ms ease;
}
.wara-chat__send:hover { background: var(--wac-ox-deep); }
.wara-chat__send:focus-visible { outline: 2px solid var(--wac-gold); outline-offset: 2px; }
.wara-chat__send:disabled { opacity: .5; cursor: default; }
.wara-chat__send svg { width: 20px; height: 20px; fill: currentColor; }
/* Mirror the "send" arrow in RTL so it points the right way. */
.wara-chat[dir="rtl"] .wara-chat__send svg { transform: scaleX(-1); }

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .wara-chat { bottom: 12px; }
  .wara-chat[dir="ltr"] { right: 12px; }
  .wara-chat[dir="rtl"] { left: 12px; }
  .wara-chat__panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    max-height: none;
  }
  .wara-chat__row { max-width: 90%; }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .wara-chat__launcher,
  .wara-chat__panel,
  .wara-chat__dot,
  .wara-chat__cart { transition: none; animation: none; }
}
