/* =====================================================================
   Bangkok Kids — ระบบบริหารคอร์สเรียน
   ระบบสไตล์รวม

   หลักการ
   1. สีมีความหมายเสมอ  เขียว=ว่าง/สำเร็จ  ส้ม=ใกล้เต็ม/ต้องระวัง  แดง=เต็ม/ผิดพลาด
      สีประจำคลาสใช้เป็นจุดเล็ก ๆ ไม่ระบายทั้งป้าย เพื่อไม่ให้หน้าจอลายตา
   2. เว้นวรรคแทนเส้น  ลดเส้นขอบและพื้นหลังลง ใช้ระยะห่างจัดกลุ่มแทน
   3. ตัวเลขทุกที่เป็น tabular-nums ให้อ่านเทียบกันได้ตรงหลัก
   ===================================================================== */

:root {
  /* ---- พื้นและตัวอักษร ---- */
  --ground:      #F7F8FA;
  --surface:     #FFFFFF;
  --surface-2:   #F2F4F7;
  --surface-3:   #E8EBF0;
  --ink:         #171B22;
  --ink-2:       #414B57;
  --muted:       #737F8C;
  --faint:       #9AA5B1;
  --rule:        #E5E8ED;
  --rule-2:      #CFD5DD;

  /* ---- สีหลัก (ใช้อย่างประหยัด) ---- */
  --brand:       #0E7490;
  --brand-ink:   #0B5C73;
  --brand-soft:  #E7F2F6;

  /* ---- สีบอกสถานะ ---- */
  --ok:          #196A47;
  --ok-soft:     #E4F2EA;
  --warn:        #8A5200;
  --warn-soft:   #FBEEDC;
  --danger:      #A32A20;
  --danger-soft: #FBEAE8;
  --info:        #2B5CA8;
  --info-soft:   #E9F0FA;

  /* ---- ระยะและเงา ---- */
  --r:      12px;
  --r-sm:   8px;
  --r-xs:   5px;
  --shadow: 0 1px 2px rgba(23,27,34,.04), 0 4px 16px -10px rgba(23,27,34,.18);
  --sidebar-w: 244px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:      #0D1116;
    --surface:     #151A21;
    --surface-2:   #1C222A;
    --surface-3:   #262E38;
    --ink:         #E9EDF2;
    --ink-2:       #C4CDD7;
    --muted:       #8E9BA8;
    --faint:       #6E7B88;
    --rule:        #232B34;
    --rule-2:      #333D48;

    --brand:       #4FB3CE;
    --brand-ink:   #83CFE4;
    --brand-soft:  #0F2D38;

    --ok:          #6FC49B;
    --ok-soft:     #12251C;
    --warn:        #E0AA55;
    --warn-soft:   #2A2214;
    --danger:      #EF9088;
    --danger-soft: #2C1A18;
    --info:        #92B6EA;
    --info-soft:   #14202E;

    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 4px 16px -10px rgba(0,0,0,.8);
  }
}

:root[data-theme="dark"] {
  --ground: #0D1116; --surface: #151A21; --surface-2: #1C222A; --surface-3: #262E38;
  --ink: #E9EDF2; --ink-2: #C4CDD7; --muted: #8E9BA8; --faint: #6E7B88;
  --rule: #232B34; --rule-2: #333D48;
  --brand: #4FB3CE; --brand-ink: #83CFE4; --brand-soft: #0F2D38;
  --ok: #6FC49B; --ok-soft: #12251C; --warn: #E0AA55; --warn-soft: #2A2214;
  --danger: #EF9088; --danger-soft: #2C1A18; --info: #92B6EA; --info-soft: #14202E;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 4px 16px -10px rgba(0,0,0,.8);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", "Sarabun", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.num, table td, table th { font-variant-numeric: tabular-nums; }

svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none;
        stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
svg.i-sm { width: 15px; height: 15px; }

/* =====================================================================
   โครงหน้า
   ===================================================================== */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface); border-right: 1px solid var(--rule);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 36px; height: 36px; flex: none; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; letter-spacing: -.02em;
}
.brand-text b { display: block; font-size: 15px; line-height: 1.3; }
.brand-text span { font-size: 11.5px; color: var(--faint); }

