:root {
  --brand: #0f4c5c;
  --brand-2: #e36414;
  --ok: #2a9d8f;
  --warn: #e9c46a;
  --bad: #d62828;
}
body { font-family: 'Sarabun', system-ui, sans-serif; background: #f4f6f8; font-size: 15px; }
.bg-brand { background: var(--brand); }
.navbar .nav-link.active { border-bottom: 2px solid var(--brand-2); }
/* เมนู v4.30: ไม่ตัดบรรทัด · หัวข้อกลุ่ม · เมนูยาวเลื่อนได้ */
.navbar .nav-link, .navbar-brand, .navbar .btn { white-space: nowrap; }
@media (min-width: 1200px) { .navbar .navbar-text { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
.navbar .dropdown-menu { max-height: calc(100vh - 90px); overflow-y: auto; min-width: 17rem; }
.navbar .dropdown-header { font-size: .75rem; font-weight: 700; color: var(--brand); text-transform: none; padding-top: .5rem; border-top: 1px solid #eee; }
.navbar .dropdown-menu > li:first-child .dropdown-header { border-top: 0; padding-top: .25rem; }
.navbar .dropdown-item { padding-top: .3rem; padding-bottom: .3rem; }
@media (min-width: 1200px) and (max-width: 1499px) { .navbar:not(.nav-anon) .navbar-brand .brand2 { max-width: 13rem; } .navbar:not(.nav-anon) .navbar-brand { max-width: 15rem; overflow: hidden; text-overflow: ellipsis; } .navbar .nav-link { padding-left: .45rem !important; padding-right: .45rem !important; } }
#navFind .list-group-item.active { background: var(--brand); border-color: var(--brand); }
#navFind .nf-cat { font-size: .75rem; opacity: .7; }
.filter .form-label { font-size: .85rem; color: #555; margin-bottom: .2rem; }

.stat { border: 0; border-left: 5px solid #999; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat .label { font-size: .9rem; color: #666; }
.stat .value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat .sub { font-size: .85rem; color: #777; }
.stat.total  { border-color: var(--brand); }
.stat.ok     { border-color: var(--ok); }   .stat.ok .value { color: var(--ok); }
.stat.late   { border-color: var(--warn); } .stat.late .value { color: #b8860b; }
.stat.out    { border-color: #0d6efd; } .stat.out .value { color: #0d6efd; }
.stat.bad    { border-color: var(--bad); }  .stat.bad .value { color: var(--bad); }

.table-report { background: #fff; font-size: .92rem; }
.table-report th { background: #e9eef1; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table-report td.num, .table-report th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { max-height: 70vh; overflow: auto; border-radius: .4rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.progress-thin { height: 8px; min-width: 80px; }
tr.row-absent td { background: #fff5f5; }
.mono { font-variant-numeric: tabular-nums; }
.print-only { display: none; }
.print-table-alt { display: none; }

@media print {
  @page { size: A4; margin: 10mm 8mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }       /* พิมพ์สีพื้นในตาราง/การ์ด */
  main.container-fluid, main { padding: 0 !important; max-width: none !important; }
  .row > .col-6.col-lg { flex: 1 0 0% !important; width: auto !important; max-width: none !important; }   /* การ์ดสรุปเรียงแถวเดียว */
  .card.stat .card-body { padding: .45rem .6rem; }
  .card.stat .value { font-size: 1.35rem; }
  canvas { max-width: 100% !important; }
  h4, h5, h6 { break-after: avoid; page-break-after: avoid; }
  tr, .card { break-inside: avoid; page-break-inside: avoid; }
  thead { display: table-header-group; }
  .table-report { font-size: 10.5px; }
  .table-report th, .table-report td { padding: .18rem .35rem !important; }
  .print-break { break-before: page; page-break-before: always; }
  .print-foot { display: block !important; position: fixed; bottom: 0; right: 0; font-size: 9px; color: #555; }
  .no-print { display: none !important; }
  a.btn, button.btn, input.btn, .btn-close, .modal, .toast-container, details > summary::marker { display: none !important; }   /* ปุ่มไม่ต้องพิมพ์ (label ของตัวเลือกยังแสดง) */
  .sticky-top, .position-sticky { position: static !important; }
  .btn-check:not(:checked) + label.btn { display: none !important; }          /* หน้าเช็คชื่อ/ตรวจ: พิมพ์เฉพาะสถานะที่เลือก */
  .btn-check:checked + label.btn { border-radius: .3rem !important; padding: .05rem .5rem !important; font-size: 11px; }
  .btn-group { display: inline-flex !important; width: auto !important; }
  .list-group-item { padding: .25rem .5rem !important; break-inside: avoid; }
  .list-group-item .d-flex.mb-1 { margin-bottom: 0 !important; display: inline-flex !important; width: 72%; }
  .list-group-item .btn-group, .list-group-item .d-flex.flex-wrap.gap-1 { vertical-align: middle; }
  .pc-note:placeholder-shown, .dr-note:placeholder-shown { display: none !important; }
  /* พิมพ์แบบตาราง (หน้าที่มีตารางสำรอง .print-table-alt) */
  .print-table .print-table-alt { display: block !important; }
  .print-table .print-cards { display: none !important; }
  .print-table-alt td, .print-table-alt th { vertical-align: middle; }
  .print-table .avatar { display: none !important; }
  /* พิมพ์แบบไม่มีรูป */
  .print-nophoto .avatar, .print-nophoto img.avatar, .print-nophoto .sq { display: none !important; }
  .print-nophoto .student-grid { grid-template-columns: repeat(4, 1fr) !important; gap: .2rem !important; }
  .print-nophoto .student-card { padding: .15rem .4rem !important; text-align: left !important; border-top-width: 2px !important; min-height: 0 !important; }
  .print-nophoto .student-card .no { position: static !important; display: inline; margin-right: .3rem; }
  .print-nophoto .student-card .nm { display: inline; margin-top: 0 !important; font-size: 11px; }
  .print-nophoto .student-card .tm, .print-nophoto .student-card > div { font-size: 10px; }
  .print-nophoto .name-cell { gap: 0 !important; }
  .print-head { font-size: 13px; border-bottom: 1.5px solid #333; padding-bottom: 2px; margin-bottom: 6px !important; }
  .nav-tabs, .nav-pills { display: none !important; }
  .table-wrap, .table-responsive { overflow: visible !important; max-height: none !important; }
  a[href] { color: inherit !important; text-decoration: none !important; }
  .badge { border: 1px solid rgba(0,0,0,.25); }
  input.form-control, select.form-select { border: 0 !important; padding: 0 !important; background: none !important; -webkit-appearance: none; appearance: none; }
  .print-only { display: block; }
  td.print-only, th.print-only { display: table-cell; }
  body { background: #fff; font-size: 12px; }
  .table-wrap { max-height: none; overflow: visible; box-shadow: none; }
  .table-report th { position: static; }
  .card { box-shadow: none !important; }
  a { text-decoration: none; color: inherit; }
}

/* ---------- ตัวเลือกวันที่ พ.ศ. / เวลา 24 ชม. (assets/thai-date.js) ---------- */
.tdp-input {
  padding-right: 2.2rem;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23555' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z'/%3E%3C/svg%3E") no-repeat right .7rem center;
  cursor: pointer;
}
.tdp-pop {
  position: absolute; z-index: 2000; width: 292px; background: #fff; border: 1px solid #cfd6dc;
  border-radius: .5rem; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: .5rem; font-size: .95rem; user-select: none;
}
.tdp-head { display: flex; gap: .25rem; align-items: center; margin-bottom: .35rem; }
.tdp-head select { flex: 1; min-width: 0; border: 1px solid #cfd6dc; border-radius: .35rem; padding: .2rem .3rem; background: #fff; font: inherit; }
.tdp-head select[data-f="y"] { flex: 0 0 74px; }
.tdp-nav { border: 0; background: #eef2f4; border-radius: .35rem; width: 30px; height: 30px; font-size: 1.1rem; line-height: 1; }
.tdp-nav:hover { background: #dde5ea; }
.tdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.tdp-dow { text-align: center; font-size: .8rem; color: #667; padding: .15rem 0; font-weight: 600; }
.tdp-dow.we, .tdp-day.we { color: #c0392b; }
.tdp-day { border: 0; background: none; border-radius: .35rem; height: 34px; font: inherit; }
.tdp-day:hover:not(:disabled) { background: #e8f1f4; }
.tdp-day.today { outline: 1px solid var(--brand, #0f4c5c); }
.tdp-day.sel { background: var(--brand, #0f4c5c); color: #fff; font-weight: 700; }
.tdp-day:disabled { opacity: .3; }
.tdp-foot { display: flex; justify-content: space-between; margin-top: .35rem; }
.tdp-foot button { border: 0; background: none; color: #0d6efd; padding: .2rem .4rem; font: inherit; }
.tdp-time { flex-wrap: nowrap; }
.tdp-time .form-select { padding-right: 1.8rem; min-width: 4.2rem; }
@media print { .tdp-pop { display: none !important; } }

/* ---------- รูปนักเรียน ---------- */
.avatar { border-radius: 50%; object-fit: cover; background: #e9eef1; flex-shrink: 0; vertical-align: middle; }
.avatar.sq { border-radius: .6rem; }
.name-cell { display: flex; align-items: center; gap: .55rem; }
.name-cell .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 3px #dfe5ea; }
.st-ontime .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ok); }
.st-late .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--warn); }
.st-absent .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--bad); filter: grayscale(.6); }
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.student-card { background: #fff; border-radius: .7rem; padding: .8rem .6rem; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-top: 4px solid #ccd; position: relative; transition: transform .12s; }
.student-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.student-card.st-ontime { border-top-color: var(--ok); }
.student-card.st-late { border-top-color: var(--warn); }
.student-card.st-absent { border-top-color: var(--bad); background: #fff8f8; }
.student-card .no { position: absolute; top: .35rem; left: .5rem; font-size: .75rem; color: #889; }
.student-card .nm { font-weight: 600; line-height: 1.25; margin-top: .45rem; font-size: .93rem; }
.student-card .tm { font-variant-numeric: tabular-nums; font-size: .85rem; color: #555; }
.student-card a { color: inherit; text-decoration: none; }
@media print {
  .student-grid { grid-template-columns: repeat(6, 1fr); gap: .4rem; }
  .student-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .avatar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* การ์ดหน้าภาพรวมที่กดดูรายชื่อได้ */
.stat.stat-link { transition: transform .12s, box-shadow .12s; cursor: pointer; }
.stat.stat-link:hover { transform: translateY(-2px); box-shadow: 0 .4rem 1rem rgba(0,0,0,.12); }
.stat .stat-go { opacity: .5; font-weight: 700; }
.stat.stat-link:hover .stat-go { opacity: 1; }
.stat .stat-sublink { position: relative; z-index: 2; }

.stat.info { border-color: #0dcaf0; } .stat.info .value { color: #0aa2c0; }
.stat.muted { border-color: #6c757d; } .stat.muted .value { color: #6c757d; }

/* v4.22 กลุ่มยกเว้นการสแกน (เรียนที่บ้าน / ขาดเรียนนาน) */
.st-exempt .avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0dcaf0; }
.student-card.st-exempt { border-top-color: #0dcaf0; background: #f3fcfe; }
.row-exempt td { color: #0a6f84; }
.ex-chip { display: inline-block; margin: 0 .35rem .15rem 0; white-space: nowrap; }
.ex-reason { white-space: normal; max-height: 7.5em; overflow: auto; line-height: 1.35; }

/* หน้าสาธารณะ (ยังไม่เข้าสู่ระบบ): ชื่อระบบ + ปุ่มเข้าสู่ระบบอยู่บรรทัดเดียว */
.nav-anon .container-fluid { flex-wrap: nowrap; gap: .5rem; }
.nav-anon .navbar-brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 575px) { .nav-anon .navbar-brand { font-size: 1rem; } }

/* ชื่อบนแถบเมนูแบบ 2 บรรทัด (ชื่อโรงเรียน + ชื่อระบบ) */
.navbar-brand .brand2 { display: inline-flex; flex-direction: column; line-height: 1.1; min-width: 0; max-width: 24rem; }
.navbar-brand .brand2 span { white-space: nowrap; display: block; overflow: hidden; text-overflow: ellipsis; }
.navbar:not(.nav-anon) .navbar-brand:has(.brand2) { flex-shrink: 0; }
.navbar-brand .brand2 .b1 { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; }
.navbar-brand .brand2 .b2 { font-size: .72rem; font-weight: 400; opacity: .85; overflow: hidden; text-overflow: ellipsis; }
