/* รอบ 56: ค่าเรียน (/school/fees) และแท็บค่าเรียนของนักเรียน — prefix sfe- */
/* ใช้คู่กับ fit.css / fit-lists.css · ใช้เฉพาะตัวแปรสีใน :root ของ app.css (โหมดมืดทับให้เองใน dark.css)
   มือถือ 390px: หน้าไม่เลื่อนแนวนอน — ตารางราคาเลื่อนได้เฉพาะในกล่อง .sfe-mx-wrap */

@media screen {
  /* ---------- แท็บ ---------- */
  .fit > .sfe-tabs { flex: none; }
  .sfe-tabs {
    display: inline-flex; align-self: flex-start; gap: 3px; padding: 4px; border-radius: 14px;
    background: var(--chip); max-width: 100%; overflow-x: auto; scrollbar-width: none;
  }
  .sfe-tabs::-webkit-scrollbar { display: none; }
  .sfe-tabs button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; min-width: 0;
    border: 0; border-radius: 10px; background: none; color: var(--muted); font: inherit; font-size: .94rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  }
  .sfe-tabs button:hover { color: var(--ink); }
  .sfe-tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .sfe-tab-n { font-style: normal; min-width: 24px; height: 22px; padding: 0 7px; border-radius: 999px; display: inline-grid; place-items: center; background: var(--line); font-size: .78rem; font-weight: 700; }
  .sfe-tabs button.on .sfe-tab-n { background: var(--brand-soft); color: var(--brand-strong); }

  .fit > .sfe-viewonly, .fit > .sfe-hint { flex: none; margin: 0; }
  .sfe-hint { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--ink); font-size: .9rem; }
  .sfe-body { min-width: 0; }
  .sfe-note { margin: 0; }

  /* ---------- ว่าง ---------- */
  .sfe-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; }
  .sfe-empty h2, .sfe-empty p { margin: 0; }
  .sfe-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

  /* ---------- ป้าย ---------- */
  .sfe-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--chip); color: var(--muted); }
  .sfe-badge.all { background: var(--brand-soft); color: var(--brand-strong); }
  .sfe-badge.opt { background: var(--chip); color: var(--ink); }
  .sfe-badge.sub { background: var(--ok-soft); color: var(--ok); }
  .sfe-badge.none { background: var(--chip); color: var(--muted); }
  .sfe-chip { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--chip); color: var(--muted); white-space: nowrap; }
  .sfe-chip-auto { background: var(--ok-soft); color: var(--ok); }
  .sfe-iname { overflow-wrap: anywhere; }
  .sfe-code { white-space: nowrap; font-size: .8rem; }

  /* ---------- แถบเลือกปี / ตัวกรอง ---------- */
  .sfe-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
  .sfe-filter { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 0 1 240px; font-size: .82rem; color: var(--muted); }
  .sfe-filter select {
    width: 100%; min-width: 0; min-height: 40px; padding: 6px 10px; font: inherit; font-size: .92rem;
    color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  }
  .sfe-bar-note { margin: 0; flex: 1 1 220px; min-width: 0; }

  /* ---------- ตารางราคา (เลื่อนเฉพาะในกล่อง) ---------- */
  .sfe-mx-wrap { max-width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
  .sfe-mx { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: .9rem; }
  .sfe-mx th, .sfe-mx td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
  .sfe-mx thead th { color: var(--muted); font-weight: 600; font-size: .8rem; background: var(--surface); }
  .sfe-mx .r { text-align: right; }
  .sfe-mx-stage th { text-align: center; color: var(--ink); background: var(--brand-tint); border-left: 1px solid var(--line); }
  .sfe-mx tbody tr:last-child th, .sfe-mx tbody tr:last-child td { border-bottom: 0; }
  .sfe-mx-item {
    position: sticky; left: 0; z-index: 1; text-align: left; background: var(--surface);
    min-width: 150px; max-width: 220px; white-space: normal; border-right: 1px solid var(--line);
  }
  .sfe-mx tbody .sfe-mx-item { font-weight: 400; }
  .sfe-mx-name { display: block; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
  .sfe-mx-item small { display: block; }
  .sfe-mx-edit { margin-top: 4px; padding: 2px 8px; }
  .sfe-mx-none { color: var(--muted); }

  /* ---------- หน้าต่างแก้ราคา ---------- */
  .sfe-fill { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px 14px; padding: 12px; border-radius: var(--radius-sm); background: var(--brand-tint); }
  .sfe-fill-row { display: flex; align-items: flex-end; gap: 8px; min-width: 0; }
  .sfe-fill-row .field { flex: 1 1 auto; min-width: 0; }
  .sfe-fill-row .btn { flex: none; min-height: 40px; }
  .sfe-pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 10px 12px; }
  .sfe-pcell { min-width: 0; }
  .sfe-pgrade { display: flex; align-items: baseline; gap: 6px; min-width: 0; color: var(--ink); }
  .sfe-pgrade small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sfe-pcell input { width: 100%; min-width: 0; text-align: right; }
  .sfe-fgrid .sfe-applies { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
  .sfe-fgrid .sfe-applies legend { padding: 0; margin-bottom: 4px; }
  .sfe-fgrid .sfe-applies small { flex-basis: 100%; }
  .sfe-applies .check, .sfe-check { color: var(--ink); }

  /* ---------- กล่อง ---------- */
  .sfe-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .sfe-panel p { margin: 0; }
  .sfe-panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
  .sfe-panel-head h2 { margin: 0; font-size: 1.05rem; }
  .sfe-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

  /* ---------- เดือนที่เก็บ ---------- */
  .sfe-months { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .sfe-month {
    display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 6px 10px; cursor: pointer;
    border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); font-weight: 600;
  }
  .sfe-month input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
  .sfe-month.on { border-color: var(--brand); background: var(--brand-tint); color: var(--ink); }
  .sfe-due { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 14px; }
  .sfe-due .field { width: 140px; }

  /* ---------- สมัครทั้งห้อง ---------- */
  .sfe-sublist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
  .sfe-subrow { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
  .sfe-subrow:last-child { border-bottom: 0; }
  .sfe-subrow.on { background: var(--brand-tint); }
  .sfe-subpick { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 220px; cursor: pointer; }
  .sfe-subpick input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
  .sfe-subname { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
  .sfe-subname strong { overflow-wrap: anywhere; }
  .sfe-substate { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .sfe-subfoot { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 14px; }
  .sfe-subfrom { flex: 0 1 220px; min-width: 0; }
  .sfe-subbtns { display: flex; flex-wrap: wrap; gap: 8px; }

  /* ---------- ค่าเรียนในแผงนักเรียน ---------- */
  /* รอบ 106a: <StudentFeePanel> ในลิ้นชักของหน้าอื่น (ไม่มีหัวข้อ — ลิ้นชักมีชื่อแล้ว) */
  .sfe-st.sfp-bare { margin-top: 0; }
  .sfe-st h4.sfe-st-h { margin: 14px 0 6px; font-size: .9rem; color: var(--muted); font-weight: 600; }
  .sfe-st-year { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
  .sfe-st-year .sfe-chip { margin-left: 0; }
  .sfe-st-totals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .sfe-st-totals > div { min-width: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--chip); display: flex; flex-direction: column; gap: 2px; }
  .sfe-st-totals span { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sfe-st-totals strong { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sfe-st-totals .ok { background: var(--ok-soft); }
  .sfe-st-totals .ok strong { color: var(--ok); }
  .sfe-st-totals .due { background: var(--brand-tint); }
  .sfe-st-totals .bad { background: var(--danger-soft); }
  .sfe-st-totals .bad strong { color: var(--danger); }

  .sfe-st-subs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
  .sfe-st-sub { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); min-width: 0; }
  .sfe-st-sub.off { background: var(--bg); }
  .sfe-st-subtop { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
  .sfe-st-subname { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
  .sfe-st-subname strong { overflow-wrap: anywhere; }
  .sfe-st-subinfo { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; margin-top: 2px; font-size: .85rem; }
  .sfe-st-noprice { color: var(--danger); font-size: .82rem; }
  .sfe-st-months { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 8px; }
  .sfe-st-months .field { flex: 1 1 130px; min-width: 0; font-size: .8rem; }
  .sfe-st-months input { min-width: 0; width: 100%; }

  /* สวิตช์สมัคร/ไม่สมัคร */
  .sfe-switch {
    flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 3px 10px 3px 4px;
    border: 1px solid var(--line); border-radius: 999px; background: var(--chip); color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  }
  .sfe-switch:disabled { opacity: .6; cursor: default; }
  .sfe-switch-knob { width: 24px; height: 24px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); flex: none; }
  .sfe-switch.on { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); flex-direction: row-reverse; padding: 3px 4px 3px 10px; }
  .sfe-switch.on .sfe-switch-knob { background: var(--ok); }

  /* งวด */
  .sfe-chg { margin-top: 8px; }
  .sfe-chg-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; margin-bottom: 4px; }
  .sfe-ch-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
  .sfe-ch {
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr) auto; align-items: center; gap: 4px 10px;
    padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--surface); font-size: .85rem;
  }
  .sfe-ch:last-child { border-bottom: 0; }
  .sfe-ch-period { display: flex; flex-direction: column; min-width: 0; }
  .sfe-ch-period strong { overflow-wrap: anywhere; }
  .sfe-ch-nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; min-width: 0; }
  .sfe-ch-n { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; }
  .sfe-ch-n small { font-size: .7rem; color: var(--muted); }
  .sfe-ch-n b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

  .sfe-cst { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--chip); color: var(--muted); justify-self: end; }
  .sfe-cst-paid { background: var(--ok-soft); color: var(--ok); }
  .sfe-cst-overdue { background: var(--danger-soft); color: var(--danger); }
  .sfe-cst-partial { background: var(--warn-soft); color: var(--ink); }
  .sfe-cst-due { background: var(--brand-soft); color: var(--brand-strong); }
  .sfe-cst-upcoming { background: var(--chip); color: var(--muted); }
}

