/* ============================================================
   style.css — โครงสร้าง component (copy ไปวางที่ root โปรเจกต์)

   - ใช้ token จาก theme.css เท่านั้น: ห้ามเขียน hex ตรงในไฟล์นี้
   - Mobile-first: base = 360px แล้ว scale ขึ้นที่ 768px
   - ทุก interactive component มี state: hover / focus-visible /
     active / disabled / loading ครบ — ห้ามตัดออก
   - กติกาการใช้แต่ละ component: references/design-guide.md ของ skill
   ============================================================ */

/* ---------- Fonts (Sarabun self-host — ไฟล์อยู่ใน fonts/) ----------
   แยก 2 slice ต่อน้ำหนัก (latin + thai) ตาม unicode-range แบบเดียวกับที่
   Google Fonts เสิร์ฟ — browser โหลดเฉพาะ slice ที่หน้าใช้จริง
   รวมทุกไฟล์ 72KB · หน้าอังกฤษล้วนโหลดแค่ ~11KB                       */
@font-face {
  font-family: 'Sarabun'; font-weight: 400; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-400-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;
}
@font-face {
  font-family: 'Sarabun'; font-weight: 400; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-400-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Sarabun'; font-weight: 600; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-600-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;
}
@font-face {
  font-family: 'Sarabun'; font-weight: 600; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-600-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Sarabun'; font-weight: 700; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-700-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;
}
@font-face {
  font-family: 'Sarabun'; font-weight: 700; font-style: normal;
  font-display: swap; src: url('fonts/sarabun-700-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
img, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Base ---------- */
html { height: 100%; }
body {
  min-height: 100%;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: var(--fs-xl); font-weight: 700; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-md); font-weight: 600; }
h1, h2, h3 { text-wrap: balance; }
p  { line-height: var(--lh-body); max-width: 70ch; }
a  { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Focus ทั้งระบบ — คีย์บอร์ดเท่านั้น ไม่โผล่ตอนคลิกเมาส์
   box-shadow เพิ่มความเรืองแสงบาง ๆ รอบ outline — ใช้ได้ทุก theme เพราะ
   --glow ถูกปรับความเข้มต่อ theme แล้ว (ชัดใน dark และ contrast · แทบไม่เห็นใน light)
   เป็น "จุดสำคัญ" จุดเดียวที่ครอบคลุมทุก element เพราะ focus มีได้ทีละจุดเท่านั้น */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
  box-shadow: 0 0 14px 2px var(--glow);
}

/* ============================================================
   1) App Shell — topbar + sidebar (mobile: off-canvas drawer)
   <body class="app">
     <header class="topbar">…</header>
     <nav class="sidebar" id="sidebar">…</nav>
     <div class="backdrop" id="backdrop" hidden></div>
     <main class="main">…</main>
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--sp-3);
  height: 56px; padding: 0 var(--sp-4);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: var(--fs-md); font-weight: 600; }
.topbar-spacer { flex: 1; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: var(--z-modal);
  width: 260px; padding: var(--sp-4);
  background: var(--surface-2); border-right: 1px solid var(--border);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--dur-base) var(--ease-out);
}
.sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-2); }

.backdrop {
  position: fixed; inset: 0; z-index: var(--z-backdrop);
  background: rgba(0, 0, 0, .45);
}
.backdrop[hidden] { display: none; }

.nav-link {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); margin-bottom: 2px;
  border-radius: var(--r-sm); color: var(--text); font-weight: 500;
  transition: background var(--dur-fast), box-shadow var(--dur-fast);
}
.nav-link:hover { background: var(--surface); text-decoration: none; }
/* หน้าปัจจุบัน — จุดสำคัญจุดที่สาม: บอกตำแหน่งด้วยแสงเรือง ๆ แทนแถบสีข้าง
   (แถบสีข้างหนาเป็น anti-pattern ตาม design-guide §8) */
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); box-shadow: 0 0 10px 0 var(--glow); }

.main { padding: var(--sp-4); }

@media (min-width: 768px) {
  .sidebar { transform: none; z-index: auto; }   /* desktop: ค้างถาวร */
  .main   { margin-left: var(--sidebar-w); padding: var(--sp-6); }

  /* topbar ต้องใช้ margin-left ไม่ใช่ padding-left —
     padding ดันแค่ "เนื้อหา" แต่พื้นหลังยังกินตั้งแต่ x=0 ไปทับหัว sidebar
     พอ sidebar ถูกลด z-index เป็น auto บนเดสก์ท็อป โลโก้กับชื่อระบบจะจมอยู่ใต้แถบบน
     margin-left ย้ายทั้งกล่องมาเริ่มหลัง sidebar จึงไม่ทับกันตั้งแต่แรก */
  .topbar { margin-left: var(--sidebar-w); padding-left: var(--sp-6); }

  .menu-toggle, .backdrop { display: none; }
}

/* ============================================================
   2) Buttons — <button class="btn btn-primary">บันทึก</button>
   variants: btn-primary / btn-ghost / btn-danger · size: btn-sm
   loading: เพิ่ม class is-loading + disabled (JS)
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2); min-height: 42px; padding: 0 var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-base); font-weight: 600;
  position: relative;
  transition: background var(--dur-fast), border-color var(--dur-fast),
              opacity var(--dur-fast), box-shadow var(--dur-fast);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ปุ่ม primary มีได้จอละ 1 จุด (design-guide §5) — จึงเป็นอีก "จุดสำคัญ"
   ที่ใส่เรืองแสงได้โดยไม่ทำให้หน้าจอรก: เรืองแผ่วตอนปกติ เข้มขึ้นนิดตอน hover */
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: var(--primary-text);
  box-shadow: 0 0 14px 0 var(--glow);
}
.btn-primary:hover {
  background: var(--primary-hover); border-color: var(--primary-hover);
  box-shadow: 0 0 20px 2px var(--glow);
}

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }

.btn-sm { min-height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }

.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
}
/* วงแหวนโหลดบนปุ่ม primary ต้องอิงสีตัวอักษรของปุ่ม ไม่ใช่ขาวตายตัว —
   ธีม dark มี --primary-text เป็นสีเข้ม ถ้าใช้ขาวจะจมหายไปกับพื้นปุ่ม
   (บรรทัดแรกคือ fallback ให้ browser ที่ยังไม่รู้จัก color-mix) */
.btn-primary.is-loading::after { border-color: var(--border); border-top-color: var(--primary-text); }
@supports (color: color-mix(in srgb, red 50%, transparent)) {
  .btn-primary.is-loading::after {
    border-color: color-mix(in srgb, var(--primary-text) 35%, transparent);
    border-top-color: var(--primary-text);
  }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   3) Forms — โครงต่อ field:
   <div class="field">
     <label class="field-label" for="x">ชื่อ <span class="req">*</span></label>
     <input class="input" id="x">
     <p class="field-hint">คำอธิบายสั้น</p>          ← optional
     <p class="field-error">ข้อความ error</p>        ← โชว์เมื่อ invalid
   </div>
   invalid: เพิ่ม aria-invalid="true" ที่ input (JS/PHP)
   ============================================================ */
.field { margin-bottom: var(--sp-4); }
.field-label {
  display: block; margin-bottom: var(--sp-1);
  font-size: var(--fs-sm); font-weight: 600;
}
.req { color: var(--error); }

.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-md);              /* 16px — กัน iOS zoom */
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  transition: border-color var(--dur-fast);
}
textarea.input { min-height: 96px; line-height: var(--lh-body); resize: vertical; }
.input:hover { border-color: var(--text-muted); }
.input:focus { border-color: var(--primary); outline: none; }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.input:disabled { background: var(--surface-2); opacity: .7; cursor: not-allowed; }
.input::placeholder { color: var(--text-muted); }

.input[aria-invalid="true"] { border-color: var(--error); }
.field-hint  { margin-top: var(--sp-1); font-size: var(--fs-sm); color: var(--text-muted); }
.field-error { margin-top: var(--sp-1); font-size: var(--fs-sm); color: var(--error); font-weight: 500; }

/* checkbox / radio — ใช้ native + accent-color (สม่ำเสมอ + a11y ฟรี) */
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; accent-color: var(--primary);
}
.check-row {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: 42px; cursor: pointer;
}

