/* ============================================================
   STUDY BUDDY — style.css
   Modern Dark Theme Chatbot UI
   ============================================================ */

/* ---------- CSS Custom Properties (Design Tokens) ---------- */
:root {
  /* Colors */
  --clr-bg:            #0d0e14;
  --clr-surface:       #13141c;
  --clr-surface-2:     #1a1b27;
  --clr-surface-3:     #22243a;
  --clr-border:        rgba(255, 255, 255, 0.07);
  --clr-border-hover:  rgba(255, 255, 255, 0.14);

  /* Brand */
  --clr-primary:       #7c6aff;
  --clr-primary-light: #9d8fff;
  --clr-primary-glow:  rgba(124, 106, 255, 0.35);
  --clr-secondary:     #00d4aa;
  --clr-accent:        #ff6b9d;

  /* Text */
  --clr-text-primary:  #f0f1fa;
  --clr-text-secondary:#9a9bb8;
  --clr-text-muted:    #5c5e7a;

  /* Gradients */
  --grad-brand:        linear-gradient(135deg, #7c6aff 0%, #5a48d8 100%);
  --grad-hero:         linear-gradient(135deg, #7c6aff 0%, #00d4aa 100%);
  --grad-user-bubble:  linear-gradient(135deg, #7c6aff 0%, #5448e5 100%);
  --grad-bot-surface:  linear-gradient(135deg, #1e203a 0%, #252742 100%);

  /* UI */
  --sidebar-width:     280px;
  --topbar-h:          60px;
  --input-area-h:      90px;
  --radius-sm:         10px;
  --radius-md:         16px;
  --radius-lg:         24px;
  --radius-xl:         32px;
  --radius-full:       9999px;

  /* Shadows */
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:  0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg:  0 16px 48px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 32px var(--clr-primary-glow);

  /* Transitions */
  --ease-out:   cubic-bezier(0.25, 0.8, 0.25, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast:   150ms;
  --dur-mid:    300ms;
  --dur-slow:   500ms;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--clr-bg);
  color: var(--clr-text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

textarea {
  font-family: inherit;
  resize: none;
}

/* ---------- Animated Background Orbs ---------- */
.bg-orb {
  position: fixed;
  border-radius: var(--radius-full);
  filter: blur(80px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
  animation: orbFloat 12s ease-in-out infinite;
}

.orb-1 {
  width: 500px; height: 500px;
  background: var(--clr-primary);
  top: -150px; left: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 400px; height: 400px;
  background: var(--clr-secondary);
  bottom: -100px; right: -80px;
  animation-delay: -4s;
}

.orb-3 {
  width: 300px; height: 300px;
  background: var(--clr-accent);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -8s;
  opacity: 0.06;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(20px, -30px) scale(1.05); }
  66%       { transform: translate(-15px, 15px) scale(0.95); }
}

/* ---------- App Layout ---------- */
.app-wrapper {
  display: flex;
  height: 100dvh;
  position: relative;
  z-index: 1;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: linear-gradient(180deg, #15162099 0%, #0f101899 100%);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-right: 1px solid var(--clr-border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 12px;
  overflow-y: auto;
  transition: transform var(--dur-mid) var(--ease-out),
              opacity var(--dur-mid) var(--ease-out);
  z-index: 100;
}

/* Custom Scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--clr-border-hover);
  border-radius: var(--radius-full);
}

/* ---- Sidebar Header ---- */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 40px; height: 40px;
  background: var(--grad-brand);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px var(--clr-primary-glow);
}

.logo-text {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--grad-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-toggle {
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--clr-text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sidebar-toggle:hover {
  background: var(--clr-surface-3);
  color: var(--clr-text-primary);
}

/* ---- New Chat Button ---- */
.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--grad-brand);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 16px var(--clr-primary-glow);
  transition: transform var(--dur-fast) var(--ease-spring),
              box-shadow var(--dur-fast),
              opacity var(--dur-fast);
}
.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--clr-primary-glow);
}
.new-chat-btn:active { transform: translateY(0); }

/* ---- Section Label ---- */
.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--clr-text-muted);
  padding: 4px 4px 0;
}

/* ---- Quick Questions ---- */
.quick-questions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-q-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  color: var(--clr-text-secondary);
  text-align: left;
  transition: background var(--dur-fast), color var(--dur-fast),
              transform var(--dur-fast) var(--ease-spring);
  border: 1px solid transparent;
}
.quick-q-btn:hover {
  background: var(--clr-surface-3);
  color: var(--clr-text-primary);
  border-color: var(--clr-border);
  transform: translateX(4px);
}

.q-icon {
  font-size: 1rem;
  flex-shrink: 0;
  line-height: 1;
}

/* ---- Sidebar Footer ---- */
.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--clr-border);
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.775rem;
  color: var(--clr-text-muted);
  padding: 6px 8px;
}