.branch-picker { padding: 0 14px 14px; }
.branch-picker label {
  display: block; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); margin: 0 6px 6px;
}
.branch-picker select { font-weight: 600; }
.branch-static {
  font-size: 14px; font-weight: 600; padding: 0 6px;
  display: flex; align-items: center; gap: 7px; color: var(--ink-2);
}

.nav { padding: 6px 12px 24px; flex: 1; }
.nav-sec { margin-bottom: 20px; }
.nav-sec > span {
  display: block; padding: 0 8px 6px;
  font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--faint);
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-size: 14.5px; margin-bottom: 2px;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.nav a.active svg.i { stroke-width: 2; }
.nav .pill {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; line-height: 18px; min-width: 18px; text-align: center;
  padding: 0 5px; border-radius: 9px; font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--rule);
  padding: 0 26px; height: 60px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -.015em; }
.topbar .grow { flex: 1; }
.who { text-align: right; line-height: 1.25; }
.who b { display: block; font-size: 13.5px; font-weight: 600; }
.who span { color: var(--faint); font-size: 11.5px; }

.content { padding: 26px; max-width: 1360px; width: 100%; }
.content > *:last-child { margin-bottom: 0; }

/* หัวข้อย่อยของหน้า */
.page-intro { margin: -6px 0 22px; color: var(--muted); font-size: 14px; max-width: 74ch; }
.pagetitle { font-size: 21px; font-weight: 650; letter-spacing: -.02em; line-height: 1.3; }
.pagetitle span { color: var(--faint); font-weight: 400; font-size: 15px; }

/* =====================================================================
   การ์ด
   ===================================================================== */

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r); box-shadow: var(--shadow);
  margin-bottom: 20px; overflow: hidden;
}
.card-head {
  padding: 15px 18px 13px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-head + .card-body, .card-head + .tw, .card-head + .tbl-empty { border-top: 1px solid var(--rule); }
.card-head h2 { font-size: 15.5px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.card-head .sub { font-size: 12.5px; color: var(--faint); margin-top: -2px; }
.card-head .grow { flex: 1; }
.card-body { padding: 18px; }

.grid { display: grid; gap: 18px; margin-bottom: 20px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); }

/* =====================================================================
   ตัวเลขสรุป
   ===================================================================== */

.stat {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat .label svg.i { color: var(--faint); }
.stat .value {
  display: block;
  font-size: 30px; font-weight: 650; letter-spacing: -.03em; line-height: 1.2; margin-top: 4px;
}
.stat .sub { display: block; }
.stat .sub { font-size: 12.5px; color: var(--faint); }
.stat.hot .value { color: var(--danger); }
.stat.warm .value { color: var(--warn); }
.stat.good .value { color: var(--ok); }

/* =====================================================================
   ตาราง
   ===================================================================== */

.tw { overflow-x: auto; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
table.tbl th, table.tbl td { padding: 11px 16px; text-align: left; vertical-align: middle; }
table.tbl thead th {
  font-size: 11.5px; font-weight: 600; color: var(--faint);
  letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
  padding-top: 10px; padding-bottom: 8px;
}
table.tbl tbody td { border-top: 1px solid var(--rule); }
table.tbl tbody tr:hover td { background: var(--surface-2); }
table.tbl td.num, table.tbl th.num { text-align: right; }
table.tbl .lead { font-weight: 600; }
table.tbl .sub { font-size: 12.5px; color: var(--faint); }
.tbl-empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.tbl-empty b { display: block; color: var(--ink-2); font-weight: 600; margin-bottom: 4px; }
.tbl-empty span { font-size: 13px; color: var(--faint); }

/* =====================================================================
   ปุ่ม
   ===================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--rule-2);
  background: var(--surface); color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  cursor: pointer; font-family: inherit; line-height: 1.5; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.1); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.end { justify-content: flex-end; }

/* กลุ่มปุ่มติดกัน เช่น มา / ไม่มา */
.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: var(--r-xs); overflow: hidden; }
.seg button {
  border: none; background: var(--surface); color: var(--muted);
  padding: 5px 11px; font-size: 12.5px; font-family: inherit; cursor: pointer;
  border-right: 1px solid var(--rule-2);
}
.seg form:last-child button { border-right: none; }
.seg button:hover { background: var(--surface-2); color: var(--ink); }
.seg button.on-ok { background: var(--ok); color: #fff; }
.seg button.on-no { background: var(--danger); color: #fff; }
.seg form { display: contents; }

/* =====================================================================
   ฟอร์ม
   ===================================================================== */

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500; }
.field .hint { font-size: 12.5px; color: var(--faint); margin-top: 5px; line-height: 1.5; }
.req { color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], input[type=email], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--rule-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); line-height: 1.5;
  transition: border-color .12s, box-shadow .12s;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--faint); }