/* ============================================================
   4) Table — ห่อด้วย .table-wrap เสมอ (แนวนอน scroll บนมือถือ)
   <div class="table-wrap"><table class="table">…</table></div>
   ============================================================ */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; padding: var(--sp-3);
  background: var(--surface-2); color: var(--text-muted);
  font-weight: 600; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td { padding: var(--sp-3); border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: var(--primary-soft); }

/* ============================================================
   5) Card — ห้ามซ้อน card ใน card
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--fs-md); font-weight: 600; }
.card-body { padding: var(--sp-4); }

/* ============================================================
   6) Badge — สถานะสั้น 1-2 คำ
   ============================================================ */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px var(--sp-2); border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
  background: var(--surface-2); color: var(--text-muted);
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error   { background: var(--error-bg);   color: var(--error); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--info-bg);    color: var(--info); }

/* ============================================================
   7) Modal — ใช้ native <dialog> (focus-trap + Esc + top-layer ฟรี)
   <dialog class="modal" id="m">
     <div class="modal-head"><h2>หัวข้อ</h2>
       <button class="btn btn-ghost btn-sm" data-close>✕</button></div>
     <div class="modal-body">…</div>
     <div class="modal-foot">…ปุ่ม…</div>
   </dialog>
   JS: m.showModal() / m.close()
   ============================================================ */
.modal {
  width: min(480px, calc(100vw - 32px));
  padding: 0; border: 0; border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2);
}
.modal::backdrop { background: rgba(0, 0, 0, .5); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: var(--fs-md); }
.modal-body { padding: var(--sp-4); max-height: 65vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4); border-top: 1px solid var(--border);
}

/* ============================================================
   8) Toast — region วางท้าย <body> ครั้งเดียว + JS showToast()
   <div class="toast-region" id="toastRegion"
        role="status" aria-live="polite"></div>
   ============================================================ */
.toast-region {
  position: fixed; bottom: var(--sp-4); left: var(--sp-4); right: var(--sp-4);
  z-index: var(--z-toast);
  display: grid; gap: var(--sp-2); justify-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-2);
  max-width: 420px; padding: var(--sp-3) var(--sp-4);
  background: var(--text); color: var(--bg);   /* inverse — เด่นทุก theme */
  border-radius: var(--r-sm); box-shadow: var(--shadow-2);
  font-weight: 500; pointer-events: auto;
  opacity: 0; transform: translateY(8px);
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--error);   color: #fff; }
@media (min-width: 768px) {
  .toast-region { left: auto; justify-items: end; }
}

/* ============================================================
   9) Empty state — สอนการใช้งาน ไม่ใช่แค่ "ไม่มีข้อมูล"
   <div class="empty">
     <div class="empty-icon">📋</div>
     <h3 class="empty-title">ยังไม่มีงานในระบบ</h3>
     <p class="empty-hint">เริ่มสร้างงานแรกเพื่อมอบหมายให้ทีม</p>
     <button class="btn btn-primary">+ สร้างงานแรก</button>
   </div>
   ============================================================ */
.empty {
  display: grid; justify-items: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4); text-align: center;
}
.empty-icon  { font-size: 40px; line-height: 1; }
.empty-title { font-size: var(--fs-md); }
.empty-hint  { color: var(--text-muted); max-width: 40ch; }
.empty .btn  { margin-top: var(--sp-2); }

/* ============================================================
   10) Loading — skeleton สำหรับพื้นที่เนื้อหา (ห้าม spinner กลางจอ)
   <div class="skeleton" style="height:16px;width:60%"></div>
   ============================================================ */
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg,
    var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================================================
   11) Pagination
   <nav class="pager" aria-label="เปลี่ยนหน้า">
     <a class="btn btn-sm" href="?page=1">←</a>
     <span class="pager-info">หน้า 2 / 8</span>
     <a class="btn btn-sm" href="?page=3">→</a>
   </nav>
   ============================================================ */
.pager {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-4) 0;
}
.pager-info { font-size: var(--fs-sm); color: var(--text-muted); }

/* ============================================================
   12) Page header — หัวหน้าจอ + ปุ่ม action หลัก
   ============================================================ */
.page-head {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

/* ---------- Utilities (ชุดเล็ก — อย่าขยายจนเป็น framework) ---------- */
.flex-row     { display: flex; align-items: center; gap: var(--sp-2); }
.text-center  { text-align: center; }
.text-muted   { color: var(--text-muted); }
.is-hidden    { display: none !important; }
.mt-2 { margin-top: var(--sp-2); }  .mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); }

/* ---------- Reduced motion — บังคับ ไม่ใช่ optional ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .skeleton { animation: none; background: var(--surface-2); }
}

/* ============================================================
   =========  ส่วนเพิ่มเฉพาะแอป RD Portfolio Hub  =========
   ทุกสีมาจาก token ใน theme.css เท่านั้น — ห้าม hex ตรงในไฟล์นี้
   ============================================================ */

/* ---------- 13) Accessibility helpers ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--sp-2); top: -60px; z-index: var(--z-tooltip);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm);
  background: var(--primary); color: var(--primary-text); font-weight: 600;
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--sp-2); text-decoration: none; }

/* ---------- 14) Sidebar / topbar ส่วนเสริม ---------- */
.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-5); padding: var(--sp-2) var(--sp-1);
  color: var(--text); font-weight: 700;
}
.brand:hover { text-decoration: none; }
/* กล่องของตราสัญลักษณ์ — โปร่งใส ไม่มีพื้น
   `color` ตรงนี้คือสีที่กรอบกรมท่าใน SVG จะรับไปใช้ (helpers.php: brandMark) */
.brand-mark { display: grid; place-items: center; flex: none; color: var(--text); }
.brand-text { font-size: var(--fs-base); line-height: 1.25; }

.nav-group {
  margin: var(--sp-4) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
}
.nav-group:first-of-type { margin-top: 0; }
/* ไอคอนเมนูเป็น SVG เส้น — จางกว่าตัวหนังสือเล็กน้อยตอนปกติ ชัดเต็มตอนเป็นหน้าปัจจุบัน */
.nav-icon { flex: none; display: grid; place-items: center; opacity: .7; }
.nav-link:hover .nav-icon { opacity: .9; }
.nav-link.is-active .nav-icon { opacity: 1; }
.icon { display: block; flex: none; }

.sidebar-foot {
  margin-top: var(--sp-5); padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}
.nav-user {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); color: var(--text);
}
.nav-user:hover { background: var(--surface); text-decoration: none; }
.nav-user-text { display: grid; min-width: 0; }
.nav-user-text strong {
  font-size: var(--fs-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-user-text small { font-size: var(--fs-xs); color: var(--text-muted); }
/* ป้ายบอกว่ากำลังดูแบบผู้เยี่ยมชม — วางที่เดียวกับชื่อผู้ใช้ ให้รู้ทันทีว่ายังไม่ได้ล็อกอิน */
.nav-guest {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs); color: var(--text-muted); line-height: var(--lh-ui);
}

.topbar-search { display: none; }
.topbar-search .input { width: 200px; }
.input-sm { min-height: 34px; font-size: var(--fs-sm); padding: var(--sp-1) var(--sp-2); }
.topbar-me:hover { text-decoration: none; }
@media (min-width: 640px) { .topbar-search { display: block; } }

/* ---------- 15) Avatar — ตัวตนของสมาชิก ----------
   สีเป็นช่องทาง "รอง" เท่านั้น: อักษรย่ออยู่ในวงเสมอ + มีชื่อกำกับข้างๆ
   ตัวอักษรใช้ --text บน --surface-2 (contrast ผ่านทุก theme อยู่แล้ว)
   โทนสีไปอยู่ที่ "วงแหวน" จึงไม่กระทบ contrast ของตัวอักษร        */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text);
  border: 2px solid var(--tone, var(--border));
  font-size: var(--fs-xs); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; text-transform: uppercase;
}
.avatar-sm { width: 28px; height: 28px; font-size: 10px; }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-md); }
.avatar-tone-1 { --tone: var(--tone-1); }
.avatar-tone-2 { --tone: var(--tone-2); }
.avatar-tone-3 { --tone: var(--tone-3); }
.avatar-tone-4 { --tone: var(--tone-4); }
.avatar-tone-5 { --tone: var(--tone-5); }
.avatar-tone-6 { --tone: var(--tone-6); }

