:root {
  --bg: #f9fafc;
  --card: #ffffff;
  --text: #1a2032;
  --text-muted: #5c6478;
  /* สีตัวหนังสือ "รองแบบอ่านออก" — อยู่กึ่งกลางระหว่าง --text กับ --text-muted
     ใช้กับข้อมูลที่ต้องอ่านจริง ๆ แต่ไม่ควรเด่นเท่าหัวเรื่อง (ชื่อเล่น, ชื่อคนดูแล)
     ทีมแจ้ง 1 ก.ย. ว่า --text-muted จางเกินจนอ่านไม่ออกบนการ์ดกระดาน
     เพิ่มตัวแปรใหม่แทนการดัน --text-muted ให้สว่างขึ้น เพราะตัวนั้นใช้ทั้งเว็บ */
  --text-soft: #3d4457;
  /* สีชื่อเล่นอินฟลูโดยเฉพาะ — เจ้าของขอให้เป็นชมพู 1 ก.ย. เพื่อให้แยกจากชื่อช่องได้ทันที
     เลี่ยงโทนแดง-ชมพูจัดตั้งใจ เพราะใกล้สีแบรนด์ TikTok (#FE2C55) ซึ่ง CLAUDE.md ห้ามใช้เป็นสี UI */
  --nick: #c02a68;
  /* จานสี "ชื่อคนดูแล" — คนละสีต่อคน เพื่อกวาดตาหาการ์ดของตัวเองเจอเร็วบนคอลัมน์หมื่นใบ
     เลือกคนละเฉดสีให้ห่างกันมากที่สุด และเลี่ยงสีที่ระบบใช้สื่อความหมายอยู่แล้ว
     (เขียว=สำเร็จ · เหลือง=เตือน · แดง=อันตราย · น้ำเงิน #2563eb=สีหลัก)
     ผ่านเกณฑ์ AA ทั้ง 8 สี ทั้งสองธีม — ดูตัวเลขในคอมมิตที่เพิ่มไฟล์นี้ */
  --who-0: #d6336c;
  --who-1: #4338ca;
  --who-2: #0f766e;
  --who-3: #c2410c;
  --who-4: #7e22ce;
  --who-5: #0e7490;
  --who-6: #92400e;
  --who-7: #4d7c0f;
  --accent: #2563eb;
  --accent-light: #eef4ff;
  --btn-bg: #1a2032;
  --btn-bg-hover: #2563eb;
  --success: #16a34a;
  --success-bg: #eafaf0;
  --warn: #d97706;
  --warn-bg: #fef6ea;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --border: #e7e9ef;
  --border-strong: #cbd0dd;
  /* พื้นรองที่ใช้ตอน hover/แถวสลับสี/ปุ่มถูกกด — เดิมฝังสีตายกระจายอยู่หลายที่ */
  --surface-2: #f1f4fa;
  --surface-3: #e7e9ef;
  --surface-muted: #f0f1f5;
  --disabled-bg: #f5f6f9;
  /* พื้น+ขอบของ "ช่องกรอก" โดยเฉพาะ — โหมดสว่างเท่ากับการ์ด แต่โหมดมืดต้องต่างจากการ์ด
     ไม่งั้นช่องกรอกจมไปกับพื้นการ์ด มองไม่ออกว่าตรงไหนกรอกได้ (เจ้าของแจ้งมาเอง 29 ส.ค.) */
  --field-bg: #ffffff;
  --field-border: #e7e9ef;
  --on-accent: #ffffff;
  --text-faint: #c7cad4;
  --overlay: rgba(26, 32, 50, .45);
  --shadow-sm: 0 2px 16px rgba(26, 32, 50, .06);
  --shadow-md: 0 8px 28px rgba(26, 32, 50, .16);
  --shadow-lg: 0 12px 32px rgba(26, 32, 50, .16);
  --shadow-toast: 0 6px 20px rgba(26, 32, 50, .18);
  /* เงาการ์ดย่อยที่หน้าอื่นใช้ (การ์ด Kanban, การ์ดโปรเจกต์) */
  --cat-1: #2563eb;
  --cat-2: #16a34a;
  --cat-3: #d97706;
  --cat-4: #7c3aed;
  --cat-5: #db2777;
  --cat-6: #0891b2;
  --shadow-card: rgba(26, 32, 50, .08);
  --shadow-card-hover: rgba(26, 32, 50, .14);
  --testbar-border: #f0cf9b;
  --testbar-text: #8a4b06;
  --test-row-bg: #fffaf2;
  --radius: 14px;
  /* ตัวเลขเงินใช้ฟอนต์ความกว้างเท่ากันทุกตัว เรียงเป็นคอลัมน์แล้วหลักตรงกัน อ่านง่ายกว่ามาก */
  --font-mono: "IBM Plex Mono", "Anuphan", monospace;
  /* ลูกศรของช่องเลือก วาดเป็น SVG ฝังใน CSS — ไม่ต้องโหลดไฟล์เพิ่ม และเปลี่ยนสีได้ที่เดียว */
  --select-arrow: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%235c6478' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ===== ชุดสีมืด =====
   ค่าพื้น/การ์ด/ตัวหนังสือ ถอดมาจากเว็บแอปเดิมของเจ้าของโดยตรง จะได้ความรู้สึกเดียวกัน
   ส่วนสีหลักยังเป็นน้ำเงินตามระบบเรา (ไม่ใช้ส้ม เพราะชนกับสีแบรนด์ Shopee เวลาแยกช่องทาง)
   แค่ปรับให้สว่างขึ้นพอที่จะอ่านออกบนพื้นมืด */
[data-theme="dark"] {
  --bg: #0e0f13;
  --card: #1a1c23;
  --text: #f2f2f5;
  --text-muted: #9aa0ae;
  --text-soft: #c8cde0;
  --nick: #f7b8d0;
  --who-0: #fda4c4;
  --who-1: #a5b4fc;
  --who-2: #5eead4;
  --who-3: #fdba74;
  --who-4: #d8b4fe;
  --who-5: #67e8f9;
  --who-6: #e0b088;
  --who-7: #a3e635;
  --text-faint: #6b7280;
  --accent: #60a5fa;
  --accent-light: #1b2740;
  --btn-bg: #2563eb;
  --btn-bg-hover: #1d4ed8;
  --success: #34d399;
  --success-bg: #10291f;
  --warn: #fbbf24;
  --warn-bg: #2e2410;
  --danger: #f87171;
  --danger-bg: #2e1b1b;
  --border: #2a2d37;
  --border-strong: #3a3d49;
  --surface-2: #22242c;
  --surface-3: #2a2d37;
  --surface-muted: #22242c;
  --disabled-bg: #1f2129;
  --field-bg: #262a35;
  --field-border: #414659;
  --on-accent: #ffffff;
  --overlay: rgba(0, 0, 0, .62);
  --shadow-sm: 0 2px 16px rgba(0, 0, 0, .45);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .55);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  --shadow-toast: 0 6px 20px rgba(0, 0, 0, .6);
  --testbar-border: #6b4a12;
  --testbar-text: #fbbf24;
  --test-row-bg: #241d10;
  --cat-1: #60a5fa;
  --cat-2: #34d399;
  --cat-3: #fbbf24;
  --cat-4: #a78bfa;
  --cat-5: #f472b6;
  --cat-6: #22d3ee;
  --shadow-card: rgba(0, 0, 0, .5);
  --shadow-card-hover: rgba(0, 0, 0, .6);
  --select-arrow: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%239aa0ae' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Anuphan', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .heading, .stat-number, .logo-text {
  font-family: 'Bai Jamjuree', sans-serif;
  margin: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 13px 22px;
  font-family: 'Anuphan', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease, transform .05s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--btn-bg); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--btn-bg-hover); }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-block { width: 100%; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
/* ช่องกรอกที่ไม่ได้อยู่ใน .field (ช่องค้นหาตามหัวตาราง ฯลฯ) เคยตกไปใช้ค่าเริ่มต้นของเบราว์เซอร์
   ผลคือบนมือถือสูงแค่ 21px กดยาก และ iOS ซูมหน้าจอเองเพราะตัวอักษรเล็กกว่า 16px
   ตั้งค่าพื้นฐานให้ทุกช่องก่อน แล้ว .field ค่อยทับด้วยขนาดเต็ม */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  font-family: 'Anuphan', sans-serif;
  font-size: 16px;
  padding: 9px 12px;
  border: 1.5px solid var(--field-border);
  border-radius: 9px;
  background: var(--field-bg);
  color: var(--text);
  outline: none;
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus { border-color: var(--accent); }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: 'Anuphan', sans-serif;
  border: 1.5px solid var(--field-border);
  border-radius: 10px;
  background: var(--field-bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 84px; line-height: 1.5; }

/* ===== ช่องเลือก (select) ทั้งระบบ =====
   ปิดหน้าตาเริ่มต้นของเบราว์เซอร์แล้ววาดลูกศรเอง จะได้เหมือนกันทุกเครื่อง
   ทุกระบบปฏิบัติการ และเข้ากับการ์ด/ชิปที่เหลือ */
select {
  appearance: none;
  -webkit-appearance: none;
  font-family: 'Anuphan', sans-serif;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  background: var(--field-bg) var(--select-arrow) no-repeat right 12px center;
  background-size: 11px;
  border: 1.5px solid var(--field-border);
  border-radius: 10px;
  padding: 9px 34px 9px 13px;   /* เว้นที่ขวาให้ลูกศร ตัวหนังสือจะได้ไม่ทับ */
  cursor: pointer;
  outline: none;
  max-width: 100%;
  transition: border-color .15s ease;
}
select:hover { border-color: var(--border-strong); }
select:focus { border-color: var(--accent); }
select:disabled { background-color: var(--disabled-bg); color: var(--text-muted); cursor: not-allowed; }

/* ช่องเลือกในฟอร์ม (.field) ตัวใหญ่กว่า และตั้ง background ทับไว้ ต้องคืนลูกศรให้ด้วย */
.field select {
  background: var(--field-bg) var(--select-arrow) no-repeat right 14px center;
  background-size: 11px;
  padding-right: 38px;
  font-size: 16px;
  font-weight: 400;
}

/* ปุ่มลืมตาดูรหัสผ่าน — พิมพ์รหัสผิดแล้วไม่รู้ตัวคือปัญหาที่เจอบ่อยสุดตอนตั้งรหัสใหม่ */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 9px 10px; border-radius: 8px;
  /* ให้นิ้วโป้งกดโดนบนมือถือ */
  min-width: 40px; min-height: 40px;
}
.pw-toggle:hover { background: var(--surface-2); }
.pw-toggle:active { background: var(--surface-3); }

