/* ============================================================
   style.css — ระบบประเมินทีม S&M / TD
   ============================================================ */

/* ---------- ฟอนต์ Anuphan (self-host ใช้งานออฟไลน์ได้) ----------
   Anuphan · Cadson Demak · SIL Open Font License 1.1
   variable font น้ำหนัก 100–700 */
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url('fonts/anuphan-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url('fonts/anuphan-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Anuphan';
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url('fonts/anuphan-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font: 'Anuphan', "Segoe UI", "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
  --bg:        #f4f6fa;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e2e8f0;
  --border-2:  #cbd5e1;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --brand:     #2563eb;
  --brand-2:   #1d4ed8;
  --brand-soft:#dbeafe;
  --good:      #16a34a;
  --warn:      #d97706;
  --danger:    #dc2626;
  --grid:      #e8edf5;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.04);
  --sidebar-w: 262px;

  /* สเกลระยะห่าง ใช้ทั้งระบบให้สม่ำเสมอ */
  --sp-1: 6px; --sp-2: 10px; --sp-3: 14px; --sp-4: 18px; --sp-5: 24px; --sp-6: 32px;
  /* สเกลตัวอักษร */
  --fs-xs: 11.5px; --fs-sm: 12.5px; --fs-md: 13.5px; --fs-lg: 15px; --fs-xl: 18px;
}

html[data-theme="dark"] {
  --bg:        #0b1120;
  --surface:   #131c2e;
  --surface-2: #1a2439;
  --border:    #263349;
  --border-2:  #35455e;
  --text:      #e8eef8;
  --text-2:    #a3b1c6;
  --text-3:    #6b7c96;
  --brand:     #60a5fa;
  --brand-2:   #3b82f6;
  --brand-soft:#1e3a5f;
  --good:      #4ade80;
  --warn:      #fbbf24;
  --danger:    #f87171;
  --grid:      #22304a;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 1px 3px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

/* attribute hidden ต้องชนะกฎ display ของเราเสมอ
   (ไม่งั้น .nav button{display:flex} จะทับ hidden ทำให้ซ่อนเมนูตามสิทธิ์ไม่สำเร็จ) */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--brand); }

/* ---------- โครงหน้า ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 2px 8px 20px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-text b { display: block; font-size: 14.5px; line-height: 1.3; }
.brand-text span { font-size: 11.5px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  color: var(--text-3); padding: 18px 12px 7px;
}
.nav button {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left; padding: 11px 12px;
  background: none; border: 0; border-radius: 10px;
  color: var(--text-2); font: inherit; font-size: 14.5px; font-weight: 500;
  cursor: pointer; transition: background .12s, color .12s;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 650; }
html[data-theme="dark"] .nav button.active { color: #cfe1ff; }
.nav button .ic {
  width: 19px; height: 19px; flex: 0 0 19px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: .78;
}
.nav button.active .ic { opacity: 1; stroke-width: 2; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: var(--fs-xl); letter-spacing: -.015em; }
.topbar .sub { font-size: var(--fs-sm); color: var(--text-3); margin-top: 1px; }
.spacer { flex: 1; }
.scope-picker {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap;
}
.scope-picker select { width: auto; min-width: 150px; padding: 7px 30px 7px 9px; font-size: var(--fs-sm); }
@media (max-width: 760px) {
  .scope-picker { order: 3; width: 100%; }
  .scope-picker select { flex: 1; }
}

.content { padding: var(--sp-5) var(--sp-5) 72px; max-width: 1460px; width: 100%; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- ชิ้นส่วน ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-3);
}
.card > h3 { font-size: var(--fs-lg); margin-bottom: 3px; letter-spacing: -.005em; }
.card > .card-sub { font-size: var(--fs-sm); color: var(--text-3); margin-bottom: var(--sp-4); line-height: 1.5; }

/* ---------- Workflow รุ่น 2 ---------- */
.wf-chip {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font-size: 11px; font-weight: 650; white-space: nowrap;
}
.wf-chip.info { color: var(--brand-2); background: color-mix(in srgb, var(--brand) 12%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 28%, var(--border)); }
.wf-chip.success { color: var(--good); background: color-mix(in srgb, var(--good) 11%, var(--surface)); border-color: color-mix(in srgb, var(--good) 25%, var(--border)); }
.wf-chip.warning { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 28%, var(--border)); }

.wf-pipeline {
  display: grid; grid-template-columns: repeat(7, minmax(110px,1fr)); gap: 7px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; margin-bottom: var(--sp-3); box-shadow: var(--shadow); overflow-x: auto;
}
.wf-stage { display: flex; align-items: center; gap: 7px; min-width: 110px; padding: 7px 9px; border-radius: 9px; color: var(--text-3); font-size: 11.5px; font-weight: 600; }
.wf-stage b { width: 22px; height: 22px; display: grid; place-items: center; flex: 0 0 22px; border-radius: 7px; background: var(--surface-2); }
.wf-stage.done { color: var(--good); background: color-mix(in srgb, var(--good) 7%, transparent); }
.wf-stage.next { color: var(--warn); background: color-mix(in srgb, var(--warn) 6%, transparent); }

.wf-hero { border-left: 4px solid var(--brand); }
.wf-progress { height: 9px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.wf-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--brand),#7c3aed); }
.wf-progress-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--text-3); font-size: var(--fs-xs); }
.wf-progress-meta b { color: var(--text-2); }