/* รูปโปรไฟล์ที่อัปโหลดเอง — วางทับอักษรย่อ ไม่ได้แทนที่
   อักษรย่อยังอยู่ข้างใต้ จึงยังอ่านออกถ้ารูปโหลดไม่ขึ้นหรือยังโหลดไม่เสร็จ
   วงแหวนสีประจำตัวยังอยู่ครบ — รูปไม่ได้ลบช่องทางแยกคนออกจากกัน มันเพิ่มอีกช่องทาง */
.avatar.has-photo { position: relative; overflow: hidden; }
.avatar.has-photo img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  border-radius: inherit;
}

/* กลุ่ม avatar ซ้อนกัน — เว้นช่อง 2px ด้วยวงแหวนสี surface */
.avatar-stack { display: flex; align-items: center; }
.avatar-stack .avatar { margin-right: -8px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar:last-child { margin-right: 0; }
.avatar-more {
  display: inline-grid; place-items: center; flex: none;
  width: 28px; height: 28px; border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); font-size: 10px; font-weight: 600;
}

/* max-width:100% จำเป็นคู่กับ min-width:0 —
   inline-flex คิดความกว้างแบบ shrink-to-fit ซึ่งไม่ยอมลงต่ำกว่า min-content ของตัวเอง
   ชื่อยาว ๆ จึงดันกล่องทะลุคอลัมน์ออกไป ทั้งที่ลูกข้างในตัดด้วย … ได้แล้ว */
.person { display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0; max-width: 100%; }
/* min-width:0 จำเป็นเพื่อให้ ellipsis ทำงานจริง —
   flex item มี min-width:auto เป็นค่าเริ่มต้น จึงย่อต่ำกว่าความยาวข้อความไม่ได้
   ชื่อยาว ๆ จะดันกล่องพ่อให้กว้างเกินคอลัมน์แทนที่จะตัดด้วย … */
.person-name {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500;
}
.person-role { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- 16) Stat tile — ตัวเลขพาดหัว (ไม่ใช่กราฟ) ----------
   ใช้เมื่อ "ตัวเลขเดียว" คือคำตอบ — ไม่ต้องวาดกราฟให้รก      */
.stat-grid {
  display: grid; gap: var(--sp-3); margin-bottom: var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  display: grid; gap: var(--sp-1); padding: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1); color: var(--text);
  transition: border-color var(--dur-fast);
}
a.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat-label {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); color: var(--text-muted); font-weight: 600;
}
.stat-value {
  font-size: 2rem; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.stat-value.is-alert { color: var(--error); }
.stat-note { font-size: var(--fs-xs); color: var(--text-muted); }
.stat-dot { width: 10px; height: 10px; border-radius: var(--r-full); flex: none; background: var(--dot, var(--text-muted)); }

/* ---------- 17) Progress bar — ราง + เนื้อ ปลายมน 4px ---------- */
.progress { position: relative; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.progress-bar {
  height: 100%; border-radius: 4px; background: var(--primary);
  width: var(--pct, 0%); transition: width var(--dur-slow) var(--ease-out);
}
.progress-bar.is-done    { background: var(--success); }
.progress-bar.is-overdue { background: var(--error); }
.progress-row { display: flex; align-items: center; gap: var(--sp-2); min-width: 140px; }
.progress-row .progress { flex: 1; }
.progress-num {
  font-size: var(--fs-xs); color: var(--text-muted);
  font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right;
}

/* ---------- 18) Meter row — ภาระงานต่อคน ---------- */
.meter-list { display: grid; gap: var(--sp-3); }
.meter-row { display: grid; gap: var(--sp-2) var(--sp-3); align-items: center; grid-template-columns: 1fr; }
.meter-row > * { min-width: 0; }
.meter-head { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.meter-bars { display: flex; align-items: center; gap: 2px; height: 22px; }
.meter-seg {
  height: 100%; border-radius: 3px; min-width: 22px;
  display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700;
  color: var(--seg-fg); background: var(--seg-bg);
  flex: var(--n, 1) 1 auto;
}
.meter-seg.seg-ongoing { --seg-bg: var(--info-bg);    --seg-fg: var(--info); }
.meter-seg.seg-todo    { --seg-bg: var(--surface-2);  --seg-fg: var(--text-muted); }
.meter-seg.seg-overdue { --seg-bg: var(--error-bg);   --seg-fg: var(--error); }
.meter-seg.seg-done    { --seg-bg: var(--success-bg); --seg-fg: var(--success); }
.meter-empty { font-size: var(--fs-sm); color: var(--text-muted); }
@media (min-width: 768px) { .meter-row { grid-template-columns: minmax(160px, 220px) 1fr auto; } }

/* legend — ต้องมีเสมอเมื่อมีตั้งแต่ 2 ชุดข้อมูลขึ้นไป */
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-3); font-size: var(--fs-xs); color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: var(--sp-1); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; background: var(--sw, var(--surface-2)); border: 1px solid var(--border); }

/* ---------- 19) Card grid + project card ---------- */
.card-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.p-card {
  display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1); color: var(--text);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.p-card:hover { border-color: var(--primary); box-shadow: var(--shadow-2); text-decoration: none; }
.p-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.p-card-code { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.p-card-title { font-size: var(--fs-md); font-weight: 600; line-height: 1.4; }
.p-card-sum { font-size: var(--fs-sm); color: var(--text-muted); line-height: var(--lh-body); }
.p-card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-top: auto; padding-top: var(--sp-1); }
.p-card-impact {
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
  background: var(--success-bg); color: var(--success);
  font-size: var(--fs-sm); font-weight: 500; line-height: var(--lh-body);
}
.p-card.is-featured { border-color: var(--primary); }

/* ---------- 20) Chip / tag ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 1px var(--sp-2); border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); font-size: var(--fs-xs);
}
a.chip:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
a.chip.is-on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* ---------- 21) Filter bar — แถวเดียวเหนือเนื้อหาเสมอ ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
}
.filters .field { margin-bottom: 0; }
.filters .input { min-width: 150px; }
.filter-count { margin-left: auto; font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- 22) Section / layout ---------- */
.section { margin-bottom: var(--sp-7); }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.section-head h2 { font-size: var(--fs-lg); }
.page-sub { margin-top: var(--sp-1); font-size: var(--fs-sm); }
.split { display: grid; gap: var(--sp-5); align-items: start; }
/* grid item มี min-width:auto เป็นค่าเริ่มต้น → เนื้อหากว้าง ๆ (ตาราง, แถบ gantt)
   จะดันคอลัมน์ให้กว้างเกินจอแทนที่จะ scroll ในกรอบตัวเอง · min-width:0 คือตัวปลด */
.split > * { min-width: 0; }
@media (min-width: 1024px) { .split { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); } }

/* ---------- 23) Timeline (gantt) — แถบสีตาม "สถานะ" ไม่ใช่ตามคน ----------
   ทุกแถวมี badge สถานะกำกับ → สีไม่ใช่ช่องทางเดียวที่สื่อความหมาย     */
.gantt { display: grid; gap: var(--sp-1); }
.gantt-row {
  display: grid; gap: var(--sp-2); align-items: center;
  grid-template-columns: 1fr; padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.gantt-row:last-child { border-bottom: 0; }
.gantt-row > * { min-width: 0; }
.gantt-label { min-width: 0; font-size: var(--fs-sm); }
.gantt-label a { color: var(--text); font-weight: 500; }
.gantt-track { position: relative; height: 24px; border-radius: var(--r-sm); background: var(--track); }
.gantt-bar {
  position: absolute; top: 3px; bottom: 3px;
  left: var(--from, 0%); width: var(--span, 10%);
  min-width: 6px; border-radius: 4px;
  background: var(--info); box-shadow: 0 0 0 2px var(--surface);
}
.gantt-bar.is-todo    { background: var(--text-muted); }
.gantt-bar.is-done    { background: var(--success); }
.gantt-bar.is-hold    { background: var(--warning); }
.gantt-bar.is-overdue { background: var(--error); }
.gantt-today { position: absolute; top: -2px; bottom: -2px; left: var(--at, 50%); width: 2px; background: var(--primary); border-radius: 1px; }
.gantt-scale { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-muted); padding-top: var(--sp-1); }
@media (min-width: 768px) { .gantt-row { grid-template-columns: minmax(180px, 280px) 1fr; } }

