/* ========================================================================
   ระบบประเมิน PA — ธีมทางการ สีสันสดใส ฟอนต์ Sarabun
   ======================================================================== */
:root {
  --navy: #1e2a78;
  --indigo: #4338ca;
  --violet: #7c3aed;
  --gold: #f5b301;
  --gold-soft: #fff4d1;
  --ink: #1f2547;
  --muted: #6b7194;
  --line: #e4e7f5;
  --bg: #f3f5fd;
  --card: #ffffff;
  --radius: 18px;
  --shadow: 0 10px 30px -12px rgba(30, 42, 120, .22);
  --shadow-sm: 0 4px 14px -6px rgba(30, 42, 120, .18);
  --lv1: #ef4444; --lv1-bg: #fee2e2;
  --lv2: #f97316; --lv2-bg: #ffedd5;
  --lv3: #0ea5e9; --lv3-bg: #e0f2fe;
  --lv4: #16a34a; --lv4-bg: #dcfce7;
  --bs-body-font-family: 'Sarabun', system-ui, sans-serif;
  --bs-primary: #4338ca;
  --bs-primary-rgb: 67, 56, 202;
  --bs-link-color: #4338ca;
  --bs-link-hover-color: #312e81;
}

html, body { font-family: 'Sarabun', system-ui, sans-serif; }
body {
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(124, 58, 237, .10), transparent 60%),
    radial-gradient(900px 400px at -10% 0%, rgba(14, 165, 233, .10), transparent 60%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
}
.app-main { flex: 1; padding: 24px 0 40px; }
input, select, textarea, button, .swal2-popup { font-family: 'Sarabun', sans-serif !important; }

