/* ---- Table alias for compatibility ---- */
.table { width: 100%; border-collapse: collapse; }
.table th { background: #F8FAFC; text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #F8FAFC; }
.table td small { display: block; font-size: 11px; color: var(--text-muted); }
/* ============================================================
   EduSystem – Main Stylesheet
   ============================================================ */

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

:root {
  --primary:     #3B82F6;
  --primary-dk:  #1D4ED8;
  --success:     #10B981;
  --warning:     #F59E0B;
  --danger:      #EF4444;
  --info:        #06B6D4;
  --purple:      #8B5CF6;
  --sidebar-w:   240px;
  --nav-h:       60px;
  --bg:          #F1F5F9;
  --card-bg:     #FFFFFF;
  --text:        #1E293B;
  --text-muted:  #64748B;
  --border:      #E2E8F0;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ---- Layout ------------------------------------------------ */
.main-wrapper { display: flex; min-height: calc(100vh - var(--nav-h)); padding-top: var(--nav-h); }

/* ---- Topnav ------------------------------------------------ */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h);
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 100; box-shadow: var(--shadow);
}
.topnav .brand { font-weight: 700; font-size: 18px; color: var(--primary); text-decoration: none; }
.topnav .nav-right { display: flex; align-items: center; gap: 16px; }
.topnav .nav-user { font-size: 13px; color: var(--text-muted); }

