/* ════════════════════════════════════════════════
   CHAT WIDGET — widget.css
   Scoped entirely to #cw-root
   Themed for Quibbl dark site
════════════════════════════════════════════════ */

#cw-root {
  /* Tokens — Quibbl accent blue, light widget panel */
  --acc: #144fff;
  --acc-hover: #2960ff;
  --bg: #ffffff;
  --surface: #f8f8f7;
  --border: #e5e5e3;
  --text: #18181b;
  --text-2: #6b6a67;
  --text-3: #b0aea9;
  --user-bg: #144fff;
  --user-txt: #ffffff;
  --bot-bg: #f0f0ed;
  --bot-txt: #18181b;
  --top-bg: #0a0a0a;
  --top-txt: #fafafa;
  --top-txt-2: rgba(250,250,250,0.55);
  --dot-color: #4ade80;
  --radius: 16px;
  --w: 348px;
  --h: 530px;
  --tr: 220ms cubic-bezier(0.16, 1, 0.3, 1);

  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
}

/* ── LAUNCHER ───────────────────────────────── */
#cw-launcher {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--acc);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(20,79,255,0.35), 0 1px 4px rgba(0,0,0,0.12);
  transition: transform var(--tr), box-shadow var(--tr), background var(--tr);
  z-index: 2;
  outline: none;
}
#cw-launcher:hover {
  background: var(--acc-hover);
  transform: scale(1.07);
  box-shadow: 0 6px 26px rgba(20,79,255,0.4);
}
#cw-launcher:active { transform: scale(0.95); }

.cw-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--tr), transform var(--tr);
}
.cw-icon-close {
  opacity: 0;
  transform: rotate(-80deg) scale(0.6);
}

#cw-root.open .cw-icon-open {
  opacity: 0;
  transform: rotate(80deg) scale(0.6);
}
#cw-root.open .cw-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* ── PANEL ──────────────────────────────────── */
#cw-panel {
  position: absolute;
  bottom: 62px;
  right: 4px;
  width: var(--w);
  height: var(--h);
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.06),
    0 8px 24px rgba(0,0,0,0.15),
    0 24px 64px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  /* closed */
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity var(--tr), transform var(--tr);
}
#cw-root.open #cw-panel {
  opacity: 1;
  pointer-events: all;
  transform: none;
}

/* ── SCREENS ────────────────────────────────── */
.cw-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.cw-hidden { display: none !important; }

/* ── WELCOME TOP (dark header) ──────────────── */
.cw-welcome-top {
  background: var(--top-bg);
  padding: 22px 20px 20px;
  flex-shrink: 0;
}

.cw-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.cw-avatar-cluster { position: relative; }

.cw-av {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(20,79,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.9);
}

.cw-brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--top-txt);
  line-height: 1.2;
}

.cw-online-txt {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--top-txt-2);
  margin-top: 2px;
}

.cw-dot-live {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot-color);
  animation: cw-pulse 2.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes cw-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.cw-tagline {
  font-size: 22px;
  font-weight: 600;
  color: var(--top-txt);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

/* ── TOPIC CARDS (2x2 grid) ─────────────────── */
.cw-topics-area {
  flex: 1;
  padding: 16px 16px 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.cw-topics-area::-webkit-scrollbar { display: none; }

.cw-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
  padding-left: 2px;
}

.cw-topics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cw-topic {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 14px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 140ms, border-color 140ms, transform 120ms, box-shadow 140ms;
}
.cw-topic:hover {
  background: var(--bg);
  border-color: #c8c7c2;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.cw-topic:active { transform: translateY(0) scale(0.98); }

.cw-topic-icon { font-size: 20px; line-height: 1; }

.cw-topic-text {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

/* ── INPUT AREA ─────────────────────────────── */
.cw-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.cw-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 96px;
  overflow-y: auto;
  transition: border-color 160ms, box-shadow 160ms;
  scrollbar-width: none;
}
.cw-input::-webkit-scrollbar { display: none; }
.cw-input::placeholder { color: var(--text-3); }
.cw-input:focus {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px rgba(20,79,255,0.1);
  background: var(--bg);
}

.cw-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 10px;
  background: var(--acc);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 140ms, transform 120ms;
}
.cw-send:hover:not([disabled]) { background: var(--acc-hover); }
.cw-send:active:not([disabled]) { transform: scale(0.91); }
.cw-send[disabled] {
  background: var(--border);
  color: var(--text-3);
  cursor: not-allowed;
}

/* ── CHAT SCREEN ────────────────────────────── */
.cw-chat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.cw-hdr-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-family: inherit;
  transition: background 140ms, color 140ms;
}
.cw-hdr-btn:hover { background: var(--surface); color: var(--text); }

.cw-chat-id {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

/* ── MESSAGE FEED ───────────────────────────── */
.cw-feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.cw-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: cw-in 0.2s ease both;
}
@keyframes cw-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cw-msg-u { align-self: flex-end; align-items: flex-end; }
.cw-msg-b { align-self: flex-start; align-items: flex-start; }

.cw-bubble {
  padding: 9px 13px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.cw-msg-u .cw-bubble {
  background: var(--user-bg);
  color: var(--user-txt);
  border-radius: 14px 14px 3px 14px;
}
.cw-msg-b .cw-bubble {
  background: var(--bot-bg);
  color: var(--bot-txt);
  border-radius: 14px 14px 14px 3px;
}

.cw-ts {
  font-size: 11px;
  color: var(--text-3);
  padding: 0 4px;
  margin-top: 3px;
}

/* Typing */
.cw-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
  background: var(--bot-bg);
  border-radius: 14px 14px 14px 3px;
  width: fit-content;
  animation: cw-in 0.2s ease both;
}
.cw-d {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: cw-bounce 1.2s ease-in-out infinite;
}
.cw-d:nth-child(2) { animation-delay: 0.15s; }
.cw-d:nth-child(3) { animation-delay: 0.3s; }
@keyframes cw-bounce {
  0%, 80%, 100% { transform: translateY(0); background: var(--text-3); }
  40% { transform: translateY(-5px); background: var(--acc); }
}

/* Follow-up chips */
.cw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
  animation: cw-in 0.25s ease 0.1s both;
}
.cw-chip {
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  font-weight: 450;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: background 130ms, border-color 130ms, color 130ms;
}
.cw-chip:hover {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}

/* ── MOBILE ─────────────────────────────────── */
@media (max-width: 420px) {
  #cw-root { bottom: 16px; right: 16px; --w: calc(100vw - 32px); }
  #cw-panel { right: 0; }
}
