/* NOVA Chatbot — Floating Bubble UI
   Matches dark theme + leading-product UX (Linear / Claude.ai / Perplexity)
   2026-05-26
*/

:root {
  --cb-bg: rgba(20, 14, 40, 0.94);
  --cb-bg-elevated: rgba(30, 22, 56, 0.94);
  --cb-border: rgba(255, 255, 255, 0.08);
  --cb-border-strong: rgba(255, 255, 255, 0.18);
  --cb-ink: rgba(255, 255, 255, 0.92);
  --cb-ink-2: rgba(255, 255, 255, 0.62);
  --cb-ink-3: rgba(255, 255, 255, 0.38);
  --cb-accent: rgba(255, 210, 110, 1);
  --cb-accent-dim: rgba(255, 210, 110, 0.45);
  --cb-user: rgba(70, 140, 255, 0.18);
  --cb-user-border: rgba(70, 140, 255, 0.32);
  --cb-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ─── Floating bubble (collapsed state) ─────────────────────────────── */
#cb-bubble {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd26e 0%, #ff8c5a 50%, #c45ec6 100%);
  box-shadow: 0 12px 28px rgba(255, 140, 90, 0.35), 0 4px 12px rgba(196, 94, 198, 0.25);
  cursor: pointer;
  z-index: 2147483646;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s;
  border: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#cb-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 16px 36px rgba(255, 140, 90, 0.45), 0 6px 16px rgba(196, 94, 198, 0.35);
}
#cb-bubble:active { transform: scale(0.96); }
#cb-bubble svg { width: 26px; height: 26px; color: #1a0b2e; }
#cb-bubble[data-open="true"] { display: none; }

/* Notification pulse */
#cb-bubble::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 210, 110, 0.5);
  opacity: 0;
  animation: cb-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes cb-pulse {
  0%   { opacity: 0.7; transform: scale(1); }
  70%  { opacity: 0;   transform: scale(1.35); }
  100% { opacity: 0;   transform: scale(1.35); }
}

/* ─── Chat panel (expanded state) ───────────────────────────────────── */
#cb-panel {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 60px);
  background: var(--cb-bg);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-radius: 18px;
  border: 1px solid var(--cb-border-strong);
  box-shadow: var(--cb-shadow);
  z-index: 2147483646;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--cb-ink);
  transform-origin: bottom right;
  animation: cb-open 0.28s cubic-bezier(0.34, 1.32, 0.64, 1);
}
@keyframes cb-open {
  0%   { opacity: 0; transform: scale(0.7) translateY(20px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
#cb-panel[data-open="true"] { display: flex; }

/* Header */
.cb-header {
  flex-shrink: 0;
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--cb-border);
  background: linear-gradient(180deg, rgba(255, 210, 110, 0.06) 0%, transparent 100%);
}
.cb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd26e 0%, #ff8c5a 50%, #c45ec6 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #1a0b2e;
  flex-shrink: 0;
}
.cb-titlewrap { flex: 1; min-width: 0; }
.cb-title {
  font-size: 14px; font-weight: 600; letter-spacing: 0.01em;
  color: var(--cb-ink); line-height: 1.2;
}
.cb-subtitle {
  font-size: 11px; color: var(--cb-ink-3);
  margin-top: 2px; font-weight: 500;
}
.cb-subtitle .cb-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: #34d399;
  margin-right: 5px; vertical-align: middle;
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.7);
}
.cb-close {
  background: transparent; border: none;
  color: var(--cb-ink-2); cursor: pointer;
  padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.cb-close:hover { background: rgba(255, 255, 255, 0.06); color: var(--cb-ink); }
.cb-close svg { width: 18px; height: 18px; }

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

.cb-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
  animation: cb-slide-in 0.22s ease-out;
}
@keyframes cb-slide-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cb-msg-user {
  align-self: flex-end;
  background: var(--cb-user);
  border: 1px solid var(--cb-user-border);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 13px;
  color: var(--cb-ink);
  line-height: 1.5;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.cb-msg-bot {
  align-self: flex-start;
  background: var(--cb-bg-elevated);
  border: 1px solid var(--cb-border);
  border-radius: 14px 14px 14px 4px;
  padding: 11px 14px;
  color: var(--cb-ink);
  line-height: 1.6;
  font-size: 13.5px;
  word-wrap: break-word;
  max-width: 92%;
}
.cb-msg-bot.cb-streaming::after {
  content: "▋";
  color: var(--cb-accent);
  animation: cb-cursor 0.85s infinite;
  margin-left: 2px;
}
@keyframes cb-cursor { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* Markdown rendered inside bot messages */
.cb-msg-bot p { margin: 0 0 8px 0; }
.cb-msg-bot p:last-child { margin-bottom: 0; }
.cb-msg-bot ul, .cb-msg-bot ol { margin: 6px 0 8px 0; padding-left: 22px; }
.cb-msg-bot li { margin: 2px 0; }
.cb-msg-bot strong { color: var(--cb-ink); font-weight: 600; }
.cb-msg-bot em { color: var(--cb-ink-2); font-style: italic; }
.cb-msg-bot code {
  font-family: "SF Mono", "Consolas", "Courier New", monospace;
  font-size: 12.5px;
  background: rgba(255, 210, 110, 0.10);
  color: rgba(255, 210, 110, 0.95);
  padding: 1px 5px;
  border-radius: 4px;
}
.cb-msg-bot pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  position: relative;
}
.cb-msg-bot pre code {
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  padding: 0;
  font-size: 12px;
  line-height: 1.5;
}
.cb-copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--cb-border);
  color: var(--cb-ink-2);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.cb-copy-btn:hover { background: rgba(255, 255, 255, 0.10); color: var(--cb-ink); }
