/* ============================================
   TripManga Chat Widget — Namespaced CSS
   All rules prefixed .cb- to avoid conflicts
   Brand: Green #1a7a3c + Orange #f59e0b
   ============================================ */

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

:root {
  --cb-primary:      #1a7a3c;
  --cb-primary-dark: #0d5c2e;
  --cb-accent:       #f59e0b;
  --cb-accent-light: #fde68a;
  --cb-surface:      #ffffff;
  --cb-surface2:     #f0faf4;
  --cb-border:       #d1fae5;
  --cb-text:         #111827;
  --cb-text-muted:   #6b7280;
  --cb-visitor-bg:   #1a7a3c;
  --cb-visitor-text: #ffffff;
  --cb-agent-bg:     #f0faf4;
  --cb-agent-text:   #111827;
  --cb-shadow:       0 8px 40px rgba(13,92,46,.2);
  --cb-radius:       16px;
  --cb-font:         'Inter', sans-serif;
  --cb-width:        380px;
  --cb-height:       580px;
  --cb-z:            999999;
}

/* ── LAUNCHER ── */
#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: 12px 20px 12px 14px;
  font-family: var(--cb-font);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(13,92,46,.4);
  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(13,92,46,.5);
}
.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-icon svg { width: 16px; height: 16px; fill: #fff; }
.cb-unread-badge {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: cb-pulse 1.5s infinite;
}
@keyframes cb-pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ── 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(26,122,60,.12);
}
#cb-panel.cb-hidden {
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
}

/* ── HEADER ── */
.cb-header {
  background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark));
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  flex-shrink: 0;
}
.cb-header-avatar {
  width: 40px;
  height: 40px;
  background: var(--cb-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}
.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;
}
.cb-header-brand {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  margin-top: 1px;
}
.cb-header-status {
  font-size: 11px;
  color: rgba(255,255,255,.65);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.cb-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  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: 5px; }
.cb-header-btn {
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  color: rgba(255,255,255,.8);
}
.cb-header-btn:hover { background: rgba(255,255,255,.22); }
.cb-header-btn svg { width: 13px; height: 13px; fill: currentColor; }

/* ── TOPICS ── */
.cb-topics {
  padding: 12px 14px 8px;
  background: var(--cb-surface2);
  border-bottom: 1px solid var(--cb-border);
  flex-shrink: 0;
}
.cb-topics-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--cb-text-muted);
  text-transform: uppercase;
  letter-spacing: .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 11px;
  font-size: 11px;
  font-weight: 500;
  color: var(--cb-text);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  font-family: var(--cb-font);
}
.cb-topic-chip:hover {
  border-color: var(--cb-accent);
  color: var(--cb-primary);
  background: #fffbeb;
}

/* ── MESSAGES ── */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.cb-messages::-webkit-scrollbar { width: 3px; }
.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 .25s ease forwards;
}
@keyframes cb-fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  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: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  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: 3px;
}
.cb-msg-agent .cb-msg-bubble {
  background: var(--cb-agent-bg);
  color: var(--cb-agent-text);
  border-bottom-left-radius: 3px;
}
.cb-msg-meta { font-size: 10px; color: var(--cb-text-muted); margin-top: 3px; padding: 0 3px; }

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

