:root {
  --primary: #0D47A1;
  --primary-light: #1565C0;
  --primary-dark: #0A3D91;
  --accent: #42A5F5;
  --accent-light: #64B5F6;
  --success: #2E7D32;
  --warning: #F57F17;
  --danger: #C62828;
  --info: #0277BD;
  --bg: #F5F7FA;
  --bg-card: #FFFFFF;
  --text: #212529;
  --text-muted: #6C757D;
  --border: #DEE2E6;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  --radius-sm: 4px;
  --transition: all 0.2s ease;
  --sidebar-width: 260px;
  --header-height: 60px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #CED4DA; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #1B5E20; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #B71C1C; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #F9A825; }

.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #01579B; }

.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-hover); }

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body { padding: 20px; }

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 71, 161, 0.15);
}

.form-control::placeholder { color: var(--text-muted); }

.form-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 10px 14px;
  padding-right: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
  background-color: white;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236C757D' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
  color: var(--text);
}
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 71, 161, 0.15);
}
select.form-select option { padding: 8px; }
.form-select[disabled] { background-color: #f5f5f5; cursor: not-allowed; }

.input-group { display: flex; gap: 8px; }
.input-group .form-control { flex: 1; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-row .form-group { margin-bottom: 0; }

.form-view { display: none; }
.form-view.active { display: block; }
.form-view .card-header h3 { font-size: 18px; font-weight: 600; }
.form-view .card-body { max-width: 720px; }
.form-view .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.table-container { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th { background: #F8F9FA; font-weight: 600; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

tr:hover td { background: #F8F9FA; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-primary { background: #E3F2FD; color: var(--primary); }
.badge-success { background: #E8F5E9; color: var(--success); }
.badge-warning { background: #FFF8E1; color: var(--warning); }
.badge-danger { background: #FFEBEE; color: var(--danger); }
.badge-info { background: #E1F5FE; color: var(--info); }
.badge-secondary { background: #ECEFF1; color: var(--text-muted); }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success { background: #E8F5E9; color: var(--success); border: 1px solid #C8E6C9; }
.alert-danger { background: #FFEBEE; color: var(--danger); border: 1px solid #FFCDD2; }
.alert-warning { background: #FFF8E1; color: #F57F17; border: 1px solid #FFECB3; }
.alert-info { background: #E1F5FE; color: var(--info); border: 1px solid #B3E5FC; }

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.app-layout .modal-overlay { display: flex; }

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: var(--transition);
}

.modal-overlay.active .modal { transform: scale(1); }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.app-layout .modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.2s;
}
.app-layout .modal-close:hover { background: #f0f0f0; color: var(--text); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stat-icon.primary { background: #E3F2FD; color: var(--primary); }
.stat-icon.success { background: #E8F5E9; color: var(--success); }
.stat-icon.warning { background: #FFF8E1; color: var(--warning); }
.stat-icon.info { background: #E1F5FE; color: var(--info); }
.stat-icon.danger { background: #FFEBEE; color: var(--danger); }

.stat-content h3 { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.stat-content p { font-size: 13px; color: var(--text-muted); }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title h1 { font-size: 28px; font-weight: 700; color: var(--text); }
.page-title p { color: var(--text-muted); margin-top: 4px; }

.search-filter {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.search-filter .form-control { max-width: 300px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.5; }

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

.app-layout {
  display: flex;
  min-height: 100vh;
}
.app-layout .overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}
.app-layout .overlay.active {
  display: block;
}

.app-layout .sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #0D47A1 0%, #002171 100%);
  border-right: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  transition: width 0.3s ease, transform 0.3s ease;
  overflow: hidden;
}
.app-layout .sidebar.collapsed { width: 68px; }
.app-layout .sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}
.app-layout .sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
}
.app-layout .sidebar .logo svg { color: #64B5F6; flex-shrink: 0; }
.app-layout .sidebar.collapsed .logo span { opacity: 0; width: 0; }
.app-layout .sidebar-toggle {
  background: rgba(255,255,255,0.15);
  border: none;
  color: rgba(255,255,255,0.7);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.app-layout .sidebar-toggle:hover { background: rgba(255,255,255,0.25); color: #fff; }
.app-layout .sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }
.app-layout .sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; overflow-x: hidden; }
.app-layout .sidebar-nav::-webkit-scrollbar { width: 4px; }
.app-layout .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.app-layout .nav-section { margin-bottom: 16px; }
.app-layout .nav-section-title {
  padding: 0 12px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
  overflow: hidden;
}
.app-layout .sidebar.collapsed .nav-section-title { opacity: 0; height: 0; margin: 0; padding: 0; }
.app-layout .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}
.app-layout .nav-link:hover, .app-layout .nav-link.active { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.app-layout .nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.app-layout .sidebar.collapsed .nav-link span { opacity: 0; width: 0; }
.app-layout .sidebar-footer { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.app-layout .sidebar-footer .btn-outline { border-color: rgba(255,255,255,0.25); color: rgba(255,255,255,0.7); }
.app-layout .sidebar-footer .btn-outline:hover { border-color: #fff; color: #fff; background: rgba(255,255,255,0.1); }

.app-layout .main-wrapper { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; transition: margin-left 0.3s ease; }
.app-layout .sidebar.collapsed + .main-wrapper,
.app-layout .sidebar.collapsed ~ .main-wrapper { margin-left: 68px; }

.app-layout .top-header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-layout .hamburger { display: none; background: none; border: none; padding: 8px; border-radius: var(--radius); cursor: pointer; color: var(--text); }
.app-layout .hamburger:hover { background: #f0f0f0; }
.app-layout .header-search {
  position: relative;
  flex: 1;
  max-width: 360px;
  margin: 0 20px;
}
.app-layout .header-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.app-layout .header-search input {
  width: 100%;
  padding: 8px 12px 8px 38px !important;
  border: 1px solid var(--border) !important;
  border-radius: 20px !important;
  font-size: 13px !important;
  background: var(--bg) !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
  outline: none !important;
  box-sizing: border-box !important;
}
.app-layout .header-search input:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(13, 71, 161, 0.12) !important;
  background: #fff !important;
}
.app-layout .header-actions { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.app-layout .user-menu { position: relative; }
.app-layout .user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  border: none; cursor: pointer;
}
.app-layout .user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 200px;
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
  z-index: 100;
}
.app-layout .user-menu:hover .user-dropdown,
.app-layout .user-dropdown:hover { opacity: 1; visibility: visible; transform: translateY(0); }
.app-layout .user-info { padding: 8px 12px; }
.app-layout .user-info strong { display: block; font-size: 14px; }
.app-layout .user-info small { color: var(--text-muted); font-size: 12px; }
.app-layout .dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: none; background: none;
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text);
  cursor: pointer; text-align: left; text-decoration: none;
}
.app-layout .dropdown-item:hover { background: #EEF2FF; color: var(--primary); text-decoration: none; }

.app-layout .main-content { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }

.app-layout .page-transition {
  animation: pageIn 0.35s ease-out;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.classification-scale { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.class-card {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.class-card .class-icon { font-size: 18px; }
.class-card .class-info { }
.class-card .class-name { font-weight: 600; }
.class-card .class-range { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.app-layout .grade-first { background: linear-gradient(135deg, #1B5E20, #2E7D32); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.app-layout .grade-second-upper { background: linear-gradient(135deg, #1565C0, #1976D2); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.app-layout .grade-second-lower { background: linear-gradient(135deg, #E65100, #EF6C00); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.app-layout .grade-third { background: linear-gradient(135deg, #880E4F, #AD1457); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.app-layout .grade-pass { background: linear-gradient(135deg, #4E342E, #5D4037); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.app-layout .grade-fail { background: linear-gradient(135deg, #B71C1C, #C62828); color: #fff; padding: 3px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }

@media (max-width: 992px) {
  .app-layout .sidebar { transform: translateX(-100%); }
  .app-layout .sidebar.open { transform: translateX(0); }
  .app-layout .sidebar.collapsed { width: var(--sidebar-width); }
  .app-layout .sidebar.collapsed .logo span { opacity: 1; width: auto; }
  .app-layout .sidebar.collapsed .nav-section-title { opacity: 1; height: auto; padding: 0 12px 8px; }
  .app-layout .sidebar.collapsed .nav-link span { opacity: 1; width: auto; }
  .app-layout .sidebar.collapsed .sidebar-toggle { transform: none; }
  .app-layout .sidebar.collapsed + .main-wrapper,
  .app-layout .sidebar.collapsed ~ .main-wrapper { margin-left: 0; }
  .app-layout .main-wrapper { margin-left: 0; }
  .app-layout .hamburger { display: flex; }
  .app-layout .header-search { max-width: 200px; }
}
@media (max-width: 768px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .search-filter { width: 100%; }
  .search-filter .form-control { max-width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
}