.model-dot {
  width: 7px; height: 7px;
  border-radius: var(--radius-full);
  background: var(--clr-secondary);
  box-shadow: 0 0 8px var(--clr-secondary);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

/* ============================================================
   CHAT MAIN
   ============================================================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---- Topbar ---- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  background: rgba(13, 14, 20, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle, .new-chat-icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--clr-text-secondary);
  transition: background var(--dur-fast), color var(--dur-fast);
  flex-shrink: 0;
}
.menu-toggle:hover, .new-chat-icon-btn:hover {
  background: var(--clr-surface-3);
  color: var(--clr-text-primary);
}

/* hide menu toggle on desktop (sidebar always visible) */
.menu-toggle { display: none; }

.topbar-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-text-primary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  background: var(--clr-secondary);
  box-shadow: 0 0 8px var(--clr-secondary);
  animation: pulse 2s ease-in-out infinite;
}

/* ============================================================
   CHAT CONTAINER
   ============================================================ */
.chat-container {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 24px 0;
  position: relative;
}

/* Custom Scrollbar */
.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-full);
}
.chat-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

/* ---- Welcome Screen ---- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 40px;
  text-align: center;
  gap: 16px;
  min-height: calc(100% - 40px);
  animation: fadeSlideUp 0.6s var(--ease-out) both;
}

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

.welcome-avatar {
  position: relative;
  width: 96px; height: 96px;
  margin-bottom: 8px;
}

.avatar-ring {
  position: absolute; inset: 0;
  border-radius: var(--radius-full);
  background: conic-gradient(from 0deg, var(--clr-primary), var(--clr-secondary), var(--clr-accent), var(--clr-primary));
  animation: spin 4s linear infinite;
  padding: 3px;
}

.avatar-ring::before {
  content: '';
  position: absolute; inset: 3px;
  border-radius: var(--radius-full);
  background: var(--clr-bg);
}

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.avatar-inner {
  position: absolute; inset: 6px;
  border-radius: var(--radius-full);
  background: var(--grad-brand);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-glow);
}

.welcome-title {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
  background: var(--grad-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--clr-text-secondary);
  line-height: 1.7;
  max-width: 460px;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border);
  font-size: 0.8rem;
  color: var(--clr-text-secondary);
  letter-spacing: 0.01em;
}

/* ---- Messages Wrapper ---- */
.messages-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Message Row ---- */
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: msgIn 0.35s var(--ease-out) both;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-row.user { flex-direction: row-reverse; }

/* ---- Avatars ---- */
.msg-avatar {
  width: 34px; height: 34px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  margin-top: 4px;
}

.msg-avatar.bot-avatar {
  background: var(--grad-brand);
  box-shadow: 0 2px 10px var(--clr-primary-glow);
}

.msg-avatar.user-avatar {
  background: linear-gradient(135deg, #2d2d3f, #3a3a58);
  border: 1px solid var(--clr-border-hover);
  font-size: 1.1rem;
}

/* ---- Bubbles ---- */
.msg-bubble {
  max-width: min(75%, 600px);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.65;
  position: relative;
}

.msg-row.bot .msg-bubble {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border);
  border-top-left-radius: 4px;
  color: var(--clr-text-primary);
}

.msg-row.user .msg-bubble {
  background: var(--grad-user-bubble);
  border-top-right-radius: 4px;
  color: white;
  box-shadow: 0 4px 16px var(--clr-primary-glow);
}

