/* ═══════════════════════════════════════════════
   CUBO — Maths Tutor Chat Widget
   ═══════════════════════════════════════════════ */

/* ── Trigger bubble ─────────────────────────────── */
#cubo-trigger {
  position: fixed;
  bottom: 166px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

#cubo-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(124, 58, 237, 0.55);
}

#cubo-trigger:active {
  transform: scale(0.96);
}

#cubo-trigger svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: opacity 0.15s;
}

#cubo-trigger .cubo-icon-close {
  display: none;
}

#cubo-trigger.is-open .cubo-icon-chat {
  display: none;
}

#cubo-trigger.is-open .cubo-icon-close {
  display: block;
}

/* ── Unread badge ───────────────────────────────── */
#cubo-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #EF4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  line-height: 1;
}

#cubo-badge.visible {
  display: flex;
}

/* ── Chat panel ─────────────────────────────────── */
#cubo-panel {
  position: fixed;
  bottom: 166px;
  right: 28px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9997;
  transform: scale(0.92) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.18s ease;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#cubo-panel.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────── */
#cubo-header {
  background: linear-gradient(135deg, #7C3AED 0%, #4F46E5 100%);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.cubo-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
}

.cubo-header-info {
  flex: 1;
  min-width: 0;
}

.cubo-header-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  line-height: 1.2;
}

.cubo-header-status {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 5px;
}

.cubo-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34D399;
  display: inline-block;
  flex-shrink: 0;
}

.cubo-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: background 0.15s;
  outline: none;
}

.cubo-close-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.cubo-close-btn svg {
  width: 14px;
  height: 14px;
  fill: #fff;
}

/* ── Messages area ──────────────────────────────── */
#cubo-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

#cubo-messages::-webkit-scrollbar {
  width: 4px;
}

#cubo-messages::-webkit-scrollbar-track {
  background: transparent;
}

#cubo-messages::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 4px;
}

/* ── Message bubbles ────────────────────────────── */
.cubo-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: cuboFadeUp 0.2s ease;
}

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

.cubo-msg.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.cubo-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.855rem;
  line-height: 1.55;
  word-break: break-word;
}

.cubo-msg.user .cubo-bubble {
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.cubo-msg.bot .cubo-bubble {
  background: #F3F4F6;
  color: #111827;
  border-bottom-left-radius: 4px;
}

.cubo-bubble br {
  display: block;
  content: '';
  margin-top: 4px;
}

/* KaTeX overrides inside bubbles */
.cubo-bubble .katex {
  font-size: 1em;
}

.cubo-bubble .katex-display {
  margin: 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.cubo-msg.user .cubo-bubble .katex {
  color: #fff;
}

.cubo-msg.user .cubo-bubble .katex-html {
  color: #fff;
}

.cubo-msg-time {
  font-size: 0.68rem;
  color: #9CA3AF;
  margin-top: 3px;
  padding: 0 4px;
}

/* ── Typing indicator ───────────────────────────── */
#cubo-typing {
  display: none;
  align-self: flex-start;
  padding: 10px 14px;
  background: #F3F4F6;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  gap: 5px;
  align-items: center;
  animation: cuboFadeUp 0.2s ease;
}

#cubo-typing.visible {
  display: flex;
}

.cubo-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9CA3AF;
  animation: cuboBounce 1.2s ease-in-out infinite;
}

.cubo-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.cubo-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

@keyframes cuboFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Welcome message ────────────────────────────── */
#cubo-welcome {
  text-align: center;
  padding: 20px 12px 8px;
  flex-shrink: 0;
}

#cubo-welcome p {
  font-size: 0.78rem;
  color: #6B7280;
  margin: 0;
  line-height: 1.5;
}

#cubo-welcome strong {
  display: block;
  font-size: 0.88rem;
  color: #374151;
  margin-bottom: 4px;
}

/* ── Divider ────────────────────────────────────── */
.cubo-divider {
  border: none;
  border-top: 1px solid #F3F4F6;
  margin: 0;
  flex-shrink: 0;
}

/* ── Input area ─────────────────────────────────── */
#cubo-input-area {
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: #fff;
}

#cubo-input {
  flex: 1;
  border: 1.5px solid #E5E7EB;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 0.855rem;
  font-family: inherit;
  color: #111827;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.45;
  transition: border-color 0.15s;
  overflow-y: auto;
}

#cubo-input:focus {
  border-color: #7C3AED;
}

#cubo-input::placeholder {
  color: #9CA3AF;
}

#cubo-input:disabled {
  background: #F9FAFB;
  color: #6B7280;
}

#cubo-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2563EB;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  outline: none;
}

#cubo-send:hover:not(:disabled) {
  background: #1D4ED8;
}

#cubo-send:active:not(:disabled) {
  transform: scale(0.93);
}

#cubo-send:disabled {
  background: #93C5FD;
  cursor: not-allowed;
}

#cubo-send svg {
  width: 16px;
  height: 16px;
  fill: #fff;
  margin-left: 2px;
}

/* ── Error banner ───────────────────────────────── */
#cubo-error {
  display: none;
  background: #FEF2F2;
  border-top: 1px solid #FECACA;
  color: #B91C1C;
  font-size: 0.78rem;
  padding: 8px 14px;
  text-align: center;
  flex-shrink: 0;
}

#cubo-error.visible {
  display: block;
}

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
  #cubo-panel {
    bottom: 0;
    right: 0;
    width: 100%;
    height: 90dvh;
    border-radius: 20px 20px 0 0;
    max-height: 640px;
  }

  #cubo-trigger {
    bottom: 88px;
    right: 18px;
  }
}