/* ---------- 24) Task list ---------- */
.task-list { display: grid; }
.task-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.task-item:last-child { border-bottom: 0; }
.task-title { flex: 1; min-width: 0; }
.task-item.is-done .task-title { color: var(--text-muted); text-decoration: line-through; }
.task-meta { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.task-meta.is-overdue { color: var(--error); font-weight: 600; }

/* ---------- 25) Comments ---------- */
.comment-list { display: grid; gap: var(--sp-4); }
.comment { display: flex; gap: var(--sp-3); }
.comment-body { flex: 1; min-width: 0; }
.comment-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-1); }
.comment-author { font-weight: 600; font-size: var(--fs-sm); }
.comment-time { font-size: var(--fs-xs); color: var(--text-muted); }
.comment-text { line-height: var(--lh-body); white-space: pre-wrap; word-break: break-word; }

/* ---------- 26) Key/value list ---------- */
.kv { display: grid; gap: var(--sp-3); }
.kv-row { display: grid; gap: 2px; }
.kv-key { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; }
.kv-val { font-size: var(--fs-sm); }
@media (min-width: 480px) {
  /* ต้องเป็น minmax(0, 1fr) ไม่ใช่ 1fr เฉย ๆ —
     `1fr` ย่อต่ำกว่า min-content ไม่ได้ พอเจอข้อความที่ห้ามตัดบรรทัด (.task-meta)
     แถวจะดันกว้างเกินคอลัมน์ขวาของ .split แล้วทำให้ทั้งหน้าล้นแนวนอน */
  .kv-row { grid-template-columns: 130px minmax(0, 1fr); align-items: baseline; gap: var(--sp-3); }
}
/* ในตารางต้องไม่ตัดบรรทัด (กัน "อีก 5 วัน" แตกเป็นสองบรรทัด)
   แต่ในรายการ key/value ที่คอลัมน์แคบ ให้ตัดบรรทัดได้ */
.kv-val .task-meta { white-space: normal; }

/* ---------- 27) Vote (idea pool) ---------- */
.vote {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 46px; min-height: 46px; padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text-muted); font-weight: 700;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.vote:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.vote:disabled { opacity: .55; cursor: not-allowed; }
.vote.is-on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.vote-arrow { font-size: 10px; line-height: 1; }
.vote-count { font-size: var(--fs-md); line-height: 1.1; font-variant-numeric: tabular-nums; }

/* ---------- 28) Link list (เอกสารอ้างอิง / ไฟล์แนบ) ---------- */
.link-list { display: grid; gap: var(--sp-2); }
.link-item {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2);
}
.link-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 29) Activity feed ---------- */
.feed { display: grid; gap: var(--sp-3); }
.feed-item { display: flex; gap: var(--sp-3); align-items: flex-start; font-size: var(--fs-sm); }
.feed-text { flex: 1; min-width: 0; line-height: var(--lh-body); }
.feed-time { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }

/* ---------- 30) Login page ---------- */
.auth-wrap { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: var(--sp-4); background: var(--bg); }
.auth-card { width: min(400px, 100%); }
.auth-brand { display: grid; justify-items: center; gap: var(--sp-2); margin-bottom: var(--sp-5); }

/* ============================================================
   32) Desktop-first — แอปนี้ใช้บนจอคอมเป็นหลัก
   ============================================================
   กติกา 2 ชั้น แยกกันชัดเจน:

   (ก) `min-width` อย่างเดียว  → เรื่อง "พื้นที่" เช่นจำนวนคอลัมน์, ความกว้างสูงสุด
   (ข) `min-width` + `pointer: fine` → เรื่อง "ความหนาแน่น" เช่นลด padding, ลดขนาดปุ่ม

   ที่ต้องมี `pointer: fine` เพราะ iPad แนวนอนกว้าง 1024–1366px เท่าจอคอม
   แต่ใช้นิ้วจิ้ม — ถ้าย่อปุ่มตามความกว้างอย่างเดียว จะกดยากบนแท็บเล็ต
   และ input ที่เล็กกว่า 16px จะทำให้ iOS ซูมเข้าเองตอนโฟกัส
   เงื่อนไขนี้จึงบังคับให้ความหนาแน่นเกิดเฉพาะเครื่องที่มีเมาส์จริง        */

/* ---------- (ก) พื้นที่และคอลัมน์ ---------- */

/* คอลัมน์เสริมที่โผล่เฉพาะจอกว้าง — ค่าเริ่มต้นคือซ่อน
   ⚠️ ต้องประกาศ "ก่อน" media query ข้างล่าง เพราะ specificity เท่ากัน
      ถ้าอยู่ทีหลังจะชนะและคอลัมน์จะไม่โผล่เลย */
.col-lg { display: none; }

@media (min-width: 1024px) {
  .main { padding: var(--sp-6) var(--sp-7); }
  /* จำกัดความกว้างเนื้อหาแล้วจัดกึ่งกลาง — บนจอ 2560px ตารางที่ยืดเต็มจอ
     ทำให้ตาต้องกวาดจากซ้ายสุดไปขวาสุดเพื่ออ่านแถวเดียว */
  .main > * { max-width: var(--content-max); margin-inline: auto; }

  /* คอลัมน์ขวาแคบลงนิด ให้เนื้อหาหลักได้พื้นที่มากขึ้น */
  .split { grid-template-columns: minmax(0, 2.2fr) minmax(300px, 1fr); gap: var(--sp-6); }

  /* คอลัมน์ที่มีเฉพาะจอกว้าง — ใช้กับข้อมูลเสริมที่มือถือไม่ต้องเห็น */
  .col-lg { display: table-cell; }
}

@media (min-width: 1440px) {
  .split { grid-template-columns: minmax(0, 2.6fr) minmax(340px, 1fr); }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .stat-grid { gap: var(--sp-4); }
}

/* ---------- (ข) ความหนาแน่น — เฉพาะเครื่องที่มีเมาส์ ---------- */
@media (min-width: 1024px) and (pointer: fine) {
  /* ตารางคือหัวใจของงานนี้ — แถวเตี้ยลง = เห็นข้อมูลต่อจอมากขึ้น */
  .table { font-size: var(--fs-base); }
  .table th { padding: var(--sp-2) var(--sp-3); }
  .table td { padding: var(--sp-2) var(--sp-3); }

  /* ไม่ต้องเผื่อพื้นที่นิ้ว 42px อีกต่อไป */
  .btn    { min-height: 34px; padding: 0 var(--sp-3); }
  .btn-sm { min-height: 28px; }
  .input, select.input, textarea.input {
    min-height: 34px;
    font-size: var(--fs-base);      /* 14px — ไม่ต้องกัน iOS zoom เพราะไม่ใช่ touch */
  }
  .check-row { min-height: 32px; }
  .field { margin-bottom: var(--sp-3); }
  .card-body, .card-head, .modal-head, .modal-body, .modal-foot { padding: var(--sp-3) var(--sp-4); }
  .filters { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2) var(--sp-3); }
  .task-item { padding: var(--sp-2) 0; }
  .stat { padding: var(--sp-3) var(--sp-4); }
  /* แถบความคืบหน้าไม่ต้องยืดเต็มคอลัมน์บนจอกว้าง — ยิ่งยาวยิ่งกะสัดส่วนยาก
     และตัวเลข % ถูกผลักไปไกลจากแถบจนต้องกวาดสายตาตาม */
  .progress-row { max-width: 240px; }

  /* modal กว้างขึ้นได้บนจอคอม */
  .modal { width: min(560px, calc(100vw - 64px)); }
}

/* ---------- หัวตารางค้างเมื่อเลื่อนดูรายการยาว ----------
   ตารางที่ยาวเกินจอจะเลื่อนในกรอบตัวเองพร้อมตรึงหัวไว้ ทำให้ไม่ลืมว่าคอลัมน์ไหนคืออะไร
   ตารางสั้นจะไม่ถึง max-height จึงไม่มี scrollbar โผล่มากวน                        */
