/* ============================================================
   KKW Timetable — สไตล์หลัก
   ============================================================ */

@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Bai Jamjuree"; src: url("../fonts/BaiJamjuree-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Bai Jamjuree"; src: url("../fonts/BaiJamjuree-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
    --bg: #F2F4F1;
    --surface: #FFFFFF;
    --surface-2: #E9EDE8;
    --ink: #17221E;
    --ink-2: #46534D;
    --ink-3: #6F7B75;
    --line: #D3DAD4;
    --line-2: #E3E8E4;
    --accent: #1B6A4F;
    --accent-ink: #FFFFFF;
    --accent-soft: #DAECE3;
    --warn: #9A6A0B;
    --warn-soft: #F6EACB;
    --bad: #B73828;
    --bad-soft: #F7DFDA;
    --good: #2B7A4C;
    --good-soft: #DDF0E4;
    --radius: 8px;
    --f-body: "Sarabun", "Leelawadee UI", "Tahoma", sans-serif;
    --f-head: "Bai Jamjuree", "Sarabun", "Leelawadee UI", "Tahoma", sans-serif;
    --sidebar: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.55; }
h1, h2, h3, h4 { font-family: var(--f-head); margin: 0; line-height: 1.3; text-wrap: balance; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; }
td.n.c, th.n.c { text-align: center; }
.nowrap { white-space: nowrap; }
.code { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: none; object-fit: contain; }
.brand-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand b { font-family: var(--f-head); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-t > span { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-foot { margin-top: 28px; padding: 14px 4px 6px; border-top: 1px solid var(--line); text-align: center; color: var(--ink-3); font-size: 13px; }
@media print { .site-foot { display: none; } }
.term-switch select { min-width: 220px; font-weight: 600; }
.user-box { display: flex; align-items: center; gap: 14px; font-size: 14px; flex-wrap: wrap; }
.user-box small { color: var(--ink-3); margin-left: 4px; }
.user-box form { margin: 0; }
.linklike { background: none; border: 0; color: var(--accent); padding: 0; cursor: pointer; text-decoration: underline; }
.nav-toggle { display: none; }
.nav-btn { display: none; font-size: 20px; cursor: pointer; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - 58px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px 20px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 58px; height: calc(100vh - 58px); overflow-y: auto; }
.sidebar a, .sidebar .soon { display: block; padding: 7px 12px; border-radius: 7px; text-decoration: none; color: var(--ink-2); font-weight: 500; }
.sidebar a:hover { background: var(--surface-2); color: var(--ink); }
.sidebar a.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.sidebar .soon { color: var(--ink-3); cursor: default; }
.sidebar .soon small { font-size: 11px; border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; margin-left: 4px; }
.nav-group { font-family: var(--f-head); font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--ink-3); padding: 14px 12px 4px; }
/* สีกลุ่มเมนู: ข้อมูลพื้นฐาน ชมพู · ภาคเรียน ฟ้า · จัดการสอน เหลือง · ระบบ เทาน้ำเงิน */
.nav-sec { display: flex; flex-direction: column; gap: 2px; }
.nav-sec.nav-pink { --nc: #B4306F; --nc-bar: #E07AAA; --nc-bg: #FCEFF5; --nc-soft: #F8DCE9; }
.nav-sec.nav-sky { --nc: #1C6A99; --nc-bar: #5FAEDD; --nc-bg: #EDF6FC; --nc-soft: #D6EAF7; }
.nav-sec.nav-yellow { --nc: #855F00; --nc-bar: #E1B634; --nc-bg: #FDF7E3; --nc-soft: #F8EBBF; }
.nav-sec.nav-green { --nc: #1E7347; --nc-bar: #5DBB8A; --nc-bg: #EDF8F1; --nc-soft: #D3EEDD; }
.nav-sec.nav-slate { --nc: #435775; --nc-bar: #8C9DBB; --nc-bg: #F0F3F8; --nc-soft: #DFE5EF; }
.nav-c { margin-top: 10px; padding: 2px 4px 6px; border-radius: 10px; background: var(--nc-bg); border: 1.5px solid var(--nc); }
.nav-c .nav-group { color: var(--nc); padding-top: 8px; font-weight: 700; }
.nav-c a:hover { background: var(--nc-soft); color: var(--nc); }
.nav-c a.on { background: var(--nc-soft); color: var(--nc); }
/* หมวดเมนูย่อ/ขยายได้ */
details.nav-sec { display: block; }
.nav-items { display: flex; flex-direction: column; gap: 2px; }
details.nav-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding-bottom: 6px; border-radius: 7px; user-select: none; }
details.nav-sec > summary::-webkit-details-marker { display: none; }
details.nav-sec > summary::after { content: ''; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin: -3px 4px 0 8px; transition: transform .15s; }
details.nav-sec:not([open]) > summary::after { transform: rotate(-45deg); margin-top: 0; }
details.nav-sec:not([open]) { padding-bottom: 2px; }
details.nav-sec > summary:hover { background: var(--nc-soft); }
details.nav-sec > summary:focus-visible { outline: 2px solid var(--nc); outline-offset: 1px; }
.layout.no-side { grid-template-columns: minmax(0, 1fr); }
.layout.no-side .main { max-width: none; }
.nav-foot { margin-top: auto; padding: 16px 12px 0; font-size: 12px; color: var(--ink-3); }
.main { padding: 22px 28px 60px; min-width: 0; max-width: 1400px; }

@media (max-width: 900px) {
    .nav-btn { display: inline-block; }
    .layout { grid-template-columns: minmax(0, 1fr); }
    .sidebar { display: none; position: fixed; z-index: 40; top: 0; left: 0; bottom: 0; width: 260px; height: 100vh; box-shadow: 0 0 40px rgba(0,0,0,.2); }
    .nav-toggle:checked ~ .layout .sidebar { display: flex; }
    .main { padding: 18px 16px 50px; }
    .term-switch { order: 5; flex: 1 1 100%; }
    .term-switch select { width: 100%; }
}

/* ---------- page head ---------- */
.pagehead { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.pagehead h1 { font-size: 25px; font-weight: 700; }
.pagehead p { margin: 4px 0 0; color: var(--ink-2); max-width: 75ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- flash ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; font-size: 14.5px; }
.flash.success { background: var(--good-soft); border-color: #B5DCC3; }
.flash.error { background: var(--bad-soft); border-color: #EBB8AF; }
.flash.info { background: var(--warn-soft); border-color: #E8D29C; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 7px 14px; cursor: pointer; font-weight: 500; font-size: 14px; line-height: 1.3; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--ink-3); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.pri:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: #E3B3AB; }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.ic { width: 16px; height: 16px; flex: none; }
select, input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], input[type=time], textarea {
    background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; font-size: 14.5px; max-width: 100%;
}
input[type=file] { font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--ink-2); font-weight: 500; }
.field input, .field select, .field textarea { font-size: 15px; color: var(--ink); }
.field .hint { font-weight: 400; color: var(--ink-3); font-size: 12.5px; }
.field .err { color: var(--bad); font-weight: 500; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 18px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 560px) { .span-2 { grid-column: 1 / -1; } }
.check { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; font-size: 14.5px; color: var(--ink); font-weight: 400; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { width: 240px; }
.toolbar .count { color: var(--ink-3); font-size: 13.5px; }
form.inline { display: inline; margin: 0; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
.panel > h2, .panel > h3 { font-size: 16px; font-weight: 600; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.panel .pb { padding: 16px 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- tables ---------- */
.tscroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.panel .tscroll { border: 0; border-radius: 0 0 10px 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 14.5px; }
table.data th { font-family: var(--f-head); font-weight: 600; font-size: 12.5px; letter-spacing: .02em; color: var(--ink-2); text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #F7FAF8; }
table.data tr.inactive td { color: var(--ink-3); }
table.data td.act { white-space: nowrap; text-align: right; }
table.data tr.err td { background: var(--bad-soft); }
table.data tr.upd td { background: #FBF6E6; }
.empty { padding: 30px 16px; text-align: center; color: var(--ink-3); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 1px 9px 1px 7px; border-radius: 20px; background: hsl(var(--h) 52% 93%); color: hsl(var(--h) 45% 27%); border: 1px solid hsl(var(--h) 52% 78%); white-space: nowrap; letter-spacing: .03em; }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: hsl(var(--h) 55% 45%); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 20px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }

/* ---------- meters ---------- */
.meter { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 70px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.over > i { background: var(--bad); }
.meter.warn > i { background: #C99A2E; }
.lm { display: flex; align-items: center; gap: 8px; }
.lm .meter { flex: 1; }
.lm span { min-width: 60px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

/* ---------- dashboard ---------- */
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 20px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 13px 16px; display: flex; flex-direction: column; gap: 3px; text-decoration: none; color: var(--ink); }
a.step:hover { border-color: var(--accent); }
.step .k { display: flex; align-items: center; gap: 8px; font-family: var(--f-head); font-weight: 600; color: var(--ink-2); font-size: 14px; }
.step .k i { font-style: normal; width: 23px; height: 23px; border-radius: 50%; border: 1.5px solid var(--ink-3); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.step.ok .k i { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.todo .k i { border-color: var(--warn); color: var(--warn); }
.step .v { font-family: var(--f-head); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.step .s { font-size: 13px; color: var(--ink-3); }
.step.later { opacity: .6; border-style: dashed; }
.alerts > div { padding: 9px 18px; border-bottom: 1px solid var(--line-2); display: flex; gap: 10px; align-items: baseline; font-size: 14.5px; }
.alerts > div:last-child { border-bottom: 0; }

/* ---------- classroom / curriculum ---------- */
.grade-row { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); align-items: start; }
.grade-row:last-child { border-bottom: 0; }
.grade-row > b { font-family: var(--f-head); font-size: 18px; }
.rooms { display: flex; flex-wrap: wrap; gap: 6px; }
.room { display: inline-flex; flex-direction: column; min-width: 78px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 7px; text-decoration: none; color: var(--ink); background: var(--surface); font-size: 13px; line-height: 1.35; }
.room b { font-size: 13.5px; }
.room span { color: var(--ink-3); font-size: 12px; }
.room:hover { border-color: var(--accent); }
.room.off { opacity: .5; border-style: dashed; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tabs a { padding: 6px 14px; border: 1px solid var(--line); border-radius: 20px; text-decoration: none; color: var(--ink-2); background: var(--surface); font-weight: 500; font-size: 14px; }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tabs a small { opacity: .8; }
.subj-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; max-height: 420px; overflow: auto; padding: 4px 0; }
.subj-pick label { display: flex; gap: 8px; align-items: baseline; padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.subj-pick label:hover { background: var(--surface-2); }
.pick-group { font-family: var(--f-head); font-weight: 600; font-size: 13px; color: var(--ink-2); grid-column: 1 / -1; padding: 8px 6px 2px; border-bottom: 1px solid var(--line-2); }
.summary-line { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line-2); font-size: 14.5px; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 58px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 26px 26px 22px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-card .btn { justify-content: center; padding: 10px; }

.help { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 16px; font-size: 14px; color: var(--ink-2); margin-bottom: 16px; }
.help ol, .help ul { margin: 6px 0 0; padding-left: 20px; }
.danger-zone { border-color: #EBB8AF; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print {
    .topbar, .sidebar, .actions, .toolbar, .btn, form, .no-print, .flash, .pagehead { display: none !important; }
    .layout { display: block; }
    .main { padding: 0; }
    .panel { border: 0; box-shadow: none; }
    .tscroll { overflow: visible; }
    table.tt { font-size: 10px; }
    table.tt .tt-cell { height: auto; }
    .tt-print-break { break-after: page; }
}
.stack { display: flex; flex-direction: column; gap: 0; }
table.data tfoot td { border-top: 1px solid var(--line); background: var(--surface-2); }
.room.move { border-style: dashed; }
.room span i { font-style: normal; }

/* ---------- สรุปโครงสร้างรายวิชา (1.2) ---------- */
.tabs.sub a { padding: 4px 12px; font-size: 13.5px; }
table.matrix td.c, table.matrix th.c { text-align: center; padding-left: 4px; padding-right: 4px; min-width: 30px; }
table.matrix td.on { background: var(--accent-soft); font-weight: 600; }
table.matrix td.on[style] { background: hsl(var(--h) 52% 90%); color: hsl(var(--h) 45% 25%); }
table.matrix td.on small { display: block; font-size: 10px; font-weight: 700; line-height: 1; }
table.matrix tr.sec td { background: var(--surface-2); font-family: var(--f-head); font-weight: 600; font-size: 13px; color: var(--ink-2); }
table.matrix tr.follower td { color: var(--ink-2); }
table.matrix tr.follower td.on { background: transparent; border: 1px dashed var(--line); }
table.data td.badn { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
table.data tr.gtop td { border-top: 2px solid var(--line); }
.panel > .ph { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.panel > .ph h2 { font-size: 16px; font-weight: 600; margin: 0; display: flex; gap: 8px; align-items: center; }
table.matrix td.nm { min-width: 210px; }
table.matrix th, table.matrix td { padding-top: 6px; padding-bottom: 6px; }
table.matrix th.c small { font-size: 9.5px; letter-spacing: 0; }

.toolbar input.big-search { width: 320px; max-width: 100%; font-size: 15px; }
.room-pick { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.room-pick label { min-width: 58px; }
.txt-bad { color: var(--bad); font-weight: 700; }
.txt-warn { color: var(--warn); font-weight: 600; }
.txt-good { color: var(--good); font-weight: 600; }
table.data tr.follower td { color: var(--ink-2); }
table.matrix td.na { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--line-2) 4px 5px); }
.grid2.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .grid2.even { grid-template-columns: minmax(0, 1fr); } }

/* ---------- จัดครูผู้สอน (รอบ 2) ---------- */
.room-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rchip { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 44px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; line-height: 1.15; background: var(--surface); }
.rchip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.rchip.pick { cursor: pointer; user-select: none; position: relative; }
.rchip.pick input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.rchip.pick small { font-size: 10px; color: var(--ink-3); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rchip.pick.taken { background: var(--surface-2); }
.rchip.pick:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.rchip.pick:has(input:checked) small { color: var(--accent-ink); opacity: .85; }
.rchip.pick:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.rchip.pick:has(input:disabled) { cursor: default; opacity: .75; }
.sticky-save { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line-2); display: flex; gap: 14px; align-items: center; z-index: 2; }

/* ---------- ช่องค้นหาแบบเลือกจากรายการ ---------- */
.combo { position: relative; width: 420px; max-width: 100%; }
.combo-input { width: 100%; font-size: 15px; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 360px; overflow: auto; margin: 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(0, 0, 0, .12); }
.combo-group { padding: 8px 12px 3px; font-size: 12px; font-weight: 700; color: var(--ink-3); }
.combo-opt { padding: 6px 12px 6px 20px; cursor: pointer; font-size: 14.5px; }
.combo-opt:hover, .combo-opt.on { background: var(--accent-soft); color: var(--accent); }
.combo-opt.sel { font-weight: 700; }
.combo-input.combo-dd { padding-right: 32px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23555' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center; cursor: pointer; }
.combo-input.combo-dd:focus { cursor: text; }
.combo-input.combo-dd::-webkit-search-cancel-button { margin-right: 4px; }
.combo-none { padding: 10px 12px; color: var(--ink-3); font-size: 14px; }

/* ---------- เวลาที่ครูไม่ว่างรายบุคคล ---------- */
table.ugrid th, table.ugrid td { text-align: center; padding: 5px 4px; }
table.ugrid tbody th { text-align: left; padding-left: 12px; }
.ucell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 74px; min-height: 48px; border: 1px dashed var(--line); border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1.2; background: var(--surface); }
.ucell:hover { border-color: var(--accent); }
.ucell input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.ucell small { font-size: 10.5px; color: var(--ink-3); max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ucell small.blk { color: var(--ink-3); font-style: italic; }
.ucell:has(input:checked) { border-style: solid; background: var(--bad-soft); border-color: var(--bad); color: var(--bad); font-weight: 600; }
.ucell.r-duty:has(input:checked), .ucell.r-rd:has(input:checked) { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.ucell:has(input:checked):not([class*=" r-"]) .t::before { content: "ไม่ว่าง"; }
.ucell:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.ucell:has(input:disabled) { cursor: default; }

/* ---------- ครูที่ปรึกษา ---------- */
.adv-list { display: flex; flex-direction: column; }
.adv-row { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); align-items: start; }
.adv-row.off { opacity: .6; }
.adv-room { display: flex; flex-direction: column; gap: 2px; padding-top: 6px; }
.adv-room b { font-size: 16px; }
.adv-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.adv-slot { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.adv-slot .combo { width: 100%; }
.adv-slot .combo-input { font-size: 14px; }
.adv-ro { padding: 7px 0; font-size: 14px; }
@media (max-width: 700px) { .adv-row { grid-template-columns: minmax(0, 1fr); gap: 6px; } .adv-room { flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: baseline; padding-top: 0; } }

/* ---------- ตารางสอน ---------- */
.checklist { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; }
.checklist li { padding-left: 24px; position: relative; }
.checklist li::before { position: absolute; left: 0; top: 0; font-weight: 700; }
.checklist li.ok::before { content: "✓"; color: var(--good); }
.checklist li.warn::before { content: "!"; color: var(--warn); left: 5px; }
.checklist li.bad::before { content: "✕"; color: var(--bad); }
.rchip.bad { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.rchip.miss { cursor: pointer; align-items: flex-start; padding: 5px 9px; font: inherit; font-size: 13px; }
.rchip.miss small { font-size: 11px; color: var(--ink-3); }
.rchip.miss[data-ah] { background: hsl(var(--h) 52% 93%); border-color: hsl(var(--h) 52% 72%); color: hsl(var(--h) 45% 25%); }
.rchip.miss[data-ah] small { color: hsl(var(--h) 30% 35%); }
.rchip.miss[data-ah]:hover { border-color: hsl(var(--h) 55% 45%); }
.rchip.miss.on, .rchip.miss[data-ah].on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rchip.miss.on small, .rchip.miss[data-ah].on small { color: inherit; }
table.tt { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; min-width: 760px; }
table.tt th { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 4px 2px; text-align: center; }
table.tt th small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-3); }
table.tt th.tt-day { width: 72px; text-align: left; padding-left: 8px; }
table.tt tbody th.tt-day { font-size: 14px; color: var(--ink); }
.tt-cell { position: relative; height: 70px; vertical-align: top; padding: 4px 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 12px; line-height: 1.25; overflow: hidden; }
.tt-cell.empty { background: var(--surface-2); border-style: dashed; }
.tt-cell.blk { background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 6px, transparent 6px, transparent 12px); color: var(--ink-3); text-align: center; vertical-align: middle; font-size: 12px; border-style: dotted; }
.tt-cell.blk.fixed { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-color: transparent; }
.tt-cell.locked { border-left: 4px solid var(--accent); }
.tt-cell.conflict { border-color: var(--bad); background: var(--bad-soft); }
.tt-e + .tt-e { border-top: 1px dotted var(--line); margin-top: 3px; padding-top: 3px; }
.tt-e b { display: block; font-size: 12.5px; }
.tt-e .tt-n, .tt-e .tt-t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-e .tt-n { color: var(--ink-2); }
.tt-e .tt-t { color: var(--ink-3); font-size: 11px; }
.tt-lock { position: absolute; right: 3px; top: 3px; color: var(--accent); }
.tt-lock .ic { width: 13px; height: 13px; }
.tt-edit[data-edit="1"] .tt-cell:not(.blk) { cursor: pointer; }
.tt-cell.sel { outline: 3px solid var(--accent); outline-offset: 1px; }
.tt-cell.ok { box-shadow: inset 0 0 0 2px var(--good); }
.tt-cell.ok.empty { background: var(--good-soft); }
.tt-cell.warn { box-shadow: inset 0 0 0 2px var(--warn); }
.tt-cell.no:not(.blk) { opacity: .45; }
.tt-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tt-bar { position: fixed; bottom: 0; left: var(--sidebar); right: 0; z-index: 30; box-shadow: 0 -6px 18px rgba(0, 0, 0, .08); display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 10px 18px; background: var(--surface); border-top: 1px solid var(--line-2); font-size: 14px; }
.tt-bar #ttMsg { font-weight: 600; }
.tt-bar.new [data-op="lock"], .tt-bar.new [data-op="remove"], .tt-bar.new [data-op="room"] { display: none; }
.tt-legend { color: var(--ink-3); font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; }
.tt-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.tt-legend .lg.ok { box-shadow: inset 0 0 0 2px var(--good); }
.tt-legend .lg.warn { box-shadow: inset 0 0 0 2px var(--warn); }
.tt-legend .lg.no { background: var(--line); opacity: .6; }
.tt-cell.no:not(.blk).has, .tt-cell.no:not(.blk).empty { box-shadow: inset 0 0 0 2px var(--bad-soft); }
.tt-cell.same:not(.blk), .tt-cell.no.same:not(.blk) { opacity: 1; outline: 2px dashed var(--accent); outline-offset: -5px; }
.tt-legend .lg.same { outline: 2px dashed var(--accent); outline-offset: -2px; }
.tt-mini-box.cls .tm-cell.busy { background: var(--surface-2); color: var(--ink); }
.tt-main { min-width: 0; }
.tt-actions { display: inline-flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.tt-cell.unav { background: var(--warn-soft); color: var(--warn); }
.tt-bar[hidden] { display: none; }

/* ---------- รอระบบทำงาน ---------- */
.busy-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(20, 28, 24, .35); padding: 16px; }
.busy-box { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 360px; padding: 24px 28px; border-radius: 14px; background: var(--surface); box-shadow: 0 18px 40px rgba(0, 0, 0, .2); text-align: center; }
.busy-box small { color: var(--ink-3); }
.spin { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media print {
    @page { size: A4 landscape; margin: 10mm; }
    .tt-sheet { break-after: page; break-inside: avoid; margin: 0; }
    .tt-sheet:last-child { break-after: auto; }
}

@media (max-width: 900px) { .tt-bar { left: 0; } }
/* ---------- แก้ตาราง: ข้อความแจ้ง ทั้งระดับ รายครู ---------- */
.tt-toast { position: fixed; z-index: 60; left: 50%; bottom: 76px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 10px; background: var(--ink); color: var(--surface); font-size: 14px; box-shadow: 0 10px 24px rgba(0, 0, 0, .2); transition: opacity .25s; }
.tt-toast.bad { background: var(--bad); color: #fff; }
.tt-toast.hide { opacity: 0; pointer-events: none; }
[data-drop-remove].drop { outline: 3px dashed var(--bad); outline-offset: 2px; }
.tt-grade .panel { margin-bottom: 14px; }
.tt-grade .ph h2 a { color: inherit; }
table.tt.compact { min-width: 720px; border-spacing: 2px; }
table.tt.compact .tt-cell { height: 46px; padding: 3px 4px; font-size: 11.5px; }
table.tt.compact .tt-e b { font-size: 12px; }
table.tt.compact th.tt-day { width: 58px; }
.tt-miss-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 18px 0; }
.tt-miss-row .lbl { font-size: 13px; color: var(--warn); font-weight: 600; }

/* ---------- ตารางเรียนทั้งระดับ: แผงตารางครูด้านข้าง ---------- */
.main:has(.tt-grade-layout) { max-width: none; }
.tt-grade-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 1280px) {
    .tt-grade-layout { grid-template-columns: minmax(0, 1fr) 400px; }
    .tt-side { position: sticky; top: 72px; max-height: calc(100vh - 150px); overflow-y: auto; }
}
.tt-side .panel { margin: 0; }
.tt-side-pick select { width: 100%; }
.tt-mini-box { padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.tt-mini-box.auto { background: var(--accent-soft); }
.tt-mini-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tt-mini-head a { color: var(--ink); text-decoration: none; }
.tt-mini-head [data-side-close] { margin-left: auto; padding: 2px 6px; }
.tt-mini-head [data-side-close] .ic { width: 14px; height: 14px; }
table.tt-mini { width: 100%; border-collapse: separate; border-spacing: 2px; table-layout: fixed; font-size: 10.5px; }
table.tt-mini th { font-weight: 600; color: var(--ink-3); padding: 0; text-align: center; }
table.tt-mini tbody th { width: 26px; text-align: left; }
.tm-cell { height: 24px; padding: 0 1px; text-align: center; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 24px; }
.tm-cell.own { background: var(--good-soft); color: var(--good); font-weight: 700; }
.tm-cell.busy { background: var(--line); color: var(--ink); }
.tm-cell.unav { background: repeating-linear-gradient(135deg, var(--warn-soft), var(--warn-soft) 4px, transparent 4px, transparent 8px); }
.tm-cell.clash { background: var(--bad-soft); color: var(--bad); }
.tm-cell.src { box-shadow: inset 0 0 0 2px var(--accent); }
.tm-cell.hl { box-shadow: inset 0 0 0 2px var(--warn); }
.tm-cell.src.hl { box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 2px var(--warn); }
.tt-mini-box.hov { background: var(--warn-soft); }
.tt-mini-tag:empty { display: none; }
.tt-mini-tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface); color: var(--ink-2); }
.tt-mini-box.auto .tt-mini-tag { color: var(--accent); }
.tt-mini-box.hov .tt-mini-tag { color: var(--warn); }

/* ---------- พิมพ์รายงาน ---------- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.report-card .field { margin-bottom: 10px; }
.report-card .field select { width: 100%; }
.report-card .form-actions { flex-wrap: wrap; }
.sheet-school { font-size: 12px; color: var(--ink-3); }
table.tt-matrix { border-collapse: collapse; width: 100%; font-size: 10.5px; table-layout: fixed; min-width: 1100px; }
table.tt-matrix th, table.tt-matrix td { border: 1px solid var(--line); padding: 1px 2px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 20px; }
table.tt-matrix thead th { background: var(--surface-2); font-weight: 600; }
table.tt-matrix th.rm { width: 86px; text-align: left; font-weight: 700; }
table.tt-matrix th.rm small { font-weight: 400; color: var(--ink-3); font-size: 9px; margin-left: 3px; }
table.tt-matrix thead th:first-child { width: 86px; }
table.tt-matrix thead th:last-child, table.tt-matrix td.n { width: 34px; }
table.tt-matrix .dstart { border-left: 2px solid var(--ink-3); }
table.tt-matrix td.use { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
table.tt-matrix td.clash { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
table.tt-matrix td.unav { background: repeating-linear-gradient(135deg, var(--warn-soft), var(--warn-soft) 3px, transparent 3px, transparent 6px); }
table.tt-matrix tbody tr:nth-child(even) th.rm { background: var(--surface-2); }
@media print {
    .tt-matrix-sheet { break-after: auto; break-inside: auto; }
    table.tt-matrix { min-width: 0; font-size: 7px; }
    table.tt-matrix th, table.tt-matrix td { height: 13px; padding: 0 1px; }
    table.tt-matrix thead { display: table-header-group; }
    table.tt-matrix tr { break-inside: avoid; }
    .sheet-head { padding: 0 0 4px; }
}
.tt-e.tt-e-mini { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px; }
.tt-e.tt-e-mini b { display: inline; font-size: 11px; }
.tt-e.tt-e-mini + .tt-e-mini { margin-top: 1px; padding-top: 1px; }
.tt-main table.tt { min-width: 660px; }
.tt-main table.tt th.tt-day { width: 60px; }
@media print { .tt-grade-layout { display: block; } }
.pill.wrap { white-space: normal; max-width: 100%; }
/* ไม่ว่างแบบไม่แสดงในตารางสอน: เห็นบนจอ (ขอบประ) แต่ไม่พิมพ์ */
.tt-cell.unav-hidden { background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 4px, transparent 4px, transparent 8px); color: var(--ink-3); }
@media print { .tt-cell.unav-hidden { background: none !important; } .tt-cell.unav-hidden > * { display: none !important; } }
.ucell.r-hidden:has(input:checked) { background: var(--surface-2); border-color: var(--ink-3); color: var(--ink-2); border-style: dashed; }
.act-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 28px; }
.sc-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.sc-row select { width: auto; min-width: 110px; }
.scout-day { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 2px 0; }
.scout-day select { width: auto; min-width: 110px; padding-top: 4px; padding-bottom: 4px; }
.period-ticks { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.ptick { position: relative; display: inline-flex; }
.ptick input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.ptick span { display: inline-block; min-width: 28px; padding: 3px 0; text-align: center; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: var(--surface); }
.ptick input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.ptick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
/* ตารางภาระงานครู: หัวคอลัมน์และตัวเลขอยู่กลาง */
table.load-table th { text-align: center; }
table.load-table td.n, table.load-table th.n { text-align: center; }
table.load-table td:has(> .lm) { text-align: center; }
table.load-table .lm { justify-content: center; }
table.load-table .lm span { text-align: center; min-width: 48px; }

/* 1.15.0 หน้าจัดวิชาให้ครู: บันทึกครั้งเดียว */
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; margin-right: 6px; vertical-align: 2px; }
.req { color: var(--bad); }
.act-opts { display: flex; flex-wrap: wrap; gap: 4px 22px; font-weight: 400; }
.act-club.need { outline: 2px solid var(--bad); outline-offset: 6px; border-radius: 6px; }
.panel.save-all { padding: 10px 16px; }
#activity .pick-table .period-ticks { display: inline-flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.panel.save-all { flex-wrap: wrap; gap: 6px 14px; }
.panel.save-all .small { flex: 1 1 260px; }
@media (max-width: 640px) { .panel.save-all .small { display: none; } .panel.save-all .btn { width: 100%; justify-content: center; } }

/* 1.16.0 ห้องที่ใช้สอนรายห้องเรียน */
.troom { display: grid; gap: 4px; }
.troom select { max-width: 280px; }
.troom-split { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 8px; }
.troom-c { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.troom-c span { min-width: 38px; font-size: 13px; color: var(--ink-2); }
.troom-c select { flex: 1; min-width: 0; padding-top: 3px; padding-bottom: 3px; font-size: 13px; }
.room-live { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 8px; padding-bottom: 0; }
.room-live:empty { display: none; }
.troom-split[hidden], .troom-all[hidden] { display: none; }
.scout-when { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }

/* 1.17.0 คาบที่ล็อกไว้: เลือกห้องรายระดับ */
.fs-grades { display: grid; gap: 8px; margin-top: 6px; font-weight: 400; }
.fs-grade { border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }
.fs-grade.off { opacity: .55; }
.fs-gh { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: center; }
.fs-rooms[hidden] { display: none; }

/* 1.18.0 กลุ่มห้องที่ใช้สอน (เลือกได้หลายห้อง) */
.rm { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.rm-list { display: contents; }
.rm-chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; }
.rm-x { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; border-radius: 999px; }
.rm-x:hover { background: rgba(0,0,0,.08); }
.rm select { width: auto; min-width: 84px; max-width: 160px; padding-top: 3px; padding-bottom: 3px; font-size: 13px; }
.rm-empty[hidden] { display: none; }
.troom-c { align-items: flex-start; }
.troom-c > span { padding-top: 4px; }

/* 1.18.1 แจ้งเตือนรายวิชาที่ไม่มีรหัสตอนนำเข้าโครงสร้าง */
.alert-box { border: 1px solid; border-radius: var(--radius); padding: 10px 14px; }
.alert-box.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert-box.warn ul, .alert-box.warn p { color: var(--ink, inherit); }
tr.nocode td { background: var(--warn-soft); }

/* 1.19.0 กลุ่มสาระที่ร่วมสอน */
.co-areas { display: flex; flex-wrap: wrap; gap: 4px 16px; font-weight: 400; margin-top: 4px; }
table.data td.c, table.data th.c { text-align: center; }

/* ห้องเรียน×วิชาที่ปิดใช้ในภาคเรียน (คลิกขวาที่ห้องในหน้าจัดวิชาให้ครู) */
.rchip.pick.off { background: transparent; border-style: dashed; color: var(--ink-3); cursor: context-menu; opacity: 1; }
.rchip.pick.off span { text-decoration: line-through; }
.rchip.pick.off small { color: var(--ink-3); }
.ctx-menu { position: fixed; z-index: 1000; min-width: 190px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.ctx-menu .ctx-h { padding: 5px 10px 6px; font-size: 12px; color: var(--ink-3); border-bottom: 1px solid var(--line); margin-bottom: 3px; }
.ctx-menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; font: inherit; font-size: 14px; color: var(--ink); border-radius: 5px; cursor: pointer; }
.ctx-menu button:hover:not(:disabled) { background: var(--accent-soft); }
.ctx-menu button:disabled { color: var(--ink-3); cursor: default; }

/* 1.23.0 ห้องที่ใช้สอนรายครั้ง */
.tr-gen[hidden], .tr-ses[hidden] { display: none; }
.tr-ses { display: grid; gap: 4px; }
.tr-s { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.tr-s > span.small { min-width: 104px; color: var(--ink-2); }
.troom-c .tr-gen, .troom-c .tr-ses { flex: 1; min-width: 0; }
.troom-c .tr-s > span.small { min-width: 96px; }

/* 1.24.0 จัดสถานที่ใช้สอน */
.venue-table tr.unset td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
.venue-table tr.unset td { background: color-mix(in srgb, var(--warn-soft) 45%, transparent); }
.venue-table td { vertical-align: top; }

/* 1.24.3 ที่มาของคาบห้อง */
.room-pill { cursor: pointer; border: 1px solid transparent; font: inherit; font-size: 12px; font-weight: 600; }
.room-pill:hover, .room-pill.sel { border-color: currentColor; }
.room-src { flex-basis: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); }
.room-src[hidden] { display: none; }
.room-src-h { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.room-src-h .btn { margin-left: auto; }
.room-src tr.on td { background: var(--accent-soft); }
.room-pill.mine { box-shadow: inset 0 0 0 1px var(--accent); }
.room-live-opt { display: inline-flex; gap: 4px; margin-right: 4px; }
.room-live-opt .btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* 1.26.0 จัดทีละขั้น */
.steps-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 8px; }
.steps-list li form { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.steps-list li form .small.muted { flex-basis: 100%; }
/* เลือกครูตามกลุ่มสาระ (หน้าจัดตารางรายครู) */
.tpick { padding: 10px 12px; }
.tpick .tabs { align-items: center; margin-bottom: 6px; }
.tchips { display: flex; flex-wrap: wrap; gap: 6px; }
.tchip { padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); background: var(--surface); font-size: 13.5px; }
.tchip small { color: var(--ink-2); }
.tchip:hover { border-color: var(--accent); }
.tchip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tchip.on small { color: inherit; opacity: .85; }
/* สรุปอัปเดตสถานที่ในตาราง */
.sync-sum details { margin-top: 6px; }
.sync-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 320px; overflow: auto; font-size: 13.5px; }
.sync-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
/* สีกลุ่มสาระของคาบในตาราง (บนจอเท่านั้น ไม่พิมพ์) */
.tt-cell.has[data-ah]:not(.conflict) { background: hsl(var(--h) 52% 95%); border-color: hsl(var(--h) 45% 80%); }
.tt-cell.has[data-ah] .tt-e > b { color: hsl(var(--h) 45% 25%); }
@media print {
    .tt-cell.has[data-ah]:not(.conflict) { background: var(--surface) !important; border-color: var(--line) !important; }
    .tt-cell.has[data-ah] .tt-e > b { color: inherit !important; }
}
/* แผงตารางเพื่อเทียบ: หัวข้อคั่นก่อนตารางห้องสถานที่ */
.tt-side-sep { margin-top: 18px; padding: 10px 16px 6px; border-top: 3px double var(--line); font-size: 13px; font-weight: 700; color: var(--ink-2); letter-spacing: .02em; background: var(--surface-2); }
.tt-side-sep::before { content: "▼ "; font-size: 10px; color: var(--ink-3); }
.tt-side-sep[hidden] { display: none; }
/* ---------- พิมพ์รายงาน (print.php): A4 แนวตั้ง หน้าละ 2 ตาราง · ในตารางจัดกลาง ตัวอักษรดำ กรอบดำทุกช่อง ---------- */
@media print {
    html, body, .layout, .main { background: #fff !important; }
    .ttp .tt-sheet { break-after: auto; break-inside: avoid; margin: 0; padding: 0; height: 136mm; overflow: hidden; background: #fff !important; }
    .ttp .tt-sheet:nth-child(2n) { break-after: page; }
    .ttp .tt-sheet:nth-child(2n+1) { margin-bottom: 4mm; }
    .ttp .tt-sheet:last-child { break-after: auto; }
    .ttp .sheet-head { padding: 0 0 2mm; border: 0; }
    .ttp .sheet-head, .ttp .sheet-head * { color: #000 !important; }
    .ttp .sheet-school { font-size: 10px; }
    .ttp .print-title { font-size: 14px; margin: 0; }
    .ttp .sheet-head .small { font-size: 10px; }
    .ttp table.tt { min-width: 0; width: 100%; table-layout: fixed; border-collapse: collapse; border-spacing: 0; font-size: 9px; color: #000; }
    .ttp table.tt th, .ttp table.tt td, .ttp table.tt .tt-cell { border: 1px solid #000 !important; border-radius: 0; background: #fff !important; color: #000 !important; text-align: center !important; vertical-align: middle !important; padding: 1mm .6mm; height: 19mm; box-shadow: none !important; }
    .ttp table.tt thead th { height: auto; padding: 1mm .5mm; font-size: 10px; font-weight: 700; }
    .ttp table.tt th small { color: #000 !important; font-size: 8px; font-weight: 400; }
    .ttp table.tt th.tt-day { width: 15mm; padding-left: .5mm; font-size: 10.5px; font-weight: 700; }
    .ttp table.tt .tt-cell.blk { font-weight: 600; font-size: 9.5px; }
    .ttp table.tt .tt-cell.blk span, .ttp table.tt .tt-cell * { color: #000 !important; }
    .ttp .tt-e { text-align: center; }
    .ttp .tt-e b { font-size: 10.5px; }
    .ttp .tt-e .tt-n, .ttp .tt-e .tt-t { font-size: 8.5px; white-space: normal; overflow: hidden; text-overflow: clip; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.15; }
    .ttp .tt-e + .tt-e { border-top: 1px dotted #000; }
    .ttp .tt-e.tt-e-mini { font-size: 8px; white-space: normal; }
    .ttp .tt-e.tt-e-mini b { font-size: 8.5px; }
}
/* โลโก้โรงเรียนหน้าส่วนหัวตารางที่พิมพ์: สูงเท่าบรรทัดโรงเรียน–บรรทัดห้องเรียน ตัวอักษรอยู่ถัดจากโลโก้ */
.ph.sheet-head { display: flex; align-items: center; justify-content: flex-start; gap: 10px; }
.sheet-head .sheet-logo { display: block; flex: none; width: auto; height: 56px; object-fit: contain; }
@media print {
    .sheet-head .sheet-logo { height: 13mm; }
}
@media print {
    /* กรอบด้านขวา/ล่างของตารางไม่ถูกตัด */
    .ttp .tscroll { border: 0; border-radius: 0; padding: 1px; overflow: visible; }
    .ttp table.tt { width: calc(100% - 2px); }
}
@media print {
    /* ช่องวิชา (.tt-cell มี position: relative) ห้ามวาดพื้นทับเส้นกรอบแบบ collapse: เส้นในช่องวิชาจะบาง/หายไม่เท่ากับเส้นวัน/คาบ */
    .ttp table.tt .tt-cell { position: static !important; overflow: visible !important; background: transparent !important; }
    .ttp table.tt th { background: transparent !important; }
}
/* ตารางเรียนทั้งระดับ: รายการผิดข้อบังคับแบบเลื่อนลง */
.conf-drop { position: relative; display: inline-block; }
.conf-drop > summary { list-style: none; cursor: pointer; }
.conf-drop > summary::-webkit-details-marker { display: none; }
.conf-drop .conf-list { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; width: min(560px, 90vw); max-height: 60vh; overflow: auto; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 28px rgba(0, 0, 0, .15); font-size: 13px; }
.conf-drop .conf-cls { margin-top: 8px; font-weight: 700; }
.conf-drop .conf-cls:first-child { margin-top: 0; }
.conf-drop ul { margin: 4px 0 0; padding-left: 18px; color: var(--bad); }
.conf-drop li { margin: 2px 0; }
/* เลือก/เปลี่ยนห้องของคาบ (แก้ตารางเอง) */
.tt-room-pick { position: absolute; z-index: 70; width: 300px; max-width: calc(100vw - 16px); padding: 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 14px 32px rgba(0, 0, 0, .18); font-size: 13.5px; }
.tt-room-pick .rp-head { margin-bottom: 8px; }
.tt-room-pick .rp-list { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow: auto; }
.tt-room-pick .rp-room { display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font: inherit; cursor: pointer; }
.tt-room-pick .rp-room b { min-width: 52px; }
.tt-room-pick .rp-room span { font-size: 12px; color: var(--ink-3); }
.tt-room-pick .rp-room.free { border-color: var(--good); background: var(--good-soft); }
.tt-room-pick .rp-room.free span { color: var(--good); }
.tt-room-pick .rp-room.busy span, .tt-room-pick .rp-room.closed span { color: var(--bad); }
.tt-room-pick .rp-room.cur { box-shadow: inset 3px 0 0 var(--accent); }
.tt-room-pick .rp-room:hover, .tt-room-pick .rp-room:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tt-room-pick .rp-span { display: block; margin-top: 8px; }
.tt-room-pick .rp-foot { margin-top: 8px; text-align: right; }
/* ---------- ผู้ใช้กลุ่มสาระ: แถบเมนู + หน้าเมนู ---------- */
.area-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 18px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.area-nav-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; margin-right: 10px; font-size: 14px; }
.area-nav a { padding: 6px 14px; border-radius: 20px; text-decoration: none; color: var(--ink-2); font-size: 14px; font-weight: 500; border: 1px solid transparent; }
.area-nav a:hover { border-color: var(--line); }
.area-nav a.on { background: var(--accent); color: var(--accent-ink); }
.area-home { max-width: 980px; margin: 24px auto; text-align: center; }
.area-home-head h1 { margin: 4px 0 6px; font-size: 28px; }
.area-home-prog { width: min(420px, 90%); height: 10px; margin: 14px auto 4px; border-radius: 10px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.area-home-prog span { display: block; height: 100%; background: var(--accent); }
.area-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 32px; align-items: stretch; }
.area-card { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 30px 22px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .04); transition: transform .12s, box-shadow .12s; }
.area-card:hover, .area-card:focus-visible { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, .1); border-color: var(--accent); }
.area-card b { font-size: 21px; }
.area-card .small { color: var(--ink-2); max-width: 320px; }
.area-card-ic { display: inline-flex; width: 56px; height: 56px; align-items: center; justify-content: center; border-radius: 16px; background: var(--accent-soft); color: var(--accent); }
.area-card-ic svg { width: 28px; height: 28px; }
.area-card.c2 .area-card-ic { background: hsl(200 60% 93%); color: hsl(200 55% 32%); }
.area-card.c3 .area-card-ic { background: hsl(35 80% 92%); color: hsl(30 60% 32%); }
.area-card.c4 .area-card-ic { background: hsl(280 45% 93%); color: hsl(280 35% 36%); }
.area-card .pill { margin-top: auto; }
.area-card .small { line-height: 1.55; }
@media (max-width: 1000px) { .area-cards { gap: 14px; } .area-card { padding: 24px 16px; } .area-card b { font-size: 19px; } }
@media (max-width: 700px) { .area-cards { grid-template-columns: minmax(0, 1fr); } }
/* จัดสถานที่ใช้สอน: ตาราง + แถบจำนวนคาบของห้องด้านข้าง */
.venue-layout { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 14px; align-items: start; }
.venue-layout > form { margin: 0; min-width: 0; }
.venue-side { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; padding: 12px; margin: 0; }
.rl-head { margin-bottom: 8px; font-size: 14px; }
.rl-list { display: flex; flex-direction: column; gap: 6px; }
.rl-row { display: block; width: 100%; text-align: left; padding: 6px 9px 7px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font: inherit; cursor: pointer; }
.rl-row.mine { border-color: var(--good); }
.rl-row.sel { outline: 2px solid var(--accent); }
.rl-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; }
.rl-n { font-weight: 700; font-variant-numeric: tabular-nums; }
.rl-bar { display: block; height: 7px; margin-top: 5px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.rl-bar i { display: block; height: 100%; background: var(--good); border-radius: 6px; }
.rl-row.warn .rl-bar i { background: var(--warn); }
.rl-row.warn .rl-n { color: var(--warn); }
.rl-row.bad .rl-bar i { background: var(--bad); }
.rl-row.bad .rl-n { color: var(--bad); }
.rl-note { margin: 10px 0 0; }
.venue-side .room-src { margin-top: 10px; font-size: 12.5px; }
@media (max-width: 1100px) { .venue-layout { grid-template-columns: minmax(0, 1fr); } .venue-side { position: static; max-height: none; } }
/* ---------- รายงานกลุ่มสาระ ---------- */
.rpt-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.rpt-card { display: flex; flex-direction: column; gap: 8px; padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
a.rpt-card:hover { border-color: var(--accent); box-shadow: 0 6px 16px rgba(0, 0, 0, .08); }
.rpt-card b { font-size: 16px; }
.rpt-card-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
@media (max-width: 900px) { .rpt-cards { grid-template-columns: minmax(0, 1fr); } }
.rpt-sheet { padding: 14px 16px; }
.rpt-sheet .rpt-head { padding: 0 0 8px; border: 0; }
table.rpt { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
table.rpt th, table.rpt td { border: 1px solid var(--ink-3); padding: 4px 6px; text-align: center; vertical-align: middle; word-wrap: break-word; }
table.rpt th { background: var(--surface-2); font-weight: 700; }
table.rpt td.l { text-align: left; }
table.rpt td.r { text-align: right; }
table.rpt tr.rpt-total td { font-weight: 700; background: var(--surface-2); }
table.rpt .rpt-warn { color: var(--bad); font-weight: 600; }
table.rpt td small { color: var(--ink-3); }
@media print {
    html, body, .layout, .main { background: #fff !important; }
    .rpt-wrap .rpt-sheet { border: 0; box-shadow: none; padding: 0; margin: 0 0 6mm; }
    .rpt-wrap .rpt-person { break-inside: avoid; }
    .rpt-wrap .rpt-head, .rpt-wrap .rpt-head * { color: #000 !important; }
    .rpt-wrap .sheet-logo { height: 13mm; }
    table.rpt { font-size: 9.5pt; color: #000; }
    table.rpt th, table.rpt td { border: 1px solid #000 !important; color: #000 !important; background: #fff !important; padding: 1mm 1.2mm; }
    table.rpt th { font-weight: 700; }
    table.rpt thead { display: table-header-group; }
    table.rpt tr { break-inside: avoid; }
    table.rpt .rpt-warn, table.rpt td small { color: #000 !important; }
}
.ph.sheet-head { flex-wrap: nowrap; }
.ph.sheet-head > div { flex: 1 1 auto; min-width: 0; }
.tt-room-pick .rp-room.group span { color: var(--warn); }
.tt-room-pick.wide { width: 560px; }
.tt-room-pick .rp-sec { margin-top: 8px; }
.tt-room-pick .rp-sec-h { margin-bottom: 4px; font-size: 13px; }
.tt-room-pick.wide .rp-list { flex-direction: row; flex-wrap: wrap; max-height: none; }
.tt-room-pick.wide .rp-room { width: auto; min-width: 120px; flex: 0 1 auto; flex-direction: column; gap: 0; }
.tt-room-pick .rp-room.on { outline: 3px solid var(--accent); outline-offset: 0; background: var(--accent-soft); }
.tt-room-pick .rp-room.dup { outline-color: var(--bad); }
.tt-room-pick .rp-warn { color: var(--bad); margin: 8px 0 0; }
.tt-room-pick .rp-room.on { background: var(--accent); border-color: var(--accent); }
.tt-room-pick .rp-room.on b, .tt-room-pick .rp-room.on span { color: var(--accent-ink) !important; }
.tt-room-pick .rp-room.on b::before { content: "✓ "; }
.tt-room-pick .rp-room.on.dup { background: var(--bad); border-color: var(--bad); }
/* ห้องที่ใช้สอนได้รายอาคาร (room/building) */
.bld-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.bld .ph { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bld .ph h2 { margin: 0; }
.bld-act { margin-left: auto; display: flex; gap: 4px; }
.bld-rooms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.bld-room { display: flex; gap: 8px; align-items: flex-start; min-width: 0; cursor: pointer; padding: 3px 4px; border-radius: 6px; }
.bld-room:hover { background: var(--surface-2); }
.bld-room input { margin-top: 4px; flex: none; }
.bld-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.bld-t small { color: var(--ink-3); font-size: 12px; overflow-wrap: anywhere; }
.bld-t .pill { align-self: flex-start; font-size: 11px; padding: 0 6px; margin-top: 2px; white-space: normal; }
/* รายงานการจัดรายวิชารายบุคคล (ผู้ดูแลระบบ): A4 แนวตั้ง ตารางละกลุ่มสาระ · ตัวอักษร 11 pt (ประมาณ TH Sarabun New 15) */
.prs-wrap { font-size: 11pt; }
.prs-sheet { padding: 16px 20px; margin-bottom: 16px; }
.prs-head { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; text-align: center; }
.prs-head .sheet-logo { height: 48px; width: auto; }
.prs-school { font-size: 10pt; }
.prs-title { font-size: 13.5pt; margin: 0; }
table.prs { width: calc(100% - 4px); margin: 0 2px; border-collapse: collapse; table-layout: fixed; font-size: 11pt; line-height: 1.3; }
table.prs th, table.prs td { border: 1px solid var(--ink-3); padding: 2px 4px; text-align: center; vertical-align: middle; overflow-wrap: anywhere; }
table.prs th { background: var(--surface-2); font-weight: 700; font-size: 11pt; white-space: nowrap; }
table.prs th.prs-area { font-size: 12.5pt; background: var(--surface); }
table.prs td.l { text-align: left; }
table.prs td.r { text-align: right; }
table.prs td.nw { white-space: nowrap; overflow-wrap: normal; }
table.prs tbody.prs-t { break-inside: avoid; }
@media print {
    .prs-wrap .prs-sheet { border: 0; box-shadow: none; padding: 0 1px; margin: 0; break-after: page; overflow: visible; }
    .prs-wrap .prs-sheet:last-child { break-after: auto; }
    .prs-wrap, .prs-wrap * { color: #000 !important; }
    .prs-head .sheet-logo { height: 13mm; }
    /* พื้นช่องโปร่งใส: พื้นขาวของช่องวาดทับเส้นกรอบแบบ collapse ทำให้เส้นขวาหาย */
    table.prs th, table.prs td { border: 1px solid #000 !important; background: transparent !important; padding: .6mm 1.2mm; }
    table.prs thead { display: table-header-group; }
    table.prs tr { break-inside: avoid; }
}
/* หน้าพิมพ์รายงาน: กรอบใหญ่ตามประเภทรายงาน */
.report-group { border: 1.5px solid var(--line-2); border-radius: 14px; padding: 14px 16px 16px; margin-bottom: 18px; background: var(--surface-2); }
.report-group-h { font-size: 17px; margin: 0 0 12px; }

/* 1.39.0: เปิด-ปิดการบันทึกของกลุ่มสาระ */
.alert-box.info { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.edit-window { margin: 0 0 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.edit-window svg { flex: none; }
.edit-window a { color: inherit; text-decoration: underline; font-weight: 600; }
.ew-table td, .ew-table th { vertical-align: middle; }
.ew-table input[type=datetime-local] { width: 205px; }
.ew-table .ew-name { font-weight: 600; }
.ew-switch { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-weight: 600; }
.ew-bulk { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 1.41.0: หน้าจัดตารางสอน ส่วนที่ย่อ/ขยายได้ + ตรวจคาบที่ยังไม่มีห้อง */
details.tt-fold { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
details.tt-fold:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
details.tt-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; margin: 0 0 6px; user-select: none; }
details.tt-fold > summary::-webkit-details-marker { display: none; }
details.tt-fold > summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin: -4px 2px 0 2px; transition: transform .15s; flex: none; }
details.tt-fold:not([open]) > summary::before { transform: rotate(-45deg); margin-top: 0; }
details.tt-fold > summary h3 { margin: 0; font-size: 15px; display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.tt-fold > summary:hover h3 { color: var(--accent); }
.noroom-t td { vertical-align: top; }
.noroom-t td.nw { white-space: nowrap; }
.noroom-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.noroom-list > li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); }
.noroom-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.noroom-chips .rchip { text-decoration: none; font-size: 12.5px; }

/* 1.42.0: ห้องคาบพัฒนาคุณธรรม (หน้าครูที่ปรึกษา) */
.adv-dev { display: flex; flex-direction: column; gap: 3px; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; }
.adv-dev .combo { width: 100%; }
.adv-dev .combo-input { background: var(--accent-soft); }

/* 1.43.0: สำรองฐานข้อมูล */
.bk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.bk-grid .panel { margin: 0; }
.bk-steps { margin: 4px 0 12px; padding-left: 20px; }
.bk-cmd { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0 10px; }
details.bk-term { border-top: 1px solid var(--line); }
details.bk-term > summary { padding: 10px 18px; cursor: pointer; }
details.bk-term .tscroll { margin: 0 18px 12px; border: 1px solid var(--line); border-radius: 8px; }

/* 1.44.0: สถานะออนไลน์ (วงกลมตัวอักษร) + แชทผู้ดูแลระบบ */
.ob { --c: #435775; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--c); color: #fff; font-weight: 700; font-size: 15px; line-height: 1; border: 2.5px solid #22A55A; box-shadow: 0 0 0 2px var(--surface); user-select: none; }
.ob.more { background: var(--surface-2); color: var(--ink-2); font-size: 12px; }
.online-bar { position: relative; }
.online-btn { display: flex; align-items: center; gap: 8px; padding: 2px 6px; border: 0; background: none; cursor: pointer; border-radius: 22px; font: inherit; color: var(--ink-3); }
.online-btn:hover, .online-btn[aria-expanded="true"] { background: var(--surface-2); }
.online-bubbles { display: flex; }
.online-bubbles .ob + .ob { margin-left: -7px; }
.online-none { font-size: 12.5px; }
.online-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; width: 300px; max-width: 86vw; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .14); padding: 8px; }
.op-h { font-weight: 700; padding: 4px 6px 8px; }
.op-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px; border-radius: 8px; }
.op-row:hover { background: var(--surface-2); }
.op-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.op-t span { overflow-wrap: anywhere; }
.op-f { padding: 6px 6px 2px; border-top: 1px solid var(--line-2); margin-top: 4px; }
.chat-dock { position: fixed; right: 18px; bottom: 18px; z-index: 70; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chat-fab { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border: 0; border-radius: 26px; background: var(--accent); color: #fff; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); }
.chat-fab:hover { filter: brightness(1.08); }
.chat-dock.open .chat-fab { opacity: .85; }
.chat-badge { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #D93025; color: #fff; font-size: 12px; line-height: 22px; text-align: center; border: 2px solid var(--surface); }
.chat-panel { order: -1; width: 360px; max-width: calc(100vw - 36px); height: 480px; max-height: calc(100vh - 120px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 40px rgba(0, 0, 0, .22); overflow: hidden; }
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--accent-soft); }
.chat-head b { margin-right: auto; }
.chat-x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 0 4px; }
.chat-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { margin: auto; text-align: center; }
.cm { display: flex; gap: 8px; align-items: flex-start; }
.cm .ob { width: 28px; height: 28px; font-size: 13px; border-width: 2px; }
.cm-b { max-width: calc(100% - 44px); background: var(--surface-2); border-radius: 4px 12px 12px 12px; padding: 6px 10px; }
.cm.mine { flex-direction: row-reverse; }
.cm.mine .cm-b { background: var(--accent-soft); border-radius: 12px 4px 12px 12px; }
.cm-h { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.cm-t { color: var(--ink-3); font-size: 11.5px; }
.cm-del { border: 0; background: none; color: var(--ink-3); font-size: 11.5px; cursor: pointer; padding: 0; margin-left: auto; }
.cm-del:hover { color: var(--bad); text-decoration: underline; }
.cm-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.45; }
.chat-form { display: flex; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; font: inherit; font-size: 14.5px; }
.chat-note { margin: 0; padding: 0 10px 8px; }
.chat-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; padding: 2px 10px 4px; font-size: 13px; color: var(--ink-2); }
.chat-opts label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.chat-opts input:disabled + * { opacity: .6; }
/* กล่องเด้งเมื่อมีข้อความใหม่ (เหนือปุ่มแชท) */
.chat-toast { display: flex; align-items: flex-start; gap: 10px; width: 320px; max-width: calc(100vw - 36px); padding: 10px 10px 10px 12px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; box-shadow: 0 10px 28px rgba(0, 0, 0, .2); cursor: pointer; animation: chat-toast-in .2s ease-out; }
.chat-toast[hidden] { display: none; }
.ct-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ct-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
.ct-body { font-size: 14px; color: var(--ink-2); white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ct-x { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 0 2px; }
.chat-fab.ring { animation: chat-ring .7s ease-in-out 2; }
@keyframes chat-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes chat-ring { 0%, 100% { transform: none; } 20% { transform: rotate(-7deg) scale(1.06); } 40% { transform: rotate(6deg) scale(1.06); } 60% { transform: rotate(-4deg); } 80% { transform: rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .chat-toast, .chat-fab.ring { animation: none; } }
@media (max-width: 700px) { .online-bar { order: 4; } .chat-dock { right: 10px; bottom: 10px; } }
@media print { .chat-dock, .online-bar { display: none !important; } }
.scout-groups { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

/* 1.45.1: รายงานโครงสร้างรายวิชา (แบบเอกสาร) */
.cp-sheet { padding: 14px 16px; }
.cp-head { text-align: center; margin: 0 0 10px; line-height: 1.5; }
.cp-h1 { font-family: var(--f-head); font-weight: 700; font-size: 17px; }
.cp-h2 { font-size: 14px; }
.cp-h3 { font-weight: 700; font-size: 15px; }
table.cp-t { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
table.cp-t col.cp-c { width: 10.5%; }
table.cp-t col.cp-n { width: 6.17%; }
table.cp-t th, table.cp-t td { border: 1px solid #333; padding: 2px 4px; vertical-align: middle; }
table.cp-t th { text-align: center; font-weight: 700; background: #F3F5F2; line-height: 1.25; font-size: 12px; overflow-wrap: anywhere; }
table.cp-t td.cp-num { text-align: center; }
table.cp-t td.cp-code { overflow-wrap: anywhere; line-height: 1.25; }
table.cp-t td.cp-code small { display: block; font-size: 10.5px; color: var(--ink-3); white-space: normal; line-height: 1.2; }
table.cp-t td.cp-act { white-space: normal; font-size: 12px; line-height: 1.25; }
table.cp-t td.cp-miss { text-decoration: underline dotted var(--warn); text-underline-offset: 3px; }
table.cp-t tr.cp-sec td { text-align: center; font-weight: 700; background: #F3F5F2; }
table.cp-t tr.cp-sum td { background: #BCD0E6; font-weight: 700; text-align: center; }
table.cp-t tr.cp-hrs td { text-align: center; font-weight: 700; line-height: 1.25; }
table.cp-t tr.cp-hrs small { display: block; font-weight: 400; font-size: 11px; }
table.cp-t .cp-red { color: #D00000; }
table.cp-t .cp-yel { background: #FFF200; }
.cp-print .cp-sheet { margin-bottom: 16px; }
@media print {
    .cp-print .cp-sheet { break-after: page; page-break-after: always; border: 0; box-shadow: none; padding: 0; margin: 0; }
    .cp-print .cp-sheet:last-child { break-after: auto; page-break-after: auto; }
    table.cp-t { font-size: 10.5pt; }
    table.cp-t th, table.cp-t td { padding: 1px 3px; }
    table.cp-t th, table.cp-t tr.cp-sec td { background: #F3F5F2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    table.cp-t tr.cp-sum td { background: #BCD0E6 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    table.cp-t .cp-yel { background: #FFF200 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* 1.46.0: ที่ปรึกษาแบบไม่มีห้อง */
.adv-noroom .adv-row { border-top: 2px dashed var(--line); background: var(--bg-2, #F7F8F6); }
.adv-noroom .adv-ga-note { grid-column: 1 / -1; }

/* เลือกห้อง: ชี้ห้องในรายการ ช่องที่ห้องนั้นว่างมีกรอบเขียว (ช่องที่มีวิชายังเป็นพื้นเดิม แสดงแค่กรอบ) */
@media screen {
    table.tt .tt-cell.room-free { outline: 3px solid #1F9D55 !important; outline-offset: -3px; box-shadow: 0 0 0 1px #1F9D55; }
}

/* จัดเวรประตู (timetable/gate) */
.gate-chips { display: flex; flex-direction: column; gap: 10px; padding: 4px 18px 16px; }
.gate-sec { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gchip { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 999px; padding: 2px 4px 2px 12px; }
.gchip a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.gchip a small { font-weight: 400; color: var(--ink-3); }
.gchip.done { border-color: var(--good); background: var(--good-soft); }
.gchip.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.gchip form { margin: 0; }
.gchip .gx { border: 0; background: transparent; color: var(--ink-3); font-size: 16px; line-height: 1; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; }
.gchip .gx:hover { background: var(--bad-soft); color: var(--bad); }
table.gate-grid td.gcell { vertical-align: top; min-width: 92px; font-size: 13px; line-height: 1.3; }
.gcell .gc-n { font-size: 11.5px; color: var(--ink-3); }
.gcell .gc-n.max { color: var(--bad); font-weight: 700; }
.gcell .gc-t { font-weight: 600; }
.gcell .gc-t.me { color: var(--good); }
.gcell .gc-why { font-size: 11.5px; color: var(--ink-3); }
.gcell form { margin: 4px 0 0; }
.gcell .gc-btn { width: 100%; }
.gcell.busy { background: var(--surface-2); }
.gcell.full { background: var(--bad-soft); }
.gcell.mine { background: var(--good-soft); box-shadow: inset 0 0 0 2px var(--good); }
.gcell.ok { box-shadow: inset 0 0 0 1px var(--line-2); }
/* เวรประตูในหน้าจัดตารางรายครู */
table.tt.gate-mode td.tt-cell[data-gate="ok"] { outline: 3px dashed #1F9D55; outline-offset: -4px; cursor: pointer; }
table.tt.gate-mode td.tt-cell[data-gate="full"] { background: var(--bad-soft); cursor: not-allowed; }
table.tt.gate-mode td.tt-cell[data-gate="extra"] { outline: 3px dashed var(--bad); outline-offset: -4px; background: var(--bad-soft); cursor: pointer; }
table.tt.gate-mode td.tt-cell:not([data-gate]) { opacity: .55; }
.rchip.gate-chip { cursor: pointer; align-items: flex-start; padding: 5px 9px; font: inherit; font-size: 13px; }
.rchip.gate-chip small { font-size: 11px; color: var(--ink-3); }
.gate-chip.on { outline: 3px solid #1F9D55; outline-offset: 1px; }
.tt-cell .gate-lbl { color: var(--good); font-weight: 700; }
.gcell .gc-btn.gc-extra { border-color: var(--bad); color: var(--bad); }
.gcell.busy.teach { background: #C5CEE0; }
.gcell.busy.teach .gc-why { color: #1F2A44; font-weight: 600; }
/* บันทึกการใช้งาน (user/audit) */
.audit-filter { flex-wrap: wrap; gap: 8px; }
.audit-filter input[type="date"] { width: auto; }
table.audit-table td.audit-detail { word-break: break-word; min-width: 280px; }
table.audit-table tr.audit-fail td { background: var(--bad-soft); }
