/**
 * AI Chatbot Builder — Widget Styles
 *
 * Self-contained CSS for the chat widget.
 * Uses CSS custom properties for theming.
 *
 * @package AI_Chatbot_Builder
 * @version 1.0.1
 */

/* ─── Root Container ────────────────────────────────────────────── */

#acb-widget-root {
  --acb-primary: #D4A86A;
  --acb-bg: #0C0908;
  --acb-surface: #1A1410;
  --acb-text: #E8E0D5;
  --acb-radius: 12px;
  --acb-shadow: 0 8px 32px rgba(0,0,0,0.4);
  --acb-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  position: fixed;
  z-index: 999999;
  font-family: var(--acb-font);
  font-size: 14px;
  line-height: 1.5;
}

#acb-widget-root[data-position="bottom-right"] {
  bottom: 24px;
  right: 24px;
}

#acb-widget-root[data-position="bottom-left"] {
  bottom: 24px;
  left: 24px;
}

/* ─── Bubble Button ─────────────────────────────────────────────── */

#acb-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

#acb-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

#acb-bubble .acb-bubble-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50%;
  height: 50%;
  color: #ffffff;
}

#acb-bubble .acb-bubble-icon svg {
  width: 100%;
  height: 100%;
}

#acb-bubble.acb-bubble-active {
  transform: rotate(90deg);
}

/* Bubble shapes */
.acb-shape-circle { border-radius: 50%; }
.acb-shape-rounded { border-radius: 16px; }
.acb-shape-squircle { border-radius: 22%; }

/* Badge */
#acb-bubble .acb-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Tooltip */
#acb-bubble .acb-tooltip {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  background: #ffffff;
  color: #1a1a2e;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  opacity: 0;
  transform: translateY(4px);
  animation: acb-tooltip-in 0.3s 1.5s forwards;
  pointer-events: none;
}

#acb-bubble .acb-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 20px;
  border: 6px solid transparent;
  border-top-color: #ffffff;
}

@keyframes acb-tooltip-in {
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Chat Window ───────────────────────────────────────────────── */

#acb-chat {
  position: absolute;
  bottom: calc(100% + 16px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 100px);
  background: var(--acb-bg);
  border-radius: var(--acb-radius);
  box-shadow: var(--acb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#acb-widget-root[data-position="bottom-left"] #acb-chat {
  right: auto;
  left: 0;
}

#acb-chat.acb-hidden {
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
}

#acb-chat.acb-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ─── Header ────────────────────────────────────────────────────── */

.acb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.acb-header-info {
  display: flex;
  flex-direction: column;
}

.acb-header-title {
  font-weight: 600;
  font-size: 15px;
}

.acb-header-sub {
  font-size: 12px;
  opacity: 0.7;
  color: var(--acb-primary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.acb-header-sub::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
}

/* Multi-bot switcher (Plus) */
.acb-bot-switcher {
  margin-top: 6px;
  max-width: 100%;
  font-size: 12px;
  color: var(--acb-text);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 3px 6px;
  cursor: pointer;
}

.acb-close {
  background: none;
  border: none;
  color: var(--acb-text);
  opacity: 0.7;
  cursor: pointer;
  padding: 4px;
  display: flex;
  transition: opacity 0.2s;
  border-radius: 4px;
}

.acb-close:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

.acb-close svg {
  width: 20px;
  height: 20px;
}

/* ─── Messages Area ─────────────────────────────────────────────── */

.acb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.acb-messages::-webkit-scrollbar {
  width: 4px;
}

.acb-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

/* Message bubbles */
.acb-msg {
  display: flex;
  max-width: 85%;
}

.acb-msg-user {
  align-self: flex-end;
}

.acb-msg-assistant {
  align-self: flex-start;
}

.acb-msg-system {
  align-self: center;
}

.acb-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  word-break: break-word;
}

.acb-msg-bubble a {
  color: inherit;
  text-decoration: underline;
}

.acb-msg-user .acb-msg-bubble {
  background: var(--acb-primary);
  color: #0c0908;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.acb-msg-assistant .acb-msg-bubble {
  background: var(--acb-surface);
  color: var(--acb-text);
  border-bottom-left-radius: 4px;
}

.acb-msg-system .acb-msg-bubble {
  background: rgba(255,255,255,0.08);
  color: var(--acb-text);
  opacity: 0.85;
  font-size: 13px;
  text-align: center;
}

