/*
 * Question Paper Generator — design system
 * Theming layer on top of Bootstrap 5.3. Remaps Bootstrap's CSS custom
 * properties to this product's palette rather than fighting Bootstrap's
 * structure/components.
 *
 * Palette variables (reuse these in any page-specific CSS):
 *   --bp-primary, --bp-primary-dark, --bp-primary-light
 *   --bp-secondary
 *   --bp-success, --bp-warning, --bp-danger, --bp-info
 *   --bp-slate-50 .. --bp-slate-900   (neutral scale)
 *   --bp-sidebar-width
 *   --bp-mcq, --bp-short, --bp-long, --bp-comprehension  (question-type accents)
 */

/* ---------------------------------------------------------------------- */
/* 1. Palette + design tokens                                             */
/* ---------------------------------------------------------------------- */
:root {
  /* Brand */
  --bp-primary: #4f46e5;
  --bp-primary-dark: #4338ca;
  --bp-primary-light: #eef2ff;
  --bp-secondary: #64748b;

  /* Status */
  --bp-success: #16a34a;
  --bp-warning: #d97706;
  --bp-danger: #dc2626;
  --bp-info: #0891b2;

  /* Slate neutral scale */
  --bp-slate-50: #f8fafc;
  --bp-slate-100: #f1f5f9;
  --bp-slate-200: #e2e8f0;
  --bp-slate-300: #cbd5e1;
  --bp-slate-400: #94a3b8;
  --bp-slate-500: #64748b;
  --bp-slate-600: #475569;
  --bp-slate-700: #334155;
  --bp-slate-800: #1e293b;
  --bp-slate-900: #0f172a;

  /* Question-type accents */
  --bp-mcq: #4f46e5;
  --bp-mcq-bg: #eef2ff;
  --bp-short: #0891b2;
  --bp-short-bg: #e0f7fa;
  --bp-long: #d97706;
  --bp-long-bg: #fef3c7;
  --bp-comprehension: #be185d;
  --bp-comprehension-bg: #fce7f3;

  /* Layout */
  --bp-sidebar-width: 260px;
  --bp-topbar-height: 64px;
  --bp-radius: 0.75rem;
  --bp-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --bp-shadow-md: 0 4px 16px rgba(15, 23, 42, 0.1);

  /* Remap Bootstrap theme variables to the palette above */
  --bs-primary: var(--bp-primary);
  --bs-primary-rgb: 79, 70, 229;
  --bs-secondary: var(--bp-secondary);
  --bs-secondary-rgb: 100, 116, 139;
  --bs-success: var(--bp-success);
  --bs-success-rgb: 22, 163, 74;
  --bs-warning: var(--bp-warning);
  --bs-warning-rgb: 217, 119, 6;
  --bs-danger: var(--bp-danger);
  --bs-danger-rgb: 220, 38, 38;
  --bs-info: var(--bp-info);
  --bs-info-rgb: 8, 145, 178;
  --bs-body-color: var(--bp-slate-700);
  --bs-body-bg: var(--bp-slate-50);
  --bs-border-color: var(--bp-slate-200);
  --bs-link-color: var(--bp-primary);
  --bs-link-hover-color: var(--bp-primary-dark);
  --bs-font-sans-serif: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ---------------------------------------------------------------------- */
/* 2. Base                                                                 */
/* ---------------------------------------------------------------------- */
html, body {
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bp-slate-50);
  color: var(--bp-slate-700);
}

a {
  color: var(--bp-primary);
}
a:hover {
  color: var(--bp-primary-dark);
}

.btn-primary {
  --bs-btn-bg: var(--bp-primary);
  --bs-btn-border-color: var(--bp-primary);
  --bs-btn-hover-bg: var(--bp-primary-dark);
  --bs-btn-hover-border-color: var(--bp-primary-dark);
  --bs-btn-active-bg: var(--bp-primary-dark);
  --bs-btn-active-border-color: var(--bp-primary-dark);
}

