/* Cayvoy Support Chat Widget */
:root {
  --sw-accent:   #B9FF66;
  --sw-dark:     #18181b;
  --sw-surface:  #27272a;
  --sw-border:   rgba(255,255,255,0.08);
  --sw-text:     #fafafa;
  --sw-muted:    #a1a1aa;
  --sw-agent-bg: #3f3f46;
  --sw-you-bg:   #B9FF66;
  --sw-you-text: #18181b;
  --sw-radius:   20px;
  --sw-bubble-size: 60px;
  --sw-z:        9999;
}

/* ── Bubble ─────────────────────────────────────────────────────────────────── */
#cv-support-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--sw-bubble-size);
  height: var(--sw-bubble-size);
  background: var(--sw-accent);
  border-radius: 50%;
  cursor: pointer;
  z-index: var(--sw-z);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(185,255,102,0.35);
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s;
  border: none;
  outline: none;
}
#cv-support-bubble:hover  { transform: scale(1.08); box-shadow: 0 6px 32px rgba(185,255,102,0.5); }
#cv-support-bubble:active { transform: scale(0.95); }
#cv-support-bubble svg    { width: 28px; height: 28px; color: #18181b; }

/* Unread badge */
#cv-support-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.2s, transform 0.2s;
}
#cv-support-badge.show { opacity: 1; transform: scale(1); }