@media (min-width: 1024px) {
  .table-wrap { max-height: calc(100vh - 240px); overflow: auto; }
  .table thead th {
    position: sticky; top: 0; z-index: var(--z-dropdown);
    background: var(--surface-2);
  }
}

/* ============================================================
   33) ภาพประกอบโครงการ — ปกบนการ์ด · แกลเลอรี · ที่วางไฟล์ · ดูรูปเต็ม
   ============================================================ */

/* ---------- ปกบนการ์ด ----------
   ใช้ aspect-ratio ตายตัวเพื่อให้ทุกใบสูงเท่ากัน กริดจึงไม่ฟันหลอ
   margin ติดลบดันรูปให้ชนขอบการ์ด (การ์ดมี padding var(--sp-4) อยู่) */
.p-card-cover {
  position: relative;
  margin: calc(var(--sp-4) * -1) calc(var(--sp-4) * -1) 0;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.p-card-cover img {
  width: 100%; height: 100%;
  object-fit: cover;                     /* เต็มกรอบเสมอ ไม่บิดสัดส่วน */
  display: block;
  transition: transform var(--dur-slow) var(--ease-out);
}
.p-card:hover .p-card-cover img { transform: scale(1.03); }

/* โครงการที่ยังไม่มีรูป — วางตราสัญลักษณ์จาง ๆ ไว้ ให้กริดยังเรียงสวย
   ไม่ปล่อยว่างเพราะการ์ดจะสูงไม่เท่ากันแล้วดูรก */
.p-card-cover.is-empty {
  display: grid; place-items: center;
  color: var(--text-muted); opacity: .35;
}
.p-card-cover.is-empty svg { width: 64px; height: auto; }

/* ---------- แกลเลอรีในหน้ารายละเอียด ---------- */
.gallery {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.gallery-item {
  position: relative;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden; background: var(--surface-2);
}
.gallery-item.is-cover { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.gallery-btn {
  display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in;
  aspect-ratio: 4 / 3;
}
.gallery-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }

.gallery-bar {
  display: flex; align-items: center; gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  border-top: 1px solid var(--border); background: var(--surface);
}
.gallery-bar .btn { min-height: 26px; padding: 0 var(--sp-2); font-size: var(--fs-xs); }
.gallery-cover-tag {
  flex: 1; min-width: 0;
  font-size: var(--fs-xs); font-weight: 600; color: var(--primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gallery-caption {
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-xs); color: var(--text-muted);
  line-height: var(--lh-body); word-break: break-word;
}

/* ---------- ที่วางไฟล์ (drag & drop) ---------- */
.dropzone {
  display: grid; place-items: center; gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-4); text-align: center;
  border: 2px dashed var(--border); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text-muted);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone.is-busy { opacity: .6; pointer-events: none; }
.dropzone-icon { font-size: 30px; line-height: 1; }
.dropzone-hint { font-size: var(--fs-xs); }
.dropzone input[type="file"] { display: none; }

.upload-list { display: grid; gap: var(--sp-1); margin-top: var(--sp-3); }
.upload-row {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2); border-radius: var(--r-sm);
  font-size: var(--fs-xs); background: var(--surface-2);
}
.upload-row.is-error { background: var(--error-bg); color: var(--error); }
.upload-row.is-done  { background: var(--success-bg); color: var(--success); }
.upload-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- ดูรูปเต็ม (lightbox) ---------- */
.lightbox {
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0; border: 0; border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2);
}
.lightbox::backdrop { background: rgba(0, 0, 0, .8); }
.lightbox-img {
  display: block; width: 100%; max-height: calc(100vh - 150px);
  object-fit: contain; background: var(--surface-2);
}
.lightbox-bar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border);
}
.lightbox-caption { flex: 1; min-width: 0; font-size: var(--fs-sm); line-height: var(--lh-body); }
.lightbox-count { font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- รูปเล็กในรายงานผู้บริหาร ---------- */
.report-thumb {
  width: 68px; height: 46px; object-fit: cover; display: block;
  border-radius: var(--r-sm); border: 1px solid var(--border);
}

/* ============================================================
   34) Project charter + โครงสร้างงาน (Project → Phase → Task)
   ============================================================ */

/* ---------- charter: ที่มา / วัตถุประสงค์ / ตัวชี้วัด / ผู้เกี่ยวข้อง ---------- */
.charter { display: grid; gap: var(--sp-3); }
.charter-row { display: grid; gap: 2px; }
.charter-key {
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
}
.charter-val { font-size: var(--fs-sm); }
@media (min-width: 640px) {
  .charter-row { grid-template-columns: 140px minmax(0, 1fr); gap: var(--sp-3); align-items: baseline; }
}

/* ---------- ต้นไม้งาน ----------
   ใช้ "เยื้องเข้า + เส้นแนวตั้ง" บอกความสัมพันธ์พ่อ-ลูก แทนการซ้อน card ในการ์ด
   (card ซ้อน card เป็น anti-pattern ตาม design-guide §8) */
.tree-label {
  display: flex; align-items: center; gap: var(--sp-2); min-width: 0;
  flex-wrap: wrap;
}
.tree-label strong { font-size: var(--fs-md); }
.tree-meta {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-muted);
}
.tree-actions { display: flex; align-items: center; gap: var(--sp-2); flex: none; }

/* Phase — ชั้นที่ 2 เยื้องเข้ามาพร้อมเส้นบอกว่าอยู่ใต้ Project */
.tree-phase {
  padding-left: var(--sp-4);
  border-left: 2px solid var(--border);
  margin-bottom: var(--sp-4);
}
.tree-phase:last-of-type { margin-bottom: var(--sp-2); }
.tree-phase-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap;
  padding-bottom: var(--sp-1);
}
/* Task — ชั้นที่ 3 เยื้องอีกขั้น */
.tree-tasks { padding-left: var(--sp-4); }

/* ============================================================
   35) แถบกรองหมวดหมู่ · Hero · การ์ดทีมงาน (หน้า Dashboard / Portfolio)
   ============================================================ */

/* ---------- แถบกรองแบบแท็บ ----------
   กรองด้วย JS ฝั่งหน้าเว็บ (โปรเจกต์ทีมนี้มีหลักสิบ ไม่ใช่หลักพัน)
   จึงสลับได้ทันทีไม่ต้องรอโหลดหน้าใหม่ · ถ้า JS ไม่ทำงานจะแสดงทุกอันตามปกติ */
.filter-tabs {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1);
  padding-bottom: var(--sp-3); margin-bottom: var(--sp-5);
  border-bottom: 1px dashed var(--border);
}
.filter-tab {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 0; border-radius: var(--r-sm); background: none;
  color: var(--text-muted); font: inherit; font-weight: 600; font-size: var(--fs-sm);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.filter-tab::before {
  content: ""; width: 7px; height: 7px; flex: none;
  background: currentColor;                 /* จุดนำหน้าแบบเดียวกับแท็บในภาพอ้างอิง */
}
.filter-tab:hover { color: var(--text); background: var(--surface-2); }
.filter-tab.is-on { color: var(--primary); background: var(--primary-soft); }
.filter-tab-count { font-weight: 500; opacity: .7; font-variant-numeric: tabular-nums; }

/* การ์ดที่ถูกกรองออก — ซ่อนด้วย attribute ไม่ใช่ class เพื่อไม่ชนกับ .is-hidden ที่ใช้ที่อื่น */
[data-filtered="out"] { display: none !important; }

/* ---------- Hero ของหน้า Portfolio ---------- */
.hero {
  padding: var(--sp-7) var(--sp-6);
  margin-bottom: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
  text-align: center;
}
.hero h1 { font-size: 1.75rem; margin-bottom: var(--sp-2); }
.hero-sub {
  max-width: 62ch; margin: 0 auto var(--sp-5);
  color: var(--text-muted); line-height: var(--lh-body);
}
.hero-stats {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  max-width: 720px; margin: 0 auto;
}
.hero-stat-value {
  font-size: 1.9rem; font-weight: 700; line-height: 1.1; color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.hero-stat-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; }
@media (min-width: 1024px) { .hero { padding: var(--sp-8) var(--sp-7); } }

/* ---------- การ์ดสมาชิกทีม (Meet the team) ---------- */
.team-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.team-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4); text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.team-card:hover { border-color: var(--primary); box-shadow: var(--shadow-2); text-decoration: none; }
.team-card .avatar { width: 68px; height: 68px; font-size: var(--fs-md); }
.team-card-name { font-weight: 600; font-size: var(--fs-md); }
.team-card-role { font-size: var(--fs-xs); color: var(--text-muted); }
.team-card-stats {
  display: flex; gap: var(--sp-3); margin-top: var(--sp-1);
  font-size: var(--fs-xs); color: var(--text-muted);
}
.team-card-stats strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ============================================================
   36) หน้าแรกแบบโปรไฟล์แผนก — hero แนะนำตัว · พันธกิจ · ตัวเลขแนะนำตัว
   ============================================================
   ต่างจาก .hero ของหน้า Portfolio ที่จัดกึ่งกลางและมีแต่ตัวเลข:
   หน้าแรกมีย่อหน้าให้อ่านจริง จึงชิดซ้ายและแยกเป็นสองคอลัมน์บนจอกว้าง
   (ข้อความยาวที่จัดกึ่งกลางอ่านยาก — ตาหาจุดเริ่มของบรรทัดถัดไปไม่เจอ)

   ตัว hero ไม่มีพื้นและไม่มีกรอบ — ปล่อยให้พื้นหน้าโชว์ผ่าน แล้วให้กล่อง
   "สิ่งที่เราทำ" เป็นกล่องเดียวที่มีกรอบ จะได้ไม่กลายเป็น card ซ้อน card    */

