/* ==========================================================================
   STUDY BUDDY - CSS DESIGN SYSTEM & STYLES
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Root Variables & Reset
   -------------------------------------------------------------------------- */
:root {
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Color Palette - Vibrant Dark Student Theme */
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --bg-input-focus: #475569;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  
  --bot-gradient: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
  --user-bubble-bg: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --bot-bubble-bg: #1e293b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #cbd5e1;
  
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.3);
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   2. Main Layout Container
   -------------------------------------------------------------------------- */
.app-container {
  width: 100%;
  max-width: 1000px;
  height: 94vh;
  margin: 3vh auto;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* --------------------------------------------------------------------------
   3. Header Styling
   -------------------------------------------------------------------------- */
.app-header {
  padding: 16px 24px;
  background: rgba(30, 41, 59, 0.7);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bot-logo {
  width: 46px;
  height: 46px;
  background: var(--bot-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.header-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.header-info .badge {
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-online {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.status-online .dot {
  width: 8px;
  height: 8px;
  background-color: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-green);
  display: inline-block;
}

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

/* --------------------------------------------------------------------------
   4. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-subtle);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.25);
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   5. Chat Main Body & Welcome Card
   -------------------------------------------------------------------------- */
.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-main::-webkit-scrollbar {
  width: 6px;
}

.chat-main::-webkit-scrollbar-track {
  background: transparent;
}

.chat-main::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

.chat-main::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Welcome Card */
.welcome-card {
  margin: auto;
  max-width: 680px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
  animation: fadeIn 0.4s ease-out;
}

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

.hero-avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px auto;
  background: var(--primary-gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.welcome-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #ffffff;
}

.welcome-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* Quick Questions Chips */
.quick-questions {
  text-align: left;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.quick-questions h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-subtle);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-questions h3 i {
  color: var(--accent-amber);
}

.chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.chip-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  transform: translateY(-2px);
  color: #ffffff;
}

.chip-icon {
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   6. Messages Container & Chat Bubbles
   -------------------------------------------------------------------------- */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message-row.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-row.bot {
  margin-right: auto;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.bot-avatar {
  background: var(--bot-gradient);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(79, 70, 229, 0.3);
}

.user-avatar {
  background: linear-gradient(135deg, #0ea5e9, #3b82f6);
  color: #ffffff;
}

.bubble-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-row.user .bubble-wrapper {
  align-items: flex-end;
}

.message-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 2px;
}

.bubble {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.6;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.message-row.user .bubble {
  background: var(--user-bubble-bg);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-row.bot .bubble {
  background: var(--bot-bubble-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

/* Markdown Styling within Bot Bubble */
.bubble p {
  margin-bottom: 0.8em;
}

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

.bubble ul, .bubble ol {
  margin: 0.6em 0 0.8em 1.4em;
}

.bubble li {
  margin-bottom: 0.4em;
}

.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  color: #ffffff;
  margin: 1em 0 0.5em 0;
  font-weight: 700;
}

.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child {
  margin-top: 0;
}

.bubble blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 12px;
  margin: 0.8em 0;
  color: var(--text-muted);
  font-style: italic;
}

.bubble code {
  font-family: 'Courier New', Courier, monospace;
  background: rgba(0, 0, 0, 0.3);
  color: #a5b4fc;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}

.bubble pre {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 0.8em 0;
}

.bubble pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Error Bubble */
.message-row.error .bubble {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: #fecdd3;
}

/* --------------------------------------------------------------------------
   7. Typing Indicator Animation
   -------------------------------------------------------------------------- */
.typing-indicator {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-right: auto;
  animation: fadeIn 0.2s ease-in;
}

.typing-indicator.hidden {
  display: none !important;
}

.typing-bubble {
  background: var(--bot-bubble-bg);
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dots .dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.dots .dot:nth-child(1) { animation-delay: 0s; }
.dots .dot:nth-child(2) { animation-delay: 0.2s; }
.dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* --------------------------------------------------------------------------
   8. Input Footer Area
   -------------------------------------------------------------------------- */
.chat-footer {
  padding: 16px 24px;
  background: rgba(30, 41, 59, 0.8);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* API Warning Banner */
.api-warning-banner {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fef08a;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.api-warning-banner.hidden {
  display: none !important;
}

.api-warning-banner button {
  background: var(--accent-amber);
  color: #0f172a;
  border: none;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: var(--transition);
}

.api-warning-banner button:hover {
  opacity: 0.9;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 12px 8px 18px;
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background: var(--bg-input-focus);
}

textarea#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  min-height: 24px;
  padding: 4px 0;
}

textarea#user-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-gradient);
  border: none;
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.6);
}

.send-btn:disabled {
  background: #475569;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.6;
}

.input-footer-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* --------------------------------------------------------------------------
   9. Modal Dialog (API Key Settings)
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-content {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 18px 24px;
  background: rgba(30, 41, 59, 0.8);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: var(--transition);
}

.modal-close:hover {
  color: #ffffff;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.9rem;
  color: var(--text-subtle);
  line-height: 1.5;
}

.api-steps {
  margin-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.api-steps a {
  color: #818cf8;
  text-decoration: none;
}

.api-steps a:hover {
  text-decoration: underline;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.input-group label {
  font-weight: 600;
  color: #ffffff;
}

.input-group input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(30, 41, 59, 0.8);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* --------------------------------------------------------------------------
   10. Responsive Utilities
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .app-container {
    height: 100vh;
    margin: 0;
    border-radius: 0;
    border: none;
  }
  
  .app-header {
    padding: 12px 16px;
  }

  .header-info h1 {
    font-size: 1.1rem;
  }

  .btn-text {
    display: none;
  }

  .chat-main {
    padding: 16px;
  }

  .welcome-card {
    padding: 24px 16px;
  }

  .message-row {
    max-width: 92%;
  }

  .chat-footer {
    padding: 12px 16px;
  }
}