.banner {
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.banner-error { background: var(--danger-bg); color: var(--danger); }
.banner-success { background: var(--success-bg); color: var(--success); }
.banner-info { background: var(--accent-light); color: var(--accent); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }

.chip {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}
.chip-blue { background: var(--accent-light); color: var(--accent); }
.chip-green { background: var(--success-bg); color: var(--success); }
.chip-amber { background: var(--warn-bg); color: var(--warn); }
.chip-red { background: var(--danger-bg); color: var(--danger); }
.chip-grey { background: var(--surface-muted); color: var(--text-muted); }

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: currentColor;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted { color: var(--text-muted); }
/* ชื่อเล่นในวงเล็บหลังชื่อช่อง · ชื่อคนดูแล — 2 จุดที่ทีมอ่านไม่ออกตอนใช้กระดานจริง
   คมชัดขึ้นเป็น ~10:1 (เดิม ~6:1) แต่ยังไม่เท่าตัวหนังสือหลัก ชื่อช่องจึงยังเด่นกว่า */
.nick { color: var(--nick); font-weight: 500; }
.owner-tag { color: var(--text-soft); font-weight: 600; }
/* สีประจำตัวคนดูแล — ใส่คู่กับ .owner-tag เสมอ (.owner-tag คุมขนาด/น้ำหนัก · .who-N คุมสี)
   ไม่มีคลาส .who-N = ตกกลับไปใช้สีเทาของ .owner-tag ซึ่งอ่านออกอยู่แล้ว ไม่พัง */
.who-0 { color: var(--who-0); }
.who-1 { color: var(--who-1); }
.who-2 { color: var(--who-2); }
.who-3 { color: var(--who-3); }
.who-4 { color: var(--who-4); }
.who-5 { color: var(--who-5); }
.who-6 { color: var(--who-6); }
.who-7 { color: var(--who-7); }

@media (max-width: 640px) {
  .container { padding: 0 16px; }
}

/* ===== App shell: sidebar + topbar (app.* / dashboard.html / sales.html ฯลฯ) ===== */
.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 230px;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  z-index: 30;
  overflow-y: auto;
  transition: transform .2s ease;
}
.sidebar-brand {
  font-family: 'Bai Jamjuree', sans-serif;
  font-weight: 700;
  font-size: 20px;
  padding: 6px 10px 22px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--text); font-size: 14.5px; font-weight: 500;
}
.sidebar-link:hover { background: var(--surface-2); text-decoration: none; }
.sidebar-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.sidebar-icon { font-size: 17px; width: 20px; text-align: center; flex: none; }