/* Code blocks in markdown */
.acb-msg-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

.acb-msg-bubble pre {
  background: rgba(0,0,0,0.4);
  padding: 8px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

/* ─── Typing Indicator ──────────────────────────────────────────── */

.acb-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}

.acb-typing span {
  width: 7px;
  height: 7px;
  background: var(--acb-primary);
  border-radius: 50%;
  opacity: 0.4;
  animation: acb-bounce 1.4s infinite;
}

.acb-typing span:nth-child(2) { animation-delay: 0.2s; }
.acb-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes acb-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ────────────────────────────────────────────────── */

.acb-input-area {
  padding: 12px 14px;
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.acb-input-area form {
  display: flex;
  gap: 8px;
  align-items: center;
}

#acb-input {
  flex: 1;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--acb-font);
  outline: none;
  transition: border-color 0.2s;
}

#acb-input:focus {
  border-color: var(--acb-primary) !important;
}

.acb-send {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  transition: transform 0.2s;
}

.acb-send:hover {
  transform: scale(1.1);
}

.acb-send svg {
  width: 20px;
  height: 20px;
}

/* ─── Lead Form ─────────────────────────────────────────────────── */

.acb-lead-form {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--acb-surface);
  border-radius: 8px;
}

.acb-lead-form p {
  font-size: 13px;
  color: var(--acb-text);
  opacity: 0.9;
  margin: 0 0 4px;
}

.acb-lead-form input {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: var(--acb-text);
  font-size: 14px;
  font-family: var(--acb-font);
  outline: none;
}

.acb-lead-form input:focus {
  border-color: var(--acb-primary);
}

.acb-lead-form button {
  border: none;
  border-radius: 8px;
  padding: 10px;
  color: #0c0908;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.acb-lead-form button:hover {
  opacity: 0.9;
}

/* ─── CSAT ──────────────────────────────────────────────────────── */

.acb-csat {
  padding: 12px;
  text-align: center;
  background: var(--acb-surface);
  border-radius: 8px;
}

.acb-csat p {
  font-size: 13px;
  color: var(--acb-text);
  margin: 0 0 8px;
}

.acb-stars {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.acb-star-btn {
  background: none;
  border: none;
  color: var(--acb-primary);
  cursor: pointer;
  padding: 4px;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
}

.acb-star-btn:hover {
  opacity: 1;
  transform: scale(1.2);
}

.acb-star-btn svg {
  width: 24px;
  height: 24px;
}

.acb-csat-thanks {
  color: var(--acb-primary);
  font-weight: 500;
}

/* ─── Animations ────────────────────────────────────────────────── */

@keyframes acb-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes acb-bubble-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes acb-slideUp {
  0% { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* ─── Mobile ────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #acb-widget-root[data-position="bottom-right"] {
    bottom: 12px;
    right: 12px;
  }

  #acb-widget-root[data-position="bottom-left"] {
    bottom: 12px;
    left: 12px;
  }

  /* Smaller bubble on mobile */
  #acb-bubble {
    width: 50px !important;
    height: 50px !important;
  }

  /* Chat window: compact, not full-screen */
  #acb-chat {
    width: calc(100vw - 24px);
    max-width: 340px;
    height: 420px;
    max-height: calc(100vh - 140px);
    bottom: calc(100% + 10px);
    right: 0;
    border-radius: 14px;
  }

  #acb-widget-root[data-position="bottom-left"] #acb-chat {
    right: auto;
    left: 0;
  }

  .acb-header {
    padding: 12px 14px;
  }

  .acb-header-title {
    font-size: 14px;
  }

  .acb-messages {
    padding: 12px;
    gap: 10px;
  }

  .acb-msg {
    max-width: 90%;
  }

  .acb-msg-bubble {
    padding: 8px 12px;
    font-size: 13px;
  }

  .acb-input-area {
    padding: 10px 12px;
  }

  #acb-input {
    padding: 8px 14px;
    font-size: 13px;
  }

  .acb-lead-form input {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* ─── F5: Handoff Button ──────────────────────────────────────── */

.acb-handoff-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.acb-handoff-btn:hover {
  background: rgba(255,255,255,0.05);
}

/* ─── F4: File Attach Button ──────────────────────────────────── */

.acb-attach {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s;
  padding: 0;
}

.acb-attach:hover {
  background: rgba(255,255,255,0.1);
}

#acb-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
