/* ==========================================================================
   STUDY BUDDY - CSS STYLESHEET
   Theme: Cute, Minimalist, Light Blue Pastel
   ========================================================================== */

/* --- Custom Properties (CSS Variables) --- */
:root {
  /* Colors */
  --bg-app: #f0f9ff;
  --bg-gradient: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 50%, #dbeafe 100%);
  
  --primary-light: #e0f2fe;
  --primary-soft: #bfdbfe;
  --primary-main: #60a5fa;
  --primary-accent: #3b82f6;
  --primary-dark: #1d4ed8;
  
  --user-bubble-bg: #bfdbfe;
  --user-bubble-text: #1e3a8a;
  
  --bot-bubble-bg: #ffffff;
  --bot-bubble-text: #1e293b;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --accent-pink: #fbcfe8;
  --accent-yellow: #fef08a;
  --accent-green: #4ade80;
  --accent-red: #f87171;
  
  /* Layout & Shadows */
  --header-height: 72px;
  --input-area-height: 100px;
  --max-width: 900px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(148, 163, 184, 0.08);
  --shadow-md: 0 8px 20px rgba(148, 163, 184, 0.12);
  --shadow-lg: 0 16px 32px rgba(96, 165, 250, 0.15);
  
  --font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Base & Reset --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg-gradient);
  color: var(--text-main);
  overflow: hidden;
  font-size: 16px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

/* --- App Outer Container --- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: var(--max-width);
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

@media (min-width: 901px) {
  body {
    padding: 1.5rem 0;
  }
  .app-container {
    height: calc(100vh - 3rem);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.8);
  }
}

/* --- Header Section --- */
.app-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(191, 219, 254, 0.5);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.mascot-badge {
  position: relative;
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.mascot-badge:hover {
  transform: scale(1.05) rotate(5deg);
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.status-dot.online {
  background-color: var(--accent-green);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.header-info h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  line-height: 1.2;
}

.sparkle {
  font-size: 1rem;
  animation: pulse-sparkle 2s infinite ease-in-out;
}

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

.status-text {
  color: #16a34a;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --- Buttons --- */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 1px solid var(--primary-soft);
  background: #ffffff;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
  background: var(--primary-light);
  transform: translateY(-2px);
  color: var(--primary-accent);
}

.btn-secondary {
  height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--primary-soft);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--primary-soft);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-primary {
  height: 42px;
  padding: 0 1.25rem;
  border-radius: var(--radius-full);
  border: none;
  background: var(--primary-accent);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.5rem;
  transition: color var(--transition-fast);
}

.btn-link:hover {
  color: var(--accent-red);
}

/* --- Chat Viewport & Messages --- */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem 0.5rem;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 100%;
}

/* --- Welcome Card --- */
.welcome-card {
  margin: auto;
  padding: 2rem 1.5rem;
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--primary-soft);
  text-align: center;
  box-shadow: var(--shadow-md);
  max-width: 600px;
  animation: fadeIn 0.4s ease-out;
}

.welcome-avatar {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 1.25rem;
}

.mascot-circle {
  width: 100%;
  height: 100%;
  background: var(--bg-gradient);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--primary-soft);
  box-shadow: var(--shadow-sm);
}

.big-mascot {
  font-size: 3rem;
  animation: float 3s ease-in-out infinite;
}

.badge-float {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--accent-yellow);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  border: 2px solid #ffffff;
  box-shadow: var(--shadow-sm);
}

.welcome-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.welcome-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

/* Suggestion Chips */
.suggestions-container {
  text-align: left;
  background: var(--bg-app);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--primary-light);
}

.suggestions-label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip-btn {
  background: #ffffff;
  border: 1.5px solid var(--primary-soft);
  border-radius: var(--radius-full);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.chip-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-main);
  color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

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

/* --- Message Bubbles --- */
.message-row {
  display: flex;
  gap: 0.75rem;
  max-width: 88%;
  animation: slideUp 0.3s ease-out;
}

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

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

.avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.user-avatar {
  background: var(--primary-accent);
  color: #ffffff;
  font-size: 1.1rem;
}