/* sidebar 2 ชั้น — หัวกลุ่มพับได้ + เมนูลูก */
.sidebar-group { display: flex; flex-direction: column; margin-top: 6px; }
.sidebar-group:first-child { margin-top: 0; }
.sidebar-group-head {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: 0; background: none; border-radius: 10px;
  cursor: pointer; text-align: left;
  font-family: 'Anuphan', sans-serif; font-size: 13px; font-weight: 700;
  color: var(--text-muted);
}
.sidebar-group-head:hover { background: var(--surface-2); }
.sidebar-group-label { flex: 1; }
.sidebar-caret { font-size: 11px; color: var(--text-muted); transition: transform .18s ease; }
.sidebar-group.open .sidebar-caret { transform: rotate(180deg); }
.sidebar-group-items {
  display: none; flex-direction: column; gap: 2px;
  margin: 2px 0 0 21px; padding-left: 8px;
  border-left: 1px solid var(--border);
}
.sidebar-group.open .sidebar-group-items { display: flex; }
.sidebar-link.sidebar-sub { padding: 9px 10px; font-size: 14px; }

/* ตัวเลขคำขอค้างบนเมนู — ซ่อนไว้จนกว่าจะมีของจริง ไม่ให้เมนูรกด้วยเลข 0 */
.sidebar-badge { display: none; }
.sidebar-badge.show {
  display: inline-block; margin-left: auto; min-width: 20px; padding: 1px 6px;
  border-radius: 10px; font-size: 12px; font-weight: 700; text-align: center;
  background: var(--warn-bg); color: var(--warn);
}
.sidebar-badge.show.urgent { background: var(--danger-bg); color: var(--danger); }


