/* =====================================================================
   ระบบตารางเรียน ตารางสอน — โรงเรียนเสาไห้ "วิมลวิทยานุกูล"
   ยึดมาตรฐาน THAI-WEB-UXUI-STANDARD (Kanit + Prompt, line-height ≥ 1.6, ปุ่มนูน Soft 3D, ปุ่มแตะ ≥ 44px)
   โทนสีตามตราโรงเรียน: ขาว · เขียว · เหลือง
   ===================================================================== */
:root {
  --bg: #f5f9f2;
  --surface: #ffffff;
  --surface-2: #f3f8ef;
  --surface-3: #e9f3e4;
  --border: #dde8d7;
  --border-strong: #c6d8bd;
  --text: #1b2a1c;
  --text-2: #3d5140;
  --muted: #637565;

  --green-900: #1e4a1b;
  --green-800: #265d22;
  --green-700: #2f7129;
  --green-600: #3b8a33;
  --green-500: #55a847;
  --green-200: #cfe8c8;
  --green-100: #e5f3e0;
  --green-50: #f2faef;

  --yellow-500: #f5d000;
  --yellow-400: #ffe11a;
  --yellow-200: #fff1a1;
  --yellow-100: #fff8d1;
  --yellow-50: #fffceb;
  --amber-800: #7a5b00;
  --amber-700: #8f6b00;

  --red-600: #c93b3b;
  --red-100: #fde6e6;
  --red-50: #fff4f4;
  --blue-700: #1f5f8b;
  --blue-50: #eef6fc;

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 1px 2px rgba(25, 60, 20, 0.06), 0 10px 28px -16px rgba(25, 70, 20, 0.28);
  --shadow-pop: 0 18px 48px -14px rgba(20, 50, 16, 0.35), 0 2px 6px rgba(20, 50, 16, 0.08);
  --font-head: 'Kanit', 'Prompt', 'Leelawadee UI', 'Tahoma', sans-serif;
  --font-body: 'Prompt', 'Sarabun', 'Leelawadee UI', 'Tahoma', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--text);
  background:
    radial-gradient(1200px 380px at 50% -140px, rgba(85, 168, 71, 0.16), transparent 70%),
    linear-gradient(180deg, #ffffff 0, var(--bg) 420px);
  background-color: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
h1, h2, h3, h4, .head { font-family: var(--font-head); line-height: 1.45; margin: 0; color: var(--green-900); }
h1 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); font-weight: 700; }
h2 { font-size: clamp(1.25rem, 2.4vw, 1.5rem); font-weight: 600; }
h3 { font-size: 1.08rem; font-weight: 600; }
p { margin: 0 0 0.6em; }
a { color: var(--green-700); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--green-900); }
small, .small { font-size: 0.86rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--yellow-400); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--yellow-200); }

