/* ============================================================
   Public sales assistant — text only.
   Uses the site.css design tokens, so it follows the visitor's
   dark/light choice without a second palette.
   ============================================================ */

.sa {
  position: fixed;
  inset-inline-end: 20px;
  inset-block-end: 20px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* Both families, always. A visitor can ask in Arabic on an English page
     and vice versa, so the font cannot follow the page direction: Inter has
     no Arabic glyphs, and listing Cairo after it lets the browser pick per
     character rather than substituting something arbitrary. */
  font-family: "Inter", "Cairo", "Segoe UI", Tahoma, sans-serif;
}

[dir="rtl"] .sa { align-items: flex-start; }

/* The browser's own [hidden] rule is display:none at UA specificity, which a
   class selector setting display:flex silently beats — so toggling .hidden in
   script did nothing and the close button appeared dead. State that the
   attribute wins, explicitly. */
.sa[hidden],
.sa-panel[hidden] { display: none !important; }

/* ------------------------------------------------------------- launcher -- */

.sa-launch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--grad);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 26px var(--shadow-soft);
  transition: transform .18s, box-shadow .18s;
}

.sa-launch:hover { transform: translateY(-2px); box-shadow: 0 14px 32px var(--shadow-deep); }
.sa-launch svg { width: 18px; height: 18px; }

/* The launcher stays put while the panel is open, so the visitor keeps a
   fixed target to close it with. */
.sa.is-open .sa-launch { opacity: .9; }

/* ---------------------------------------------------------------- panel -- */

.sa-panel {
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 60px var(--shadow-deep);
}

.sa-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.sa-title { margin: 0; font-size: 15px; font-weight: 650; line-height: 1.3; color: var(--text); }
.sa-sub { margin: 3px 0 0; font-size: 12px; font-weight: 400; line-height: 1.4; color: var(--text-dim); }

.sa-close {
  border: 0;
  background: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.sa-close:hover { color: var(--text); }

/* ------------------------------------------------------------------ log -- */

.sa-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sa-msg { max-width: 88%; }

/* Direction is set per message by the script, from the text itself — an
   Arabic answer on an English page still has to read right to left, or the
   punctuation lands at the wrong end of the sentence. */
.sa-msg[dir="rtl"] { text-align: right; }
.sa-msg[dir="ltr"] { text-align: left; }
/* pre-wrap, not a <br> pass: the text is model output rendered with
   textContent, so honouring its newlines in CSS keeps short lists readable
   without ever letting that text become markup. */
.sa-msg p {
  margin: 0;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* site.css sets `p { color: var(--text-dim) }` as a bare element rule, and an
   element selector beats a colour merely inherited from the bubble — so the
   text has to be stated on the paragraph itself, not on its container. */
.sa-msg.is-visitor p { color: #fff; }
.sa-msg.is-agent p { color: var(--text); }

.sa-msg.is-agent {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 10px 13px;
  color: var(--text);
}

[dir="rtl"] .sa-msg.is-agent { border-radius: 14px 4px 14px 14px; }

.sa-msg.is-visitor {
  align-self: flex-end;
  background: var(--accent);
  border-radius: 14px 4px 14px 14px;
  padding: 10px 13px;
  color: #fff;
}

[dir="rtl"] .sa-msg.is-visitor { border-radius: 4px 14px 14px 14px; }

/* Three dots while the model is thinking. Motion is suppressed for anyone
   who has asked for less of it. */
.sa-thinking { display: flex; gap: 4px; padding: 14px 13px; }

.sa-thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: sa-blink 1.2s infinite ease-in-out;
}

.sa-thinking span:nth-child(2) { animation-delay: .18s; }
.sa-thinking span:nth-child(3) { animation-delay: .36s; }

@keyframes sa-blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sa-thinking span { animation: none; opacity: .5; }
  .sa-launch { transition: none; }
}

/* ---------------------------------------------------------------- chips -- */

.sa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
}

.sa-chips button {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: color .16s, border-color .16s;
}

.sa-chips button:hover { color: var(--text); border-color: var(--accent); }

/* ----------------------------------------------------------------- form -- */

.sa-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

/* Honeypot: off-screen rather than display:none, which some bots skip. */
.sa-form [data-sa-hp] {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.sa-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
}

.sa-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sa-input::placeholder { color: var(--text-dim); }

.sa-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sa-send svg { width: 17px; height: 17px; }
.sa-send:disabled { opacity: .5; cursor: default; }

[dir="rtl"] .sa-send svg { transform: scaleX(-1); }

.sa-foot {
  margin: 0;
  padding: 0 18px 14px;
  font-size: 10.5px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-dim);
  opacity: .75;
}

@media (max-width: 480px) {
  .sa { inset-inline-end: 12px; inset-block-end: 12px; }
  .sa-panel { width: calc(100vw - 24px); }
}
