/* PA UI — ธีมสว่าง สีหลัก #2559d3 สีรอง #e7bd1d
   โหลดหลัง app.min.css (Bootstrap 4) เพื่อทับสไตล์เดิม */
:root {
  --primary: #2559d3;
  --primary-600: #1d47ad;
  --primary-50: #eef3fd;
  --primary-100: #dbe5fb;
  --accent: #e7bd1d;          /* ใช้เป็นพื้น/เส้นเท่านั้น: ตัวอักษรสีนี้บนพื้นขาว contrast ไม่ผ่าน */
  --accent-50: #fdf7e1;
  --accent-ink: #7a5d00;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e4e8f0;
  --text: #1b2333;
  --muted: #5b6475;

  --ok: #1f8a4c;   --ok-bg: #e6f5ec;
  --bad: #c0392b;  --bad-bg: #fdecea;
  --info: #2559d3; --info-bg: #eef3fd;
  --idle: #5b6475; --idle-bg: #eef0f4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .05);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
a:hover { color: var(--primary-600); }
h1, h2, h3, h4, h5, h6 { line-height: 1.3; font-weight: 600; color: var(--text); font-family: inherit; }
:focus-visible { outline: 3px solid var(--primary-100); outline-offset: 2px; }
svg.feather { width: 20px; height: 20px; stroke-width: 2; flex: none; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  font: inherit; font-size: 15px; font-weight: 500; line-height: 1.2; white-space: nowrap; border-radius: var(--radius-sm);
  box-shadow: none !important;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary, .btn-primary:disabled { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:focus, .btn-primary:not(:disabled):active { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn-outline-primary, .btn-outline { background: var(--surface); color: var(--primary); border: 1px solid var(--primary-100); }
.btn-outline-primary:hover, .btn-outline:hover, .btn-outline-primary:not(:disabled):active { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.btn-secondary, .btn-dark { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover, .btn-dark:hover { background: var(--bg); color: var(--text); border-color: #cfd5e1; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-lg { min-height: 48px; font-size: 16px; }
.btn-block { width: 100%; display: flex; }
input.btn { display: inline-block; }

/* ---------- ฟอร์ม ---------- */
.form-group { margin-bottom: 18px; }
label, .control-label { font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-control, .custom-select, .input {
  width: 100%; height: auto; min-height: 46px; padding: 10px 14px;
  font: inherit; font-size: 16px; color: var(--text);
  background-color: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: none; transition: border-color .15s, box-shadow .15s;
}
textarea.form-control { min-height: 110px; }
.form-control:focus, .custom-select:focus, .input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.form-control[readonly], .form-control:disabled { background: var(--bg); }
.input-group-text { background: var(--bg); border-color: var(--border); color: var(--muted); }
.input-group > .form-control:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .form-control:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input, .input-icon .form-control { padding-left: 42px; }
.form-text, .text-muted { color: var(--muted) !important; }
.form-group small { display: block; margin-top: 4px; font-size: 13px; }
.text-danger { color: var(--bad) !important; }
.custom-file { height: auto; margin-bottom: 4px; }
input[type=file] {
  width: 100%; padding: 8px; font: inherit; font-size: 15px;
  border: 1px dashed #c6cedd; border-radius: var(--radius-sm); background: var(--bg); cursor: pointer;
}
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 8px 14px; border: 0; border-radius: 6px;
  background: var(--primary); color: #fff; font: inherit; font-size: 14px; cursor: pointer;
}
.section-title { font-weight: 600; font-size: 15px; margin: 18px 0 8px; color: var(--text); }
.section-title:first-child { margin-top: 0; }

/* ปุ่มเลือกคะแนน (selectgroup จาก template เดิม ใช้ใน lform/*) */
.selectgroup { display: inline-flex; gap: 6px; width: 100%; }
.selectgroup-item { flex: 1; position: relative; margin: 0; }
.selectgroup-input-radio { position: absolute; opacity: 0; inset: 0; z-index: -1; }
.selectgroup-button {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 44px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--muted); font-weight: 600; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.selectgroup-button:hover { border-color: var(--primary); color: var(--primary); }
.selectgroup-input-radio:checked + .selectgroup-button { background: var(--primary); border-color: var(--primary); color: #fff; }
.selectgroup-input-radio:focus-visible + .selectgroup-button { box-shadow: 0 0 0 3px var(--primary-100); }

/* ตัวเลือกแบบปุ่มแบ่งช่อง (หน้า login) */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; min-height: 44px; border-radius: 6px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted); text-align: center;
}
.segmented input:checked + label { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid var(--primary-100); }

/* ---------- แจ้งเตือน ---------- */
.alert { position: relative; display: block; padding: 12px 44px 12px 14px; border: 0; border-radius: var(--radius-sm); font-size: 15px; margin-bottom: 18px; }
.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-danger, .alert-error { background: var(--bad-bg); color: var(--bad); }
.alert-flex { display: flex; gap: 10px; align-items: flex-start; padding-right: 14px; }
.alert .close { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; padding: 0; border: 0; background: none; color: inherit; opacity: .7; font-size: 22px; line-height: 1; cursor: pointer; }
.alert .close:hover { opacity: 1; }

/* ---------- ป้ายสถานะ ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 500; line-height: 1.5; white-space: nowrap; box-shadow: none !important;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok, .badge-success { background: var(--ok-bg); color: var(--ok); }
.badge-bad, .badge-danger { background: var(--bad-bg); color: var(--bad); }
.badge-info, .badge-primary { background: var(--info-bg); color: var(--info); }
.badge-idle, .badge-light, .badge-secondary { background: var(--idle-bg); color: var(--idle); }
.badge-warn, .badge-warning { background: var(--accent-50); color: var(--accent-ink); }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card-head, .card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 20px; background: none; border-bottom: 1px solid var(--border); }
.card-head h2, .card-header h4 { font-size: 18px; margin: 0; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: 14px 20px; background: #fafbfd; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.font-15 { font-size: 15px; } .font-18 { font-size: 18px; } .font-24 { font-size: 24px; }

/* ---------- โลโก้ ---------- */
.brand { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-radius: var(--radius); background: linear-gradient(135deg, var(--primary) 0%, #3b6fe6 100%); color: #fff; box-shadow: var(--shadow); }
.brand:hover { color: #fff; text-decoration: none; }
.brand-mark { width: 56px; height: 56px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px var(--accent); }
.brand-mark img { width: 46px; height: 46px; }
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-size: clamp(24px, 8vw, 36px); font-weight: 600; line-height: 1.1; }
.brand-sub { margin-top: 6px; padding-top: 6px; border-top: 2px solid var(--accent); font-size: clamp(13px, 4vw, 16px); font-weight: 500; opacity: .95; line-height: 1.2; }
/* data-spread: JS แยกตัวอักษรเป็น span แล้วกระจายเต็มความกว้าง */
.brand [data-spread].spread { display: flex; justify-content: space-between; }
.brand-sm { padding: 10px 12px; gap: 10px; box-shadow: none; }
.brand-sm .brand-mark { width: 38px; height: 38px; box-shadow: 0 0 0 2px var(--accent); }
.brand-sm .brand-mark img { width: 30px; height: 30px; }
.brand-sm .brand-name { font-size: 20px; }
.brand-sm .brand-sub { font-size: 11px; margin-top: 3px; padding-top: 3px; border-top-width: 1.5px; }

/* ---------- หน้า login ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(600px 300px at 0% 0%, var(--primary-100), transparent 70%),
    radial-gradient(500px 260px at 100% 100%, var(--accent-50), transparent 70%),
    var(--bg);
}
.auth-box { width: 100%; max-width: 420px; }
.auth .brand { margin-bottom: 20px; }
.auth .card-body { padding: 28px; }
.auth h1 { font-size: 22px; margin: 0 0 4px; }
.auth .sub { color: var(--muted); margin: 0 0 22px; font-size: 15px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 14px; margin-top: 20px; }

/* ---------- โครงหน้า app ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1030;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  transition: transform .2s ease;
}
.sidebar-brand { padding: 14px 12px; border-bottom: 1px solid var(--border); }
.side-nav { list-style: none; margin: 0; padding: 14px 12px; flex: 1; overflow-y: auto; }
.side-nav-label { padding: 10px 12px 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.side-nav a {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 500;
}
.side-nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.side-nav a[aria-current="page"] { background: var(--primary-50); color: var(--primary); box-shadow: inset 3px 0 0 var(--accent); }
.side-nav a svg { color: var(--muted); }
.side-nav a[aria-current="page"] svg { color: var(--primary); }
.side-nav-bottom { padding: 12px; border-top: 1px solid var(--border); }
.side-nav-bottom a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm); color: var(--bad); font-weight: 500; }
.side-nav-bottom a:hover { background: var(--bad-bg); color: var(--bad); text-decoration: none; }

.main { margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 12px;
  height: 64px; padding: 0 24px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; width: 44px; height: 44px; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); align-items: center; justify-content: center; flex: none; }
.menu-btn:hover { background: var(--bg); }
.year-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--accent-50); color: var(--accent-ink); font-size: 14px; font-weight: 600; border: 1px solid #f2dc87; white-space: nowrap; }
.year-chip svg { width: 16px; height: 16px; }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; font-weight: 600; font-size: 15px; flex: none; }
.user-name { font-size: 15px; font-weight: 500; line-height: 1.3; white-space: nowrap; }
.user-role { font-size: 13px; color: var(--muted); line-height: 1.3; }

.content { padding: 24px; }
.content > .card:last-child, .content > .row:last-child .card { margin-bottom: 0; }
.page-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title h2 { font-size: 24px; margin: 0; }
.page-title p { margin: 4px 0 0; color: var(--muted); }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 1025; }
.foot { padding: 8px 24px 24px; color: var(--muted); font-size: 14px; }
.foot a { color: var(--muted); }

/* ---------- แถบโปรไฟล์ครู ---------- */
.profile {
  display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center;
  padding: 24px; color: #fff; border: 0;
  background: linear-gradient(135deg, var(--primary) 0%, #3b6fe6 100%);
  position: relative; overflow: hidden;
}
.profile::after { content: ""; position: absolute; right: -56px; top: -56px; width: 150px; height: 150px; border-radius: 50%; border: 18px solid var(--accent); opacity: .9; }
.profile > * { position: relative; z-index: 1; }
.profile .avatar { width: 64px; height: 64px; font-size: 24px; background: #fff; color: var(--primary); }
.profile h2 { font-size: 22px; margin: 0; color: #fff; }
.profile .meta { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 8px; font-size: 15px; opacity: .95; }
.profile .meta span { display: inline-flex; align-items: center; gap: 6px; }
.profile .meta svg { width: 16px; height: 16px; }

/* ---------- ตัวเลขสรุป ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stats .card { margin: 0; }
.stat { padding: 16px 18px; }
.stat-label { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 28px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---------- ขั้นตอนผู้ประเมิน ---------- */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.step { display: flex; gap: 14px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.step-num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; flex: none; background: var(--idle-bg); color: var(--idle); }
.step.done .step-num { background: var(--ok-bg); color: var(--ok); }
.step.wait .step-num { background: var(--accent-50); color: var(--accent-ink); }
.step-title { font-size: 13px; color: var(--muted); }
.step-name { font-weight: 500; margin: 2px 0 6px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

/* ---------- ตาราง ---------- */
.table-wrap, .table-responsive { overflow-x: auto; }
.table { width: 100%; margin: 0; border-collapse: collapse; font-size: 15px; color: var(--text); }
.table th { text-align: left; font-weight: 600; font-size: 13px; color: var(--muted); background: #fafbfd; padding: 12px 16px; border-top: 0; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.table td { padding: 14px 16px; border-top: 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td, .table tr:last-child td { border-bottom: 0; }
.table-striped tbody tr:nth-of-type(odd) { background: none; }
.table tbody tr:hover, .table-hover tbody tr:hover { background: #fafbfd; }
/* แถวหัวข้อในแบบประเมิน lform/* (เดิมใส่ style สีเทาไว้ในแท็ก) */
.table tr[style*="C0C0C0"] { background: var(--primary-50) !important; font-weight: 600; color: var(--primary-600); }
.table .num { color: var(--muted); font-variant-numeric: tabular-nums; width: 48px; }
.table .act { text-align: right; width: 1%; white-space: nowrap; }
.cell-name { font-weight: 500; }
.cell-sub { font-size: 13px; color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- ตัวกรอง ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; flex: 1; }
.toolbar .input-icon { flex: 1 1 260px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font: inherit; font-size: 14px; color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--primary); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Modal (<dialog class="modal-box">) ---------- */
.modal-box {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25); overflow: auto;
}
.modal-box::backdrop { background: rgba(16, 24, 40, .45); }
.modal-box[open] { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-close { width: 40px; height: 40px; margin: -8px -8px -8px 0; display: grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-box .card-header { flex-wrap: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(16, 24, 40, .15); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 8px 0 4px; height: 60px; }
  .user-name, .user-role { display: none; }
  .content { padding: 16px; }
  .foot { padding: 8px 16px 20px; }
  .page-title h2 { font-size: 20px; }
  .profile { grid-template-columns: 1fr; padding: 20px; gap: 14px; }
  .profile::after { width: 110px; height: 110px; border-width: 14px; right: -44px; top: -44px; }
  .steps { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 22px; }
  .card-head, .card-header, .card-body { padding: 16px; }
  .card-footer { padding: 12px 16px; }

  /* แบบให้คะแนน (lform/*): ข้อ | คำอธิบาย แล้วปุ่มคะแนนเต็มบรรทัดด้านล่าง */
  .score-form .selectgroup.w-50 { width: 100% !important; }
  .score-form .table thead { display: none; }
  .score-form .table tr { display: grid; grid-template-columns: 40px 1fr; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .score-form .table td { display: block; padding: 0; border: 0; }
  .score-form .table td:nth-child(3) { grid-column: 1 / -1; }
  .score-form .table td:nth-child(3):not(:empty) { margin-top: 10px; }
  .score-form .table .form-group { margin: 0; }

  /* ตารางเป็นการ์ดรายแถว */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table-stack td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  .table-stack td.num { display: none; }
  .table-stack td.main-cell { display: block; text-align: left; margin-bottom: 6px; }
  .table-stack td.main-cell::before { content: none; }
  .table-stack td.act { width: 100%; margin-top: 8px; }
  .table-stack td.act::before { content: none; }
  .table-stack td.act .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
