/* kkw.css — ระบบสารสนเทศบุคลากร โรงเรียนขอนแก่นวิทยายน
   ใช้ร่วมกันทั้ง 3 ระบบ (บุคลากร / ฝ่ายบุคคล / ตรวจการเข้าสอน)
   สีจากโลโก้โรงเรียน: ฟ้า ชมพู เหลือง และน้ำเงินเข้มจากคบเพลิง */

:root {
  --sky: #0b78b8;
  --sky-dark: #095f92;
  --sky-bright: #2bb5e5;
  --sky-tint: #e4f4fb;
  --pink: #e8559a;
  --pink-dark: #b0336a;
  --pink-tint: #fde9f1;
  --gold: #f2b300;
  --gold-text: #7a5200;
  --gold-strong: #8a5a00;
  --gold-tint: #fff5d9;
  --navy: #1b2559;

  --ok: #16875a;
  --ok-text: #11693f;
  --ok-tint: #e3f5ec;
  --bad: #cc2e3a;
  --bad-text: #b3202c;
  --bad-tint: #fdecee;
  --bad-border: #f0b3ba;

  --ink: #28304a;
  --muted: #616a80;
  --muted-2: #4d566b;
  --faint: #8a92a6;
  --line: #e2e5ee;
  --line-soft: #eef0f5;
  --field: #cfd5e3;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;

  --font-body: 'Sarabun', 'Leelawadee UI', Tahoma, sans-serif;
  --font-head: 'IBM Plex Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
}

