:root {
  --lms-navy:   #0f2c59;
  --lms-blue:   #1b54a0;
  --lms-light-blue: #3d7dd6;
  --lms-gold:   #f0b429;
  --lms-bg:     #f0f4f9;
  --sidebar-w:  240px;
  --sidebar-w-collapsed: 64px;
  --radius:     12px;
  --shadow:     0 2px 16px rgba(15,44,89,.10);
  --shadow-md:  0 4px 24px rgba(15,44,89,.14);
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--lms-bg);
  min-height: 100vh;
  margin: 0;
  color: #1e293b;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Navbar ── */
.navbar-lms {
  background: linear-gradient(90deg, var(--lms-navy) 0%, var(--lms-blue) 60%, var(--lms-light-blue) 100%);
  height: 58px;
  z-index: 1030;
  box-shadow: 0 2px 12px rgba(15,44,89,.25);
}
.navbar-lms .navbar-brand { font-size: 1.15rem; letter-spacing: .3px; }

/* ── Layout ──
   Rail icon luôn chiếm 64px trong flow.
   Khi mở rộng, sidebar overlay đè lên nội dung (kiểu YouTube), không đẩy layout. */
.lms-layout {
  display: flex;
  position: relative;
  min-height: calc(100vh - 58px);
  width: 100%;
  overflow: hidden;
}
.lms-layout::before {
  content: "";
  flex: 0 0 var(--sidebar-w-collapsed);
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
}

/* ── Sidebar (luôn absolute, overlay khi mở rộng) ── */
.sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  padding-top: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 1020;
  box-shadow: 8px 0 28px rgba(15, 44, 89, .16);
  transition: width .25s ease, min-width .25s ease, box-shadow .25s ease, border-color .25s ease;
}

/* Trạng thái thu nhỏ: chỉ còn rail icon, không đổ bóng */
.lms-layout.collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
  box-shadow: none;
}
.lms-layout.collapsed .sidebar .nav-link {
  justify-content: center;
  padding: 9px 0;
  margin: 2px 6px;
}
.lms-layout.collapsed .sidebar .nav-link i { margin: 0; }
.lms-layout.collapsed .sidebar .nav-link span,
.lms-layout.collapsed .sidebar .section-title,
.lms-layout.collapsed .sidebar .sidebar-divider,
.lms-layout.collapsed .sidebar .sidebar-user { display: none; }

/* Backdrop khi sidebar overlay đang mở */
.sidebar-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(15, 44, 89, .22);
  z-index: 1010;
  cursor: pointer;
}
@media (min-width: 768px) {
  .lms-layout:not(.collapsed) .sidebar-backdrop { display: block; }
}

