:root {
  --bg: #0f1117; --surface: #171a23; --surface-2: #1e222e;
  --text: #e8ebf2; --muted: #8b93a7; --border: #272c3a;
  --primary: #5b6cff; --primary-hover: #7a88ff;
  --success: #22c55e; --danger: #ef4444; --warning: #f59e0b;
  --radius: 10px; --gap: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
       background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 26px; margin: 0 0 20px; }
h2 { font-size: 18px; margin: 0 0 14px; }
.app-body, .admin-body { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border);
           padding: 22px 16px; display: flex; flex-direction: column; gap: 18px;
           position: sticky; top: 0; height: 100vh; }
.sidebar .brand { font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.content { padding: 28px 34px; max-width: 1240px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 20px; margin-bottom: var(--gap); }
.grid { display: grid; gap: var(--gap); margin-bottom: var(--gap); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { font-size: 26px; font-weight: 700; }
.btn { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
       background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 500;
       transition: .15s; font-size: 14px; text-decoration: none; display: inline-block; }
.btn:hover { background: #262b3a; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.danger { color: var(--danger); border-color: var(--danger); }
.form label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.form input, .form select, .form textarea,
.text-input, select, input[type=text], input[type=email], input[type=password], input[type=number], input[type=color] {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; margin-top: 6px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; margin: 0; }
.exam { display: flex; flex-direction: column; height: calc(100vh - 56px); gap: 14px; }
.exam-header { display: flex; align-items: center; justify-content: space-between; }
.exam-timer { font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 700;
              padding: 6px 14px; background: var(--surface); border-radius: 8px; border: 1px solid var(--border); }
.exam-timer.warning { color: var(--warning); border-color: var(--warning); }
.exam-body { display: grid; grid-template-columns: 220px 1fr; gap: 18px; flex: 1; min-height: 0; }
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; align-content: start;
           background: var(--surface); padding: 14px; border-radius: var(--radius);
           border: 1px solid var(--border); overflow-y: auto; }
.palette-btn { aspect-ratio: 1; border-radius: 6px; border: 1px solid var(--border);
               background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 13px; }
.palette-btn.answered { background: var(--success); border-color: var(--success); color: #06240f; font-weight: 700; }
.palette-btn.flagged  { outline: 2px solid var(--warning); }
.palette-btn.current  { box-shadow: 0 0 0 2px var(--primary); }
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
         padding: 26px; overflow-y: auto; }
.q-stem { font-size: 19px; line-height: 1.5; margin: 14px 0 22px; }
.q-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.opt { display: flex; align-items: center; gap: 12px; padding: 12px 14px;
       border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; cursor: pointer; }
.opt:hover { background: var(--surface-2); }
.opt input { width: auto; margin: 0; }
.opt-label { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
             background: var(--surface-2); font-weight: 700; font-size: 13px; }
.q-actions { display: flex; gap: 10px; margin-top: 20px; }
.exam-footer { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.q-media { max-width: 100%; border-radius: 8px; margin: 10px 0; }
.q-code { background: #0a0d13; padding: 16px; border-radius: 8px; overflow-x: auto;
          border: 1px solid var(--border); font-size: 13px; }
.review { border-left: 3px solid var(--border); padding: 12px 16px; margin-bottom: 14px; }
.review.correct   { border-left-color: var(--success); }
.review.incorrect { border-left-color: var(--danger); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid var(--danger); }
.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-card { background: var(--surface); padding: 38px; border-radius: 14px;
             border: 1px solid var(--border); width: min(420px, 92vw); }
.builder { display: grid; grid-template-columns: 220px 1fr; gap: 20px; margin-bottom: 20px; }
.palette-types { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.palette-types li { padding: 10px 12px; background: var(--surface-2);
                    border: 1px dashed var(--border); border-radius: 8px; cursor: grab; font-size: 13.5px; }
.builder-canvas { min-height: 220px; border: 2px dashed var(--border); border-radius: var(--radius); padding: 14px; }
.q-block { background: var(--surface-2); padding: 14px; border-radius: 8px;
           margin-bottom: 12px; border: 1px solid var(--border); }
.q-block header { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.q-block .q-stem { font-size: 14px; margin: 0 0 10px; }
.q-opt { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.q-opt .opt-correct { width: auto; }
.q-score { display: flex; gap: 12px; align-items: center; font-size: 13px;
           color: var(--muted); margin-top: 10px; }
.q-score input { width: 80px; margin: 0; }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--surface-2);
         font-size: 12px; color: var(--muted); border: 1px solid var(--border); margin-right: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
@media (max-width: 860px) {
  .app-body, .admin-body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .exam-body { grid-template-columns: 1fr; }
  .builder { grid-template-columns: 1fr; }
}


/* =========================================
   Advanced Dashboard UI
   ========================================= */

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn 0.4s ease-out forwards; }
.animate-slide-up { animation: slideUp 0.5s ease-out forwards; opacity: 0; }

/* Typography & Colors */
.text-gradient {
  background: linear-gradient(135deg, #7a88ff, #22c55e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }

/* Dashboard Header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.welcome-text { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }

/* Tier Badge */
.tier-badge {
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.tier-bronze { background: linear-gradient(135deg, #cd7f32, #8b4513); color: #fff; }
.tier-silver { background: linear-gradient(135deg, #bdc3c7, #7f8c8d); color: #fff; }
.tier-gold { background: linear-gradient(135deg, #f1c40f, #d4af37); color: #111; }
.tier-platinum { background: linear-gradient(135deg, #e0e0e0, #95a5a6); color: #111; }
.tier-diamond, .tier-grandmaster { background: linear-gradient(135deg, #00c6ff, #0072ff); color: #fff; }

/* KPI Cards Enhancements */
.kpi-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}
.kpi-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border-color: #3b4256;
}
.kpi-icon {
  font-size: 32px;
  background: var(--surface-2);
  padding: 12px;
  border-radius: 12px;
  line-height: 1;
}
.kpi-content { display: flex; flex-direction: column; flex: 1; }
.kpi-content span { color: var(--muted); font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-content strong { font-size: 24px; font-weight: 800; margin: 4px 0; }

/* XP Progress Bar */
.xp-progress-wrapper {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}
.xp-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #5b6cff, #7a88ff, #22c55e);
  border-radius: 4px;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(122, 136, 255, 0.5);
}

/* Main Dashboard Split Grid */
.dashboard-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 960px) {
  .dashboard-split { grid-template-columns: 1fr; }
}

.content-card { display: flex; flex-direction: column; }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* Activity List */
.activity-list { display: flex; flex-direction: column; gap: 12px; }
.activity-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.activity-item:hover { border-color: var(--border); }
.activity-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: bold; font-size: 16px;
}
.activity-icon.success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.activity-icon.danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.activity-details { flex: 1; display: flex; flex-direction: column; }
.activity-details strong { font-size: 15px; }
.activity-score { display: flex; align-items: center; gap: 16px; font-size: 15px; font-weight: 600; }

/* Badges Grid */
.badges-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .badges-grid { grid-template-columns: 1fr; } }
.badge-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: help;
  transition: transform 0.2s;
}
.badge-item:hover { transform: scale(1.02); border-color: #5b6cff; }
.badge-icon { font-size: 24px; }
.badge-info { display: flex; flex-direction: column; }
.badge-info strong { font-size: 14px; }
.badge-info small { color: var(--muted); font-size: 12px; }

/* Empty States */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px dashed var(--border);
}
.empty-state p { margin-bottom: 16px; }

/* Tooltip implementation */
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: #000; color: #fff;
  padding: 6px 12px; border-radius: 6px;
  font-size: 12px; white-space: nowrap;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: all 0.2s ease;
  z-index: 10;
}
.tooltip:hover::after { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-4px); }


/* =========================================
   Advanced Sidebar & Layout
   ========================================= */

/* Base App Layout */
.app-body {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: rgba(15, 17, 23, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}
.menu-btn {
  background: transparent; border: none; color: var(--text);
  font-size: 24px; cursor: pointer;
}

/* Sidebar Base (Desktop) */
.sidebar {
  width: 280px;
  background: rgba(23, 26, 35, 0.6);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  position: fixed;
  height: 100vh;
  z-index: 90;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.brand-container {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 32px;
}
.brand { font-size: 22px; font-weight: 900; letter-spacing: -0.5px; color: var(--text); }
.close-btn { display: none; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }

/* Navigation Links */
.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateX(4px);
}
.nav-icon { font-size: 18px; }

/* Active State with Glow */
.nav-link.active {
  background: linear-gradient(90deg, rgba(91, 108, 255, 0.15), transparent);
  color: var(--primary);
  font-weight: 700;
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 12px var(--primary);
}

/* User Card in Sidebar */
.sidebar-user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-top: auto;
  margin-bottom: 16px;
}
.user-info { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar, .avatar-fallback {
  width: 42px; height: 42px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--border);
}
.avatar-fallback {
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  font-weight: bold; font-size: 18px;
}
.user-details { display: flex; flex-direction: column; }
.user-details strong { font-size: 15px; line-height: 1.2; }
.level-badge {
  font-size: 11px; background: var(--surface-2); padding: 2px 8px;
  border-radius: 12px; width: fit-content; margin-top: 4px; color: var(--muted);
}

/* Mini XP Bar */
.mini-xp-bar {
  width: 100%; height: 6px; background: var(--surface-2);
  border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.mini-xp-fill {
  height: 100%; background: linear-gradient(90deg, #5b6cff, #22c55e);
  border-radius: 3px; transition: width 0.5s ease;
}
.user-stats {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); font-weight: 600;
}

.btn-logout {
  width: 100%; display: flex; align-items: center; gap: 12px;
  justify-content: flex-start; padding: 12px 16px; color: var(--danger);
}
.btn-logout:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* Content Area */
.content {
  flex: 1;
  margin-left: 280px; /* Push content past the fixed sidebar */
  padding: 32px 40px;
  min-width: 0; /* Prevents overflow issues */
}

/* Overlay for Mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  z-index: 80; opacity: 0; transition: opacity 0.3s;
}

/* Mobile Responsive Fixes */
@media (max-width: 860px) {
  .mobile-header { display: flex; }
  
  .content {
    margin-left: 0;
    padding: 80px 16px 24px; /* 80px top padding for mobile header */
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  
  .close-btn { display: block; }
  
  .sidebar-overlay.open {
    display: block; opacity: 1;
  }
}

.grid-2 { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: var(--gap); 
  margin-bottom: var(--gap); 
}
@media (max-width: 960px) { 
  .grid-2 { grid-template-columns: 1fr; } 
}

/* =========================================
   Mobile Exam View Fixes
   ========================================= */
@media (max-width: 860px) {
  .exam { height: auto; min-height: 100vh; display: flex; flex-direction: column; }
  .exam-header { 
    flex-direction: column; 
    align-items: flex-start; 
    gap: 10px; 
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
  }
  .exam-header h1 { font-size: 20px; margin: 0; width: 100%; }
  
  .exam-timer { 
    position: absolute; 
    top: 15px; 
    right: 15px; 
    font-size: 16px; 
    padding: 4px 10px; 
  }
  
  .exam-progress { font-size: 13px; font-weight: 600; color: var(--muted); }
  
  .exam-body { 
    grid-template-columns: 1fr; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    flex: 1;
  }
  
  /* Make palette horizontal on mobile */
  .palette { 
    display: flex; 
    flex-wrap: nowrap; 
    overflow-x: auto; 
    padding: 10px; 
    gap: 8px; 
    border-radius: 8px;
    scrollbar-width: none; /* Hide scrollbar Firefox */
  }
  .palette::-webkit-scrollbar { display: none; } /* Hide scrollbar Chrome */
  
  .palette-btn { 
    min-width: 40px; 
    min-height: 40px; 
    flex-shrink: 0; 
  }
  
  .stage { padding: 15px; }
  .q-stem { font-size: 16px; }
  .opt { padding: 10px; font-size: 14px; }
  
  /* Fix bottom buttons */
  .exam-footer { 
    flex-wrap: wrap; 
    justify-content: space-between; 
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 15px 0;
    margin-top: auto;
    z-index: 10;
  }
  .exam-footer .btn { flex: 1; text-align: center; justify-content: center; font-size: 13px; padding: 10px 5px; }
  .exam-footer form { width: 100%; margin-top: 10px; }
  .exam-footer form .btn { width: 100%; }
}


/* =========================================
   FIXED LAYOUT & SIDEBAR
   ========================================= */

body.app-body {
  display: block; /* Important: Removes grid/flex that breaks mobile layout */
  margin: 0;
  padding: 0;
  background: var(--bg);
}

/* --- Mobile Top Header --- */
.mobile-header {
  display: none; /* Hidden on Desktop */
}

/* --- Sidebar (Desktop) --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  z-index: 1000;
  transform: translateX(0);
  transition: transform 0.3s ease-in-out;
}

/* --- Main Content --- */
.content {
  margin-left: 280px; /* Push content to the right on desktop */
  padding: 30px 40px;
  min-height: 100vh;
  box-sizing: border-box;
}

/* --- Sidebar Overlay --- */
.sidebar-overlay {
  display: none;
}

/* --- Mobile Styles --- */
@media (max-width: 860px) {
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1001;
  }

  /* Fix white buttons */
  .mobile-btn {
    background: transparent !important;
    border: none !important;
    color: var(--text) !important;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .close-btn {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%); /* Hide sidebar off-screen */
    z-index: 1002;
    background: var(--surface);
    box-shadow: 5px 0 25px rgba(0,0,0,0.5);
  }
  
  .sidebar.open {
    transform: translateX(0); /* Slide in */
  }

  .content {
    margin-left: 0;
    padding: 80px 16px 24px; /* 80px padding top for fixed header */
  }

  .sidebar-overlay.open {
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1001;
    opacity: 1;
  }
}

/* =========================================
   MODERN PREMIUM SIDEBAR UI
   ========================================= */

body.app-body {
  display: block;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* --- Mobile Top Header --- */
.mobile-header {
  display: none; /* Hidden on desktop */
}

/* Icon Buttons (Fixes white boxes) */
.icon-btn {
  background: transparent !important;
  color: var(--text) !important;
  border: none !important;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: var(--surface-2) !important;
}

/* --- Sidebar Base (Desktop) --- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 280px;
  background: rgba(23, 26, 35, 0.98);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  z-index: 1000;
}

.brand-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}
.brand {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--text);
}
.close-btn {
  display: none; /* Hide on desktop */
}

/* --- Navigation Links --- */
.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
  transition: all 0.2s ease;
  position: relative;
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-icon { font-size: 18px; }

/* Glowing Active State */
.nav-link.active {
  background: linear-gradient(90deg, rgba(91, 108, 255, 0.15), transparent);
  color: var(--primary);
  font-weight: 700;
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 10%; bottom: 10%;
  width: 4px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 12px var(--primary);
}

/* --- User Card --- */
.sidebar-user-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-top: auto;
  margin-bottom: 16px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.avatar, .avatar-fallback {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid var(--border);
  object-fit: cover;
}
.avatar-fallback {
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-weight: bold; font-size: 18px;
}
.user-details { display: flex; flex-direction: column; }
.user-details strong { font-size: 15px; }
.level-badge {
  font-size: 11px; background: rgba(255,255,255,0.1);
  padding: 2px 8px; border-radius: 12px;
  width: fit-content; margin-top: 4px; color: var(--muted);
}

.mini-xp-bar {
  width: 100%; height: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.mini-xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #5b6cff, #22c55e);
  border-radius: 3px;
}
.user-stats {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); font-weight: 600;
}

.btn-logout {
  width: 100%; display: flex; align-items: center; gap: 12px;
  justify-content: flex-start; padding: 12px 16px; color: var(--danger);
  border-radius: 10px;
}
.btn-logout:hover { background: rgba(239, 68, 68, 0.1); }

/* --- Main Content --- */
.content {
  margin-left: 280px; /* Push content on Desktop */
  padding: 32px 40px;
  min-height: 100vh;
  box-sizing: border-box;
}

/* --- Overlay --- */
.sidebar-overlay {
  display: none;
}

/* =========================================
   MOBILE SPECIFIC (Drawer & Glassmorphism)
   ========================================= */
@media (max-width: 860px) {
  .mobile-header {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 900; /* Below the drawer */
  }

  .content {
    margin-left: 0;
    padding: 80px 16px 24px; /* 80px top for header */
  }

  .sidebar {
    transform: translateX(-100%); /* Hide off-screen */
    z-index: 1002; /* Above header */
    background: rgba(23, 26, 35, 0.85); /* Glass effect */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255,255,255,0.05);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }

  .close-btn {
    display: flex;
  }

  .sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 1001;
    opacity: 1;
    transition: opacity 0.3s ease;
  }
}


/* Admin Tables Mobile Scroll */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  min-width: 600px; /* Force table to not squish */
}


/* =========================================
   ADMIN ADVANCED UI STYLES
   ========================================= */

.admin-page-header {
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}
.admin-page-header h1 {
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 4px 0;
  letter-spacing: -0.5px;
}
.admin-page-header p {
  margin: 0;
  font-size: 14px;
}

/* Responsive Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.table {
  min-width: 700px; /* Prevents squishing on mobile */
  margin: 0;
}
.table th {
  background: var(--surface-2);
  font-weight: 600;
  padding: 14px 16px;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 14px 16px;
  vertical-align: middle;
}

/* Form Improvements */
.form input, .form select, .form textarea {
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,108,255,0.2);
}

/* =========================================
   FINAL FIX: MOBILE HAMBURGER & SIDEBAR
   ========================================= */

/* 1. Mobile Header (Sirf mobile par dikhega) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1001; /* Header ke upar */
}

/* 2. Hamburger aur Close buttons ka style (White box fix) */
.icon-btn {
  background: transparent !important;
  border: none !important;
  color: var(--text) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: var(--surface-2) !important;
}

/* 3. Sidebar (Desktop) */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  z-index: 1002; /* Sabse upar */
  transition: transform 0.3s ease;
}
.content {
  margin-left: 280px;
  padding: 32px 40px;
  min-height: 100vh;
}

/* 4. Sidebar Overlay (Piche ka black background) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.open {
  display: block;
  opacity: 1;
}

/* 5. Mobile Specific Drawer Effect */
@media (max-width: 860px) {
  .mobile-header {
    display: flex;
  }
  .content {
    margin-left: 0;
    padding: 80px 16px 24px; /* 80px padding top for header */
  }
  .sidebar {
    transform: translateX(-100%); /* Chhup jayega left side */
    background: rgba(23, 26, 35, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  }
  .sidebar.open {
    transform: translateX(0); /* Khul jayega */
  }
  .close-btn {
    display: flex; /* Mobile par close button dikhega */
  }
  .brand-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
  }
}