textarea { min-height: 84px; resize: vertical; }
.w-auto { width: auto; }

.form-grid { display: grid; gap: 0 18px; grid-template-columns: repeat(auto-fit, minmax(216px, 1fr)); }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.check input { width: auto; margin-top: 5px; flex: none; }
.check .hint { margin-top: 2px; }

fieldset { border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 16px 18px 4px; margin: 0 0 18px; }
fieldset legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 7px;
                  text-transform: uppercase; letter-spacing: .05em; }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 22px; }
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1; }

/* =====================================================================
   ป้ายสถานะ  — ใช้เท่าที่จำเป็น
   ===================================================================== */

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--ink-2); white-space: nowrap;
}
.tag.ok     { background: var(--ok-soft); color: var(--ok); }
.tag.warn   { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info   { background: var(--info-soft); color: var(--info); }
.tag.brand  { background: var(--brand-soft); color: var(--brand-ink); }
.tag.plain  { background: transparent; color: var(--faint); padding-left: 0; padding-right: 0; }

/* จุดสีประจำคลาส — แทนการระบายทั้งป้าย */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.classname { display: inline-flex; align-items: center; gap: 7px; }

/* ---------- รูปน้อง ---------- */
.avatar {
  border-radius: 50%; object-fit: cover; flex: none; display: inline-block;
  background: var(--surface-3); vertical-align: middle;
}
.avatar-ph {
  display: inline-grid; place-items: center; color: #fff; font-weight: 600;
  line-height: 1; user-select: none;
}
.avatar-xs { width: 22px; height: 22px; font-size: 11px; }
.avatar-sm { width: 34px; height: 34px; font-size: 15px; }
.avatar-md { width: 52px; height: 52px; font-size: 22px; }
.avatar-lg { width: 104px; height: 104px; font-size: 42px; }

/* ชื่อคู่กับรูปในตาราง */
.who-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-cell .txt { min-width: 0; }

/* ช่องเลือกรูปในฟอร์ม */
.photo-field { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.photo-field .preview {
  width: 104px; height: 104px; border-radius: 50%; flex: none;
  background: var(--surface-2); border: 1px dashed var(--rule-2);
  display: grid; place-items: center; overflow: hidden; color: var(--faint); font-size: 12px;
  text-align: center; padding: 6px;
}
.photo-field .preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.photo-field .controls { flex: 1; min-width: 220px; }

/* =====================================================================
   ข้อความแจ้งเตือน
   ===================================================================== */

.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash {
  padding: 12px 16px; border-radius: var(--r-sm); font-size: 14px;
  background: var(--bg); color: var(--fg); display: flex; gap: 10px; align-items: flex-start;
}
.flash svg.i { margin-top: 3px; }
.flash.success { --bg: var(--ok-soft); --fg: var(--ok); }
.flash.error   { --bg: var(--danger-soft); --fg: var(--danger); }
.flash.warn    { --bg: var(--warn-soft); --fg: var(--warn); }
.flash.info    { --bg: var(--info-soft); --fg: var(--info); }

/* กล่องแจ้งข้อผิดพลาดแบบ popup — ใช้ <dialog> จึงอ่านได้แม้ปิด JS */
.alert-dialog {
  border: 1px solid var(--rule); border-radius: var(--r);
  background: var(--surface); color: var(--ink);
  padding: 20px 22px; max-width: 560px; width: calc(100% - 32px);
  box-shadow: 0 18px 48px -18px rgba(0,0,0,.4); margin: 0 0 20px;
}
.alert-dialog::backdrop { background: rgba(12,16,22,.55); }
.alert-head { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 14px; }
.alert-mark {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--danger-soft); color: var(--danger);
  display: grid; place-items: center;
}
.alert-head b { display: block; font-size: 16px; }
.alert-head span { font-size: 12.5px; color: var(--faint); }
.alert-msg {
  margin: 0 0 14px; font-size: 15px; line-height: 1.65;
  padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--danger-soft); color: var(--danger);
}
.alert-tech { margin: 0 0 14px; }
.alert-tech > summary {
  cursor: pointer; font-size: 12.5px; color: var(--muted); list-style: none;
  display: flex; align-items: center; gap: 7px;
}
.alert-tech > summary::-webkit-details-marker { display: none; }
.alert-tech > summary::before { content: "▸"; font-size: 10px; }
.alert-tech[open] > summary::before { content: "▾"; }
.alert-tech pre {
  margin: 9px 0 0; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--rule);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px; line-height: 1.65; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow: auto;
}
.alert-foot { display: flex; justify-content: flex-end; margin: 0; }

