/* ===================================================================
   Giao diện hệ thống quản lý học sinh VLLL
   =================================================================== */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16202c;
  --muted: #667287;
  --line: #e3e7ee;
  --brand: #1f5eff;
  --brand-dark: #1748c9;
  --brand-soft: #eef3ff;
  --ok: #128a52;
  --ok-soft: #e6f6ee;
  --warn: #b7791f;
  --warn-soft: #fdf5e4;
  --danger: #c33232;
  --danger-soft: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------- Đăng nhập ------------------------------ */
.auth-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, #eef3ff 0%, #f6f7f9 45%, #f6f7f9 100%);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); padding: 32px;
  border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.auth-logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .5px; margin-bottom: 18px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; }
.auth-card label { display: block; margin-bottom: 14px; font-weight: 500; }
.auth-card input { margin-top: 6px; }

/* ------------------------- Khung ứng dụng ------------------------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: #101725; color: #c9d3e3; display: flex; flex-direction: column;
  padding: 18px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
  background: var(--brand); color: #fff; font-weight: 800; font-size: 11px;
  padding: 6px 8px; border-radius: 8px; letter-spacing: .5px;
}
.brand-text { font-weight: 600; color: #fff; font-size: 14px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #a8b5c9; cursor: pointer; font-weight: 500; border: none; background: none;
  width: 100%; text-align: left; font-family: inherit; font-size: 14px;
}
.nav-item:hover { background: #1a2333; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #5d6b82; padding: 16px 10px 6px; }
.sidebar-foot { border-top: 1px solid #1f2a3c; padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.user-meta { display: flex; flex-direction: column; overflow: hidden; }
.user-meta strong { color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11px; color: #7d8aa0; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 17px; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.view { padding: 22px 24px 60px; }

/* ------------------------- Thành phần ----------------------------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

button, .btn {
  font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  border-radius: 8px; border: 1px solid transparent; padding: 8px 14px; transition: .12s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-default { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-default:hover { background: #f2f4f8; }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.sidebar .btn-ghost { color: #a8b5c9; }
.sidebar .btn-ghost:hover { background: #1a2333; color: #fff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { padding: 6px 10px; }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }
label.field { display: block; margin-bottom: 12px; font-weight: 500; font-size: 13px; }
label.field > input, label.field > select, label.field > textarea { margin-top: 5px; font-weight: 400; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fafbfd; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tbody tr:hover { background: #fafbfd; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #eef0f4; color: var(--muted); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.progress { height: 6px; background: #eef0f4; border-radius: 999px; overflow: hidden; min-width: 90px; }
.progress > span { display: block; height: 100%; background: var(--brand); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 14px; border: none; background: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Bảng nhập nhận xét */
.review-table input[type="number"] { width: 64px; padding: 6px 8px; }
.review-table textarea { min-height: 38px; font-size: 13px; padding: 6px 8px; }
.review-table td { vertical-align: top; padding: 8px 8px; }
.review-table th { padding: 8px; }
/* Cột họ tên dính bên trái để không mất dấu khi cuộn ngang */
.review-table .name-cell,
.review-table thead th:first-child {
  position: sticky; left: 0; z-index: 2; min-width: 132px; font-weight: 600;
  box-shadow: 1px 0 0 var(--line);
}
.review-table .name-cell { background: #fff; }
.review-table thead th:first-child { background: #fafbfd; }
.review-table tbody tr:hover .name-cell { background: #fafbfd; }
.review-table tr.dirty .name-cell { background: #fffbe9; }
.flag-label { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 4px; cursor: pointer; }
.flag-label input { width: auto; }
.flag-label:has(input:checked) { color: var(--danger); font-weight: 600; }
.th-tag { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 10px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.th-print { background: var(--brand-soft); color: var(--brand); }
.th-internal { background: #eef0f4; color: var(--muted); }
.dirty { background: #fffbe9 !important; }
.trend-up { color: var(--ok); font-weight: 600; }
.trend-down { color: var(--danger); font-weight: 600; }

/* Băng cảnh báo trên trang Tổng quan */
.banner {
  background: var(--warn-soft); border: 1px solid #f0dcae; border-left: 4px solid var(--warn);
  color: #6b4a10; padding: 13px 16px; border-radius: var(--radius); margin-bottom: 16px;
}
.banner a { color: #6b4a10; font-weight: 600; }

/* Nút chèn mẫu câu trong ô nhận xét */
.cell-tpl { position: relative; }
.cell-tpl textarea { padding-right: 22px; }
.tpl-btn {
  position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; padding: 0;
  border: none; background: var(--brand-soft); color: var(--brand); border-radius: 4px;
  font-size: 11px; line-height: 1; cursor: pointer; opacity: .55;
}
.tpl-btn:hover { opacity: 1; }
.tpl-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.tpl-item {
  text-align: left; font-family: inherit; font-size: 13.5px; line-height: 1.5;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px;
  cursor: pointer; color: var(--ink);
}
.tpl-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.tpl-count { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
kbd {
  font-family: var(--font); font-size: 11px; background: #eef0f4; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}

/* Bảng sức khoẻ vận hành */
table.health { table-layout: fixed; }
table.health th { white-space: normal; line-height: 1.25; vertical-align: bottom; }
table.health th:first-child { width: auto; }
table.health th:nth-child(2) { width: 62px; }
table.health th:nth-child(3) { width: 96px; }
table.health th:nth-child(n+4) { width: 62px; }
table.health td.hm {
  text-align: center; font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums;
  border-left: 2px solid #fff;
}
.hm-0 { color: var(--muted); background: #f4f5f7; }
.hm-1 { background: #fbe3e3; color: #8f2020; }
.hm-2 { background: #fdf0d9; color: #8a5a11; }
.hm-3 { background: #e4f2e9; color: #1d6b45; }
.hm-4 { background: #cfeadd; color: #12603c; }
.late-dot { color: var(--danger); font-weight: 700; }

/* Chọn nhiều giáo viên phụ trách */
.teacher-picker { border: 1px solid var(--line); border-radius: 8px; max-height: 230px; overflow-y: auto; }
.teacher-row {
  display: grid; grid-template-columns: 20px 1fr auto auto; gap: 10px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 400; cursor: pointer; margin: 0;
}
.teacher-row:last-child { border-bottom: none; }
.teacher-row:hover { background: #fafbfd; }
.teacher-row input[type="checkbox"], .teacher-row input[type="radio"] { width: auto; margin: 0; }
.teacher-row .tname { font-weight: 500; }
.primary-pick { display: flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; margin: 0; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 88vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { max-width: 780px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* Toast */
.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #101725; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.only-mobile { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 248px; z-index: 60; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-flex; }
  .view { padding: 16px; }
  .topbar { padding: 12px 16px; }
}
