/* ============================================================
   AI School Chatbot Widget – CSS
   Modern, mobile-first chat UI inspired by WhatsApp/Intercom
   ============================================================ */

:root {
  --aiscb-primary:       #2563eb;
  --aiscb-primary-dark:  #1d4ed8;
  --aiscb-primary-light: #dbeafe;
  --aiscb-surface:       #ffffff;
  --aiscb-bg:            #f0f2f5;
  --aiscb-text:          #111827;
  --aiscb-text-muted:    #6b7280;
  --aiscb-border:        #e5e7eb;
  --aiscb-bot-bubble:    #ffffff;
  --aiscb-user-bubble:   var(--aiscb-primary);
  --aiscb-shadow:        0 20px 60px rgba(0,0,0,0.18);
  --aiscb-radius:        18px;
  --aiscb-radius-sm:     10px;
  --aiscb-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --aiscb-z:             999999;
  --aiscb-width:         380px;
  --aiscb-height:        580px;
  --aiscb-toggle-size:   58px;
}

/* ── Root Container ─────────────────────────────────────────── */
#aiscb-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--aiscb-z);
  font-family: var(--aiscb-font);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Toggle Button ──────────────────────────────────────────── */
#aiscb-toggle {
  position: relative;
  width: var(--aiscb-toggle-size);
  height: var(--aiscb-toggle-size);
  border-radius: 50%;
  background: var(--aiscb-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  color: #fff;
}

#aiscb-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(37, 99, 235, 0.55);
  background: var(--aiscb-primary-dark);
}

#aiscb-toggle svg {
  width: 26px;
  height: 26px;
}

#aiscb-toggle .aiscb-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: aiscb-pulse 1.5s infinite;
}

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

/* ── Chat Window ────────────────────────────────────────────── */
#aiscb-window {
  position: absolute;
  bottom: calc(var(--aiscb-toggle-size) + 12px);
  right: 0;
  width: var(--aiscb-width);
  height: var(--aiscb-height);
  background: var(--aiscb-surface);
  border-radius: var(--aiscb-radius);
  box-shadow: var(--aiscb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: aiscb-open 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes aiscb-open {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ─────────────────────────────────────────────────── */
.aiscb-header {
  background: var(--aiscb-primary);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  flex-shrink: 0;
}

.aiscb-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.aiscb-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.aiscb-avatar svg {
  width: 22px;
  height: 22px;
}

.aiscb-bot-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.aiscb-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
}

.aiscb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: aiscb-blink 2s infinite;
}

@keyframes aiscb-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.aiscb-header-actions {
  display: flex;
  gap: 6px;
}

.aiscb-btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.aiscb-btn-icon:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ── Lead Capture Form ──────────────────────────────────────── */
#aiscb-lead-form {
  flex: 1;
  background: var(--aiscb-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.aiscb-lead-inner {
  text-align: center;
  max-width: 280px;
}

.aiscb-lead-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.aiscb-lead-inner h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--aiscb-text);
  margin: 0 0 8px;
}

.aiscb-lead-inner p {
  font-size: 13px;
  color: var(--aiscb-text-muted);
  margin: 0 0 20px;
}

.aiscb-field {
  margin-bottom: 12px;
}

.aiscb-field input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--aiscb-border);
  border-radius: var(--aiscb-radius-sm);
  font-size: 14px;
  font-family: var(--aiscb-font);
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.aiscb-field input:focus {
  border-color: var(--aiscb-primary);
}

.aiscb-btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--aiscb-primary);
  color: #fff;
  border: none;
  border-radius: var(--aiscb-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: var(--aiscb-font);
}

.aiscb-btn-primary:hover   { background: var(--aiscb-primary-dark); }
.aiscb-btn-primary:active  { transform: scale(0.98); }

.aiscb-privacy {
  font-size: 11px;
  color: var(--aiscb-text-muted);
  margin-top: 12px;
}

/* ── Messages ───────────────────────────────────────────────── */
#aiscb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--aiscb-bg);
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#aiscb-messages::-webkit-scrollbar       { width: 4px; }
#aiscb-messages::-webkit-scrollbar-track { background: transparent; }
#aiscb-messages::-webkit-scrollbar-thumb { background: var(--aiscb-border); border-radius: 4px; }

/* Message bubble wrapper */
.aiscb-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 85%;
  animation: aiscb-msg-in 0.2s ease;
}