.cb-copy-btn[data-copied="true"] { color: #34d399; border-color: rgba(52, 211, 153, 0.4); }

.cb-msg-bot a {
  color: var(--cb-accent);
  text-decoration: none;
  border-bottom: 1px dashed var(--cb-accent-dim);
}
.cb-msg-bot a:hover { border-bottom-style: solid; }

.cb-msg-bot table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
  width: 100%;
}
.cb-msg-bot th, .cb-msg-bot td {
  border: 1px solid var(--cb-border);
  padding: 5px 8px;
  text-align: left;
}
.cb-msg-bot th {
  background: rgba(255, 210, 110, 0.06);
  color: var(--cb-ink);
  font-weight: 600;
}

/* Citations row */
.cb-citations {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.cb-citation {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 10.5px;
  color: var(--cb-ink-2);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--cb-border);
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cb-citation:hover { background: rgba(255, 255, 255, 0.08); color: var(--cb-ink); }

/* Status indicator */
.cb-status {
  align-self: flex-start;
  color: var(--cb-ink-3);
  font-size: 11.5px;
  font-style: italic;
  padding: 4px 12px;
  animation: cb-fade-pulse 1.6s ease-in-out infinite;
}
@keyframes cb-fade-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.85; } }

/* Empty state / suggestions */
.cb-empty {
  padding: 20px 8px 8px;
  text-align: center;
  color: var(--cb-ink-2);
}
.cb-empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--cb-ink);
  margin-bottom: 6px;
}
.cb-empty-sub {
  font-size: 12.5px;
  margin-bottom: 18px;
  line-height: 1.5;
}
.cb-suggest-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 4px;
}
.cb-suggest {
  background: var(--cb-bg-elevated);
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 12px;
  color: var(--cb-ink-2);
  text-align: left;
  cursor: pointer;
  line-height: 1.4;
  transition: all 0.15s;
  font-family: inherit;
}
.cb-suggest:hover {
  border-color: var(--cb-accent-dim);
  background: rgba(255, 210, 110, 0.08);
  color: var(--cb-ink);
  transform: translateY(-1px);
}

/* Input area */
.cb-input-wrap {
  flex-shrink: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-bg);
}
.cb-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--cb-bg-elevated);
  border: 1px solid var(--cb-border);
  border-radius: 12px;
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.cb-input-row:focus-within { border-color: var(--cb-accent-dim); }
#cb-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cb-ink);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  max-height: 120px;
  min-height: 22px;
  padding: 2px 0;
}
#cb-input::placeholder { color: var(--cb-ink-3); }
.cb-send {
  flex-shrink: 0;
  background: linear-gradient(135deg, #ffd26e, #ff8c5a);
  border: none;
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s;
}
.cb-send:hover { transform: scale(1.05); }
.cb-send:active { transform: scale(0.94); }
.cb-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.cb-send svg { width: 16px; height: 16px; color: #1a0b2e; }
.cb-footer {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--cb-ink-3);
}
.cb-shortcut { font-family: "SF Mono", "Consolas", monospace; }
.cb-shortcut kbd {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--cb-border);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  color: var(--cb-ink-2);
}

/* Mobile responsive */
@media (max-width: 540px) {
  #cb-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 90px);
    bottom: 80px; right: 8px;
    border-radius: 14px;
  }
  #cb-bubble { bottom: 14px; right: 14px; width: 54px; height: 54px; }
}

/* Prevent host page from leaking into our UI */
#cb-bubble *, #cb-panel * { box-sizing: border-box; }


/* New-chat button (added v2) */
.cb-newchat {
  background: transparent; border: none;
  color: var(--cb-ink-2); cursor: pointer;
  padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-right: 2px;
  transition: background 0.12s, color 0.12s, transform 0.12s;
}
.cb-newchat:hover { background: rgba(255,210,110,0.10); color: var(--cb-accent); transform: rotate(-12deg) scale(1.05); }
.cb-newchat svg { width: 16px; height: 16px; }