/* ---------- Navbar ---------- */
.app-navbar {
  background: linear-gradient(100deg, var(--navy) 0%, var(--indigo) 55%, var(--violet) 100%);
  box-shadow: 0 6px 24px -10px rgba(30, 42, 120, .7);
  border-bottom: 3px solid var(--gold);
  padding: .55rem 0;
}
.brand-emblem {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.35rem;
  background: linear-gradient(135deg, var(--gold), #ffd966);
  color: var(--navy);
  box-shadow: 0 4px 12px rgba(245, 179, 1, .45);
}
.brand-sub { font-size: .78rem; opacity: .85; max-width: 220px; font-weight: 400; }
.app-navbar .nav-link {
  color: rgba(255, 255, 255, .82); border-radius: 10px; padding: .5rem .8rem !important; font-weight: 500;
}
.app-navbar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.app-navbar .nav-link.active { color: var(--navy); background: #fff; box-shadow: var(--shadow-sm); }
.fy-picker {
  display: flex; align-items: center; gap: .45rem; color: #fff;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 12px; padding: .25rem .35rem .25rem .7rem; font-size: .92rem;
}
.fy-picker select {
  border: 0; border-radius: 9px; font-weight: 700; color: var(--navy);
  background-color: var(--gold-soft); min-width: 120px;
}
.btn-user {
  background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .25); border-radius: 12px;
}
.btn-user:hover, .btn-user:focus, .btn-user.show { background: #fff; color: var(--navy); }

/* ---------- Page header ---------- */
.page-head {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.55rem; font-weight: 800; margin: 0; color: var(--navy); }
.page-head .sub { color: var(--muted); margin: .15rem 0 0; }
.page-icon {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 1.5rem;
  color: #fff; background: linear-gradient(135deg, var(--indigo), var(--violet));
  box-shadow: 0 8px 20px -8px rgba(124, 58, 237, .8); flex-shrink: 0;
}

/* ---------- Cards ---------- */
.card-x {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-x > .card-x-head {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  background: linear-gradient(180deg, #fbfbff, #fff);
}
.card-x-head h2, .card-x-head h3 { font-size: 1.08rem; font-weight: 700; margin: 0; color: var(--navy); }
.card-x > .card-x-body { padding: 1.25rem; }

.stat {
  position: relative; border-radius: var(--radius); padding: 1.1rem 1.2rem; color: #fff; overflow: hidden;
  box-shadow: var(--shadow); min-height: 118px;
}
.stat::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255, 255, 255, .14);
}
.stat .stat-icon { position: absolute; right: 16px; bottom: 10px; font-size: 2.6rem; opacity: .35; }
.stat .stat-label { font-size: .93rem; opacity: .92; }
.stat .stat-value { font-size: 2.1rem; font-weight: 800; line-height: 1.1; margin-top: .25rem; }
.stat .stat-foot { font-size: .82rem; opacity: .85; }
.g-indigo { background: linear-gradient(135deg, #4338ca, #6d28d9); }
.g-sky    { background: linear-gradient(135deg, #0284c7, #06b6d4); }
.g-green  { background: linear-gradient(135deg, #059669, #22c55e); }
.g-rose   { background: linear-gradient(135deg, #e11d48, #f97316); }
.g-gold   { background: linear-gradient(135deg, #d97706, #f5b301); }

/* ---------- Rank chips & tabs ---------- */
.rank-chip {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; font-weight: 600;
  padding: .2rem .6rem; border-radius: 999px; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 12%, white);
  border: 1px solid color-mix(in srgb, var(--c) 35%, white);
}
.rank-tabs { display: flex; gap: .5rem; flex-wrap: wrap; }
.rank-tab {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: .45rem .85rem;
  font-weight: 600; color: var(--muted); display: inline-flex; gap: .45rem; align-items: center;
  transition: all .15s;
}
.rank-tab .count {
  font-size: .75rem; background: var(--bg); border-radius: 999px; padding: 0 .5rem; color: var(--ink);
}
.rank-tab:hover { border-color: var(--c, var(--indigo)); color: var(--c, var(--indigo)); }
.rank-tab.active {
  color: #fff; background: var(--c, var(--indigo)); border-color: var(--c, var(--indigo));
  box-shadow: 0 6px 16px -8px var(--c, var(--indigo));
}
.rank-tab.active .count { background: rgba(255, 255, 255, .25); color: #fff; }

/* ---------- Tables ---------- */
.table-x { margin: 0; }
.table-x thead th {
  background: #f5f6fe; color: var(--navy); font-weight: 700; font-size: .9rem;
  border-bottom: 2px solid var(--line); white-space: nowrap; vertical-align: middle;
}
.table-x td { vertical-align: middle; }
.table-x tbody tr:hover { background: #fafaff; }
.score-pill {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 64px;
  border-radius: 12px; padding: .25rem .5rem; font-weight: 700; line-height: 1.15; cursor: pointer;
  border: 1.5px dashed #c7cbe6; color: var(--muted); background: #fff; transition: all .15s;
}
.score-pill small { font-weight: 500; font-size: .7rem; }
.score-pill:hover { border-color: var(--indigo); color: var(--indigo); transform: translateY(-1px); }
.score-pill.done { border-style: solid; }
.score-pill.pass { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.score-pill.fail { border-color: #fca5a5; background: #fef2f2; color: #b91c1c; }
.score-pill.partial { border-color: #fcd34d; background: #fffbeb; color: #b45309; }
.badge-result { border-radius: 999px; padding: .35rem .75rem; font-weight: 700; font-size: .82rem; }
.badge-pass { background: #dcfce7; color: #15803d; }
.badge-fail { background: #fee2e2; color: #b91c1c; }
.badge-wait { background: #eef0fb; color: var(--muted); }

.btn { border-radius: 11px; font-weight: 600; }
.btn-grad {
  color: #fff; border: 0;
  background: linear-gradient(120deg, var(--indigo), var(--violet));
  box-shadow: 0 8px 18px -10px rgba(67, 56, 202, .9);
}
.btn-grad:hover { color: #fff; filter: brightness(1.08); }
.btn-gold { background: var(--gold); color: var(--navy); border: 0; }
.btn-gold:hover { background: #e0a400; color: var(--navy); }
.btn-soft { background: #eef0fd; color: var(--indigo); border: 0; }
.btn-soft:hover { background: #e0e3fb; color: var(--navy); }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; }

.form-control, .form-select { border-radius: 11px; border-color: #d9ddf0; }
.form-control:focus, .form-select:focus { border-color: var(--indigo); box-shadow: 0 0 0 .2rem rgba(67, 56, 202, .15); }
.form-label { font-weight: 600; color: var(--navy); font-size: .93rem; }

/* ---------- Modals ---------- */
.modal-content { border: 0; border-radius: 20px; overflow: hidden; box-shadow: 0 30px 60px -20px rgba(15, 23, 75, .5); }
.modal-header.grad {
  color: #fff; border: 0;
  background: linear-gradient(100deg, var(--navy), var(--indigo) 60%, var(--violet));
}
.modal-header.grad .btn-close { filter: invert(1) grayscale(1) brightness(2); }
.modal-header.grad .modal-title { font-weight: 700; }
.modal-footer { background: #fafbff; border-top: 1px solid var(--line); }

/* ---------- Rubric form (PA2) ---------- */
.eval-meta {
  display: grid; gap: .35rem 1.25rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  background: #f7f8ff; border: 1px solid var(--line); border-radius: 14px; padding: .85rem 1rem; font-size: .95rem;
}
.eval-meta b { color: var(--navy); }
.committee-switch { display: flex; gap: .5rem; flex-wrap: wrap; }
.committee-switch .btn { border-radius: 12px; }
.committee-switch .btn.active { background: var(--navy); color: #fff; }
.committee-switch .btn .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #cbd0ea; }
.committee-switch .btn .dot.on { background: #22c55e; }

.part-title {
  font-weight: 800; color: #fff; padding: .6rem 1rem; border-radius: 12px; margin: 1.1rem 0 .6rem;
  background: linear-gradient(100deg, var(--indigo), var(--violet)); font-size: 1rem;
}
.part-title.p2 { background: linear-gradient(100deg, #0369a1, #0d9488); }

.rubric { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .95rem; }
.rubric th, .rubric td { border: 1px solid var(--line); padding: .55rem .6rem; vertical-align: middle; }
.rubric thead th { background: #eef0fd; color: var(--navy); text-align: center; font-weight: 700; line-height: 1.3; }
.rubric thead th.lv { width: 86px; }
.rubric thead th.lv small { display: block; font-weight: 500; font-size: .7rem; color: var(--muted); line-height: 1.25; }
.rubric thead th:first-child { text-align: left; }
.rubric .group-row td { background: #fff8e1; font-weight: 700; color: #7a5300; }
.rubric .ind-title { font-weight: 700; color: var(--navy); }
.rubric .ind-desc { color: #4a5078; font-size: .9rem; margin-top: .2rem; }
.rubric td.lv-cell { width: 86px; text-align: center; padding: .35rem; }
.rubric td.note-cell { width: 130px; font-size: .82rem; color: var(--muted); text-align: center; }
.rubric td.note-cell[rowspan] { vertical-align: top; padding-top: 1.2rem; background: #fffdf5; }
.rubric tr.missing td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }

.lv-btn {
  width: 48px; height: 48px; border-radius: 14px; border: 2px solid #dfe3f3; background: #fff;
  font-weight: 800; font-size: 1.15rem; color: #9aa0c3; transition: all .12s; cursor: pointer;
  display: inline-grid; place-items: center;
}
.lv-btn:hover { transform: scale(1.06); }
.lv-btn[data-lv="1"]:hover, .lv-btn[data-lv="1"].on { border-color: var(--lv1); color: var(--lv1); }
.lv-btn[data-lv="2"]:hover, .lv-btn[data-lv="2"].on { border-color: var(--lv2); color: var(--lv2); }
.lv-btn[data-lv="3"]:hover, .lv-btn[data-lv="3"].on { border-color: var(--lv3); color: var(--lv3); }
.lv-btn[data-lv="4"]:hover, .lv-btn[data-lv="4"].on { border-color: var(--lv4); color: var(--lv4); }
.lv-btn.on { color: #fff !important; transform: scale(1.04); }
.lv-btn[data-lv="1"].on { background: var(--lv1); }
.lv-btn[data-lv="2"].on { background: var(--lv2); }
.lv-btn[data-lv="3"].on { background: var(--lv3); }
.lv-btn[data-lv="4"].on { background: var(--lv4); }
.lv-btn .mlabel { display: none; }

.score-bar {
  position: sticky; bottom: 0; z-index: 5; display: grid; gap: .6rem;
  grid-template-columns: repeat(4, minmax(0, 1fr)); padding: .75rem; margin: 1rem -1rem 0;
  box-shadow: 0 -8px 20px -14px rgba(30, 42, 120, .5);
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(6px); border-top: 1px solid var(--line);
}
.score-box { border-radius: 14px; padding: .45rem .75rem; text-align: center; background: #f5f6fe; }
.score-box .lbl { font-size: .78rem; color: var(--muted); }
.score-box .val { font-size: 1.35rem; font-weight: 800; color: var(--navy); line-height: 1.2; }
.score-box .val small { font-size: .8rem; color: var(--muted); font-weight: 600; }
.score-box.total { background: linear-gradient(120deg, var(--indigo), var(--violet)); }
.score-box.total .lbl, .score-box.total .val, .score-box.total .val small { color: #fff; }
.score-box.result.pass { background: #dcfce7; } .score-box.result.pass .val { color: #15803d; }
.score-box.result.fail { background: #fee2e2; } .score-box.result.fail .val { color: #b91c1c; }

.workload-box {
  display: flex; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem; border-radius: 14px;
  background: #f7f8ff; border: 1px solid var(--line);
}
.workload-box .form-check { margin: 0; }

/* ---------- PA3 summary ---------- */
.sum-table th, .sum-table td { text-align: center; vertical-align: middle; }
.sum-table td:first-child, .sum-table th:first-child { text-align: left; }
.sum-table tfoot td { font-weight: 800; background: #f5f6fe; }
.result-banner {
  border-radius: 16px; padding: 1rem 1.25rem; display: flex; align-items: center; gap: 1rem; font-weight: 700;
}
.result-banner i { font-size: 2.2rem; }
.result-banner.pass { background: linear-gradient(120deg, #dcfce7, #f0fdf4); color: #166534; border: 1px solid #86efac; }
.result-banner.fail { background: linear-gradient(120deg, #fee2e2, #fff1f2); color: #991b1b; border: 1px solid #fca5a5; }
.result-banner.wait { background: #f5f6fe; color: var(--muted); border: 1px dashed #c7cbe6; }

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(800px 400px at 0% 0%, rgba(245, 179, 1, .25), transparent 60%),
    linear-gradient(135deg, var(--navy), var(--indigo) 55%, var(--violet));
}
.auth-card { width: 100%; max-width: 460px; background: #fff; border-radius: 24px; box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .55); overflow: hidden; }
.auth-card.wide { max-width: 720px; }
.auth-top { padding: 1.75rem 1.75rem 1rem; text-align: center; }
.auth-top .brand-emblem { width: 68px; height: 68px; font-size: 2.1rem; border-radius: 20px; margin: 0 auto .75rem; }
.auth-top h1 { font-size: 1.35rem; font-weight: 800; color: var(--navy); margin: 0; }
.auth-top p { color: var(--muted); margin: .25rem 0 0; font-size: .95rem; }
.auth-body { padding: 0 1.75rem 1.75rem; }
.auth-strip { height: 6px; background: linear-gradient(90deg, var(--gold), #fb7185, var(--violet), #0ea5e9); }

.app-footer { color: var(--muted); font-size: .85rem; padding: 14px 0; border-top: 1px solid var(--line); background: rgba(255, 255, 255, .6); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 3rem; color: #c7cbe6; display: block; margin-bottom: .5rem; }

.legend-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.bar-track { height: 10px; background: #eef0fb; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }

/* ---------- Responsive ---------- */
.app-navbar .nav-link { white-space: nowrap; }
@media (max-width: 1199.98px) {
  .app-navbar .navbar-collapse { padding-top: .5rem; }
  .fy-picker select { flex: 1; }
}
@media (max-width: 767.98px) {
  .app-main { padding-top: 16px; }
  .page-head h1 { font-size: 1.3rem; }
  .card-x > .card-x-body { padding: 1rem; }
  .score-bar { gap: .35rem; padding: .5rem; }
  .score-box { padding: .3rem .25rem; border-radius: 10px; }
  .score-box .lbl { font-size: .62rem; line-height: 1.2; }
  .score-box .val { font-size: 1.05rem; }
  .score-box .val small { font-size: .65rem; }
  .rank-tabs { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: .25rem; scrollbar-width: thin; }
  .rank-tab { flex-shrink: 0; }
  .modal-footer { padding: .5rem; gap: .35rem !important; }
  .modal-footer .btn { flex: 1 1 auto; font-size: .88rem; padding: .45rem .55rem; }
  .modal-footer .btn.me-auto { flex: 0 0 auto; margin-right: 0 !important; }
  .card-x-head .input-group { max-width: none !important; }
  .stat .stat-value { font-size: 1.75rem; }

  /* rubric table → cards */
  .rubric thead { display: none; }
  .rubric, .rubric tbody, .rubric tr, .rubric td { display: block; width: 100%; }
  .rubric tr { border: 1px solid var(--line); border-radius: 14px; margin-bottom: .65rem; overflow: hidden; background: #fff; }
  .rubric td { border: 0; }
  .rubric tr.group-row { border: 0; background: transparent; margin: 1rem 0 .4rem; }
  .rubric tr.group-row td { border-radius: 12px; }
  .rubric td.lv-cell { display: inline-block; width: 25%; padding: .35rem .2rem .6rem; vertical-align: top; }
  .rubric td.note-cell { display: none; }
  .lv-btn { width: 100%; height: auto; min-height: 56px; padding: .3rem .1rem; border-radius: 12px; }
  .lv-btn .mlabel { display: block; font-size: .64rem; font-weight: 500; line-height: 1.15; }

  /* responsive data table → stacked */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { border-bottom: 1px solid var(--line); padding: .65rem .25rem; }
  .table-stack td { border: 0; padding: .2rem .5rem; display: flex; justify-content: space-between; align-items: center; gap: .75rem; text-align: right; }
  .table-stack td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; font-size: .88rem; }
  .table-stack td.td-main { display: block; text-align: left; }
  .table-stack td.td-main::before { display: none; }
}

/* SweetAlert2 theming */
.swal2-popup { border-radius: 20px !important; }
.swal2-title { color: var(--navy) !important; font-weight: 800 !important; }
.swal2-confirm { background: linear-gradient(120deg, var(--indigo), var(--violet)) !important; border-radius: 11px !important; }
.swal2-cancel, .swal2-deny { border-radius: 11px !important; }
.swal2-confirm.swal-danger { background: #dc2626 !important; }
#emBody { padding-bottom: 0; }
