/* รอบ 59b-1: ตารางสอน (/school/timetable) — prefix stt-
   - ใช้คู่กับ fit.css และแท็บ .sfe-tabs (school-fees.css)
   - จอกว้าง: ตาราง แถว = คาบ, คอลัมน์ = วัน (TimetableGrid.razor) เลื่อนในกรอบของตัวเอง
   - มือถือ ≤760px: ซ่อนตาราง แสดงปุ่มเลือกวัน + รายการคาบของวันนั้น (.stt-mob) ไม่เลื่อนแนวนอน
   - พิมพ์: .stt-print (TimetablePrint.razor) แสดงเฉพาะ html[data-print="timetable"] → A4 แนวนอน (@page stt)
   ใช้เฉพาะตัวแปรสีใน :root (โหมดมืดทับให้เองใน dark.css) */

.stt-print { display: none; }

@media screen {
  .fit > .stt-tabs { flex: none; }
  .stt-tools { flex-wrap: wrap; }
  .stt-print-btn { display: inline-flex; align-items: center; gap: 6px; }

  /* ---------- ตัวกรอง ---------- */
  .stt-bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
  .stt-filter { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: .82rem; color: var(--muted); }
  .stt-filter select { min-width: 0; max-width: 100%; }
  .stt-f-year select { width: 150px; }
  .stt-f-room select, .stt-f-teacher select { width: 260px; }
  .stt-check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-size: .9rem; color: var(--ink); cursor: pointer; }
  .stt-check input { width: 18px; height: 18px; margin: 0; }

  .stt-empty { padding: 28px 12px; text-align: center; color: var(--muted); }
  .stt-empty p { margin: 0 0 8px; }
  .stt-hint { margin: 0 0 8px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--ink); font-size: .86rem; }
  .stt-pane { gap: 4px; }
  .stt-phead h2 { overflow-wrap: anywhere; }
  .stt-total { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-size: .84rem; font-weight: 700; white-space: nowrap; }
  .stt-dirty { color: var(--danger); font-size: .86rem; font-weight: 600; }
  .stt-badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: .72rem; font-weight: 600; white-space: nowrap; }

  /* ---------- ตาราง (จอกว้าง) ---------- */
  .stt-grid-wrap { min-width: 0; }
  .stt-grid { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; min-width: 640px; }
  .stt-grid th, .stt-grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
  .stt-grid thead th {
    position: sticky; top: 0; z-index: 2; background: var(--surface); padding: 8px 6px; font-size: .86rem; font-weight: 700;
    text-align: center; border-top: 1px solid var(--line);
  }
  .stt-grid tr > :first-child { border-left: 1px solid var(--line); }
  .stt-grid thead th:first-child { border-top-left-radius: var(--radius-sm); }
  .stt-grid thead th:last-child { border-top-right-radius: var(--radius-sm); }
  .stt-grid .stt-corner { width: 118px; color: var(--muted); font-weight: 600; text-align: left; padding-left: 10px; }
  .stt-grid thead th.today { color: var(--brand-strong); box-shadow: inset 0 -3px 0 var(--brand); }
  .stt-grid td.today { background: var(--brand-tint); }
  .stt-ph { padding: 6px 10px !important; text-align: left; vertical-align: middle; background: var(--chip); }
  .stt-pname { display: block; font-size: .86rem; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stt-ptime { display: block; font-size: .76rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
  .stt-td { vertical-align: top; height: 62px; }
  .stt-brow .stt-ph { background: var(--bg); }
  .stt-break {
    background: var(--bg); color: var(--muted); text-align: center; font-size: .82rem; font-weight: 600; letter-spacing: .04em;
    height: 30px; padding: 4px 8px !important;
  }
  .stt-cell {
    display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 1px; width: 100%; height: 100%; min-height: 62px;
    padding: 6px 8px; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; min-width: 0;
  }
  button.stt-cell { cursor: pointer; border-radius: 0; }
  button.stt-cell:hover, button.stt-cell:focus-visible { background: var(--brand-soft); outline: none; box-shadow: inset 0 0 0 2px var(--brand); }
  button.stt-cell.empty { align-items: center; justify-content: center; }
  .stt-plus { color: var(--line); font-size: 1.3rem; font-weight: 300; line-height: 1; }
  button.stt-cell.empty:hover .stt-plus { color: var(--brand); }
  .stt-c1 { display: block; max-width: 100%; font-size: .88rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
  .stt-c2, .stt-c3 { display: block; max-width: 100%; font-size: .76rem; color: var(--muted); line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stt-c3 { color: var(--brand-strong); }

  /* ---------- มือถือ: เลือกวัน + รายการคาบ ---------- */
  .stt-mob { display: none; }
  .stt-mdays { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--chip); }
  .stt-mday {
    min-height: 40px; min-width: 0; padding: 0 2px; border: 0; border-radius: 9px; background: none; color: var(--muted);
    font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
  }
  .stt-mday.today { color: var(--brand-strong); }
  .stt-mday.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .stt-mtitle { margin: 10px 2px 6px; font-size: 1rem; }
  .stt-mlist { display: flex; flex-direction: column; gap: 6px; }
  .stt-mrow { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 8px; align-items: stretch; min-width: 0; }
  .stt-mtime { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; font-size: .86rem; font-weight: 700; color: var(--ink); }
  .stt-mtime small { color: var(--muted); font-weight: 500; font-size: .76rem; }
  .stt-mbody {
    display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 8px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; text-align: left;
  }
  .stt-mbody.empty { border-style: dashed; }
  .stt-mbody.brk { justify-content: center; padding: 4px 12px; border: 0; background: var(--bg); color: var(--muted); font-size: .84rem; font-weight: 600; }
  .stt-mrow.brk .stt-mtime { opacity: .7; }
  .stt-mbtn { cursor: pointer; }
  .stt-mbtn:active { background: var(--brand-soft); }
  .stt-mp { font-size: .74rem; color: var(--muted); }
  .stt-mnone { color: var(--muted); font-size: .86rem; }

  /* ---------- ครูสอน ---------- */
  .stt-ttable td { vertical-align: middle; }
  .stt-ttable .stt-tsel { width: 100%; min-width: 160px; max-width: 320px; }
  .stt-hours { width: 70px; text-align: right; }
  .stt-sched { display: inline-block; min-width: 34px; padding: 2px 8px; border-radius: 999px; background: var(--chip); font-weight: 700; text-align: center; }
  .stt-sched.ok { background: var(--ok-soft); color: var(--ok); }
  .stt-sched.warn { background: var(--danger-soft); color: var(--danger); }
  .stt-extra .stt-tsubj strong { font-style: italic; }
  .stt-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; flex: none; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; }
  .stt-addsubj { display: flex; gap: 8px; min-width: 0; flex: 1 1 280px; }
  .stt-addsubj select { flex: 1 1 auto; min-width: 0; max-width: 300px; }
  .stt-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

  /* ---------- เวลาคาบ / แบบเช็กชื่อ ---------- */
  .stt-psplit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: 16px; min-width: 0; }
  .stt-psplit > .panel { margin: 0; }
  .stt-pnote { margin: 0 0 10px; }
  .stt-plist { display: flex; flex-direction: column; gap: 6px; }
  .stt-prow { display: grid; grid-template-columns: minmax(0, 1fr) 118px 118px 74px 44px; gap: 8px; align-items: center; min-width: 0; }
  .stt-prow input[type="text"], .stt-prow input[type="time"] { width: 100%; min-width: 0; }
  .stt-prow.brk .stt-pn { background: var(--bg); color: var(--muted); }
  .stt-prhead { font-size: .78rem; color: var(--muted); font-weight: 600; }
  .stt-pb { display: inline-flex; align-items: center; gap: 6px; font-size: .86rem; cursor: pointer; }
  .stt-pb input { width: 18px; height: 18px; margin: 0; }
  .stt-prm { justify-self: end; color: var(--muted); }
  .stt-prm:hover { color: var(--danger); }
  .stt-prm:disabled { opacity: .35; cursor: not-allowed; }
  .stt-prm:disabled:hover { color: var(--muted); }
  .stt-prow input.stt-pt.bad { border-color: var(--danger); background: var(--danger-soft); }
  .stt-trm-h, .stt-trm { width: 52px; text-align: right; }
  .stt-modes { display: flex; flex-direction: column; gap: 6px; }
  .stt-mode { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 190px); gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .stt-mode:last-child { border-bottom: 0; }
  .stt-mode-name { font-weight: 700; overflow-wrap: anywhere; }
  .stt-mode select { width: 100%; min-width: 0; }

  /* ---------- หน้าต่าง ---------- */
  .stt-clear { margin-right: auto; color: var(--danger); }
  .stt-plost { margin: 0; padding-left: 20px; }
  .stt-plost li { margin: 2px 0; }
}

