/* ==========================================================================
   STUDY BUDDY - MODERN & BEAUTIFUL CSS DESIGN SYSTEM
   ========================================================================== */

:root {
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Color Tokens */
  --bg-main: #0b0f19;
  --bg-card: #141b2d;
  --bg-card-alt: #1a233a;
  --bg-input: #111827;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-sky: #06b6d4;
  --accent-purple: #a855f7;

  --text-main: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  --user-bubble-bg: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --bot-bubble-bg: #1e293b;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.3);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.2);
}

/* Reset & Global */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Outer Container */
.app-container {
  width: 100%;
  max-width: 1000px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  .app-container {
    height: 95vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), var(--shadow-glow);
  }
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(20, 27, 45, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.brand-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar-container {
  position: relative;
}

.bot-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.bot-avatar.small {
  width: 32px;
  height: 32px;
  font-size: 14px;
}

.online-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  border: 2px solid var(--bg-card);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
}

.brand-text .tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.brand-text .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.brand-text .subtitle i {
  color: var(--accent-amber);
}

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

/* Buttons */
.btn-primary, .btn-secondary, .btn-primary-outline {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-primary-outline {
  background: transparent;
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
}
.btn-primary-outline:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
}

/* ==========================================================================
   MAIN CHAT WINDOW & WELCOME SCREEN
   ========================================================================== */
.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.chat-main::-webkit-scrollbar {
  width: 6px;
}
.chat-main::-webkit-scrollbar-track {
  background: transparent;
}
.chat-main::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
.chat-main::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  gap: 28px;
  max-width: 800px;
  margin: auto;
  width: 100%;
  animation: fadeIn 0.4s ease-out;
}

.hero-card {
  text-align: center;
  background: linear-gradient(180deg, rgba(26, 35, 58, 0.6) 0%, rgba(20, 27, 45, 0.4) 100%);
  border: 1px solid var(--border-color);
  padding: 36px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.hero-card::before {
  content: '';
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 100px;
  background: var(--primary);
  filter: blur(80px);
  opacity: 0.3;
  pointer-events: none;
}

.hero-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(168, 85, 247, 0.2) 100%);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #a5b4fc;
}

.hero-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.hero-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 550px;
  margin: 0 auto;
}

/* Quick Questions Grid */
.quick-questions-container h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.quick-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  text-align: left;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
}

.quick-card:hover {
  background: var(--bg-card-alt);
  border-color: var(--border-highlight);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.card-icon.math { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.card-icon.bio { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.card-icon.calc { background: rgba(6, 182, 212, 0.15); color: #38bdf8; }
.card-icon.tips { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.card-desc {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-main);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-arrow {
  color: var(--text-muted);
  font-size: 14px;
  transition: transform 0.2s ease, color 0.2s ease;
}

.quick-card:hover .card-arrow {
  transform: translateX(4px);
  color: var(--primary);
}

/* ==========================================================================
   CHAT MESSAGES LIST
   ========================================================================== */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

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

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.bot {
  align-self: flex-start;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 4px;
  box-shadow: 0 3px 8px rgba(6, 182, 212, 0.3);
}

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

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

.sender-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding: 0 4px;
}

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

.message-row.user .message-bubble {
  background: var(--user-bubble-bg);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.3);
}

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

/* Markdown formatting inside Bot Bubble */
.message-bubble p {
  margin-bottom: 10px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  color: #ffffff;
  font-weight: 700;
}

.message-bubble ul, .message-bubble ol {
  margin: 8px 0 12px 20px;
}

.message-bubble li {
  margin-bottom: 4px;
}

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

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

.message-bubble pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
  font-size: 0.88rem;
  line-height: 1.5;
}

/* Action button inside message (e.g., Copy) */
.bubble-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.message-row:hover .bubble-actions {
  opacity: 1;
}

.btn-copy {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

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

/* ==========================================================================
   TYPING / LOADING INDICATOR
   ========================================================================== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  animation: fadeIn 0.3s ease;
}

.typing-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.typing-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

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

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   API KEY BANNER & FOOTER INPUT
   ========================================================================== */
.api-key-banner {
  background: rgba(245, 158, 11, 0.15);
  border-top: 1px solid rgba(245, 158, 11, 0.4);
  border-bottom: 1px solid rgba(245, 158, 11, 0.4);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  color: #fef08a;
  animation: slideDown 0.3s ease;
}

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

.banner-content i {
  font-size: 16px;
  color: var(--accent-amber);
}

.btn-banner {
  background: var(--accent-amber);
  color: #000;
  border: none;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.btn-banner:hover {
  opacity: 0.9;
}

/* Footer Input Area */
.chat-footer {
  padding: 16px 24px 20px;
  background: rgba(20, 27, 45, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-form {
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px 8px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

textarea {
  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: 120px;
  min-height: 24px;
  padding: 4px 0;
}

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

.btn-send {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.btn-send:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  cursor: not-allowed;
}

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

/* ==========================================================================
   MODAL DIALOG
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-md), var(--shadow-glow);
  overflow: hidden;
  animation: scaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.modal-header h3 i {
  color: var(--accent-amber);
}

.btn-icon-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s;
}

.btn-icon-close:hover {
  color: #fff;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-body p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

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

.input-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrapper input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 42px 10px 14px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-password-wrapper input:focus {
  border-color: var(--primary);
}

.btn-toggle-vis {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}

.btn-toggle-vis:hover {
  color: #fff;
}

.modal-help {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
}

.modal-help a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.modal-help a:hover {
  text-decoration: underline;
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Helper Utilities */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  .app-header {
    padding: 12px 16px;
  }
  .btn-text {
    display: none;
  }
  .btn-secondary, .btn-primary-outline {
    padding: 8px 10px;
  }
  .chat-main {
    padding: 16px;
  }
  .message-row {
    max-width: 92%;
  }
  .hero-card {
    padding: 24px 16px;
  }
  .hero-card h2 {
    font-size: 1.25rem;
  }
  .quick-grid {
    grid-template-columns: 1fr;
  }
  .chat-footer {
    padding: 12px 16px 16px;
  }
}
