/* ============================================
   CHATBOT WIDGET v4 — Lead Capture extension
   Giữ nguyên CSS v3, thêm phần unlock form + final CTA
   ============================================ */

.cb-root {
  --cb-brand: var(--brand, #0f172a);
  --cb-accent: var(--accent, #f59e0b);
  --cb-bg: #fff;
  --cb-text: #0f172a;
  --cb-muted: #64748b;
  --cb-border: #e2e8f0;
  --cb-radius: 14px;
  --cb-shadow: 0 8px 32px rgba(15, 23, 42, 0.2);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}

/* === Toggle button === */
.cb-toggle {
  position: fixed; bottom: 84px; right: 16px; z-index: 9998;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cb-brand), var(--cb-accent));
  color: #fff; border: none; cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.3);
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s;
}
.cb-toggle:hover { transform: scale(1.05); }
.cb-toggle svg { width: 26px; height: 26px; stroke-width: 2; }
.cb-toggle.is-open svg.cb-icon-chat { display: none; }
.cb-toggle:not(.is-open) svg.cb-icon-close { display: none; }
.cb-toggle::before {
  content: 'AI'; position: absolute; top: -4px; right: -4px;
  background: #fff; color: var(--cb-brand);
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
@media (max-width: 767px) {
  .cb-toggle { bottom: 76px; right: 12px; }
}

/* === Chat window === */
.cb-window {
  position: fixed; bottom: 156px; right: 16px; z-index: 9999;
  width: 380px; height: 540px; max-height: calc(100vh - 200px);
  background: var(--cb-bg); border-radius: var(--cb-radius); box-shadow: var(--cb-shadow);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(20px) scale(0.96);
  pointer-events: none; transition: opacity .2s, transform .2s;
}
@media (max-width: 767px) {
  .cb-window {
    top: 60px; bottom: 150px; left: 8px; right: 8px;
    width: auto; height: auto; max-height: none; border-radius: 14px;
  }
}
.cb-window.is-open {
  opacity: 1; transform: translateY(0) scale(1); pointer-events: auto;
}
body.cb-open .bottom-nav,
body.cb-open .bottom-nav-bar,
body.cb-open nav.bottom-nav { display: none !important; }
@media (max-width: 767px) {
  body.cb-open .cb-window { bottom: 80px; }
}

/* === Header === */
.cb-header {
  flex-shrink: 0; padding: 14px 16px;
  background: linear-gradient(135deg, var(--cb-brand), var(--cb-accent));
  color: #fff; display: flex; align-items: center; gap: 12px;
}
.cb-header-avatar {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cb-header-info { flex: 1; min-width: 0; }
.cb-header-title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.cb-header-status {
  font-size: 11px; opacity: .85;
  display: flex; align-items: center; gap: 4px;
}
.cb-header-status::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #4ade80; display: inline-block;
}
.cb-close {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.cb-close:hover { background: rgba(255,255,255,0.3); }
.cb-close svg { width: 18px; height: 18px; }

/* === Messages === */
.cb-messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px; background: #f8fafc;
  display: flex; flex-direction: column; gap: 12px;
}
.cb-msg {
  max-width: 85%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.5; word-wrap: break-word; white-space: pre-wrap;
}
.cb-msg-user {
  align-self: flex-end; background: var(--cb-brand); color: #fff;
  border-bottom-right-radius: 4px;
}
.cb-msg-ai {
  align-self: flex-start; background: #fff; color: var(--cb-text);
  border: 1px solid var(--cb-border); border-bottom-left-radius: 4px;
}
.cb-msg-ai strong { color: var(--cb-brand); }
.cb-msg-ai a { color: var(--cb-brand); text-decoration: underline; }
.cb-msg-system {
  align-self: center; background: #fef3c7; color: #92400e;
  font-size: 12.5px; padding: 8px 14px; border-radius: 10px;
  max-width: 90%; text-align: center;
}

.cb-typing {
  align-self: flex-start; background: #fff; border: 1px solid var(--cb-border);
  padding: 12px 16px; border-radius: 14px; border-bottom-left-radius: 4px;
  display: flex; gap: 4px;
}
.cb-typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--cb-muted);
  animation: cbBlink 1.4s infinite ease-in-out both;
}
.cb-typing span:nth-child(2) { animation-delay: .2s; }
.cb-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cbBlink {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* === UNLOCK FORM (mới) === */
.cb-unlock {
  background: linear-gradient(135deg, var(--cb-brand), var(--cb-accent));
  color: #fff; padding: 16px 18px; border-radius: 12px;
  align-self: stretch; text-align: center;
}
.cb-unlock h4 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.cb-unlock-input {
  width: 100%; box-sizing: border-box;
  padding: 10px 14px; margin-bottom: 8px;
  border: none; border-radius: 8px;
  font-size: 14px; font-family: inherit;
  background: rgba(255,255,255,0.95); color: #0f172a;
  outline: none;
}
.cb-unlock-input:focus { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,0.4); }
.cb-unlock-input::placeholder { color: #94a3b8; }
.cb-unlock-btn {
  width: 100%; box-sizing: border-box;
  background: #fff; color: var(--cb-brand);
  padding: 10px 16px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: inherit; margin-top: 4px;
  transition: transform .15s;
}
.cb-unlock-btn:hover:not(:disabled) { transform: scale(1.02); }
.cb-unlock-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.cb-unlock-note {
  font-size: 11px; opacity: 0.9; margin-top: 10px; line-height: 1.4;
}

/* === FINAL CTA (mới) === */
.cb-cta-final {
  background: #fff; border: 2px solid var(--cb-brand);
  padding: 16px 18px; border-radius: 12px; align-self: stretch; text-align: center;
}
.cb-cta-final h4 { margin: 0 0 6px; font-size: 14px; font-weight: 700; color: var(--cb-brand); }
.cb-cta-final p { margin: 0 0 12px; font-size: 12.5px; color: #475569; line-height: 1.4; }
.cb-cta-final-btn {
  display: block;
  background: var(--cb-brand); color: #fff;
  padding: 11px 16px; border-radius: 8px;
  text-decoration: none; font-size: 14px; font-weight: 600;
  margin-bottom: 8px;
}
.cb-cta-final-btn:hover { background: var(--cb-accent); }
.cb-cta-final-btn-alt {
  background: #fff; color: var(--cb-brand);
  border: 1px solid var(--cb-brand);
}
.cb-cta-final-btn-alt:hover { background: #f8fafc; color: var(--cb-brand); }

/* Suggestions */
.cb-suggestions {
  flex-shrink: 0; padding: 8px 16px 4px; background: #f8fafc;
  border-top: 1px solid var(--cb-border);
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.cb-suggestions::-webkit-scrollbar { display: none; }
.cb-suggestion {
  flex-shrink: 0; background: #fff; border: 1px solid var(--cb-border);
  color: var(--cb-text); padding: 6px 12px; border-radius: 16px;
  font-size: 12.5px; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.cb-suggestion:hover {
  background: var(--cb-brand); color: #fff; border-color: var(--cb-brand);
}

/* Input */
.cb-input-area {
  flex-shrink: 0; padding: 10px 12px 12px;
  background: #fff; border-top: 1px solid var(--cb-border);
}
.cb-input-row { display: flex; gap: 8px; align-items: flex-end; }
.cb-input {
  flex: 1; min-height: 40px; max-height: 100px;
  padding: 10px 14px; border: 1px solid var(--cb-border); border-radius: 20px;
  font-size: 14px; font-family: inherit; outline: none; resize: none; line-height: 1.4;
}
.cb-input:focus { border-color: var(--cb-brand); }
.cb-input:disabled { background: #f1f5f9; color: #94a3b8; }
.cb-send {
  width: 40px; height: 40px; background: var(--cb-brand); color: #fff;
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s, transform .15s;
}
.cb-send:hover:not(:disabled) { background: var(--cb-accent); transform: scale(1.05); }
.cb-send:disabled { background: var(--cb-muted); cursor: not-allowed; opacity: 0.6; }
.cb-send svg { width: 18px; height: 18px; }

.cb-disclaimer {
  margin-top: 6px; font-size: 10.5px; color: var(--cb-muted); text-align: center;
}