/* Markdown inside bot bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: 'Outfit', sans-serif;
  margin-bottom: 8px;
  margin-top: 12px;
  color: var(--clr-text-primary);
}
.msg-bubble h1 { font-size: 1.15rem; }
.msg-bubble h2 { font-size: 1.05rem; }
.msg-bubble h3 { font-size: 0.95rem; }

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin-bottom: 8px;
}
.msg-bubble li { margin-bottom: 4px; }

.msg-bubble code {
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85em;
  background: rgba(124, 106, 255, 0.12);
  border: 1px solid rgba(124, 106, 255, 0.2);
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--clr-primary-light);
}

.msg-bubble pre {
  background: #0d0e14;
  border: 1px solid var(--clr-border);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: #c0c5ea;
}

.msg-bubble strong {
  font-weight: 600;
  color: var(--clr-primary-light);
}

.msg-row.user .msg-bubble strong { color: rgba(255,255,255,0.95); }

.msg-bubble blockquote {
  border-left: 3px solid var(--clr-primary);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--clr-text-secondary);
  font-style: italic;
}

.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.85em;
}
.msg-bubble th, .msg-bubble td {
  border: 1px solid var(--clr-border);
  padding: 6px 10px;
  text-align: left;
}
.msg-bubble th {
  background: var(--clr-surface-3);
  font-weight: 600;
}

/* ---- Timestamp ---- */
.msg-time {
  font-size: 0.7rem;
  color: var(--clr-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}
.msg-row.user .msg-time { text-align: right; }

/* ---- Typing / Loading Indicator ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  width: fit-content;
}

.typing-text {
  font-size: 0.85rem;
  color: var(--clr-text-secondary);
  font-style: italic;
}

.typing-dots {
  display: flex; gap: 4px;
}
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: var(--radius-full);
  background: var(--clr-primary);
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1;   }
}

/* ---- Error Message ---- */
.error-bubble {
  background: rgba(255, 80, 80, 0.08) !important;
  border-color: rgba(255, 80, 80, 0.2) !important;
  color: #ff8080 !important;
}

/* ============================================================
   API KEY BANNER
   ============================================================ */
.api-key-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: rgba(255, 170, 0, 0.1);
  border-top: 1px solid rgba(255, 170, 0, 0.2);
  color: #ffbb33;
  font-size: 0.82rem;
}
.api-key-banner[hidden] { display: none; }
.api-key-banner svg { flex-shrink: 0; }

/* ============================================================
   INPUT AREA
   ============================================================ */
.input-area {
  padding: 12px 16px 14px;
  background: rgba(13, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--clr-border);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 18px;
  max-width: 860px;
  margin: 0 auto;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.input-wrapper:focus-within {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-glow), var(--shadow-md);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--clr-text-primary);
  font-size: 0.9rem;
  line-height: 1.6;
  max-height: 180px;
  overflow-y: auto;
  padding: 2px 0;
}

.chat-input::placeholder { color: var(--clr-text-muted); }

.chat-input::-webkit-scrollbar { width: 4px; }
.chat-input::-webkit-scrollbar-thumb {
  background: var(--clr-border-hover);
  border-radius: var(--radius-full);
}

.send-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  background: var(--grad-brand);
  color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--clr-primary-glow);
  transition: transform var(--dur-fast) var(--ease-spring),
              box-shadow var(--dur-fast),
              opacity var(--dur-fast);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.1) translateY(-1px);
  box-shadow: 0 8px 20px var(--clr-primary-glow);
}
.send-btn:not(:disabled):active { transform: scale(0.95); }

.input-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--clr-text-muted);
  margin-top: 6px;
  max-width: 860px;
  margin-inline: auto;
}

kbd {
  font-family: 'Inter', monospace;
  font-size: 0.65rem;
  background: var(--clr-surface-3);
  border: 1px solid var(--clr-border-hover);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--clr-text-secondary);
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  transition: opacity var(--dur-mid);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-width: 270px; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    transform: translateX(-100%);
    transition: transform var(--dur-mid) var(--ease-out);
    box-shadow: var(--shadow-lg);
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
  }
  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: all;
  }

  .menu-toggle { display: flex !important; }
  .sidebar-toggle { display: flex; }

  .topbar { padding: 0 12px; }

  .chat-container { padding: 16px 0; }

  .messages-wrapper { padding: 0 10px; }

  .msg-bubble { max-width: 88%; }

  .input-area { padding: 10px 12px 12px; }
}

@media (max-width: 480px) {
  .welcome-title { font-size: 1.5rem; }
  .welcome-chips { gap: 6px; }
  .chip { font-size: 0.75rem; padding: 5px 10px; }
  .msg-bubble { font-size: 0.875rem; }
}

/* ============================================================
   UTILITY
   ============================================================ */
.hidden { display: none !important; }

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
  border-radius: 4px;
}