.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: 25;
}

.app-body { margin-left: 230px; min-height: 100vh; transition: margin-left .2s ease; }
/* พับเมนูซ้ายเก็บ — คืนพื้นที่ 230px ให้เนื้อหา (ทีมที่ใช้จอ 19 นิ้วเห็นกระดานไม่ครบ)
   จำแยกรายคนที่เครื่องของคนนั้น เหมือนโหมดสว่าง/มืด ไม่ได้บังคับให้เหมือนกันทั้งทีม
   จำกัดไว้เฉพาะจอกว้าง เพราะจอแคบกว่านี้เมนูซ่อนเป็นปุ่ม ☰ อยู่แล้ว จะชนกันเอง */
@media (min-width: 861px) {
  html.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
  html.sidebar-collapsed .app-body { margin-left: 0; }
}
.app-topbar {
  height: 60px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; flex: 1; }
/* ปุ่มกลับหน้าเดิม โผล่เฉพาะตอนถูกส่งมาจากหน้าอื่น (มี ?back= ใน URL) */
.topbar-back { flex: 0 0 auto; margin-right: 10px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 13.5px; font-weight: 600; }
.hamburger-btn { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
/* ปุ่มพับเมนู — ตรงข้ามกับ ☰ ตรงที่โผล่เฉพาะจอกว้าง */
.sidebar-toggle { display: none; }
@media (min-width: 861px) { .sidebar-toggle { display: block; } }

.notif-wrap { position: relative; }
.notif-bell { background: none; border: none; font-size: 19px; cursor: pointer; position: relative; padding: 4px 6px; line-height: 1; color: var(--text); }
.notif-count { position: absolute; top: -2px; right: -2px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.notif-panel { position: absolute; top: calc(100% + 8px); right: 0; width: 340px; max-height: 420px; overflow-y: auto; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md); z-index: 30; display: none; }
.notif-panel.open { display: block; }
.notif-panel-head { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: var(--accent-light); }
.notif-item-title { font-weight: 600; margin-bottom: 3px; }
.notif-item-body { color: var(--text-muted); font-size: 12px; margin-bottom: 3px; }
.notif-item-time { color: var(--text-muted); font-size: 11px; }
.notif-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* แถบกรองประเภทแจ้งเตือน — วัดจริงแล้ว 74% ของแจ้งเตือนทั้งระบบเป็นประเภทเดียว (การ์ดย้ายเข้า)
   ถ้าไม่มีที่กรอง เรื่องที่มีคนเรียกหาตัวจริง (@แท็ก 0.3%) จะไม่มีวันถูกเห็น */
.notif-tabs { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.notif-tab { flex: 0 0 auto; font-family: 'Anuphan', sans-serif; font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.notif-tab:hover { color: var(--text); }
.notif-tab.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.notif-tab .n { opacity: .75; margin-left: 3px; }
/* @แท็ก ต้องเด่นกว่าใบอื่นเสมอ ไม่ว่าจะอ่านแล้วหรือยัง — นี่คือใบที่มีคนรอคำตอบอยู่ */
.notif-item.kind-mention { border-left: 3px solid var(--warn); }
.notif-item.kind-mention .notif-item-title::before { content: '@ '; color: var(--warn); font-weight: 700; }
.btn-small { padding: 8px 14px; font-size: 13px; }
.app-main { padding: 24px; max-width: 1120px; }

.pending-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.pending-card { max-width: 420px; text-align: center; padding: 36px 28px; }

.module-placeholder {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}
.module-placeholder .icon { font-size: 34px; margin-bottom: 12px; display: block; }
.module-placeholder h2 { color: var(--text); margin-bottom: 8px; font-size: 18px; }

@media (max-width: 860px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); }
  .app-body { margin-left: 0; }
  .hamburger-btn { display: block; }
  .sidebar-backdrop.open { display: block; }
  .topbar-user { display: none; }
}

/* ===== Data tables & CRUD widgets (ใช้ร่วมกันทุกโมดูล) ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.section-header h2 { font-size: 17px; }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.data-table th {
  text-align: left; font-size: 13px; color: var(--text); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
/* หัวข้อของคอลัมน์เงินต้องชิดขวาให้ตรงกับตัวเลขข้างล่าง
   ⚠️ ต้องเขียนเป็น .data-table th.money (0,2,1) ไม่ใช่พึ่งคลาส .money เฉย ๆ (0,1,0)
   เพราะ .data-table th (0,1,1) แรงกว่า จะทับ text-align ของ .money ทิ้งแบบเงียบ ๆ
   ผลคือหัวข้ออยู่ซ้าย ตัวเลขอยู่ขวา มองแล้วเหมือนคอลัมน์เหลื่อมกัน (เจ้าของแจ้งเอง 29 ส.ค.) */
.data-table th.money { text-align: right; }
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.money { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -.2px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; font-size: 12.5px; font-family: 'Anuphan', sans-serif;
  color: var(--text); transition: border-color .15s, color .15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: 14px; }

.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-box { background: var(--card); border-radius: 16px; max-width: 460px; width: 100%; padding: 26px; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

.tabs-row { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-link {
  padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-weight: 600; font-size: 13.5px; cursor: pointer;
  background: none; border-left: none; border-top: none; border-right: none; font-family: 'Anuphan', sans-serif;
}
.tab-link.active { color: var(--accent); border-bottom-color: var(--accent); }

.cost-panel { margin-top: 12px; padding: 20px; background: var(--bg); border-radius: 12px; }
.cost-summary-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.cost-summary-row:last-child { border-bottom: none; font-weight: 700; padding-top: 10px; }
.form-row-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row-inline .field { margin-bottom: 0; flex: 1; min-width: 110px; }

/* ===== Toast (แจ้งเตือนแทน alert()) ===== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; max-width: 320px;
}
.toast {
  padding: 13px 16px; border-radius: 10px; font-size: 13.5px; color: #fff;
  box-shadow: var(--shadow-toast);
  animation: toast-in .18s ease;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }
.toast-info { background: var(--accent); }
.toast-warn { background: var(--warn); }

/* กล่องผลค้นหาที่ลอยเหนือช่องกรอก — ใช้ทั้งการแท็ก @ ในคอมเมนต์ และช่องค้นอินฟลูในหน้ายอดขาย */
.mention-wrap { position: relative; }
.mention-pop {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); overflow: hidden; max-height: 240px; overflow-y: auto;
}
.mention-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 44px; padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.mention-item.active, .mention-item:hover { background: var(--bg); }
.mention-role { font-size: 11.5px; color: var(--text-muted); }

/* ปุ่มปิดโมดัล — เดิมพื้นเป็น var(--text) ซึ่งโหมดมืดเกือบขาว ตัว × ก็ขาว เลยกลายเป็นวงกลมขาวเปล่า ๆ
   ใช้พื้นเดียวกับฉากหลังการ์ด + เส้นขอบ จึงเห็นชัดทั้งสองธีม · 32px ให้กดโดนบนมือถือ */
.modal-close {
  position: absolute; top: 12px; right: 14px;
  width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 50%;
  font-size: 15px; line-height: 1; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 480px) {
  .toast-container { left: 16px; right: 16px; max-width: none; }
}

/* ===== Date Range Picker (ตัวกรองวันที่แบบเดียวกันทุกหน้า) ===== */
.drp-wrap { position: relative; display: inline-block; }
.drp-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); cursor: pointer; font-size: 13.5px; font-family: inherit;
  color: var(--text); white-space: nowrap; height: 40px;
}
.drp-trigger:hover { border-color: var(--accent); }
.drp-trigger .drp-icon { opacity: .6; }
.drp-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex; overflow: hidden; width: max-content;
}
.drp-presets { width: 148px; border-right: 1px solid var(--border); padding: 8px; flex-shrink: 0; }
.drp-preset-btn {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px;
  border: none; background: none; cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text);
}
.drp-preset-btn:hover, .drp-preset-btn.active { background: var(--accent-light); color: var(--accent); }
.drp-body { padding: 14px 16px; }
.drp-cal-row { display: flex; gap: 22px; }
.drp-cal { width: 220px; }
.drp-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13.5px; font-weight: 600; }
.drp-cal-nav { border: none; background: none; cursor: pointer; font-size: 14px; padding: 3px 8px; border-radius: 6px; color: var(--text-muted); }
.drp-cal-nav:hover { background: var(--bg); color: var(--accent); }
.drp-cal-nav.drp-invisible { visibility: hidden; }
.drp-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.drp-cal-dow { text-align: center; font-size: 11px; color: var(--text-muted); padding: 4px 0; }
.drp-cal-day { text-align: center; font-size: 12.5px; padding: 7px 0; cursor: pointer; }
.drp-cal-day .drp-day-inner { border-radius: 6px; padding: 2px 0; }
.drp-cal-day:hover .drp-day-inner { background: var(--bg); }
.drp-cal-day.drp-muted { color: var(--text-faint); cursor: default; pointer-events: none; }
.drp-cal-day.drp-in-range { background: var(--accent-light); }
.drp-cal-day.drp-range-start { background: var(--accent-light); border-radius: 6px 0 0 6px; }
.drp-cal-day.drp-range-end { background: var(--accent-light); border-radius: 0 6px 6px 0; }
.drp-cal-day.drp-range-start .drp-day-inner, .drp-cal-day.drp-range-end .drp-day-inner { background: var(--accent); color: var(--on-accent); }
.drp-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--border); }
.drp-footer-text { font-size: 12.5px; color: var(--text-muted); }
.drp-footer-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 640px) {
  .drp-panel { position: fixed; left: 16px; right: 16px; width: auto; flex-direction: column; max-height: 80vh; overflow-y: auto; }
  .drp-presets { width: 100%; border-right: none; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 4px; }
  .drp-preset-btn { width: auto; }
  .drp-cal-row { flex-direction: column; gap: 14px; }
  .drp-cal { width: 100%; }
}