.profile-hero {
  display: grid; gap: var(--sp-6);
  margin-bottom: var(--sp-6);
}
@media (min-width: 1024px) {
  .profile-hero {
    grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr);
    gap: var(--sp-8); align-items: start;
  }
}

/* บรรทัดเหนือหัวเรื่อง — ตราสัญลักษณ์ + ชื่อภาษาอังกฤษของแผนก */
.profile-eyebrow {
  display: flex; align-items: center; gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted);
}
.profile-hero h1 { font-size: 1.75rem; line-height: 1.25; }
@media (min-width: 1024px) { .profile-hero h1 { font-size: 2.125rem; } }

/* ประโยคเดียวใต้ชื่อแผนก — ใช้สี primary ให้เด่นกว่าย่อหน้าธรรมดา */
.profile-lead {
  margin-top: var(--sp-3); max-width: 60ch;
  font-size: var(--fs-md); font-weight: 600; line-height: var(--lh-body);
  color: var(--primary);
}
.profile-prose { margin-top: var(--sp-4); }
.profile-prose p { max-width: 68ch; color: var(--text-muted); }
.profile-prose p + p { margin-top: var(--sp-3); }

/* แถวปุ่ม — ต้องขึ้นบรรทัดใหม่ได้ (.flex-row ไม่ wrap) */
.profile-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  margin-top: var(--sp-5);
}
.profile-contact {
  margin-top: var(--sp-5); padding-top: var(--sp-4);
  border-top: 1px dashed var(--border);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.profile-contact strong { color: var(--text); }

/* ---------- กล่อง "สิ่งที่เราทำ" ---------- */
.mission-card {
  padding: var(--sp-5);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.mission-title { font-size: var(--fs-base); font-weight: 700; margin-bottom: var(--sp-4); }
.mission-list { display: grid; gap: var(--sp-3); margin: 0; padding: 0; list-style: none; }
.mission-list li {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-3);
  align-items: start;
  font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted);
}
/* จุดนำหน้าวาดด้วย CSS ไม่ใช่ emoji (DESIGN.md §5.0) — วงแหวนสี primary */
.mission-list li::before {
  content: ""; width: 12px; height: 12px; margin-top: .45em; flex: none;
  border: 2px solid var(--primary); border-radius: var(--r-full);
}

/* ---------- แถบตัวเลขแนะนำตัว ----------
   คนละตัวกับ .stat ของแดชบอร์ด: ตรงนี้ไม่มีเส้นสถานะและไม่มีคำอธิบายท้าย
   เพราะเป็นตัวเลข "ขนาดของงานที่ทำมา" ไม่ใช่ตัวเลขที่ต้องลงมือทำอะไรต่อ */
.figures {
  display: grid; gap: var(--sp-5) var(--sp-4);
  /* 120px คือค่าที่ทำให้จอ 360–375px ยังได้ 2 คอลัมน์ — ตัวเลข 4 ตัวเรียงลงมา
     เป็นแถวเดี่ยวกินความสูงเกือบครึ่งจอมือถือโดยไม่ได้ข้อมูลเพิ่ม */
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  padding: var(--sp-5) var(--sp-6);
  margin-bottom: var(--sp-7);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.figure {
  display: grid; gap: var(--sp-1);
  color: var(--text);
  transition: color var(--dur-fast);
}
/* hover ผูกกับ a.figure เท่านั้น — คนนอกที่กดไม่ได้จะได้ <div> ที่ไม่ขยับตอนเอาเมาส์ไปชี้
   ถ้าปล่อยเป็น .figure:hover กล่องจะดูเหมือนกดได้แต่กดแล้วไม่มีอะไรเกิดขึ้น */
a.figure:hover { text-decoration: none; }
a.figure:hover .figure-value { color: var(--primary-hover); }
.figure-value {
  font-size: 1.9rem; font-weight: 700; line-height: 1.1;
  color: var(--primary); font-variant-numeric: tabular-nums;
  transition: color var(--dur-fast);
}
.figure-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }

/* ---------- บรรทัดขอบเขตงาน (ชิปหมวดหมู่ + จำนวน) ---------- */
.profile-scope {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  max-width: none; margin-bottom: var(--sp-6);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.profile-scope > span:first-child { font-weight: 600; }
.profile-scope .chip strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ความเชี่ยวชาญบนการ์ดทีมงาน — ต่อจาก §35 */
.team-card-tags {
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-1);
  margin-top: var(--sp-1);
}

/* ============================================================
   36) หน้า R&D Department — Core value · Mission · Vision
   ตั้งใจให้เปิดโชว์บนจอประชุมได้ ตัวอักษรจึงใหญ่กว่าหน้าอื่น
   ============================================================ */
.dept-hero { max-width: 72ch; margin-bottom: var(--sp-7); }
.dept-hero h1 { font-size: 1.75rem; line-height: 1.25; }
@media (min-width: 1024px) { .dept-hero h1 { font-size: 2.125rem; } }

.value-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.value-card {
  position: relative; padding: var(--sp-5);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
/* เลขลำดับเป็นของประดับ ไม่ใช่เนื้อหา — จางไว้ให้หัวข้อเด่นกว่าเสมอ */
.value-num {
  display: block; font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: .12em; color: var(--primary); opacity: .65;
  margin-bottom: var(--sp-2); font-variant-numeric: tabular-nums;
}
.value-title { font-size: var(--fs-md); font-weight: 700; }
.value-text {
  margin-top: var(--sp-2);
  font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted);
}

/* พันธกิจบนหน้าแผนกอ่านเป็นรายการยาว ไม่ใช่กล่องข้างหน้าแรก จึงขยายขนาดขึ้น */
.mission-list-lg li { font-size: var(--fs-base); color: var(--text); }

.vision-card { border-left: 3px solid var(--primary); }
.vision-quote {
  margin: 0; font-size: var(--fs-md); font-weight: 600;
  line-height: var(--lh-body); color: var(--text);
}
@media (min-width: 768px) { .vision-quote { font-size: 1.25rem; } }

/* ============================================================
   37) รายการความเชี่ยวชาญ 0-5
   ตัวหลอดพลังเองอยู่ใน §44 (.power) — ที่นี่คือแถวรายการที่ห่อมันไว้
   ============================================================ */
.skill-list { display: grid; gap: var(--sp-2); }
.skill-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm);
}
.skill-name { font-weight: 600; }
.skill-label { font-size: var(--fs-xs); color: var(--text-muted); }
.skill-list.is-tight { gap: var(--sp-1); font-size: var(--fs-xs); }
.skill-list.is-tight .skill-label { display: none; }

.skill-people { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.skill-person {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm);
}