/* ── Window ─────────────────────────────────────────────────────────────────── */
#cv-support-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--sw-dark);
  border-radius: var(--sw-radius);
  border: 1px solid var(--sw-border);
  z-index: var(--sw-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  transform-origin: bottom right;
  transform: scale(0.8) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), opacity 0.2s;
}
#cv-support-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.sw-header {
  background: var(--sw-surface);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sw-border);
  flex-shrink: 0;
}
.sw-header-icon {
  width: 40px; height: 40px;
  background: var(--sw-accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sw-header-icon svg { width: 20px; height: 20px; color: #18181b; }
.sw-header-info { flex: 1; min-width: 0; }
.sw-header-title { font-size: 14px; font-weight: 800; color: var(--sw-text); letter-spacing: 0.01em; }
.sw-header-status { font-size: 11px; color: var(--sw-muted); display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.sw-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #6b7280; }
.sw-status-dot.online { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.sw-close-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(255,255,255,0.06);
  color: var(--sw-muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s; flex-shrink: 0;
}
.sw-close-btn:hover { background: rgba(255,255,255,0.12); color: var(--sw-text); }
.sw-close-btn svg { width: 16px; height: 16px; }

/* ── Screens ─────────────────────────────────────────────────────────────────── */
.sw-screen { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sw-screen.hidden { display: none; }

/* ── Form screen ────────────────────────────────────────────────────────────── */
.sw-form-body {
  flex: 1;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  overflow-y: auto;
}
.sw-form-title { font-size: 20px; font-weight: 900; color: var(--sw-text); line-height: 1.2; }
.sw-form-desc  { font-size: 13px; color: var(--sw-muted); margin-top: 4px; line-height: 1.5; }
.sw-form-group { display: flex; flex-direction: column; gap: 6px; }
.sw-label { font-size: 11px; font-weight: 700; color: var(--sw-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.sw-input {
  background: var(--sw-surface);
  border: 1.5px solid var(--sw-border);
  border-radius: 12px;
  color: var(--sw-text);
  font-size: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.sw-input:focus { border-color: var(--sw-accent); }
.sw-input::placeholder { color: #52525b; }
.sw-btn {
  background: var(--sw-accent);
  color: #18181b;
  border: none;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  padding: 14px 24px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  letter-spacing: 0.02em;
  font-family: inherit;
}
.sw-btn:hover { opacity: 0.9; }
.sw-btn:active { transform: scale(0.97); }
.sw-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sw-offline-note {
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--sw-muted);
  line-height: 1.5;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.sw-offline-note svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; color: #f59e0b; }

/* ── Chat screen ─────────────────────────────────────────────────────────────── */
.sw-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.sw-messages::-webkit-scrollbar { width: 4px; }
.sw-messages::-webkit-scrollbar-track { background: transparent; }
.sw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Message bubble */
.sw-msg { display: flex; flex-direction: column; max-width: 78%; }
.sw-msg.visitor { align-self: flex-end; align-items: flex-end; }
.sw-msg.agent   { align-self: flex-start; align-items: flex-start; }
.sw-msg.system  { align-self: center; max-width: 90%; }

.sw-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}
.sw-msg.visitor .sw-msg-bubble { background: var(--sw-you-bg); color: var(--sw-you-text); border-bottom-right-radius: 4px; }
.sw-msg.agent   .sw-msg-bubble { background: var(--sw-agent-bg); color: var(--sw-text); border-bottom-left-radius: 4px; }
.sw-msg.system  .sw-msg-bubble { background: transparent; color: var(--sw-muted); font-size: 12px; text-align: center; border: 1px solid var(--sw-border); border-radius: 8px; }

.sw-msg-image { max-width: 100%; border-radius: 12px; cursor: pointer; display: block; }
.sw-msg-meta  { font-size: 10px; color: var(--sw-muted); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.sw-msg-agent-name { font-size: 11px; font-weight: 700; color: var(--sw-accent); margin-bottom: 4px; }

/* Agent avatar */
.sw-agent-row { display: flex; gap: 8px; align-items: flex-end; }
.sw-agent-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--sw-surface); flex-shrink: 0; }

/* Typing indicator */
.sw-typing { display: flex; align-items: center; gap: 4px; padding: 10px 14px; background: var(--sw-agent-bg); border-radius: 16px; border-bottom-left-radius: 4px; width: fit-content; }
.sw-typing span { width: 6px; height: 6px; background: var(--sw-muted); border-radius: 50%; animation: sw-bounce 1.2s infinite; }
.sw-typing span:nth-child(2) { animation-delay: 0.2s; }
.sw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes sw-bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

/* Delivery status */
.sw-check { width: 14px; height: 14px; color: var(--sw-muted); }
.sw-check.read { color: var(--sw-accent); }

/* ── Input bar ───────────────────────────────────────────────────────────────── */
.sw-input-bar {
  padding: 12px 16px;
  background: var(--sw-surface);
  border-top: 1px solid var(--sw-border);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}
.sw-input-bar textarea {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid var(--sw-border);
  border-radius: 12px;
  color: var(--sw-text);
  font-size: 13.5px;
  padding: 10px 12px;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 40px;
  height: 40px;
  line-height: 1.5;
  transition: border-color 0.15s;
  font-family: inherit;
  box-sizing: border-box;
}
.sw-input-bar textarea:focus { border-color: rgba(185,255,102,0.4); }
.sw-input-bar textarea::placeholder { color: #52525b; }
.sw-icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s, transform 0.1s; flex-shrink: 0;
}
.sw-icon-btn:active { transform: scale(0.92); }
.sw-attach-btn { background: rgba(255,255,255,0.06); color: var(--sw-muted); }
.sw-attach-btn:hover { background: rgba(255,255,255,0.1); color: var(--sw-text); }
.sw-send-btn { background: var(--sw-accent); color: #18181b; }
.sw-send-btn:hover { opacity: 0.9; }
.sw-send-btn:disabled { opacity: 0.4; cursor: default; }
.sw-icon-btn svg { width: 18px; height: 18px; }

/* Closed banner */
.sw-closed-banner {
  padding: 14px 20px;
  background: rgba(239,68,68,0.1);
  border-top: 1px solid rgba(239,68,68,0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: #fca5a5;
  flex-shrink: 0;
}
.sw-new-chat-btn {
  background: var(--sw-accent);
  color: #18181b;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #cv-support-window { bottom: 80px; right: 12px; left: 12px; width: auto; max-height: calc(100vh - 100px); border-radius: 16px; }
  #cv-support-bubble { bottom: 16px; right: 16px; }
}

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.sw-toast {
  position: fixed;
  bottom: 100px;
  right: 24px;
  background: var(--sw-surface);
  color: var(--sw-text);
  border: 1px solid var(--sw-border);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: calc(var(--sw-z) + 1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transform: translateY(8px);
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  max-width: 280px;
}
.sw-toast.show { transform: translateY(0); opacity: 1; }
