:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light: #dbeafe;
  --accent: #0891b2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ---------- Header ---------- */
header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary) 60%, var(--accent));
  color: #fff;
  padding: 20px 24px;
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.logo {
  width: 52px; height: 52px; border-radius: 14px;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 26px; flex-shrink: 0;
}
header h1 { font-size: 20px; font-weight: 700; line-height: 1.3; }
header p { font-size: 14px; opacity: .85; }
.header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Nav ---------- */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.nav-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; gap: 4px; overflow-x: auto;
}
.tab {
  display: inline-block; text-decoration: none;
  padding: 14px 16px; color: var(--muted); font-weight: 500;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- เมนูแนวตั้ง (จอกว้าง) ---------- */
@media (min-width: 861px) {
  :root { --sidebar: 240px; }
  nav {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar);
    border-bottom: none; border-right: 1px solid var(--border);
    overflow-y: auto; padding: 16px 0;
  }
  .nav-title { display: block !important; }
  .nav-inner { flex-direction: column; gap: 2px; padding: 0 10px; overflow: visible; }
  .tab {
    border-bottom: none; border-left: 4px solid transparent; border-radius: 8px;
    padding: 10px 14px; white-space: normal;
  }
  .tab:hover { background: var(--bg); }
  .tab.active { background: var(--primary-light); border-left-color: var(--primary); }
  header, main { margin-left: var(--sidebar); }
  main { max-width: calc(1200px + var(--sidebar)); }
}

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head h2 { font-size: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
/* การ์ดที่อยู่ในกริด (สถิติ/การ์ดครู/ทำเนียบ) ไม่ต้องเว้นบน */
.stats > .card, .grid-2 > .card, .ao-grid > .card, .staff-grid > .card { margin-top: 0; }
.card h3 { font-size: 16px; margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { display: flex; align-items: center; gap: 14px; }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px; flex-shrink: 0;
}
.form-actions {
  display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border);
}
.form-actions .btn { min-width: 120px; justify-content: center; }
.unsaved { margin-right: auto; color: var(--warning); font-size: 14px; font-weight: 600; }

/* ---------- Weekly results ---------- */
.wk-profile { display: flex; align-items: center; gap: 16px; }
.wk-avatar {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 34px;
  background: linear-gradient(135deg, var(--primary-light), #fce7f3); flex-shrink: 0;
}
.wk-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 4px 0; }
.wk-item + .wk-item { border-top: 1px dashed var(--border); }
.wk-cat { font-size: 18px; }

