/* ====== SOFIA WIDGET ====== */

/* Toggle Button */
.cb-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(108,92,231,0.4), 0 0 40px rgba(0,210,255,0.15);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.cb-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 30px rgba(108,92,231,0.5), 0 0 60px rgba(0,210,255,0.25);
}
.cb-toggle svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.cb-toggle .cb-icon-close {
  position: absolute;
  transform: rotate(90deg) scale(0);
  opacity: 0;
}
.cb-toggle.open .cb-icon-chat { transform: rotate(-90deg) scale(0); opacity: 0; }
.cb-toggle.open .cb-icon-close { transform: rotate(0) scale(1); opacity: 1; }

/* Unread Badge */
.cb-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #ff4757;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family);
  opacity: 0;
  transform: scale(0);
  transition: all var(--transition-fast);
}
.cb-badge.visible { opacity: 1; transform: scale(1); }

/* Panel */
.cb-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 400px;
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(108,92,231,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.cb-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.cb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.cb-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.cb-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cb-header-info { flex: 1; min-width: 0; }
.cb-header-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.cb-header-status {
  font-size: 0.75rem;
  color: #20e3b2;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cb-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #20e3b2;
  display: inline-block;
}
.cb-header-actions {
  display: flex;
  gap: 4px;
}
.cb-header-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.cb-header-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}
.cb-header-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* Messages Area */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

/* Message Bubbles */
.cb-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
  animation: cbMsgIn 0.25s ease;
}
@keyframes cbMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.cb-msg-user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.cb-msg-assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

/* Markdown inside messages */
.cb-msg-assistant p { margin: 0 0 8px; }
.cb-msg-assistant p:last-child { margin-bottom: 0; }
.cb-msg-assistant strong { color: var(--text-primary); font-weight: 600; }
.cb-msg-assistant a { color: var(--accent-2); text-decoration: underline; }
.cb-msg-assistant .cb-code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.5;
}
.cb-msg-assistant .cb-code-block code { font-family: 'SF Mono', 'Fira Code', monospace; }
.cb-msg-assistant .cb-inline-code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.cb-msg-assistant .cb-list { padding-left: 20px; margin: 4px 0; }
.cb-msg-assistant .cb-list li { margin: 2px 0; }
.cb-msg-assistant ul.cb-list { list-style: disc; }
.cb-msg-assistant ol.cb-list { list-style: decimal; }
.cb-msg-assistant .cb-heading { font-size: 0.9375rem; font-weight: 700; margin: 8px 0 4px; }

/* Streaming Cursor */
.cb-cursor {
  display: inline-block;
  width: 7px;
  height: 16px;
  background: var(--accent-2);
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cbBlink 0.8s step-end infinite;
}
@keyframes cbBlink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Typing Indicator */
.cb-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}
.cb-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: cbBounce 1.4s ease-in-out infinite;
}
.cb-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.cb-typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes cbBounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Error Banner */
.cb-error {
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: rgba(255,71,87,0.1);
  border: 1px solid rgba(255,71,87,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: #ff6b7a;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: cbMsgIn 0.25s ease;
}
.cb-error-dismiss {
  margin-left: auto;
  color: #ff6b7a;
  opacity: 0.6;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
}
.cb-error-dismiss:hover { opacity: 1; }

/* Input Area */
.cb-input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.cb-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 10px 14px;
  font-family: var(--font-family);
  font-size: 0.875rem;
  line-height: 1.5;
  max-height: 120px;
  min-height: 42px;
  outline: none;
  transition: border-color var(--transition-fast);
}
.cb-textarea::placeholder { color: var(--text-muted); }
.cb-textarea:focus { border-color: var(--accent-1); }
.cb-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.cb-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cb-send-btn:not(:disabled):hover { transform: scale(1.05); }
.cb-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* Welcome Message */
.cb-welcome {
  text-align: center;
  padding: 24px 16px 8px;
}
.cb-welcome-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 12px;
}
.cb-welcome-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cb-welcome-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}
.cb-welcome-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.cb-welcome-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Mobile */
@media (max-width: 480px) {
  .cb-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    transform: translateY(100%);
  }
  .cb-panel.open { transform: translateY(0); }
  .cb-toggle { bottom: 16px; right: 16px; width: 56px; height: 56px; }
}

/* Powered by footer */
.cb-powered {
  text-align: center;
  padding: 6px 16px 10px;
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: var(--bg-card);
}
.cb-powered a {
  color: var(--accent-2);
  text-decoration: none;
}
.cb-powered a:hover { text-decoration: underline; }
