:root {
  --green-900: #14532d; --green-700: #15803d; --green-600: #16a34a; --green-100: #dcfce7; --green-50: #f0fdf4;
  --bg: #f6f8f6; --card: #ffffff; --border: #e4e8e4; --text: #1a2e1f; --muted: #6b7c6e;
  --amber-100: #fef3c7; --amber-700: #b45309; --amber-500: #f59e0b;
  --rose-100: #ffe4e6; --rose-700: #be123c; --rose-500: #f43f5e;
  --emerald-100: #d1fae5; --emerald-700: #047857; --emerald-500: #10b981;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans Thai', 'IBM Plex Sans Thai', Tahoma, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 230px; background: linear-gradient(180deg, var(--green-900), #0d3a1f);
  color: #e6f4ea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-icon { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; opacity: .7; }
.nav { flex: 1; padding: 14px 10px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; opacity: .55; padding: 6px 8px; }
.nav-item {
  display: block; padding: 9px 10px; border-radius: 8px; color: #d9ecdf; text-decoration: none;
  font-size: 13.5px; margin-bottom: 2px; transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: rgba(255,255,255,.16); font-weight: 600; color: #fff; }
.nav-item.muted { opacity: .6; }
.sidebar-foot { padding: 12px 16px; font-size: 10.5px; opacity: .45; }

/* ---------- topbar / main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--card);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.hamburger { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 16px; cursor: pointer; }
.page-title { font-weight: 700; font-size: 16px; }
.spacer { flex: 1; }
.content { padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }
.backdrop { display: none; }

/* ---------- company switcher ---------- */
.company-switch { position: relative; }
.company-btn {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
}
.company-btn .dot { width: 8px; height: 8px; border-radius: 50%; }
.company-menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); min-width: 230px; overflow: hidden; z-index: 50; display: none;
}
.company-menu.open { display: block; }
.company-opt { display: flex; gap: 10px; align-items: center; width: 100%; padding: 10px 14px; border: 0; background: none; cursor: pointer; font-family: inherit; font-size: 13px; text-align: left; }
.company-opt:hover { background: var(--green-50); }
.company-opt .ic { font-size: 18px; }
.company-opt .nm { font-weight: 600; }
.company-opt .sub { font-size: 11px; color: var(--muted); }
.company-opt.sel { background: var(--green-100); }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.h2 { font-size: 19px; font-weight: 700; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--card);
  border-radius: 9px; padding: 7px 14px; font-family: inherit; font-size: 13px; cursor: pointer; transition: all .15s; color: var(--text);
}
.btn:hover { border-color: var(--green-600); color: var(--green-700); }
.btn.primary { background: var(--green-600); border-color: var(--green-600); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--green-700); }
.btn.sm { padding: 3px 8px; font-size: 11.5px; border-radius: 7px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost-danger { color: var(--rose-700); border-color: #fecdd3; }
.btn.ghost-danger:hover { background: var(--rose-100); }
.btn.ghost-ok { color: var(--emerald-700); border-color: #a7f3d0; }
.btn.ghost-ok:hover { background: var(--emerald-100); }
.btn.ghost-blue { color: #1d4ed8; border-color: #bfdbfe; }
.btn.ghost-blue:hover { background: #dbeafe; }

.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select.inp, input.inp {
  height: 34px; border: 1px solid var(--border); border-radius: 9px; padding: 0 10px; font-family: inherit;
  font-size: 13px; background: var(--card); color: var(--text); min-width: 120px;
}
select.inp:focus, input.inp:focus { outline: 2px solid var(--green-100); border-color: var(--green-600); }
select.inp:disabled { opacity: .5; }
.link-clear { background: none; border: 1px dashed var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); cursor: pointer; font-family: inherit; }
.link-clear:hover { color: var(--text); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 7px 13px; font-family: inherit; font-size: 12.5px; cursor: pointer; color: var(--muted); border-left: 1px solid var(--border); }
.seg button:first-child { border-left: 0; }
.seg button.on-all { background: var(--green-700); color: #fff; font-weight: 600; }
.seg button.on-wait { background: var(--amber-500); color: #fff; font-weight: 600; }
.seg button.on-ok { background: var(--emerald-500); color: #fff; font-weight: 600; }
.seg button.on-cancel { background: var(--rose-500); color: #fff; font-weight: 600; }

/* ---------- groups & cards ---------- */
.fac-head {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 16px;
  background: var(--green-700); color: #fff; border-radius: 10px; font-weight: 600; font-size: 13.5px; margin-bottom: 10px;
}
.fac-head .meta { font-size: 11.5px; font-weight: 400; opacity: .85; }
.branch-block { margin: 0 0 16px 16px; }
.branch-head {
  display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #eceeec;
  border-radius: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px;
}
.branch-head .gpa { color: var(--text); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,.04); display: flex; flex-direction: column; transition: box-shadow .2s, background .5s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.card.hl { background: #fef9c3; }
.card-top { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px 4px; }
.card-id { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.gpa-badge { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: #ef4444; color: #fff; }
.gpa-badge.na { background: #eceeec; color: var(--muted); }
.card-mid { padding: 4px 10px 8px; flex: 1; }
.card-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.card-code { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.card-info { font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-foot { border-top: 1px solid var(--border); padding: 6px 8px; display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; align-items: center; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; font-weight: 600; margin-right: auto; }
.badge.wait { background: var(--amber-100); color: var(--amber-700); }
.badge.ok { background: var(--emerald-100); color: var(--emerald-700); }
.badge.cancel { background: var(--rose-100); color: var(--rose-700); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); background: var(--card); border: 1px solid var(--border); border-radius: 16px; }
.empty small { display: block; margin-top: 8px; font-size: 12.5px; color: #8a9a8d; }

#b55gate, #b55toast { display: none !important; }
.loading { display: flex; justify-content: center; padding: 60px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--green-100); border-top-color: var(--green-600); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast & modal ---------- */
#toastWrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px;
  opacity: 0; transform: translateY(8px); transition: all .3s; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--rose-700); }
.toast.success { background: var(--green-700); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: 16px; padding: 22px; max-width: 380px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { font-size: 15px; margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- sync badge ---------- */
.sync-note { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; z-index: 60; transition: left .25s; height: 100vh; }
  .sidebar.open { left: 0; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
  .hamburger { display: block; }
  .content { padding: 14px; }
  .branch-block { margin-left: 6px; }
}

/* ═══════════ เฟส 2: wizard / report / assess ═══════════ */

.wizard { max-width: 820px; margin: 0 auto; }
.wz-head { text-align: center; margin-bottom: 18px; position: relative; }
.wz-head .btn { position: absolute; left: 0; top: 0; }
.wz-head h2 { font-size: 19px; color: var(--green-700); }
.wz-sub { font-size: 11.5px; color: var(--muted); }

.wsteps { display: flex; justify-content: center; margin-bottom: 22px; }
.wstep { display: flex; align-items: center; }
.wstep-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wstep-dot {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid #d1d5db; background: #fff; color: #9ca3af;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.wstep-dot.on { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.wstep-lb { font-size: 11px; color: var(--muted); white-space: nowrap; }
.wstep-lb.on { color: var(--text); font-weight: 600; }
.wstep-line { height: 2px; width: 56px; background: #d1d5db; margin: 0 4px 18px; }
.wstep-line.on { background: var(--green-700); }

.wcard { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 20px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.wcard h3 { font-size: 14.5px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.wnum { width: 26px; height: 26px; border-radius: 50%; background: var(--green-700); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.wwait { text-align: center; color: var(--muted); font-size: 13px; padding: 12px 0; }
.werr { font-size: 11.5px; color: var(--rose-700); margin-top: 5px; }
.wpick { margin-top: 10px; background: var(--green-50); color: var(--green-700); border-radius: 9px; padding: 8px 12px; font-size: 13px; }
.wconfirm { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 16px; }
.wc-item { background: #f3f5f3; border-radius: 10px; padding: 10px 12px; }
.wc-lb { font-size: 11px; color: var(--muted); }
.wc-v { font-size: 13.5px; font-weight: 600; }
.wc-s { font-size: 11.5px; color: var(--muted); }

.emp-box { border: 1px solid var(--border); border-radius: 12px; max-height: 260px; min-height: 90px; overflow-y: auto; }
.emp-empty { text-align: center; color: var(--muted); font-size: 12.5px; padding: 30px 16px; }
.emp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.emp-table tr { border-bottom: 1px solid var(--border); cursor: pointer; }
.emp-table tr:last-child { border-bottom: 0; }
.emp-table tr:hover { background: #f6f8f6; }
.emp-table tr.sel { background: var(--green-50); }
.emp-table td { padding: 8px 8px; }
.emp-table .rd { width: 30px; padding-left: 12px; }
.emp-table .code { font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--muted); width: 90px; }
.emp-table .nm { font-weight: 600; }
.emp-table .mut { font-size: 11.5px; color: var(--muted); }
.radio { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--border); display: inline-block; }
.radio.on { border-color: var(--green-700); background: var(--green-700); box-shadow: inset 0 0 0 3px #fff; }

/* report / assess shared */
.rep-head { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.rep-name { font-size: 16.5px; font-weight: 700; }
.rep-sub { font-size: 13px; color: var(--muted); }
.rep-sub2 { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.rep-gpa { text-align: center; }
.rep-gpa .lb { font-size: 10.5px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }
.rep-gpa .v { font-size: 30px; font-weight: 800; color: var(--green-700); }
.rep-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.rep-subj { padding: 11px 18px; background: var(--green-50); border-bottom: 1px solid var(--border); font-weight: 700; color: var(--green-700); font-size: 14px; }
.rep-topic { padding: 8px 18px; background: #f3f5f3; border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--muted); }
.rep-row { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.rep-row:last-child { border-bottom: 0; }
.rep-q { flex: 1; min-width: 220px; }
.q-name { font-size: 13.5px; font-weight: 600; }
.q-meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.q-comment { font-size: 11.5px; color: var(--text); background: #fef9c3; border-radius: 6px; padding: 3px 8px; margin-top: 4px; display: inline-block; }
.rep-score { display: flex; align-items: center; gap: 8px; }
.rep-score .pt { font-weight: 700; font-size: 14px; min-width: 40px; text-align: center; }
.rep-score .mut { color: var(--muted); }
.gbadge { font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 99px; display: inline-block; margin-top: 3px; }
.gbadge.g5 { background: var(--emerald-100); color: var(--emerald-700); }
.gbadge.g4 { background: #dbeafe; color: #1d4ed8; }
.gbadge.g3 { background: #e0f2fe; color: #0369a1; }
.gbadge.g2 { background: var(--amber-100); color: var(--amber-700); }
.gbadge.g1 { background: #ffedd5; color: #c2410c; }
.gbadge.g0 { background: var(--rose-100); color: var(--rose-700); }
.gbadge.gnull { background: #eceeec; color: var(--muted); }

/* assess */
.assess { max-width: 860px; margin: 0 auto; }
.ainfo { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; border-radius: 12px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 14px; }
.aprog { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.aprog .bar { width: 130px; height: 6px; border-radius: 99px; background: #eceeec; overflow: hidden; }
.aprog .fill { height: 100%; background: var(--green-600); border-radius: 99px; transition: width .3s; }
.aprog span { font-size: 11px; color: var(--muted); }
.tprog { font-size: 10.5px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: #eceeec; color: var(--muted); }
.tprog.ok { background: var(--emerald-100); color: var(--emerald-700); }
.a-row { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.a-row:last-child { border-bottom: 0; }
.a-row.done { background: #f7fdf9; }
.a-q { display: flex; gap: 10px; margin-bottom: 10px; }
.a-dot { width: 20px; height: 20px; border-radius: 50%; background: #eceeec; color: var(--muted); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; }
.a-dot.ok { background: var(--emerald-500); color: #fff; }
.a-input { margin-left: 30px; }
.score-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.score-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #d1d5db; background: #fff; color: #6b7280;
  font-weight: 700; font-size: 13px; cursor: pointer; transition: all .15s; font-family: inherit;
}
.score-btn:hover:not(:disabled) { border-color: #9ca3af; }
.score-btn.sel { background: #2563eb; border-color: #2563eb; color: #fff; transform: scale(1.1); box-shadow: 0 3px 10px rgba(37,99,235,.35); }
.score-btn:disabled { opacity: .55; cursor: not-allowed; }
.score-x {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #fca5a5; background: #fff; color: #f87171;
  font-weight: 700; cursor: pointer; font-family: inherit; transition: all .15s;
}
.score-x.on { background: #ef4444; border-color: #ef4444; color: #fff; box-shadow: 0 3px 8px rgba(239,68,68,.3); }
.score-free { display: flex; gap: 6px; align-items: center; }
.a-comment { width: 100%; max-width: 460px; margin-top: 8px; font-size: 12px; height: 30px; }

/* print เฉพาะรายงาน */
@media print {
  .sidebar, .topbar, .no-print, #toastWrap, #modalWrap { display: none !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
  .rep-card, .rep-head { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
}
