/* ============================================================
   ExamPortal LMS — Custom Styles
   Bootstrap 5 override + sidebar + exam engine + dark mode
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --ep-primary:      #4F46E5;
  --ep-primary-dark: #3730A3;
  --ep-secondary:    #7C3AED;
  --ep-accent:       #06B6D4;
  --ep-success:      #10B981;
  --ep-warning:      #F59E0B;
  --ep-danger:       #EF4444;
  --ep-sidebar-bg:   #1E1B4B;
  --ep-sidebar-w:    250px;
  --ep-sidebar-collapsed: 60px;
  --ep-topbar-h:     60px;
  --ep-card-radius:  12px;
  --ep-shadow:       0 2px 12px rgba(0,0,0,.08);
  --ep-shadow-lg:    0 8px 30px rgba(0,0,0,.12);
  --ep-transition:   .25s ease;
}

[data-bs-theme="dark"] {
  --ep-sidebar-bg: #13113a;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: .9375rem;
  background: #F8FAFC;
  overflow-x: hidden;
}
[data-bs-theme="dark"] body { background: #0f172a; }

/* ── Layout Shell ───────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }
.main-content {
  flex: 1;
  margin-left: var(--ep-sidebar-w);
  min-width: 0;
  transition: margin-left var(--ep-transition);
}
.app-wrapper.sidebar-collapsed .main-content { margin-left: var(--ep-sidebar-collapsed); }
.page-body { padding: 1.5rem; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--ep-sidebar-w);
  height: 100vh;
  background: var(--ep-sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 1040;
  transition: width var(--ep-transition);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar-collapsed .sidebar { width: var(--ep-sidebar-collapsed); }
.sidebar-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--ep-topbar-h);
}
.sidebar-logo { width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-collapsed .sidebar-brand,
.sidebar-collapsed .sidebar-section,
.sidebar-collapsed .sidebar-link span,
.sidebar-collapsed .sidebar-role-badge { display: none !important; }
.sidebar-role-badge { padding: .5rem 1rem; }
.sidebar-nav {
  list-style: none;
  padding: .5rem 0;
  margin: 0;
  flex: 1;
}
.sidebar-section {
  font-size: .65rem;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 1rem 1rem .25rem;
  font-weight: 600;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  transition: all var(--ep-transition);
  border-left: 3px solid transparent;
  border-radius: 0 .5rem .5rem 0;
  margin: .1rem .5rem .1rem 0;
  white-space: nowrap;
}
.sidebar-link i { width: 20px; text-align: center; flex-shrink: 0; font-size: .95rem; }
.sidebar-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-link.active {
  background: rgba(79,70,229,.35);
  color: #fff;
  border-left-color: var(--ep-accent);
  font-weight: 600;
}
.sidebar-footer { padding: .75rem 0; border-top: 1px solid rgba(255,255,255,.08); margin-top: auto; }
.sidebar-collapsed .sidebar-link { justify-content: center; margin: .1rem 0; border-left: none; border-radius: .5rem; }
.sidebar-collapsed .sidebar-link.active { background: rgba(79,70,229,.4); }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1039;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--ep-topbar-h);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  z-index: 1030;
}
[data-bs-theme="dark"] .topbar { background: #1e2433; border-color: #2d3748; }
.topbar-title { font-size: .8rem; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  border: none;
  border-radius: var(--ep-card-radius);
  box-shadow: var(--ep-shadow);
  transition: box-shadow var(--ep-transition);
}
.card:hover { box-shadow: var(--ep-shadow-lg); }
.card-header { border-radius: var(--ep-card-radius) var(--ep-card-radius) 0 0 !important; }

/* ── Stat Cards ─────────────────────────────────────────────── */
.stat-card { overflow: hidden; }
.stat-card .stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}
.stat-card .stat-number { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label  { font-size: .8rem; color: #6b7280; margin-top: .25rem; }
.stat-card .stat-trend  { font-size: .75rem; }

/* ── Tables ─────────────────────────────────────────────────── */
.table th { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.table td { vertical-align: middle; font-size: .875rem; }
.table-hover tbody tr:hover { background: rgba(79,70,229,.04); }
[data-bs-theme="dark"] .table th { color: #9ca3af; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn-primary { background: var(--ep-primary); border-color: var(--ep-primary); }
.btn-primary:hover { background: var(--ep-primary-dark); border-color: var(--ep-primary-dark); }
.btn { border-radius: 8px; font-weight: 500; }
.btn-sm { font-size: .8rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 8px;
  font-size: .875rem;
  border-color: #d1d5db;
}
.form-control:focus, .form-select:focus {
  border-color: var(--ep-primary);
  box-shadow: 0 0 0 .2rem rgba(79,70,229,.15);
}
.form-label { font-weight: 500; font-size: .875rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge { border-radius: 6px; font-weight: 500; font-size: .7rem; }
.bg-purple { background: var(--ep-secondary) !important; }
.bg-teal   { background: #0d9488 !important; }
.bg-amber-dark { background: #b45309 !important; }

/* ── Login Page ─────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #1E1B4B 0%, #4F46E5 50%, #06B6D4 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.login-card { border-radius: 20px; box-shadow: var(--ep-shadow-lg); max-width: 420px; width: 100%; }

/* ── Question Palette ───────────────────────────────────────── */
.q-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.q-btn {
  width: 36px; height: 36px;
  border-radius: 6px;
  border: 1.5px solid #d1d5db;
  background: #fff;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.q-btn:hover    { border-color: var(--ep-primary); color: var(--ep-primary); }
.q-btn.answered { background: #10B981; border-color: #10B981; color: #fff; }
.q-btn.marked   { background: #F59E0B; border-color: #F59E0B; color: #fff; }
.q-btn.current  { background: var(--ep-primary); border-color: var(--ep-primary); color: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.3); }

/* ── Exam Timer ─────────────────────────────────────────────── */
.exam-timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: .25rem .75rem;
  border-radius: 8px;
  background: #f3f4f6;
  color: #1f2937;
  transition: background .3s;
}
.exam-timer.warning  { background: #fef3c7; color: #92400e; }
.exam-timer.critical { background: #fee2e2; color: #991b1b; animation: pulse-timer 1s infinite; }
@keyframes pulse-timer { 0%,100%{opacity:1} 50%{opacity:.7} }

/* ── Watermark Overlay ──────────────────────────────────────── */
.exam-watermark {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 900;
  opacity: .07;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #000;
  transform: rotate(-30deg);
  user-select: none;
  white-space: nowrap;
}
[data-bs-theme="dark"] .exam-watermark { color: #fff; }

/* ── Flashcard ──────────────────────────────────────────────── */
.flashcard-container { perspective: 1000px; }
.flashcard {
  width: 100%; min-height: 200px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.4,0,.2,1);
  cursor: pointer;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: var(--ep-card-radius);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--ep-shadow);
}
.flashcard-front { background: #fff; }
.flashcard-back  { background: var(--ep-primary); color: #fff; transform: rotateY(180deg); }
[data-bs-theme="dark"] .flashcard-front { background: #1e2433; }

/* ── Progress Dashboard ─────────────────────────────────────── */
.progress-ring-wrap { position: relative; display: inline-flex; }
.progress-ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-weight: 700;
}

/* ── Section Timer Bar ──────────────────────────────────────── */
.section-timer-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}
.section-timer-bar .fill {
  height: 100%;
  background: var(--ep-accent);
  transition: width 1s linear;
}
.section-timer-bar .fill.warning  { background: var(--ep-warning); }
.section-timer-bar .fill.critical { background: var(--ep-danger); }

/* ── Section Nav Tabs (Exam) ────────────────────────────────── */
.section-tabs .nav-link {
  border-radius: 8px 8px 0 0;
  font-size: .85rem;
  font-weight: 500;
  color: #6b7280;
}
.section-tabs .nav-link.active { color: var(--ep-primary); border-bottom: 2px solid var(--ep-primary); }
.section-badge { font-size: .65rem; }

/* ── Notification Dropdown ──────────────────────────────────── */
.notification-dropdown { border-radius: 12px; }
.notif-item:hover { background: #f9fafb !important; }
[data-bs-theme="dark"] .notif-item:hover { background: rgba(255,255,255,.05) !important; }
[data-bs-theme="dark"] .notif-item.fw-semibold { background: rgba(255,255,255,.05) !important; }

/* ── Violation Alert ────────────────────────────────────────── */
.violation-alert {
  position: fixed;
  top: 70px; right: 1rem;
  z-index: 9999;
  min-width: 300px;
  border-radius: 10px;
  box-shadow: var(--ep-shadow-lg);
  animation: slideIn .3s ease;
}
@keyframes slideIn { from{transform:translateX(120%)} to{transform:translateX(0)} }

/* ── Dark Mode Specifics ────────────────────────────────────── */
[data-bs-theme="dark"] {
  --bs-body-bg: #0f172a;
  --bs-body-color: #e2e8f0;
}
[data-bs-theme="dark"] .card          { background: #1e2433; box-shadow: 0 2px 12px rgba(0,0,0,.3); }
[data-bs-theme="dark"] .stat-label    { color: #94a3b8; }
[data-bs-theme="dark"] .q-btn         { background: #1e2433; border-color: #374151; color: #e2e8f0; }
[data-bs-theme="dark"] .exam-timer    { background: #1e2433; color: #e2e8f0; }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select   { background: #1e2433; border-color: #374151; color: #e2e8f0; }
[data-bs-theme="dark"] .table         { --bs-table-bg: #1e2433; --bs-table-striped-bg: #232b3e; }
[data-bs-theme="dark"] .login-card    { background: #1e2433; }

/* ── Responsive / Mobile ────────────────────────────────────── */
@media (max-width: 991.98px) {
  .main-content { margin-left: 0 !important; }
  .sidebar { transform: translateX(-100%); }
  .app-wrapper.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .app-wrapper.sidebar-mobile-open .sidebar-overlay { display: block; }
  .page-body { padding: 1rem; }
}
@media (max-width: 575.98px) {
  .stat-card .stat-number { font-size: 1.4rem; }
  .exam-timer { font-size: 1.1rem; }
}