/* ── HANDOVER ── */
.cb-handover-notice {
  text-align: center;
  padding: 9px 14px;
  background: linear-gradient(135deg,#fffbeb,#fef9c3);
  border-top: 1px solid rgba(245,158,11,.2);
  border-bottom: 1px solid rgba(245,158,11,.2);
  font-size: 12px;
  color: #92400e;
  font-weight: 500;
  display: none;
  flex-shrink: 0;
}
.cb-handover-notice.cb-visible { display: block; }

/* ── INPUT ── */
.cb-input-area {
  border-top: 1px solid var(--cb-border);
  background: var(--cb-surface);
  padding: 10px 12px;
  flex-shrink: 0;
}
.cb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  background: var(--cb-surface2);
  border: 1.5px solid var(--cb-border);
  border-radius: 12px;
  padding: 7px 7px 7px 12px;
  transition: border-color .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: 13px;
  color: var(--cb-text);
  resize: none;
  outline: none;
  max-height: 90px;
  line-height: 1.5;
  min-height: 20px;
}
.cb-input::placeholder { color: var(--cb-text-muted); }
.cb-send-btn {
  width: 34px;
  height: 34px;
  background: var(--cb-primary);
  border: none;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
}
.cb-send-btn:hover { background: var(--cb-accent); transform: scale(1.05); }
.cb-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.cb-send-btn svg { width: 15px; height: 15px; fill: #fff; }

.cb-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 7px;
  padding: 0 2px;
}
.cb-input-actions { display: flex; gap: 4px; }
.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 .2s;
}
.cb-action-btn:hover { color: var(--cb-primary); background: var(--cb-surface2); }
.cb-powered { font-size: 10px; color: #d1d5db; font-family: var(--cb-font); }

/* ── TRANSCRIPT ── */
.cb-transcript-panel {
  padding: 12px 14px;
  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: 11px; color: var(--cb-text-muted); display: block; margin-bottom: 6px; font-weight: 500; }
.cb-transcript-row { display: flex; gap: 7px; }
.cb-transcript-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 8px;
  padding: 7px 11px;
  font-family: var(--cb-font);
  font-size: 12px;
  color: var(--cb-text);
  outline: none;
  transition: border-color .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: 7px 13px;
  font-family: var(--cb-font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s;
}
.cb-transcript-btn:hover { background: var(--cb-accent); }

/* ── FEEDBACK ── */
.cb-feedback-panel {
  position: absolute;
  inset: 0;
  background: var(--cb-surface);
  z-index: 10;
  display: none;
  flex-direction: column;
  padding: 28px 22px;
  gap: 16px;
  animation: cb-fadeUp .3s ease;
}
.cb-feedback-panel.cb-visible { display: flex; }
.cb-feedback-title { font-size: 20px; font-weight: 700; color: var(--cb-primary); }
.cb-feedback-sub { font-size: 13px; color: var(--cb-text-muted); margin-top: -8px; }
.cb-stars { display: flex; gap: 8px; }
.cb-star {
  font-size: 28px;
  cursor: pointer;
  color: #d1d5db;
  transition: color .15s, transform .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: 600; color: var(--cb-text); }
.cb-radio-group { display: flex; gap: 10px; }
.cb-radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--cb-text);
  background: var(--cb-surface2);
  padding: 7px 13px;
  border-radius: 8px;
  border: 1.5px solid var(--cb-border);
  transition: all .2s;
}
.cb-radio-label:has(input:checked) {
  border-color: var(--cb-accent);
  background: #fffbeb;
  color: var(--cb-primary);
}
.cb-feedback-textarea {
  width: 100%;
  border: 1.5px solid var(--cb-border);
  border-radius: 10px;
  padding: 9px 11px;
  font-family: var(--cb-font);
  font-size: 12px;
  color: var(--cb-text);
  resize: none;
  outline: none;
  height: 72px;
  box-sizing: border-box;
  transition: border-color .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: 700;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.cb-submit-btn:hover { background: var(--cb-accent); transform: translateY(-1px); }

/* ── ALL SCREEN SIZES — Launcher always visible ── */
#cb-launcher {
  /* Guaranteed fallback position — overridden by JS after load */
  bottom: 20px;
  right: 20px;
  /* Never hidden unless showIcon is false */
  visibility: visible !important;
  opacity: 1 !important;
}

/* ── DESKTOP & TABLET (768px and above) ── */
@media (min-width: 769px) {
  #cb-launcher {
    bottom: 28px;
    right: 28px;
  }
  #cb-panel {
    width: 400px;
    height: 600px;
    bottom: 96px;
    right: 28px;
  }
}

/* ── TABLET (441px – 768px) ── */
@media (min-width: 441px) and (max-width: 768px) {
  #cb-launcher {
    bottom: 24px;
    right: 20px;
  }
  #cb-panel {
    width: 380px;
    height: 560px;
    bottom: 88px;
    right: 20px;
  }
}

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