/* ==========================================================================
   ReadBuddy - Base Stylesheet & Design System
   ========================================================================== */

:root {
  /* Brand Colors */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --primary-dark: #3730a3;
  
  --secondary: #06b6d4;
  --secondary-light: #cffafe;
  
  --accent-green: #10b981;
  --accent-green-light: #d1fae5;
  
  --accent-amber: #f59e0b;
  --accent-amber-light: #fef3c7;
  
  --accent-rose: #f43f5e;
  --accent-rose-light: #ffe4e6;
  
  --accent-purple: #8b5cf6;
  --accent-purple-light: #ede9fe;

  /* Neutrals */
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-alt: #f1f5f9;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-focus: #818cf8;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-reading: 'Georgia', 'Merriweather', serif;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Navigation Bar
   ========================================================================== */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.5rem;
  align-items: center;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.nav-item a:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-item.active a {
  color: var(--primary);
  background: var(--primary-light);
}

.user-quick-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-alt);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
}

.stat-pill.streak { color: #d97706; background: var(--accent-amber-light); border-color: #fde68a; }
.stat-pill.seeds { color: #059669; background: var(--accent-green-light); border-color: #a7f3d0; }
.stat-pill.stars { color: #7c3aed; background: var(--accent-purple-light); border-color: #ddd6fe; }

.user-profile-badge,
.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  user-select: none;
  font: inherit;
  color: inherit;
}

.user-profile-badge:hover,
.user-profile-btn:hover,
.user-profile-btn:focus-visible,
.user-profile-btn[aria-expanded="true"] {
  background: var(--bg-alt);
  border-color: var(--border-color);
  outline: none;
}

/* User Profile Menu & Dropdown */
.user-profile-menu-container {
  position: relative;
  display: flex;
  align-items: center;
}

.dropdown-chevron {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  margin-left: 0.1rem;
}

.user-profile-btn[aria-expanded="true"] .dropdown-chevron {
  transform: rotate(180deg);
}

.profile-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 215px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.12), 0 4px 10px -2px rgba(0, 0, 0, 0.04);
  padding: 0.45rem;
  z-index: 1000;
  display: none;
  flex-direction: column;
  animation: dropdownFadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.profile-dropdown-menu.show {
  display: flex;
}

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

.dropdown-user-header {
  padding: 0.6rem 0.75rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 0.35rem;
  text-align: left;
}

.dropdown-user-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: #f1f5f9;
  color: var(--primary);
  outline: none;
}

.dropdown-item.logout-item {
  color: #dc2626;
  margin-top: 0.2rem;
  border-top: 1px solid #f8fafc;
  padding-top: 0.65rem;
}

.dropdown-item.logout-item:hover,
.dropdown-item.logout-item:focus-visible {
  background: #fee2e2;
  color: #b91c1c;
}

.dropdown-item-icon {
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
}

.avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #f43f5e, #f59e0b);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}

.user-info-text {
  text-align: left;
  line-height: 1.2;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
}