@media screen and (max-width: 760px) {
  .sfe-tabs { display: flex; align-self: stretch; }
  .sfe-tabs button { flex: 1 0 auto; padding: 0 10px; gap: 6px; font-size: .88rem; }
  .sfe-filter { flex: 1 1 100%; }
  .sfe-panel { padding: 12px; }
  .sfe-subfoot { flex-direction: column; align-items: stretch; }
  .sfe-subfrom { flex: none; }
  .sfe-subbtns .btn { flex: 1 1 auto; }
  .sfe-st-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sfe-mx-item { min-width: 120px; max-width: 150px; }
}

@media screen and (max-width: 440px) {
  .sfe-ch { grid-template-columns: minmax(0, 1fr) auto; }
  .sfe-ch-nums { grid-column: 1 / -1; grid-row: 2; }
  .sfe-months { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sfe-month { padding: 6px 8px; gap: 6px; font-size: .88rem; }
  .sfe-fill-row { flex-wrap: wrap; }
}

/* ---------- รอบ 56b: ราคาพิเศษรายคน ---------- */
.sfe-badge.sp { background: var(--warn-soft); color: var(--warn-text, #7a5300); }
.sfe-sp-box { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; margin-top: 6px; padding: 6px 10px; border-radius: 10px; background: var(--warn-soft); color: var(--warn-text, #5c3f00); font-size: .85rem; }
.sfe-sp-box .muted { color: var(--warn-text, #7a5300); }
.sfe-sp-box .sfe-badge.sp { background: var(--surface); }
.sfe-sp-eff { font-weight: 700; }
.sfe-sp-reason { flex-basis: 100%; overflow-wrap: anywhere; }
.sfe-sp-open { margin-top: 6px; }
.sfe-sp-edit { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; }
.sfe-sp-edit .field { min-width: 0; font-size: .8rem; }
.sfe-sp-edit input, .sfe-sp-edit select { min-width: 0; width: 100%; }
.sfe-sp-edit p { margin: 0; }
.sfe-sp-wide { grid-column: 1 / -1; }
.sfe-sp-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.sfe-spl-sub { display: block; }
/* รอบ 103c: ปุ่มเปิดแผงนักเรียน (ตั้ง/แก้ราคาพิเศษที่ส่วนค่าเรียน) */
.sfe-spl-open { margin-top: 6px; }
.sfe-spl td { overflow-wrap: anywhere; }
/* รอบ 108b: ราคาพิเศษที่ไม่มีงวดในปีนี้ — แสดงไว้ (ให้ลบ/ตั้งใหม่) แต่สีจาง */
.sfe-spl-nocharge td { color: var(--muted); }
.sfe-spl-nocharge td strong { color: var(--muted); font-weight: 600; }
.sfe-spl-nc { margin-left: 4px; }
@media (max-width: 480px) {
  .sfe-sp-edit { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- รอบ 56b-2: ค่าปรับจ่ายช้า / รับเงิน / ยกเลิกงวด / ประวัติการจ่าย ---------- */
.sfe-late-toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; user-select: none; }
.sfe-late-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.sfe-late-fields .field { width: 180px; max-width: 100%; }

.sfe-st-payrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; margin-top: 8px; }
.sfe-st-credit { padding: 3px 10px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-size: .82rem; font-weight: 600; }
.sfe-st-pay { margin-left: auto; }

.sfe-cst-void { background: var(--chip); color: var(--muted); text-decoration: none; }
.sfe-ch.void { background: var(--chip); }
.sfe-ch.void .sfe-ch-period strong, .sfe-ch.void .sfe-ch-nums b { text-decoration: line-through; color: var(--muted); }
.sfe-ch-voidinfo { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 2px 10px; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.sfe-ch-voidbtn { grid-column: 1 / -1; justify-self: end; color: var(--danger); font-size: .8rem; }
.sfe-ch-voidbox {
  grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; padding: 10px;
  border: 1px dashed var(--danger); border-radius: 10px; background: var(--danger-soft);
}
.sfe-ch-voidbox .field { min-width: 0; font-size: .8rem; }
.sfe-ch-voidbox input, .sfe-ch-voidbox select { min-width: 0; width: 100%; }
.sfe-ch-voidbox p { margin: 0; }

.sfe-st-hist { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sfe-st-histbtn { align-self: flex-start; }
.sfe-hist {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: center; gap: 4px 10px;
  padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--surface); font-size: .85rem;
}
.sfe-hist:last-child { border-bottom: 0; }
.sfe-hist-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sfe-hist-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; min-width: 0; }
.sfe-hist-top:empty { display: none; }
.sfe-hist-code { font-weight: 600; color: var(--brand-strong); overflow-wrap: anywhere; }
.sfe-hist-period { overflow-wrap: anywhere; }
.sfe-hist-nums { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; min-width: 0; }
.sfe-badge.late { background: var(--warn-soft); color: var(--warn-text, #7a5300); padding: 1px 8px; font-size: .72rem; }
.sfe-hist.void { background: var(--chip); }
.sfe-hist.void .sfe-hist-code, .sfe-hist.void .sfe-hist-period, .sfe-hist.void .sfe-hist-nums b { text-decoration: line-through; color: var(--muted); }
@media (max-width: 440px) {
  .sfe-hist { grid-template-columns: minmax(0, 1fr); }
  .sfe-late-fields .field { width: 100%; }
}

/* รอบ 56e: ปุ่มป๊อปอัปในแถบเดือนที่เก็บ + แผงในป๊อปอัปไม่ต้องมีกรอบซ้อน */
.sfe-bar-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.sfe-bar-btns .btn { display: inline-flex; align-items: center; gap: 8px; }
.mdl .sfe-panel { margin: 0; padding: 0; border: 0; box-shadow: none; background: none; }
.mdl .sfe-panel > .sfe-panel-head { display: none; }

/* ---------- รอบ 56e: แท็บราคา / สมัครทั้งห้อง = หน้าเดียวจบบนจอคอม (เลื่อนเฉพาะในกรอบ) ---------- */
@media screen and (min-width: 1025px) {
  /* ตารางราคา: กล่องสูงเท่าเนื้อหา แต่ไม่เกินพื้นที่ที่เหลือ หัวตารางติดบน */
  .fit-body > .sfe-mx-wrap.fit-scroll { flex: 0 1 auto; }
  .sfe-mx-wrap.fit-scroll .sfe-mx thead { position: sticky; top: 0; z-index: 3; }
  .sfe-body > .sfe-note { flex: none; }
  /* สมัครทั้งห้อง: รายชื่อเลื่อนในกล่อง ส่วนหัว/ปุ่มด้านล่างอยู่กับที่ */
  .sfe-body > .sfe-panel.sfe-subs { flex: 0 1 auto; min-height: 0; }
  .sfe-subs > * { flex: none; }
  .sfe-subs > .sfe-sublist { flex: 0 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
}