/* ---------- พื้นฐาน ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.5; }
img { max-width: 100%; }
a { color: var(--sky); text-decoration: none; font-weight: 600; }
a:hover { color: var(--sky-dark); }
h1, h2, h3, .h { margin: 0; font-family: var(--font-head); font-weight: 600; line-height: 1.3; color: var(--navy); }
p { margin: 0; }
svg { display: block; flex-shrink: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sky-bright); outline-offset: 2px; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-xs { display: flex; flex-direction: column; gap: 2px; }
.center { align-items: center; text-align: center; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 20px; align-items: start; }
@media (max-width: 900px) {
  .grid-cols, .grid-side { grid-template-columns: 1fr; }
}

.stripe { display: flex; height: 4px; }
.stripe span { flex: 1; }
.stripe span:nth-child(1) { background: var(--sky-bright); }
.stripe span:nth-child(2) { background: var(--pink); }
.stripe span:nth-child(3) { background: var(--gold); }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1.5px solid transparent; font-size: 16px; font-weight: 700; line-height: 1.2; text-align: center; cursor: pointer; white-space: nowrap; transition: background-color .15s, border-color .15s, color .15s; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--sky); color: #fff; }
.btn-primary:hover { background: var(--sky-dark); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--field); color: var(--navy); font-weight: 600; }
.btn-secondary:hover { background: #fafbfd; border-color: #aeb6c9; color: var(--navy); }
.btn-danger { background: #fff; border-color: var(--bad-border); color: var(--bad-text); font-weight: 600; }
.btn-danger:hover { background: var(--bad-tint); color: var(--bad-text); }
.btn-bad { background: var(--bad); color: #fff; }
.btn-bad:hover { background: #ad2430; color: #fff; }
.btn-ghost { background: transparent; color: var(--muted-2); font-weight: 600; }
.btn-ghost:hover { background: var(--surface-2); color: var(--navy); }
.btn-lg { min-height: 60px; padding: 0 24px; border-radius: 16px; font-size: 18px; }
.btn-sm { min-height: 40px; padding: 0 14px; border-radius: 10px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { width: 44px; height: 44px; border: none; border-radius: 50%; background: var(--surface-2); color: var(--muted-2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: #e6e9f1; color: var(--navy); }
.link-btn { border: none; background: none; padding: 4px 0; color: var(--sky); font-size: 15px; font-weight: 600; cursor: pointer; }
.link-btn:hover { color: var(--sky-dark); }
.link-danger { border: none; background: none; padding: 2px 0; color: var(--bad-text); font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted-2); font-weight: 600; }
.back-link:hover { color: var(--navy); }

/* ---------- ป้ายสถานะ ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.b-ok { background: var(--ok-tint); color: var(--ok-text); }
.b-leave { background: var(--gold-tint); color: var(--gold-text); }
.b-absent { background: var(--bad-tint); color: var(--bad-text); }
.b-none { background: #eef0f5; color: var(--muted-2); }
.b-info { background: var(--sky-tint); color: #0a5a8a; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--ok); }
.dot-leave { background: var(--gold); }
.dot-bad { background: var(--bad); }
.dot-none { background: var(--faint); }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.card-pad { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 24px; border-bottom: 1px solid var(--line-soft); }
.card-head h2 { font-size: 18px; }
.card-body { padding: 20px 24px 24px; }
@media (max-width: 600px) {
  .card-pad { padding: 20px 16px; }
  .card-head { padding: 16px; }
  .card-body { padding: 16px; }
}

/* ---------- ฟอร์ม ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 15px; font-weight: 600; color: var(--navy); }
.opt-text { font-weight: 400; color: var(--muted); }
.input, .select, .textarea { width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 14px; border: 1.5px solid var(--field); background: #fff; font-size: 16px; color: var(--ink); }
.textarea { min-height: 96px; line-height: 1.5; resize: vertical; }
.select { appearance: none; -webkit-appearance: none; padding-right: 44px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23616a80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 9l7 7 7-7'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 4px var(--sky-tint); }
.input[readonly] { background: var(--surface-2); color: var(--muted-2); }
.input[type="file"] { padding: 10px 12px; }
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 46px; }
.hint { font-size: 14px; color: var(--muted); line-height: 1.45; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-section { display: flex; flex-direction: column; gap: 16px; }
.form-section + .form-section { padding-top: 24px; border-top: 1px solid var(--line-soft); }
.form-section h2 { font-size: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .form-actions .btn { flex: 1; }
}

/* ---------- ข้อความแจ้งเตือน ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: 12px; font-size: 15px; line-height: 1.45; }
.alert > svg { margin-top: 1px; }
.alert-success { background: var(--ok-tint); color: var(--ok-text); }
.alert-error { background: var(--bad-tint); color: var(--bad-text); }
.alert-warn { background: var(--gold-tint); color: var(--gold-text); }
.alert-info { background: var(--sky-tint); color: #0a5a8a; }

/* ---------- ตัวเลขสรุป ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.stat-soft { background: var(--bg); border-color: transparent; }
.stat-label { font-size: 14px; color: var(--muted); }
.stat-value { font-family: var(--font-head); font-size: 26px; font-weight: 600; line-height: 1.3; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 15px; font-weight: 500; color: var(--muted); }
.v-ok { color: var(--ok); }
.v-leave { color: var(--gold-strong); }
.v-bad { color: var(--bad-text); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; text-align: center; color: var(--muted); }
.empty > svg { color: #b8bfd0; }
.empty strong { font-family: var(--font-head); font-size: 17px; font-weight: 600; color: var(--navy); }

/* ================= ระบบบุคลากร ================= */
.topbar { position: sticky; top: 0; z-index: 30; background: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 10px 40px; }
.topbar-left { display: flex; align-items: center; gap: 36px; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; font-weight: inherit; }
.brand:hover { color: inherit; }
.brand img { width: 46px; height: 46px; }
.brand-name { display: block; font-family: var(--font-head); font-size: 17px; font-weight: 600; line-height: 1.25; color: var(--navy); }
.brand-sub { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav a { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; color: var(--muted-2); font-weight: 600; }
.topnav a:hover { background: var(--surface-2); color: var(--navy); }
.topnav a.active { background: var(--sky-tint); color: var(--sky); font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--pink-tint); color: var(--pink-dark); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { display: block; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--navy); }
.user-sub { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }
.vline { width: 1px; height: 32px; background: var(--line); }
.bottomnav { display: none; }
.mobile-only { display: none !important; }