.note {
  padding: 14px 16px; border-radius: var(--r-sm); font-size: 13.5px; line-height: 1.65;
  background: var(--surface-2); color: var(--ink-2); margin-bottom: 20px;
  display: flex; gap: 11px; align-items: flex-start;
}
.note svg.i { margin-top: 3px; color: var(--muted); }
.note b { color: var(--ink); }
.note.brand  { background: var(--brand-soft);  color: var(--brand-ink); }
.note.warn   { background: var(--warn-soft);   color: var(--warn); }
.note.danger { background: var(--danger-soft); color: var(--danger); }
.note.brand svg.i, .note.warn svg.i, .note.danger svg.i { color: inherit; }
.note.brand b, .note.warn b, .note.danger b { color: inherit; }

/* =====================================================================
   ตารางเรียนรายวัน
   ===================================================================== */

.daybar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px;
}
.daybar .title { font-size: 22px; font-weight: 650; letter-spacing: -.02em; line-height: 1.25; }
.daybar .title .yr { color: var(--faint); font-weight: 400; font-size: 16px; }
.daybar .meta { font-size: 13px; color: var(--muted); }
.nav-day {
  display: inline-flex; border: 1px solid var(--rule-2); border-radius: var(--r-sm); overflow: hidden;
}
.nav-day a, .nav-day span {
  padding: 7px 11px; color: var(--ink-2); font-size: 13px; display: inline-flex; align-items: center;
  border-right: 1px solid var(--rule-2); background: var(--surface);
}
.nav-day a:last-child, .nav-day span:last-child { border-right: none; }
.nav-day a:hover { background: var(--surface-2); text-decoration: none; }
.nav-day span { color: var(--faint); }