/* ===== โหมดทดสอบ (ซ้อมใช้งานโดยไม่กระทบยอดจริง) ===== */
.testmode-toggle {
  background: none; border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  color: var(--text-muted); font-family: inherit; white-space: nowrap; line-height: 1.2;
}
.testmode-toggle:hover { border-color: var(--warn); color: var(--warn); }
.testmode-toggle.on { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.testmode-bar {
  background: var(--warn-bg); border-bottom: 1px solid var(--testbar-border); color: var(--testbar-text);
  padding: 10px 24px; font-size: 13.5px; line-height: 1.5;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 60px; z-index: 19;
}
.testmode-bar strong { font-weight: 700; }
.testmode-bar .btn { margin-left: auto; flex-shrink: 0; }
.chip-test { background: var(--warn-bg); color: var(--warn); }
tr.row-test td { background: var(--test-row-bg); }
@media (max-width: 860px) {
  /* บนมือถือปล่อยให้แถบเลื่อนหายไปได้ ไม่กินพื้นที่จอค้าง — ปุ่ม 🧪 บน topbar ยังติดหนึบเตือนอยู่ตลอด */
  .testmode-bar { padding: 10px 16px; position: static; }
  .testmode-bar .btn { margin-left: 0; }
  .testmode-toggle .label { display: none; }
  .testmode-toggle { padding: 8px 12px; min-height: 38px; }
}

/* ===== นาฬิกาจับเวลาต่อคอลัมน์ (SLA) — ป้ายบอกว่าการ์ดค้างเกินกำหนดหรือยัง ===== */
.kb-card.sla-overdue { border-color: var(--danger); }
.sla-chip { display:inline-block; padding:3px 10px; border-radius:999px; font-size:11.5px; white-space:nowrap; }
.sla-overdue-chip { background: var(--danger-bg); color: var(--danger); font-weight:600; }
.sla-today-chip { background: var(--warn-bg); color: var(--warn); font-weight:600; }
.sla-soon-chip { background: var(--warn-bg); color: var(--warn); }
.sla-ok-chip { background: var(--success-bg); color: var(--success); }
.sla-none-chip { background: var(--surface-muted); color: var(--text-muted); }

/* ===== ตารางกรอกค่าใช้จ่ายย้อนหลังรายเดือน (แถว=ประเภท · คอลัมน์=เดือน) =====
   ทุกสีมาจากตัวแปร ห้ามเขียนสีตรง ๆ ไม่งั้นโหมดมืดจะเหลือจุดขาวโพลน */
.mx-grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.mx-grid th, .mx-grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.mx-grid thead th {
  font-size: 12px; color: var(--text-muted); font-weight: 700; text-align: right;
  position: sticky; top: 0; background: var(--card); z-index: 2;
}
.mx-grid thead th.mx-cat-head { text-align: left; }
/* คอลัมน์ประเภทติดขอบซ้ายไว้ เลื่อนดูเดือนไกล ๆ แล้วยังรู้ว่าบรรทัดนี้คืออะไร */
.mx-grid .mx-cat { position: sticky; left: 0; background: var(--card); z-index: 1; font-weight: 600; text-align: left; }
.mx-grid thead th.mx-cat-head { left: 0; z-index: 3; }
.mx-grid tbody tr:hover .mx-cat { background: var(--surface-2); }

.mx-cell { width: 108px; }
.mx-grid td.mx-cell input {
  width: 100%; text-align: right; padding: 7px 8px; font-size: 16px; /* ต่ำกว่า 16px มือถือจะซูมเอง */
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  border: 1px solid var(--field-border); border-radius: 8px;
  background: var(--field-bg); color: var(--text);
}
.mx-grid td.mx-cell input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
/* ช่องว่าง = "ยังไม่ได้กรอก" ไม่ใช่ ฿0 — ทำให้เห็นด้วยตาว่ายังขาดตรงไหน */
.mx-grid td.mx-cell input:placeholder-shown { border-style: dashed; border-color: var(--border-strong); background: var(--disabled-bg); }
.mx-grid td.mx-cell input.mx-dirty { border-color: var(--warn); background: var(--warn-bg); }

.mx-locked {
  text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--text-muted); background: var(--surface-muted); border-radius: 8px; padding: 7px 8px;
}
.mx-total { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; font-weight: 700; }
.mx-grid tfoot td { border-top: 2px solid var(--border); border-bottom: none; padding-top: 12px; background: var(--card); }
.mx-grid tfoot td.mx-cat { font-weight: 700; }
.mx-miss { color: var(--warn); font-weight: 600; }
.mx-locked.mx-dup { background: var(--warn-bg); color: var(--warn); font-weight: 600; }

