/* =========================================================
   EDUQUEST - MODERN EDUCATIONAL LMS DESIGN SYSTEM
   ========================================================= */

:root {
  --bg-body: #0b1120;
  --bg-sidebar: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #24344d;
  --bg-input: #0f172a;
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-primary-glow: rgba(99, 102, 241, 0.35);
  
  --accent-teal: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-light: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Base Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-light);
}

.logo-badge {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}

.logo-text h1 {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text span {
  font-size: 11px;
  color: var(--accent-teal);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav-item:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: #ffffff;
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  font-weight: 600;
}

.nav-item .icon {
  font-size: 18px;
  width: 24px;
  display: flex;
  justify-content: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-light);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-light);
}

.user-avatar {
  font-size: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  font-size: 11px;
  color: var(--accent-teal);
  font-weight: 500;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  font-size: 16px;
  border-radius: 6px;
  transition: color 0.2s;
}

.btn-logout:hover {
  color: var(--accent-rose);
}

/* Main Content Area */
.main-wrapper {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-navbar {
  height: 70px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.page-title-box h2 {
  font-size: 20px;
  font-weight: 700;
}

.page-title-box p {
  font-size: 12px;
  color: var(--text-secondary);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.content-container {
  padding: 32px;
  flex: 1;
  max-width: 1300px;
  width: 100%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-purple));
  color: white;
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-color: var(--border-light);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-teal {
  background: linear-gradient(135deg, var(--accent-teal), #0284c7);
  color: white;
}

.btn-emerald {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  color: white;
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Cards & Widgets */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
  position: relative;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Stat Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s ease;
}

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

.stat-icon-box {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stat-icon-box.purple { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.stat-icon-box.blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.stat-icon-box.emerald { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.stat-icon-box.amber { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

.stat-val {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 2px;
}

.stat-lbl {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}

/* Badges and Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-danger { background: rgba(244, 63, 94, 0.15); color: #fb7185; border: 1px solid rgba(244, 63, 94, 0.3); }
.badge-primary { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.badge-secondary { background: rgba(255, 255, 255, 0.08); color: var(--text-secondary); border: 1px solid var(--border-light); }

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.edu-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.edu-table th {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
}

.edu-table td {
  padding: 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}

.edu-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-backdrop.active .modal-container {
  transform: scale(1);
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close-btn:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Game Player Fullscreen Overlay */
.player-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000000;
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.player-topbar {
  height: 56px;
  background: #0f172a;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.player-frame {
  flex: 1;
  width: 100%;
  border: none;
}

/* Toast Notifications */
.toast-box {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--accent-emerald); }
.toast.error { border-left: 4px solid var(--accent-rose); }
.toast.info { border-left: 4px solid var(--accent-primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Quick User Switcher */
.demo-pill {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-light);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.demo-pill:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
}

/* Level & Streak Widget for Students */
.student-rank-bar {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(168, 85, 247, 0.2));
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

/* ========================================== */
/* CHAT SYSTEM & MESSAGING UI                 */
/* ========================================== */
.chat-container {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  height: calc(100vh - 180px);
  min-height: 500px;
  overflow: hidden;
}

.chat-sidebar {
  width: 320px;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.6);
}

.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.chat-user-list {
  flex: 1;
  overflow-y: auto;
}

.chat-user-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: background 0.2s;
}

.chat-user-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-user-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-left: 3px solid var(--accent-primary);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0f172a;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.5);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 75%;
}

.chat-msg.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg.received {
  align-self: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.chat-msg.sent .chat-bubble {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.chat-msg.received .chat-bubble {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 2px;
}

.chat-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-msg.sent .chat-time {
  justify-content: flex-end;
}

.chat-input-bar {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 12px;
  background: rgba(30, 41, 59, 0.7);
}

.chat-input-bar input {
  flex: 1;
  background: #0b1120;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 10px 16px;
  color: #ffffff;
  font-size: 14px;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--accent-primary);
}

/* Avatar Upload styling */
.avatar-picker-preview {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid var(--accent-primary);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
  margin: 0 auto 16px;
}

/* ========================================== */
/* RESPONSIVE & MOBILE ADAPTATION             */
/* ========================================== */
.mobile-menu-btn {
  display: none;
  font-size: 18px;
  padding: 6px 12px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 95;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  }

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

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

  .main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 100% !important;
  }

  .top-navbar {
    padding: 0 16px;
    height: 60px;
  }

  .page-title-box p {
    display: none;
  }

  .page-title-box h2 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
  }

  .content-container {
    padding: 16px 12px;
  }

  .student-rank-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
  }

  .student-rank-bar > div {
    width: 100%;
    justify-content: space-between;
  }

  .grid-2, .grid-3, .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .modal-container {
    width: 95% !important;
    max-width: 95% !important;
    max-height: 92vh !important;
    padding: 16px;
    margin: 8px auto;
  }

  #insp-metrics-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .chat-container {
    height: calc(100dvh - 160px);
    min-height: 420px;
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100% !important;
    max-height: 160px;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
  }

  .chat-msg {
    max-width: 90%;
  }

  .chat-input-bar {
    padding: 10px 12px;
  }

  .chat-input-bar input {
    font-size: 14px;
    padding: 8px 12px;
  }

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table, .edu-table {
    min-width: 520px;
  }

  /* Player topbar on mobile */
  .player-topbar {
    padding: 8px 12px;
  }

  .player-topbar #player-title {
    font-size: 13px !important;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .player-topbar #player-mode-badge {
    display: none;
  }
}