/* ───────────────────────── Header ───────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; flex: 1 1 280px; }
.brand img { width: 46px; height: 56px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 3px rgba(30, 70, 20, 0.2)); }
.brand-title { font-family: var(--font-head); font-weight: 600; font-size: 1.12rem; color: var(--green-900); line-height: 1.35; }
.brand-sub { font-size: 0.84rem; color: var(--muted); line-height: 1.4; }
.header-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stripe { height: 5px; background: linear-gradient(90deg, var(--green-600) 0 58%, var(--yellow-400) 58% 78%, var(--green-500) 78% 100%); }

.term-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
  padding: 4px 10px 4px 14px; border-radius: 999px;
  background: var(--yellow-100); border: 1px solid var(--yellow-200); color: var(--amber-800);
  font-weight: 500;
}
.term-chip select {
  border: none; background: transparent; font: inherit; color: inherit; font-weight: 600;
  min-height: 36px; padding: 0 22px 0 4px; cursor: pointer; max-width: 230px;
}
.term-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green-500); box-shadow: 0 0 0 3px rgba(85, 168, 71, 0.2); }
.term-chip.is-draft .dot { background: #9aa39b; box-shadow: 0 0 0 3px rgba(150, 150, 150, 0.2); }

.user-pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 6px 4px 12px;
  border-radius: 999px; background: var(--green-50); border: 1px solid var(--green-200);
}
.user-pill .who { line-height: 1.25; }
.user-pill .who b { display: block; font-weight: 600; font-size: 0.92rem; color: var(--green-900); }
.user-pill .who span { font-size: 0.78rem; color: var(--muted); }

/* ───────────────────────── Navigation ───────────────────────── */
.nav-wrap { background: var(--surface); border-bottom: 1px solid var(--border); }
.nav {
  max-width: 1240px; margin: 0 auto; padding: 8px 12px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; align-items: center;
}
.nav-group-label {
  font-size: 0.74rem; color: var(--muted); padding: 0 4px 0 10px; white-space: nowrap;
  border-left: 1px solid var(--border); margin-left: 4px;
}
.nav-group-label:first-child { border-left: none; margin-left: 0; padding-left: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
  min-height: 42px; padding: 6px 14px; border-radius: 999px; color: var(--text-2); font-weight: 500; font-size: 0.93rem;
  border: 1px solid transparent; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav a:hover { background: var(--green-50); color: var(--green-800); }
.nav a.active { background: var(--green-600); color: #fff; border-color: rgba(255, 255, 255, 0.3); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 10px -4px rgba(47, 113, 41, 0.6); }

/* ───────────────────────── Layout ───────────────────────── */
main.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 22px 16px 40px; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .lead { color: var(--muted); margin: 4px 0 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); padding: 20px;
}
.card.tight { padding: 14px 16px; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-title .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; background: var(--green-100); flex: none; }
.card-title .ic.y { background: var(--yellow-100); }
.card.accent { border-top: 4px solid var(--green-500); }
.card.warn { border-color: var(--yellow-200); background: linear-gradient(180deg, var(--yellow-50), #fff); }

/* Hero หน้าแรก */
.hero {
  position: relative; border-radius: 26px; padding: 30px 26px 26px;
  background:
    radial-gradient(300px 260px at 94% 6%, rgba(255, 225, 26, 0.5), rgba(255, 225, 26, 0) 70%),
    linear-gradient(135deg, var(--green-700) 0%, var(--green-600) 55%, #4a9b3d 100%);
  color: #fff; box-shadow: var(--shadow-pop);
}
.hero h1 { color: #fff; }
.hero p { color: rgba(255, 255, 255, 0.92); max-width: 720px; }
.hero .search-big { margin-top: 16px; position: relative; max-width: 720px; z-index: 1; }
.hero .search-big input {
  width: 100%; min-height: 58px; border-radius: 16px; border: 2px solid rgba(255, 255, 255, 0.7);
  padding: 10px 18px 10px 52px; font: inherit; font-size: 1.05rem; color: var(--text);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.35);
}
.hero .search-big .ic { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); font-size: 1.2rem; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: #fff; color: var(--text);
  border-radius: 16px; box-shadow: var(--shadow-pop); border: 1px solid var(--border); max-height: 360px; overflow: auto; z-index: 5;
}
.search-results a { display: flex; gap: 10px; align-items: center; padding: 10px 16px; text-decoration: none; color: inherit; min-height: 48px; }
.search-results a:hover, .search-results a.on { background: var(--green-50); }
.search-results .grp { font-size: 0.78rem; color: var(--muted); padding: 8px 16px 2px; }

.choice-grid { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 14px; margin-top: 18px; }
.choice {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px;
  box-shadow: var(--shadow-card); transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.choice:hover { transform: translateY(-2px); border-color: var(--green-200); box-shadow: var(--shadow-pop); }
.choice .big { font-size: 1.9rem; line-height: 1; }
.choice b { font-family: var(--font-head); font-weight: 600; font-size: 1.12rem; color: var(--green-900); }
.choice span { color: var(--muted); font-size: 0.9rem; }
.choice.main { background: linear-gradient(180deg, var(--yellow-50), #fff 70%); border-color: var(--yellow-200); }

/* ───────────────────────── Buttons ───────────────────────── */
.btn {
  --b1: #ffffff; --b2: #f2f6ef; --bc: var(--border-strong); --bt: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px; cursor: pointer;
  font: inherit; font-weight: 500; font-size: 0.95rem; line-height: 1.3; text-decoration: none; white-space: nowrap;
  color: var(--bt); background: linear-gradient(180deg, var(--b1), var(--b2)); border: 1px solid var(--bc);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 1px 2px rgba(20, 50, 16, 0.08);
  transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.12s, filter 0.12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 6px 14px -6px rgba(20, 50, 16, 0.3); }
.btn:active { transform: translateY(1px) scale(0.985); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12); }
.btn[disabled], .btn.is-busy { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.is-busy::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
.btn-primary { --b1: #5fb351; --b2: #3b8a33; --bc: rgba(255, 255, 255, 0.25); --bt: #fff; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.4), 0 4px 12px -2px rgba(59, 138, 51, 0.45); }
.btn-primary:hover { box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.5), 0 8px 20px -4px rgba(59, 138, 51, 0.55); }
.btn-yellow { --b1: #fff06a; --b2: #ffd900; --bc: #e6c300; --bt: #4a3a00; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.7), 0 4px 12px -3px rgba(214, 180, 0, 0.55); }
.btn-danger { --b1: #fff; --b2: #fff1f1; --bc: #f0b9b9; --bt: var(--red-600); }
.btn-danger.solid { --b1: #e05555; --b2: #c93b3b; --bc: rgba(255, 255, 255, 0.2); --bt: #fff; }
.btn-ghost { --b1: transparent; --b2: transparent; --bc: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--green-50); }
.btn-sm { min-height: 36px; padding: 5px 11px; font-size: 0.86rem; border-radius: 10px; }
.btn-icon { min-width: 44px; padding: 0 10px; }
.btn-block { width: 100%; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────── Forms ───────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-weight: 500; font-size: 0.9rem; color: var(--text-2); }
.field .hint { font-size: 0.8rem; color: var(--muted); }
.input, .select, textarea.input {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: #fff; font: inherit; color: var(--text); line-height: 1.5;
  box-shadow: inset 0 1px 2px rgba(20, 50, 16, 0.06);
}
.select { padding-right: 32px; }
textarea.input { min-height: 110px; resize: vertical; }
.input:focus, .select:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(85, 168, 71, 0.2); }
.input[readonly], .select[disabled], .input[disabled] { background: var(--surface-2); color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green-600); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { flex: 1 1 200px; }
.toolbar .field.grow { flex: 3 1 280px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; font: inherit; min-height: 40px; padding: 4px 14px; border-radius: 10px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button.on { background: #fff; color: var(--green-800); box-shadow: 0 1px 3px rgba(20, 50, 16, 0.15); }

/* Picker (ช่องค้นหา + รายการให้เลือก) */
.picker { position: relative; }
.picker-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow: auto;
  background: #fff; border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-pop);
}
.picker-item { padding: 9px 12px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; min-height: 42px; }
.picker-item:hover, .picker-item.on { background: var(--green-50); }
.picker-item.disabled { color: #a3aea4; cursor: not-allowed; background: none; }
.picker-item small { color: var(--muted); margin-left: auto; white-space: nowrap; }
.picker-empty { padding: 12px; color: var(--muted); }
.picker-chosen { font-size: 0.82rem; color: var(--green-700); min-height: 1.2em; }

/* ───────────────────────── Chips / badges ───────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.82rem; line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; text-decoration: none;
}
a.chip:hover, button.chip:hover { border-color: var(--green-500); color: var(--green-800); }
button.chip { cursor: pointer; font: inherit; font-size: 0.86rem; min-height: 38px; padding: 4px 14px; }
.chip.on { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.chip.g { background: var(--green-100); border-color: var(--green-200); color: var(--green-800); }
.chip.y { background: var(--yellow-100); border-color: var(--yellow-200); color: var(--amber-800); }
.chip.r { background: var(--red-100); border-color: #f4c2c2; color: var(--red-600); }
.chip.b { background: var(--blue-50); border-color: #cfe3f3; color: var(--blue-700); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.class-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.class-chips a {
  min-width: 64px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 6px 12px;
  border-radius: 12px; background: #fff; border: 1px solid var(--border-strong); text-decoration: none; color: var(--green-900);
  font-weight: 500; box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(20, 50, 16, 0.07);
}
.class-chips a:hover { background: var(--yellow-100); border-color: var(--yellow-500); }

/* ───────────────────────── Tables ───────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th {
  position: sticky; top: 0; background: var(--green-50); color: var(--green-900); text-align: left; font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; font-family: var(--font-head); font-size: 0.9rem;
}
.table td { padding: 9px 12px; border-bottom: 1px solid #edf2ea; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fbfdf9; }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions .btn { margin-left: 4px; }
.table td.c, .table th.c { text-align: center; }
.list-count { font-size: 0.86rem; color: var(--muted); margin: 6px 2px; }

/* ───────────────────────── Timetable ───────────────────────── */
.tt-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tt-head .facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.tt-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow-card); }
table.tt { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 980px; table-layout: fixed; }
table.tt th, table.tt td { border-right: 1px solid #e8efe4; border-bottom: 1px solid #e8efe4; }
table.tt thead th {
  background: var(--green-50); padding: 8px 4px; font-family: var(--font-head); font-weight: 600; color: var(--green-900);
  text-align: center; font-size: 0.92rem; line-height: 1.3; position: sticky; top: 0; z-index: 2;
}
table.tt thead th .t { display: block; font-family: var(--font-body); font-weight: 400; font-size: 0.72rem; color: var(--muted); }
table.tt thead th .n { display: block; font-family: var(--font-body); font-weight: 500; font-size: 0.68rem; color: var(--amber-700); }
table.tt th.day {
  width: 86px; position: sticky; left: 0; z-index: 1; background: #fff; font-family: var(--font-head); font-weight: 600;
  color: var(--green-900); text-align: center; font-size: 0.95rem;
}
table.tt thead th.day { z-index: 3; background: var(--green-100); }
table.tt tr.today th.day { background: var(--yellow-200); }
table.tt tr.today td { background: var(--yellow-50); }
table.tt td { height: 86px; padding: 4px; vertical-align: top; position: relative; }
table.tt td.now { box-shadow: inset 0 0 0 3px var(--yellow-500); }
table.tt td.drop-ok { background: var(--green-100) !important; box-shadow: inset 0 0 0 2px var(--green-500); }
table.tt td.move-target { cursor: copy; }
table.tt td.move-target:hover { background: var(--green-50); box-shadow: inset 0 0 0 2px var(--green-500); }
.slot {
  position: relative; border-radius: 10px; padding: 5px 7px; font-size: 0.8rem; line-height: 1.4; min-height: 74px;
  background: linear-gradient(180deg, #f7fcf5, #eef7ea); border: 1px solid var(--green-200); color: var(--text);
  display: flex; flex-direction: column; gap: 1px; overflow: hidden;
}
.slot + .slot { margin-top: 4px; }
td > .slot:only-child { height: 100%; }
.slot.clash { min-height: 0; }
.slot .code { font-weight: 600; color: var(--green-900); font-size: 0.82rem; }
.slot .name { color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.35; }
.slot .meta { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; }
.slot .meta a, .slot .meta span {
  font-size: 0.72rem; padding: 0 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.85); border: 1px solid var(--border);
  color: var(--green-800); text-decoration: none; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.slot .meta a:hover { background: var(--yellow-100); border-color: var(--yellow-500); }
.slot.lock { background: linear-gradient(180deg, #f6f7f8, #eceff1); border-color: #d3d9dd; }
.slot.activity { background: linear-gradient(180deg, #fbf8ff, #f1ecfb); border-color: #ddd3f1; }
.slot.lunch, .cell-lunch { background: repeating-linear-gradient(135deg, var(--yellow-50), var(--yellow-50) 8px, var(--yellow-100) 8px, var(--yellow-100) 16px); border: 1px dashed var(--yellow-500); color: var(--amber-800); align-items: center; justify-content: center; text-align: center; font-weight: 500; }
.cell-lunch { border-radius: 10px; height: 100%; min-height: 74px; display: flex; font-size: 0.8rem; }
.slot.clash { border: 2px solid var(--red-600); background: var(--red-50); }
.slot .clash-tag { position: absolute; top: 3px; right: 4px; font-size: 0.66rem; background: var(--red-600); color: #fff; border-radius: 6px; padding: 0 5px; }
.slot.editable { cursor: grab; }
.slot.editable:hover { border-color: var(--green-500); box-shadow: 0 4px 12px -6px rgba(47, 113, 41, 0.5); }
.slot.dragging { opacity: 0.45; }
.slot .tools { display: none; position: absolute; right: 3px; bottom: 3px; gap: 3px; }
.slot.editable:hover .tools, .slot.editable:focus-within .tools, .touch .slot.editable .tools { display: flex; }
.slot .tools button {
  border: 1px solid var(--border-strong); background: #fff; border-radius: 8px; min-width: 30px; min-height: 30px; cursor: pointer;
  font-size: 0.82rem; line-height: 1; padding: 0 5px;
}
.slot .tools button:hover { background: var(--yellow-100); }
.cell-add {
  width: 100%; height: 100%; min-height: 74px; border: 1.5px dashed transparent; border-radius: 10px; background: transparent;
  color: var(--green-600); font-size: 1.3rem; cursor: pointer; opacity: 0; transition: opacity 0.15s, border-color 0.15s, background 0.15s;
}
td:hover > .cell-add, .cell-add:focus-visible, .touch .cell-add { opacity: 1; border-color: var(--green-200); }
.cell-add:hover { background: var(--green-50); border-color: var(--green-500); }
.cell-empty { color: #c3cdc0; text-align: center; padding-top: 26px; font-size: 0.85rem; }
.move-banner {
  position: sticky; top: 74px; z-index: 15; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--yellow-100); border: 1px solid var(--yellow-500); color: var(--amber-800); border-radius: 14px;
  padding: 10px 14px; margin-bottom: 12px; box-shadow: var(--shadow-card); font-weight: 500;
}
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--border); }

/* มุมมองรายวัน (มือถือ) */
.daylist { display: none; }
.day-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.day-tabs button { flex: 1 0 auto; min-height: 44px; border-radius: 12px; border: 1px solid var(--border); background: #fff; font: inherit; font-weight: 500; padding: 4px 14px; cursor: pointer; }
.day-tabs button.on { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.day-tabs button.today:not(.on) { background: var(--yellow-100); border-color: var(--yellow-500); }
.day-panel { display: none; }
.day-panel.on { display: block; }
.day-item { display: grid; grid-template-columns: 74px 1fr; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #edf2ea; background: #fff; }
.day-item:first-child { border-radius: 14px 14px 0 0; }
.day-item:last-child { border-bottom: none; border-radius: 0 0 14px 14px; }
.day-item .p { font-family: var(--font-head); font-weight: 600; color: var(--green-800); line-height: 1.3; }
.day-item .p small { display: block; font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: 0.74rem; }
.day-item.now { background: var(--yellow-50); box-shadow: inset 4px 0 0 var(--yellow-500); }
.day-item .s b { color: var(--green-900); font-weight: 600; }
.day-item .s .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.day-list-box { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }

/* ───────────────────────── Stats / empty / misc ───────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow-card); }
.stat b { display: block; font-family: var(--font-head); font-size: 1.7rem; font-weight: 600; color: var(--green-800); line-height: 1.25; }
.stat span { color: var(--muted); font-size: 0.86rem; }
.stat.y b { color: var(--amber-700); }
.stat.r b { color: var(--red-600); }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 2.4rem; }
.empty b { display: block; color: var(--text); font-family: var(--font-head); font-weight: 600; font-size: 1.08rem; margin: 6px 0 2px; }
.empty .btn { margin-top: 12px; }
.note {
  border-radius: 14px; padding: 12px 14px; background: var(--blue-50); border: 1px solid #cfe3f3; color: #1d4d70; font-size: 0.92rem;
}
.note.y { background: var(--yellow-50); border-color: var(--yellow-200); color: var(--amber-800); }
.note.g { background: var(--green-50); border-color: var(--green-200); color: var(--green-900); }
.note.r { background: var(--red-50); border-color: #f4c2c2; color: #8a2a2a; }
.steps { counter-reset: st; display: grid; gap: 10px; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: st; position: relative; padding: 10px 12px 10px 52px; background: #fff; border: 1px solid var(--border); border-radius: 14px; }
.steps li::before {
  content: counter(st); position: absolute; left: 12px; top: 10px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--yellow-400); color: #4a3a00; font-family: var(--font-head); font-weight: 600; display: grid; place-items: center;
}
.kbd { font-family: var(--font-body); background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; font-size: 0.85em; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green-500), var(--yellow-400)); }
.conf-item { border: 1px solid var(--border); border-left: 4px solid var(--red-600); border-radius: 12px; padding: 10px 12px; background: #fff; }
.conf-item.soft { border-left-color: var(--yellow-500); }
.conf-item + .conf-item { margin-top: 8px; }
.conf-list { max-height: 60vh; overflow: auto; }
.skeleton { background: linear-gradient(90deg, #eef4ea 25%, #f8fbf6 50%, #eef4ea 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading-screen { display: grid; place-items: center; min-height: 50vh; text-align: center; color: var(--muted); }
.loading-screen .ring { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--green-100); border-top-color: var(--green-600); animation: spin 0.9s linear infinite; margin: 0 auto 12px; }

.status-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 14px; margin-bottom: 14px;
  background: var(--yellow-50); border: 1px solid var(--yellow-200); color: var(--amber-800); font-size: 0.92rem;
}
.status-bar.g { background: var(--green-50); border-color: var(--green-200); color: var(--green-900); }

/* ───────────────────────── Modal ───────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(18, 36, 16, 0.45); display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 12px 12px; overflow-y: auto; animation: fadeIn 0.15s ease-out;
}
.modal {
  width: 100%; max-width: 560px; background: #fff; border-radius: 22px; box-shadow: var(--shadow-pop); border: 1px solid var(--border);
  animation: popIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2); margin-bottom: 5vh;
}
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 10px; border-bottom: 1px solid #edf2ea; }
.modal-head h3 { flex: 1; font-size: 1.14rem; }
.modal-head .x { border: none; background: var(--surface-2); width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 1.1rem; }
.modal-body { padding: 16px 20px; }
.modal-body .msg { white-space: pre-line; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.modal .ic-big { font-size: 2.2rem; line-height: 1; margin-bottom: 6px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* ───────────────────────── Toast ───────────────────────── */
.toasts { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: #fff; border: 1px solid var(--border);
  box-shadow: var(--shadow-pop); animation: popIn 0.2s ease-out; font-size: 0.93rem; border-left: 5px solid var(--green-500);
}
.toast.err { border-left-color: var(--red-600); }
.toast.warn { border-left-color: var(--yellow-500); }

/* ───────────────────────── Footer ───────────────────────── */
.app-footer { margin-top: auto; background: #fff; border-top: 1px solid var(--border); }
.app-footer .stripe { height: 4px; }
.footer-inner { max-width: 1240px; margin: 0 auto; padding: 18px 16px 22px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.footer-inner img { width: 38px; height: 46px; object-fit: contain; }
.footer-text { flex: 1 1 320px; font-size: 0.86rem; color: var(--muted); line-height: 1.7; }
.footer-text b { color: var(--green-900); font-weight: 600; }
.footer-links { display: flex; gap: 8px; flex-wrap: wrap; }

/* ───────────────────────── Print (A4 แนวนอน) ───────────────────────── */
.print-area { display: grid; gap: 18px; }
.sheet {
  background: #fff; width: 100%; max-width: 1123px; aspect-ratio: 297 / 210; margin: 0 auto; padding: 22px 26px;
  box-shadow: var(--shadow-card); border: 1px solid var(--border); border-radius: 6px; display: flex; flex-direction: column; overflow: hidden;
}
.sheet-head { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid var(--green-600); padding-bottom: 8px; margin-bottom: 8px; }
.sheet-head img { width: 44px; height: 54px; object-fit: contain; }
.sheet-head .t1 { font-family: var(--font-head); font-weight: 600; font-size: 15px; color: #123; line-height: 1.35; }
.sheet-head .t2 { font-size: 11px; color: #444; }
.sheet-head .right { margin-left: auto; text-align: right; font-size: 10px; color: #555; }
.sheet-title { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; margin-bottom: 6px; background: var(--yellow-50); border: 1px solid var(--yellow-200); padding: 4px 10px; border-radius: 6px; }
.sheet-title b { font-family: var(--font-head); font-weight: 600; }
table.ps { width: 100%; border-collapse: collapse; table-layout: fixed; flex: 1; }
table.ps th, table.ps td { border: 1px solid #7d8a7a; text-align: center; vertical-align: middle; padding: 2px; font-size: 9.5px; line-height: 1.3; }
table.ps thead th { background: #e5f3e0; font-weight: 600; font-size: 10px; }
table.ps thead th span { display: block; font-weight: 400; font-size: 8px; color: #333; }
table.ps th.d { width: 58px; background: #f2faef; font-family: var(--font-head); font-size: 11px; }
table.ps td .c { font-weight: 600; font-size: 10px; display: block; }
table.ps td .m { font-size: 8.5px; color: #333; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.ps td.l { background: #fff8d1; color: #6b5200; font-size: 9px; }
.sheet-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; font-size: 10.5px; text-align: center; }
.sheet-sign .pos { font-size: 9.5px; color: #444; }

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff !important; font-size: 12px; }
  .app-header, .nav-wrap, .app-footer, .no-print, .toasts, .modal-backdrop { display: none !important; }
  main.container { padding: 0; max-width: none; }
  .print-area { display: block; }
  .sheet { box-shadow: none; border: none; border-radius: 0; width: 100%; max-width: none; aspect-ratio: auto; height: 190mm; padding: 0; page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .print-substitute .table-wrap { border: none; }
}

/* ───────────────────────── Responsive ───────────────────────── */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-grid { grid-template-columns: 1fr 1fr; }
  .choice.main { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .choice-grid { grid-template-columns: 1fr; }
  .brand img { width: 38px; height: 46px; }
  .brand-title { font-size: 1rem; }
  .header-tools { width: 100%; justify-content: space-between; }
  .term-chip select { max-width: 170px; }
  .hero { padding: 22px 18px; border-radius: 20px; }
  .card { padding: 16px; border-radius: 18px; }
  .tt-wrap.has-daylist { display: none; }
  .daylist { display: block; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 22px 22px 0 0; margin-bottom: 0; max-height: 94vh; overflow-y: auto; }
  .toasts { left: 16px; right: 16px; }
  .move-banner { top: 110px; }
  .table .actions { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* พิมพ์เฉพาะส่วน (เช่น ใบสอนแทน) */
.print-only { display: none; }
@media print {
  .print-only { display: block !important; }
  body.printing-partial main.container > *:not(.print-only) { display: none !important; }
}

/* กันเนื้อหาดันหน้าจอกว้างเกิน (ลิงก์ยาว/คำที่ตัดไม่ได้) — ห้ามมีแถบเลื่อนแนวนอนทั้งหน้า */
body > * { min-width: 0; max-width: 100%; }
p, li, .note, .status-bar { overflow-wrap: break-word; }

.grid-users { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid-users { grid-template-columns: minmax(0, 1fr); } }
@media screen and (max-width: 720px) { .print-area { overflow-x: auto; } .sheet { width: 920px; max-width: none; } }

/* ครูที่ปรึกษา: รายชื่อแบบติ๊กเลือกหลายท่าน (แทน dropdown ที่ถูกตัดบนมือถือ) */
.hr-list { max-height: min(52vh, 420px); overflow-y: auto; border: 1px solid var(--border); border-radius: 14px; background: #fff; margin-top: 6px; overscroll-behavior: contain; }
.hr-row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; min-height: 54px; border-bottom: 1px solid #edf2ea; cursor: pointer; }
.hr-row:last-child { border-bottom: none; }
.hr-row:hover { background: var(--green-50); }
.hr-row input { width: 22px; height: 22px; flex: none; accent-color: var(--green-600); }
.hr-row span { display: flex; flex-direction: column; line-height: 1.4; min-width: 0; }
.hr-row small { color: var(--muted); font-size: 0.8rem; }
.hr-row.on { background: var(--green-100); }
.hr-row.dis { opacity: 0.45; cursor: not-allowed; }
.hr-chip { padding-right: 4px; }
.chip-x { border: none; background: rgba(255, 255, 255, 0.8); border-radius: 50%; width: 32px; height: 32px; margin-left: 4px; cursor: pointer; font-size: 0.85rem; color: var(--red-600); flex: none; }
.chip-x:hover { background: var(--red-100); }

/* ช่องค้นหาแบบเลือกได้ในหน้าต่าง: บนมือถือให้รายการแทรกในหน้าต่าง (ไม่ลอยจนถูกขอบหน้าต่างตัด) */
@media (max-width: 720px) {
  .modal .picker-list { position: static; max-height: 45vh; margin-top: 4px; box-shadow: none; }
}
@media (max-width: 720px) {
  /* ปุ่มบันทึกของหน้าต่างมองเห็นเสมอ แม้รายการยาว */
  .modal-foot { position: sticky; bottom: 0; background: #fff; border-top: 1px solid #edf2ea; border-radius: 0 0 22px 22px; z-index: 2; }
  .hr-list { max-height: 42vh; }
}
/* ปุ่มของหน้าต่างติดขอบล่างเสมอ (จอโน้ตบุ๊กเตี้ยก็กดบันทึกได้โดยไม่ต้องเลื่อนหา) */
.modal-foot { position: sticky; bottom: 0; background: #fff; border-radius: 0 0 22px 22px; z-index: 2; }
.hr-list { max-height: min(40vh, 380px); }