/* มือถือ: ช่องกรอกในตารางต้องสูงพอให้นิ้วโป้งกดโดน (36px เดิมฝืดไป) */
@media (max-width: 720px) {
  .mx-grid td.mx-cell input { padding: 11px 8px; }
  .mx-grid .mx-locked { padding: 11px 8px; }
}

/* ===== ตัวเลือกเดือน (◀ เดือน ปี ▶) =====
   ใช้แทน input[type=month] ของเบราว์เซอร์ ซึ่งโชว์ปี ค.ศ. และหน้าตาไม่เหมือนหน้าอื่นทั้งเว็บ */
.month-nav { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-nav select { min-height: 42px; }   /* ให้สูงเท่าปุ่ม ◀ ▶ ไม่งั้นขอบเหลื่อมกัน 2px */
.month-nav-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; min-height: 42px; padding: 0 12px;
  font-size: 14px; line-height: 1; cursor: pointer;
  color: var(--text); background: var(--field-bg);
  border: 1.5px solid var(--field-border); border-radius: 10px;
  transition: border-color .15s ease, background .15s ease;
}
.month-nav-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-light); }
.month-nav-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ปุ่ม 📎 ของแถวที่ยังไม่มีเอกสารแนบ — ต้องสะดุดตาพอให้ตามเก็บก่อนถึงเวลายื่นภาษี */
.icon-btn.exp-nodoc { color: var(--warn); border-color: var(--warn); }

