:root {
  --primary: #2563EB;
  --secondary: #0EA5E9;
  --success: #22C55E;
  --danger: #EF4444;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #1E293B;
  --sidebar: #0F172A;
  --sidebar-width: 260px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body.admin-body {
  font-family: Roboto, Inter, system-ui, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  margin: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

h1, h2, .font-poppins {
  font-family: Poppins, Inter, sans-serif;
}

.admin-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--sidebar);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1030;
  transition: transform 0.3s ease;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1025;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
}

.admin-sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

.admin-sidebar .nav-link {
  color: rgba(255, 255, 255, 0.72);
  border-radius: 10px;
  margin: 2px 12px;
  padding: 0.65rem 1rem;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.admin-sidebar .nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(4px);
}

.admin-sidebar .nav-link.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.5), rgba(14, 165, 233, 0.25));
  border-left: 3px solid var(--secondary);
}

/* Critical: margin-left + width:100% makes total width > viewport — use calc */
.admin-main {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  max-width: calc(100% - var(--sidebar-width));
  min-height: 100vh;
  min-height: 100dvh;
  transition: margin 0.3s ease, width 0.3s ease;
  min-width: 0;
}

/* Let wide tables scroll inside .table-responsive; do not clip horizontally */
.admin-main > main {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: visible;
  overflow-y: visible;
}

/* Flex/grid columns must shrink so charts and cards don’t force page wider than main */
.admin-main .row > [class*="col-"] {
  min-width: 0;
}

.admin-main .card {
  min-width: 0;
  max-width: 100%;
}

.admin-main .table-responsive {
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.admin-topbar {
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  gap: 0.5rem;
}

.admin-topbar .form-control,
.admin-topbar .form-select {
  min-height: 38px;
}

.glass-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  border-radius: 16px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
  .glass-card:hover {
    transform: scale(1.02);
    box-shadow: 0 16px 40px rgba(37, 99, 235, 0.1);
  }
}

.stat-card {
  border-radius: 16px;
  border: none;
  overflow: hidden;
  position: relative;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 16px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(14, 165, 233, 0.2));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.badge-pending { background: #FACC15; color: #422006; }
.badge-active { background: var(--success); }
.badge-completed { background: #6366F1; }
.badge-rejected { background: var(--danger); }

.btn-gradient {
  background: linear-gradient(135deg, #2563EB, #0EA5E9);
  border: none;
  color: #fff;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-gradient:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.table-hover tbody tr {
  transition: background 0.2s;
}

@media (max-width: 991.98px) {
  .admin-sidebar {
    transform: translateX(-100%);
    width: min(var(--sidebar-width), 88vw);
    max-width: 88vw;
  }
  .admin-sidebar.show {
    transform: translateX(0);
  }
  .admin-main {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }
  .admin-sidebar-backdrop.show {
    display: block;
    opacity: 1;
  }
}

/* Chart.js parents need explicit height when maintainAspectRatio: false */
.chart-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 220px;
  overflow: hidden;
}

.chart-wrap--tall {
  height: 240px;
}

.chart-wrap--pie {
  height: 260px;
}

@media (min-width: 576px) {
  .chart-wrap {
    height: 240px;
  }
  .chart-wrap--tall {
    height: 280px;
  }
  .chart-wrap--pie {
    height: 280px;
  }
}

@media (min-width: 992px) {
  .chart-wrap {
    height: 260px;
  }
  .chart-wrap--tall {
    height: 300px;
  }
  .chart-wrap--pie {
    height: 300px;
  }
}

.dashboard-page .row {
  --bs-gutter-x: 0.75rem;
}

@media (max-width: 575.98px) {
  .dashboard-page .row {
    --bs-gutter-x: 0.5rem;
  }

  .admin-topbar form[action="students.php"] {
    max-width: 100% !important;
    flex: 1 1 100%;
    order: 3;
  }

  .table-responsive {
    font-size: 0.875rem;
    -webkit-overflow-scrolling: touch;
  }

  .display-6 {
    font-size: calc(1.35rem + 1.2vw);
  }

  .dashboard-page .card-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

.page-fade {
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.toast-container { z-index: 1080; }

/* Student list cards (photo + details) */
.student-cards-grid {
  --bs-gutter-x: 0.75rem;
  --bs-gutter-y: 0.75rem;
}

.student-card {
  min-width: 0;
}

.student-card-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: linear-gradient(145deg, #e8eef7 0%, #f1f5f9 100%);
  overflow: hidden;
}

.student-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.student-card-photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb22, #0ea5e933);
  color: #2563eb;
  font-size: clamp(2rem, 8vw, 2.75rem);
  font-weight: 700;
  font-family: Poppins, Inter, sans-serif;
  letter-spacing: 0.02em;
}
