/*
 * หน้าตาระบบโรงเรียนกวดวิชาถึงแก่น
 * แนวคิด: วงปีของต้นไม้ (ถึงแก่น = ถึงแก่นไม้) พื้นครีม แถบเมนูสีเลือดหมู
 * เปลี่ยนสีทั้งระบบได้ที่ตัวแปรใน :root ด้านล่าง
 */

:root {
    /* โทนครีม + เลือดหมู: พื้นครีมอุ่น แถบเมนูสีเลือดหมู ทองเป็นสีเน้น */
    --paper: #F5EEE1;
    --surface: #FFFCF6;
    --surface-2: #FAF4E8;
    --hover: #F4EBDC;
    --track: #EBDFCC;
    --ink: #2A1C1B;
    --ink-soft: #6F5D57;
    --line: #E9DDCA;
    --line-strong: #D8C7AD;
    --heartwood: #7B2433;
    --heartwood-dark: #5E1A27;
    --sage: #D2A9A0;
    --sage-light: #E9CFA3;
    --sprout: #E2ECD9;
    --blush: #F6E5DF;
    --success-ink: #3B6544;
    --petal: #B8432F;
    --petal-soft: #F7E1D9;
    --danger-ink: #962F1F;
    --sun: #C9A35C;
    --sun-soft: #F6EBD3;
    --warn-ink: #6E5420;
    --warn-strong: #B48A35;
    --sky-soft: #E3E9EE;
    --sky: #4F6E86;
    --on-dark: #FBF1E7;
    --on-dark-soft: #E3C3BC;

    --font-display: 'Bai Jamjuree', 'Noto Sans Thai Looped', system-ui, sans-serif;
    --font-body: 'Noto Sans Thai Looped', system-ui, -apple-system, 'Segoe UI', sans-serif;

    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 24px;
    --sidebar: 256px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 500;
    line-height: 1.3;
    margin: 0;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }

a { color: var(--heartwood); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--heartwood-dark); }

:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 4px; }

/* ---------- โครงหน้าหลัก ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
    background: var(--heartwood-dark);
    color: var(--on-dark);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand-name { font-family: var(--font-display); font-size: 1.05rem; line-height: 1.2; }
.brand-name small { display: block; font-family: var(--font-body); font-size: .72rem; opacity: .75; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; align-items: center; gap: 10px;
    color: var(--on-dark-soft); text-decoration: none;
    padding: 9px 12px; border-radius: var(--radius-sm);
    font-size: .95rem;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.is-active { background: var(--surface); color: var(--heartwood-dark); font-weight: 600; }
.nav-group { font-size: .78rem; color: var(--sage-light); margin: 18px 12px 6px; }
.nav .badge-count { margin-left: auto; background: var(--sun); color: var(--ink); border-radius: 99px; font-size: .75rem; padding: 0 8px; font-weight: 600; }

.sidebar-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: .88rem; }
.sidebar-foot .who { color: #fff; }
.sidebar-foot form { margin-top: 8px; }
.sidebar-foot button { background: none; border: 0; color: var(--on-dark-soft); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.main { padding: 28px 36px 64px; min-width: 0; }
.main-inner { max-width: 1120px; }

.topbar-mobile { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--ink-soft); margin: 4px 0 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: .88rem; margin-bottom: 4px; display: inline-block; }

/* ---------- กล่องและส่วนต่างๆ ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head p { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush .panel-head { padding: 18px 22px 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-2 > .panel, .grid-3 > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 20px; }

/* ตัวเลขสรุปบนหน้าแรก */
.tally { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.tally > div { padding: 18px 22px; border-left: 1px solid var(--line); }
.tally > div:first-child { border-left: 0; }
.tally-3 { grid-template-columns: repeat(3, 1fr); }
.tally .num { font-family: var(--font-body); font-weight: 600; font-size: 1.9rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tally .lbl { color: var(--ink-soft); font-size: .9rem; }
.tally .num.is-money { color: var(--petal); }
.tally a { color: inherit; text-decoration: none; display: block; }
.tally a:hover .lbl { text-decoration: underline; }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.list th {
    text-align: left; font-weight: 600; color: var(--ink-soft); font-size: .85rem;
    padding: 10px 14px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--surface-2);
}
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: var(--hover); }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.list td.nowrap { white-space: nowrap; }
table.list .sub { display: block; color: var(--ink-soft); font-size: .85rem; }
table.list tr.is-muted td { color: var(--ink-soft); }
table.list tr.is-muted td s { text-decoration-color: var(--line-strong); }
.code { font-variant-numeric: tabular-nums; letter-spacing: .02em; font-weight: 600; }