.wf-template-list { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 10px; }
.wf-template-card, .wf-cycle-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 7px; text-align: left;
  padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2);
  color: var(--text); font: inherit; cursor: pointer;
}
.wf-template-card:hover, .wf-cycle-item:hover { border-color: var(--border-2); background: var(--surface); }
.wf-template-card.selected, .wf-cycle-item.selected { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); background: color-mix(in srgb,var(--brand) 5%,var(--surface)); }
.wf-template-card b, .wf-cycle-item b { line-height: 1.4; }
.wf-template-card small, .wf-cycle-item small { color: var(--text-3); }
.wf-section { margin-top: 18px; border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.wf-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.wf-section-head b, .wf-section-head span { display: block; }
.wf-section-head > div > span { color: var(--text-3); font-size: var(--fs-xs); margin-top: 2px; }

.wf-cycle-layout { grid-template-columns: minmax(245px,.65fr) minmax(0,2fr); align-items: start; }
.wf-cycle-list { display: flex; flex-direction: column; gap: 8px; }
.wf-status-select { min-width: 175px !important; }
.wf-assignment-picker {
  display: grid; grid-template-columns: minmax(140px,220px) minmax(280px,1fr); align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: var(--sp-3); box-shadow: var(--shadow);
}
.wf-assignment-picker .fl { margin: 0; }
.wf-review-head { border-left: 4px solid #7c3aed; }
.wf-review-list { display: flex; flex-direction: column; gap: 10px; }
.wf-review-question { border: 1px solid var(--border); border-radius: 11px; padding: 14px; background: var(--surface-2); }
.wf-q-title { display: flex; justify-content: space-between; gap: 12px; }
.wf-q-title span { color: var(--text-3); font-size: var(--fs-xs); }
.wf-score-entry { display: grid; grid-template-columns: 110px 130px; align-items: center; gap: 10px; margin-top: 10px; }
.wf-score-entry label { color: var(--text-2); font-size: var(--fs-sm); }
.wf-score-entry input { font-size: 18px; font-weight: 700; }
.wf-sticky-actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; }
.wf-manager-grid { display: grid; grid-template-columns: minmax(240px,1.4fr) minmax(120px,.45fr) minmax(150px,.55fr); gap: 12px; align-items: center; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.wf-manager-head { color: var(--text-3); font-size: var(--fs-xs); font-weight: 650; background: var(--surface-2); border-radius: 9px 9px 0 0; }
.wf-score-big { font-size: 20px; }
.wf-cal-score { width: 82px !important; min-width: 82px !important; text-align: right; font-weight: 700; }
@media (max-width: 900px) {
  .wf-cycle-layout { grid-template-columns: 1fr; }
  .wf-progress-meta { flex-wrap: wrap; }
  .wf-manager-grid { grid-template-columns: 1fr 100px 120px; }
}
@media (max-width: 620px) {
  .wf-assignment-picker { grid-template-columns: 1fr; }
  .wf-manager-grid { grid-template-columns: 1fr 1fr; }
  .wf-manager-grid > :first-child { grid-column: 1 / -1; }
  .wf-sticky-actions { align-items: flex-start; flex-direction: column; }
}

.grid { display: grid; gap: var(--sp-3); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* c4/c5 เติมเต็มแถวเสมอ ไม่เหลือการ์ดโดดเดี่ยว */
.grid.c4, .grid.c5 { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
@media (max-width: 900px) { .grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); } }
@media (max-width: 780px) { .grid.c2 { grid-template-columns: 1fr; } }

/* ตัวเลขสรุป */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow); min-width: 0;
}
.stat .k { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }
.stat .v {
  font-size: 25px; font-weight: 700; line-height: 1.3; margin-top: 3px;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat .v small { font-size: 12.5px; font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.stat .d { font-size: var(--fs-xs); margin-top: 3px; color: var(--text-2); }

.delta-up   { color: var(--good); font-weight: 600; }
.delta-down { color: var(--danger); font-weight: 600; }
.delta-flat { color: var(--text-3); font-weight: 600; }

/* ตาราง */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
/* ตารางที่ต้อง "พอดีหน้า" ไม่มีแถบเลื่อนแนวนอน */
table.fit { table-layout: auto; width: 100%; }
table.fit th, table.fit td { padding-left: 9px; padding-right: 9px; }
table.fit td.wrap, table.fit th.wrap { min-width: 0; white-space: normal; }
table.fit .score-in { width: 100%; min-width: 52px; max-width: 76px; }
table.fit .person span { display: none; }          /* ซ่อนตำแหน่งใต้ชื่อ ประหยัดความกว้าง */
@media (min-width: 1500px) { table.fit .person span { display: block; } }
/* คอลัมน์ข้อความยาว ๆ (JD / หมายเหตุ) ให้ตัดบรรทัดแทนดันตารางออกนอกจอ */
table.fit td.wrap textarea, table.fit td.wrap input { min-width: 0; width: 100%; }
table.fit .cell { min-width: 0; }
table.fit input.cell[style*="min-width"] { min-width: 0 !important; }

/* สวิตช์เล็กในหัวการ์ด */
.tgl {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tgl input { width: auto; margin: 0; cursor: pointer; }

/* ---------- สิทธิ์ / การรับรองผล ---------- */
.role-card {
  border: 1px solid var(--border); border-left: 3px solid var(--rc);
  border-radius: 10px; padding: var(--sp-3) var(--sp-4); background: var(--surface-2);
}
.role-sel { min-width: 148px; font-size: var(--fs-sm); }

/* ช่องที่ถูกล็อกเป็นอ่านอย่างเดียวตามสิทธิ์ */
.ro, input.ro, textarea.ro, select.ro {
  background: transparent; border-color: transparent;
  color: var(--text); cursor: default; pointer-events: none;
}
.ro:focus { outline: none; }

/* ฟอร์มย่อยในการ์ด — แยกให้เห็นชัดว่าเป็นคนละเรื่องกับส่วนอื่น */
.subform {
  margin-top: var(--sp-4); padding-top: var(--sp-4);
  border-top: 1px dashed var(--border-2);
}
.subform-title { font-size: var(--fs-md); font-weight: 650; margin-bottom: var(--sp-3); }
.subform-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end; }
.subform-row .field { flex: 1 1 190px; margin-bottom: 0; }
.subform-row .field .btn { width: 100%; justify-content: center; }

.cert-card { border-left: 3px solid var(--border-2); }
.cert-card.is-cert {
  border-left-color: var(--good);
  background: color-mix(in srgb, var(--good) 7%, var(--surface));
}
.cert-card.is-cert h3 { color: var(--good); }

#roleChip .badge { font-size: 11px; padding: 3px 10px; }

/* ช่องรหัสอ้างอิง */
input.code-in {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px; color: var(--text-2); min-width: 96px; max-width: 130px;
}
input.code-in:focus { color: var(--text); }
code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px; font-size: 12px;
}
table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); background: var(--surface); }
th, td { padding: 10px 13px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th {
  background: var(--surface-2); font-size: var(--fs-xs); font-weight: 650; color: var(--text-2);
  position: sticky; top: 0; letter-spacing: .01em; line-height: 1.35;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total-row td { background: var(--surface-2); font-weight: 650; }
td.wrap, th.wrap { white-space: normal; min-width: 220px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: #fff; white-space: nowrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.chip.partial {
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  border-color: transparent; color: var(--warn); font-weight: 600;
  padding: 2px 7px; font-size: 11px; margin-left: 4px; cursor: help;
}
.chip-x {
  border: 0; background: transparent; color: var(--text-3); cursor: pointer;
  font: inherit; font-size: 15px; line-height: 1; padding: 0 0 0 2px;
}
.chip-x:hover { color: var(--danger); }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px;
}
.person { display: flex; align-items: center; gap: 9px; }
.person b { font-weight: 600; }
.person span { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; }

/* ฟอร์ม */
label.fl { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-2); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
textarea { resize: vertical; min-height: 74px; line-height: 1.6; }
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
input.score-in { width: 74px; font-weight: 600; }
input.cell { border-color: transparent; background: transparent; padding: 4px 6px; }
input.cell:hover { border-color: var(--border-2); background: var(--surface); }
.field { margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

select.inline { width: auto; min-width: 160px; }

/* แถบคะแนนในตาราง */
.bar { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; border-radius: 4px; }

/* กล่องข้อความอัตโนมัติ */
.callout {
  border-left: 3px solid var(--brand); background: var(--surface-2);
  padding: 11px 14px; border-radius: 0 9px 9px 0; font-size: 13px; color: var(--text-2); line-height: 1.7;
}
.flag { display: flex; gap: 8px; align-items: flex-start; padding: 8px 11px; border-radius: 8px; font-size: 12.5px; margin-bottom: 6px; }
.flag.good   { background: color-mix(in srgb, var(--good) 12%, transparent);   color: var(--good); }
.flag.warn   { background: color-mix(in srgb, var(--warn) 14%, transparent);   color: var(--warn); }
.flag.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.flag.info   { background: var(--surface-2); color: var(--text-2); }

.empty { text-align: center; padding: 36px 16px; color: var(--text-3); font-size: 13px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

.hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: 4px; line-height: 1.55; }
.stat-k { font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 1px; }
.warn-box { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); padding: 9px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }

/* ---------- กราฟ ---------- */
.c-wrap { width: 100%; }
svg.chart { width: 100%; height: auto; display: block; }
svg text { font-family: inherit; }
svg .ax { font-size: 10.5px; fill: var(--text-3); }
svg .ax-b { font-size: 11.5px; font-weight: 550; fill: var(--text-2); }
svg .vl { font-size: 10.5px; font-weight: 650; }

.c-legend {
  display: flex; gap: var(--sp-3); flex-wrap: wrap;
  font-size: var(--fs-xs); color: var(--text-2); margin-top: var(--sp-2);
}
.c-legend span { display: inline-flex; align-items: center; gap: 5px; }
.c-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.c-bars { display: flex; flex-direction: column; gap: var(--sp-3); }
.c-bar-row {
  display: grid; grid-template-columns: minmax(150px, 240px) minmax(0, 1fr) 48px;
  align-items: center; gap: var(--sp-4);
}
/* ชื่อบรรทัดแรก น้ำหนักบรรทัดสอง — กันตัดคำไทยกลางคำ */
.c-bar-label { display: flex; flex-direction: column; gap: 1px; min-width: 0; line-height: 1.4; }
.c-bar-label .n { font-size: var(--fs-md); color: var(--text); }
.c-bar-label .s { font-size: var(--fs-xs); color: var(--text-3); }
.c-bar-track { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.c-bar-track > i { display: block; height: 100%; border-radius: 4px; transition: width .25s ease; }
.c-bar-val { font-size: var(--fs-sm); text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 620px) { .c-bar-row { grid-template-columns: 1fr 46px; } .c-bar-track { grid-column: 1 / -1; } }

.c-stack {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  background: var(--surface-2);
}
.muted { color: var(--text-3); }

/* ---------- ตัวกรองรอบ / หัวข้อส่วน ---------- */
.period-filter { display: inline-flex; align-items: center; gap: 8px; }
.period-filter .pf-label { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.period-filter select { font-weight: 600; }

.card-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head > div:first-child { flex: 1; min-width: 240px; }

.section-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 30px 0 14px; padding-top: 20px;
  border-top: 2px solid var(--border);
}
.section-head > div:first-child { flex: 1; min-width: 220px; }
.section-head h2 { font-size: 17px; }
.section-head .section-sub { font-size: 12.5px; color: var(--text-3); }

/* ---------- รูปโปรไฟล์ ---------- */
.avatar.photo { object-fit: cover; border: 2px solid; padding: 0; }

.portrait { position: relative; width: 100%; }
.portrait-frame {
  position: relative; width: 100%; aspect-ratio: 4 / 5;
  border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(15,23,42,.08), 0 12px 30px rgba(15,23,42,.10);
  background: var(--surface-2);
}
html[data-theme="dark"] .portrait-frame { box-shadow: 0 12px 32px rgba(0,0,0,.45); }
/* รูปวางแบบ absolute แล้วเลื่อนด้วย left/top + translate → ลากได้จริงทุกทิศ
   ขนาดถูกตั้งจาก JS (fitCover) ให้ "คลุมกรอบ" พอดี ไม่ใช่ขนาดธรรมชาติเต็ม
   เพราะถ้าใช้ min-width/min-height รูปจะใหญ่เกินและคำนวณขอบเขตลากไม่ตรง */
.portrait-frame img {
  position: absolute;
  max-width: none; max-height: none;
  display: block; transform-origin: center;
  user-select: none; -webkit-user-drag: none;
}
.portrait-frame img[data-drag] { cursor: grab; }
.portrait-frame img[data-drag].dragging { cursor: grabbing; }
.portrait .portrait-empty {
  width: 100%; height: 100%;
  display: grid; place-content: center; gap: 6px; text-align: center; color: #fff;
}
.portrait .portrait-empty span { font-size: 46px; font-weight: 700; letter-spacing: .02em; }
.portrait .portrait-empty small { font-size: 12px; opacity: .85; }

.portrait-tools { display: flex; gap: 6px; margin-top: var(--sp-2); }
.portrait-adjust {
  margin-top: var(--sp-2); padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.portrait-adjust .pa-hint { font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 5px; }
.portrait-adjust .pa-row { display: flex; align-items: center; gap: 9px; font-size: var(--fs-xs); color: var(--text-2); }
.portrait-adjust .pa-row input[type="range"] { flex: 1; padding: 0; border: 0; background: transparent; }

/* เซลล์คะแนนรายเดือน + อัตราขึ้นลงประกบใต้ตัวเลข */
td.mom { line-height: 1.3; padding-top: 8px; padding-bottom: 8px; }
td.mom > b { display: block; font-variant-numeric: tabular-nums; }
td.mom .mom-d { display: block; font-size: 10.5px; font-weight: 600; margin-top: 1px; white-space: nowrap; }
td.mom .mom-d.up { color: var(--good); }
td.mom .mom-d.down { color: var(--danger); }
td.mom .mom-d.flat { color: var(--text-3); font-weight: 500; }

/* แถวที่คลิกไปแก้คะแนนได้ */
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--brand-soft); }
.rowgo { font-size: var(--fs-xs); color: var(--brand-2); font-weight: 600; opacity: 0; white-space: nowrap; }
tr.rowlink:hover .rowgo { opacity: 1; }

/* เซลล์ที่ระบบคำนวณเอง — แก้ไขไม่ได้ ต้องดูออกทันทีว่าต่างจากช่องกรอก */
td.calc {
  background: var(--surface-2);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
td.calc.total { color: var(--text); }
tbody tr:hover td.calc { background: var(--surface-2); }

.profile-head { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.profile-photo { width: 300px; flex: 0 0 300px; }
.profile-meta { flex: 1; min-width: 280px; }
.profile-top { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.profile-name { font-size: 27px; line-height: 1.2; }
.profile-role { color: var(--text-2); font-size: 14px; }

.profile-score {
  display: flex; gap: 22px; flex-wrap: wrap; align-items: center;
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border);
}
.profile-score .k { font-size: 11.5px; color: var(--text-3); }
.ps-main { min-width: 172px; }
.ps-num { font-size: 46px; font-weight: 750; line-height: 1.15; }
.ps-num small { font-size: 15px; font-weight: 500; color: var(--text-3); }
.ps-grid {
  flex: 1; min-width: 260px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 12px 18px;
}
.ps-grid b { font-size: 13.5px; }

@media (max-width: 720px) {
  .profile-photo { width: 100%; flex: 0 0 auto; max-width: 320px; margin: 0 auto; }
}

.photo-cell { display: flex; align-items: center; gap: 8px; }
.thumb45 {
  width: 44px; height: 55px; flex: 0 0 44px;
  object-fit: cover; border-radius: 7px; border: 1px solid var(--border);
}
.thumb45.empty { display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }

/* ---------- หน้าล็อกอิน ---------- */
.app-loading {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: #f4f7fb;
  color: #64748b;
  font-size: 13px;
}
.gate-wrap {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(500px, 42%) minmax(0, 1fr);
  background: #f4f7fb;
  color: #0f172a;
}

.gate-card {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(38px, 6vh, 72px) clamp(42px, 5vw, 80px);
  background: #fff;
  border-right: 1px solid #d8e0ea;
  box-shadow: 18px 0 48px rgba(15, 23, 42, .08);
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
}
.gate-context {
  width: max-content;
  margin-bottom: 22px;
  padding: 5px 10px;
  border: 1px solid #d8e0ea;
  border-radius: 999px;
  color: #64748b;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
}
.gate-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 34px; }
.gate-card .brand-mark {
  width: 52px !important;
  height: 52px !important;
  flex: 0 0 52px;
  border-radius: 13px !important;
  background: linear-gradient(145deg, #1d4ed8, #173a77);
  box-shadow: 0 8px 22px rgba(29, 78, 216, .2);
  color: #fff;
  font-size: 15px !important;
  letter-spacing: .02em;
}
.gate-card .gate-brand > div:last-child { min-width: 0; }
.gate-card .gate-brand b,
.gate-card .gate-brand span { display: block; }
.gate-card .gate-brand b { color: #0f172a; font-size: 18px !important; line-height: 1.35; letter-spacing: -.015em; }
.gate-card .gate-brand span { margin-top: 2px; color: #64748b; font-size: 12.5px; }
.gate-card h1 { margin: 0 0 4px; color: #0f172a; font-size: 24px; font-weight: 650; line-height: 1.35; letter-spacing: -.02em; }
.gate-card label.fl { color: #334155; font-size: 12.5px; font-weight: 600; }
.gate-card input {
  min-height: 46px;
  padding: 11px 13px;
  background: #fff;
  border-color: #cbd5e1;
  color: #0f172a;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.gate-card input::placeholder { color: #94a3b8; }
.gate-card input:focus {
  border-color: #2563eb;
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.gate-card .btn.primary {
  min-height: 46px;
  padding: 11px 16px;
  background: #1d4ed8;
  border-color: #1d4ed8;
  font-size: 14px;
  font-weight: 650;
}
.gate-card .btn.primary:hover { background: #1e40af; border-color: #1e40af; }
.gate-card .btn.primary:focus-visible { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; }
.gate-err {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 12.5px;
}
.gate-success {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #f0fdf4;
  color: #166534;
  font-size: 12.5px;
}
.gate-note {
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  color: #64748b;
  font-size: 11.5px;
  line-height: 1.7;
  text-align: left;
}
.gate-prepared {
  display: grid;
  gap: 3px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: #f0fdf4;
  color: #166534;
}
.gate-prepared b { font-size: 12.5px; }
.gate-prepared span { font-size: 11px; line-height: 1.6; }
.gate-card code {
  padding: 1px 5px;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
  background: #f8fafc;
  color: #334155;
  font-size: 11.5px;
}
.gate-footer {
  margin-top: 24px;
  color: #94a3b8;
  font-size: 10.5px;
  line-height: 1.6;
}
.gate-official {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  overflow: hidden;
  padding: clamp(48px, 7vw, 112px);
  background:
    radial-gradient(circle at 86% 18%, rgba(96, 165, 250, .25), transparent 30%),
    radial-gradient(circle at 12% 88%, rgba(29, 78, 216, .28), transparent 32%),
    linear-gradient(145deg, #0b1f3a 0%, #11345b 56%, #174a78 100%);
  color: #fff;
}
.gate-official::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(135deg, rgba(0,0,0,.7), transparent 75%);
  pointer-events: none;
}
.gate-official::after {
  content: "";
  position: absolute;
  width: min(42vw, 620px);
  aspect-ratio: 1;
  right: -18%;
  bottom: -34%;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 50%;
  box-shadow: 0 0 0 80px rgba(255,255,255,.025), 0 0 0 160px rgba(255,255,255,.018);
}
.gate-official-content { position: relative; z-index: 1; max-width: 760px; }
.gate-kicker {
  margin-bottom: 18px;
  color: #bfdbfe;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .08em;
}
.gate-official h2 {
  max-width: 720px;
  color: #fff;
  font-size: clamp(34px, 4vw, 58px);
  font-weight: 650;
  line-height: 1.24;
  letter-spacing: -.035em;
}
.gate-official-content > p {
  max-width: 660px;
  margin: 24px 0 0;
  color: #cbd5e1;
  font-size: clamp(14px, 1.2vw, 17px);
  line-height: 1.9;
}
.gate-benefits {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 38px;
}
.gate-benefits > div {
  min-height: 142px;
  padding: 20px 18px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(8px);
}
.gate-benefits span {
  display: block;
  width: 8px;
  height: 8px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: #60a5fa;
  box-shadow: 0 0 0 5px rgba(96,165,250,.14);
}
.gate-benefits b,
.gate-benefits small { display: block; }
.gate-benefits b { color: #fff; font-size: 14px; }
.gate-benefits small { margin-top: 7px; color: #bfcee0; font-size: 11px; line-height: 1.65; }
.gate-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 30px;
  color: #bfcee0;
  font-size: 11px;
}
.gate-trust span::before { content: ""; display: inline-block; width: 4px; height: 4px; margin: 0 8px 2px 0; border-radius: 50%; background: #93c5fd; }

@media (max-width: 1100px) {
  .gate-wrap { grid-template-columns: minmax(460px, 48%) minmax(0, 1fr); }
  .gate-card { padding-inline: clamp(36px, 5vw, 58px); }
  .gate-official { padding: 52px; }
  .gate-official h2 { font-size: clamp(30px, 4vw, 44px); }
  .gate-benefits { grid-template-columns: 1fr; }
  .gate-benefits > div { min-height: 0; }
}

@media (max-width: 820px) {
  .gate-wrap { display: block; }
  .gate-card {
    width: min(100%, 620px);
    margin: 0 auto;
    border-right: 0;
    box-shadow: 0 0 48px rgba(15,23,42,.08);
  }
  .gate-official { display: none; }
}

@media (max-width: 560px) {
  .gate-card {
    width: 100%;
    justify-content: flex-start;
    padding: 30px 22px 26px;
  }
  .gate-context { margin-bottom: 18px; }
  .gate-brand { margin-bottom: 28px; }
  .gate-card .brand-mark { width: 46px !important; height: 46px !important; flex-basis: 46px; }
  .gate-card .gate-brand b { font-size: 16px !important; }
  .gate-card h1 { font-size: 21px; }
  .gate-card input { min-height: 48px; font-size: 16px; }
  .gate-card .btn.primary { min-height: 48px; }
  .gate-footer { margin-top: 22px; }
}

@media (max-height: 760px) {
  .gate-card { justify-content: flex-start; padding-block: 28px; }
}
#gate:empty { display: none; }

/* toast */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* พิมพ์ */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ddd; }
  .view { display: none !important; }
  .view.active { display: block !important; }
  /* เมื่อมีรายงาน PDF: ซ่อนแอปทั้งหมด แสดงเฉพาะรายงาน */
  body.printing .app { display: none !important; }
  body.printing #printRoot { display: block !important; }
  /* กันเนื้อหาถูกตัดกลางบล็อกเวลาข้ามหน้า (แก้ "หน้าขาด") */
  .rpt-stats, .rpt-chartbox, .rpt-2col, .rpt-2col > div,
  .rpt-sign, .rpt-signer, .rpt table tr, .rpt table thead { break-inside: avoid; page-break-inside: avoid; }
  .rpt h3 { break-after: avoid; page-break-after: avoid; }
}

/* ============ รายงาน PDF รายบุคคล (A4) ============ */
#printRoot { display: none; }
@page { size: A4; margin: 14mm 14mm 16mm; }

.rpt {
  font-family: var(--font);
  color: #111; background: #fff;
  width: 182mm; margin: 0 auto;
  font-size: 11px; line-height: 1.5;
  /* บังคับสีกราฟให้พิมพ์ออกมาถูกเสมอ ไม่ว่าจอจะเป็นธีมมืดหรือสว่าง */
  --grid: #e3e3e8; --surface: #fff; --surface-2: #f4f4f6;
  --text: #222; --text-2: #555; --text-3: #999;
  --good: #157a3e; --danger: #b0201f; --brand: #4f75d1; --brand-2: #3a5cb0;
}
.rpt .chart { max-width: 100%; height: auto; }
.rpt .c-legend { display: flex; gap: 12px; justify-content: center; font-size: 9.5px; color: #666; margin-top: 4px; }
.rpt .c-legend span { display: inline-flex; align-items: center; gap: 4px; }
.rpt .c-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.rpt svg .ax { font-size: 9px; fill: #999; }
.rpt svg .ax-b { font-size: 9.5px; fill: #555; }
.rpt svg .vl { font-size: 9px; font-weight: 700; }
.rpt-chartbox { border: 1px solid #eee; border-radius: 6px; padding: 8px 10px; break-inside: avoid; }
/* การ์ดสถิติในรายงาน */
.rpt-stats { display: flex; gap: 6px; margin: 10px 0 4px; }
.rpt-sc { flex: 1; border: 1px solid #e5e5e9; border-radius: 6px; padding: 6px 9px; }
.rpt-sc .k { font-size: 8px; color: #888; }
.rpt-sc .v { font-size: 15px; font-weight: 750; line-height: 1.2; margin-top: 1px; }
.rpt-sc .d { font-size: 8px; color: #888; margin-top: 1px; }
/* อัตราขึ้น–ลงใต้ตัวเลข (▲▼) แบบเดียวกับในระบบ */
.rpt .rd { display: block; font-size: 8px; font-weight: 700; margin-top: 1px; }
.rpt .rd.u { color: #157a3e; } .rpt .rd.d { color: #b0201f; } .rpt .rd.z { color: #999; font-weight: 500; }
.rpt-badge { display: inline-block; font-size: 8.5px; font-weight: 700; color: #fff; padding: 1px 8px; border-radius: 999px; }
.rpt .u { color: #157a3e; } .rpt .d-neg { color: #b0201f; }
.rpt * { box-sizing: border-box; }
.rpt .rpt-head {
  display: flex; align-items: flex-start; gap: 14px;
  border-bottom: 2.5px solid #2563eb; padding-bottom: 12px; margin-bottom: 16px;
}
.rpt .rpt-logo {
  width: 44px; height: 44px; border-radius: 10px; flex: 0 0 44px;
  background: linear-gradient(135deg, #3b6fd4, #1e3a8a);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.rpt .rpt-title b { font-size: 16px; display: block; letter-spacing: -.01em; color: #16264f; }
.rpt .rpt-title span { font-size: 10px; color: #666; }
.rpt .rpt-doctype { margin-top: 6px; font-size: 11px; font-weight: 700; color: #1d4ed8; line-height: 1.35; }
.rpt .rpt-meta { margin-left: auto; text-align: right; font-size: 10px; color: #555; line-height: 1.75; }
.rpt .rpt-conf {
  display: inline-block; font-size: 8.5px; font-weight: 700; letter-spacing: .08em;
  color: #b0201f; border: 1px solid #e6b3b3; border-radius: 4px;
  padding: 1px 7px; margin-bottom: 5px;
}

.rpt-person { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 10px; }
.rpt-photo {
  width: 30mm; flex: 0 0 30mm; border-radius: 8px; overflow: hidden;
  border: 1px solid #ddd; background: #f2f2f4; align-self: flex-start;
}
/* แสดงรูปเต็มทั้งใบตามสัดส่วนจริง ไม่ครอป */
.rpt-photo img { width: 100%; height: auto; display: block; }
.rpt-photo .ph {
  width: 100%; aspect-ratio: 4 / 5; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 30px;
}
.rpt-id { flex: 1; }
.rpt-id .nm { font-size: 22px; font-weight: 750; line-height: 1.1; }
.rpt-id .po { font-size: 12px; color: #444; margin-top: 2px; }
.rpt-id .kf {
  display: inline-block; margin-top: 7px; font-size: 10px; color: #444;
  border: 1px solid #ddd; border-radius: 999px; padding: 2px 9px;
}
.rpt-score { display: flex; gap: 18px; align-items: baseline; margin-top: 11px; }
.rpt-score .big { font-size: 34px; font-weight: 800; line-height: 1; }
.rpt-score .lvl { font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 999px; color: #fff; }
.rpt-kv { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 10px; }
.rpt-kv > div { font-size: 10.5px; }
.rpt-kv .k { color: #777; }
.rpt-kv b { font-size: 13px; }

.rpt h3 {
  font-size: 12px; font-weight: 700; color: #1d4ed8;
  border-left: 3px solid #2563eb; padding-left: 8px; margin: 11px 0 6px;
  break-after: avoid;
}
.rpt .callout {
  border-left: 3px solid #ccc; background: #f7f7f8; color: #333;
  padding: 8px 11px; border-radius: 0 6px 6px 0; font-size: 10.5px; line-height: 1.7;
}
.rpt table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 10px; break-inside: auto; }
.rpt th, .rpt td { border: 1px solid #e2e2e2; padding: 4px 6px; text-align: right; overflow-wrap: anywhere; word-break: break-word; }
.rpt td.l, .rpt th.l { width: 30%; }
.rpt th { background: #f3f3f5; color: #333; font-weight: 700; }
.rpt td.l, .rpt th.l { text-align: left; }
.rpt tr.tot td { background: #eef3fc; font-weight: 700; }
.rpt .updn.u { color: #157a3e; } .rpt .updn.d { color: #b0201f; }
.rpt-bars { display: flex; flex-direction: column; gap: 6px; }
.rpt-bar { display: grid; grid-template-columns: 46mm 1fr 12mm; gap: 8px; align-items: center; font-size: 10px; }
.rpt-bar .tr { height: 7px; background: #eee; border-radius: 4px; overflow: hidden; }
.rpt-bar .tr > i { display: block; height: 100%; border-radius: 4px; }
.rpt-bar b { text-align: right; }
.rpt-2col { display: flex; gap: 16px; }
.rpt-2col > div { flex: 1 1 0; min-width: 0; }
.rpt-2col.rpt-page2 { margin-top: 4px; }
.rpt-sign { display: flex; gap: 40px; margin-top: 16px; break-inside: avoid; justify-content: center; }
.rpt-signer { flex: 0 1 240px; text-align: center; }
.rpt-signer .sig-wrap { height: 60px; display: flex; align-items: flex-end; justify-content: center; }
.rpt-signer .sig-wrap svg.sig { display: block; }
.rpt-signer .sig-wrap .sig-img { display: block; height: 58px; width: auto; max-width: 200px; object-fit: contain; mix-blend-mode: multiply; }
.rpt-signer .sig-line { border-top: 1px solid #333; margin: 2px 6px 6px; }
.rpt-signer .sig-nm { font-size: 11px; font-weight: 700; color: #16264f; }
.rpt-signer .sig-ti { font-size: 10px; color: #444; margin-top: 1px; }
.rpt-signer .sig-or { font-size: 9.5px; color: #777; }
.rpt-signer .sig-dt { font-size: 9.5px; color: #555; margin-top: 5px; }

.rpt-foot {
  margin-top: 12px; padding-top: 8px; border-top: 2px solid #2563eb;
  font-size: 9px; color: #777; text-align: center; line-height: 1.7;
}
.rpt-foot b { color: #16264f; }

/* ============ Foundation v3: พื้นที่ทำงานตามบทบาท ============ */
.v3-role-banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 13px 16px; margin-bottom: var(--sp-3); border: 1px solid var(--line);
  border-radius: var(--r-lg); background: linear-gradient(120deg, var(--surface), var(--surface-2));
}
.v3-role-banner > div { display: flex; align-items: center; gap: 10px; }
.v3-role-banner b { display: block; font-size: var(--fs-lg); }
.v3-role-banner span { color: var(--text-3); font-size: var(--fs-sm); }
.v3-kpis .stat.v3-alert { border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); background: color-mix(in srgb, var(--warn) 7%, var(--surface)); }
.v3-kpis .stat.v3-good { border-color: color-mix(in srgb, var(--good) 30%, var(--line)); background: color-mix(in srgb, var(--good) 6%, var(--surface)); }
.v3-task-list { display: flex; flex-direction: column; }
.v3-task {
  display: grid; grid-template-columns: 34px minmax(220px,1fr) 130px 150px auto;
  align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line);
}
.v3-task:first-child { border-top: 0; }
.v3-task.urgent { margin: 3px 0; padding-left: 9px; padding-right: 9px; border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); border-radius: var(--r-md); background: color-mix(in srgb, var(--warn) 7%, var(--surface)); }
.v3-task-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-2); color: var(--brand); font-weight: 850; }
.v3-task > div:nth-child(2) b { display: block; font-size: var(--fs-md); }
.v3-task > div:nth-child(2) span, .v3-task-due span { display: block; color: var(--text-3); font-size: var(--fs-xs); }
.v3-task-due b { display: block; font-size: var(--fs-sm); }
.v3-timeline { display: grid; grid-template-columns: repeat(6, 1fr); padding: 8px 6px 2px; }
.v3-timeline > div { position: relative; text-align: center; color: var(--text-3); font-size: var(--fs-xs); padding-top: 28px; }
.v3-timeline > div:not(:last-child):after { content: ''; position: absolute; left: 50%; right: -50%; top: 11px; height: 3px; background: var(--line); }
.v3-timeline i { position: absolute; z-index: 1; top: 4px; left: 50%; width: 17px; height: 17px; border: 4px solid var(--surface); border-radius: 50%; background: var(--line); transform: translateX(-50%); box-shadow: 0 0 0 1px var(--line); }
.v3-timeline .done { color: var(--good); }
.v3-timeline .done:after, .v3-timeline .done i { background: var(--good); }
.v3-timeline .current { color: var(--warn); font-weight: 800; }
.v3-timeline .current i { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 20%, transparent); }
.v3-cycle-select { min-width: 280px; }
.v3-funnel { display: grid; grid-template-columns: 1.2fr 1.05fr .9fr .75fr .65fr; gap: 7px; }
.v3-funnel > div { position: relative; min-height: 78px; display: grid; place-content: center; text-align: center; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.v3-funnel > div:after { content: '›'; position: absolute; right: -8px; top: 25px; z-index: 2; color: var(--text-3); font-size: 22px; }
.v3-funnel > div:last-child:after { display: none; }
.v3-funnel b { font-size: 24px; line-height: 1; color: var(--brand); }
.v3-funnel span { margin-top: 5px; color: var(--text-3); font-size: var(--fs-xs); }
.v3-level-bars { display: grid; gap: 14px; margin-top: 16px; }
.v3-level-bars > div > span { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-sm); }
.v3-level-bars > div > span i { width: 9px; height: 9px; border-radius: 3px; }
.v3-level-bars > div > b { float: right; font-size: var(--fs-sm); }
.v3-insight { margin: 16px 0; padding: 16px; border-left: 4px solid var(--brand); border-radius: 0 var(--r-md) var(--r-md) 0; background: var(--surface-2); }
.v3-insight b, .v3-insight span { display: block; }
.v3-insight span { margin-top: 7px; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.6; }
.v3-readonly { padding: 10px 12px; border-radius: var(--r-md); background: color-mix(in srgb, #7c3aed 8%, var(--surface)); color: #6d4baa; font-size: var(--fs-sm); }

@media (max-width: 980px) {
  .v3-task { grid-template-columns: 34px minmax(180px,1fr) auto; }
  .v3-task-due { display: none; }
  .v3-task > div:nth-child(4) { display: none; }
  .v3-funnel { grid-template-columns: repeat(5, minmax(100px,1fr)); overflow-x: auto; padding-bottom: 6px; }
}
@media (max-width: 620px) {
  .v3-role-banner { align-items: flex-start; }
  .v3-task { grid-template-columns: 30px 1fr auto; gap: 7px; }
  .v3-task > div:nth-child(2) b { font-size: var(--fs-sm); }
  .v3-timeline { min-width: 600px; }
  .v3-timeline-card { overflow-x: auto; }
  .v3-cycle-select { min-width: 0; width: 100%; }
}
