/* ============================================
   ChatBot Widget — Namespaced CSS
   All rules prefixed with .cb- to avoid conflicts
   with the host website's existing styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Playfair+Display:wght@600&display=swap');

:root {
  --cb-primary:     #1a2340;
  --cb-accent:      #c8973a;
  --cb-accent-light:#f4c56a;
  --cb-surface:     #ffffff;
  --cb-surface2:    #f7f8fc;
  --cb-border:      #e4e8f0;
  --cb-text:        #1a2340;
  --cb-text-muted:  #7a8296;
  --cb-visitor-bg:  #1a2340;
  --cb-visitor-text:#ffffff;
  --cb-agent-bg:    #f0f2f8;
  --cb-agent-text:  #1a2340;
  --cb-shadow:      0 8px 40px rgba(26,35,64,0.18);
  --cb-radius:      16px;
  --cb-font:        'DM Sans', sans-serif;
  --cb-font-display:'Playfair Display', serif;
  --cb-width:       380px;
  --cb-height:      580px;
  --cb-z:           999999;
}

/* ---- LAUNCHER BUTTON ---- */
#cb-launcher {
  position: fixed;
  z-index: var(--cb-z);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--cb-primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 13px 20px 13px 16px;
  font-family: var(--cb-font);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(26,35,64,0.35);
  transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
  user-select: none;
  white-space: nowrap;
}
#cb-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 28px rgba(26,35,64,0.4);
}
#cb-launcher .cb-launcher-icon {
  width: 32px;
  height: 32px;
  background: var(--cb-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}
#cb-launcher:hover .cb-launcher-icon {
  transform: rotate(15deg);
}
#cb-launcher .cb-launcher-icon svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}
#cb-launcher .cb-unread-badge {
  background: #e53e3e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  animation: cb-pulse 1.5s infinite;
}
@keyframes cb-pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ---- CHAT PANEL ---- */
#cb-panel {
  position: fixed;
  z-index: var(--cb-z);
  width: var(--cb-width);
  height: var(--cb-height);
  background: var(--cb-surface);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--cb-font);
  transform-origin: bottom right;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s ease;
  border: 1px solid rgba(200,151,58,0.15);
}
#cb-panel.cb-hidden {
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
}

/* ---- HEADER ---- */
.cb-header {
  background: var(--cb-primary);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}