/* ฟอร์มให้คะแนน — ชื่อทักษะกว้างเต็ม แล้วระดับกับปุ่มลบต่อท้าย */
.skill-rows { display: grid; gap: var(--sp-2); }
.skill-row {
  display: grid; gap: var(--sp-2); align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}
.skill-row select { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .skill-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; }
  .skill-row select { grid-column: auto; }
}
.scale-list {
  margin: var(--sp-3) 0 0; padding-left: var(--sp-5);
  font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted);
}

/* ============================================================
   38) การ์ดรายการแบบมีแถบซ้าย — ใช้กับ Product และ Tool
   (ชื่อ .deliver-* มาจากหน้า Deliverables ที่ถอดออกไปแล้ว · คงชื่อไว้เพราะ
    เป็นโครงการ์ดที่ใช้ซ้ำหลายที่ ไม่ได้ผูกกับหน้าใดหน้าหนึ่งอีกต่อไป)
   ============================================================ */
.deliver-list { display: grid; gap: var(--sp-4); }
.deliver-card {
  display: grid; gap: var(--sp-3);
  padding: var(--sp-5);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.deliver-head {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: var(--sp-3);
}
.deliver-title { font-size: var(--fs-md); font-weight: 700; }
.deliver-parent {
  margin-top: 2px;
  font-size: var(--fs-xs); color: var(--text-muted);
}
.deliver-sum { font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted); }
.deliver-foot {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: var(--sp-2);
  padding-top: var(--sp-3); border-top: 1px solid var(--border);
}

/* ============================================================
   39) คำขอจากหน่วยงานอื่น
   ============================================================ */
.req-head {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: var(--sp-3);
}
.req-actions {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  padding-top: var(--sp-4); border-top: 1px dashed var(--border);
}
.req-actions .field { margin-bottom: 0; }
/* .filter-tab ถูกเขียนไว้สำหรับ <button> — หน้าคำขอกรองด้วยลิงก์ (bookmark ได้) */
a.filter-tab:hover { text-decoration: none; }

/* ============================================================
   40) ปฏิทินรายเดือน
   ช่องวันสูงคงที่ไม่ได้ เพราะบางวันมีรายการเดียวบางวันมีห้า —
   ใช้ min-height แล้วปล่อยให้แถวยืดตามวันที่แน่นที่สุดของสัปดาห์นั้น
   ============================================================ */