.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 36px 40px 48px; display: flex; flex-direction: column; gap: 24px; }
.page-mid { max-width: 820px; }
.page-narrow { max-width: 600px; }
.greeting h1 { font-size: 30px; }
.greeting p { font-size: 17px; color: var(--muted); }
.page-title h1 { font-size: 28px; }
.page-title p { color: var(--muted); }
.title-lg { font-size: 28px; }
.title-md { font-size: 22px; }
@media (max-width: 767px) {
  .title-lg { font-size: 24px; }
}
.site-foot { padding: 8px 16px 32px; text-align: center; font-size: 13px; color: var(--faint); }

@media (max-width: 767px) {
  .topbar-inner { min-height: 64px; padding: 10px 16px; }
  .brand img { width: 42px; height: 42px; }
  .topnav, .topbar-user { display: none; }
  .mobile-only { display: flex !important; }
  .desktop-only { display: none !important; }
  .bottomnav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(68px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 14px; font-weight: 500; }
  .bottomnav a.active { color: var(--sky); font-weight: 700; }
  body.has-bottomnav { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .page { padding: 20px 16px 24px; gap: 20px; }
  .greeting h1, .page-title h1 { font-size: 24px; }
  .greeting p { font-size: 16px; }
}

/* การ์ดสถานะวันนี้ */
.home-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; gap: 20px; }
}
.today { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 36px 32px; text-align: center; }
.today-time { font-family: var(--font-head); font-size: 56px; font-weight: 600; line-height: 1.1; color: var(--navy); font-variant-numeric: tabular-nums; }
.today-title { font-family: var(--font-head); font-size: 32px; font-weight: 600; line-height: 1.25; color: var(--navy); }
.today-icon { width: 88px; height: 88px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.today-actions { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.today-actions form { display: block; }
.today-foot { width: 100%; padding-top: 16px; border-top: 1px solid var(--line-soft); font-size: 15px; color: var(--muted); }
.ic-ok { background: var(--ok-tint); color: var(--ok); }
.ic-leave { background: var(--gold-tint); color: var(--gold-strong); }
.ic-bad { background: var(--bad-tint); color: var(--bad-text); }
.ic-none { background: var(--surface-2); color: var(--faint); }
@media (max-width: 767px) {
  .today { padding: 24px 20px; gap: 18px; }
  .today-title { font-size: 24px; }
  .today-icon { width: 72px; height: 72px; }
}

/* รายการวัน (ประวัติ) */
.day-list { display: flex; flex-direction: column; }
.day-row { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-top: 1px solid var(--line-soft); }
.day-row:first-child { border-top: none; }
.day-num { width: 60px; display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.day-num b { font-family: var(--font-head); font-size: 22px; font-weight: 600; line-height: 1.15; color: var(--navy); }
.day-num span { font-size: 13px; color: var(--muted); }
.day-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.day-main strong { font-size: 16px; color: var(--navy); }
.day-main span { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.round-ico { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.compact-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 72px; align-items: center; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--line-soft); }
.compact-row .when { font-weight: 600; color: var(--navy); }
.compact-row .time { text-align: right; color: var(--muted-2); }

.month-nav { display: flex; align-items: center; justify-content: space-between; min-height: 56px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.month-nav a, .month-nav .disabled { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 12px; color: var(--navy); }
.month-nav a:hover { background: var(--surface-2); }
.month-nav .disabled { color: #c3c9d8; }
.month-nav strong { font-family: var(--font-head); font-size: 18px; font-weight: 600; color: var(--navy); }

/* โปรไฟล์ */
.profile-head { display: flex; align-items: center; gap: 20px; }
.profile-photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: var(--pink-tint); box-shadow: 0 0 0 1px var(--line); flex-shrink: 0; }
.profile-head h1 { font-size: 24px; }
@media (max-width: 600px) {
  .profile-head { flex-direction: column; text-align: center; gap: 12px; }
}
.link-row { display: flex; align-items: center; gap: 14px; min-height: 60px; padding: 12px 20px; border-top: 1px solid var(--line-soft); color: var(--navy); font-weight: 600; }
.link-row:first-child { border-top: none; }
.link-row:hover { background: var(--bg); color: var(--navy); }
.link-row .grow { flex: 1; }
.link-row .chev { color: var(--faint); }
.link-row small { display: block; font-size: 14px; font-weight: 400; color: var(--muted); }

/* หน้าต่างแจ้งลา (มือถือเป็นแผ่นเลื่อนขึ้นจากด้านล่าง) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(27, 37, 89, .45); }
.sheet { width: 100%; max-width: 520px; max-height: calc(100vh - 48px); overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 24px; background: #fff; border-radius: 24px; }
.sheet-handle { display: none; width: 40px; height: 4px; margin: 0 auto; border-radius: 2px; background: var(--field); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-size: 22px; }
@media (max-width: 767px) {
  .sheet-backdrop { align-items: flex-end; padding: 0; }
  .sheet { max-width: none; max-height: 92vh; padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; }
  .sheet-handle { display: block; }
}
.options { display: flex; flex-direction: column; gap: 8px; }
.option { position: relative; display: block; cursor: pointer; }
.option input { position: absolute; left: 16px; top: 50%; width: 1px; height: 1px; opacity: 0; }
.option-box { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; font-size: 17px; color: var(--ink); }
.option:hover .option-box { border-color: #b8c3d6; }
.option-radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #b8bfd0; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.option-radio svg { opacity: 0; }
.option input:checked + .option-box { border: 2px solid var(--sky); padding: 7.5px 15.5px; background: var(--sky-tint); color: var(--navy); font-weight: 600; }
.option input:checked + .option-box .option-radio { background: var(--sky); border-color: var(--sky); }
.option input:checked + .option-box .option-radio svg { opacity: 1; }
.option input:focus-visible + .option-box { outline: 3px solid var(--sky-bright); outline-offset: 2px; }
.more-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px; padding: 8px 16px; border: none; border-radius: 14px; background: var(--bg); text-align: left; cursor: pointer; }
.more-toggle strong { display: block; font-size: 16px; line-height: 1.3; color: var(--navy); }
.more-toggle small { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }
.more-toggle svg { color: var(--muted-2); transition: transform .15s; }
.more-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

/* ================= หน้าเข้าสู่ระบบ ================= */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 600px) minmax(0, 1fr); }
.login-brand { display: flex; flex-direction: column; justify-content: space-between; gap: 32px; padding: 48px; background: var(--navy); color: #fff; }
.login-brand > .stripe { width: 132px; height: 6px; border-radius: 3px; overflow: hidden; }
.login-hero { display: flex; flex-direction: column; align-items: center; gap: 28px; text-align: center; }
.login-hero img { width: 210px; height: 210px; }
.login-hero h1 { font-size: 34px; color: #fff; }
.login-hero p { font-size: 19px; color: #c9d0e8; }
.login-copy { font-size: 14px; color: #9aa3c7; }
.login-stripe-m { display: none; }
.login-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; }
.login-box { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 24px; }
.login-box h1 { font-size: 32px; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: #e9ecf3; }
.seg a { min-height: 48px; padding: 4px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--muted-2); font-weight: 600; line-height: 1.25; text-align: center; }
.seg a:hover { color: var(--navy); }
.seg a.active { background: #fff; color: var(--sky); font-weight: 700; box-shadow: 0 1px 3px rgba(27, 37, 89, .12); }
.login-foot-m { display: none; }
@media (max-width: 900px) {
  .login { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .login-brand { align-items: center; gap: 12px; padding: 32px 24px 26px; }
  .login-brand > .stripe, .login-brand .login-copy { display: none; }
  .login-stripe-m { display: flex; }
  .login-hero { gap: 12px; }
  .login-hero img { width: 104px; height: 104px; }
  .login-hero h1 { font-size: 22px; }
  .login-hero p { font-size: 15px; }
  .login-main { justify-content: flex-start; padding: 28px 20px 24px; }
  .login-box h1 { font-size: 26px; }
  .login-foot-m { display: block; padding: 0 20px 28px; text-align: center; font-size: 13px; color: var(--faint); }
}

/* ================= หลังบ้าน (ฝ่ายบุคคล / ตรวจการสอน) ================= */
.shell { min-height: 100vh; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; justify-content: space-between; overflow-y: auto; background: #fff; border-right: 1px solid var(--line); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: inherit; font-weight: inherit; }
.side-brand:hover { color: inherit; }
.side-brand img { width: 44px; height: 44px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; }
.side-nav a { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: 12px; color: var(--muted-2); font-weight: 600; line-height: 1.3; }
.side-nav a:hover { background: var(--surface-2); color: var(--navy); }
.side-nav a.active { background: var(--sky-tint); color: var(--sky); font-weight: 700; }
.side-section { padding: 16px 14px 4px; font-size: 13px; font-weight: 600; color: var(--faint); }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--line-soft); }
.icon-square { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); color: var(--muted-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-square:hover { background: var(--surface-2); color: var(--navy); }
.main { min-width: 0; display: flex; flex-direction: column; }
.main-inner { width: 100%; max-width: 1180px; padding: 28px 40px 56px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; }
.page-head p { font-size: 16px; color: var(--muted); }
.mobilebar { display: none; }
.shell-backdrop { display: none; }
@media (max-width: 991px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; width: 280px; height: auto; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(27, 37, 89, .25); }
  .shell.nav-open .shell-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(27, 37, 89, .4); }
  .mobilebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; z-index: 40; min-height: 64px; padding: 8px 12px 8px 16px; background: #fff; border-bottom: 1px solid var(--line); }
  .mobilebar .brand img { width: 38px; height: 38px; }
  .main-inner { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 24px; }
}

/* เลือกวันที่ */
.date-nav { display: inline-flex; align-items: center; gap: 2px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.date-nav > a, .date-nav > .disabled { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--navy); }
.date-nav > a:hover { background: var(--surface-2); }
.date-nav > .disabled { color: #c3c9d8; }
.date-pick { position: relative; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; border-radius: 10px; color: var(--navy); font-weight: 600; cursor: pointer; white-space: nowrap; }
.date-pick:hover { background: var(--surface-2); }
.date-pick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .input-icon { flex: 1 1 320px; max-width: 400px; }
.toolbar > .select { flex: 0 1 280px; }
.filter-bar { display: flex; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 8px; }

/* กล่องตัวเลขที่กดเพื่อกรอง */
.stat-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-tab { display: flex; flex-direction: column; gap: 2px; padding: 14px 18px; background: #fff; border: 1px solid var(--line); border-radius: 16px; color: inherit; font-weight: inherit; }
.stat-tab:hover { border-color: #b8c3d6; color: inherit; }
.stat-tab.active { border-color: var(--sky); box-shadow: inset 0 0 0 1px var(--sky); }
.stat-tab .stat-label { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--muted-2); }
.stat-tab .stat-value { font-size: 30px; }
@media (max-width: 900px) {
  .stat-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-tab { padding: 12px 14px; }
  .stat-tab .stat-value { font-size: 24px; }
}

/* ตาราง */
.table-card { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
/* position: relative ทำให้ข้อความที่ซ่อนไว้ (.sr-only) ในตารางไม่ดันความกว้างของทั้งหน้าบนมือถือ */
.table-scroll { position: relative; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th { padding: 12px 20px; background: var(--bg); border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; font-weight: 600; color: var(--muted-2); white-space: nowrap; }
.table td { padding: 12px 20px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table .group td { padding: 10px 20px; background: #fbfcfe; }
.table .group strong { margin-right: 12px; font-family: var(--font-head); font-size: 16px; font-weight: 600; color: var(--navy); }
.table .group span { font-size: 14px; color: var(--muted); }
.table .t-right { text-align: right; }
.table .muted-cell { color: var(--faint); }
.cell-name strong { display: block; font-weight: 600; line-height: 1.35; color: var(--navy); }
.cell-name span { display: block; font-size: 13px; line-height: 1.3; color: var(--muted); }
.num { font-weight: 600; color: var(--navy); font-variant-numeric: tabular-nums; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.actions form { display: inline-flex; }
.today-mark { margin-left: 8px; }

/* ปุ่มเลือก (ห้อง / ระดับชั้น) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-width: 72px; min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 12px; background: #fff; border: 1.5px solid var(--line); font-size: 16px; font-weight: 600; color: var(--ink); }
.chip:hover { border-color: #b8c3d6; color: var(--navy); }
.chip.active { background: var(--sky); border-color: var(--sky); color: #fff; font-weight: 700; }
.chip .dot { background: var(--bad); }
.chip.active .dot { background: #fff; }

/* การ์ดคาบเรียน */
.period-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
@media (max-width: 1180px) {
  .period-grid { grid-template-columns: 1fr; }
}
.pcard { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.pcard.is-absent { padding: 13.5px 15.5px; background: #fffafa; border: 1.5px solid var(--bad-border); }
.pcard.is-empty { padding: 13.5px 15.5px; background: transparent; border: 1.5px dashed #d5dae6; }
.prow { display: flex; align-items: center; gap: 16px; }
.pnum { width: 56px; height: 56px; border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; }
.pnum span { font-size: 12px; line-height: 1.2; color: var(--muted); }
.pnum b { font-family: var(--font-head); font-size: 22px; font-weight: 600; line-height: 1.1; color: var(--navy); }
.is-absent .pnum { background: var(--bad-tint); }
.is-absent .pnum span, .is-absent .pnum b { color: var(--bad-text); }
.is-empty .pnum { background: transparent; }
.is-empty .pnum span, .is-empty .pnum b { color: var(--faint); }
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pinfo strong { font-size: 17px; line-height: 1.3; color: var(--navy); }
.pinfo span { font-size: 15px; line-height: 1.35; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggle { width: 212px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); flex-shrink: 0; }
.toggle button { min-height: 44px; border: none; border-radius: 9px; background: transparent; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; }
.toggle button:hover { color: var(--navy); }
.toggle .on-ok { background: #fff; color: var(--ok-text); font-weight: 700; box-shadow: 0 1px 2px rgba(27, 37, 89, .14); }
.toggle .on-ok:hover { color: var(--ok-text); }
.toggle .on-absent { background: var(--bad); color: #fff; font-weight: 700; }
.toggle .on-absent:hover { color: #fff; }
@media (max-width: 560px) {
  .prow { flex-wrap: wrap; }
  .toggle { width: 100%; }
}
.reason { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 10px; background: var(--bad-tint); color: #8f1d27; font-size: 15px; }
.reason span { overflow-wrap: anywhere; }
.reason-form { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.reason-form .row { justify-content: flex-end; }

/* ตารางสอนรายห้อง */
.matrix { width: 100%; min-width: 960px; border-collapse: separate; border-spacing: 6px; }
.matrix th { padding: 6px; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted-2); }
.matrix td { height: 96px; vertical-align: top; }
.matrix .day { width: 92px; border-radius: 12px; background: var(--navy); color: #fff; text-align: center; vertical-align: middle; font-family: var(--font-head); font-weight: 600; }
.mcell { height: 100%; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; padding: 10px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.mcell strong { font-size: 15px; color: var(--navy); }
.mcell span { font-size: 13px; line-height: 1.3; color: var(--muted); }
.mcell .link-danger { align-self: flex-end; }
.mcell-empty { height: 100%; min-height: 92px; border-radius: 12px; border: 1.5px dashed #dfe3ec; }

/* จัดตารางสอน */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.room-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 16px; }
.slot { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 8px; }
.slot .select, .slot .input { min-height: 44px; padding: 8px 12px; border-radius: 10px; font-size: 15px; }
.slot .select { padding-right: 36px; background-position: right 10px center; }

@media print {
  .sidebar, .mobilebar, .topbar, .bottomnav, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
