/* ==========================================================================
 * Unified chat widget — Live Helper Chat skin
 * --------------------------------------------------------------------------
 * Internal dashboard components reuse these classes. The customer web-chat
 * widget and its previews use frontends/embed/lhc exclusively.
 *
 * The visual language deliberately matches the Live Helper Chat widget
 * (10px-radius bordered shell, #ededed header/agent bubbles, brand user
 * bubbles at 20px radius, 62px circular launcher) so existing LHC
 * customers see a familiar widget. Backend is Chat2 throughout.
 *
 * Theming: the widget takes a `--cw-brand` custom property from its
 * parent (set inline, per-instance). Light/dark is driven by a
 * `data-theme="dark"` attribute on the .chat-widget root. Everything
 * else is derived so a host page only has to set the brand colour.
 * ========================================================================== */

.chat-widget {
  /* theme tokens — overridable per-instance */
  --cw-brand: #0c8fc4;
  --cw-brand-contrast: #fff;
  --cw-bg: #ffffff;
  --cw-body-bg: #ffffff;
  --cw-border: #cecece;
  --cw-header-bg: #ededed;
  --cw-header-text: #212529;
  --cw-text: #212529;
  --cw-text-muted: #6b6b6b;
  --cw-bubble-agent-bg: #ededed;
  --cw-bubble-agent-text: #212529;
  --cw-bubble-user-bg: var(--cw-brand);
  --cw-bubble-user-text: var(--cw-brand-contrast);
  --cw-input-bg: #ffffff;
  --cw-input-text: #212529;
  --cw-shadow: 0 2px 10px rgba(50, 50, 50, 0.18);
  --cw-radius: 10px;
  --cw-radius-bubble: 20px;

  display: flex;
  flex-direction: column;
  background: var(--cw-bg);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius);
  overflow: hidden;
  box-shadow: var(--cw-shadow);
  font-family: Helvetica, Arial, "Segoe UI", system-ui, sans-serif;
  color: var(--cw-text);
  min-width: 0;
}

.chat-widget[data-theme="dark"] {
  --cw-bg: #1a1a1a;
  --cw-body-bg: #1a1a1a;
  --cw-border: #3a3a3a;
  --cw-header-bg: #242424;
  --cw-header-text: #f0f0f0;
  --cw-text: #f0f0f0;
  --cw-text-muted: #a0a0a0;
  --cw-bubble-agent-bg: #2c2c2c;
  --cw-bubble-agent-text: #f0f0f0;
  --cw-input-bg: #1a1a1a;
  --cw-input-text: #f0f0f0;
  --cw-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

/* ── Header ───────────────────────────────────────────────────── */

.chat-widget__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cw-border);
  background: var(--cw-header-bg);
  color: var(--cw-header-text);
  flex-shrink: 0;
  user-select: none;
}

.chat-widget__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--cw-brand);
  color: var(--cw-brand-contrast);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
  flex-shrink: 0;
}

.chat-widget__info {
  flex: 1;
  min-width: 0;
}

.chat-widget__name {
  font-weight: 700;
  font-size: 14px;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__sub {
  font-size: 11px;
  color: inherit;
  opacity: .75;
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

/* The tagline is user-supplied, so it clips rather than widening the header. */
.chat-widget__sub > span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* LHC-style online status dot in front of the subtitle */
.chat-widget__sub::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #47ba51;
  flex-shrink: 0;
}

.chat-widget__close {
  background: transparent;
  border: none;
  color: inherit;
  opacity: .75;
  font-size: 22px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 6px;
  transition: opacity .15s ease, background .15s ease;
}

.chat-widget__close:hover { opacity: 1; background: rgba(0, 0, 0, .08); }

/* ── Body ─────────────────────────────────────────────────────── */

.chat-widget__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px;
  background: var(--cw-body-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Subtle scrollbar styling — optional, progressive */
.chat-widget__body::-webkit-scrollbar { width: 8px; }
.chat-widget__body::-webkit-scrollbar-thumb { background: var(--cw-border); border-radius: 4px; }
.chat-widget__body::-webkit-scrollbar-track { background: transparent; }

/* ── Messages ─────────────────────────────────────────────────── */

.chat-widget__msg {
  display: flex;
  animation: cw-msg-in .28s ease-out both;
}

.chat-widget__msg--user { justify-content: flex-end; }
.chat-widget__msg--agent { justify-content: flex-start; }

.chat-widget__bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: var(--cw-radius-bubble);
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-widget__bubble--agent {
  background: var(--cw-bubble-agent-bg);
  color: var(--cw-bubble-agent-text);
}

.chat-widget__bubble--user {
  background: var(--cw-bubble-user-bg);
  color: var(--cw-bubble-user-text);
}

/* ── Typing dots ─────────────────────────────────────────────── */

.chat-widget__typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
  animation: cw-blink 1.5s linear infinite;
}

.chat-widget__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cw-text-muted);
  opacity: .6;
  animation: cw-typing 1.2s ease-in-out infinite;
}

.chat-widget__typing span:nth-child(2) { animation-delay: .15s; }
.chat-widget__typing span:nth-child(3) { animation-delay: .3s; }

@keyframes cw-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes cw-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

/* ── Input row ───────────────────────────────────────────────── */

.chat-widget__input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-input-bg);
  flex-shrink: 0;
}

.chat-widget__input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  padding: 8px 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: transparent;
  color: var(--cw-input-text);
}

.chat-widget__input::placeholder { color: var(--cw-text-muted); }

.chat-widget__send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--cw-brand);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  transition: transform .18s ease, opacity .18s ease, background .15s ease;
}

/* The paper-airplane SVG's visual mass sits up-right of the viewBox
   centre — the airplane's tip pulls the eye to (22,2) and the empty
   lower-left triangle leaves dead space the centring algorithm can't
   see. Push the SVG down-left so the optical centre lands on the
   button centre. Tuned by eye against the round button. */
.chat-widget__send svg {
  display: block;
  transform: translate(-2px, 2px);
}

.chat-widget__send:hover { transform: scale(1.08); background: var(--cw-bubble-agent-bg); }
.chat-widget__send:active { transform: scale(.95); }
.chat-widget__send:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ── Message append animation ────────────────────────────────── */

@keyframes cw-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Reduced-motion: respect the user's wishes ────────────────── */

@media (prefers-reduced-motion: reduce) {
  .chat-widget__msg,
  .chat-widget__send,
  .chat-widget__close {
    animation: none !important;
    transition: none !important;
  }
  .chat-widget__typing,
  .chat-widget__typing span { animation: none !important; opacity: .7; }
}