@keyframes aiscb-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.aiscb-msg.aiscb-bot  { align-self: flex-start; }
.aiscb-msg.aiscb-user { align-self: flex-end; flex-direction: row-reverse; }

.aiscb-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--aiscb-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.aiscb-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}

.aiscb-bot .aiscb-bubble {
  background: var(--aiscb-bot-bubble);
  color: var(--aiscb-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.aiscb-user .aiscb-bubble {
  background: var(--aiscb-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.aiscb-msg-time {
  font-size: 10px;
  color: var(--aiscb-text-muted);
  margin-top: 3px;
  text-align: right;
}

.aiscb-bot .aiscb-msg-time  { text-align: left; }
.aiscb-user .aiscb-msg-time { text-align: right; }

/* ── Typing Indicator ───────────────────────────────────────── */
.aiscb-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: var(--aiscb-bot-bubble);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  width: fit-content;
}

.aiscb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aiscb-text-muted);
  animation: aiscb-typing 1.2s infinite;
}

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

@keyframes aiscb-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Suggested Questions ────────────────────────────────────── */
#aiscb-suggestions {
  padding: 8px 14px 4px;
  background: var(--aiscb-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.aiscb-chip {
  background: var(--aiscb-surface);
  border: 1.5px solid var(--aiscb-primary);
  color: var(--aiscb-primary);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--aiscb-font);
  white-space: nowrap;
}

.aiscb-chip:hover {
  background: var(--aiscb-primary);
  color: #fff;
  transform: translateY(-1px);
}

/* ── Input Area ─────────────────────────────────────────────── */
.aiscb-input-area {
  padding: 10px 12px 12px;
  background: var(--aiscb-surface);
  border-top: 1px solid var(--aiscb-border);
  flex-shrink: 0;
}

.aiscb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--aiscb-bg);
  border: 1.5px solid var(--aiscb-border);
  border-radius: 24px;
  padding: 6px 6px 6px 12px;
  transition: border-color 0.15s;
}

.aiscb-input-row:focus-within {
  border-color: var(--aiscb-primary);
}

#aiscb-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 14px;
  font-family: var(--aiscb-font);
  color: var(--aiscb-text);
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.5;
  padding: 2px 0;
}

#aiscb-input::placeholder { color: var(--aiscb-text-muted); }

#aiscb-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--aiscb-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

#aiscb-send:hover  { background: var(--aiscb-primary-dark); }
#aiscb-send:active { transform: scale(0.92); }
#aiscb-send:disabled { opacity: 0.5; cursor: not-allowed; }

.aiscb-voice {
  color: var(--aiscb-text-muted) !important;
  flex-shrink: 0;
}

.aiscb-voice.aiscb-recording {
  color: #ef4444 !important;
  animation: aiscb-pulse 0.8s infinite;
}

.aiscb-footer-note {
  text-align: center;
  font-size: 10px;
  color: var(--aiscb-text-muted);
  margin-top: 7px;
}

/* ── Error / System Messages ────────────────────────────────── */
.aiscb-sys-msg {
  text-align: center;
  font-size: 12px;
  color: var(--aiscb-text-muted);
  background: rgba(0,0,0,0.04);
  border-radius: 20px;
  padding: 4px 14px;
  align-self: center;
}

.aiscb-error-bubble {
  background: #fef2f2 !important;
  color: #dc2626 !important;
  border: 1px solid #fecaca !important;
}

/* ── Inline Shortcode Widget ────────────────────────────────── */
.aiscb-inline-widget {
  width: 100%;
  border-radius: var(--aiscb-radius);
  overflow: hidden;
  box-shadow: var(--aiscb-shadow);
  position: relative;
}

/* ── Mobile Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  #aiscb-root {
    bottom: 16px;
    right: 16px;
  }

  #aiscb-window {
    width: calc(100vw - 24px);
    height: calc(100svh - 100px);
    right: -8px;
    bottom: calc(var(--aiscb-toggle-size) + 8px);
    max-height: 600px;
    border-radius: 16px;
  }
}

/* ── Markdown formatting inside bubbles ─────────────────────── */
.aiscb-bubble strong { font-weight: 600; }
.aiscb-bubble em     { font-style: italic; }
.aiscb-bubble ul     { margin: 6px 0 0 16px; padding: 0; }
.aiscb-bubble li     { margin-bottom: 3px; }
.aiscb-bubble a      { color: var(--aiscb-primary); }
.aiscb-user .aiscb-bubble a { color: #bfdbfe; }