.cb-header-avatar {
  width: 42px;
  height: 42px;
  background: var(--cb-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--cb-font-display);
  font-size: 18px;
  color: #fff;
  font-weight: 600;
}
.cb-header-info { flex: 1; min-width: 0; }
.cb-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}
.cb-header-status {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.cb-status-dot {
  width: 7px;
  height: 7px;
  background: #48bb78;
  border-radius: 50%;
  animation: cb-blink 2s infinite;
}
@keyframes cb-blink {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.cb-header-actions {
  display: flex;
  gap: 6px;
}
.cb-header-btn {
  width: 30px;
  height: 30px;
  background: rgba(255,255,255,0.12);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  color: rgba(255,255,255,0.8);
}
.cb-header-btn:hover { background: rgba(255,255,255,0.22); }
.cb-header-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* ---- TOPIC CHIPS ---- */
.cb-topics {
  padding: 14px 16px 8px;
  background: var(--cb-surface2);
  border-bottom: 1px solid var(--cb-border);
  flex-shrink: 0;
}
.cb-topics-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--cb-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.cb-topics-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cb-topic-chip {
  background: #fff;
  border: 1.5px solid var(--cb-border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--cb-text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: var(--cb-font);
}
.cb-topic-chip:hover {
  border-color: var(--cb-accent);
  color: var(--cb-accent);
  background: #fdf8f0;
}

/* ---- MESSAGES ---- */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb { background: var(--cb-border); border-radius: 4px; }

.cb-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: cb-fadeUp 0.3s ease forwards;
}
@keyframes cb-fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cb-msg.cb-msg-visitor { align-self: flex-end; align-items: flex-end; }
.cb-msg.cb-msg-agent   { align-self: flex-start; align-items: flex-start; }

.cb-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}
.cb-msg-visitor .cb-msg-bubble {
  background: var(--cb-visitor-bg);
  color: var(--cb-visitor-text);
  border-bottom-right-radius: 4px;
}
.cb-msg-agent .cb-msg-bubble {
  background: var(--cb-agent-bg);
  color: var(--cb-agent-text);
  border-bottom-left-radius: 4px;
}
.cb-msg-meta {
  font-size: 11px;
  color: var(--cb-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* Typing indicator */
.cb-typing .cb-msg-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}
.cb-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--cb-text-muted);
  border-radius: 50%;
  animation: cb-typing 1.2s infinite;
}
.cb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cb-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cb-typing {
  0%,60%,100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- HANDOVER NOTICE ---- */
.cb-handover-notice {
  text-align: center;
  padding: 10px 16px;
  background: linear-gradient(135deg, #fdf8f0, #fff8e7);
  border-top: 1px solid rgba(200,151,58,0.2);
  border-bottom: 1px solid rgba(200,151,58,0.2);
  font-size: 12px;
  color: var(--cb-accent);
  font-weight: 500;
  display: none;
  flex-shrink: 0;
}
.cb-handover-notice.cb-visible { display: block; }

/* ---- INPUT AREA ---- */
.cb-input-area {
  border-top: 1px solid var(--cb-border);
  background: var(--cb-surface);
  padding: 12px 14px;
  flex-shrink: 0;
}
.cb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cb-surface2);
  border: 1.5px solid var(--cb-border);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s;
}
.cb-input-row:focus-within {
  border-color: var(--cb-accent);
}
.cb-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--cb-font);
  font-size: 14px;
  color: var(--cb-text);
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.5;
  min-height: 22px;
}
.cb-input::placeholder { color: var(--cb-text-muted); }
.cb-send-btn {
  width: 36px;
  height: 36px;
  background: var(--cb-primary);
  border: none;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.cb-send-btn:hover { background: var(--cb-accent); transform: scale(1.05); }
.cb-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.cb-send-btn svg { width: 16px; height: 16px; fill: #fff; }

.cb-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 2px;
}
.cb-input-actions { display: flex; gap: 6px; }
.cb-action-btn {
  background: none;
  border: none;
  font-family: var(--cb-font);
  font-size: 11px;
  color: var(--cb-text-muted);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}
.cb-action-btn:hover { color: var(--cb-accent); background: #fdf8f0; }
.cb-powered {
  font-size: 10px;
  color: var(--cb-border);
  font-family: var(--cb-font);
}

/* ---- FEEDBACK PANEL ---- */
.cb-feedback-panel {
  position: absolute;
  inset: 0;
  background: var(--cb-surface);
  z-index: 10;
  display: none;
  flex-direction: column;
  padding: 28px 24px;
  gap: 18px;
  animation: cb-fadeUp 0.3s ease;
}
.cb-feedback-panel.cb-visible { display: flex; }
.cb-feedback-title {
  font-family: var(--cb-font-display);
  font-size: 20px;
  color: var(--cb-primary);
}
.cb-feedback-sub {
  font-size: 13px;
  color: var(--cb-text-muted);
  margin-top: -10px;
}
.cb-stars {
  display: flex;
  gap: 8px;
}
.cb-star {
  font-size: 28px;
  cursor: pointer;
  color: var(--cb-border);
  transition: color 0.15s, transform 0.15s;
  line-height: 1;
}
.cb-star:hover, .cb-star.cb-active { color: var(--cb-accent); transform: scale(1.15); }
.cb-feedback-q { font-size: 13px; font-weight: 500; color: var(--cb-text); }
.cb-radio-group { display: flex; gap: 10px; }
.cb-radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--cb-text);
  background: var(--cb-surface2);
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--cb-border);
  transition: all 0.2s;
}
.cb-radio-label:has(input:checked) {
  border-color: var(--cb-accent);
  background: #fdf8f0;
  color: var(--cb-accent);
}
.cb-feedback-textarea {
  width: 100%;
  border: 1.5px solid var(--cb-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--cb-font);
  font-size: 13px;
  color: var(--cb-text);
  resize: none;
  outline: none;
  height: 80px;
  box-sizing: border-box;
  transition: border-color 0.2s;
}
.cb-feedback-textarea:focus { border-color: var(--cb-accent); }
.cb-submit-btn {
  background: var(--cb-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-family: var(--cb-font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  letter-spacing: 0.3px;
}
.cb-submit-btn:hover { background: var(--cb-accent); transform: translateY(-1px); }

/* ---- TRANSCRIPT REQUEST ---- */
.cb-transcript-panel {
  padding: 16px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-surface2);
  display: none;
  flex-shrink: 0;
}
.cb-transcript-panel.cb-visible { display: block; }
.cb-transcript-panel label { font-size: 12px; color: var(--cb-text-muted); display: block; margin-bottom: 6px; }
.cb-transcript-row { display: flex; gap: 8px; }
.cb-transcript-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--cb-font);
  font-size: 13px;
  color: var(--cb-text);
  outline: none;
  transition: border-color 0.2s;
}
.cb-transcript-input:focus { border-color: var(--cb-accent); }
.cb-transcript-btn {
  background: var(--cb-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-family: var(--cb-font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.cb-transcript-btn:hover { background: var(--cb-accent); }

/* ---- MOBILE RESPONSIVE ---- */
@media (max-width: 440px) {
  #cb-panel {
    width: 100vw !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    top: 0 !important;
  }
  #cb-launcher {
    bottom: 20px !important;
    right: 16px !important;
  }
}