.empty { text-align: center; padding: 36px 20px; color: var(--ink-soft); }
.empty p { margin-bottom: 12px; }

/* ---------- ป้ายสถานะ ---------- */
.chip { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .82rem; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.chip-success { background: var(--sprout); color: var(--success-ink); }
.chip-warning { background: var(--sun-soft); color: var(--warn-ink); border-color: #E5D3A8; }
.chip-danger { background: var(--petal-soft); color: var(--danger-ink); }
.chip-info { background: var(--sky-soft); color: var(--sky); }
.chip-muted { background: var(--track); color: var(--ink-soft); }

/* ---------- ปุ่ม ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-size: .95rem; font-weight: 500;
    padding: 8px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
    text-decoration: none; cursor: pointer; white-space: nowrap; line-height: 1.4;
}
.btn:hover { background: var(--hover); color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--heartwood); border-color: var(--heartwood); color: #fff; }
.btn-primary:hover { background: var(--heartwood-dark); border-color: var(--heartwood-dark); color: #fff; }
.btn-danger { color: var(--danger-ink); border-color: #E0BDB5; }
.btn-danger:hover { background: var(--petal-soft); color: var(--danger-ink); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-link { border: 0; background: none; padding: 0; color: var(--heartwood); text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { background: none; color: var(--heartwood-dark); }
.btn-block { width: 100%; }
.inline-form { display: inline; }

/* ---------- ฟอร์ม ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid .span-2 { grid-column: span 2; }
.field label, .field .label { display: block; font-weight: 500; font-size: .92rem; margin-bottom: 5px; }
.field .hint { font-size: .84rem; color: var(--ink-soft); margin-top: 4px; }
.field .req { color: var(--petal); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=tel], input[type=search], input[type=url], select, textarea {
    width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
    padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--heartwood); box-shadow: 0 0 0 3px rgba(123,36,51,.16); }
textarea { min-height: 84px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-size: .95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--heartwood); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.is-invalid { border-color: var(--petal) !important; }
.field-error { color: var(--danger-ink); font-size: .85rem; margin-top: 4px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }

/* ---------- ข้อความแจ้ง ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; }
.flash-success { background: var(--sprout); border-color: #C4D3B4; color: var(--success-ink); }
.flash-error { background: var(--petal-soft); border-color: #E5C3BB; color: var(--danger-ink); }
.flash-info { background: var(--sky-soft); border-color: #C9D6DF; color: #3B5468; }

/* PIN ที่แสดงครั้งเดียว */
.reveal {
    display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
    background: var(--sun-soft); border: 1px dashed var(--warn-strong); border-radius: var(--radius);
    padding: 16px 20px; margin-bottom: 20px;
}
.reveal .pin { font-family: var(--font-body); font-weight: 600; font-size: 2rem; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.reveal p { margin: 0; }

/* ---------- รายละเอียด ---------- */
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
dl.facts dt { color: var(--ink-soft); font-size: .92rem; }
dl.facts dd { margin: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-strong); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--ink-soft); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.is-active { color: var(--heartwood-dark); border-bottom-color: var(--heartwood); font-weight: 600; }

/* แถบความจุกลุ่มเรียน */
.fill { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; margin-left: 8px; }
.fill > span { display: block; height: 100%; background: var(--heartwood); }

/* ---------- ปฏิทินสัปดาห์ ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: 8px; overflow-x: auto; }
.week .day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 160px; display: flex; flex-direction: column; }
.week .day-head { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.week .day-head strong { font-weight: 600; font-size: 1rem; }
.week .day.is-today { border-color: var(--heartwood); box-shadow: inset 0 3px 0 var(--heartwood); }
.week .slot { margin: 6px 6px 0; padding: 6px 8px; border-radius: var(--radius-sm); background: var(--blush); font-size: .82rem; line-height: 1.4; border-left: 3px solid var(--heartwood); }
.week .slot.c1 { background: var(--petal-soft); border-left-color: var(--petal); }
.week .slot.c2 { background: var(--sky-soft); border-left-color: var(--sky); }
.week .slot.c3 { background: var(--sun-soft); border-left-color: var(--warn-strong); }
.week .slot.is-cancelled { opacity: .55; text-decoration: line-through; }
.week .slot b { display: block; font-weight: 600; }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.auth {
    min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr;
    background: var(--paper);
}
.auth-art {
    background: var(--heartwood-dark); color: var(--on-dark); position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between; padding: 44px 48px;
}
.auth-art .rings { position: absolute; right: -180px; bottom: -180px; width: 620px; height: 620px; opacity: .45; }
.auth-art h1 { font-size: 2.6rem; color: #fff; position: relative; }
.auth-art .tagline { font-size: 1.1rem; max-width: 26ch; position: relative; color: var(--on-dark-soft); }
.auth-art .contact { position: relative; font-size: .92rem; color: var(--on-dark-soft); }
.auth-art .contact a { color: #fff; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 1.5rem; margin-bottom: 6px; }
.auth-card > p { color: var(--ink-soft); }
.role-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; margin: 20px 0 22px; background: var(--surface); }
.role-switch input { position: absolute; opacity: 0; pointer-events: none; }
.role-switch label { text-align: center; padding: 10px 6px; cursor: pointer; font-size: .92rem; border-left: 1px solid var(--line); line-height: 1.3; }
.role-switch label:first-of-type { border-left: 0; }
.role-switch label small { display: block; font-size: .75rem; color: var(--ink-soft); }
.role-switch input:checked + label { background: var(--heartwood); color: #fff; }
.role-switch input:checked + label small { color: var(--on-dark-soft); }
.role-switch input:focus-visible + label { outline: 3px solid var(--sun); outline-offset: -3px; }
.pin-input { font-size: 1.4rem !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.auth-card .field + .field { margin-top: 14px; }

/* ---------- หน้าธรรมดา (ติดตั้ง/ผิดพลาด) ---------- */
.plain { max-width: 560px; margin: 60px auto; padding: 0 20px; }
.plain .brand { color: var(--heartwood-dark); padding-left: 0; }

/* ---------- บัตรรหัส ---------- */
.card-sheet { max-width: 420px; margin: 32px auto; padding: 0 16px; }
.id-card { border: 2px solid var(--heartwood); border-radius: var(--radius-lg); padding: 22px 24px; background: var(--surface); position: relative; overflow: hidden; }
.id-card .rings { position: absolute; right: -70px; top: -70px; width: 200px; height: 200px; opacity: .14; }
.id-card .school { font-family: var(--font-display); color: var(--heartwood-dark); font-size: 1.05rem; }
.id-card .who { font-size: 1.25rem; font-weight: 600; margin: 14px 0 12px; }
.id-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.id-card dt { color: var(--ink-soft); }
.id-card dd { margin: 0; font-family: var(--font-body); font-weight: 600; font-size: 1.3rem; letter-spacing: .08em; }
.id-card .foot { margin-top: 14px; font-size: .85rem; color: var(--ink-soft); border-top: 1px dashed var(--line-strong); padding-top: 10px; }

/* ---------- มือถือ ---------- */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
    .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(40,16,20,.45); }
    .topbar-mobile {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        background: var(--heartwood-dark); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20;
    }
    .topbar-mobile .brand { padding: 0; }
    .topbar-mobile button { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: var(--radius-sm); padding: 6px 12px; font: inherit; }
    .main { padding: 20px 16px 48px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .tally { grid-template-columns: 1fr 1fr; }
    .tally > div:nth-child(3) { border-left: 0; }
    .tally > div:nth-child(n+3) { border-top: 1px solid var(--line); }
    .tally-3 { grid-template-columns: 1fr; }
    .tally-3 > div { border-left: 0 !important; border-top: 1px solid var(--line); padding: 14px 18px; }
    .tally-3 > div:first-child { border-top: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
    .auth { grid-template-columns: 1fr; }
    .auth-art { padding: 28px 24px; min-height: 220px; }
    .auth-art h1 { font-size: 1.9rem; }
    .auth-art .rings { width: 360px; height: 360px; right: -140px; bottom: -160px; }
    .auth-art .contact { display: none; }
    h1 { font-size: 1.35rem; }
    table.list th, table.list td { padding: 9px 10px; }
    .panel { padding: 16px; }
    .panel.flush .panel-head { padding: 16px 16px 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media print {
    .sidebar, .topbar-mobile, .no-print { display: none !important; }
    .shell { display: block; }
    body { background: var(--surface); }
    .card-sheet { margin: 0; }
}

/* ---------- หน้าสาธารณะ (สมัครเรียน) ---------- */
.public-bar { background: var(--heartwood-dark); color: #fff; }
.public-inner { max-width: 860px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
.public-bar .public-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.public-bar .brand { padding: 0; }
.public-login { color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: var(--radius-sm); padding: 6px 14px; text-decoration: none; white-space: nowrap; }
.public-login:hover { color: #fff; background: rgba(255,255,255,.1); }
.public-main { padding-top: 28px; padding-bottom: 40px; }
.public-foot { padding-bottom: 40px; color: var(--ink-soft); font-size: .92rem; }

.step-title { display: flex; align-items: baseline; gap: 10px; }
.step-title .n { font-family: var(--font-body); font-weight: 600; color: var(--heartwood); }

/* ตัวเลือกกลุ่มเรียน */
.choice-list { display: grid; gap: 10px; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .box { border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 14px 16px 14px 48px; background: var(--surface); display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; }
.choice .box::before { content: ''; position: absolute; left: 16px; top: 18px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); }
.choice input:checked + .box { border-color: var(--heartwood); box-shadow: 0 0 0 1px var(--heartwood); background: var(--surface-2); }
.choice input:checked + .box::before { border-color: var(--heartwood); background: radial-gradient(var(--heartwood) 45%, #fff 50%); }
.choice input:focus-visible + .box { outline: 3px solid var(--sun); outline-offset: 2px; }
.choice .name { font-weight: 600; }
.choice .price { font-weight: 600; white-space: nowrap; text-align: right; }
.choice .meta { color: var(--ink-soft); font-size: .9rem; grid-column: 1 / -1; }
.course-label { font-family: var(--font-display); font-size: 1.05rem; margin: 18px 0 8px; color: var(--heartwood-dark); }
.course-label:first-child { margin-top: 0; }

/* สรุปยอด */
.summary { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); padding: 14px 16px; }
.summary dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 0; }
.summary dt { color: var(--ink-soft); }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.summary .total { font-weight: 600; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }
.summary .deposit { color: var(--heartwood-dark); font-weight: 600; }
.code-msg { font-size: .88rem; margin-top: 4px; }
.code-msg.ok { color: var(--heartwood-dark); }
.code-msg.err { color: var(--danger-ink); }

.bank { display: flex; gap: 16px; align-items: center; border: 1px dashed var(--heartwood); border-radius: var(--radius); padding: 14px 18px; background: var(--sprout); margin-bottom: 16px; flex-wrap: wrap; }
.bank .acc { font-weight: 600; font-size: 1.3rem; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

input[type=file] { font: inherit; font-size: .95rem; width: 100%; padding: 8px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }
input[type=datetime-local] { width: 100%; font: inherit; font-size: 1rem; color: var(--ink); padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }

/* ---------- ใบเสร็จ ---------- */
.receipt-sheet { max-width: 760px; margin: 28px auto; padding: 0 16px; }
.receipt-tools { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.receipt { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 4px; padding: 32px 36px; position: relative; overflow: hidden; }
.receipt .small { font-size: .85rem; color: var(--ink-soft); }
.receipt table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.receipt th, .receipt td { line-height: 1.5; }
.rc-head { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: start; padding-bottom: 16px; border-bottom: 3px double var(--heartwood); }
.receipt-mark { width: 56px; height: 56px; }
.school-th { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; color: var(--heartwood); line-height: 1.3; }
.school-en { font-size: .9rem; margin-bottom: 2px; }
.rc-title { text-align: right; }
.rc-title .t { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; color: var(--heartwood); line-height: 1.2; }
.rc-info { margin: 16px 0; }
.rc-info th, .rc-info td { padding: 5px 0; vertical-align: baseline; text-align: left; }
.rc-info th { width: 7.5em; font-weight: 400; color: var(--ink-soft); white-space: nowrap; padding-right: 12px; }
.rc-info th:nth-child(3) { width: 5em; padding-left: 16px; }
.rc-info .rc-no { width: 10em; font-weight: 600; white-space: nowrap; }
.rc-items { border: 1px solid var(--ink); }
.rc-items .c-no { width: 3.6em; }
.rc-items .c-amt { width: 9.5em; }
.rc-items th { background: var(--surface-2); font-weight: 600; font-size: .9rem; padding: 7px 10px; border: 1px solid var(--ink); text-align: center; }
.rc-items td { padding: 9px 10px; border-left: 1px solid var(--ink); border-right: 1px solid var(--ink); vertical-align: top; }
.rc-items td.c { text-align: center; }
.rc-items td.n { text-align: right; white-space: nowrap; }
.rc-items .small { margin-top: 2px; }
.rc-items .rc-blank td { height: 56px; }
.rc-items tfoot td { border: 1px solid var(--ink); vertical-align: middle; padding: 9px 10px; }
.rc-words { background: var(--surface-2); }
.rc-words span { color: var(--ink-soft); font-size: .88rem; margin-right: 6px; }
.rc-total { font-weight: 700; font-size: 1.1rem; }
.rc-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 32px; margin-top: 22px; align-items: end; }
.rc-balance { max-width: 320px; font-size: .92rem; }
.rc-balance caption { text-align: left; font-weight: 600; padding-bottom: 4px; caption-side: top; }
.rc-balance th, .rc-balance td { padding: 3px 0; border-bottom: 1px dotted var(--line-strong); vertical-align: baseline; }
.rc-balance th { text-align: left; font-weight: 400; color: var(--ink-soft); }
.rc-balance td { text-align: right; white-space: nowrap; }
.rc-balance .strong th, .rc-balance .strong td { color: var(--ink); font-weight: 700; border-bottom: 0; }
.rc-sign { text-align: center; line-height: 1.6; }
.rc-line { border-bottom: 1px dotted var(--ink); height: 48px; margin: 0 12px 6px; }
.receipt.is-cancelled { background: var(--surface-2); }
.void-stamp { position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%) rotate(-14deg); border: 4px solid var(--petal); color: var(--petal); font-family: var(--font-display); font-size: 3.2rem; padding: 2px 28px; border-radius: 8px; opacity: .55; pointer-events: none; }
@media (max-width: 640px) {
    .receipt { padding: 20px 14px; }
    .rc-head { grid-template-columns: 44px 1fr; }
    .receipt-mark { width: 44px; height: 44px; }
    .rc-title { grid-column: 1 / -1; text-align: left; }
    .rc-info, .rc-info tbody { display: block; }
    .rc-info tr { display: grid; grid-template-columns: 7em minmax(0, 1fr); }
    .rc-info th, .rc-info th:nth-child(3), .rc-info .rc-no { width: auto; padding-left: 0; }
    .rc-items .c-no { width: 2.6em; }
    .rc-items .c-amt { width: 6.8em; }
    .rc-items th, .rc-items td, .rc-items tfoot td { padding-left: 6px; padding-right: 6px; }
    .rc-bottom { grid-template-columns: 1fr; }
    .rc-balance { max-width: none; }
}
@media print {
    @page { size: A4; margin: 12mm; }
    .receipt-sheet { margin: 0; max-width: none; padding: 0; }
    .receipt { border: 0; padding: 0; background: #fff !important; }
    body { background: #fff; }
    .flash { display: none; }
}

/* ---------- คาบเรียน ---------- */
.clock { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-left: 4px solid var(--heartwood); }
.clock p { margin: 4px 0 0; }
.btn-big { padding: 14px 28px; font-size: 1.1rem; border-radius: var(--radius); }

.roll { list-style: none; margin: 0; padding: 0; }
.roll li { display: grid; grid-template-columns: minmax(200px, 1.4fr) auto minmax(140px, 1fr); gap: 10px 16px; align-items: center; padding: 10px 22px; border-top: 1px solid var(--line); }
.roll li:first-child { border-top: 0; }
.roll .who { min-width: 0; }
.roll-note { padding: 7px 10px !important; font-size: .92rem !important; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; padding: 0; margin: 0; background: var(--surface); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 7px 14px; cursor: pointer; font-size: .95rem; border-left: 1px solid var(--line); user-select: none; min-width: 52px; text-align: center; }
.seg label:first-of-type { border-left: 0; }
.seg input:focus-visible + label { outline: 3px solid var(--sun); outline-offset: -3px; }
.seg input:checked + label { background: var(--heartwood); color: #fff; }
.seg input:checked + label.seg-late { background: var(--warn-strong); color: #fff; }
.seg input:checked + label.seg-absent { background: var(--petal); color: #fff; }
.seg input:checked + label.seg-leave { background: var(--sky); color: #fff; }
.seg-wide label { min-width: 110px; }

.files { list-style: none; margin: 0 0 16px; padding: 0; }
.files li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.files li a { font-weight: 500; }
.attach { border-top: 1px dashed var(--line-strong); padding-top: 16px; }

/* ตารางกรอกคะแนน */
.score-input { width: 90px !important; text-align: right; font-variant-numeric: tabular-nums; }
.score-bar { display: inline-block; height: 6px; border-radius: 99px; background: var(--heartwood); vertical-align: middle; margin-left: 8px; opacity: .75; }

@media (max-width: 900px) {
    .roll li { grid-template-columns: 1fr; padding: 12px 16px; }
    .seg { width: 100%; }
    .seg label { flex: 1; padding: 10px 4px; }
    .clock .btn-big, .clock form { width: 100%; }
}

/* หน้าแรกของครู */
.today-list { list-style: none; margin: 12px 0 0; padding: 0; }
.today-card { display: grid; grid-template-columns: 120px 1fr auto auto; gap: 12px 20px; align-items: center; padding: 16px 22px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.today-card:hover { background: var(--hover); color: inherit; }
.today-card .t { font-weight: 600; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.today-card .st { display: flex; gap: 6px; flex-wrap: wrap; }
.today-card .go { color: var(--heartwood); font-weight: 500; }
@media (max-width: 900px) {
    .today-card { grid-template-columns: 1fr; gap: 6px; padding: 14px 16px; }
}

table.list tr.is-selected td { background: var(--blush); }

/* ---------- หน้าผู้ปกครอง ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.meter { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--heartwood); border-radius: 99px; }

/* แถบผลการมาเรียนรายคาบ: สีบอกสถานะ มีคำอธิบายและตารางกำกับเสมอ */
.strip { display: flex; flex-wrap: wrap; gap: 3px; padding: 14px 22px 6px; }
.cell { display: inline-block; width: 14px; height: 22px; border-radius: 3px; background: var(--track); position: relative; }
.cell-present { background: var(--heartwood); }
.cell-late { background: var(--warn-strong); }
.cell-absent { background: var(--petal); }
.cell-leave { background: var(--sky); }
.cell-none { background: var(--track); box-shadow: inset 0 0 0 1px var(--line-strong); }
.strip-key { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 4px 22px 14px; font-size: .85rem; color: var(--ink-soft); }
.strip-key span { display: inline-flex; align-items: center; gap: 6px; }
.strip-key .cell { width: 10px; height: 14px; }

/* คะแนนเทียบค่าเฉลี่ยกลุ่ม */
.scorelist { list-style: none; margin: 0; padding: 0; }
.scorelist li { padding: 12px 0; border-top: 1px solid var(--line); }
.scorelist li:first-child { border-top: 0; padding-top: 0; }
.sl-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.sl-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { position: relative; height: 10px; background: var(--track); border-radius: 99px; margin: 8px 0 4px; }
.bar .fillbar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--heartwood); border-radius: 99px; }
.bar .avgmark { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; background: var(--ink); border-radius: 2px; box-shadow: 0 0 0 2px #fff; }
.avgmark-key { display: inline-block; width: 3px; height: 14px; background: var(--ink); vertical-align: middle; border-radius: 2px; margin-right: 4px; }

@media (max-width: 900px) {
    .strip, .strip-key { padding-left: 16px; padding-right: 16px; }
}

/* ---------- มือถือและแท็บเล็ต ---------- */
/* ให้ตารางกว้างเลื่อนในกล่องของตัวเอง ไม่ดันทั้งหน้าให้เลื่อนซ้ายขวา */
.shell { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.shell > div { min-width: 0; }
@media (max-width: 900px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
}
/* iPhone ซูมหน้าเองเมื่อกดช่องที่ตัวอักษรเล็กกว่า 16px */
input, select, textarea { font-size: 16px; }
.roll-note, input[type=file] { font-size: 16px !important; }
/* นิ้วกดง่าย: ปุ่มและลิงก์คำสั่งสูงอย่างน้อย 44px บนจอสัมผัส */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .btn-sm { min-height: 40px; padding: 6px 14px; }
    .btn-link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 6px; }
    .nav a { padding: 12px 12px; }
    .seg label { padding-top: 11px; padding-bottom: 11px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
}
@media (max-width: 900px) {
    /* ฟอร์มที่วางหลายช่องเรียงกัน ให้เรียงลงทีละช่องบนมือถือ */
    .form-grid[style] { grid-template-columns: 1fr !important; }
    .grid-2[style] { grid-template-columns: 1fr !important; }
}
/* ช่องเลือกในตารางไม่บีบจนอ่านไม่ออกบนจอแคบ ตารางเลื่อนซ้ายขวาในกล่องแทน */
table.list select { min-width: 150px; }
table.list input[type=time] { min-width: 120px; }
table.list input[type=text]:not(.score-input) { min-width: 140px; }
table.list input[type=number] { min-width: 90px; }

/* ---------- โทนเสจ: รายละเอียดเฉพาะของธีม ---------- */
h1 { font-size: 1.8rem; font-weight: 600; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-weight: 600; }

/* แถบเมนูเขียวป่าเข้ม เมนูที่เลือกเป็นแคปซูลสีนวล */
.sidebar { background: var(--heartwood-dark); color: var(--on-dark); }
.nav a { color: var(--on-dark-soft); border-radius: 999px; padding-left: 16px; }
.nav a:hover { background: rgba(251,241,231,.08); color: var(--on-dark); }
.nav a.is-active { background: var(--on-dark); color: var(--heartwood-dark); }
.nav-group { color: var(--sage); }
.nav .badge-count { background: var(--sun); color: var(--heartwood-dark); }
.brand-name { font-weight: 600; letter-spacing: .01em; }
.topbar-mobile, .public-bar { background: var(--heartwood-dark); }

/* ปุ่มแคปซูล */
.btn { border-radius: 999px; padding: 9px 20px; background: var(--surface); }
.btn-sm { padding: 5px 14px; }
.btn-primary { background: var(--heartwood); border-color: var(--heartwood); color: var(--on-dark); }
.btn-primary:hover { background: var(--heartwood-dark); border-color: var(--heartwood-dark); color: var(--on-dark); }
.btn-link { background: none; }
.public-login { border-radius: 999px; }

/* การ์ด */
.panel, .tally, .week .day, .receipt { background: var(--surface); }
.panel { border-color: var(--line); }
table.list th { background: var(--surface-2); }

/* แถบตัวเลขสรุป: แถบเขียวเข้ม ตัวเลขสีนวล เป็นจุดเด่นของหน้า */
.tally { background: var(--heartwood-dark); border: 0; color: var(--on-dark); }
.tally > div { border-left-color: rgba(251,241,231,.14) !important; border-top-color: rgba(251,241,231,.14) !important; }
.tally .num { color: var(--on-dark); font-weight: 500; letter-spacing: -.01em; }
.tally .lbl { color: var(--on-dark-soft); }
.tally .num.is-money { color: #F0D49A; }
.tally a:hover .lbl { color: var(--on-dark); }
.tally .meter { background: rgba(251,241,231,.16); }
.tally .meter > span { background: var(--sage-light); }

/* ป้ายสถานะ */
.chip-success { background: var(--sprout); color: var(--success-ink); }
.chip-muted { background: var(--track); }

/* หน้าเข้าสู่ระบบ */
.auth-art { background: var(--heartwood-dark); }
.auth-art h1 { font-size: 2.7rem; font-weight: 600; line-height: 1.25; color: var(--on-dark); }
.auth-art .tagline { color: var(--sage-light); }
.role-switch { border-radius: 999px; padding: 4px !important; gap: 4px; background: var(--surface); }
.role-switch label { border: 0 !important; border-radius: 999px; }
.role-switch input:checked + label { background: var(--heartwood); color: var(--on-dark); }

/* ตัวเลือกกลุ่มเรียน สรุปยอด และบัญชีธนาคาร */
.choice .box { background: var(--surface); }
.choice input:checked + .box { background: var(--surface-2); }
.bank { background: var(--surface-2); border-color: var(--sage); }
.summary { background: var(--surface-2); }

/* แถบความคืบหน้า */
.meter > span, .bar .fillbar, .fill > span { background: var(--heartwood); }
.cell-late { background: var(--warn-strong); }
.cell-absent { background: var(--petal); }
.seg input:checked + label { background: var(--heartwood); color: var(--on-dark); }
.seg input:checked + label.seg-late { background: var(--warn-strong); }
.seg input:checked + label.seg-absent { background: var(--petal); }

/* ใบเสร็จ */
.void-stamp { border-color: var(--petal); color: var(--petal); }

.brand-name small { font-size: .68rem; white-space: nowrap; font-weight: 400; }

/* แท็บเลือกวิชา (หน้าคะแนน/เอกสารของนักเรียน) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.pills a { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: 99px;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); text-decoration: none; font-weight: 500; }
.pills a span { font-size: .8rem; color: var(--ink-soft); background: var(--track); border-radius: 99px; padding: 0 7px; }
.pills a.is-active { background: var(--heartwood); border-color: var(--heartwood); color: #fff; }
.pills a.is-active span { background: rgba(255,255,255,.22); color: #fff; }
.link-danger, .link-danger:hover { color: var(--danger-ink); }
