/* ==========================================================================
   STUDY BUDDY - CUTE & MINIMALIST DESIGN SYSTEM
   Dominant Palette: Soft Blue (#BFDBFE, #3B82F6, #EFF6FF)
   ========================================================================== */

:root {
  /* Color Tokens */
  --primary-50: #EFF6FF;
  --primary-100: #DBEAFE;
  --primary-200: #BFDBFE; /* Primary Soft Blue */
  --primary-300: #93C5FD;
  --primary-400: #60A5FA;
  --primary-500: #3B82F6; /* Accent Blue */
  --primary-600: #2563EB;
  --primary-700: #1D4ED8;
  --primary-900: #1E3A8A; /* Dark Accent */
  
  --bg-app: #F4F8FF;
  --bg-surface: #FFFFFF;
  --bg-glass: rgba(255, 255, 255, 0.85);
  
  --text-main: #1E293B;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  
  --border-light: #E2E8F0;
  --border-focus: #93C5FD;
  
  --user-bubble-bg: #DBEAFE;
  --user-bubble-text: #1E3A8A;
  --bot-bubble-bg: #FFFFFF;
  --bot-bubble-text: #1E293B;
  --bot-bubble-border: #E2E8F0;

  --shadow-sm: 0 2px 8px rgba(59, 130, 246, 0.06);
  --shadow-md: 0 8px 24px rgba(59, 130, 246, 0.1);
  --shadow-lg: 0 12px 36px rgba(30, 58, 138, 0.12);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* CSS Reset & General Settings */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Main App Wrapper */
.app-container {
  width: 100%;
  max-width: 960px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-app);
  box-shadow: var(--shadow-lg);
  position: relative;
}

@media (min-width: 768px) {
  .app-container {
    height: 94vh;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-light);
  }
}

/* Header */
.app-header {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  z-index: 10;
}

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

.mascot-avatar {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary-300), var(--primary-500));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  position: relative;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
  animation: pulse-avatar 3s infinite ease-in-out;
}

@keyframes pulse-avatar {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.online-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background-color: #22C55E;
  border: 2px solid white;
  border-radius: 50%;
}

.header-title h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag-badge {
  font-size: 0.68rem;
  background-color: var(--primary-200);
  color: var(--primary-900);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-title p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

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

/* Buttons */
.btn {
  font-family: 'Poppins', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
  outline: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-secondary {
  background-color: var(--primary-100);
  color: var(--primary-900);
}

.btn-secondary:hover {
  background-color: var(--primary-200);
  color: var(--primary-900);
}

.btn-outline {
  background-color: transparent;
  border: 1.5px solid var(--primary-300);
  color: var(--primary-700);
}

.btn-outline:hover {
  background-color: var(--primary-50);
  border-color: var(--primary-500);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
}

.btn-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.btn-send:hover {
  transform: scale(1.06);
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
}

.btn-send:disabled {
  background: var(--text-light);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* Chat Main Scroll Area */
.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.chat-main::-webkit-scrollbar {
  width: 6px;
}

.chat-main::-webkit-scrollbar-thumb {
  background-color: var(--primary-200);
  border-radius: 10px;
}

/* Welcome Card */
.welcome-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
  animation: fadeIn 0.4s ease-out;
}

.welcome-avatar {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #FEF08A, #F59E0B);
  color: white;
  font-size: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.25);
}

.welcome-card h2 {
  font-family: 'Poppins', sans-serif;
  font-size: 1.35rem;
  color: var(--primary-900);
  margin-bottom: 8px;
}

.welcome-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 620px;
  margin: 0 auto 20px;
}

.suggestions-section {
  text-align: left;
  border-top: 1px dashed var(--primary-200);
  padding-top: 18px;
}