/* ---- Sidebar ----------------------------------------------- */
.sidebar {
  width: var(--sidebar-w); background: #1E293B; color: #CBD5E1;
  height: calc(100vh - var(--nav-h)); position: fixed; top: var(--nav-h);
  overflow-y: auto; padding: 16px 0;
}
.sidebar .menu-label { font-size: 10px; font-weight: 600; letter-spacing: 1px; color: #475569; padding: 12px 20px 4px; text-transform: uppercase; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: #CBD5E1; text-decoration: none; border-radius: 6px; margin: 1px 8px; font-size: 13px; transition: all .15s; }
.sidebar a:hover, .sidebar a.active { background: rgba(255,255,255,.08); color: #fff; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-contact { margin: 18px 12px 0; padding: 16px 18px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; }
.sidebar-contact .menu-label { padding: 0; margin-bottom: 8px; color: #CBD5E1; }
.sidebar-contact-link { display: flex; align-items: center; gap: 10px; color: #E2E8F0; font-size: 13px; text-decoration: none; margin-bottom: 8px; }
.sidebar-contact-link:hover { color: #fff; text-decoration: none; }
.sidebar-contact-link .icon { width: auto; }

/* ---- Content ----------------------------------------------- */
.content { margin-left: var(--sidebar-w); padding: 24px; flex: 1; min-width: 0; }

/* ---- Page header ------------------------------------------ */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 700; color: var(--text); }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---- Cards ------------------------------------------------- */
.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 20px; box-shadow: var(--shadow); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-header a { font-size: 12px; color: var(--primary); text-decoration: none; }
.card-body { padding: 20px; }

/* ---- Stat cards -------------------------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stats-grid.mini .stat-card { padding: 16px 18px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card::before { content:''; position:absolute; top:0; left:0; width:4px; height:100%; border-radius: 4px 0 0 4px; }
.stat-card.blue::before   { background: var(--primary); }
.stat-card.green::before  { background: var(--success); }
.stat-card.purple::before { background: var(--purple); }
.stat-card.orange::before { background: #F97316; }
.stat-card.teal::before   { background: var(--info); }
.stat-card.red::before    { background: var(--danger); }
.stat-card.yellow::before { background: var(--warning); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-icon  { font-size: 22px; margin-bottom: 8px; }

/* ---- Tables ------------------------------------------------ */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #F8FAFC; text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #F8FAFC; }
.data-table td small { display: block; font-size: 11px; color: var(--text-muted); }

/* ---- Badges ----------------------------------------------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.badge-active, .badge-completed { background: #D1FAE5; color: #065F46; }
.badge-pending   { background: #FEF3C7; color: #92400E; }
.badge-suspended, .badge-cancelled { background: #FEE2E2; color: #991B1B; }
.badge-draft     { background: #E0E7FF; color: #3730A3; }
.badge-paid      { background: #D1FAE5; color: #065F46; }
.badge-failed    { background: #FEE2E2; color: #991B1B; }

.role-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.role-admin        { background: #FEE2E2; color: #991B1B; }
.role-manager      { background: #E0E7FF; color: #3730A3; }
.role-teacher      { background: #D1FAE5; color: #065F46; }
.role-student      { background: #DBEAFE; color: #1E40AF; }
.role-school_admin { background: #FEF3C7; color: #92400E; }
.role-marketer     { background: #F3E8FF; color: #6B21A8; }

/* ---- Buttons ---------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; text-decoration: none; transition: all .15s; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-outline   { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: #F8FAFC; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-block     { width: 100%; justify-content: center; }
.btn-sm        { padding: 6px 12px; font-size: 12px; }
.btn-xs        { padding: 4px 8px; font-size: 11px; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }

/* ---- Alerts ----------------------------------------------- */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; display: flex; align-items: center; gap: 12px; }
.alert-danger  { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ---- Toast notifications (in-app popups) ──────────────────*/
.toast-container { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 9999; max-width: 500px; width: 90%; }
.toast-notification { animation: slideDown .3s ease-out; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Forms ------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; color: var(--text); background: #fff; transition: border-color .15s;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-hint   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ---- Auth page -------------------------------------------- */
.auth-body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; border-radius: 14px; padding: 36px 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.15); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 { font-size: 28px; font-weight: 800; color: var(--primary); }
.auth-logo p  { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.auth-links   { text-align: center; margin-top: 16px; font-size: 13px; }
.auth-links a { color: var(--primary); text-decoration: none; }

/* ---- Misc -------------------------------------------------- */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.tables-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.empty-state   { padding: 32px; text-align: center; color: var(--text-muted); font-size: 13px; }
.empty-state a { color: var(--primary); }
.hint          { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ---- Exam grid -------------------------------------------- */
.exam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding: 16px; }
.exam-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; background: #fff; }
.exam-card.locked { opacity: .7; }
.exam-card h4 { font-size: 14px; font-weight: 600; margin: 8px 0; }
.exam-card p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.exam-meta { display: flex; gap: 6px; margin-bottom: 6px; }
.subject-tag, .exam-type-tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: #EFF6FF; color: var(--primary); font-weight: 500; }
.exam-info { display: flex; gap: 10px; font-size: 11px; color: var(--text-muted); margin: 8px 0; flex-wrap: wrap; }
.attempted-badge { color: var(--success); }

/* ---- Groups ----------------------------------------------- */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding: 16px; }
.group-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.group-type-badge { font-size: 10px; font-weight: 600; text-transform: uppercase; background: #EFF6FF; color: var(--primary); padding: 2px 6px; border-radius: 4px; display: inline-block; margin-bottom: 6px; }
.group-card h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.group-card p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.group-stats { display: flex; gap: 10px; font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.group-join-code { font-size: 11px; background: #F8FAFC; padding: 4px 8px; border-radius: 4px; margin-bottom: 8px; }
.group-actions { display: flex; gap: 6px; }
.group-list { padding: 8px 16px; }
.group-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.group-item:last-child { border-bottom: none; }
.group-item strong { font-size: 13px; }
.group-item small { display: block; font-size: 11px; color: var(--text-muted); }

/* ---- Teacher type badge ------------------------------------ */
.teacher-type-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.teacher-type-badge.private { background: #F3E8FF; color: #6B21A8; }
.teacher-type-badge.school  { background: #D1FAE5; color: #065F46; }

/* ---- Marketer -------------------------------------------- */
.referral-code-box { background: #EFF6FF; border: 1px solid #BFDBFE; padding: 10px 16px; border-radius: var(--radius); display: flex; align-items: center; gap: 10px; }
.referral-code-box span { font-size: 12px; color: var(--text-muted); }
.referral-code-box strong { font-size: 18px; font-weight: 700; color: var(--primary); letter-spacing: 2px; }
.level-banner { border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.level-banner.level-bronze   { background: linear-gradient(135deg, #D97706, #F59E0B); color: #fff; }
.level-banner.level-silver   { background: linear-gradient(135deg, #6B7280, #9CA3AF); color: #fff; }
.level-banner.level-gold     { background: linear-gradient(135deg, #B45309, #D97706); color: #fff; }
.level-banner.level-platinum { background: linear-gradient(135deg, #5B21B6, #7C3AED); color: #fff; }
.level-name { font-size: 22px; font-weight: 700; }
.commission-rate { font-size: 14px; opacity: .9; margin-top: 2px; }
.level-progress { flex: 1; min-width: 200px; }
.level-next { font-size: 12px; opacity: .9; margin-bottom: 8px; }
.progress-row { margin-bottom: 6px; font-size: 11px; opacity: .9; }
.progress-bar { height: 6px; background: rgba(255,255,255,.3); border-radius: 3px; margin-top: 3px; }
.progress-fill { height: 100%; background: #fff; border-radius: 3px; }
.level-max { font-size: 16px; font-weight: 600; }
.payout-notice { background: #F0FDF4; border: 1px solid #BBF7D0; padding: 10px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 20px; color: #166534; }
.referral-share { display: flex; gap: 10px; align-items: center; padding: 0 20px 16px; }
.referral-url { background: #F8FAFC; border: 1px solid var(--border); padding: 8px 12px; border-radius: 6px; font-size: 12px; color: var(--text-muted); flex: 1; word-break: break-all; }
.referral-share-card { display: grid; gap: 14px; }
.share-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.share-row input { flex: 1; min-width: 0; }
.share-row button { white-space: nowrap; }
.share-note { font-size: 12px; color: #64748B; }
.subscription-info { background: #EFF6FF; border: 1px solid #BFDBFE; padding: 8px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; display: flex; gap: 16px; align-items: center; }
.subscription-cta { justify-content: space-between; }

/* ---- Responsive ------------------------------------------ */
@media (max-width: 1024px) {
  .tables-row { grid-template-columns: 1fr; }
  .sidebar { width: 200px; }
  .content { margin-left: 200px; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .form-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root {
    --sidebar-w: 0;
    --nav-h: 56px;
  }
  
  /* Topnav */
  .topnav { padding: 0 16px; }
  .topnav .brand { font-size: 16px; }
  .topnav .nav-right { gap: 12px; }
  
  /* Sidebar */
  .sidebar {
    display: none;
    width: 260px;
    height: calc(100vh - var(--nav-h));
    position: fixed;
    top: var(--nav-h);
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 99;
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .sidebar.open {
    display: block !important;
    transform: translateX(0) !important;
  }
  
  /* Content */
  .main-wrapper { padding-top: var(--nav-h); }
  .content { margin-left: 0; padding: 16px; }
  
  /* Page Header */
  .page-header { flex-direction: column; gap: 12px; }
  .page-header h2 { font-size: 18px; }
  .header-actions { width: 100%; }
  
  /* Cards */
  .card { margin-bottom: 16px; }
  .card-body { padding: 16px; }
  
  /* Stats Grid */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 11px; }
  
  /* Tables */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 10px 8px; }
  .data-table th { font-size: 10px; }
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  
  .tabs { flex-direction: column; align-items: stretch; }
  .tab-btn { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .target-form .form-row { grid-template-columns: 1fr; }
  .leaderboard-item { flex-direction: column; align-items: flex-start; }
  .leaderboard-item .avatar { margin-right: 0; margin-bottom: 0.75rem; }
  .leaderboard-item .score { width: 100%; text-align: left; }
  .tips-grid { grid-template-columns: 1fr; }
  
  /* Forms */
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; gap: 12px; }
  .form-group { margin-bottom: 12px; }
  .form-group label { font-size: 12px; margin-bottom: 4px; }
  .form-group input, .form-group select, .form-group textarea {
    padding: 8px 10px;
    font-size: 12px;
  }
  
  /* Buttons */
  .btn { padding: 8px 12px; font-size: 12px; }
  .btn-block { width: 100%; }
  .quick-actions { gap: 6px; }
  
  /* Modals */
  .modal-content { width: 95%; max-width: 100%; margin: 30% auto; }
  .modal-header { padding: 16px; }
  .modal-header h3 { font-size: 16px; }
  
  /* Exam Grid */
  .exam-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; padding: 12px; }
  .exam-card { padding: 12px; }
  .exam-card h4 { font-size: 13px; }
  .exam-card p { font-size: 11px; }
  
  /* Group Grid */
  .group-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 12px; }
  .group-card { padding: 12px; }
  .group-card h4 { font-size: 13px; }
  
  /* Auth */
  .auth-card { padding: 24px 20px; max-width: 100%; margin: 16px; }
  .auth-logo h1 { font-size: 24px; }
  
  /* Alerts */
  .alert { font-size: 12px; padding: 10px 12px; margin-bottom: 12px; }
  
  /* Toast Notifications */
  .toast-container { width: 95%; top: 66px; }
}

@media (max-width: 480px) {
  :root {
    --nav-h: 50px;
  }
  
  /* Topnav */
  .topnav {
    padding: 0 12px;
    height: var(--nav-h);
  }
  .topnav .brand { font-size: 14px; }
  .topnav .nav-right { gap: 8px; }
  .topnav .nav-user { display: none; }
  
  /* Sidebar */
  .sidebar { width: 280px; }
  .main-wrapper { flex-direction: column; }
  
  /* Content */
  .content { padding: 12px; }
  
  /* Page Header */
  .page-header { margin-bottom: 16px; }
  .page-header h2 { font-size: 16px; }
  .page-header p { font-size: 12px; }
  
  /* Stats Grid */
  .stats-grid { grid-template-columns: 1fr; gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 18px; }
  .stat-icon { font-size: 18px; }
  
  /* Cards */
  .card { margin-bottom: 12px; border-radius: 8px; }
  .card-header { padding: 12px 14px; }
  .card-header h3 { font-size: 14px; }
  .card-body { padding: 14px; }
  
  /* Tables */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { width: 100%; min-width: 720px; font-size: 12px; }
  .data-table th, .data-table td { white-space: nowrap; }
  .data-table th { font-size: 11px; }
  .data-table td { padding: 10px 12px; }
  .data-table th, .data-table td { border-bottom: 1px solid var(--border); }

  /* Performance tabs */
  .tabs { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem; }
  .tab-btn { min-width: 120px; }
  
  .table-responsive { overflow-x: auto; }
  .data-table { min-width: 100%; }
  canvas { max-width: 100% !important; height: auto !important; }
  
  /* Forms */
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .form-group { margin-bottom: 12px; }
  .form-group label { font-size: 12px; }
  .form-group input, .form-group select, .form-group textarea {
    padding: 10px 10px;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 6px;
  }
  .form-group input[type="checkbox"],
  .form-group input[type="radio"] {
    width: auto;
    margin-right: 8px;
  }
  
  /* Buttons */
  .btn {
    padding: 10px 14px;
    font-size: 13px;
    border-radius: 6px;
    width: 100%;
    justify-content: center;
  }
  .btn-sm { padding: 8px 12px; font-size: 11px; width: auto; }
  .btn-xs { padding: 6px 10px; font-size: 10px; width: auto; }
  .quick-actions { flex-direction: column; gap: 8px; }
  .quick-actions .btn { width: 100%; }
  
  /* Modals */
  .modal-content {
    width: 95%;
    max-width: 95%;
    margin: 20% auto;
    border-radius: 12px;
  }
  .modal-header { padding: 14px; }
  .modal-header h3 { font-size: 15px; }
  .close { font-size: 20px; }
  
  /* Badge */
  .badge { font-size: 10px; padding: 2px 6px; }
  .role-badge { font-size: 10px; padding: 2px 6px; }
  
  /* Exam Grid */
  .exam-grid { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  .exam-card { padding: 12px; }
  .exam-card h4 { font-size: 14px; margin: 6px 0; }
  
  /* Group Grid */
  .group-grid { grid-template-columns: 1fr; gap: 10px; }
  .group-card { padding: 12px; }
  
  /* Auth */
  .auth-card { padding: 20px 16px; }
  .auth-logo h1 { font-size: 20px; }
  .auth-links { font-size: 12px; }
  
  /* Alerts */
  .alert { font-size: 11px; padding: 8px 10px; }
  
  /* Header Actions */
  .header-actions { gap: 6px; }
  .header-actions .btn { margin: 0; }
  
  /* Dropdown */
  .user-dropdown { min-width: 180px; right: -8px; top: calc(100% + 4px); }
  .ud-header { padding: 10px 12px; }
  .user-dropdown a { padding: 8px 12px; font-size: 12px; }
  
  /* Level Banner */
  .level-banner {
    flex-direction: column;
    text-align: center;
    padding: 16px 12px;
    gap: 12px;
  }
  .level-banner .level-progress { min-width: 100%; }
  .level-name { font-size: 18px; }
  .commission-rate { font-size: 12px; }
  
  /* Subscription Info */
  .subscription-info { flex-direction: column; gap: 10px; padding: 10px 12px; }
  
  /* Referral */
  .referral-code-box {
    flex-direction: column;
    align-items: center;
    padding: 12px;
  }
  .referral-code-box strong { font-size: 16px; }
  .referral-url { width: 100%; }
  
  /* Tables Row */
  .tables-row { grid-template-columns: 1fr; }
  
  /* Empty State */
  .empty-state { padding: 24px 16px; }
  .empty-state a { font-size: 12px; }
}

@media (max-width: 360px) {
  :root {
    --nav-h: 48px;
  }
  
  .topnav { padding: 0 10px; }
  .topnav .brand { font-size: 13px; }
  .content { padding: 10px; }
  .stat-card { padding: 10px; }
  .stat-value { font-size: 16px; }
  .page-header h2 { font-size: 15px; }
  .card-body { padding: 12px; }
  .btn { padding: 9px 12px; font-size: 12px; }
  .modal-content { margin: 15% auto; }
  .auth-card { padding: 18px 14px; }
  .auth-logo h1 { font-size: 18px; }
}

/* ── Nav extras ─────────────────────────────────────────── */
.sidebar-toggle { background:none; border:none; cursor:pointer; font-size:20px; color:#1E293B; padding:4px 8px; display:none; }
@media (max-width: 768px) {
  .sidebar-toggle { display: block; }
}
.sidebar-backdrop {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    z-index: 95;
    pointer-events: none;
}
.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.nav-notif-btn  { position:relative; background:none; border:none; cursor:pointer; font-size:20px; padding:4px 8px; text-decoration:none; color:#1E293B; }
.notif-badge {
    position:absolute; top:0; right:0;
    background:#EF4444; color:#fff;
    font-size:10px; font-weight:700; min-width:16px; height:16px;
    border-radius:8px; display:inline-flex; align-items:center; justify-content:center;
    padding:0 3px;
}
.nav-user-wrap {
    display:flex; align-items:center; gap:6px; cursor:pointer;
    padding:6px 10px; border-radius:8px; position:relative;
    user-select:none;
}
.nav-user-wrap:hover { background:#F1F5F9; }
.nav-role-icon { font-size:18px; }

.nav-username  { font-size:13px; font-weight:600; color:#1E293B; }
.nav-chevron   { font-size:10px; color:#94A3B8; }
.user-dropdown {
    position:absolute; top:calc(100% + 6px); right:0;
    background:#fff; border:1px solid #E2E8F0; border-radius:10px;
    box-shadow:0 8px 24px rgba(0,0,0,.12); min-width:200px;
    z-index:200; display:none; overflow:hidden;
}
.user-dropdown.open { display:block; }
.ud-header { padding:12px 14px; border-bottom:1px solid #F1F5F9; }
.ud-header strong { display:block; font-size:13px; color:#1E293B; }
.ud-role { font-size:11px; color:#94A3B8; }
.user-dropdown a { display:block; padding:9px 14px; font-size:13px; color:#1E293B; text-decoration:none; }
.user-dropdown a:hover { background:#F8FAFC; }
.ud-divider { height:1px; background:#F1F5F9; margin:4px 0; }
.ud-logout { color:#EF4444 !important; }


/* ── Utility classes for mobile ────────────────────────────── */
.hide-mobile { display: block; }
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}

.show-mobile { display: none; }
@media (max-width: 768px) {
  .show-mobile { display: block !important; }
}

.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-break { word-break: break-word; }

/* ── Mobile-friendly spacing ───────────────────────────────── */
@media (max-width: 768px) {
  .gap-lg { gap: 12px !important; }
  .p-lg { padding: 12px !important; }
  .m-lg { margin: 12px !important; }
}

/* ── 403 / 404 pages ────────────────────────────────────── */
.error-page { min-height:100vh; display:flex; align-items:center; justify-content:center; text-align:center; padding:24px; }
.error-box  { max-width:420px; }
.error-box h1 { font-size:72px; font-weight:900; color:#E2E8F0; margin-bottom:0; }
.error-box h2 { font-size:22px; font-weight:700; color:#1E293B; margin-bottom:8px; }
.error-box p  { font-size:14px; color:#64748B; margin-bottom:20px; }

/* ── Session timeout modal ────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}

.timeout-modal {
    background: #fff; border-radius: 12px;
    padding: 0; width: 100%; max-width: 450px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    animation: modalFadeIn .3s ease-out;
}

.timeout-modal .modal-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--warning), #FCD34D);
    color: #92400E; border-radius: 12px 12px 0 0;
}

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

.timeout-modal .modal-body {
    padding: 24px;
    text-align: center;
}

.timeout-modal .modal-body p {
    font-size: 15px; color: var(--text); margin-bottom: 8px; line-height: 1.5;
}

.timeout-modal .modal-body strong {
    color: var(--danger); font-weight: 700;
}

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

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(.9); }
    to { opacity: 1; transform: scale(1); }
}