/* ── Automatiseer-Slim Chatbot — Next Level Mobile-First Design ──────────── */

:root {
  --cb-bg: #080f1e;
  --cb-surface: #0f1c33;
  --cb-surface2: #162039;
  --cb-border: rgba(255, 255, 255, 0.07);
  --cb-accent: #22d3ee;
  --cb-accent2: #6366f1;
  --cb-accent-dim: rgba(34, 211, 238, 0.12);
  --cb-text: #e2e8f0;
  --cb-text-dim: #7b90b2;
  --cb-bot-bg: #111d35;
  --cb-user-bg: rgba(34, 211, 238, 0.14);
  --cb-radius: 20px;
  --cb-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(34,211,238,0.1);
  --cb-z: 9999;
}

/* ── Backdrop (mobiel) ──────────────────────────────────────────────────── */
#cb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: calc(var(--cb-z) - 1);
  opacity: 0;
  transition: opacity 0.25s ease;
}

#cb-backdrop.visible {
  opacity: 1;
}

@media (max-width: 480px) {
  #cb-backdrop { display: block; pointer-events: none; }
  #cb-backdrop.visible { pointer-events: all; }
}

/* ── Toggle knop ─────────────────────────────────────────────────────────── */
#chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: var(--cb-z);
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#chat-toggle::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #22d3ee, #6366f1, #22d3ee);
  animation: cbRingSpin 3s linear infinite;
  opacity: 0.7;
  z-index: -1;
}

#chat-toggle::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #22d3ee, #6366f1, #22d3ee);
  animation: cbRingSpin 3s linear infinite;
  filter: blur(6px);
  opacity: 0.4;
  z-index: -2;
}

#chat-toggle.open::before,
#chat-toggle.open::after {
  opacity: 0;
  animation: none;
}

@keyframes cbRingSpin {
  to { transform: rotate(360deg); }
}

.cb-toggle-inner {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  overflow: hidden;
  border: 2.5px solid var(--cb-bg);
  background: linear-gradient(135deg, #0f1c33, #162039);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

#chat-toggle:hover .cb-toggle-inner {
  transform: scale(1.07);
}

.cb-toggle-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  transition: opacity 0.2s ease;
}

.cb-close-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.6) rotate(-90deg);
  transition: opacity 0.2s ease, transform 0.2s ease;
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  border-radius: 50%;
}

#chat-toggle.open .cb-close-icon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

#chat-toggle.open .cb-toggle-inner img {
  opacity: 0;
}

.cb-close-icon svg {
  width: 20px;
  height: 20px;
  color: #fff;
}

#chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, sans-serif;
  border: 2px solid var(--cb-bg);
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

#chat-badge.visible {
  opacity: 1;
  transform: scale(1);
}

.cb-online-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #22c55e;
  border: 2.5px solid var(--cb-bg);
  z-index: 2;
  animation: cbGreenPulse 2.5s ease-in-out infinite;
}

#chat-toggle.open .cb-online-dot {
  opacity: 0;
}

@keyframes cbGreenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

/* ── Chatvenster ─────────────────────────────────────────────────────────── */
#chat-window {
  position: fixed;
  z-index: var(--cb-z);
  display: flex;
  flex-direction: column;
  background: var(--cb-bg);
  border: 1px solid var(--cb-border);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

@media (min-width: 481px) {
  #chat-window {
    bottom: 96px;
    right: 20px;
    width: 460px;
    height: min(720px, calc(100vh - 120px));
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
  }
  #chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
  }
}

@media (max-width: 480px) {
  #chat-window {
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 85dvh;
    max-height: 85dvh;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
    transform: translateY(100%);
  }
  #chat-window.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
  }
  #chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }
  .cb-toggle-inner {
    width: 52px;
    height: 52px;
  }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#chat-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, #0f1c33 0%, #111d38 100%);
  border-bottom: 1px solid var(--cb-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}

#chat-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34,211,238,0.3), transparent);
}

.cb-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid rgba(34, 211, 238, 0.4);
}

.cb-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cb-header-info {
  flex: 1;
  min-width: 0;
}

.cb-header-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--cb-text);
  font-family: system-ui, -apple-system, sans-serif;
  letter-spacing: -0.01em;
}

.cb-header-role {
  font-size: 11px;
  color: var(--cb-text-dim);
  font-family: system-ui, -apple-system, sans-serif;
  margin-top: 1px;
}

.cb-header-status {
  font-size: 11px;
  color: #22c55e;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: system-ui, -apple-system, sans-serif;
  margin-top: 2px;
}

.cb-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  animation: cbGreenPulse 2.5s ease-in-out infinite;
}

#cb-call-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--cb-accent);
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

#cb-call-btn:hover { background: rgba(34, 211, 238, 0.2); transform: scale(1.05); }
#cb-call-btn:active { transform: scale(0.95); }
#cb-call-btn svg { width: 18px; height: 18px; }

