/* แฟ้มแยกสี — แต่ละเมนูมีสีประจำของตัวเอง เหมือนแฟ้มเอกสารที่แยกสีตามหมวด
   --c = สีของหน้าที่เปิดอยู่ (JS ตั้งให้ที่ body) */
:root {
  --ink: #16142e;
  --muted: #5f5c78;
  --paper: #f7f6fc;
  --surface: #ffffff;
  --line: #e6e3f3;
  --c: #6c4cf1;
  --side: 272px;
  --display: "Prompt", "IBM Plex Sans Thai", system-ui, sans-serif;
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
/* สีย่อยคำนวณจาก --c ใหม่ทุกที่ที่เปลี่ยนสี */
:root, body, .nav a, .stat {
  --c-deep: color-mix(in srgb, var(--c) 58%, #14112b);
  --c-tint: color-mix(in srgb, var(--c) 12%, #ffffff);
  --c-soft: color-mix(in srgb, var(--c) 24%, #ffffff);
}
body { margin: 0; font-size: 16px; line-height: 1.65; }
a { color: var(--c-deep); text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.25; margin: 0 0 .4em; font-weight: 600; }
h2 { font-size: 1.3rem; margin-top: 2rem; }
h3 { font-size: 1.05rem; font-weight: 500; }
:focus-visible { outline: 3px solid var(--c); outline-offset: 2px; border-radius: 6px; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 12px auto 12px 12px; width: calc(var(--side) - 24px);
  background: var(--surface); border-radius: 24px; box-shadow: 0 1px 0 var(--line), 0 12px 32px -18px rgba(40, 30, 110, .35);
  display: flex; flex-direction: column; z-index: 30; transition: transform .25s ease;
}
.side-profile { display: flex; gap: 12px; align-items: center; padding: 22px 20px 18px; }
.side-name { font-family: var(--display); font-weight: 600; line-height: 1.3; }
.side-role { font-size: .85rem; color: var(--muted); }
.avatar {
  width: 46px; height: 46px; border-radius: 14px; flex: none; color: #fff;
  background: linear-gradient(135deg, #6c4cf1, #e8459b) center/cover no-repeat;
  display: grid; place-items: center; font-family: var(--display); font-weight: 600; font-size: 1.1rem;
}
.avatar.photo { background: center/cover no-repeat; }
.nav { display: flex; flex-direction: column; padding: 6px 12px; gap: 2px; overflow-y: auto; }
.nav a {
  color: var(--ink); text-decoration: none; padding: 10px 12px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px; font-weight: 500;
}
.nav a::before {
  content: ""; width: 10px; height: 22px; border-radius: 4px; background: var(--c); flex: none;
}
.nav a:hover { background: var(--paper); }
.nav a.active { background: var(--c-tint); color: var(--c-deep); font-weight: 600; }
.side-foot { margin-top: auto; padding: 16px 22px 20px; font-size: .8rem; color: var(--muted); }

/* ---------- Topbar (mobile) ---------- */
.topbar, .scrim { display: none; }

/* ---------- Main ---------- */
.main { margin-left: var(--side); padding: 12px clamp(16px, 3vw, 40px) 64px 12px; max-width: 1160px; outline: none; }
.loading, .empty { color: var(--muted); padding: 24px 0; }

/* หัวหน้าเพจ: แถบสีประจำหมวด + รูปทรงสี */
.band {
  position: relative; overflow: hidden; border-radius: 24px; background: var(--c-tint);
  padding: 36px 40px; margin-bottom: 28px; min-height: 148px;
  display: flex; flex-direction: column; justify-content: center;
}
.band::before, .band::after { content: ""; position: absolute; border-radius: 50%; pointer-events: none; z-index: 0; }
.band > * { position: relative; z-index: 1; }
.band::before { width: 220px; height: 220px; right: -40px; top: -70px; background: var(--c); }
.band::after { width: 120px; height: 120px; right: 150px; bottom: -60px; border: 18px solid var(--c-soft); }
.band h1 { position: relative; font-size: clamp(1.7rem, 3.4vw, 2.5rem); color: var(--c-deep); font-weight: 700; margin: 0; max-width: 70%; }
.band p { position: relative; margin: 6px 0 0; color: var(--ink); max-width: 64%; }
@media (prefers-reduced-motion: no-preference) {
  .band::before { animation: pop .5s cubic-bezier(.2, .9, .3, 1.3) both; }
  @keyframes pop { from { transform: scale(.6); opacity: 0; } }
}

/* Hero หน้าแรก */
.hero::after { right: 40%; bottom: -80px; }
.hero { padding: 36px 40px; display: grid; grid-template-columns: 168px 1fr; gap: 32px; align-items: center; min-height: 240px; }
.hero h1 { max-width: none; font-size: clamp(2rem, 4.2vw, 3rem); }
.hero-photo {
  position: relative; width: 168px; height: 168px; border-radius: 32px; color: #fff;
  background: linear-gradient(135deg, #6c4cf1 0%, #e8459b 60%, #f2a900 100%) center/cover no-repeat;
  display: grid; place-items: center; font-family: var(--display); font-size: 4rem; font-weight: 600;
  box-shadow: 0 16px 30px -16px rgba(60, 30, 160, .6); transform: rotate(-3deg);
}
.hero-photo.photo { background: center/cover no-repeat; }
.hero .who { position: relative; color: var(--ink); margin: 8px 0 14px; }
.chips { position: relative; display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-block; font-size: .8rem; padding: 3px 12px; border-radius: 999px;
  background: var(--t, var(--c-tint)); color: var(--tc, var(--c-deep)); font-weight: 500;
}
.tag.solid { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.meta { color: var(--muted); font-size: .92rem; }

.quote {
  margin: 0 0 28px; padding: 22px 26px 22px 72px; position: relative; background: var(--surface);
  border-radius: 20px; font-size: 1.05rem; box-shadow: inset 0 0 0 1px var(--line);
}
.quote::before {
  content: "“"; position: absolute; left: 22px; font-family: var(--display);
  font-size: 4.5rem; line-height: 1; color: #f2a900; top: 2px;
}
.quote b { display: block; font-family: var(--display); font-weight: 600; color: var(--muted); font-size: .9rem; }

/* ตัวเลขสรุป: แต่ละช่องใช้สีของหมวดที่ลิงก์ไป */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.stat {
  --c: var(--sc); background: var(--c-tint); border-radius: 20px; padding: 18px 20px 20px;
  text-decoration: none; color: var(--ink);
  position: relative; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease;
}
.stat::after { content: ""; position: absolute; right: -16px; top: -16px; width: 56px; height: 56px; border-radius: 50%; background: var(--c); }
.stat:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 2px var(--c); }
.stat b { display: block; font-family: var(--display); font-size: 2.4rem; font-weight: 700; color: var(--c-deep); line-height: 1.1; }
.stat span { position: relative; z-index: 1; color: var(--muted); font-size: .92rem; }

/* รายการ */
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--surface); border-radius: 20px; padding: 20px 22px; box-shadow: inset 0 0 0 1px var(--line); }
.item { display: flex; gap: 18px; align-items: center; border-left: 6px solid var(--c); border-radius: 8px 20px 20px 8px; }
.item-body { flex: 1; min-width: 0; }
.item-body h3 { margin-bottom: 2px; }
.item-side { text-align: right; flex: none; }
.hours {
  font-family: var(--display); font-weight: 700; color: var(--c-deep); background: var(--c-tint);
  border-radius: 14px; padding: 6px 14px; font-size: 1.15rem; white-space: nowrap;
}

/* ตัวกรอง */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters button {
  font: inherit; font-size: .92rem; border: 0; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
  padding: 6px 16px; border-radius: 999px; cursor: pointer; color: var(--ink);
}
.filters button:hover { box-shadow: inset 0 0 0 1px var(--c); }
.filters button.on { background: var(--c-deep); box-shadow: none; color: #fff; }
.filters + :not(.filters) { margin-top: 14px; }

/* เกียรติบัตร */
.cert { padding: 10px; display: flex; flex-direction: column; }
.cert-img {
  aspect-ratio: 4 / 3; border-radius: 14px; border: 0; padding: 0; width: 100%; cursor: default;
  background: repeating-linear-gradient(-45deg, var(--c-tint) 0 12px, #fff 12px 24px) center/cover no-repeat;
  display: grid; place-items: center; color: var(--c-deep); font: inherit; font-size: .9rem;
}
.cert-img.has-img { cursor: zoom-in; }
.cert-body { padding: 14px 10px 8px; }
.cert-body h3 { margin-top: 10px; }

/* ตารางสอน */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 20px; box-shadow: inset 0 0 0 1px var(--line); padding: 8px; }
table.sched { border-collapse: separate; border-spacing: 4px; width: 100%; min-width: 760px; font-size: .9rem; }
.sched th, .sched td { padding: 8px 6px; text-align: center; vertical-align: middle; border-radius: 10px; }
.sched thead th { font-family: var(--display); font-weight: 600; color: var(--c-deep); }
.sched thead small { display: block; font-family: "IBM Plex Sans Thai", sans-serif; font-weight: 400; color: var(--muted); font-size: .78rem; }
.sched tbody th { font-family: var(--display); font-weight: 500; text-align: left; padding-left: 12px; width: 96px; }
.sched td { background: var(--paper); height: 64px; }
.sched td.has { background: var(--c); color: #fff; }
.sched td.has b { display: block; font-family: var(--display); font-weight: 600; }

/* Lightbox */
.lightbox { border: 0; padding: 0; background: transparent; max-width: 92vw; max-height: 92vh; }
.lightbox::backdrop { background: rgba(22, 20, 46, .85); }
.lightbox img { max-width: 92vw; max-height: 80vh; display: block; border-radius: 12px; }
.lightbox p { color: #fff; text-align: center; margin: 10px 0 0; }
.lightbox-close { position: fixed; top: 12px; right: 18px; font-size: 2.2rem; color: #fff; background: none; border: 0; cursor: pointer; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20;
    background: rgba(247, 246, 252, .9); backdrop-filter: blur(10px); padding: 10px 16px;
    border-bottom: 1px solid var(--line);
  }
  .topbar-title { font-family: var(--display); font-weight: 600; color: var(--c-deep); }
  .menu-btn { background: none; border: 0; padding: 8px 4px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
  .menu-btn span { width: 22px; height: 2px; background: var(--ink); display: block; border-radius: 2px; }
  .sidebar { transform: translateX(calc(-100% - 24px)); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(22, 20, 46, .4); z-index: 25; }
  .main { margin-left: 0; padding: 12px 12px 48px; }
  .band { padding: 26px 22px; min-height: 120px; border-radius: 20px; }
  .band::before { width: 140px; height: 140px; right: -50px; top: -50px; }
  .band::after { display: none; }
  .band h1, .band p { max-width: 78%; }
  .hero { grid-template-columns: 1fr; text-align: left; gap: 20px; padding: 26px 22px; }
  .hero h1 { max-width: 100%; }
  .hero-photo { width: 112px; height: 112px; border-radius: 24px; font-size: 2.8rem; }
  .item { flex-direction: column; align-items: flex-start; gap: 6px; }
  .item-side { text-align: left; }
}

/* ===================== ส่วนเพิ่ม: โหมดครู / ผู้ประเมิน ===================== */
.nav-group { font-size: .78rem; color: var(--muted); padding: 14px 12px 4px; font-weight: 500; }
.nav a { padding: 8px 12px; }
.nav a::before { height: 18px; width: 8px; }
.side-foot { border-top: 1px solid var(--line); }
.mode-label { margin-bottom: 6px; }
.modes { display: flex; background: var(--paper); border-radius: 12px; padding: 4px; gap: 2px; }
.modes a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .82rem; padding: 6px 2px; border-radius: 9px; }
.modes a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(40, 30, 110, .15); }

.band { flex-direction: row; align-items: center; gap: 20px; }
.band-text { flex: 1; min-width: 0; position: relative; z-index: 1; }
.band-text h1, .band-text p { max-width: 100%; }
.band-actions { position: relative; z-index: 1; display: flex; gap: 8px; flex-wrap: wrap; margin-right: 120px; }
.hero { display: grid; }

.btn {
  font: inherit; font-weight: 600; font-size: .92rem; border: 0; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--c-deep); color: #fff; padding: 10px 18px; border-radius: 12px; display: inline-block;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--surface); color: var(--c-deep); box-shadow: inset 0 0 0 1.5px var(--c-soft); }

.notice { background: #fff8e6; color: #6b4b00; border-radius: 14px; padding: 10px 16px; font-size: .88rem; margin-bottom: 12px; }
.private-note { background: #fdecef; color: #8a1c3a; border-radius: 12px; padding: 10px 16px; font-size: .88rem; }

.vis { display: inline-block; font-size: .75rem; padding: 2px 10px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.v-public { background: #e2f7ee; color: #0b6b4c; }
.v-private { background: #eef0f3; color: #4b5563; }

/* ตารางข้อมูล */
table.data { border-collapse: collapse; width: 100%; font-size: .92rem; }
.data th { text-align: left; font-family: var(--display); font-weight: 600; color: var(--c-deep); padding: 10px 12px; border-bottom: 2px solid var(--c-soft); white-space: nowrap; }
.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: var(--paper); }
.num { text-align: center !important; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }
.warn { color: #c62828; font-weight: 700; }
.table-wrap + h2, .table-wrap + .meta, .grid + h2 { margin-top: 24px; }

/* แผงสองคอลัมน์ */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 20px 0 16px; }
.panel { background: var(--surface); border-radius: 20px; padding: 20px 22px; box-shadow: inset 0 0 0 1px var(--line); margin-bottom: 16px; }
.cols .panel { margin-bottom: 0; }
.panel h2 { margin-top: 0; font-size: 1.1rem; color: var(--c-deep); }
.stats + .cols { margin-top: 20px; }

.slot { display: grid; grid-template-columns: auto auto 1fr auto; gap: 12px; align-items: center; background: var(--c-tint); border-radius: 12px; padding: 10px 14px; }
.slot b { font-family: var(--display); color: var(--c-deep); }
.mini { font-size: .82rem; white-space: nowrap; }
.todo { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px dashed var(--line); cursor: pointer; }
.todo input { width: 18px; height: 18px; accent-color: var(--c); }
.todo.done span:first-of-type { text-decoration: line-through; color: var(--muted); }
.deadlines { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.deadline { background: var(--c-tint); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; }
.deadline b { font-family: var(--display); font-size: 1.3rem; color: var(--c-deep); }
.deadline.soon { background: #ffe9e6; }
.deadline.soon b { color: #c62828; }

/* บันทึกหลังสอน */
.note-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.note dl, .kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 16px; margin: 8px 0 0; }
.note dt, .kv dt { color: var(--muted); }
.note dd, .kv dd { margin: 0; }

/* เกรด */
.grade { display: inline-block; min-width: 38px; border-radius: 8px; padding: 2px 6px; font-weight: 700; background: var(--paper); }
.grade.g4, .grade.g35 { background: #dff6ec; color: #0b6b4c; }
.grade.g0, .grade.g1 { background: #ffe5e2; color: #c62828; }
.bars { display: flex; flex-direction: column; gap: 6px; max-width: 520px; }
.bar-row { display: grid; grid-template-columns: 36px 1fr 28px; gap: 10px; align-items: center; }
.bar-row span { font-family: var(--display); font-weight: 600; text-align: right; }
.bar { background: var(--paper); border-radius: 6px; height: 18px; overflow: hidden; }
.bar i, .meter i { display: block; height: 100%; background: var(--c); border-radius: inherit; }

/* เช็กชื่อ */
.att-btn { font: inherit; font-size: .85rem; border: 0; border-radius: 8px; padding: 4px 10px; cursor: pointer; min-width: 48px; background: var(--paper); }
.a-ok { background: #dff6ec; color: #0b6b4c; }
.a-late { background: #fff3d6; color: #7a5400; }
.a-leave { background: #e3effd; color: #1e5aa0; }
.a-miss { background: #ffe2df; color: #c62828; font-weight: 700; }

/* มาตรวัด */
.meter { background: var(--paper); border-radius: 999px; height: 10px; overflow: hidden; margin: 10px 0 6px; }
.meter.big { height: 14px; margin: 0 0 20px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

/* PA */
.pa-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; padding: 12px 14px; border-radius: 14px; background: var(--paper); }
.pa-row.has { background: var(--c-tint); }
.pa-row ul { margin: 4px 0 0; padding-left: 18px; font-size: .92rem; }
.pa-code { font-family: var(--display); font-weight: 700; background: var(--c-deep); color: #fff; border-radius: 10px; padding: 2px 10px; display: inline-block; margin-right: 10px; }
.pa-row .pa-code { margin: 0; }
.pa-count { font-family: var(--display); font-weight: 700; font-size: 1.3rem; color: var(--c-deep); }
.pa-row:not(.has) .pa-code { background: #b9b6cf; }

.sar h2 { display: flex; align-items: center; }
.sar ul { margin: 0; padding-left: 20px; }

/* ไทม์ไลน์ประวัติ */
.timeline { list-style: none; padding: 0 0 0 20px; margin: 0 0 24px; border-left: 3px solid var(--c-soft); }
.timeline li { position: relative; padding: 0 0 18px 18px; display: flex; flex-direction: column; }
.timeline li::before { content: ""; position: absolute; left: -29px; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 4px var(--paper); }
.timeline b { font-family: var(--display); color: var(--c-deep); }

.qr-ph { margin-top: 12px; width: 160px; height: 160px; border-radius: 16px; display: grid; place-content: center; text-align: center;
  background: repeating-linear-gradient(45deg, var(--c-tint) 0 10px, #fff 10px 20px); font-family: var(--display); font-weight: 600; color: var(--c-deep); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 500; }

/* ฟอร์ม (dialog) */
.sheet { border: 0; border-radius: 22px; padding: 0; width: min(520px, 94vw); box-shadow: 0 30px 60px -20px rgba(20, 10, 80, .5); }
.sheet::backdrop { background: rgba(22, 20, 46, .45); }
.sheet form { padding: 24px; max-height: 86vh; overflow-y: auto; }
.sheet h2 { margin-top: 0; color: var(--c-deep); }
.sheet label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .9rem; font-weight: 500; }
.sheet input, .sheet select, .sheet textarea, .field textarea {
  font: inherit; font-weight: 400; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
.sheet input:focus, .sheet select:focus, .sheet textarea:focus, .field textarea:focus { outline: none; border-color: var(--c); box-shadow: 0 0 0 3px var(--c-tint); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 14px; font-size: .92rem; z-index: 60; transition: transform .25s ease, visibility .25s; max-width: 92vw; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

@media (max-width: 860px) {
  .band { flex-direction: column; align-items: flex-start; }
  .band-actions { margin-right: 0; }
  .cols { grid-template-columns: 1fr; }
  .slot { grid-template-columns: auto 1fr; }
  .note dl, .kv { grid-template-columns: 1fr; gap: 0; }
  .note dd, .kv dd { margin-bottom: 8px; }
  /* ตารางบนมือถือ: แสดงเป็นการ์ด */
  table.data:not(.att) thead { display: none; }
  table.data:not(.att), table.data:not(.att) tbody, table.data:not(.att) tr, table.data:not(.att) td { display: block; width: 100%; }
  table.data:not(.att) tr { padding: 10px 4px; border-bottom: 1px solid var(--line); }
  table.data:not(.att) td { border: 0; padding: 3px 8px; text-align: left !important; }
  table.data:not(.att) td::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
}

@media print {
  .sidebar, .topbar, .notice, .band-actions, .scrim, .toast { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  body { background: #fff; }
  .band { background: none; padding: 0 0 12px; min-height: 0; }
  .band::before, .band::after { display: none; }
  .panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