/* ปุ่ม 🖨️ ของแถวที่พิมพ์ใบปะหน้าบิลไปแล้ว — ไล่สายตาลงมาทั้งตารางแล้วรู้ทันทีว่าทำถึงไหน
   ใช้สีเดียวกับ "สำเร็จ" ทั้งเว็บ ไม่ตั้งสีใหม่ให้ทีมต้องมาจำเพิ่ม */
.icon-btn.exp-printed { color: var(--success); border-color: var(--success); }

/* ---------------- ช่องลากไฟล์มาวาง ----------------
   ทำเป็นคลาสกลางไว้ที่นี่ ไม่ใช่ style ฝังในหน้าเดียว เพราะที่อื่นก็ต้องแนบไฟล์เหมือนกัน
   (นำเข้าออเดอร์ · ไฟล์การเงินแพลตฟอร์ม) จะได้หน้าตาเดียวกันทั้งเว็บ
   กล่องทั้งกล่องกดได้ ไม่ใช่แค่ตัวหนังสือ — บนมือถือลากไม่ได้ ต้องกดแล้วเปิดกล้อง/คลังรูปเลย */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-muted);
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); }
/* ตอนลากไฟล์ค้างอยู่เหนือกล่อง ต้องเปลี่ยนชัดเจนพอให้รู้ว่า "ปล่อยตรงนี้ได้แล้ว" */
.dropzone.is-over { border-color: var(--accent); background: var(--accent-light); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dz-icon { font-size: 30px; line-height: 1; margin-bottom: 8px; }
.dz-main { font-weight: 600; font-size: 14.5px; }
.dz-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 5px; line-height: 1.6; }
.dz-link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

.dz-file { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--border); font-size: 13px; }
.dz-file:last-child { border-bottom: none; }
.dz-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-size { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }
.dz-state { font-size: 11.5px; white-space: nowrap; }
.dz-state.ok { color: var(--success); }
.dz-state.bad { color: var(--danger); }
.dz-state.busy { color: var(--accent); }