/* จอคอม: ทั้งหน้าพอดีจอ — ตาราง/รายการเลื่อนในกรอบ */
@media screen and (min-width: 1025px) {
  .stt-body > .stt-pane { flex: 1 1 auto; min-height: 0; overflow: hidden; }
  .stt-psplit { flex: 1 1 auto; min-height: 0; }
  .stt-psplit > .fit-pane { min-height: 0; overflow: hidden; }
  .stt-psplit .fit-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .stt-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
}

@media screen and (max-width: 1024px) {
  .stt-psplit { grid-template-columns: minmax(0, 1fr); }
  .stt-scroll { overflow-x: auto; }
}

@media screen and (max-width: 760px) {
  .stt-tools { width: 100%; }
  .stt-tools > .btn { flex: 1 1 auto; }
  .stt-bar { gap: 8px; }
  .stt-filter { flex: 1 1 150px; }
  .stt-filter select, .stt-f-year select, .stt-f-room select, .stt-f-teacher select { width: 100%; }
  .stt-check { flex: 1 1 100%; min-height: 32px; }
  .stt-pane { padding: 12px; }
  .stt-scroll { overflow: visible; }
  .stt-grid-wrap { display: none; }
  .stt-mob { display: block; }
  .stt-ttable .stt-tsel { max-width: none; min-width: 0; }
  .stt-hours { width: 90px; }
  .stt-ttable td.stt-trm { width: auto; text-align: right; }
  .stt-addsubj { flex-basis: 100%; }
  .stt-addsubj select { max-width: none; }
  .stt-actions { width: 100%; justify-content: flex-end; }
  .stt-actions .btn.primary { flex: 1 1 auto; }
  /* เวลาคาบ: ชื่อเต็มบรรทัด, เวลา 2 ช่อง + พัก + ลบ บรรทัดล่าง */
  .stt-prhead { display: none; }
  .stt-prow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto 44px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .stt-prow .stt-pn { grid-column: 1 / -1; }
  .stt-mode { grid-template-columns: minmax(0, 1fr) minmax(0, 170px); }
}

