/* ===== Admin layout & tables (clean) ===== */
/* ฟอนต์/ตัวแปรสีอยู่ที่ theme.css แล้ว */

/* ไม่บังคับระยะห่างบนของ body อีกต่อไป (เลื่อนมาที่ .with-sidebar แทน) */
/* body { padding-top: 60px; } */

/* Modal smooth fade */
.modal.fade,
.modal-backdrop.fade {
  transition: opacity .3s ease-in-out;
}

.modal.fade:not(.show),
.modal-backdrop.fade:not(.show) {
  opacity: 0;
}

/* Sidebar / Topbar / Main — ค่าพื้นฐาน: ยังไม่โชว์ sidebar/topbar จนกว่าจะล็อกอิน */
.topbar,
.sidebar {
  display: none;
}

.sidebar {
  font-family: 'Kanit', sans-serif;
  background: #343a40;
  color: #fff;
  padding: 10px;
  width: 230px;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  padding-top: 60px;
  /* เว้นให้ topbar เมื่อใช้งานจริง */
  z-index: 999;
}

.sidebar a {
  display: block;
  color: #fff;
  padding: 10px 15px;
  text-decoration: none;
}

.sidebar a:hover {
  background: #495057;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: #212529;
  color: #fff;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

/* ค่าพื้นฐาน: ยังไม่มี sidebar → ไม่ดันเนื้อหา */
.main-content {
  margin-left: 0;
  padding: 20px;
}

/* ===== เมื่อมีผู้ใช้ล็อกอิน: ใส่คลาส with-sidebar บน .app-shell ===== */
.app-shell.with-sidebar .topbar {
  display: flex;
}

.app-shell.with-sidebar .sidebar {
  display: block;
}

.app-shell.with-sidebar .main-content {
  margin-left: 230px;
  /* ดันเนื้อหาให้พ้น sidebar */
  padding-top: 60px;
  /* เว้นที่ด้านบนให้ topbar fixed */
}

/* ===== Responsive ===== */
@media (max-width:768px) {
  .sidebar {
    display: none;
    width: 100%;
    height: auto;
    position: static;
    padding-top: 10px;
    white-space: nowrap;
    overflow-x: auto;
  }

  .sidebar.mobile-visible {
    display: block !important;
  }

  .sidebar a {
    display: inline-block;
    padding: 10px;
  }

  /* มือถือ: ต่อให้ล็อกอินแล้ว ก็ไม่ดัน margin-left (sidebar จะสไลด์หรือโผล่เฉพาะตอนเปิด) */
  .app-shell.with-sidebar .main-content {
    margin-left: 0 !important;
    padding: 20px;
    /* padding บนพอประมาณ (topbar อาจเป็นแบบไม่ fixed บนมือถือ) */
    background: #f8f9fa;
  }

  .topbar {
    display: flex;
    flex-direction: row;
    /* ← สำคัญ */
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 .75rem;
  }

  .topbar .fw-semibold {
    max-width: 65vw;
    /* ตัดชื่อผู้ใช้/ตำแหน่งไม่ให้ดันปุ่ม */
  }
}

/* Sidebar accordion / links */
.sidebar .accordion-button {
  color: #fff;
  box-shadow: none;
}

.sidebar .accordion-button::after {
  filter: invert(1) opacity(.7);
}

.sidebar .accordion-button i {
  color: #adb5bd;
  transition: color .2s, transform .2s;
}

.sidebar .accordion-button:hover i {
  color: #e9ecef;
}

.sidebar .accordion-button:not(.collapsed) .icon-students {
  color: var(--bs-info);
}

.sidebar .accordion-button:not(.collapsed) .icon-teachers {
  color: var(--bs-warning);
}

.sidebar .accordion-button:not(.collapsed) .icon-subjects {
  color: var(--bs-success);
}

.sidebar .accordion-button:not(.collapsed) .icon-reports {
  color: var(--bs-danger);
}

.sidebar .accordion-button:not(.collapsed) i {
  transform: scale(1.06);
}

/* ลิงก์นอกคอลแลปส์ */
.sidebar>a {
  color: #dee2e6;
  padding: .4rem .75rem;
  display: block;
  border-radius: .5rem;
  transition: background-color .2s, color .2s;
}

.sidebar>a i {
  color: #adb5bd;
  transition: color .2s, transform .2s;
}

.sidebar>a:hover {
  background: rgba(255, 255, 255, .05);
  color: #fff;
}

.sidebar>a:hover i {
  color: var(--bs-primary);
  transform: translateX(2px);
}

.sidebar>a.router-link-exact-active {
  background: rgba(var(--bs-primary-rgb), .15);
  color: #fff;
  font-weight: 600;
}

.sidebar>a.router-link-exact-active i {
  color: var(--bs-primary);
}

/* ตารางขนาดเล็กที่ใช้บ่อย */
.small-subject-table {
  font-family: 'Kanit', sans-serif;
  font-size: .9rem;
}

.small-subject-table td,
.small-subject-table th {
  font-size: .80rem;
  padding: .3rem .5rem;
  vertical-align: middle;
  white-space: nowrap;
}

@media (max-width:576px) {
  .small-subject-table {
    font-size: .9rem;
  }

  .small-subject-table .text-truncate {
    max-width: 180px !important;
  }

  .btn-group.btn-group-sm .btn {
    padding: .5rem .6rem;
  }
}

/* หัวตารางติดบน */
.sticky-head th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ตารางอ่านง่ายขึ้น */
.table-bordered th,
.table-bordered td {
  border-color: #dee2e6 !important;
}

.table th,
.table td {
  padding: .5rem .75rem !important;
}

@media (max-width:576px) {

  .table th,
  .table td {
    padding: .4rem .5rem !important;
  }
}

.col-teacher {
  min-width: 140px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-headline {
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-detail {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-detail {
  word-break: break-word;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Assign modal */
.table thead.sticky-top {
  z-index: 15;
}

.table thead.sticky-top.shadow-sm {
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
}

.table.align-middle> :not(caption)>*>* {
  padding-top: .55rem;
  padding-bottom: .55rem;
}

.table-hover tbody tr:hover {
  background-color: rgba(33, 37, 41, .04);
}

.btn-group .btn {
  border-radius: .4rem !important;
}

.assign-table-wrapper {
  max-height: 60vh;
}

.sticky-head thead th {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* ===== PRINT (A4) ===== */
@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {

  .modal,
  .modal-backdrop {
    display: none !important;
  }

  .table {
    font-size: 11px;
    table-layout: fixed;
    width: 100% !important;
  }

  .table th,
  .table td {
    padding: 6px 8px !important;
    word-break: break-word;
    white-space: normal !important;
  }

  .table thead {
    display: table-header-group !important;
  }

  table tfoot {
    display: table-footer-group !important;
  }

  table,
  tr,
  td,
  th {
    page-break-inside: avoid !important;
  }

  .table thead th {
    background: #222 !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .col-headline,
  .col-detail {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
}

/* ===== Layout base (เดสก์ท็อป) ===== */
.app-shell.with-sidebar .topbar {
  display: flex;
}

.app-shell.with-sidebar .sidebar {
  display: block;
}

.app-shell.with-sidebar .main-content {
  margin-left: 230px;
  /* ดันเนื้อหาให้พ้น sidebar บนเดสก์ท็อป */
  padding-top: 60px;
  /* เว้นให้ topbar fixed */
}

/* ===== มือถือ/แท็บเล็ต (ต่ำกว่า 992px) → ใช้ sidebar แบบ off-canvas ===== */
@media (max-width: 991.98px) {

  /* ไม่ดันด้วย sidebar, แต่ต้องกัน topbar ทับ */
  .app-shell.with-sidebar .main-content {
    margin-left: 0 !important;
    padding: 60px 12px 20px;
    /* ← เพิ่ม padding-top = ความสูง topbar (~56-60px) */
    background: #f8f9fa;
  }

  /* Sidebar แบบเลื่อนออกจากซ้าย */
  .sidebar {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    padding: 12px 12px 16px;
    background: #343a40;
    transform: translateX(-100%);
    transition: transform .2s ease-out;
    z-index: 1045;
    /* สูงกว่า .modal-backdrop มาตรฐาน */
    overflow-y: auto;
  }

  .sidebar.mobile-overlay {
    /* แค่ alias ชัดเจน */
    transform: translateX(-100%);
  }

  .sidebar.mobile-visible {
    transform: translateX(0);
  }

  /* ปุ่มใน sidebar บนมือถือให้กดง่ายขึ้น */
  .sidebar a {
    padding: 10px 14px;
  }

  .accordion-button.p-2 {
    padding: .5rem !important;
  }

  /* Backdrop เมื่อเมนูเปิด */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 1040;
  }

  /* Topbar ปรับเป็นแถวเดียว เรียบ ๆ */
  .topbar {
    height: 56px;
    padding: 0 .75rem;
    flex-direction: row;
  }
}

/* ปรับไอคอนในลิงก์เมนู: ขนาด/ระยะเล็กน้อย */
.sidebar a i {
  width: 1.1rem;
  text-align: center;
}

/* ===== Micro responsive (XS) – fix เพี้ยนจอแคบมาก ===== */
@media (max-width: 575.98px) {
  .topbar {
    height: 56px;
    padding: 0 .5rem;
    gap: .25rem;
  }

  .topbar .btn {
    padding: .25rem .5rem;
  }

  .topbar .fw-semibold {
    max-width: 60vw;
  }

  /* ให้ชื่อผู้ใช้ไม่ดันปุ่มหลุดขอบ */
  .main-content {
    padding: 12px;
  }

  /* การ์ด/ภาพโปรไฟล์ให้ย่อสวย ๆ */
  .main-content .card {
    border-radius: 12px;
  }

  .main-content img {
    max-width: 100%;
    height: auto;
  }

  /* ถ้ารูปโปรไฟล์ใช้ img-thumbnail ให้ย่อเพิ่มนิด */
  .main-content img.img-thumbnail {
    max-width: 70vw;
    height: auto;
  }

  /* ปุ่มทั่วไปบนจอเล็ก */
  .btn {
    font-size: .95rem;
  }
}

/* กัน sidebar overlay ทับผิด z-index บางเครื่อง */
@media (max-width: 991.98px) {
  .sidebar {
    z-index: 1045;
  }

  .sidebar-backdrop {
    z-index: 1040;
  }
}

@media (max-width: 575.98px) {
  .main-content .container {
    padding-left: 12px;
    padding-right: 12px;
  }
}
.school-logo {
  height: 50px;
  width: auto;
  border-radius: 6px; /* ถ้าอยากให้โค้งมน */
}
.page-header h2 {
  font-size: 1.5rem;
  font-weight: bold;
}
.page-header small {
  font-size: 0.9rem;
  opacity: 0.9;
}
.page-footer {
  font-size: 0.85rem;
}