.suggestions-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary-700);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.suggestion-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.pill-btn {
  background-color: var(--primary-50);
  border: 1.5px solid var(--primary-200);
  color: var(--primary-900);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-family: 'Nunito', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.pill-btn i {
  color: var(--primary-500);
}

.pill-btn:hover {
  background-color: var(--primary-200);
  border-color: var(--primary-400);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

/* Chat Messages Feed */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

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

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

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

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

.bot-avatar {
  background: linear-gradient(135deg, var(--primary-300), var(--primary-500));
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.user-avatar {
  background: linear-gradient(135deg, #A7F3D0, #10B981);
  color: white;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

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

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

.bot-name, .user-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Message Bubbles */
.bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}

.user-bubble {
  background-color: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

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

/* Bubble Formatting (Markdown Rendered Elements) */
.bot-bubble p {
  margin-bottom: 10px;
}

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

.bot-bubble h1, .bot-bubble h2, .bot-bubble h3 {
  font-family: 'Poppins', sans-serif;
  color: var(--primary-900);
  margin: 14px 0 8px 0;
}

.bot-bubble h1 { font-size: 1.2rem; }
.bot-bubble h2 { font-size: 1.1rem; }
.bot-bubble h3 { font-size: 1.02rem; }

.bot-bubble ul, .bot-bubble ol {
  margin: 8px 0 10px 22px;
}

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

.bot-bubble blockquote {
  border-left: 4px solid var(--primary-400);
  background-color: var(--primary-50);
  padding: 8px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 10px 0;
  font-style: italic;
}

.bot-bubble inline-code, .bot-bubble code:not(pre code) {
  font-family: 'Courier New', Courier, monospace;
  background-color: var(--primary-100);
  color: var(--primary-900);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.88em;
  font-weight: 700;
}

.bot-bubble pre {
  background-color: #1E293B;
  color: #F8FAFC;
  padding: 14px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.88rem;
}

.bot-bubble pre code {
  color: #F8FAFC;
  background: transparent;
  padding: 0;
}

.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

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

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.action-btn:hover {
  background-color: var(--primary-100);
  color: var(--primary-900);
}

/* Typing Indicator Animation */
.typing-row {
  margin-top: 8px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background-color: var(--bg-surface);
}

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

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

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

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

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

/* Bottom Input Bar */
.input-footer {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px 20px 10px;
  border-top: 1px solid var(--border-light);
  position: relative;
  z-index: 10;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background-color: var(--bg-surface);
  border: 2px solid var(--primary-200);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast);
}

.input-container:focus-within {
  border-color: var(--primary-500);
  box-shadow: var(--shadow-md);
}

.input-container textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  color: var(--text-main);
  resize: none;
  max-height: 120px;
  min-height: 28px;
  line-height: 1.4;
  padding: 4px 6px;
}

.input-container textarea::placeholder {
  color: var(--text-light);
}

.disclaimer-text {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Modal Overlay & Card */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

.modal-card {
  background: var(--bg-surface);
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.modal-header {
  padding: 16px 20px;
  background-color: var(--primary-50);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: 'Poppins', sans-serif;
  font-size: 1.05rem;
  color: var(--primary-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-weight: 700;
  color: var(--text-main);
}

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

.input-key-wrapper input {
  width: 100%;
  padding: 10px 40px 10px 14px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

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

.btn-input-eye {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

.modal-info {
  background-color: var(--primary-50);
  padding: 12px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--primary-900);
}

.modal-info i {
  color: var(--primary-500);
  font-size: 1.1rem;
  margin-top: 2px;
}

.modal-info a {
  color: var(--primary-600);
  font-weight: 700;
  text-decoration: underline;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
}

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

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

/* Responsive adjustments */
@media (max-width: 640px) {
  .app-header {
    padding: 10px 14px;
  }
  
  .header-title h1 {
    font-size: 1rem;
  }
  
  .btn-text {
    display: none;
  }
  
  .btn {
    padding: 8px 10px;
  }
  
  .chat-main {
    padding: 12px;
  }
  
  .welcome-card {
    padding: 20px 14px;
  }
  
  .suggestion-pills {
    grid-template-columns: 1fr;
  }

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

  .input-footer {
    padding: 10px 12px 8px;
  }
}
