/* CoptAra — floating Divine/Luna chat widget
   Theme-aware (uses global tokens), mobile-first, RTL-aware.
   Scoped under #cw-root / .cw- so it never collides with the full-page chat. */

#cw-root { position: fixed; z-index: 1000; }

/* ── Launcher button ─────────────────────────────────────────────── */
.cw-launch {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 0 12px;
  height: 52px;
  border: none;
  border-radius: 26px;
  background: var(--color-accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  transition: transform var(--duration-fast), opacity var(--duration-fast);
}
.cw-launch:hover { transform: translateY(-2px); }
.cw-launch img { width: 30px; height: 30px; border-radius: 50%; display: block; }
.cw-launch__label { white-space: nowrap; }

[dir="rtl"] .cw-launch { right: auto; left: 20px; padding: 0 12px 0 16px; }

/* Hide the launcher while the panel is open */
#cw-root.cw-open .cw-launch { opacity: 0; pointer-events: none; }

/* ── Panel ───────────────────────────────────────────────────────── */
.cw-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100dvh - 40px);
  display: none;
  flex-direction: column;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
[dir="rtl"] .cw-panel { right: auto; left: 20px; }
#cw-root.cw-open .cw-panel { display: flex; }

@media (max-width: 480px) {
  .cw-panel {
    width: 100vw; height: 100dvh; max-height: 100dvh;
    bottom: 0; right: 0; left: 0; border: none; border-radius: 0;
  }
}

/* ── Header ──────────────────────────────────────────────────────── */
.cw-hd {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.cw-hd__avatar { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: var(--color-accent); }
.cw-hd__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cw-hd__name { font-weight: 600; font-size: var(--text-sm); line-height: 1.2; }
.cw-hd__sub  { font-size: var(--text-xs); color: var(--color-text-muted); }
.cw-hd__close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 22px; line-height: 1; padding: 4px 6px;
}
[dir="rtl"] .cw-hd__close { margin-left: 0; margin-right: auto; }

/* ── Messages ────────────────────────────────────────────────────── */
.cw-messages {
  flex: 1; overflow-y: auto; padding: var(--space-md);
  display: flex; flex-direction: column; gap: var(--space-sm);
  scroll-behavior: smooth;
}
.cw-msg { display: flex; gap: 8px; max-width: 88%; }
.cw-msg--bot  { align-self: flex-start; }
.cw-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.cw-msg__avatar { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; overflow: hidden; margin-top: 3px; background: var(--color-accent); }
.cw-msg__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cw-msg__bubble { padding: 9px 12px; font-size: var(--text-sm); line-height: 1.7; word-break: break-word; }
.cw-msg--bot  .cw-msg__bubble { background: var(--color-surface);   border-radius: 2px var(--radius-md) var(--radius-md) var(--radius-md); }
.cw-msg--user .cw-msg__bubble { background: var(--color-surface-2); border-radius: var(--radius-md) 2px var(--radius-md) var(--radius-md); }
.cw-msg--crisis .cw-msg__bubble { border-left: 3px solid var(--color-accent); padding-left: var(--space-md); }
.cw-msg__bubble p { margin: 0 0 0.5em; } .cw-msg__bubble p:last-child { margin-bottom: 0; }
.cw-msg__bubble a { color: var(--color-accent); text-underline-offset: 2px; }
.cw-msg__bubble strong { font-weight: 600; }

/* Discovery chip (item 1b) */
.cw-chip {
  align-self: flex-start; margin: 0 0 2px;
  background: transparent; border: 1px solid var(--color-accent);
  color: var(--color-accent); border-radius: 16px;
  padding: 5px 12px; font-size: var(--text-xs); font-weight: 600; cursor: pointer;
}
.cw-chip:hover { background: var(--color-accent); color: #fff; }

.cw-typing span { display: inline-block; width: 6px; height: 6px; background: var(--color-text-muted); border-radius: 50%; margin: 0 2px; animation: cw-typing 1.2s infinite ease-in-out; }
.cw-typing span:nth-child(2) { animation-delay: 0.2s; }
.cw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cw-typing { 0%,60%,100% { opacity: 0.3; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }

/* Collapsible sources */
.cw-sources { margin-top: 0.5em; font-size: 0.8em; }
.cw-sources summary { cursor: pointer; color: var(--color-text-muted); list-style: none; }
.cw-sources summary::before { content: '▸'; margin-right: 4px; font-size: 0.75em; }
.cw-sources[open] summary::before { content: '▾'; }
.cw-sources-body { margin-top: 0.3em; padding-left: 0.7em; border-left: 2px solid var(--color-border); line-height: 1.7; }

/* ── Input ───────────────────────────────────────────────────────── */
.cw-input-area { flex-shrink: 0; border-top: 1px solid var(--color-border); background: var(--color-bg); padding: var(--space-sm) var(--space-md); }
.cw-form { display: flex; gap: 8px; align-items: flex-end; }
.cw-input {
  flex: 1; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: 9px 12px; font-family: var(--font-sans);
  font-size: var(--text-sm); color: var(--color-text); resize: none;
  min-height: 40px; max-height: 110px; line-height: 1.5; outline: none;
}
.cw-input:focus { border-color: var(--color-accent); }
.cw-send { flex-shrink: 0; background: var(--color-accent); color: #fff; border: none; border-radius: var(--radius-md); padding: 0 14px; height: 40px; font-size: var(--text-sm); font-weight: 500; cursor: pointer; white-space: nowrap; }
.cw-send:disabled { opacity: 0.45; cursor: not-allowed; }