.user-level {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-wrapper {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  flex: 1;
  width: 100%;
}

.page-header {
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Common Components
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

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

.btn-secondary {
  background: var(--bg-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-success {
  background: var(--accent-green);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
  background: #059669;
}

.btn-danger {
  background: var(--accent-rose);
  color: white;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-beginner {
  background: #dcfce7;
  color: #15803d;
}

.badge-intermediate {
  background: #fdeee2;
  color: #cb5a34;
}

.badge-advanced {
  background: #fdeee2;
  color: #cb5a34;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 900px) {
  .nav-container {
    flex-wrap: wrap;
  }
  .nav-links {
    order: 3;
    width: 100%;
    justify-content: space-around;
    overflow-x: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
  }
  .user-info-text {
    display: none;
  }
}

@media (max-width: 600px) {
  .nav-item a span.text {
    display: none;
  }
  .page-title {
    font-size: 1.5rem;
  }
  .stat-pill {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
}


/* ==========================================================================
   ReadBuddy Celebratory Achievement Modal (Badges & Flower Bloom Popups)
   ========================================================================== */
.achievement-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  animation: achFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.achievement-modal-card {
  position: relative;
  background: #ffffff;
  border-radius: 28px;
  width: 100%;
  max-width: 480px;
  padding: 2.5rem 2rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.2);
  text-align: center;
  overflow: hidden;
  animation: achCardPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.achievement-close-x {
  position: absolute;
  top: 1.1rem;
  right: 1.25rem;
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.achievement-close-x:hover {
  background: #e2e8f0;
  color: #0f172a;
  transform: scale(1.1);
}

.lock-anim-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.animated-lock {
  position: absolute;
  font-size: 3.4rem;
  line-height: 1;
  animation: lockPopUnlock 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 4;
}

@keyframes lockPopUnlock {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  35% { transform: scale(1.25) rotate(-15deg); opacity: 1; }
  65% { transform: scale(1.35) rotate(15deg); opacity: 0.9; }
  100% { transform: scale(0.3) translateY(-40px); opacity: 0; visibility: hidden; }
}

.achievement-sticker-wrapper.animated-unlock .achievement-sticker-icon {
  animation: badgePopReveal 1.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes badgePopReveal {
  0% { transform: scale(0.15); opacity: 0; }
  45% { transform: scale(0.25); opacity: 0; }
  75% { transform: scale(1.25); opacity: 1; }
  90% { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes achCardPop {
  0% { transform: scale(0.8) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Confetti shower effect */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  opacity: 0.9;
  animation: confettiFall 2.8s linear infinite;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(450px) rotate(720deg);
    opacity: 0;
  }
}

/* Collectible Sticker Artwork */
.achievement-sticker-wrapper {
  position: relative;
  width: 130px;
  height: 130px;
  margin: 0 auto 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.15);
}

.achievement-sticker-wrapper.flower-bloom {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, #fbcfe8 100%);
  border: 4px solid #f59e0b;
}

.achievement-sticker-wrapper.badge-sticker {
  background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 50%, #fbcfe8 100%);
  border: 4px solid #8b5cf6;
}

.achievement-sticker-glow {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.35) 0%, rgba(251, 191, 36, 0) 70%);
  animation: achPulseGlow 2s ease-in-out infinite alternate;
  z-index: -1;
}

@keyframes achPulseGlow {
  0% { transform: scale(0.95); opacity: 0.5; }
  100% { transform: scale(1.25); opacity: 1; }
}

.achievement-sticker-icon {
  font-size: 4.5rem;
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
  animation: achStickerBounce 1.8s ease-in-out infinite alternate;
}

@keyframes achStickerBounce {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

.achievement-title {
  position: relative;
  z-index: 2;
  font-size: 1.45rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.3;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.achievement-subtitle {
  position: relative;
  z-index: 2;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #475569;
  margin-bottom: 1.25rem;
}

.achievement-extra-box {
  position: relative;
  z-index: 2;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 14px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.achievement-extra-box p {
  color: #166534;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0;
}

.btn-achievement-awesome {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 260px;
  padding: 0.9rem 1.75rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  box-shadow: 0 10px 20px -5px rgba(79, 70, 229, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-achievement-awesome:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 25px -5px rgba(79, 70, 229, 0.5);
}

.btn-achievement-awesome:active {
  transform: translateY(0);
}

@media (max-width: 480px) {
  .achievement-modal-card {
    padding: 2rem 1.25rem;
  }
  .achievement-title {
    font-size: 1.25rem;
  }
  .achievement-sticker-wrapper {
    width: 110px;
    height: 110px;
  }
  .achievement-sticker-icon {
    font-size: 3.8rem;
  }
}

/* ==========================================================================
   In-App Notifications System Styles
   ========================================================================== */
.notification-bell-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.notification-bell-btn {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  color: var(--text-main);
}

.notification-bell-btn:hover {
  background: #eef2ff;
  border-color: #c7d2fe;
  transform: translateY(-1px);
}

.notif-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #ef4444;
  color: white;
  font-size: 0.7rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.notif-badge.hidden {
  display: none;
}

.notifications-dropdown-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 30px -4px rgba(15, 23, 42, 0.18);
  display: none;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
  animation: fadeInDown 0.18s ease-out;
}

.notifications-dropdown-menu.show {
  display: flex;
}

.notif-dropdown-header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafafa;
}

.notif-dropdown-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.notif-mark-all-btn {
  font-size: 0.75rem;
  font-weight: 700;
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
}

.notif-mark-all-btn:hover {
  background: #eef2ff;
  text-decoration: underline;
}

.notif-list-container {
  max-height: 380px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.notif-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  text-align: left;
}

.notif-item:hover {
  background: #f8fafc;
}

.notif-item.unread {
  background: #eff6ff;
}

.notif-item.unread:hover {
  background: #e0f2fe;
}

.notif-item-icon {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.notif-item-body {
  flex: 1;
  min-width: 0;
}

.notif-item-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-item-text {
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.35;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notif-item-time {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 600;
}

.notif-unread-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.4rem;
}

.notif-empty-state {
  padding: 2.25rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==========================================================================
   Class Status Badges
   ========================================================================== */
.class-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.status-approved {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.status-pending {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

.status-rejected {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* ==========================================================================
   Vertical Sidebar Layout (Student & Teacher Portals)
   ========================================================================== */
.portal-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
  background-color: var(--bg-main);
}

.portal-sidebar {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  height: 100vh;
  position: sticky;
  top: 0;
  left: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
}

.portal-main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg-main);
}

.portal-main-area .main-wrapper {
  max-width: 1320px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
  flex: 1;
  width: 100%;
}

.portal-main-area .footer {
  margin-top: auto;
}

/* Sidebar Header */
.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

/* Sidebar Quick Stats Widget (Student Portal) */
.sidebar-stats-widget {
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.25rem;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  text-align: center;
  transition: transform 0.15s ease;
}

.sidebar-stat-card:hover {
  transform: translateY(-1px);
}

.sidebar-stat-card.streak { border-color: #fde68a; background: #fffbeb; }
.sidebar-stat-card.seeds { border-color: #a7f3d0; background: #f0fdf4; }
.sidebar-stat-card.stars { border-color: #ddd6fe; background: #faf5ff; }

.sidebar-stat-card .stat-icon {
  font-size: 1rem;
  line-height: 1.1;
}

.sidebar-stat-card .stat-number {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  margin-top: 0.1rem;
}

.sidebar-stat-card .stat-caption {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Sidebar Notifications */
.sidebar-notification-item {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.sidebar-notif-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.55rem 0.85rem;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.sidebar-notif-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.sidebar-notif-icon {
  font-size: 1.1rem;
}

.sidebar-notif-label {
  flex: 1;
  text-align: left;
}

.sidebar-notification-item .notifications-dropdown-menu {
  top: 100%;
  left: 0.5rem;
  right: 0.5rem;
  width: auto;
  max-width: 320px;
  position: absolute;
  z-index: 1050;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
}

/* Sidebar Navigation Menu */
.sidebar-nav {
  flex: 1;
  padding: 0.85rem 0.75rem;
  overflow-y: auto;
}

.sidebar-nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  transition: all 0.18s ease;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
}

.sidebar-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-link.active,
.nav-item.active .sidebar-link,
.portal-sidebar .teacher-tab-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  border-color: rgba(79, 70, 229, 0.2);
}

.teacher-sidebar .sidebar-link.active,
.teacher-sidebar .teacher-tab-btn.active {
  background: #fdeee5 !important;
  color: #c25e3a !important;
  font-weight: 700 !important;
  box-shadow: none !important;
  border-radius: 14px !important;
}

.sidebar-link .sidebar-icon,
.sidebar-link > span:first-child {
  font-size: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
}

.sidebar-text {
  flex: 1;
}

/* Sidebar Footer & User Profile */
.sidebar-footer {
  padding: 0.85rem 0.75rem;
  border-top: 1px solid var(--border-color);
  background: #fafafa;
  position: relative;
}

.sidebar-profile-btn {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-md);
  background: #ffffff;
  border: 1px solid var(--border-color);
  justify-content: flex-start;
  box-shadow: var(--shadow-sm);
}

.sidebar-profile-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.sidebar-profile-btn .user-info-text {
  flex: 1;
  min-width: 0;
  margin-left: 0.25rem;
}

.sidebar-profile-btn .user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.88rem;
}

.sidebar-profile-btn .user-level {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.75rem;
}

.sidebar-footer .profile-dropdown-menu {
  bottom: calc(100% + 8px);
  top: auto;
  left: 0.5rem;
  right: 0.5rem;
  width: auto;
  z-index: 1050;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
}

/* Teacher Sidebar Specifics */
.sidebar-teacher-chip {
  padding: 0.25rem 0.25rem 0.75rem 0.25rem;
  background: transparent;
}

.sidebar-teacher-chip .teacher-id-chip {
  background: #fdeee5;
  color: #c25e3a;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  display: inline-block;
  border: 1px solid #fae0d0;
}

/* Mobile Topbar */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.mobile-menu-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  font-size: 1.25rem;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.mobile-brand {
  font-size: 1.15rem;
}

.sidebar-backdrop {
  display: none;
}

/* Responsive Sidebar Drawer for Mobile & Tablet */
@media (max-width: 991px) {
  .mobile-topbar {
    display: flex;
  }

  .portal-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-xl);
  }

  .portal-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 999;
  }

  .sidebar-backdrop.show {
    display: block;
  }

  .portal-main-area .main-wrapper {
    padding: 1.5rem 1rem 3rem;
  }
}

/* ==========================================================================
   Shared Teacher-Student Messaging Studio Styles & Layout Fixes
   ========================================================================== */
.messages-page-body {
  overflow: hidden;
}

@media (max-width: 991px) {
  .messages-page-body {
    overflow: auto;
  }
}

.portal-main-area.messages-portal-main {
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (max-width: 991px) {
  .portal-main-area.messages-portal-main {
    height: auto;
    min-height: 100vh;
    max-height: none;
    overflow: visible;
  }
}

.messages-main-wrapper {
  padding: 1.25rem 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .messages-main-wrapper {
    padding: 0.85rem 0.85rem 1rem;
  }
}

.messages-page-header {
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}

.messages-page-header .page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  margin: 0 0 0.2rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.messages-page-header .page-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

.messaging-studio-container {
  display: grid;
  grid-template-columns: 300px 1fr;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 860px) {
  .messaging-studio-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: calc(100vh - 135px);
    min-height: 480px;
  }

  .conversations-sidebar {
    max-height: 145px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}

.conversations-sidebar {
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.conversations-header {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  background: white;
  flex-shrink: 0;
}

.conversations-header h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.conversations-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem;
}

.conversation-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 0.35rem;
  background: white;
  border: 1.5px solid transparent;
}

.conversation-card:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

.conversation-card.active {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.conversation-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.15rem;
  gap: 0.25rem;
}

.conversation-name {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-time {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 600;
  flex-shrink: 0;
}

.conversation-snippet {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-unread-pill {
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Chat Pane */
.chat-pane {
  display: flex;
  flex-direction: column;
  background: white;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  flex: 1;
}

#student-active-chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.chat-pane-header {
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: #f8fafc;
  flex-shrink: 0;
}

.chat-partner-name {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.chat-partner-class {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.chat-messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: #ffffff;
}

.chat-bubble-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.chat-bubble-wrapper.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-bubble-wrapper.theirs {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-lg);
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble-wrapper.mine .chat-bubble {
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}

.chat-bubble-wrapper.theirs .chat-bubble {
  background: #f1f5f9;
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid #e2e8f0;
}

.chat-timestamp {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 0.25rem;
  font-weight: 600;
}

.chat-input-bar {
  padding: 0.8rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: #ffffff;
  flex-shrink: 0;
}

.chat-input-field {
  flex: 1;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0.65rem 1.15rem;
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
  background: #f8fafc;
}

.chat-input-field:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.chat-send-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.chat-send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Empty chat prompt */
.chat-empty-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  flex: 1;
  color: var(--text-muted);
  text-align: center;
  padding: 2.5rem 1.5rem;
}

.chat-empty-prompt-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  opacity: 0.8;
}