/* =====================================================================
   พิมพ์ตารางสอน: html[data-print="timetable"] → A4 แนวนอน ขาวดำ เส้นขอบ
   ===================================================================== */
@page stt { size: A4 landscape; margin: 8mm; }
@media print {
  html[data-print="timetable"]:has(.stt-print), html[data-print="timetable"]:has(.stt-print) body {
    margin: 0 !important; padding: 0 !important; height: auto !important; overflow: visible !important;
    background: #fff !important; color: #000 !important; page: stt;
  }
  html[data-print="timetable"]:has(.stt-print) body *:not(:has(.stt-print)):not(.stt-print):not(.stt-print *) { display: none !important; }
  html[data-print="timetable"]:has(.stt-print) body *:has(.stt-print) {
    display: block !important; position: static !important; margin: 0 !important; padding: 0 !important; border: 0 !important;
    width: auto !important; max-width: none !important; height: auto !important; min-height: 0 !important; overflow: visible !important;
    background: none !important; box-shadow: none !important; transform: none !important;
  }
  html[data-print="timetable"] .stt-print, html[data-print="timetable"] .stt-print * { visibility: visible !important; }
  html[data-print="timetable"] .stt-print { display: block !important; }
}

/* โครงใบพิมพ์ (ใช้ตอนพิมพ์ และในไฟล์ตัวอย่าง) */
.stt-print {
  color: #000; background: #fff; font-size: 10pt; line-height: 1.25;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.stt-p-head { position: relative; min-height: 16mm; text-align: center; margin-bottom: 3mm; }
.stt-p-logo { position: absolute; left: 0; top: 0; width: 16mm; height: 16mm; object-fit: contain; }
.stt-p-school { font-size: 11pt; font-weight: 700; padding: 0 20mm; }
.stt-p-title { margin: 1.5mm 0 0; font-size: 14pt; font-weight: 700; }
.stt-p-info { margin-top: 1mm; font-size: 10pt; }
.stt-p-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.stt-p-table th, .stt-p-table td { border: 1px solid #000; padding: 1mm 1.5mm; vertical-align: middle; }
.stt-p-table thead th { font-weight: 700; text-align: center; font-size: 10.5pt; background: #eee; height: 7mm; }
.stt-p-table tr { break-inside: avoid; page-break-inside: avoid; }
.stt-p-table .stt-p-ph { width: 30mm; text-align: left; background: #f4f4f4; }
.stt-p-pn { display: block; font-weight: 700; }
.stt-p-pt { display: block; font-size: 8.5pt; font-weight: 400; }
.stt-p-cell { height: 13mm; text-align: center; }
.stt-p-cell strong { display: block; font-size: 10pt; line-height: 1.2; overflow-wrap: anywhere; }
.stt-p-cell span { display: block; font-size: 8pt; line-height: 1.2; margin-top: .5mm; overflow-wrap: anywhere; }
.stt-p-brk th, .stt-p-break { background: #e2e2e2; }
.stt-p-break { text-align: center; font-weight: 700; letter-spacing: .3mm; height: 5.5mm; padding: .5mm !important; font-size: 9pt; }
.stt-p-brk .stt-p-pt { font-size: 8pt; }
.stt-p-foot { margin: 2mm 0 0; font-size: 8pt; text-align: right; }
.stt-print .num { font-variant-numeric: tabular-nums; }
/* คาบเยอะ: บีบความสูงแถว ให้จบในหน้าเดียว */
.stt-print.stt-p-dense .stt-p-cell { height: 9.5mm; }
.stt-print.stt-p-dense .stt-p-cell strong { font-size: 9pt; }
.stt-print.stt-p-dense .stt-p-cell span { font-size: 7.5pt; }

/* ---------- รอบ 76: คัดลอกจากปีก่อน (TtCopyModal) — prefix ttc- ---------- */
@media screen {
  .ttc-hint { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
  .ttc-box { gap: 12px; }
  .ttc-intro { margin: 0; }
  .ttc-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; }
  .ttc-opts select, .ttc-opts input { width: 100%; min-width: 0; }
  .ttc-checks { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
  .ttc-label { width: 100%; font-size: .82rem; color: var(--muted); }
  .ttc-check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-size: .92rem; color: var(--ink); cursor: pointer; }
  .ttc-check input { width: 18px; height: 18px; margin: 0; flex: none; }
  .ttc-note { width: 100%; }
  .ttc-confirm { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); }
  .ttc-loading { margin: 0; }
  .ttc-empty { margin: 0; padding: 18px 12px; }
  .ttc-sum { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--brand-soft); font-size: .9rem; }
  .ttc-sum.busy { opacity: .6; }
  .ttc-rooms { width: 100%; }
  .ttc-rooms td { vertical-align: top; overflow-wrap: anywhere; }
  .ttc-rooms th:nth-child(2), .ttc-rooms td:nth-child(2) { width: 34%; }
  .ttc-src, .ttc-auto { display: block; }
  .ttc-target { width: 100%; min-width: 0; max-width: 100%; }
  .ttc-ok { display: block; color: var(--ok, var(--ink)); font-weight: 600; }
  .ttc-skip { display: block; color: var(--muted); font-weight: 600; }
  .ttc-warn { color: var(--danger); }
  span.ttc-warn.small { display: block; }
  .ttc-issues { margin: 4px 0 0; padding-left: 18px; font-size: .82rem; color: var(--muted); }
  .ttc-issues li { margin: 1px 0; }
}

@media screen and (max-width: 760px) {
  .ttc-opts { grid-template-columns: 1fr; }
  .ttc-rooms th:nth-child(2), .ttc-rooms td:nth-child(2) { width: 100%; }
}

/* รอบ 76b: ช่องที่ยังไม่มีครู (ตารางห้อง โหมดแก้ไข) */
@media screen {
  .stt-cell.nt, .stt-mbtn.nt { box-shadow: inset 3px 0 0 var(--danger); }
  .stt-nt { color: var(--danger) !important; font-style: italic; }
}
