/* ===================================================================
   URSA Chatbot – Premium Dark Theme with Glassmorphism
   =================================================================== */

/* ---------- Reset & Tokens ---------- */
:root {
  --bg-dark: #0a0e27;
  --bg-card: rgba(15, 20, 50, 0.85);
  --bg-input: rgba(30, 41, 59, 0.7);
  --bg-bot-bubble: #1e293b;
  --bg-user-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --accent: #6366f1;
  --accent-light: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: rgba(148, 163, 184, 0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-lg: 0 25px 60px rgba(0, 0, 0, 0.55);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-dark);
  min-height: 100vh;
}

/* ---------- Demo page (remove when embedding) ---------- */
.demo-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 30% 20%, rgba(99,102,241,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(139,92,246,0.1) 0%, transparent 50%),
              var(--bg-dark);
}
.demo-hero {
  text-align: center;
  max-width: 600px;
  padding: 2rem;
}
.demo-hero h1 {
  font-size: 2.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}
.demo-hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}
.demo-hint {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  color: #a5b4fc;
  animation: gentle-pulse 2.5s ease-in-out infinite;
}

/* ---------- Chatbot Container ---------- */
#ursa-chatbot {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  font-family: var(--font);
}

/* ---------- Toggle Button ---------- */
#chat-toggle {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--bg-user-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 30px var(--accent-glow),
              0 2px 8px rgba(0,0,0,0.3);
  transition: transform var(--transition), box-shadow var(--transition);
  animation: pulse-ring 3s ease-out infinite;
  z-index: 2;
}
#chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px var(--accent-glow),
              0 4px 12px rgba(0,0,0,0.4);
}
#chat-toggle:active { transform: scale(0.95); }

#chat-toggle .hidden { display: none; }

#chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ef4444;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-dark);
  animation: badge-pop 0.3s ease;
}
#chat-badge.hidden { display: none; }

@keyframes pulse-ring {
  0% { box-shadow: 0 8px 30px var(--accent-glow), 0 0 0 0 rgba(99,102,241,0.35); }
  50% { box-shadow: 0 8px 30px var(--accent-glow), 0 0 0 14px rgba(99,102,241,0); }
  100% { box-shadow: 0 8px 30px var(--accent-glow), 0 0 0 0 rgba(99,102,241,0); }
}
@keyframes badge-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ---------- Chat Window ---------- */
#chat-window {
  position: absolute;
  bottom: 78px;
  right: 0;
  width: 400px;
  height: 560px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease;
}
#chat-window.chat-closed {
  transform: scale(0.5) translateY(20px);
  opacity: 0;
  pointer-events: none;
}
#chat-window.chat-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Header ---------- */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(139,92,246,0.1));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-user-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
#chat-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
#chat-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
#chat-close:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text-primary);
}

/* ---------- Messages Area ---------- */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(148,163,184,0.2);
  border-radius: 10px;
}

/* Bubbles */
.msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.55;
  animation: msg-slide 0.35s ease;
  word-break: break-word;
}
.msg a {
  color: #a5b4fc;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg a:hover { color: #c4b5fd; }

.msg.bot {
  align-self: flex-start;
  background: var(--bg-bot-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.msg.user {
  align-self: flex-end;
  background: var(--bg-user-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

@keyframes msg-slide {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  align-self: flex-start;
  background: var(--bg-bot-bubble);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  animation: msg-slide 0.3s ease;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Quick Replies ---------- */
#quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 10px;
  flex-shrink: 0;
}
#quick-replies:empty { display: none; }

.quick-btn {
  padding: 7px 14px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(99,102,241,0.35);
  background: rgba(99,102,241,0.08);
  color: #a5b4fc;
  font-size: 0.78rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  animation: msg-slide 0.3s ease;
}
.quick-btn:hover {
  background: rgba(99,102,241,0.2);
  border-color: rgba(99,102,241,0.55);
  color: #c7d2fe;
}

/* ---------- Input Bar ---------- */
#chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: rgba(15, 20, 50, 0.6);
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#chat-input::placeholder { color: var(--text-muted); }
#chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--bg-user-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition), box-shadow var(--transition);
}
#chat-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px var(--accent-glow);
}
#chat-send:active { transform: scale(0.92); }

/* ---------- Utility ---------- */
.hidden { display: none !important; }

@keyframes gentle-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  #chat-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    bottom: 74px;
    right: -14px;
    border-radius: var(--radius-md);
  }
  #ursa-chatbot { right: 16px; bottom: 16px; }
  .demo-hero h1 { font-size: 1.8rem; }
}