.text-primary {
  color: var(--bp-primary) !important;
}

/* ---------------------------------------------------------------------- */
/* 3. App shell: topbar + sidebar + content                                */
/* ---------------------------------------------------------------------- */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--bp-topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem;
  background: #fff;
  border-bottom: 1px solid var(--bp-slate-200);
  box-shadow: var(--bp-shadow-sm);
}

.app-topbar .app-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--bp-slate-900);
  text-decoration: none;
  white-space: nowrap;
}

.app-topbar .app-brand i {
  color: var(--bp-primary);
  font-size: 1.25rem;
}

#sidebarToggle {
  border: 1px solid var(--bp-slate-200);
  background: #fff;
  color: var(--bp-slate-700);
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
}
#sidebarToggle:hover {
  background: var(--bp-slate-100);
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}

.app-user-name {
  font-weight: 600;
  color: var(--bp-slate-800);
  font-size: 0.9rem;
}

.role-badge {
  text-transform: capitalize;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 0.7rem;
  padding: 0.25em 0.6em;
}

.role-badge-admin {
  background: var(--bp-primary-light);
  color: var(--bp-primary-dark);
}
.role-badge-staff {
  background: var(--bp-short-bg);
  color: var(--bp-short);
}
.role-badge-teacher {
  background: var(--bp-long-bg);
  color: var(--bp-long);
}

.app-layout {
  display: flex;
  align-items: flex-start;
}

/* Sidebar: fixed on desktop */
#appSidebar {
  width: var(--bp-sidebar-width);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--bp-slate-200);
  min-height: calc(100vh - var(--bp-topbar-height));
}

@media (min-width: 992px) {
  #appSidebar {
    position: sticky;
    top: var(--bp-topbar-height);
    height: calc(100vh - var(--bp-topbar-height));
    overflow-y: auto;
  }
}

.sidebar-nav {
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--bp-slate-600);
  font-weight: 500;
  font-size: 0.92rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav .nav-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  text-align: center;
  color: var(--bp-slate-400);
}

.sidebar-nav .nav-link:hover {
  background: var(--bp-slate-100);
  color: var(--bp-slate-900);
}

.sidebar-nav .nav-link:hover i {
  color: var(--bp-slate-600);
}

.sidebar-nav .nav-link.active {
  background: var(--bp-primary-light);
  color: var(--bp-primary-dark);
}

.sidebar-nav .nav-link.active i {
  color: var(--bp-primary);
}

.sidebar-nav .nav-link.logout-link {
  margin-top: 0.5rem;
  border-top: 1px solid var(--bp-slate-200);
  padding-top: 0.85rem;
  color: var(--bp-danger);
}
.sidebar-nav .nav-link.logout-link i {
  color: var(--bp-danger);
}
.sidebar-nav .nav-link.logout-link:hover {
  background: #fef2f2;
}

/* Offcanvas variant on mobile/tablet reuses the same nav markup */
#appSidebar.offcanvas {
  --bs-offcanvas-width: 280px;
}

@media (max-width: 991.98px) {
  #appSidebar:not(.offcanvas) {
    display: none;
  }
}

.app-content {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

/* ---------------------------------------------------------------------- */
/* 4. Cards                                                                */
/* ---------------------------------------------------------------------- */
.card {
  border: 1px solid var(--bp-slate-200);
  border-radius: var(--bp-radius);
  box-shadow: var(--bp-shadow-sm);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid var(--bp-slate-200);
  border-top-left-radius: var(--bp-radius) !important;
  border-top-right-radius: var(--bp-radius) !important;
  font-weight: 600;
  color: var(--bp-slate-900);
}

.card-body {
  padding: 1.5rem;
}

.stat-card {
  border-radius: var(--bp-radius);
  border: 1px solid var(--bp-slate-200);
  box-shadow: var(--bp-shadow-sm);
  padding: 1.25rem 1.5rem;
  background: #fff;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--bp-slate-900);
}

.stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--bp-slate-500);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------------- */
/* 5. Tables                                                               */
/* ---------------------------------------------------------------------- */
.table-responsive {
  border-radius: var(--bp-radius);
}