.cal-nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.cal-title { font-size: var(--fs-md); font-variant-numeric: tabular-nums; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; }
.cal-dow {
  padding: var(--sp-2) var(--sp-1);
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
  text-align: center;
}
.cal-cell {
  display: grid; align-content: start; gap: 2px;
  min-height: 88px; padding: var(--sp-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.cal-cell.is-blank { background: var(--surface-2); border-style: dashed; min-height: 0; }
.cal-cell.is-today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-daynum {
  display: flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.cal-todaytag {
  padding: 0 4px; border-radius: var(--r-sm);
  background: var(--primary-soft); color: var(--primary); font-size: 10px;
}
.cal-dow-inline { display: none; }
.cal-item {
  display: flex; align-items: center; gap: 4px;
  min-width: 0; font-size: var(--fs-xs); color: var(--text);
}
a.cal-item:hover { text-decoration: none; color: var(--primary); }
.cal-dot {
  width: 7px; height: 7px; flex: none;
  border-radius: var(--r-full); background: var(--dot, var(--text-muted));
}
.cal-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* มือถือ: ตารางเจ็ดคอลัมน์บีบจนอ่านไม่ออก — ยุบเป็นรายการวันต่อวันแทน */
@media (max-width: 640px) {
  .cal-grid { grid-template-columns: 1fr; }
  .cal-dow { display: none; }
  .cal-cell.is-blank { display: none; }
  .cal-cell { min-height: 0; }
  .cal-item-text { white-space: normal; }
  .cal-dow-inline { display: inline; }
  /* วันที่ไม่มีอะไรเลยยุบเป็นบรรทัดบาง ๆ — ยังเห็นว่าเดือนเดินถึงไหน แต่ไม่กินจอ */
  .cal-cell:not(:has(.cal-item)) { padding: 4px var(--sp-2); opacity: .6; }
}

/* ============================================================
   41) กราฟแท่งรายเดือนในหน้ารายงาน
   ตัวเลขพิมพ์ใต้แท่งทุกแท่ง → อ่านค่าได้แม้พิมพ์ออกกระดาษขาวดำ
   ============================================================ */
.month-chart {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: var(--sp-1); align-items: end;
  overflow-x: auto; padding-bottom: var(--sp-2);
}
.month-col { display: grid; gap: var(--sp-1); justify-items: center; min-width: 34px; }
.month-col.is-now .month-label { color: var(--primary); font-weight: 700; }
.month-bars {
  display: flex; align-items: flex-end; gap: 2px;
  height: 96px;
}
.month-bar {
  width: 10px; min-height: 2px; height: var(--h, 0%);
  border-radius: 2px 2px 0 0;
}
.month-bar.is-started { background: var(--info); }
.month-bar.is-done    { background: var(--success); }
.month-label { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.month-year { opacity: .6; }
.month-nums {
  font-size: 10px; color: var(--text-muted); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   42) สรุปประจำสัปดาห์ — หน้าตาเหมือนกล่องเขียนอีเมล
   ============================================================ */
.mail-card { border-top: 3px solid var(--primary); }
.mail-head {
  display: grid; gap: var(--sp-2);
  padding-bottom: var(--sp-4); border-bottom: 1px dashed var(--border);
}
.mail-head-row {
  display: grid; grid-template-columns: 64px minmax(0, 1fr);
  gap: var(--sp-3); align-items: center;
}
.mail-head-key {
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.mail-head-val { font-size: var(--fs-sm); min-width: 0; }

.week-row {
  display: grid; gap: var(--sp-2);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--border);
}
.week-row:last-child { border-bottom: 0; }
.week-row-head {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: var(--sp-2);
  font-size: var(--fs-sm);
}
.week-pct { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-xs); }
.week-pct input { width: 5rem; }

/* ============================================================
   43) ไทม์ไลน์ย่อบนแดชบอร์ด — แถบเตี้ยลงและป้ายซ้ายแคบลง
   ============================================================ */
.gantt.is-compact .gantt-row { padding: var(--sp-1) 0; }
.gantt.is-compact .gantt-track { height: 18px; }
.gantt.is-compact .gantt-label { font-size: var(--fs-xs); }
@media (min-width: 768px) {
  .gantt.is-compact .gantt-row { grid-template-columns: minmax(150px, 220px) 1fr; }
}

/* ---------- 31) Print — สำหรับหน้ารายงานผู้บริหาร ---------- */
@media print {
  .sidebar, .topbar, .backdrop, .toast-region, .no-print, .skip-link { display: none !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
  .main > * { max-width: none !important; }
  .card, .stat, .p-card, .table-wrap { box-shadow: none; break-inside: avoid; }
  .section { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  /* ตารางต้องพิมพ์ออกมาครบทุกแถว ไม่ใช่แค่ส่วนที่มองเห็นในกรอบ scroll */
  .table-wrap { max-height: none !important; overflow: visible !important; }
  .table thead th { position: static !important; }
  .col-lg { display: table-cell !important; }
}

/* ============================================================
   44) หลอดพลัง (Field of Expertise) และหลอดกำลังคน (Capability)
   สองอย่างนี้ตอบคำถามต่างกัน จึงมีหน้าตาต่างกันโดยตั้งใจ:
     · หลอดพลัง = ระดับ 0-5 เป็นช่อง ๆ (นับได้ด้วยตา ไม่ต้องอ่านตัวเลข)
     · หลอดกำลังคน = เปอร์เซ็นต์ต่อเนื่อง 0-100 (เทียบสัดส่วนได้)
   ตัวเลขกำกับทั้งคู่ เพราะสีอย่างเดียวไม่พอสำหรับคนที่แยกสีไม่ได้
   ============================================================ */
.power { display: inline-flex; align-items: center; gap: 2px; }
.power-cell {
  width: 14px; height: 14px; border-radius: var(--r-sm);
  background: var(--track); border: 1px solid var(--border);
}
.power-cell.is-on { background: var(--primary); border-color: var(--primary); }
/* ขีดบอกระดับที่โครงการต้องการ — อยู่ที่ช่องนั้นเสมอ ไม่ว่าจะมีถึงหรือไม่ */
.power-cell.is-need { border-color: var(--text); border-width: 2px; }
.power.is-short .power-cell.is-on { background: var(--warning); border-color: var(--warning); }
.power-num {
  margin-left: var(--sp-1); font-size: var(--fs-xs); font-weight: 700;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.power.is-short .power-num { color: var(--warning); }

.load-bar { display: inline-flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.load-track {
  width: 120px; height: 10px; border-radius: var(--r-full);
  background: var(--track); overflow: hidden; flex: none;
}
.load-fill {
  display: block; height: 100%; width: var(--pct, 0%);
  background: var(--primary); border-radius: var(--r-full);
  transition: width var(--dur-slow) var(--ease-out);
}
.load-bar.is-over .load-fill { background: var(--error); }
.load-num {
  font-size: var(--fs-xs); font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.load-bar.is-over .load-num { color: var(--error); }
.load-note { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- 45) โครงสร้างข้อมูล JSON (สัญญากับ TaskFlow) ----------
   กล่องอ่านโค้ด: เลื่อนในกรอบตัวเอง ไม่ดันหน้าให้กว้างเกินจอ */
.code-block {
  margin-top: var(--sp-2);
  max-height: 320px; overflow: auto;
  padding: var(--sp-3); border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.5;
  white-space: pre; tab-size: 2; color: var(--text);
}

/* ---------- 46) Capability ต่อคน — ใช้ในหน้าทีมงาน โปรไฟล์ และผลงานรายบุคคล ---------- */
.cap-list { display: grid; gap: var(--sp-3); }
.cap-row {
  display: grid; gap: var(--sp-1) var(--sp-3); align-items: center;
  grid-template-columns: 1fr;
  padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border);
}
.cap-row:last-child { padding-bottom: 0; border-bottom: 0; }
.cap-name { font-size: var(--fs-sm); font-weight: 600; min-width: 0; }
.cap-input { display: flex; align-items: center; gap: var(--sp-2); }
.cap-input input { width: 5.5rem; }
/* Load ของคนอื่น — เห็นตัวเลขได้แต่แก้ไม่ได้ (token เป็นกำลังของเจ้าตัว)
   กว้างเท่า input และเส้นประ เพื่อให้อ่านออกทันทีว่าช่องนี้ไม่ใช่ช่องกรอก */
.load-locked {
  display: inline-grid; place-items: center;
  width: 5.5rem; min-height: 2.25rem;
  padding: 0 var(--sp-2); border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
@media (min-width: 768px) {
  .cap-row { grid-template-columns: minmax(180px, 1fr) auto auto; }
}


/* ============================================================
   47) Tabs — ใช้กับหน้า Settings, Products (Product/Tool) และ Field of Expertise

   เป็นลิงก์จริง (<a href="?tab=…">) ไม่ใช่ปุ่ม JS — แท็บที่เปิดอยู่จึง bookmark ได้
   ส่งลิงก์ให้เพื่อนแล้วเปิดมาตรงแท็บเดิม และปุ่ม Back ของเบราว์เซอร์ทำงานตามที่คาด
   ============================================================ */
.tabs {
  display: flex; flex-wrap: wrap; gap: var(--sp-1);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.tab {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: -1px;
  border: 1px solid transparent; border-bottom-color: transparent;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted);
  text-decoration: none; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.tab:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.tab.is-active {
  color: var(--text); background: var(--surface);
  border-color: var(--border); border-bottom-color: var(--surface);
}
.tab-count {
  font-size: var(--fs-xs); font-weight: 700;
  padding: 0 var(--sp-2); border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.tab.is-active .tab-count { background: var(--primary-soft); color: var(--text); }
@media (max-width: 767px) {
  /* มือถือ: เลื่อนแนวนอนแทนการตัดบรรทัด แท็บจะได้ไม่กินความสูงครึ่งจอ */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .tab { padding: var(--sp-3); }
}

/* ============================================================
   48) หน้า Field of Expertise — ทะเบียน 21 สาขาตาม Competency Framework
   ============================================================ */
.exp-group { margin-bottom: var(--sp-7); }
.exp-group-note {
  font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted);
  margin-bottom: var(--sp-4);
}
.exp-card {
  display: grid; gap: var(--sp-3);
  padding: var(--sp-5); margin-bottom: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.exp-head {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: var(--sp-3);
}
.exp-title { display: flex; align-items: baseline; gap: var(--sp-3); min-width: 0; }
/* รหัส A–U — ตัวเลขประจำสาขาที่เอกสารเก่าอ้างถึง จึงต้องเห็นชัดพอ ๆ กับชื่อ */
.exp-code {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: var(--r-sm);
  background: var(--primary-soft); color: var(--text);
  font-weight: 700; font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
.exp-name { font-size: var(--fs-md); font-weight: 700; }
.exp-sub {
  font-size: var(--fs-sm); line-height: var(--lh-body); color: var(--text-muted);
}
.exp-meta {
  display: grid; gap: var(--sp-2);
  padding-top: var(--sp-3); border-top: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--text-muted);
}
@media (min-width: 768px) {
  .exp-meta { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
}
.exp-meta strong { color: var(--text); }
.exp-people { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }

/* ============================================================
   49) Expenses — ค่าใช้จ่ายที่อ้างเอกสารใน ERP
   ============================================================ */
/* เลขที่เอกสารเป็น mono เพราะคนต้องเอาไปพิมพ์ค้นใน ERP ต่อ — ต้องแยก 0 กับ O ออก */
.erp-doc {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  padding: 2px var(--sp-2); border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-total {
  font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.expense-split {
  display: grid; gap: var(--sp-2);
  margin-top: var(--sp-4);
}
.expense-split-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--sp-3); align-items: center;
  font-size: var(--fs-sm);
}

/* ============================================================
   50) ที่อัปโหลดรูปโปรไฟล์ — รูปตัวอย่างใหญ่ + ปุ่มเลือกไฟล์ข้าง ๆ
   ============================================================ */
.avatar-edit {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.avatar-xl { width: 84px; height: 84px; font-size: var(--fs-xl); }
.avatar-edit-actions { display: grid; gap: var(--sp-2); }
.avatar-edit input[type="file"] { display: none; }

/* ---------- แถวผู้ได้รับมอบหมาย: ติ๊กหลายคน + เลือกผู้ดูแลหลัก 1 คน ----------
   ผู้ดูแลหลักอยู่คอลัมน์เดียวกับช่องติ๊ก ไม่ใช่ dropdown แยกอีกที่ —
   คนกรอกจะได้เห็นพร้อมกันว่า "ใครทำบ้าง" กับ "ใครเป็นหลัก" โดยไม่ต้องเลื่อนหา */
.cap-head {
  display: none;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
  padding-bottom: var(--sp-2); margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
}
.cap-lead { display: flex; align-items: center; gap: var(--sp-2); }
/* มือถือ: radio ไม่มีหัวคอลัมน์ให้อ่าน จึงติดป้ายข้างตัวเอง */
.cap-lead-tag { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
@media (min-width: 768px) {
  /* หัวคอลัมน์กับแถวข้อมูลเป็นคนละ grid — ถ้าใช้ auto ทั้งคู่ ความกว้างจะอิงเนื้อหา
     ของตัวเอง (หัวอิงข้อความ · แถวอิง input) แล้วคอลัมน์จะเหลื่อมกันทันที
     จึงล็อกความกว้าง 3 คอลัมน์ท้ายให้เท่ากันทั้งสองที่ */
  .cap-row.is-assign,
  .cap-head { grid-template-columns: minmax(180px, 1fr) 92px 150px 120px; }
  .cap-head { display: grid; gap: var(--sp-3); }
  .cap-head span:not(:first-child) { text-align: center; }
  .cap-lead { justify-content: center; }
  .cap-lead-tag { display: none; }   /* หัวคอลัมน์บอกแล้ว ไม่ต้องซ้ำทุกแถว */
}

/* หลายคนในแถว charter เดียว — เว้นช่องพอให้แยกคนออกจากกันโดยไม่ต้องมีเส้นคั่น */
.person-row { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }
