/* ── QuantumAI Chat Widget ───────────────────────────────────────────────────── */

#quantumai-bubble {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 9200;
  width: 54px;
  height: 54px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 22px rgba(37,99,235,0.35), 0 2px 8px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  color: #fff;
  flex-shrink: 0;
}

#quantumai-bubble:hover {
  transform: scale(1.09);
  box-shadow: 0 6px 30px rgba(37,99,235,0.45), 0 2px 8px rgba(0,0,0,0.25);
}

#quantumai-bubble:active {
  transform: scale(0.96);
}

/* Panel */
#quantumai-panel {
  position: fixed;
  bottom: 1.75rem;
  right: 1.75rem;
  z-index: 9300;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 560px;
  max-height: calc(100svh - 2.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#quantumai-panel.open {
  display: flex;
  animation: sai-slide-in 0.22s cubic-bezier(0.34,1.3,0.64,1);
}

@keyframes sai-slide-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* Resize handle */
#sai-resize {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  cursor: nw-resize;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border2);
  font-size: 11px;
  line-height: 1;
  border-radius: 17px 0 4px 0;
  transition: color 0.15s;
}
#sai-resize:hover { color: var(--text-muted); }

/* Header */
.sai-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.sai-header-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  color: #fff;
}

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

.sai-header-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sai-header-sub {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--positive);
  margin-top: 0.1rem;
  display: block;
}

.sai-clear-btn {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.22rem 0.55rem;
  font-size: 0.62rem;
  font-family: inherit;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.sai-clear-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.sai-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.3rem;
  border-radius: 5px;
  transition: color 0.15s;
  line-height: 1;
  flex-shrink: 0;
}

.sai-close-btn:hover {
  color: var(--text-primary);
}

/* Messages */
.sai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

/* Upsell */
.sai-upsell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.25rem 1.5rem 1.5rem;
  height: 100%;
  gap: 0.7rem;
}

.sai-upsell-icon { font-size: 2.4rem; }

.sai-upsell-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sai-upsell-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 270px;
}

.sai-upsell-features {
  list-style: none;
  text-align: left;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.8;
  margin: 0.25rem 0;
}

.sai-upsell-features li::before {
  content: '✓ ';
  color: var(--positive);
  font-weight: 700;
}

.sai-upsell-btn {
  margin-top: 0.5rem;
  background: linear-gradient(135deg, #FFB800, #FF8C00);
  border: none;
  border-radius: 10px;
  color: #000;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 0.7rem 1.6rem;
  transition: opacity 0.15s;
  width: 100%;
}

.sai-upsell-btn:hover { opacity: 0.88; }

/* Context badge */
.sai-ctx-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  background: var(--accent-subtle);
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: 20px;
  font-size: 0.63rem;
  color: var(--accent);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-self: flex-start;
}

/* Message bubbles */
.sai-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.sai-msg.user  { align-self: flex-end; align-items: flex-end; }
.sai-msg.ai    { align-self: flex-start; align-items: flex-start; }
.sai-msg.error { align-self: flex-start; align-items: flex-start; }

.sai-bubble {
  padding: 0.58rem 0.85rem;
  border-radius: 14px;
  font-size: 0.79rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.sai-msg.user .sai-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.sai-msg.ai .sai-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.sai-msg.error .sai-bubble {
  background: var(--negative-subtle);
  border: 1px solid rgba(220,38,38,0.2);
  color: var(--negative);
  border-bottom-left-radius: 4px;
}

/* Markdown content inside AI bubbles */
.sai-msg.ai .sai-bubble p { margin: 0 0 6px 0; }
.sai-msg.ai .sai-bubble p:last-child { margin-bottom: 0; }
.sai-msg.ai .sai-bubble h1,
.sai-msg.ai .sai-bubble h2,
.sai-msg.ai .sai-bubble h3 {
  font-size: 1em; font-weight: 700; color: var(--text-primary);
  margin: 6px 0 4px 0; line-height: 1.3;
}
.sai-msg.ai .sai-bubble ul,
.sai-msg.ai .sai-bubble ol { margin: 4px 0 6px 0; padding-left: 18px; }
.sai-msg.ai .sai-bubble li { margin: 2px 0; line-height: 1.5; }
.sai-msg.ai .sai-bubble code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.73rem;
  background: var(--bg-tertiary);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  color: var(--accent);
}
.sai-msg.ai .sai-bubble pre {
  background: var(--bg-tertiary);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  overflow-x: auto;
  margin: 0.35rem 0;
}
.sai-msg.ai .sai-bubble pre code { background: none; padding: 0; color: var(--text-secondary); }
.sai-msg.ai .sai-bubble strong { font-weight: 700; color: var(--text-primary); }
.sai-msg.ai .sai-bubble em { font-style: italic; }
.sai-msg.ai .sai-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.sai-msg.ai .sai-bubble blockquote {
  border-left: 2px solid var(--border2);
  margin: 0.3rem 0; padding-left: 0.7rem; color: var(--text-muted);
}
.sai-msg.ai .sai-bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.45rem 0; }

/* AI bubbles use rendered HTML */
.sai-msg.ai .sai-bubble { white-space: normal; }

/* Starter chips */
.sai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 0 4px;
}

.sai-chip {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.4;
  padding: 0.26rem 0.72rem;
  text-align: left;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sai-chip:hover {
  background: var(--accent-subtle);
  border-color: rgba(37,99,235,0.4);
  color: var(--text-primary);
}

/* Bubble action row */
.sai-bubble-actions {
  display: flex;
  justify-content: flex-end;
  padding: 2px 4px 0;
}

.sai-copy-btn {
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  line-height: 1;
  padding: 3px 4px;
  transition: color 0.15s;
}

.sai-copy-btn:hover { color: var(--text-muted); }
.sai-copy-btn.sai-copy-copied { color: var(--positive); }

/* Typing indicator */
.sai-typing {
  align-self: flex-start;
  padding: 0.55rem 0.85rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.71rem;
  color: var(--text-muted);
}

.sai-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.sai-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: sai-dot 1.3s ease-in-out infinite;
}

.sai-dots span:nth-child(2) { animation-delay: 0.18s; }
.sai-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes sai-dot {
  0%, 75%, 100% { transform: scale(0.55); opacity: 0.3; }
  38% { transform: scale(1); opacity: 1; }
}

/* Usage bar */
.sai-usage {
  padding: 0.28rem 0.75rem;
  font-size: 0.6rem;
  color: var(--text-dim);
  text-align: right;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
}

/* Input */
.sai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.6rem 0.7rem 0.7rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

#sai-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.52rem 0.75rem;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 116px;
  line-height: 1.5;
  transition: border-color 0.15s;
  overflow-y: auto;
}

#sai-input:focus { border-color: var(--accent); }
#sai-input::placeholder { color: var(--text-dim); }
#sai-input:disabled { opacity: 0.5; }

#sai-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
  align-self: flex-end;
  color: #fff;
}

#sai-send:hover:not(:disabled) { background: var(--accent-hover); }
#sai-send:disabled { opacity: 0.35; cursor: not-allowed; }

/* Article card "Ask AI" button */
.nc-sai-btn {
  background: none;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.63rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--accent);
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
  user-select: none;
}

.nc-sai-btn:hover { color: var(--accent-hover); }

/* Mobile adjustments */
@media (max-width: 480px) {
  #quantumai-bubble { bottom: 1.25rem; right: 1.25rem; }
  #quantumai-panel {
    bottom: 0; right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 90svh;
    max-height: 90svh;
    border-radius: 18px 18px 0 0;
  }
}