.slots { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.slot {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.slot:hover { border-color: var(--rule-2); }
.slot-top { padding: 14px 16px 12px; display: flex; align-items: flex-start; gap: 12px; }
.slot-time { font-size: 20px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.slot-meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.slot-count { margin-left: auto; text-align: right; line-height: 1.25; }
.slot-count b { font-size: 17px; font-weight: 650; }
.slot-count .of { color: var(--faint); font-weight: 400; }
.slot-count small { display: block; font-size: 11.5px; }
.slot.free  .slot-count small { color: var(--ok); }
.slot.tight .slot-count small { color: var(--warn); }
.slot.full  .slot-count b, .slot.full .slot-count small { color: var(--danger); }

.bar { height: 3px; background: var(--surface-3); }
.bar > i { display: block; height: 100%; background: var(--ok); transition: width .2s; }
.slot.tight .bar > i { background: var(--warn); }
.slot.full  .bar > i { background: var(--danger); }

.people { padding: 12px 16px 14px; display: flex; flex-wrap: wrap; gap: 6px; flex: 1; align-content: flex-start; }
.person {
  font-size: 12.5px; padding: 3px 9px; border-radius: 20px; color: var(--ink-2);
  background: var(--surface-2); display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
}
.person:hover { text-decoration: none; background: var(--surface-3); color: var(--ink); }
.person.mk { background: var(--warn-soft); color: var(--warn); }
.person.at { background: var(--ok-soft); color: var(--ok); }
.person.ab { background: var(--danger-soft); color: var(--danger); }
.person.cx { background: transparent; color: var(--faint); text-decoration: line-through; }
.person .seatno { font-size: 11px; color: var(--faint); }
.person.mk .seatno, .person.at .seatno, .person.ab .seatno { color: inherit; opacity: .7; }
.empty-seat {
  font-size: 12.5px; padding: 3px 9px; border-radius: 20px;
  color: var(--ok); background: var(--ok-soft); opacity: .75;
}
.slot-foot { padding: 0 16px 14px; }

/* =====================================================================
   ตัวหาคาบว่าง
   ===================================================================== */

.fday { margin-bottom: 22px; }
.fday-head {
  font-size: 14px; font-weight: 650; color: var(--ink-2);
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.fday-head::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.fday-head .n { font-weight: 400; color: var(--faint); font-size: 12.5px; }
.fgrid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); }

.fslot {
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 12px 13px;
  background: var(--surface); display: flex; flex-direction: column; gap: 7px;
}
.fslot.can { border-color: rgba(25,106,71,.35); }
.fslot.cannot { background: var(--surface-2); border-style: dashed; }
.fslot .row1 { display: flex; align-items: baseline; gap: 9px; }
.fslot .t { font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
.fslot .c { font-size: 12.5px; color: var(--muted); }
.fslot .free { margin-left: auto; }
.fslot .meta { font-size: 12px; color: var(--faint); }
.fslot .why { font-size: 12px; color: var(--danger); line-height: 1.5; }
.fslot form { margin: 0; }

/* คาบที่ระบบแนะนำ — เน้นให้เห็นก่อนเพื่อน */
.fslot.pick {
  position: relative; border-color: var(--ok); background: var(--card-pick, var(--surface));
  box-shadow: var(--shadow);
}
.fslot.pick .rank {
  position: absolute; top: -9px; left: -9px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 12.5px; font-weight: 700;
  display: grid; place-items: center;
}
.why-good { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- เลือกคลาสตอนลงทะเบียน ---------- */
.pickslot {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  padding: 11px 12px; background: var(--surface); transition: border-color .12s, background .12s;
}
.pickslot:hover { border-color: var(--brand); background: var(--surface-2); }
.pickslot > input { margin-top: 4px; flex: none; }
.pickslot .body { min-width: 0; flex: 1; }
.pickslot .l1 { display: flex; align-items: baseline; gap: 8px; }
.pickslot .t { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.pickslot .seats { margin-left: auto; }
.pickslot .classname { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.pickslot .meta { font-size: 12px; color: var(--faint); margin-top: 2px; }
.pickslot .warnline { font-size: 12px; color: var(--warn); margin-top: 3px; }
.pickslot .warnline:empty { display: none; }

.pickslot.is-full, .pickslot.age-bad { opacity: .55; cursor: not-allowed; background: var(--surface-2); }
.pickslot.is-full:hover, .pickslot.age-bad:hover { border-color: var(--rule); }
.pickslot.chosen {
  border-color: var(--brand); background: var(--brand-soft);
  box-shadow: 0 0 0 1px var(--brand);
}
.pickslot.chosen .classname, .pickslot.chosen .t { color: var(--brand-ink); }

/* ขั้นตอน: เลือกวัน → เลือกเวลา */
.steplabel {
  display: flex; align-items: center; gap: 9px;
  font-size: 14.5px; font-weight: 650; color: var(--ink); margin-bottom: 12px;
}
.stepno {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--brand); color: #fff; font-size: 12.5px; font-weight: 700;
  display: grid; place-items: center;
}
.steplabel .faint { font-weight: 400; }

.daypick { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); }
.daybtn {
  border: 1px solid var(--rule-2); background: var(--surface); border-radius: var(--r-sm);
  padding: 11px 12px; cursor: pointer; font-family: inherit; text-align: left;
  transition: border-color .12s, background .12s;
}
.daybtn:hover { border-color: var(--brand); background: var(--surface-2); }
.daybtn b { display: block; font-size: 15px; color: var(--ink); }
.daybtn .cnt { font-size: 12.5px; color: var(--ok); }
.daybtn.none { opacity: .5; }
.daybtn.none .cnt { color: var(--faint); }
.daybtn.on {
  background: var(--brand); border-color: var(--brand);
}
.daybtn.on b, .daybtn.on .cnt { color: #fff; }

/* ขั้นเลือกช่วงเวลาในหน้าหาวันชดเชย */
.timepick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.timechip {
  border: 1px solid var(--rule-2); background: var(--surface); border-radius: 20px;
  padding: 6px 14px; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: baseline; gap: 7px;
  transition: border-color .12s, background .12s;
}
.timechip:hover { border-color: var(--brand); background: var(--surface-2); }
.timechip b { font-size: 14.5px; font-weight: 650; color: var(--ink); }
.timechip span { font-size: 12px; color: var(--ok); }
.timechip.none { opacity: .45; }
.timechip.none span { color: var(--faint); }
.timechip.on { background: var(--brand); border-color: var(--brand); }
.timechip.on b, .timechip.on span { color: #fff; }

/* แถววันที่ให้เลือกในขั้นสุดท้าย — แนวนอน อ่านไล่ลงได้เร็ว */
.fdate-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 11px 14px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); margin-bottom: 8px;
}
.fdate-row:hover { border-color: var(--rule-2); }
.fdate-row.blocked { background: var(--surface-2); border-style: dashed; opacity: .8; }
.fdate-row .dte { min-width: 150px; }
.fdate-row .dte b { display: block; font-size: 14.5px; }
.fdate-row .dte span { font-size: 12px; color: var(--faint); }
.fdate-row .cls { font-size: 13px; color: var(--ink-2); }
.fdate-row .why { font-size: 12px; color: var(--danger); flex-basis: 100%; }
.fdate-row .acts { margin-left: auto; }
@media (max-width: 700px) {
  .fdate-row .acts { margin-left: 0; flex-basis: 100%; }
}

/* =====================================================================
   ตารางรายสัปดาห์ — heatmap อ่านสถานะจากสีได้โดยไม่ต้องอ่านตัวเลข
   ===================================================================== */

table.wk { border-collapse: separate; border-spacing: 5px; width: 100%; padding: 10px 12px 12px; }
table.wk th, table.wk td { padding: 0; }

table.wk thead th {
  text-align: center; padding: 6px 4px 8px; vertical-align: top; min-width: 108px;
}
table.wk thead th b { display: block; font-size: 14px; font-weight: 650; }
table.wk thead th small { display: block; font-size: 11.5px; color: var(--faint); line-height: 1.6; }
table.wk thead th small.sum { color: var(--muted); font-weight: 600; }
table.wk thead th small.hol { color: var(--danger); font-weight: 600; }
table.wk thead th.today { background: var(--brand-soft); border-radius: var(--r-sm); }

table.wk td.t {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  text-align: right; padding-right: 8px; white-space: nowrap; width: 52px;
}

.wk-cell {
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--rule); background: var(--surface);
  text-decoration: none; transition: transform .1s, box-shadow .1s, border-color .1s;
}
.wk-cell:hover {
  text-decoration: none; transform: translateY(-1px);
  box-shadow: var(--shadow); border-color: var(--rule-2);
}
.wk-cell .n { font-size: 15px; font-weight: 650; line-height: 1.2; color: var(--ink); }
.wk-cell .n em { font-style: normal; font-weight: 400; color: var(--faint); font-size: 12px; }
.wk-cell .bar { display: block; height: 3px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.wk-cell .bar i { display: block; height: 100%; border-radius: 2px; }
.wk-cell .cls {
  display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* สถานะ = สี — กวาดตาแถวเดียวรู้ทันทีว่าตรงไหนแน่น */
.wk-cell.zero { border-style: dashed; }
.wk-cell.zero .n { color: var(--faint); }
.wk-cell.ok   { border-left: 3px solid var(--ok); }
.wk-cell.ok .bar i { background: var(--ok); }
.wk-cell.warm { border-left: 3px solid var(--warn); background: var(--warn-soft); }
.wk-cell.warm .bar i { background: var(--warn); }
.wk-cell.warm .n { color: var(--warn); }
.wk-cell.full { border-left: 3px solid var(--danger); background: var(--danger-soft); }
.wk-cell.full .bar i { background: var(--danger); }
.wk-cell.full .n { color: var(--danger); }

.wk-none { display: block; text-align: center; color: var(--rule-2); font-size: 13px; padding: 8px 0; }

/* =====================================================================
   ตารางตั้งค่าคลาส
   ===================================================================== */

.sgrid { border-collapse: separate; border-spacing: 0; font-size: 13px; width: 100%; }
.sgrid th, .sgrid td { padding: 4px 6px; border-bottom: 1px solid var(--rule); }
.sgrid thead th {
  background: var(--surface); position: sticky; top: 0; z-index: 2;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint);
  border-bottom: 1px solid var(--rule-2); text-align: left;
}
.sgrid td.t { color: var(--muted); font-weight: 600; white-space: nowrap; width: 62px; }
.sgrid tr:hover td { background: var(--surface-2); }
.sgrid .cell { display: flex; gap: 4px; }
.sgrid select { padding: 5px 7px; font-size: 12.5px; border-radius: var(--r-xs); flex: 1; min-width: 0; }
.sgrid input[type=number] { padding: 5px 6px; font-size: 12.5px; width: 50px; border-radius: var(--r-xs); flex: none; }
.sgrid select[data-empty="1"] { color: var(--faint); border-color: var(--rule); background: var(--surface-2); }

/* =====================================================================
   ปฏิทินเทอม
   ===================================================================== */

.cal { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.calday {
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 9px 11px;
  background: var(--surface); font-size: 13px;
}
.calday .d { font-weight: 650; }
.calday .w { color: var(--faint); font-size: 11.5px; }
.calday.holiday { background: var(--danger-soft); border-color: transparent; }
.calday.holiday .d, .calday.holiday .w { color: var(--danger); }
.calday.makeup { background: var(--warn-soft); border-color: transparent; }
.calday.makeup .d, .calday.makeup .w { color: var(--warn); }
.calday form { margin-top: 4px; }
.calday form button { font-size: 11px; padding: 0; }

/* =====================================================================
   กราฟและมาตรวัด
   ===================================================================== */

.bars { display: flex; align-items: flex-end; gap: 3px; height: 108px; }
.bars > div { flex: 1; min-width: 2px; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; }
.bars i { display: block; border-radius: 2px 2px 0 0; }
.bars i.a { background: var(--brand); }
.bars i.b { background: var(--warn); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend em { width: 9px; height: 9px; border-radius: 2px; display: inline-block; font-style: normal; }

.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; min-width: 60px; flex: 1; }
.meter > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.meter > i.warm { background: var(--warn); }
.meter > i.hot { background: var(--danger); }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row b { font-size: 12.5px; width: 42px; text-align: right; font-weight: 600; }

/* =====================================================================
   เบ็ดเตล็ด
   ===================================================================== */

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mb0 { margin-bottom: 0 !important; }
.inline { display: inline; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.tabs a {
  padding: 6px 14px; border-radius: 20px; font-size: 13.5px;
  border: 1px solid var(--rule); color: var(--muted); background: var(--surface);
}
.tabs a:hover { text-decoration: none; background: var(--surface-2); color: var(--ink); }
.tabs a.active { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 600; }

details.panel { border-top: 1px solid var(--rule); }
details.panel > summary {
  padding: 11px 0; cursor: pointer; font-size: 13.5px; color: var(--brand-ink);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "▸"; font-size: 11px; transition: transform .15s; }
details.panel[open] > summary::before { transform: rotate(90deg); }

.enrol {
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  padding: 14px 16px; margin-bottom: 12px; background: var(--surface);
}
.enrol-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.enrol-head b { font-size: 14.5px; }
.enrol-use { margin-left: auto; font-size: 13px; color: var(--muted); }
.enrol-use b { color: var(--ink); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 18px; }
.kv > div > span { display: block; font-size: 12px; color: var(--faint); }
.kv > div > div { font-size: 14px; }

/* =====================================================================
   หน้าสำหรับผู้ปกครอง (เปิดจากลิงก์ · ส่วนใหญ่เปิดบนมือถือ)
   ===================================================================== */

.pub-wrap {
  min-height: 100vh; padding: 20px 16px 40px;
  background: radial-gradient(760px 380px at 50% -12%, var(--brand-soft), transparent 70%), var(--ground);
}
.pub-card {
  max-width: 560px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 16px; padding: 26px 22px 28px;
  box-shadow: var(--shadow);
}
.pub-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.pub-title { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 8px; line-height: 1.35; }
.pub-lede { color: var(--ink-2); font-size: 14.5px; margin: 0 0 22px; }
.pub-note { font-size: 12.5px; color: var(--faint); margin: 14px 0 0; line-height: 1.6; }
.pub-foot { max-width: 560px; margin: 18px auto 0; text-align: center; font-size: 12px; color: var(--faint); }
.pub-submit { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }

.pub-result { text-align: center; padding: 12px 0 6px; }
.pub-result .mark {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 16px;
  display: grid; place-items: center;
}
.pub-result .mark svg { width: 28px; height: 28px; stroke-width: 2; }
.pub-result.ok .mark   { background: var(--ok-soft); color: var(--ok); }
.pub-result.stop .mark { background: var(--danger-soft); color: var(--danger); }
.pub-result .pub-lede { margin-bottom: 0; }

/* ลิงก์ที่พนักงานคัดลอกส่งให้ผู้ปกครอง */
.linkbox {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--rule);
  border-radius: var(--r-sm); padding: 10px 12px; margin-top: 10px;
}
.linkbox input {
  flex: 1; min-width: 220px; font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px; background: var(--surface);
}

/* =====================================================================
   เข้าสู่ระบบ
   ===================================================================== */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 420px at 50% -10%, var(--brand-soft), transparent 70%), var(--ground);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 16px; padding: 32px 30px;
  box-shadow: var(--shadow);
}
.login-card .brand { padding: 0 0 22px; }

/* =====================================================================
   จอเล็ก
   ===================================================================== */

@media (max-width: 940px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--rule); }
  .brand { padding: 14px 16px 10px; }
  .branch-picker { padding: 0 16px 12px; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px 12px; }
  .nav-sec { display: contents; }
  .nav-sec > span { display: none; }
  .nav a { margin: 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .slots { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .toolbar, .tabs, .btn, .seg, .slot-foot { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .card { box-shadow: none; break-inside: avoid; }
}
