:root {
  --chat-accent: #4f46e5;      /* overwritten by JS from config.accent */
  --chat-radius: 14px;         /* overwritten by JS from config.radius */
  --chat-shadow: 0 10px 36px rgba(0,0,0,.18), 0 6px 16px rgba(0,0,0,.12);
  --chat-bg: #ffffff;
  --chat-fg: #0f172a;
  --chat-muted: #64748b;
  --chat-border: #4a64a5;
  --chat-user: #eef2ff;        /* user bubble */
  --chat-bot: #f8fafc;         /* bot bubble */
}

@media (prefers-color-scheme: dark) {
  :root {
    --chat-bg: #0b1220;
    --chat-fg: #e5e7eb;
    --chat-muted: #9aa4b2;
    --chat-border: #1f2a44;
    --chat-user: #101a34;
    --chat-bot: #0f1a2b;
  }
}

/* ---------- Launcher button ---------- */
.cw-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483646;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 999px;
  background: var(--chat-accent);
  color: #fff;
  box-shadow: var(--chat-shadow);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, opacity .2s ease;
}
.cw-launcher:hover { transform: translateY(-2px); }
.cw-launcher:active { transform: translateY(0); }
.cw-launcher:disabled { opacity:.6; cursor:not-allowed; }

.cw-launcher svg { width: 28px; height: 28px; }

/* ---------- Panel shell ---------- */
.cw-wrap {
  position: fixed;
  right: 22px;
  bottom: 94px;
  z-index: 2147483646;
  width: 360px;
  max-height: calc(100vh - 140px);
  border-radius: var(--chat-radius);
  background: var(--chat-bg);
  color: var(--chat-fg);
  box-shadow: var(--chat-shadow);
  display: none;                /* toggled by JS */
  overflow: hidden;
  border: 1px solid var(--chat-border);
}

@media (max-width: 480px) {
  .cw-wrap {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 88px;
    max-height: calc(100vh - 120px);
  }
}

/* ---------- Header ---------- */
.cw-head {
  position: relative;
  background: linear-gradient(135deg, var(--chat-accent), color-mix(in oklab, var(--chat-accent) 70%, #111 30%));
  color: #fff;
  padding: 14px 16px;
}
.cw-title {
  font-weight: 700;
  letter-spacing:.2px;
  margin: 0 0 4px 0;
  font-size: 16px;
}
.cw-sub {
  margin: 0;
  opacity: .9;
  font-size: 12px;
}

.cw-close {
  position:absolute;
  right:10px; top:10px;
  width:34px; height:34px;
  border:none; border-radius:999px;
  display:inline-flex; align-items:center; justify-content:center;
  background: rgba(255,255,255,.22);
  color:#fff; cursor:pointer;
  transition: background .15s ease, transform .15s ease;
}
.cw-close:hover { background: rgba(255,255,255,.3); transform: translateY(-1px); }

/* ---------- Body / messages ---------- */
.cw-body {
  display:flex;
  flex-direction:column;
  height: 420px;
  background: var(--chat-bg);
}
.cw-scroll {
  padding: 14px 14px 6px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* bubbles */
.cw-row { display:flex; gap:10px; }
.cw-row.user { justify-content:flex-end; }
.cw-bubble {
  max-width: 86%;
  border-radius: calc(var(--chat-radius) - 6px);
  padding: 10px 12px;
  line-height: 1.45;
  border: 1px solid var(--chat-border);
  font-size: 14px;
}
.cw-row.bot .cw-bubble { background: var(--chat-bot); }
.cw-row.user .cw-bubble {
  background: var(--chat-user);
  border-color: color-mix(in srgb, var(--chat-accent) 30%, var(--chat-border));
}

/* ---------- Input row ---------- */
.cw-input {
  display:flex;
  gap:10px;
  padding: 10px;
  border-top: 1px solid var(--chat-border);
  background: color-mix(in srgb, var(--chat-bg) 92%, #000 8%);
}
.cw-input input[type="text"] {
  flex:1;
  outline:none;
  border:1px solid var(--chat-border);
  background: var(--chat-bg);
  color: var(--chat-fg);
  border-radius: calc(var(--chat-radius) - 6px);
  padding: 10px 12px;
  font-size: 14px;
}
.cw-send {
  min-width: 90px;
  border:none;
  border-radius: calc(var(--chat-radius) - 6px);
  background: var(--chat-accent);
  color:#fff; font-weight:600;
  padding: 10px 14px;
  cursor:pointer;
  transition: transform .12s ease, box-shadow .12s ease, opacity .2s ease;
}
.cw-send:hover { transform: translateY(-1px); }
.cw-send:disabled { opacity:.6; cursor:not-allowed; }

/* ---------- System row (errors, tips) ---------- */
.cw-note {
  margin: 8px 14px 0;
  font-size: 12px;
  color: var(--chat-muted);
}

/* ---------- Typing dots ---------- */
.cw-typing {
  display:inline-flex; gap:3px; align-items:center;
}
.cw-dot {
  width:6px; height:6px; border-radius:999px; background: var(--chat-muted);
  animation: cw-blink 1s infinite ease-in-out;
}
.cw-dot:nth-child(2){ animation-delay:.15s }
.cw-dot:nth-child(3){ animation-delay:.3s }
@keyframes cw-blink { 0%,80%,100%{opacity:.35} 40%{opacity:1} }

/* ---------- Utility ---------- */
.cw-hidden { display:none !important; }
