/* ==========================================================================
   Sam's — customer-support chat widget
   Reuses the site's own design tokens (css/style.css :root) rather than a
   separate palette. Everything is scoped under .sams-chat so it can't leak
   into, or be affected by, the rest of the page.
   ========================================================================== */

.sams-chat {
  position: fixed;
  z-index: 999;
  inset-block-end: 20px;
  inset-inline-end: 20px;
  font-family: var(--font-body);
}

.sams-chat__toggle {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-pill);
  background: var(--charcoal);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.sams-chat__toggle:hover { transform: scale(1.05); }
.sams-chat__toggle svg { width: 26px; height: 26px; }
.sams-chat__toggle .sams-chat__badge {
  position: absolute;
  top: -2px;
  inset-inline-end: -2px;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-pill);
  background: var(--orange);
  border: 2px solid #fff;
  display: none;
}
.sams-chat.has-unread .sams-chat__badge { display: block; }

.sams-chat__panel {
  position: absolute;
  inset-block-end: 76px;
  inset-inline-end: 0;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.sams-chat.is-open .sams-chat__panel { display: flex; }
.sams-chat.is-open .sams-chat__toggle .sams-chat__icon-open { display: none; }
.sams-chat.is-open .sams-chat__toggle .sams-chat__icon-close { display: block; }
.sams-chat__toggle .sams-chat__icon-close { display: none; }

@media (max-width: 480px) {
  .sams-chat__panel {
    position: fixed;
    inset: 12px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    z-index: 1;
  }
  /* The fullscreen mobile panel covers the toggle's usual bottom-right spot
     (which would otherwise collide with the message input row) -- move the
     same button to a conventional top-right close position while open. */
  .sams-chat.is-open .sams-chat__toggle {
    position: fixed;
    inset-block-start: 24px;
    inset-inline-end: 24px;
    inset-block-end: auto;
    width: 44px;
    height: 44px;
    z-index: 2;
    box-shadow: none;
    background: rgba(36, 24, 17, 0.55);
  }
}

.sams-chat__header {
  background: var(--charcoal);
  color: #fff;
  padding: 16px 18px;
  flex-shrink: 0;
}
.sams-chat__header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #fff;
}
.sams-chat__header p {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.75);
}

.sams-chat__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sams-chat__step { display: none; flex-direction: column; gap: 12px; height: 100%; }
.sams-chat__step.is-active { display: flex; }

.sams-chat__field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-block-end: 6px;
  color: var(--charcoal-soft);
}
.sams-chat__field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
}
.sams-chat__field input:focus { outline: 2px solid var(--orange); outline-offset: 1px; }

.sams-chat__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}
.sams-chat__error {
  font-size: 0.82rem;
  color: var(--error);
  margin: 0;
  display: none;
}
.sams-chat__error.is-visible { display: block; }

.sams-chat__submit {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.sams-chat__submit:disabled { opacity: 0.55; cursor: default; }
.sams-chat__submit:not(:disabled):hover { background: var(--orange-dark); }

.sams-chat__link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  align-self: flex-start;
}
.sams-chat__link-btn:disabled { opacity: 0.5; cursor: default; text-decoration: none; }

.sams-chat__consent {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-block-start: auto;
}

/* -- chat step -- */

.sams-chat__step--chat { padding: 0; gap: 0; }
.sams-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sams-chat__msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.sams-chat__msg--customer {
  align-self: flex-end;
  background: var(--orange);
  color: #fff;
  border-end-end-radius: 4px;
}
.sams-chat__msg--ai, .sams-chat__msg--staff {
  align-self: flex-start;
  background: var(--cream);
  color: var(--charcoal);
  border-end-start-radius: 4px;
}
.sams-chat__msg-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--orange-dark);
  margin-block-end: 3px;
}

.sams-chat__typing {
  align-self: flex-start;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 18px 8px;
  display: none;
}
.sams-chat__typing.is-visible { display: block; }

.sams-chat__banner {
  font-size: 0.78rem;
  padding: 8px 18px;
  text-align: center;
  display: none;
}
.sams-chat__banner.is-visible { display: block; }
.sams-chat__banner--error { background: #fdecea; color: var(--error); }
.sams-chat__banner--offline { background: #fff3ea; color: var(--orange-dark); }

.sams-chat__input-row {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.sams-chat__input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font: inherit;
  font-size: 0.9rem;
  max-height: 90px;
}
.sams-chat__input-row textarea:focus { outline: 2px solid var(--orange); outline-offset: 1px; }
.sams-chat__send {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sams-chat__send:disabled { opacity: 0.55; cursor: default; }
.sams-chat__send svg { width: 18px; height: 18px; }

.sams-chat__logout {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font: inherit;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-block-start: 6px;
}

/* Latin-script/numeric content (phone numbers, {seconds} counters) must stay
   LTR even inside an Arabic (RTL) page -- same fix already applied site-wide
   in css/style.css and js/main.js. */
[dir="rtl"] .sams-chat [dir="ltr"] { unicode-bidi: isolate; }
