:root {
  --sidebar-bg: #1b2635;
  --sidebar-hover: #232f40;
  --sidebar-active-bg: #263447;
  --sidebar-text: #c4cddb;
  --sidebar-muted: #7f8b9c;

  --content-bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1f2733;
  --muted: #6b7480;
  --border: #e6e9ee;

  --primary: #2680eb;
  --primary-dark: #1a6fd0;
  --success: #27ae60;
  --success-bg: #e5f5ec;
  --danger: #e0526a;
  --warning: #f2a516;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--content-bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* ============ ADMIN SHELL ============ */
.app-shell { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar-brand img { width: 38px; height: 38px; }
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand .brand-title { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--sidebar-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  margin: 3px 0;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 15px;
  font-weight: 500;
}
.nav-link:hover { background: var(--sidebar-hover); text-decoration: none; color: #fff; }
.nav-link.active { background: var(--sidebar-active-bg); color: #fff; box-shadow: inset 3px 0 0 var(--primary); }
.nav-link .nav-icon { font-size: 17px; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sidebar-user { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-user .u-name { color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .u-role { color: var(--sidebar-muted); font-size: 12px; }
.btn-logout {
  background: transparent;
  border: 1px solid rgba(224, 82, 106, 0.5);
  color: #ef6b7e;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-logout:hover { background: rgba(224, 82, 106, 0.12); }

/* ---- Main ---- */
.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; }
.content { padding: 26px 32px 48px; flex: 1; }
.app-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 16px; }

/* ============ COMPONENTS ============ */

/* Cards / stat tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-card .stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 30px; font-weight: 700; }

/* Welcome banner */
.welcome-banner { background: var(--success-bg); border: 1px solid #bfe6cd; color: #1e7a45; padding: 14px 18px; border-radius: var(--radius); margin-bottom: 22px; font-weight: 500; }

/* Buttons */
.btn { display: inline-block; padding: 9px 18px; border-radius: 8px; font-weight: 600; font-size: 14px; border: 1px solid transparent; cursor: pointer; line-height: 1.4; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f7f9fb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c8465c; color: #fff; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.inline { display: inline; }

/* Icon buttons (đồng nhất kích thước, phân biệt bằng biểu tượng + tooltip) */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: #5b6674; cursor: pointer; line-height: 0;
}
.btn-icon:hover { background: #eef5fe; border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-icon.danger:hover { background: #fdeef0; border-color: var(--danger); color: var(--danger); }
.btn-icon svg { width: 17px; height: 17px; display: block; }

/* Icon buttons có nền màu */
.btn-icon.fill-view { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-icon.fill-view:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-icon.fill-edit { background: #f0a01e; border-color: #f0a01e; color: #fff; }
.btn-icon.fill-edit:hover { background: #d98e12; border-color: #d98e12; color: #fff; }
.btn-icon.fill-perm { background: #12a3a3; border-color: #12a3a3; color: #fff; }
.btn-icon.fill-perm:hover { background: #0e8a8a; border-color: #0e8a8a; color: #fff; }
.btn-icon.fill-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-icon.fill-danger:hover { background: #c8465c; border-color: #c8465c; color: #fff; }

/* Căn phải cụm nút trong ô */
.row-actions.right { justify-content: flex-end; }

/* ===== Loading overlay (chặn thao tác khi import/đồng bộ) ===== */
.loading-overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.55); display: none; align-items: center; justify-content: center; z-index: 2000; }
.loading-overlay.open { display: flex; }
.loading-box { background: #fff; border-radius: 14px; padding: 30px 40px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); max-width: 380px; }
.spinner { width: 46px; height: 46px; border: 4px solid #e3e8ef; border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 16px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.loading-sub { color: var(--muted); font-size: 14px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-weight: 500; }
.flash-success { background: var(--success-bg); color: #1e7a45; }
.flash-error { background: #fdeaed; color: #b23a4e; }
.flash-info { background: #e7f1fd; color: #1a5fb0; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* Forms */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; max-width: 460px; box-shadow: var(--shadow); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; color: #33404f; }
.form-group input, .form-group select { width: 100%; padding: 10px 13px; border: 1.5px solid #cbd3de; border-radius: 8px; font-size: 15px; background: #fff; color: var(--text); }
.form-group input::placeholder { color: #9aa4b2; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(38, 128, 235, 0.15); }
.filter-bar input, .filter-bar select { border-width: 1.5px; border-color: #cbd3de; }

/* Page header / actions bar */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { margin: 0; font-size: 24px; }
.actions-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.actions-bar .spacer { flex: 1; }
.detail-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.detail-head .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.detail-head .title-lg { font-size: 20px; font-weight: 700; }
.muted { color: var(--muted); }

/* Toolbar & filter */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.toolbar-item { display: flex; align-items: center; gap: 8px; margin: 0; }
.toolbar-item input[type="file"] { font-size: 13px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filter-bar input, .filter-bar select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; }
.filter-bar input[type="text"] { min-width: 240px; }

/* Info card (student detail) */
.info-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }
.info-card > div { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.semester-title { margin: 22px 0 8px; font-size: 16px; color: var(--primary); }

/* ============ AUTH (login) ============ */
.auth-body { min-height: 100vh; margin: 0; background: #131c2b; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 440px; text-align: center; }
.auth-logo { height: 88px; width: auto; margin: 0 auto 26px; display: block; }
.auth-card { background: #fff; border-radius: 14px; padding: 34px 30px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); text-align: left; }
.auth-card .form-group input { background: #fff; border: 1.5px solid #cbd3de; padding: 13px 14px; }
.auth-card .btn { width: 100%; padding: 13px; font-size: 16px; margin-top: 6px; }
.auth-footer { color: #5b6779; font-size: 13px; margin-top: 22px; }
.auth-error { background: #fdeaed; color: #b23a4e; padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }

/* ===== Class info card ===== */
.class-info-card { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.ci-item { flex: 1 1 160px; padding: 14px 20px; border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.ci-item:first-child { border-left: none; }
.ci-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.ci-value { font-size: 17px; font-weight: 700; }
.ci-value.sm { font-size: 15px; font-weight: 600; word-break: break-word; }
.ci-wide { flex: 2 1 260px; }

/* Section header (mục trong trang) */
.section-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 18px; }

/* ===== Badge / label ===== */
.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eef1f5; color: #47536b; }
.badge-success { background: var(--success-bg); color: #1e7a45; }
.badge-warning { background: #fdf0d9; color: #a76a09; }
.badge-danger { background: #fdeaed; color: #b23a4e; }

/* ===== Gender ===== */
.gender { display: inline-flex; align-items: center; gap: 5px; }
.gender-male { color: #2680eb; font-weight: 700; }
.gender-female { color: #e0568a; font-weight: 700; }

/* ===== Dropdown ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(16, 24, 40, 0.14); min-width: 240px; padding: 6px; display: none; z-index: 50; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu form { margin: 0; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: none; padding: 10px 12px; border-radius: 7px; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; text-decoration: none; }
.dropdown-item:hover { background: #f2f6fb; text-decoration: none; }
.dropdown-item .di-icon { font-size: 16px; width: 18px; text-align: center; }

/* Filter bar full-width */
.filter-bar.full { width: 100%; }
.filter-bar.full .f-search { flex: 1 1 auto; min-width: 200px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.5); display: none; align-items: flex-start; justify-content: center; padding: 64px 20px; z-index: 1000; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 460px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3); overflow: hidden; animation: modal-in 0.15s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.perm-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; margin-bottom: 4px; }
.perm-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.perm-item:hover { background: #f2f6fb; }
.perm-item input { width: auto; }

/* Responsive */
@media (max-width: 820px) {
  .sidebar { position: static; width: 100%; height: auto; }
  .main { margin-left: 0; }
  .app-shell { flex-direction: column; }
}
