/* StudyBuddy Custom Styling & Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Noto+Nastaliq+Urdu:wght@400;600;700&family=Lateef:wght@400;600;700&family=Noto+Sans+Arabic:wght@400;500;600;700&display=swap');

:root {
  --primary: #3B52E8;
  --primary-hover: #2F44D8;
  --primary-light: #EEF2FF;
  --accent-purple: #7C3AED;
}

body {
  font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #F8FAFC;
  color: #0F172A;
  -webkit-font-smoothing: antialiased;
}

/* Dark mode overrides */
.dark body {
  background-color: #0B0F19;
  color: #F1F5F9;
}

/* Urdu Typography */
.font-urdu {
  font-family: 'Noto Nastaliq Urdu', 'Noto Sans Arabic', Tahoma, sans-serif;
  line-height: 2.2;
}

/* Sindhi Typography */
.font-sindhi {
  font-family: 'Lateef', 'Noto Sans Arabic', Tahoma, sans-serif;
  line-height: 1.9;
  font-size: 1.15rem;
}

/* RTL layout support */
[dir="rtl"] {
  text-align: right;
  direction: rtl;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 9999px;
}

.dark ::-webkit-scrollbar-thumb {
  background: #334155;
}

::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* KaTeX tweaks for responsive display */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
  margin: 0.5rem 0 !important;
}

/* Smooth transitions */
.view-panel {
  display: none;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.view-panel.active {
  display: block;
}

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

/* Bubble animations */
@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.animate-bubble {
  animation: bubbleIn 0.2s ease-out forwards;
}

/* Student portal */
.portal-feature-layout {
  display: grid;
  grid-template-columns: minmax(205px, 245px) minmax(0, 1fr);
  align-items: start;
  gap: 1.25rem;
}

.portal-feature-content { min-width: 0; }

.portal-history-panel {
  position: sticky;
  top: 5.5rem;
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid rgb(226 232 240 / 0.9);
  border-radius: 1.25rem;
  background: white;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.04);
}

.dark .portal-history-panel {
  background: #1e293b;
  border-color: #334155;
}

.portal-history-item {
  display: block;
  width: 100%;
  padding: 0.65rem 0.7rem;
  overflow: hidden;
  border-radius: 0.75rem;
  color: #475569;
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.portal-history-item:hover,
.portal-history-item.is-active {
  color: #4338ca;
  background: #eef2ff;
}

.dark .portal-history-item { color: #cbd5e1; }
.dark .portal-history-item:hover,
.dark .portal-history-item.is-active { color: #c7d2fe; background: #312e81; }

.portal-history-empty {
  padding: 0.8rem 0.25rem;
  color: #94a3b8;
  font-size: 0.7rem;
  line-height: 1.5;
}

.profile-detail-card {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  border: 1px solid #e2e8f0;
  border-radius: 0.9rem;
  padding: 0.8rem 0.9rem;
  background: #f8fafc;
}

.profile-detail-card span { color: #94a3b8; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.profile-detail-card strong { color: #334155; font-size: 0.8rem; overflow-wrap: anywhere; }
.dark .profile-detail-card { background: #0f172a; border-color: #334155; }
.dark .profile-detail-card strong { color: #e2e8f0; }

.header-profile-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 2.25rem;
  padding: 0.25rem 0.45rem 0.25rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 0.75rem;
  color: #475569;
  font-size: 0.75rem;
  font-weight: 700;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.header-profile-button:hover,
.header-profile-button:focus-visible { border-color: #c7d2fe; background: #eef2ff; color: #4338ca; outline: none; }
.dark .header-profile-button { color: #cbd5e1; }
.dark .header-profile-button:hover,
.dark .header-profile-button:focus-visible { border-color: #4338ca; background: #312e81; color: #e0e7ff; }

.header-profile-avatar {
  display: inline-flex;
  width: 1.85rem;
  height: 1.85rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.6rem;
  color: white;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  font-size: 0.67rem;
  font-weight: 800;
}

.portal-auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 1.25rem;
  background: rgb(15 23 42 / 0.72);
  backdrop-filter: blur(8px);
}

#portal-auth-gate.hidden { display: none; }
#portal-name-field.hidden { display: none; }

.portal-auth-card {
  width: min(100%, 440px);
  padding: 2rem;
  border: 1px solid rgb(226 232 240 / 0.9);
  border-radius: 1.75rem;
  background: white;
  box-shadow: 0 25px 60px rgb(15 23 42 / 0.25);
}

.dark .portal-auth-card { background: #0f172a; border-color: #334155; }

.portal-auth-input {
  display: block;
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 0.75rem;
  padding: 0.75rem 0.85rem;
  color: #0f172a;
  background: #f8fafc;
  font-size: 0.875rem;
  outline: none;
}

.portal-auth-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgb(99 102 241 / 0.16); }
.dark .portal-auth-input { color: #f1f5f9; background: #1e293b; border-color: #475569; }

.portal-auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.2rem 0 0.9rem;
  color: #94a3b8;
  font-size: 0.7rem;
}

.portal-auth-divider::before,
.portal-auth-divider::after { content: ''; height: 1px; flex: 1; background: #e2e8f0; }
.dark .portal-auth-divider::before,
.dark .portal-auth-divider::after { background: #334155; }

.portal-save-notice {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 90;
  max-width: min(28rem, calc(100vw - 2rem));
  border: 1px solid #fde68a;
  border-radius: 0.9rem;
  padding: 0.8rem 1rem;
  color: #92400e;
  background: #fffbeb;
  box-shadow: 0 8px 24px rgb(15 23 42 / 0.14);
  font-size: 0.75rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 160ms ease, transform 160ms ease;
}

.portal-save-notice.is-visible { opacity: 1; transform: translateY(0); }
.dark .portal-save-notice { color: #fde68a; background: #422006; border-color: #92400e; }

@media (max-width: 900px) {
  .portal-feature-layout { grid-template-columns: minmax(0, 1fr); }
  .portal-history-panel { position: static; max-height: 12rem; }
}

@media (max-width: 480px) {
  .portal-auth-card { padding: 1.5rem; border-radius: 1.4rem; }
}

/* Markdown prose tweaks */
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}
.markdown-content h1 { font-size: 1.35rem; }
.markdown-content h2 { font-size: 1.2rem; }
.markdown-content h3 { font-size: 1.05rem; }

.markdown-content p {
  margin-bottom: 0.75rem;
  line-height: 1.65;
}

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

.markdown-content ul { list-style-type: disc; }
.markdown-content ol { list-style-type: decimal; }

.markdown-content li {
  margin-bottom: 0.35rem;
  line-height: 1.6;
}

.markdown-content code {
  background-color: rgba(148, 163, 184, 0.18);
  padding: 0.15rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.875em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.markdown-content pre {
  background-color: #0F172A;
  color: #F8FAFC;
  padding: 0.85rem 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}

.markdown-content pre code {
  background-color: transparent;
  color: inherit;
  padding: 0;
}

.markdown-content blockquote {
  border-left: 3px solid #3B52E8;
  padding-left: 0.85rem;
  color: #64748B;
  font-style: italic;
  margin: 0.75rem 0;
}

/* Chat typing dots animation */
.typing-dot {
  animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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