:root {
  --sb-width: 256px;
  --tb-height: 72px;
  --sb-bg: #0a2a6b;
  --sb-bg2: #0d3a8c;
  --sb-text: #dbe6ff;
  --brand: #1f63e0;
  --brand-2: #1fa2a6;
  --navy: #0d2f6e;
  --bg: #eef3fb;
}
* { box-sizing: border-box; }
html, body { font-family: 'Sarabun', system-ui, sans-serif; font-size: 15.5px; background: var(--bg); color: #222; }
a { text-decoration: none; }
h1, h2, h3, h4, h5 { font-weight: 600; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sb-width); flex-shrink: 0; color: var(--sb-text); position: fixed; top: 0; bottom: 0; left: 0; z-index: 1040;
  display: flex; flex-direction: column; transition: transform .25s; overflow: hidden;
  background: radial-gradient(120% 40% at 0% 100%, rgba(31,99,224,.55), transparent 60%), linear-gradient(180deg, #082257 0%, var(--sb-bg) 40%, var(--sb-bg2) 100%);
}
.main { flex: 1; margin-left: var(--sb-width); display: flex; flex-direction: column; min-width: 0; }
.content { padding: 1.25rem; flex: 1; }
.content-plain { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }
.page-title { font-family: 'Prompt', 'Sarabun', sans-serif; font-size: 1.3rem; font-weight: 600; margin: 0 0 1rem; color: var(--navy); }

/* ---------- topbar ---------- */
.topbar {
  height: var(--tb-height); padding: 0 1.25rem; display: flex; align-items: center; gap: 1rem; color: #fff;
  position: sticky; top: 0; z-index: 1020;
  background: linear-gradient(90deg, #0b3b9c 0%, #1554c8 55%, #1f6ae6 100%); box-shadow: 0 4px 18px -8px rgba(10,42,107,.6);
}
.tb-burger { border: 0; background: rgba(255,255,255,.14); color: #fff; width: 40px; height: 40px; border-radius: 10px; font-size: 1.4rem; display: grid; place-items: center; }
.tb-title { border-left: 4px solid #fff; padding-left: .9rem; min-width: 0; }
.tb-name { font-family: 'Prompt', 'Sarabun', sans-serif; font-weight: 600; font-size: 1.15rem; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-size: .85rem; opacity: .85; white-space: nowrap; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.tb-chip { align-items: center; gap: .4rem; font-size: .85rem; padding: .35rem .75rem; border-radius: 99px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.18); white-space: nowrap; }
.tb-user { display: flex; align-items: center; gap: .6rem; border: 0; background: transparent; color: #fff; padding: .3rem .5rem; border-radius: 12px; text-align: left; }
.tb-user:hover, .tb-user[aria-expanded="true"] { background: rgba(255,255,255,.12); }
.tb-avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem;
  background: linear-gradient(135deg, #ffd166, #f4a100); color: #0a2a6b; border: 2px solid rgba(255,255,255,.85); flex: none; }
.tb-user-text { line-height: 1.2; }
.tb-user-name { display: block; font-weight: 600; font-size: .95rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-user-role { display: block; font-size: .8rem; opacity: .8; }
.tb-user .bi-chevron-down { font-size: .8rem; opacity: .8; }
.dropdown-menu { border-radius: 12px; padding: .4rem; }
.dropdown-item { border-radius: 8px; padding: .45rem .75rem; }

/* ---------- sidebar ---------- */
.brand { height: var(--tb-height); display: flex; align-items: center; gap: .7rem; padding: 0 1rem; color: #fff; background: rgba(0,0,0,.18); flex: none; }
.brand:hover { color: #fff; }
.brand-emblem { height: 52px; width: auto; filter: drop-shadow(0 3px 6px rgba(0,0,0,.35)); }
.brand-title { font-family: 'Prompt', 'Sarabun', sans-serif; font-weight: 600; font-size: 1.15rem; line-height: 1.15; }
.brand-sub { font-size: .7rem; letter-spacing: .2em; opacity: .85; }
.sidebar .nav { flex: 1; overflow-y: auto; padding: 1rem .75rem; gap: .3rem; flex-wrap: nowrap; }
.sidebar .nav::-webkit-scrollbar { width: 6px; }
.sidebar .nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }
.sidebar .nav-link { color: var(--sb-text); padding: .65rem .85rem; border-radius: 12px; display: flex; align-items: center; gap: .8rem; font-size: .98rem; font-weight: 500; transition: background .15s, color .15s; }
.sidebar .nav-link > .bi:first-child { width: 22px; text-align: center; font-size: 1.15rem; }
.sidebar .nav-link span { flex: 1; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar .nav-link.active, .sidebar .nav-toggle.open { color: #fff; font-weight: 600;
  background: linear-gradient(90deg, #1f6ae6, #2b80f5); box-shadow: 0 8px 18px -8px rgba(31,106,230,.9), inset 0 1px 0 rgba(255,255,255,.2); }
.sidebar .caret { font-size: .8rem; transition: transform .2s; }
.sidebar .nav-toggle:not(.collapsed) .caret { transform: rotate(180deg); }
.nav-subs { margin: .3rem 0 .2rem; padding: .35rem 0; background: rgba(255,255,255,.06); border-radius: 12px; }
.nav-sub { display: flex; align-items: center; gap: .6rem; padding: .45rem .9rem .45rem 2.6rem; color: var(--sb-text); font-size: .92rem; }
.nav-sub:hover { color: #fff; }
.nav-sub.active { color: #ffd166; font-weight: 600; }.sidebar-foot { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.1); flex: none;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.15)); }
.sf-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.5rem; color: #8fc2ff; background: rgba(255,255,255,.08); flex: none; }
.sf-title { font-family: 'Prompt', 'Sarabun', sans-serif; font-weight: 600; color: #fff; }
.sf-quote { font-size: .78rem; opacity: .8; line-height: 1.4; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }

/* ---------- footer ---------- */
.footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; padding: .8rem 1.25rem; font-size: .8rem; color: #5d6b8f; background: #fff; border-top: 1px solid #e3e9f5; }
.footer .sep { margin: 0 .4rem; color: #c3cbe0; }

/* ---------- collapsible sidebar (จอใหญ่: ย่อเหลือแต่ไอคอน, ชี้เมาส์แล้วขยายทับเนื้อหา) ---------- */
@media (min-width: 992px) {
  :root { --sb-mini: 76px; }
  .sidebar { transition: width .2s ease, box-shadow .2s; }
  .main { transition: margin-left .2s ease; }
  .sidebar .nav-link, .brand, .sidebar-foot { white-space: nowrap; }
  .sb-mini .main { margin-left: var(--sb-mini); }
  .sb-mini .sidebar:not(:hover) { width: var(--sb-mini); }
  .sb-mini .sidebar:hover { box-shadow: 8px 0 24px -6px rgba(10,42,107,.45); }
  .sb-mini .sidebar:not(:hover) .brand-text,
  .sb-mini .sidebar:not(:hover) .nav-link span,
  .sb-mini .sidebar:not(:hover) .caret,
  .sb-mini .sidebar:not(:hover) .collapse,
  .sb-mini .sidebar:not(:hover) .sidebar-foot > div:not(.sf-icon) { display: none; }
  .sb-mini .sidebar:not(:hover) .nav { overflow-y: hidden; }
}

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; }
  .topbar { padding: 0 .9rem; gap: .7rem; }
  .tb-title { border-left-width: 3px; padding-left: .7rem; }
}
@media (max-width: 575.98px) {
  .tb-name { font-size: 1rem; }
  .tb-sub { display: none; }
}

/* ---------- components ---------- */
.card { border: 0; border-radius: 14px; box-shadow: 0 2px 10px rgba(30,42,90,.06); }
.card-header { background: #fff; border-bottom: 1px solid #edf0f8; font-weight: 600; border-radius: 14px 14px 0 0 !important; }
.table thead th { background: #eef3fd; color: var(--navy); font-weight: 600; white-space: nowrap; }
.table-sm td, .table-sm th { padding: .35rem .5rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: #1650c0; border-color: #1650c0; }
.form-control, .form-select { border-radius: 8px; }
.filter-bar { background: #fff; border-radius: 14px; padding: .9rem 1rem; box-shadow: 0 2px 10px rgba(30,42,90,.06); margin-bottom: 1rem; }
.grade-badge { font-size: .9rem; min-width: 2.6em; }
.grade-badge.bg-success { background-color: #28a745 !important; }   /* เขียวเดียวกับหัวตารางหน้าเช็คผลการเรียน */
.score-input { width: 72px; text-align: center; }
.score-input.is-over { border-color: #dc3545; background: #fff0f0; }

/* ตารางกรอกคะแนนทุกวิชา (grade/entry.php) — หัวคอลัมน์รหัสวิชาแนวตั้ง (อ่านจากล่างขึ้นบน), ชื่อนักเรียนตรึงซ้ายตอนเลื่อน */
.grid-wrap { max-height: calc(100vh - 230px); }
.grid-tbl thead th { position: sticky; top: 0; z-index: 2; }
/* เกรดเฉลี่ยรายคน ท้ายช่องชื่อ */
.grid-tbl .grid-gpa { min-width: 46px; padding: .1rem .45rem; border-radius: 6px; background: #28a745; color: #fff; font-weight: 700; font-size: .85rem; text-align: center; }
.grid-tbl .grid-pdf { padding: .1rem .45rem; border-radius: 6px; border: 1px solid #dc3545; color: #dc3545; font-size: .78rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.grid-tbl .grid-pdf:hover { background: #dc3545; color: #fff; }
.grid-credit { background-color: #28a745 !important; font-weight: 600; font-size: .8rem; padding: .35em .75em; vertical-align: middle; }
/* ชั่วโมง/สัปดาห์ ใต้วงกลมเลขวิชา */
.grid-tbl .grid-hrs { display: block; margin: -1px auto 3px; font-style: normal; font-size: .66rem; font-weight: 600; line-height: 1.1; color: #1d7a3a; white-space: nowrap; }
/* วงกลมเลขลำดับวิชา บนสุดของหัวคอลัมน์ */
.grid-tbl .grid-no { display: block; width: 20px; height: 20px; margin: 0 auto 4px; border-radius: 50%; background: #28a745; color: #fff;
  font-size: .68rem; font-weight: 700; line-height: 20px; text-align: center; box-shadow: 0 2px 4px -1px rgba(40,167,69,.5); }
.grid-tbl .grid-subj { width: 54px; min-width: 54px; height: 112px; padding: .3rem 0; vertical-align: bottom; cursor: help; }
/* รหัสวิชา + ชื่อวิชาตัวเล็ก วางแนวตั้งคู่กัน (อ่านจากล่างขึ้นบน) ชื่อยาวกว่ารหัสตัดด้วย … (ชี้เมาส์ดูชื่อเต็ม) */
.grid-tbl .grid-subj span, .grid-tbl .grid-subj small { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; vertical-align: bottom; height: 58px;
  text-align: start; line-height: 1; }   /* text-align: start = เริ่มที่ขอบล่างเสมอ (กัน text-center ของ th ดันชื่อสั้นลอยขึ้น) */
.grid-tbl .grid-subj span { font-weight: 600; font-size: .95rem; letter-spacing: .03em; }
.grid-tbl .grid-subj small { font-size: .68rem; font-weight: 400; opacity: .8; overflow: hidden; text-overflow: ellipsis; margin-left: 7px; }   /* ช่องว่างระหว่างรหัสกับชื่อ (ใส่ด้านในเพื่อให้คู่นี้อยู่กึ่งกลางคอลัมน์) */
.grid-tbl .grid-subj.type-basic    { color: #1f4fbf; }
.grid-tbl .grid-subj.type-extra    { color: #7a3fc2; background: #f4eefc; }
.grid-tbl .grid-subj.type-activity { color: #11804a; background: #eaf7f0; }
/* คุณลักษณะอันพึงประสงค์ / อ่าน คิดวิเคราะห์ เขียน ต่อท้ายตาราง (ข้อความยาวกว่ารหัสวิชา → ตัวเล็กลง แนวยาวขึ้น) */
.grid-tbl .grid-subj.type-attr { color: #b45309; background: #fff4e5; }
.grid-tbl .grid-subj.type-attr .grid-no { background: #f59e0b; box-shadow: 0 2px 4px -1px rgba(245,158,11,.5); font-size: .6rem; }
.grid-tbl .grid-subj.type-attr span, .grid-tbl .grid-subj.type-attr small { height: 76px; }
.grid-tbl .grid-subj.type-attr span { font-size: .78rem; letter-spacing: 0; }
.grid-tbl td.grid-attr { background: #fffaf2; }
/* ช่องเลือกระดับแสดงข้อความเต็ม เช่น "3 ดีเยี่ยม" → คอลัมน์กว้างกว่าช่องคะแนน */
.grid-tbl .grid-subj.type-attr, .grid-tbl td.grid-attr { width: 100px; min-width: 100px; max-width: 100px; }
.grid-tbl td.grid-attr select.grid-in { width: 92px; min-width: 92px; max-width: 92px; margin: 0 auto; padding-left: .4rem; padding-right: 1.5rem; text-align-last: left;
  background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") no-repeat right .4rem center / 12px 10px; }
.grid-tbl td.grid-attr select.grid-in:disabled { background-color: #e9ecef; }
.grid-tbl .grid-name { position: sticky; left: 0; z-index: 1; background: #fff; min-width: 210px; width: 100%; }   /* รับพื้นที่ส่วนเกินทั้งหมด → คอลัมน์วิชากว้างเท่ากันทุกช่อง */
.grid-tbl .grid-subj, .grid-tbl td.grid-cell { width: 54px; min-width: 54px; max-width: 54px; }
.grid-tbl thead .grid-name { z-index: 3; background: #eef3fd; }
/* ช่องกรอกตัวเลขและช่องเลือก ผ/มผ ใช้กล่องขนาดเดียวกันทุกค่า (ทับค่าของ .form-control / .form-select) */
.grid-tbl .grid-in, .grid-tbl select.grid-in, .grid-tbl input.grid-in { display: block; box-sizing: border-box; width: 46px; min-width: 46px; max-width: 46px; height: 30px; min-height: 0;
  margin: 0 auto; padding: 0 .15rem; line-height: 28px; text-align: center; font-size: .92rem; font-family: inherit; color: #212529;
  border: 1px solid #ced4da; border-radius: 6px; background-color: #fff; background-image: none; -webkit-appearance: none; appearance: none; }
.grid-tbl select.grid-in { text-align-last: center; }
.grid-tbl .grid-in:focus { border-color: #86b7fe; box-shadow: 0 0 0 .2rem rgba(13,110,253,.2); outline: 0; }
.grid-tbl .grid-in[readonly], .grid-tbl .grid-in:disabled { background-color: #e9ecef; color: #6c757d; }
.grid-tbl .grid-in.is-over { border-color: #dc3545; background: #fff0f0; }
.grid-tbl input[type=number]::-webkit-inner-spin-button, .grid-tbl input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.grid-tbl input[type=number] { -moz-appearance: textfield; }
.grid-grd { font-size: .7rem; line-height: 1; height: .8rem; margin-top: 2px; font-weight: 700; }
.grid-grd.g-hi { color: #198754; } .grid-grd.g-mid { color: #b58100; } .grid-grd.g-low { color: #dc3545; }
.total-cell { font-weight: 600; }
.stat-card { border-radius: 14px; padding: 1rem 1.1rem; color: #fff; display: flex; align-items: center; gap: .9rem; }
.stat-card i { font-size: 2rem; opacity: .85; }
.stat-card .num { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-card .lbl { font-size: .85rem; opacity: .9; }

/* login: ดู assets/css/login.css · หน้าหลัก: ดู assets/css/dashboard.css */

/* public check */
.check-hero { background: linear-gradient(135deg, #0a2a6b, #1f63e0); color: #fff; border-radius: 20px; padding: 2rem 1.5rem; text-align: center; margin-bottom: 1.25rem; }

/* print */
.print-head { display: none; }
@media print {
  body { background: #fff; font-size: 13px; }
  .sidebar, .topbar, .footer, .no-print, .sidebar-backdrop, .page-title { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  .print-head { display: block; text-align: center; margin-bottom: .75rem; }
  a[href]:after { content: ''; }
}