.bot-avatar {
  background: var(--primary-light);
  border: 1.5px solid var(--primary-soft);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.message-bubble {
  padding: 0.9rem 1.25rem;
  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: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

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

.message-time {
  font-size: 0.7rem;
  color: var(--text-light);
  font-weight: 600;
  margin-top: 0.15rem;
}

.message-row.user .message-time {
  text-align: right;
}

.message-row.bot .message-time {
  text-align: left;
}

/* System / Warning / Error Bubble */
.message-bubble.error-bubble {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border: 1.5px solid #fca5a5 !important;
}

/* --- Markdown Rendered Content Styles --- */
.markdown-body {
  font-size: 0.95rem;
  line-height: 1.65;
}

.markdown-body p {
  margin-bottom: 0.75rem;
}

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

.markdown-body strong {
  font-weight: 800;
  color: var(--primary-dark);
}

.markdown-body em {
  font-style: italic;
  opacity: 0.9;
}

.markdown-body ul, .markdown-body ol {
  margin-left: 1.25rem;
  margin-bottom: 0.75rem;
}

.markdown-body li {
  margin-bottom: 0.3rem;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  font-weight: 800;
  color: var(--primary-dark);
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 1.25rem; }
.markdown-body h2 { font-size: 1.15rem; }
.markdown-body h3 { font-size: 1.05rem; }

.markdown-body blockquote {
  border-left: 4px solid var(--primary-main);
  padding: 0.4rem 0.8rem;
  background: var(--primary-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--primary-dark);
  font-style: italic;
  margin-bottom: 0.75rem;
}

.markdown-body code {
  font-family: "Courier New", Courier, monospace;
  background: rgba(96, 165, 250, 0.15);
  color: var(--primary-dark);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
  font-weight: 700;
}

.markdown-body pre {
  margin: 0.75rem 0;
  background: #f8fafc;
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.markdown-body pre code {
  display: block;
  padding: 1rem;
  background: transparent;
  color: #1e293b;
  overflow-x: auto;
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.5;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary-light);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-dark);
  border-bottom: 1px solid var(--primary-soft);
}

.copy-code-btn {
  background: #ffffff;
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: all var(--transition-fast);
}

.copy-code-btn:hover {
  background: var(--primary-soft);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.88rem;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--primary-soft);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.markdown-body th {
  background: var(--primary-light);
  font-weight: 800;
  color: var(--primary-dark);
}

/* --- Typing Indicator --- */
.typing-container {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  animation: fadeIn 0.3s ease-out;
}

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

.typing-bubble {
  background: var(--bot-bubble-bg);
  border: 1px solid var(--primary-soft);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

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

.typing-dots span {
  width: 8px;
  height: 8px;
  background-color: var(--primary-main);
  border-radius: 50%;
  display: inline-block;
  animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* --- Bottom Input Area --- */
.chat-input-area {
  padding: 0.85rem 1.25rem 1rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(191, 219, 254, 0.6);
  z-index: 10;
}

.input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  background: var(--bg-app);
  border: 2px solid var(--primary-soft);
  border-radius: var(--radius-lg);
  padding: 0.4rem 0.5rem 0.4rem 1rem;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.input-form:focus-within {
  border-color: var(--primary-main);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
}

.input-wrapper textarea {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 0.95rem;
  color: var(--text-main);
  font-weight: 600;
  max-height: 120px;
  line-height: 1.4;
  padding: 0.4rem 0;
}

.input-wrapper textarea::placeholder {
  color: var(--text-light);
  font-weight: 500;
}

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--primary-accent);
  color: #ffffff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

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

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

.input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 0.4rem;
}

.input-hint strong {
  color: var(--text-muted);
}

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

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

.modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--primary-soft);
  animation: scaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

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

.api-status-box {
  margin: 0.85rem 0;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--primary-soft);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.85rem;
}

.api-status-box.valid {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.api-status-box.invalid {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.form-group {
  margin: 1rem 0;
}

.form-group label {
  display: block;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--primary-soft);
  outline: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--primary-main);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.info-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--primary-light);
  padding: 0.85rem;
  border-radius: var(--radius-md);
}

.info-note p {
  margin-bottom: 0.4rem;
}
.info-note p:last-child {
  margin-bottom: 0;
}

.info-note a {
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: underline;
}

.modal-footer {
  padding: 1rem 1.25rem;
  background: #f8fafc;
  border-top: 1px solid rgba(191, 219, 254, 0.5);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* --- Keyframe Animations --- */
@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1.0);
  }
}

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

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

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

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes pulse-sparkle {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
  .app-header {
    padding: 0 0.85rem;
  }
  
  .header-info h1 {
    font-size: 1.1rem;
  }
  
  .btn-text {
    display: none;
  }
  
  .btn-secondary {
    padding: 0 0.75rem;
  }

  .chat-viewport {
    padding: 0.85rem 0.75rem 0.5rem;
  }

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

  .welcome-card {
    padding: 1.25rem 1rem;
  }

  .welcome-title {
    font-size: 1.2rem;
  }

  .suggestions-container {
    padding: 0.85rem;
  }

  .chip-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }
  
  .chat-input-area {
    padding: 0.6rem 0.75rem 0.75rem;
  }
  
  .input-hint {
    font-size: 0.68rem;
  }
}