.table {
  margin-bottom: 0;
  vertical-align: middle;
}

.table thead th {
  background: var(--bp-slate-50);
  color: var(--bp-slate-600);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  border-bottom: 1px solid var(--bp-slate-200);
  white-space: nowrap;
}

.table tbody tr {
  border-bottom: 1px solid var(--bp-slate-100);
}

.table tbody tr:last-child {
  border-bottom: none;
}

.table-sticky-header thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* ---------------------------------------------------------------------- */
/* 6. Question-type badges                                                 */
/* ---------------------------------------------------------------------- */
.badge-mcq,
.badge-short,
.badge-long,
.badge-comprehension {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.35em 0.7em;
  border-radius: 999px;
  text-transform: capitalize;
}

.badge-mcq {
  background: var(--bp-mcq-bg);
  color: var(--bp-mcq);
}

.badge-short {
  background: var(--bp-short-bg);
  color: var(--bp-short);
}

.badge-long {
  background: var(--bp-long-bg);
  color: var(--bp-long);
}

.badge-comprehension {
  background: var(--bp-comprehension-bg);
  color: var(--bp-comprehension);
}

/* ---------------------------------------------------------------------- */
/* 7. Forms                                                                */
/* ---------------------------------------------------------------------- */
.form-label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--bp-slate-700);
}

.form-control,
.form-select {
  border-color: var(--bp-slate-300);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--bp-primary);
  box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

/* ---------------------------------------------------------------------- */
/* 8. Auth / bare layout (login page)                                      */
/* ---------------------------------------------------------------------- */
body.bare-layout {
  min-height: 100vh;
}

.auth-page {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #4338ca 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 1rem;
  box-shadow: var(--bp-shadow-md);
  padding: 2.25rem 2rem;
}

.auth-card .auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--bp-slate-900);
  margin-bottom: 0.25rem;
}

.auth-card .auth-brand i {
  color: var(--bp-primary);
  font-size: 1.4rem;
}

.auth-card .auth-subtitle {
  text-align: center;
  color: var(--bp-slate-500);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

@media (max-width: 400px) {
  .auth-card {
    padding: 1.75rem 1.25rem;
  }
}

/* ---------------------------------------------------------------------- */
/* 9. Responsiveness (down to ~360px)                                      */
/* ---------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  form .row > [class^='col'] {
    margin-bottom: 0.75rem;
  }

  .card-body {
    padding: 1.1rem;
  }

  .app-topbar .app-brand span {
    display: none;
  }

  .app-user-name {
    display: none;
  }
}

@media (max-width: 575.98px) {
  .container-fluid.py-4 {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    padding-top: 1rem !important;
  }

  .app-topbar {
    padding: 0 0.75rem;
  }

  .stat-card {
    padding: 1rem;
  }
}

@media (max-width: 360px) {
  .app-topbar-right {
    gap: 0.4rem;
  }

  .role-badge {
    display: none;
  }
}

/* ---------------------------------------------------------------------- */
/* 10. Print (paper preview page)                                          */
/* ---------------------------------------------------------------------- */
@media print {
  .no-print {
    display: none !important;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-family: 'Times New Roman', Georgia, serif !important;
  }

  .app-topbar,
  #appSidebar,
  .app-content {
    display: block !important;
  }

  .card,
  .paper-sheet {
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
  }

  .container-fluid {
    padding: 0 !important;
    max-width: 100% !important;
  }

  a {
    color: #000 !important;
    text-decoration: none !important;
  }

  .badge-mcq,
  .badge-short,
  .badge-long,
  .badge-comprehension {
    background: none !important;
    color: #000 !important;
    border: 1px solid #000;
  }
}