/* Main content: luôn chiếm phần còn lại, không bị sidebar mở rộng đẩy */
#page-main-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 28px 32px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: padding .25s ease;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px 6px;
}
.sidebar-toggle button {
  width: 100%;
  border: 0;
  background: #f8faff;
  color: var(--lms-blue);
  border-radius: 8px;
  height: 32px;
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-toggle button:hover { background: #e0ecff; }
.lms-layout.collapsed .sidebar-toggle button { background: transparent; }

/* Khi thu nhỏ: chỉ hiện icon, ẩn chữ */
.sidebar-toggle .toggle-label { display: inline-block; margin-left: 6px; }
.lms-layout.collapsed .sidebar-toggle .toggle-label { display: none; }
.lms-layout.collapsed .sidebar-toggle button { justify-content: center; }

.sidebar .nav-link {
  color: #475569;
  border-radius: 10px;
  margin: 2px 10px;
  padding: 9px 14px;
  font-size: .875rem;
  white-space: nowrap;
  transition: background .15s, color .15s, transform .1s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .nav-link i { font-size: 1rem; flex-shrink: 0; }
.sidebar .nav-link:hover { background: #eff6ff; color: var(--lms-blue); transform: translateX(2px); }
.sidebar .nav-link.active {
  background: linear-gradient(90deg, #dbeafe, #eff6ff);
  color: var(--lms-blue);
  font-weight: 600;
  border-left: 3px solid var(--lms-blue);
}

.sidebar-divider {
  height: 1px;
  background: #f1f5f9;
  margin: 8px 16px;
}

/* ── Page header ── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h4 { margin: 0; font-weight: 700; color: var(--lms-navy); }
.page-header small { color: #64748b; }

/* ── Hero banner ── */
.hero {
  background: linear-gradient(135deg, #0f2c59 0%, #1b54a0 55%, #3d7dd6 100%);
  color: #fff;
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,.05);
  border-radius: 50%;
}

/* ── Stat cards ── */
.stat-card {
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #fff;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}

/* ── Cards ── */
.card {
  border-radius: var(--radius) !important;
  border: 1px solid #e8edf5 !important;
  box-shadow: var(--shadow);
}
.card-header {
  border-bottom: 1px solid #f1f5f9 !important;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: 14px 20px !important;
}

/* ── Tables ── */
.table thead th {
  background: #f8faff;
  color: var(--lms-navy);
  white-space: nowrap;
  font-weight: 600;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 2px solid #e2e8f0 !important;
  padding: 12px 16px;
}
.table td {
  vertical-align: middle;
  font-size: .875rem;
  padding: 11px 16px;
  border-color: #f1f5f9;
}
.table tbody tr { transition: background .12s; }
.table-hover tbody tr:hover { background: #f8faff !important; }

/* ── Badges ── */
.badge { font-weight: 500; letter-spacing: .2px; }

/* ── Buttons ── */
.btn { border-radius: 8px; font-weight: 500; font-size: .875rem; }
.btn-primary { background: var(--lms-blue); border-color: var(--lms-blue); }
.btn-primary:hover { background: var(--lms-navy); border-color: var(--lms-navy); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }

/* ── Form controls ── */
.form-control, .form-select {
  border-radius: 8px;
  border-color: #d1d9e6;
  font-size: .875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--lms-blue);
  box-shadow: 0 0 0 3px rgba(27,84,160,.12);
}
.form-label { font-size: .82rem; font-weight: 600; color: #475569; margin-bottom: 4px; }

/* ── Modals ── */
.modal-content { border-radius: var(--radius) !important; border: 0 !important; box-shadow: var(--shadow-md); }
.modal-header { border-radius: var(--radius) var(--radius) 0 0 !important; padding: 16px 20px; }
.modal-footer { border-top: 1px solid #f1f5f9; padding: 12px 20px; }

/* ── Alert toast ── */
#alertBox {
  position: fixed;
  top: 70px; right: 20px;
  z-index: 9999;
  min-width: 320px; max-width: 440px;
}
#alertBox .alert {
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  border: 0;
  animation: slideIn .25s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Quick action cards ── */
.quick-action {
  border-radius: var(--radius);
  border: 2px solid #e8edf5;
  background: #fff;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.quick-action:hover {
  border-color: var(--lms-blue);
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--lms-blue);
}
.quick-action i { font-size: 2rem; margin-bottom: 8px; display: block; }

/* ── Status badges ── */
.status-active   { background: #dcfce7; color: #166534; }
.status-inactive { background: #fee2e2; color: #991b1b; }
.status-warning  { background: #fef9c3; color: #854d0e; }

/* ── GPA display ── */
.gpa-display {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--lms-blue), var(--lms-light-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Xep loai colors ── */
.xl-xuat-sac { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.xl-gioi     { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.xl-kha      { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.xl-tb       { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }
.xl-yeu      { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Score cell ── */
.score-pass  { color: #16a34a; font-weight: 700; }
.score-fail  { color: #dc2626; font-weight: 700; }
.score-avg   { color: #d97706; font-weight: 700; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #94a3b8;
}
.empty-state i { font-size: 3rem; margin-bottom: 12px; display: block; }

/* ── Loading spinner row ── */
.loading-row td { padding: 32px !important; }

/* ── Breadcrumb-style section title ── */
.section-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #94a3b8;
  padding: 8px 20px 4px;
}

/* ── Print ── */
@media print {
  .navbar-lms, .sidebar, #lms-sidebar, .no-print, button, .btn, #alertBox { display: none !important; }
  body, .lms-layout, #page-main-content {
    background: #fff !important; padding: 0 !important; margin: 0 !important; width: 100% !important;
  }
  .print-only { display: block !important; }
  .card { border: 1px solid #ddd !important; box-shadow: none !important; break-inside: avoid; }
  .table { border-collapse: collapse !important; }
  .table th, .table td { border: 1px solid #999 !important; }
}
@media screen { .print-only { display: none !important; } }

/* ── Responsive: sidebar ẩn trên điện thoại, mở overlay bằng hamburger ── */
@media (max-width: 767px) {
  #page-main-content { padding: 16px; }
  .navbar-lms .navbar-brand span { display: none; }
  .lms-layout::before {
    flex-basis: 0;
    width: 0;
    min-width: 0;
  }
  .sidebar {
    width: 0;
    min-width: 0;
    border-right: 0;
    box-shadow: none;
  }
  .lms-layout.sidebar-open .sidebar {
    width: 260px;
    min-width: 260px;
    border-right: 1px solid #e2e8f0;
    box-shadow: 8px 0 28px rgba(15, 44, 89, .16);
  }
  .lms-layout.sidebar-open .sidebar-backdrop { display: block; }
  /* Khi mở overlay trên mobile, luôn hiện đủ nhãn dù đang collapsed */
  .lms-layout.collapsed.sidebar-open .sidebar .nav-link {
    justify-content: flex-start;
    padding: 9px 14px;
    margin: 2px 10px;
  }
  .lms-layout.collapsed.sidebar-open .sidebar .nav-link span,
  .lms-layout.collapsed.sidebar-open .sidebar .section-title,
  .lms-layout.collapsed.sidebar-open .sidebar .sidebar-divider,
  .lms-layout.collapsed.sidebar-open .sidebar .sidebar-user { display: block; }
  .lms-layout.collapsed.sidebar-open .sidebar-toggle .toggle-label { display: inline-block; }
}

/* Khung quản trị: một trang cuộn, sidebar đẩy nội dung trên desktop. */
.lms-layout {
  min-height: calc(100vh - 58px);
  overflow: visible;
}
.lms-layout::before { content: none; }
.sidebar {
  position: sticky;
  top: 58px;
  left: auto;
  bottom: auto;
  align-self: flex-start;
  flex: 0 0 var(--sidebar-w);
  height: calc(100vh - 58px);
  box-shadow: 2px 0 10px rgba(15, 44, 89, .06);
}
.lms-layout.collapsed .sidebar { flex-basis: var(--sidebar-w-collapsed); }
.sidebar-backdrop { position: fixed; inset: 58px 0 0; }
#page-main-content {
  padding: 18px 20px;
  overflow: visible;
}
.page-header { gap: 12px; margin-bottom: 16px; }
.hero { padding: 12px 16px !important; margin-bottom: 16px !important; }
.hero h3 { font-size: 1.25rem; }
.hero p { font-size: .82rem; }
.stat-card { padding: 12px !important; }
.stat-card .stat-icon { width: 40px; height: 40px; font-size: 1.2rem; }
.card-header { padding: 11px 16px !important; }
.table td { padding: 9px 12px; }
.quick-action { padding: 14px 10px; }
.quick-action i { font-size: 1.5rem; margin-bottom: 5px; }
#lmsToastRegion { z-index: 1090; }

@media (min-width: 992px) {
  .sidebar-toggle { display: flex; }
  .sidebar-backdrop { display: none !important; }
  #mobileMenuBtn { display: none !important; }
}

@media (max-width: 991.98px) {
  .sidebar-toggle { display: none; }
  .sidebar {
    position: fixed;
    top: 58px;
    left: 0;
    bottom: 0;
    align-self: auto;
    flex: none;
    width: 280px;
    min-width: 280px;
    height: calc(100vh - 58px);
    border-right: 1px solid #e2e8f0;
    box-shadow: 8px 0 28px rgba(15, 44, 89, .16);
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 1040;
  }
  .lms-layout.collapsed .sidebar {
    width: 280px;
    min-width: 280px;
    box-shadow: 8px 0 28px rgba(15, 44, 89, .16);
  }
  .lms-layout.sidebar-open .sidebar { transform: translateX(0); }
  .lms-layout.collapsed .sidebar .nav-link {
    justify-content: flex-start;
    padding: 9px 14px;
    margin: 2px 10px;
  }
  .lms-layout.collapsed .sidebar .nav-link span,
  .lms-layout.collapsed .sidebar .section-title,
  .lms-layout.collapsed .sidebar .sidebar-divider,
  .lms-layout.collapsed .sidebar .sidebar-user { display: block; }
  .lms-layout.sidebar-open .sidebar-backdrop { display: block; }
  #page-main-content { padding: 16px; }
}

@media (max-width: 575.98px) {
  .navbar-lms { height: auto; min-height: 58px; }
  .navbar-lms .container-fluid { gap: 6px; padding: 6px 10px; }
  .navbar-lms .navbar-brand { font-size: 1rem; margin-right: 0; }
  .navbar-lms .navbar-brand span { display: none; }
  .navbar-lms .navbar-action-label { display: none; }
  .navbar-lms .btn { padding: 6px 9px; }
  #page-main-content { padding: 14px 12px; }
  .page-header { align-items: flex-start; flex-wrap: wrap; }
  .page-header h4 { font-size: 1.15rem; }
  .page-header > .btn { margin-left: auto; }
  #alertBox { right: 10px; left: 10px; min-width: 0; max-width: none; }
  .toast-container { left: 10px !important; right: 10px !important; width: auto; }
  .quick-action { padding: 12px 8px; }
  .stat-card .fs-4 { font-size: 1.15rem !important; overflow-wrap: anywhere; }
  .card-header { padding: 10px 12px !important; }
  .modal-dialog { margin: 10px; }
  .bc-table-tools > span { flex: 1 1 100%; }
  .bc-table-tools > div { width: 100%; justify-content: space-between; }
  .bc-table-tools > div > div { flex: 1 1 100%; }
  .bc-table-tools select { width: 100%; min-width: 0 !important; }
}

/* Công cụ danh sách, vùng bảng và phân trang phía trình duyệt. */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.table-toolbar > .form-control { flex: 1 1 280px; min-width: 180px; }
.table-toolbar > .form-select { flex: 0 1 220px; min-width: 170px; }
.table-result-count { margin-left: auto; color: #64748b; font-size: .82rem; white-space: nowrap; }
.table-scroll-card { background: #fff; border: 1px solid #e8edf5; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll-area { max-height: min(62vh, 680px); overflow: auto; }
.table-scroll-area thead th { position: sticky; top: 0; z-index: 2; box-shadow: 0 1px 0 #dfe6f0; }
.table-actions { display: inline-flex; justify-content: flex-end; gap: 4px; white-space: nowrap; }
.table-actions .btn { min-width: 32px; padding: 4px 7px; }
.table-pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 8px 14px; border-top: 1px solid #edf1f6; }
.table-page-summary { color: #64748b; font-size: .82rem; white-space: nowrap; }
.table-page-size { width: 70px; }
.text-end { font-variant-numeric: tabular-nums; }
@media (max-width: 575.98px) {
  .table-toolbar { flex-wrap: wrap; }
  .table-toolbar > .form-control, .table-toolbar > .form-select { flex: 1 1 100%; min-width: 0; }
  .table-result-count { margin-left: 0; }
  .table-pagination { align-items: flex-start; flex-direction: column; }
  .table-pagination > .d-flex { flex-wrap: wrap; }
  .table-scroll-area { max-height: 58vh; }
}
