/* รอบ 62d: ใบแจ้งยอดค้างชำระ/ทวงถาม (/school/fees/statements) + ปุ่ม WhatsApp (Components/WhatsAppButton.razor) — prefix sstm-
   ใช้คู่กับ fit.css · สีจากตัวแปรใน :root ของ app.css (โหมดมืดใช้ได้) · มือถือ 390px ไม่เลื่อนแนวนอน (แถวเป็นการ์ด)
   พิมพ์: .sstm-print (Components/FeeStatementPrint.razor) แสดงเฉพาะ html[data-print="stmt"] → A4 แนวตั้ง 2 ฉบับต่อหน้า (@page sstm) */

/* ---------- ปุ่ม WhatsApp (ใช้หลายหน้า) ---------- */
.sstm-wa {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  background: #1E9E57; border-color: #1E9E57; color: #fff; text-decoration: none;
}
.sstm-wa:hover { background: #17824A; border-color: #17824A; color: #fff; }
.sstm-wa:focus-visible { outline: 2px solid #1E9E57; outline-offset: 2px; }
.sstm-wa svg { flex: none; }
.sstm-wa:disabled, .sstm-wa[disabled] { background: var(--chip); border-color: var(--line); color: var(--muted); cursor: not-allowed; opacity: 1; }
.sstm-wa-off { display: inline-flex; cursor: not-allowed; }

/* ---------- ตัวกรอง ---------- */
.sstm-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
.sstm-filter { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 0 1 200px; font-size: .82rem; color: var(--muted); }
.sstm-filter select, .sstm-filter input {
  min-width: 0; width: 100%; min-height: 40px; font: inherit; font-size: .95rem; color: var(--ink);
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.sstm-filter :is(select, input):focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.sstm-f-date { flex-basis: 160px; }
.sstm-f-num { flex-basis: 150px; }
.sstm-f-days { flex-basis: 120px; }
.sstm-f-note { flex: 1 1 240px; }
.sstm-search { width: 260px; }

/* ---------- แถบเลือก/พิมพ์ ---------- */
.sstm-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.sstm-actions-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sstm-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.sstm-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.sstm-all { min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: .9rem; color: var(--ink); }
.sstm-trunc { margin: 0; }
.sstm-empty { padding: 28px 16px; }

/* ---------- รายการนักเรียน ---------- */
.sstm-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sstm-row {
  display: grid; align-items: center; gap: 6px 12px; min-width: 0;
  grid-template-columns: 28px minmax(150px, 1.5fr) minmax(120px, 1.1fr) minmax(110px, .9fr) minmax(90px, .7fr) minmax(110px, .8fr) auto;
}
.sstm-row > * { min-width: 0; }
.sstm-hrow {
  position: sticky; top: 0; z-index: 1; padding: 8px 14px; border-radius: 12px; background: var(--chip);
  font-size: .78rem; font-weight: 700; color: var(--muted);
}
.sstm-hrow .r { text-align: right; }
.sstm-item { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid transparent; }
.sstm-item.is-sel { border-color: var(--brand); background: var(--brand-tint); }
.sstm-item > .sstm-row { padding: 10px 14px; }
.sstm-stu { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; }
.sstm-stu strong { overflow-wrap: anywhere; }
.sstm-meta { flex: 1 1 100%; font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.sstm-meta code { background: none; padding: 0; font-size: inherit; color: inherit; }
.sstm-guard, .sstm-old { display: flex; flex-direction: column; gap: 1px; font-size: .9rem; overflow-wrap: anywhere; }
.sstm-guard small, .sstm-old small { font-size: .78rem; }
.sstm-late { color: var(--danger); font-weight: 600; }
.sstm-toggle {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: .82rem; cursor: pointer; white-space: nowrap;
}
.sstm-toggle:hover { border-color: var(--brand); }
.sstm-toggle svg { transition: transform .15s ease; }
.sstm-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.sstm-total { text-align: right; font-weight: 700; color: var(--danger); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sstm-btns { display: flex; justify-content: flex-end; gap: 6px; }

.sstm-lines-wrap { padding: 0 14px 12px 54px; overflow-x: auto; }
.sstm-lines { width: 100%; border-collapse: collapse; font-size: .86rem; }
.sstm-lines th { text-align: left; font-size: .76rem; font-weight: 700; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.sstm-lines td { padding: 6px 8px; border-bottom: 1px dashed var(--line); }
.sstm-lines tr:last-child td { border-bottom: 0; }
.sstm-lines .r { text-align: right; }
.sstm-lines .num { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- ตั้งค่าข้อความ ---------- */
.sstm-set { gap: 12px; }
.sstm-tpl { width: 100%; min-height: 140px; resize: vertical; line-height: 1.45; }
.sstm-phs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sstm-ph { display: inline-flex; align-items: baseline; gap: 6px; padding: 4px 10px; cursor: pointer; font-size: .82rem; }
.sstm-ph code { background: none; padding: 0; color: var(--brand-strong); font-weight: 700; }
.sstm-ph small { color: var(--muted); }
.sstm-set-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.sstm-country input { width: 90px; }
.sstm-preview { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px; border-radius: 14px; background: var(--chip); }
.sstm-bubble {
  max-width: 100%; padding: 10px 12px; border-radius: 4px 14px 14px 14px; background: #DCF8C6; color: #111;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; line-height: 1.45; box-shadow: 0 1px 1px rgba(0,0,0,.12);
}

/* จอคอม: รายการเลื่อนในกรอบ */
@media screen and (min-width: 1025px) {
  .sstm-body > .sstm-actions, .sstm-body > .sstm-trunc { flex: none; }
}

/* แท็บเล็ต: ซ่อนหัวตาราง แถวเป็นการ์ด 2 คอลัมน์ */
@media (max-width: 1024px) {
  .sstm-hrow { display: none; }
  .sstm-row {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas: "chk stu total" "chk guard old" "chk cnt btns";
  }
  .sstm-row > .sstm-check { grid-area: chk; align-self: start; padding-top: 2px; }
  .sstm-stu { grid-area: stu; }
  .sstm-total { grid-area: total; align-self: start; }
  .sstm-guard { grid-area: guard; }
  .sstm-old { grid-area: old; text-align: right; align-items: flex-end; }
  .sstm-cnt { grid-area: cnt; }
  .sstm-btns { grid-area: btns; }
  .sstm-lines-wrap { padding: 0 12px 12px; }
}

/* มือถือ */
@media (max-width: 760px) {
  .sstm-filter, .sstm-f-date, .sstm-f-num, .sstm-f-days { flex: 1 1 calc(50% - 7px); }
  .sstm-f-note { flex: 1 1 100%; }
  .sstm-search { width: auto; flex: 1 1 100%; }
  .sstm-actions-btns { width: 100%; }
  .sstm-actions-btns .btn { flex: 1 1 0; }
  .sstm-all { width: 100%; }
  .sstm-item > .sstm-row { padding: 10px 12px; }
  .sstm-row { grid-template-columns: 24px minmax(0, 1fr) auto; gap: 6px 8px; }
  .sstm-lines { font-size: .8rem; }
  .sstm-lines th:nth-child(3), .sstm-lines td:nth-child(3) { display: none; }
  .sstm-lines th, .sstm-lines td { padding: 5px 4px; }
}

/* =====================================================================
   ใบแจ้งยอดสำหรับพิมพ์ (FeeStatementPrint) — ซ่อนบนจอ
   ===================================================================== */
.sstm-print { display: none; }

@page sstm { size: A4 portrait; margin: 8mm 10mm; }
@media print {
  html[data-print="stmt"]:has(.sstm-print), html[data-print="stmt"]:has(.sstm-print) body {
    margin: 0 !important; padding: 0 !important; height: auto !important; overflow: visible !important;
    background: #fff !important; color: #000 !important; page: sstm;
  }
  html[data-print="stmt"]:has(.sstm-print) body *:not(:has(.sstm-print)):not(.sstm-print):not(.sstm-print *) { display: none !important; }
  html[data-print="stmt"]:has(.sstm-print) body *:has(.sstm-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="stmt"] .sstm-print, html[data-print="stmt"] .sstm-print * { visibility: visible !important; }
  html[data-print="stmt"] .sstm-print { display: block !important; }
}

/* โครงใบแจ้ง (ใช้ตอนพิมพ์ และในไฟล์ตัวอย่าง) — 1 แผ่น = 1 หน้า A4 (สูงใช้ได้ 281mm) · ฉบับละครึ่งหน้า */
.sstm-print { color: #000; background: #fff; font-size: 9pt; line-height: 1.25; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sstm-sheet { display: flex; flex-direction: column; break-after: page; page-break-after: always; }
.sstm-sheet:last-child { break-after: auto; page-break-after: auto; }
.sstm-doc {
  box-sizing: border-box; height: 134mm; overflow: hidden; padding: 2mm 1mm;
  display: flex; flex-direction: column; gap: 2mm; break-inside: avoid; page-break-inside: avoid;
}
.sstm-sheet-long .sstm-doc { height: auto; overflow: visible; break-inside: auto; page-break-inside: auto; }
.sstm-cut { height: 0; margin: 2mm 0; border-top: 1px dashed #777; position: relative; }
.sstm-cut::after { content: "✂"; position: absolute; left: -1mm; top: -2.4mm; font-size: 9pt; line-height: 1; background: #fff; color: #555; }

.sstm-p-head { display: flex; align-items: flex-start; gap: 3mm; padding-bottom: 2mm; border-bottom: 1.5px solid #000; }
.sstm-p-logo { width: 16mm; height: 16mm; object-fit: contain; flex: none; }
.sstm-p-school { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .3mm; }
.sstm-p-sname { font-size: 12pt; font-weight: 700; }
.sstm-p-branch { font-weight: 600; }
.sstm-p-addr { white-space: pre-line; font-size: 8.5pt; }
.sstm-p-phone { font-size: 8.5pt; }
.sstm-p-titlebox { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1mm; text-align: right; }
.sstm-p-title { margin: 0; padding: 1mm 3mm; border: 1.5px solid #000; border-radius: 1.5mm; font-size: 12pt; font-weight: 700; }
.sstm-p-date { font-size: 9pt; }

.sstm-p-info { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sstm-p-info th { width: 20mm; text-align: left; font-weight: 600; padding: .3mm 1mm; vertical-align: top; }
.sstm-p-info td { padding: .3mm 1mm; overflow-wrap: anywhere; vertical-align: top; }
.sstm-p-info td:last-child { width: 32mm; }

.sstm-p-lines { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sstm-p-lines th, .sstm-p-lines td { border: 1px solid #000; padding: .3mm 1.2mm; vertical-align: middle; line-height: 1.2; }
.sstm-p-lines thead th { font-weight: 700; text-align: center; background: #eee; }
.sstm-p-lines tr { break-inside: avoid; page-break-inside: avoid; }
.sstm-p-c-no { width: 9mm; text-align: center; }
.sstm-p-c-per { width: 40mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sstm-p-c-due { width: 33mm; text-align: center; white-space: nowrap; overflow: hidden; }
.sstm-p-c-late { width: 13mm; text-align: center; }
.sstm-p-c-amt { width: 28mm; text-align: right; }
.sstm-p-wrap { overflow-wrap: anywhere; }
.sstm-p-total td { font-weight: 700; text-align: right; background: #f4f4f4; }
.sstm-print .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.sstm-p-foot { display: flex; flex-direction: column; gap: .8mm; }
.sstm-p-foot p { margin: 0; }
.sstm-p-payby { font-size: 10pt; }
.sstm-p-note { overflow-wrap: anywhere; }
.sstm-p-small { font-size: 8pt; color: #333; }

.sstm-p-sign { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 14mm; padding: 0 6mm; }
.sstm-p-sign > div { display: flex; flex-direction: column; align-items: center; gap: 1mm; font-size: 9pt; }
.sstm-p-sline { display: block; width: 100%; height: 7mm; border-bottom: 1px dotted #000; }

/* รอบ 79: เครดิตคงเหลือที่หักแล้ว */
.sstm-total small { display: block; font-weight: 400; font-size: 11px; white-space: normal; }