/* ---------- Make-up submissions ---------- */
body:not(.role-user) .user-only { display: none !important; }
.submit-card { border: 2px dashed #f0abfc; margin-bottom: 16px; }
.upload-box {
  display: block; text-align: center; padding: 22px; border-radius: 14px; cursor: pointer; font-size: 16px;
  border: 2px dashed var(--primary); background: var(--primary-light); color: var(--primary-dark);
}
.upload-box:hover { filter: brightness(.97); }
.sub-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.sub-preview { position: relative; margin: 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.sub-preview img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.sub-preview input { border: none; border-top: 1px solid var(--border); border-radius: 0; font-size: 14px; }
.sub-remove {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,.55); color: #fff;
}
.ev-thumb { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); }
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.review-card {
  display: flex; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); transition: transform .15s;
}
.review-card:hover { transform: translateY(-2px); border-color: var(--warning); }
.review-card img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.rv-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.rv-photo { margin: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.rv-photo img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #0f172a; }
.rv-photo figcaption { padding: 8px 12px; font-size: 14px; }
.rv-note { margin-top: 12px; font-size: 14px; }

/* ---------- Advisors overview ---------- */
.ao-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.ao-card { display: flex; gap: 14px; cursor: pointer; margin: 0 !important; transition: transform .15s, box-shadow .15s; }
.ao-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(15, 23, 42, .12); }
.ao-photo { width: 96px; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 12px; flex-shrink: 0; background: var(--primary-light); }
.ao-body { flex: 1; min-width: 0; }
.ao-name { font-weight: 700; font-size: 16px; }
.ao-rooms { margin: 4px 0 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.ao-meta { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- Chat ---------- */
.chat-wrap {
  display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 300px); min-height: 420px; max-height: 760px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden;
}
.chat-wrap.single { grid-template-columns: 1fr; max-width: 960px; margin: 0 auto; }
/* หน้าแชท: กว้างพอดี (ไม่เกิน 1280px) และสูงพอดีหน้าจอ ไม่ต้องเลื่อนหน้า */
main:has(.chat-wrap) { max-width: 1280px; }
.chat-list { border-right: 1px solid var(--border); overflow-y: scroll; min-height: 0; background: var(--bg); }
.chat-list-head { padding: 12px; position: sticky; top: 0; background: var(--bg); display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.thread {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; font: inherit; color: inherit;
  border: none; background: none; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.thread:hover { background: var(--primary-light); }
.thread.active { background: var(--primary-light); box-shadow: inset 4px 0 0 var(--primary); }
.thread-ava { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; overflow: hidden; display: grid; place-items: center; font-size: 22px; background: var(--surface); }
.thread-ava img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.thread-body { flex: 1; min-width: 0; font-size: 14px; }
.thread-body small { color: var(--muted); }
.thread-last { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-unread { background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; }
.chat-head small { font-weight: 400; color: var(--muted); }
.chat-body { flex: 1; min-height: 0; overflow-y: scroll; padding: 16px 18px; background: linear-gradient(180deg, var(--bg), var(--surface)); }
.chat-empty { text-align: center; color: var(--muted); margin-top: 60px; font-size: 15px; line-height: 2; }
.chat-empty::first-line { font-size: 40px; }
.bubble-row { display: flex; margin-bottom: 10px; }
.bubble-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 68%; padding: 9px 15px; border-radius: 18px 18px 18px 4px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.mine .bubble { border-radius: 18px 18px 4px 18px; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; border: none; }
.bubble-name { font-size: 12px; font-weight: 600; opacity: .8; }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-time { font-size: 11px; opacity: .7; text-align: right; }
.chat-quick { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; }
.quick {
  font: inherit; font-size: 13px; white-space: nowrap; cursor: pointer; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--primary-light); color: var(--primary-dark);
}
.quick:hover { filter: brightness(.96); }
.chat-input { display: flex; gap: 8px; padding: 10px 12px 12px; }
.chat-input input { border-radius: 999px; }
.chat-input .btn { border-radius: 999px; white-space: nowrap; }
@media (max-width: 760px) {
  .chat-wrap { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-body { min-height: 320px; }
}

/* ---------- How-to steps ---------- */
.how-to { margin-bottom: 16px; }
.how-to summary { cursor: pointer; font-weight: 700; font-size: 16px; color: var(--primary-dark); }
.steps { list-style: none; counter-reset: step; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.steps li {
  counter-increment: step; position: relative; display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--border); font-size: 14px;
}
.steps li::before {
  content: counter(step); position: absolute; top: -10px; left: -6px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center;
}
.step-ico { font-size: 26px; line-height: 1; }

.back-home {
  display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px;
  padding: 7px 16px; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: 14px;
  color: var(--primary); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .15s, background .15s;
}
.back-home:hover { background: var(--primary-light); transform: translateX(-3px); }

.stat-link {
  text-decoration: none; color: inherit; position: relative; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.stat-link:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.stat-link:hover .stat-go { color: var(--primary); transform: translateX(3px); }
.stat-go { margin-left: auto; font-size: 28px; color: var(--border); transition: .15s; }
.stat-disabled { cursor: default; }
.stat-disabled:hover { transform: none; box-shadow: var(--shadow); }
.stat-disabled .stat-go { display: none; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons & Inputs ---------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-light { background: rgba(255,255,255,.18); color: #fff; }
.btn-light:hover { background: rgba(255,255,255,.28); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  font: inherit; width: 100%;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
label { font-size: 14px; font-weight: 500; display: block; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1; min-width: 160px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; }
td.center, th.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-muted { background: var(--border); color: var(--muted); }

.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; border-radius: 999px; }

/* ---------- Activity list ---------- */
.activity-item {
  display: flex; gap: 14px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.date-box {
  width: 54px; flex-shrink: 0; text-align: center;
  background: var(--primary-light); color: var(--primary);
  border-radius: 10px; padding: 6px 0; line-height: 1.2;
}
.date-box b { display: block; font-size: 20px; }
.date-box small { font-size: 12px; }
.activity-item .meta { color: var(--muted); font-size: 13px; }

/* ---------- Attendance ---------- */
.att-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.status-group { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.status-group button {
  font: inherit; font-size: 13px; border: none; background: var(--surface);
  padding: 5px 12px; cursor: pointer; color: var(--muted);
}
.status-group button + button { border-left: 1px solid var(--border); }
.status-group button.on-present { background: var(--success); color: #fff; }
.status-group button.on-late { background: var(--warning); color: #fff; }
.status-group button.on-leave { background: var(--accent); color: #fff; }
.status-group button.on-absent { background: var(--danger); color: #fff; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h3 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--text); color: #fff; padding: 10px 20px; border-radius: 8px;
  transition: transform .25s; z-index: 60; font-size: 14px;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; }
.bar-row .name { width: 150px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .progress { flex: 1; height: 12px; }
.bar-row .val { width: 48px; text-align: right; font-weight: 600; }

.hint { color: var(--muted); font-size: 13px; }

.schedule-settings { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .schedule-settings { grid-template-columns: 1fr 1fr; } }

/* ---------- Photos ---------- */
.week-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.photo {
  margin: 0; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); break-inside: avoid;
}
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; transition: transform .2s; }
.photo:hover img { transform: scale(1.04); }
.photo figcaption { padding: 6px 10px; font-size: 13px; color: var(--muted); }
.modal-wide { max-width: 900px; }
.view-img { display: block; width: 100%; max-height: 65vh; object-fit: contain; background: #0f172a; border-radius: 8px; }

/* ---------- Faculty ---------- */
.staff-head { display: flex; justify-content: center; margin-bottom: 20px; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.staff-card { text-align: center; margin: 0 !important; break-inside: avoid; }
.staff-card-big { width: 100%; max-width: 280px; border-top: 4px solid var(--primary); }
.staff-photo {
  width: 150px; aspect-ratio: 3 / 4; margin: 0 auto 12px; border-radius: 10px; overflow: hidden;
  cursor: pointer; border: 2px dashed var(--border); background: var(--bg);
}
.staff-card-big .staff-photo { width: 180px; }
.staff-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.staff-photo:hover { border-color: var(--primary); }
.staff-placeholder {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 32px; color: var(--muted);
}
.staff-placeholder span { font-size: 13px; margin-top: 4px; }
.staff-name { font-weight: 700; font-size: 16px; }
.staff-position { color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 2px; }

/* ---------- Notifications ---------- */
.nav-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px;
}
.switch-wrap {
  display: inline-flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 14px;
}
.switch-wrap input { display: none; }
.switch {
  position: relative; width: 46px; height: 26px; border-radius: 999px; background: #cbd5e1; transition: background .2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch-wrap input:checked + .switch { background: var(--success); }
.switch-wrap input:checked + .switch::after { transform: translateX(20px); }
.noti-card { display: flex; align-items: center; gap: 16px; border-left: 5px solid var(--primary-light); }
.noti-card.noti-soon { border-left-color: var(--warning); }
.noti-card.noti-today { border-left-color: var(--danger); background: #fff7f7; }
.noti-date { width: 64px; padding: 8px 0; }
.noti-body { flex: 1; min-width: 0; }
.noti-title { font-weight: 700; font-size: 17px; }
.noti-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); font-size: 14px; margin-top: 2px; }
.noti-count { font-weight: 700; color: var(--primary); white-space: nowrap; }
.noti-soon .noti-count { color: var(--warning); }
.noti-today .noti-count { color: var(--danger); }
@media (max-width: 560px) {
  .noti-card { flex-wrap: wrap; }
  .noti-count { width: 100%; }
}

/* ---------- Participation tables ---------- */
.part-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.part-tab {
  text-decoration: none; color: var(--primary); font-weight: 600; padding: 10px 18px; border-radius: 999px;
  background: var(--surface); border: 2px solid var(--primary-light); box-shadow: var(--shadow); transition: .15s;
}
.part-tab:hover { transform: translateY(-2px); border-color: var(--primary); }
.part-tab.active { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; border-color: transparent; }
.part-legend { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.part-legend span { white-space: nowrap; }
.part-wrap { max-height: 70vh; }
.part-table th { position: sticky; top: 0; z-index: 2; }
.part-col { min-width: 84px; position: relative; font-size: 12px; }
.part-sname { font-weight: 400; max-width: 90px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; }
.part-del { position: absolute; top: 2px; right: 2px; border: none; background: none; color: var(--danger); cursor: pointer; font-size: 11px; opacity: .5; }
.part-del:hover { opacity: 1; }
.part-cell { cursor: pointer; font-size: 17px; user-select: none; }
.part-cell:hover { background: var(--primary-light) !important; }
.part-empty { color: var(--border); font-size: 22px; line-height: 1; }
.part-sticky, .part-sticky2 { position: sticky; background: var(--surface); z-index: 1; }
.part-sticky { left: 0; width: 44px; }
.part-sticky2 { left: 44px; min-width: 190px; box-shadow: 2px 0 0 var(--border); }
th.part-sticky, th.part-sticky2 { z-index: 3; background: #f8fafc; }

/* ================= หน้าผู้ใช้ทั่วไป (นักเรียน) — โทนพาสเทลม่วงชมพู ================= */
body.role-user {
  --primary: #9333ea;
  --primary-dark: #6b21a8;
  --primary-light: #f3e8ff;
  --accent: #ec4899;
  --bg: #fdf4ff;
  --border: #f1ddf7;
  --shadow: 0 2px 6px rgba(147, 51, 234, .08), 0 8px 20px rgba(236, 72, 153, .06);
  background: linear-gradient(180deg, #fdf4ff 0%, #fff1f7 100%) fixed;
}
.role-user header {
  background: linear-gradient(135deg, #a855f7, #ec4899 60%, #f9a8d4);
}
.role-user .logo { background: rgba(255,255,255,.35); border-radius: 50%; }
.role-user .card { border-radius: 18px; }
.role-user .tab.active { background: linear-gradient(90deg, #f3e8ff, #fce7f3); }
.role-user .stat-icon { border-radius: 50%; }
.role-user .part-tab.active { background: linear-gradient(135deg, #a855f7, #ec4899); }

/* ================= ครูที่ปรึกษา — โทนมิ้นต์ ฟ้าอ่อน เรียบง่าย สบายตา ================= */
body.role-advisor {
  --primary: #0d9488;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --accent: #38bdf8;
  --bg: #f0fdfa;
  --border: #d5f0ea;
  background: linear-gradient(180deg, #f0fdfa 0%, #f0f9ff 100%) fixed;
}
.role-advisor header { background: linear-gradient(135deg, #14b8a6, #2dd4bf 55%, #7dd3fc); }
.role-advisor .logo { overflow: hidden; border-radius: 50%; border: 3px solid rgba(255,255,255,.7); }
.role-advisor .logo img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.role-user .logo { overflow: hidden; }
.role-user .logo img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.role-advisor .card { border-radius: 16px; }

/* ดูอย่างเดียว: ซ่อนปุ่มแก้ไข/ส่วนของแอดมิน */
.role-user main .btn:not(.user-ok),
.role-user .modal .btn:not(.user-ok),
.role-user .header-actions .btn:not(.user-ok),
.role-user .admin-only,
.role-user .schedule-settings > div:not(:first-child),
.role-user .schedule-settings + .toolbar .btn { display: none !important; }
.role-user .part-cell, .role-user .staff-photo { pointer-events: none; }
.role-user .staff-placeholder span { display: none; }
.role-user .modal .modal-actions::after { content: '🔒 ดูอย่างเดียว'; color: var(--muted); font-size: 13px; }

.user-welcome {
  display: flex; align-items: center; gap: 18px; margin-bottom: 16px;
  background: linear-gradient(135deg, #f3e8ff, #fce7f3); border: 2px dashed #f0abfc;
}
.user-welcome .big { font-size: 46px; line-height: 1; }
.user-welcome h3 { margin: 0; color: var(--primary-dark); font-size: 18px; }
.user-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.user-link {
  text-decoration: none; color: var(--text); text-align: center; padding: 16px 10px; border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow); font-weight: 600; transition: transform .15s;
}
.user-link:hover { transform: translateY(-3px) rotate(-1deg); }
.user-link .ico { display: block; font-size: 34px; margin-bottom: 4px; }

.print-only { display: none; }
.signatures { justify-content: space-around; margin-top: 56px; text-align: center; line-height: 2.2; }

@media print {
  header, nav, .no-print, .toolbar, .page-head .btn, .stats { display: none !important; }
  .print-only { display: flex; }
  main { margin-left: 0 !important; }
  th, td { white-space: normal; }
  .week-card { break-inside: avoid; }
  .card { box-shadow: none; border: 1px solid var(--border); }
  body { background: #fff; }
}

/* ---------- หัวข้อเมนู (กดได้ → หน้าภาพรวม) ---------- */
.nav-title { display: none; }
.nav-title {
  margin: 0 10px 8px; padding: 8px 12px 12px; border-bottom: 1px solid var(--border);
  font-weight: 700; color: var(--primary-dark); text-decoration: none; border-radius: 8px;
  transition: background .15s;
}
.nav-title:hover { background: var(--primary-light); }
.nav-title small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }

/* ---------- แถบเลื่อน (scrollbar) ของแชท ---------- */
.chat-body, .chat-list { scrollbar-width: thin; scrollbar-color: var(--primary) var(--primary-light); }
.chat-body::-webkit-scrollbar, .chat-list::-webkit-scrollbar { width: 10px; }
.chat-body::-webkit-scrollbar-track, .chat-list::-webkit-scrollbar-track { background: var(--primary-light); border-radius: 999px; }
.chat-body::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb {
  background: var(--primary); border-radius: 999px; border: 2px solid var(--primary-light);
}
.chat-body::-webkit-scrollbar-thumb:hover, .chat-list::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* ---------- แชท: ข้อความอัตโนมัติ / สถานะเรียลไทม์ ---------- */
.bubble-row.bot { justify-content: center; }
.bubble-row.bot .bubble {
  max-width: 80%; border-radius: 14px; background: #fffbeb; border: 1px dashed #fbbf24; color: #92400e; text-align: center;
}
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; margin: 0 2px 1px;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: live 1.6s infinite;
}
@keyframes live { 70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
.tab-unread {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 12px; text-align: center; line-height: 20px;
}

/* ---------- แชท: สัญลักษณ์ตอบกลับแล้ว ---------- */
.msg-status { font-weight: 600; margin-left: 4px; opacity: .85; }
.msg-status.replied { opacity: 1; }
.mine .msg-status.replied { background: rgba(255,255,255,.25); padding: 0 6px; border-radius: 999px; }
.thread-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.reply-badge { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.reply-badge.wait { background: var(--warning-light); color: var(--warning); }
.reply-badge.done { background: var(--success-light); color: var(--success); }

/* ================= มือถือ / ไอแพด ================= */
.menu-toggle { display: none; }

/* ไอแพดแนวนอน / จอกลาง: แถบเมนูแคบลง */
@media (min-width: 861px) and (max-width: 1180px) {
  :root { --sidebar: 210px; }
  .tab { padding: 9px 12px; font-size: 14px; }
}

/* ไอแพดแนวตั้ง + มือถือ: เมนูแบบปุ่ม ☰ เปิด/ปิด */
@media (max-width: 860px) {
  header { padding: 14px 16px; }
  .header-inner { gap: 10px; }
  .logo { width: 44px; height: 44px; font-size: 22px; border-radius: 12px; }
  header h1 { font-size: 16px; }
  header p { font-size: 12px; }
  .header-actions { width: 100%; margin-left: 0; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .header-actions .btn { white-space: nowrap; }

  .menu-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    font: inherit; font-weight: 700; font-size: 15px; color: var(--primary-dark); cursor: pointer;
    background: var(--surface); border: none; padding: 12px 16px;
  }
  .menu-toggle .bars { font-size: 22px; line-height: 1; }
  nav .nav-inner {
    display: none; flex-direction: column; gap: 2px; padding: 4px 10px 12px;
    max-height: 70vh; overflow-y: auto; overflow-x: hidden;
  }
  nav.open .nav-inner { display: flex; }
  nav.open { box-shadow: 0 12px 24px rgba(15, 23, 42, .15); }
  .tab { border-bottom: none; border-left: 4px solid transparent; border-radius: 10px; padding: 11px 14px; white-space: normal; }
  .tab.active { background: var(--primary-light); border-left-color: var(--primary); }
  .nav-title { display: block; margin: 0 10px 6px; }
  nav:not(.open) .nav-title { display: none; }

  main { padding: 16px 12px 40px; }
  .page-head h2 { font-size: 18px; }
  .page-head > div:last-child { width: 100%; }
  .card { padding: 16px; }
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .stats > *, .grid-2 > *, .form-grid > * { min-width: 0; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  header h1, header p { overflow-wrap: anywhere; }
  .header-inner > div:nth-child(2) { min-width: 0; flex: 1; }
  .stat-label { overflow-wrap: anywhere; }
  .stat-go { position: absolute; right: 12px; bottom: 10px; }
  .bar-row .name { width: 110px; }
  html, body { max-width: 100%; overflow-x: hidden; }
  .stat { flex-direction: column; align-items: flex-start; gap: 8px; }
  .stat-icon { width: 40px; height: 40px; font-size: 18px; }
  .stat-value { font-size: 22px; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1 1 100%; }
  th, td { padding: 8px 10px; font-size: 13px; }
  .modal { padding: 18px; max-height: 92vh; }
  .modal-actions { flex-wrap: wrap; }
  .btn { padding: 9px 14px; } /* ปุ่มใหญ่ขึ้น กดง่ายด้วยนิ้ว */
  .btn-sm { padding: 6px 11px; }
  input, select, textarea { font-size: 16px; } /* กัน iPhone ซูมเข้าเองตอนแตะช่องกรอก */
  .back-home { margin-bottom: 10px; }
  .part-tabs { gap: 6px; }
  .part-tab { padding: 8px 14px; font-size: 14px; }
  .ao-grid, .review-grid { grid-template-columns: 1fr; }
  .staff-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .staff-photo { width: 110px; }
  .staff-card-big .staff-photo { width: 140px; }
  .noti-card { gap: 12px; }
  .chat-wrap { height: auto; max-height: none; }
  .chat-body { height: 55vh; min-height: 300px; flex: none; }
  .user-links { grid-template-columns: repeat(2, 1fr); }
}

/* มือถือจอเล็ก */
@media (max-width: 420px) {
  .stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stat-label { font-size: 12px; }
  .staff-grid { grid-template-columns: repeat(2, 1fr); }
  .bubble { max-width: 85%; }
}