/* ── Disclaimer ──────────────────────────────────────────────────────────── */
#chat-disclaimer {
  padding: 7px 16px;
  font-size: 10px;
  color: var(--cb-text-dim);
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid var(--cb-border);
  text-align: center;
  font-family: system-ui, -apple-system, sans-serif;
  flex-shrink: 0;
}

/* ── Berichten ───────────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }

.cb-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  animation: cbMsgIn 0.22s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

.cb-msg-row.user-row {
  flex-direction: row-reverse;
}

.cb-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 1.5px solid rgba(34,211,238,0.25);
}

.cb-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@keyframes cbMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg {
  max-width: 78%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--cb-text);
  word-break: break-word;
}

.chat-msg.bot {
  background: var(--cb-bot-bg);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px 14px 14px 4px;
}

.chat-msg.user {
  background: linear-gradient(135deg, rgba(34,211,238,0.17), rgba(99,102,241,0.14));
  border: 1px solid rgba(34,211,238,0.2);
  border-radius: 14px 14px 4px 14px;
}

.chat-msg a {
  color: var(--cb-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Typing indicator */
#chat-typing {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
  background: var(--cb-bot-bg);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px 14px 14px 4px;
  align-self: flex-start;
  width: fit-content;
}

#chat-typing.visible { display: flex; }

#chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cb-text-dim);
  animation: cbDot 1.3s infinite ease-in-out;
}
#chat-typing span:nth-child(2) { animation-delay: 0.18s; }
#chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes cbDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick reply chips ───────────────────────────────────────────────────── */
#cb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 13px 10px;
  flex-shrink: 0;
}

.cb-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: 20px;
  background: rgba(34,211,238,0.07);
  border: 1px solid rgba(34,211,238,0.2);
  color: var(--cb-accent);
  font-size: 12px;
  font-weight: 500;
  font-family: system-ui, -apple-system, sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cb-chip-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.cb-chip:hover,
.cb-chip:active {
  background: rgba(34,211,238,0.17);
  transform: scale(0.97);
}

.cb-chip.call {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.3);
  color: #22c55e;
}

.cb-chip.call:hover {
  background: rgba(34, 197, 94, 0.18);
}

/* ── Lead form ───────────────────────────────────────────────────────────── */
.chat-lead-form {
  background: linear-gradient(135deg, rgba(34,211,238,0.06), rgba(99,102,241,0.06));
  border: 1px solid rgba(34,211,238,0.18);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-self: stretch;
  animation: cbMsgIn 0.25s ease both;
}

.chat-lead-form label {
  font-size: 12.5px;
  color: var(--cb-text-dim);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.45;
}

.chat-lead-form input {
  width: 100%;
  padding: 10px 12px;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  color: var(--cb-text);
  font-size: 16px;
  font-family: system-ui, -apple-system, sans-serif;
  outline: none;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
  -webkit-appearance: none;
}

.chat-lead-form input:focus { border-color: rgba(34,211,238,0.45); }

.chat-lead-form button {
  padding: 11px 16px;
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  transition: opacity 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-lead-form button:hover  { opacity: 0.9; }
.chat-lead-form button:active { transform: scale(0.98); }
.chat-lead-form button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Input area ──────────────────────────────────────────────────────────── */
#chat-input-area {
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--cb-border);
  background: var(--cb-surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--cb-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  color: var(--cb-text);
  font-size: 16px;
  font-family: system-ui, -apple-system, sans-serif;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color 0.15s ease;
  overflow-y: auto;
  -webkit-appearance: none;
}

#chat-input:focus { border-color: rgba(34,211,238,0.35); }
#chat-input::placeholder { color: var(--cb-text-dim); }

#chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#chat-send:hover  { opacity: 0.88; }
#chat-send:active { transform: scale(0.94); }
#chat-send:disabled { opacity: 0.35; cursor: not-allowed; }
#chat-send svg { width: 16px; height: 16px; color: #fff; }

/* ── CTA ─────────────────────────────────────────────────────────────────── */
.chat-cta {
  display: block;
  text-align: center;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(34,211,238,0.09), rgba(99,102,241,0.09));
  border: 1px solid rgba(34,211,238,0.25);
  border-radius: 12px;
  color: var(--cb-accent);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  font-family: system-ui, -apple-system, sans-serif;
  transition: background 0.15s ease;
  align-self: stretch;
  animation: cbMsgIn 0.25s ease both;
}

.chat-cta:hover {
  background: linear-gradient(135deg, rgba(34,211,238,0.18), rgba(99,102,241,0.18));
  text-decoration: none;
}

/* ── Mobiel extra ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-msg { font-size: 14.5px; line-height: 1.6; }
  .cb-chip { font-size: 13px; padding: 8px 15px; }
  #chat-header { padding: 16px; }
  .cb-header-avatar { width: 46px; height: 46px; }
  .cb-header-name { font-size: 15px; }
}
