/* ============================================================
   SCHOOL EXAM SYSTEM v2 — Global Styles
   ============================================================ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #7c3aed;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-width: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #2563eb;
  --topbar-height: 64px;
  --card-radius: 12px;
  --transition: all 0.2s ease;
  --glass-bg: rgba(255,255,255,0.12);
  --glass-border: rgba(255,255,255,0.25);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
[data-bs-theme="dark"] {
  --bs-body-bg: #0f172a;
  --bs-body-color: #e2e8f0;
  --bs-card-bg: #1e293b;
  --bs-border-color: #334155;
}
*, *::before, *::after { box-sizing: border-box; }

/* ============================================================
   AUTH / LOGIN
   ============================================================ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  overflow: hidden;
  background: #0f172a;
}
.auth-bg {
  position: absolute;
  inset: 0;
  background-image: url('https://images.unsplash.com/photo-1546410531-bb4caa6b424d?w=1920&q=80');
  background-size: cover;
  background-position: center;
  filter: blur(2px) brightness(0.35);
  transform: scale(1.05);
  z-index: 0;
}
.auth-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(37,99,235,0.6) 0%, rgba(124,58,237,0.5) 100%);
}
.auth-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
}
.auth-card {
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
  color: #fff;
}
.auth-card .form-control,
.auth-card .input-group-text {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  border-radius: 10px;
}
.auth-card .form-control::placeholder { color: rgba(255,255,255,0.5); }
.auth-card .form-control:focus {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.5);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.1);
  color: #fff;
}
.auth-card .input-group-text { color: rgba(255,255,255,0.7); border-right: none; }
.auth-card .form-label { color: rgba(255,255,255,0.85); font-weight: 600; font-size: .85rem; }
.auth-card h4, .auth-card h5, .auth-card h3 { color: #fff; }
.auth-card .text-muted { color: rgba(255,255,255,0.6) !important; }
.auth-logo-circle {
  width: 80px; height: 80px; border-radius: 50%;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 2rem; color: #fff;
  box-shadow: 0 8px 24px rgba(37,99,235,0.4);
}
.auth-logo-img { height: 80px; max-width: 200px; object-fit: contain; border-radius: 10px; }
.auth-submit-btn {
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  border: none; border-radius: 10px; padding: .75rem;
  font-weight: 700; letter-spacing: .03em;
  box-shadow: 0 4px 15px rgba(37,99,235,0.4);
  transition: all .2s;
}
.auth-submit-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37,99,235,0.5); }
.auth-footer { text-align:center; margin-top:1.5rem; color:rgba(255,255,255,0.5); font-size:.8rem; }
.auth-role-label {
  display: inline-flex; align-items: center; gap: .4rem;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  color: #fff; border-radius: 6px; padding: .3rem .8rem; font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 1.5rem;
}
.auth-back-link { color: rgba(255,255,255,0.7); text-decoration: none; font-size: .8rem; }
.auth-back-link:hover { color: #fff; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed; top: 0; left: 0; height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  overflow-y: auto; overflow-x: hidden;
  z-index: 1040;
  transition: var(--transition);
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--topbar-height);
}
.sidebar-brand img { height: 36px; width: 36px; object-fit: contain; border-radius: 8px; }
.sidebar-brand-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem; flex-shrink: 0;
}
.sidebar-brand-text { color: #fff; font-weight: 700; font-size: .9rem; line-height: 1.2; }
.sidebar-brand-sub { color: var(--sidebar-text); font-size: .7rem; }
.sidebar-nav { padding: .75rem 0; flex: 1; }
.sidebar-section {
  padding: .5rem 1rem .25rem;
  font-size: .6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
  color: #475569;
}
.sidebar-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none; font-size: .855rem;
  transition: var(--transition);
  margin: .1rem .6rem;
  border-radius: 8px;
  position: relative;
}
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #e2e8f0; }
.sidebar-link.active { background: rgba(37,99,235,.2); color: #60a5fa; }
.sidebar-link.active .sidebar-icon { color: #60a5fa; }
.sidebar-link.active::before {
  content: ''; position: absolute; left: -6px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: #2563eb; border-radius: 0 3px 3px 0;
}
.sidebar-icon { width: 18px; text-align: center; font-size: .9rem; flex-shrink: 0; opacity: .8; }
.sidebar-link.active .sidebar-icon { opacity: 1; }
.sidebar-footer { padding: .75rem 1rem; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-user { display: flex; align-items: center; gap: .6rem; }
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-name { color: #fff; font-size: .8rem; font-weight: 600; }
.sidebar-user-role { color: var(--sidebar-text); font-size: .7rem; text-transform: capitalize; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-wrapper { margin-left: var(--sidebar-width); min-height: 100vh; transition: var(--transition); }
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center;
  padding: 0 1.5rem; gap: 1rem;
  position: sticky; top: 0; z-index: 1030;
}
[data-bs-theme="dark"] .topbar { background: #1e293b; border-color: #334155; }
.topbar-title { font-weight: 700; font-size: 1rem; color: #0f172a; margin: 0; }
[data-bs-theme="dark"] .topbar-title { color: #f1f5f9; }
.topbar-spacer { flex: 1; }
.topbar-token-badge {
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  color: #fff; border-radius: 8px; padding: .35rem .9rem;
  font-size: .78rem; font-weight: 600;
  display: flex; align-items: center; gap: .4rem;
}
.page-content { padding: 1.5rem; }
.page-title { font-weight: 800; font-size: 1.25rem; margin-bottom: 1.5rem; display: flex; align-items: center; gap: .5rem; }

/* ============================================================
   CARDS
   ============================================================ */
.stat-card {
  border-radius: var(--card-radius);
  padding: 1.25rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
[data-bs-theme="dark"] .stat-card { background: #1e293b; border-color: #334155; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(0,0,0,.1); }
.stat-card-icon {
  width: 50px; height: 50px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; margin-bottom: .75rem;
}
.stat-card-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-card-label { color: #64748b; font-size: .8rem; margin-top: .3rem; font-weight: 500; }
.stat-card::after {
  content: ''; position: absolute; top: -20px; right: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: rgba(255,255,255,0.05);
}

/* ============================================================
   TABLE CARD
   ============================================================ */
.table-card { background: #fff; border-radius: var(--card-radius); border: 1px solid #e2e8f0; overflow: hidden; }
[data-bs-theme="dark"] .table-card { background: #1e293b; border-color: #334155; }
.table-card-header {
  padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #e2e8f0; background: #fafafa;
}
[data-bs-theme="dark"] .table-card-header { border-color: #334155; background: #161f2e; }
.table-card-title { font-weight: 700; font-size: .95rem; }

/* TABLE RESPONSIVE — ALWAYS */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table th {
  font-size: .75rem; text-transform: uppercase;
  letter-spacing: .06em; font-weight: 700; color: #64748b;
  background: #f8fafc; white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
[data-bs-theme="dark"] .table th { background: #0f172a; color: #94a3b8; }
.table td { vertical-align: middle; font-size: .875rem; }
.table-hover > tbody > tr:hover { background: rgba(37,99,235,.04); }
[data-bs-theme="dark"] .table-hover > tbody > tr:hover { background: rgba(37,99,235,.08); }

/* ============================================================
   BADGES
   ============================================================ */
.badge-active { background: #dcfce7; color: #16a34a; border-radius: 6px; padding: .25rem .65rem; font-size: .72rem; font-weight: 700; }
.badge-inactive { background: #fee2e2; color: #dc2626; border-radius: 6px; padding: .25rem .65rem; font-size: .72rem; font-weight: 700; }
[data-bs-theme="dark"] .badge-active { background: #14532d; color: #4ade80; }
[data-bs-theme="dark"] .badge-inactive { background: #450a0a; color: #f87171; }

/* ============================================================
   DARK TOGGLE
   ============================================================ */
.dark-toggle {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 1px solid #e2e8f0; background: transparent;
  transition: var(--transition); color: #64748b;
}
[data-bs-theme="dark"] .dark-toggle { border-color: #334155; color: #94a3b8; }
.dark-toggle:hover { background: #f1f5f9; color: #0f172a; }
[data-bs-theme="dark"] .dark-toggle:hover { background: #334155; color: #fff; }

/* ============================================================
   MOBILE SIDEBAR
   ============================================================ */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1039; }
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-wrapper { margin-left: 0; }
}

/* ============================================================
   EXAM INTERFACE v2
   ============================================================ */
.exam-topbar {
  background: #0f172a; color: #fff;
  padding: .75rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.exam-topbar-title { font-weight: 700; font-size: .9rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exam-topbar-sub { font-size: .75rem; color: #94a3b8; }
.exam-timer {
  background: #dc2626; color: #fff;
  border-radius: 8px; padding: .4rem .9rem;
  font-size: 1.3rem; font-weight: 800;
  font-family: 'Courier New', monospace; min-width: 90px; text-align: center;
  box-shadow: 0 2px 8px rgba(220,38,38,.4);
  transition: background .3s;
}
.exam-timer.warning { background: #d97706; box-shadow: 0 2px 8px rgba(217,119,6,.4); }
.exam-timer.critical { background: #dc2626; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.7} }
.exam-progress-text { font-size: .8rem; color: #94a3b8; white-space: nowrap; }

.exam-layout { display: flex; min-height: calc(100vh - 60px); }
.exam-nav-panel {
  width: 220px; flex-shrink: 0;
  background: #fff; border-right: 1px solid #e2e8f0;
  position: sticky; top: 60px; height: calc(100vh - 60px);
  overflow-y: auto; padding: 1rem;
}
[data-bs-theme="dark"] .exam-nav-panel { background: #1e293b; border-color: #334155; }
.exam-nav-title { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; margin-bottom: .75rem; }
.q-nav-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.q-nav-btn {
  width: 36px; height: 36px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; cursor: pointer;
  border: 2px solid #e2e8f0; background: #fff; color: #64748b;
  transition: all .15s; text-decoration: none;
}
.q-nav-btn:hover { border-color: #2563eb; color: #2563eb; }
.q-nav-btn.answered { background: #16a34a; color: #fff; border-color: #16a34a; }
.q-nav-btn.current { background: #2563eb; color: #fff; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
.q-nav-btn.unanswered { border-color: #fca5a5; background: #fef2f2; color: #dc2626; }
[data-bs-theme="dark"] .q-nav-btn { background: #334155; border-color: #475569; color: #94a3b8; }
[data-bs-theme="dark"] .q-nav-btn.answered { background: #14532d; border-color: #166534; color: #4ade80; }
[data-bs-theme="dark"] .q-nav-btn.current { background: #2563eb; border-color: #2563eb; color: #fff; }

.exam-legend { font-size: .7rem; color: #64748b; margin-top: .75rem; }
.exam-legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.exam-main { flex: 1; padding: 1.5rem; max-width: 800px; }

.question-block {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 1.5rem; margin-bottom: 1.25rem;
  scroll-margin-top: 70px;
  transition: box-shadow .2s;
}
[data-bs-theme="dark"] .question-block { background: #1e293b; border-color: #334155; }
.question-block.current-q { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.q-number-badge {
  background: #eff6ff; color: #2563eb;
  border-radius: 6px; padding: .2rem .6rem;
  font-size: .75rem; font-weight: 700;
  display: inline-flex; align-items: center; gap: .3rem;
  margin-bottom: .75rem;
}
[data-bs-theme="dark"] .q-number-badge { background: #1e3a5f; }
.q-text { font-size: .95rem; font-weight: 500; margin-bottom: 1rem; line-height: 1.6; }
.q-image { max-height: 200px; border-radius: 8px; margin-bottom: 1rem; }

.option-item { margin-bottom: .5rem; }
.option-item input[type=radio] { display: none; }
.option-label {
  display: flex; align-items: flex-start; gap: .75rem;
  padding: .7rem 1rem; border: 2px solid #e2e8f0; border-radius: 10px;
  cursor: pointer; transition: all .15s; font-size: .9rem;
  line-height: 1.4;
}
.option-label:hover { border-color: #93c5fd; background: #eff6ff; }
.option-item input[type=radio]:checked + .option-label {
  border-color: #2563eb; background: #eff6ff; font-weight: 600; color: #1d4ed8;
}
[data-bs-theme="dark"] .option-label { border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .option-label:hover { border-color: #3b82f6; background: #1e3a5f; }
[data-bs-theme="dark"] .option-item input[type=radio]:checked + .option-label { border-color: #3b82f6; background: #1e3a5f; color: #93c5fd; }
.option-letter {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem;
  background: #e2e8f0; color: #475569;
  transition: all .15s;
}
.option-item input[type=radio]:checked + .option-label .option-letter { background: #2563eb; color: #fff; }

.exam-summary-bar {
  background: #fff; border-top: 1px solid #e2e8f0;
  padding: 1rem 1.5rem; position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 1rem; z-index: 50;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
[data-bs-theme="dark"] .exam-summary-bar { background: #1e293b; border-color: #334155; }

/* Mobile exam layout */
@media (max-width: 767px) {
  .exam-nav-panel { display: none; }
  .exam-nav-mobile {
    display: flex; flex-wrap: wrap; gap: 4px;
    padding: .75rem; background: #fff; border-bottom: 1px solid #e2e8f0;
    overflow-x: auto;
  }
  .exam-main { padding: .75rem; }
}
@media (min-width: 768px) {
  .exam-nav-mobile { display: none; }
}

/* ============================================================
   CONTINUE EXAM CARD
   ============================================================ */
.exam-card-continue {
  border: 2px solid #d97706 !important;
  background: linear-gradient(135deg,#fffbeb,#fef3c7) !important;
}
[data-bs-theme="dark"] .exam-card-continue { background: linear-gradient(135deg,#422006,#451a03) !important; border-color: #b45309 !important; }
.exam-card-continue .continue-timer { font-family: monospace; font-weight: 800; color: #d97706; font-size: 1.1rem; }

/* ============================================================
   MISC
   ============================================================ */
.loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.loading-spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg,#f0f0f0 25%,#e0e0e0 50%,#f0f0f0 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 6px; }
[data-bs-theme="dark"] .skeleton { background: linear-gradient(90deg,#334155 25%,#475569 50%,#334155 75%); background-size: 200% 100%; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

.avatar-initials {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; flex-shrink: 0;
}

.token-expired { background: #fee2e2; color: #dc2626; border-radius: 8px; padding: .5rem 1rem; font-weight: 600; display: inline-flex; align-items: center; gap: .4rem; }

.form-switch .form-check-input { width: 2.5em; height: 1.3em; cursor: pointer; }
.form-switch .form-check-input:checked { background-color: #16a34a; border-color: #16a34a; }

.result-score-badge {
  display: inline-flex; flex-direction: column; align-items: center;
  background: linear-gradient(135deg,#2563eb,#7c3aed);
  color: #fff; border-radius: 12px; padding: .5rem .75rem;
  min-width: 70px;
}
.result-score-value { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.result-score-label { font-size: .65rem; opacity: .8; margin-top: .15rem; }

/* Sticky topbar for DataTables */
.dataTables_wrapper { overflow: auto; }

/* Modal improvements */
.modal-header { border-bottom: 2px solid #f1f5f9; }
[data-bs-theme="dark"] .modal-header { border-color: #334155; }
.modal-footer { border-top: 2px solid #f1f5f9; background: #fafafa; }
[data-bs-theme="dark"] .modal-footer { border-color: #334155; background: #161f2e; }

/* Print */
@media print {
  .sidebar, .topbar, .exam-topbar, .no-print { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
}
