/* ─────────────────────────────────────────────────────────────────────────
   monthreport — ธีม "Paper"
   โทนกระดาษ e-book สำหรับอ่านบทวิเคราะห์ยาวๆ โดยไม่ล้าตา
   หลักที่ยึด: ฟอนต์เดียว, type scale ตายตัว, เส้นขอบบางแทนเงา,
   ความกว้างบทอ่านจำกัด, สีเน้นใช้เฉพาะปุ่ม/ลิงก์/สถานะ
   ───────────────────────────────────────────────────────────────────────── */

/* ฟอนต์ self-host ทั้งหมด — ไม่มี @import จาก Google Fonts และไม่มี CDN
   (เคยเจอกราฟหายทั้งหน้าเพราะเครื่องปลายทางโหลด CDN ไม่ขึ้น) */
/*
 * Inter — ตัวอักษรละตินและตัวเลขทั้งเว็บ
 *
 * เป็น variable font ไฟล์เดียวคลุมน้ำหนัก 100-900 จึงประกาศ @font-face อันเดียว
 * แล้วให้เบราว์เซอร์ interpolate น้ำหนักเอง (เล็กกว่าโหลดแยก 4 ไฟล์มาก)
 *
 * unicode-range จำกัดไว้เฉพาะละติน เพราะ Inter ไม่มีอักษรไทยเลยสักตัว —
 * ตัวอักษรไทยจะตกไปหา IBM Plex Sans Thai ข้างล่างโดยอัตโนมัติ ทั้งสองฟอนต์
 * จึงทำงานร่วมกันในหน้าเดียวได้โดยไม่ต้องสลับ font-family เอง
 *
 * self-host เหมือนฟอนต์อื่นทุกตัวในโปรเจกต์นี้ ไม่โหลดจาก CDN ใดๆ ตอนรัน
 * (SIL Open Font License 1.1 — ดู public/fonts/OFL-Inter.txt)
 */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/inter-latin-variable.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+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-thai-400.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-thai-500.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-latin-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-thai-600.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-thai-700.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'IBM Plex Sans Thai';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/ibm-plex-sans-thai-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* ─────────────────────────────────────────────────────────────
   * Design tokens — ธีมสว่างสไตล์ dashboard
   *
   * 12 ค่าแรกคือค่าที่ตกลงกับผู้ใช้ไว้ตรงตัว ห้ามแก้โดยไม่ถามก่อน
   * ที่เหลือเป็นค่าที่ derive มาจากชุดนั้นเพื่อให้ทั้งเว็บใช้ภาษาสีเดียวกัน
   * ───────────────────────────────────────────────────────────── */
  --bg-page: #F4F6FA;
  --bg-sidebar: #F8FAFC;
  --bg-card: #FFFFFF;
  --accent-primary: #2F6BFF;
  --accent-primary-light: #6B8CFF;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --status-good-bg: #E6F4EA;
  --status-good-text: #1E7A3C;
  --status-warn-bg: #FDECEC;
  --status-warn-text: #C0392B;
  --card-radius: 16px;
  --spacing-unit: 8px;

  /*
   * ชื่อเดิมที่โค้ดเก่าทั้งไฟล์อ้างถึงอยู่ — ชี้มาที่ token ใหม่แทนการไล่แก้
   * ทุกจุดที่ใช้ ทำให้คอมโพเนนต์เดิมทั้งหมดเปลี่ยนธีมตามไปเองโดยไม่ต้องแตะ
   * และถ้าวันหนึ่งอยากเปลี่ยนธีมอีกรอบ ก็แก้ที่บล็อกนี้ที่เดียวเหมือนเดิม
   */
  --paper: var(--bg-page);
  --card: var(--bg-card);
  --border: #E7EBF2;
  --border-strong: #D6DDE8;
  --text-body: #334155;
  --accent-blue: var(--accent-primary);
  --green: var(--status-good-text);
  --red: var(--status-warn-text);
  --amber: #B7791F;

  --green-soft: var(--status-good-bg);
  --red-soft: var(--status-warn-bg);
  --amber-soft: #FDF3E2;
  --blue-soft: #EAF0FF;

  /* เงาบางแทนเส้นขอบหนา — การ์ดลอยจากพื้นด้วยแสง ไม่ใช่ด้วยกรอบ */
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-raised: 0 4px 16px rgba(15, 23, 42, 0.08);

  /* ── type scale (ฐาน 16px อัตราส่วนราว 1.2) ── */
  --fs-xs: 12px;
  --fs-sm: 13.5px;
  --fs-base: 16px;
  --fs-lg: 18px;
  --fs-xl: 21px;
  --fs-2xl: 28px;
  --fs-kpi: 32px;

  --lh-body: 1.7;
  --lh-tight: 1.35;

  --read-width: 760px;
  --measure: 100%;
  --radius: var(--card-radius);
  --radius-sm: 10px;

  --sidebar-width: 244px;

  /*
   * Inter มาก่อนเพื่อให้ตัวเลขและข้อความละตินเป็น Inter ส่วนอักษรไทยตกไปหา
   * IBM Plex Sans Thai เองตาม unicode-range ที่ประกาศไว้ข้างบน
   */
  --font: 'Inter', 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text-body);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* โฟกัสเห็นชัดทุกจุด ใช้สีน้ำเงินเน้นสีเดียวทั้งเว็บ */
:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ── โครงหน้า (mobile-first) ─────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════
 * โครงหน้า: sidebar ถาวรซ้าย + เนื้อหาขวา
 *
 * ใช้ CSS grid บน body โดยตรง ไม่มี div ครอบเพิ่ม — เหตุผลเชิงปฏิบัติ:
 * แต่ละหน้าเรนเดอร์ <main class="wrap"> ของตัวเองต่อท้าย header() ถ้าโครง
 * ต้องมี wrapper ก็จะมีแท็กเปิดอยู่ในฟังก์ชันหนึ่งและแท็กปิดอยู่อีกฟังก์ชัน
 * ซึ่งพังง่ายมากเวลามีคนมาเพิ่มหน้าใหม่ วาง grid ไว้ที่ body แล้วให้ลูกแต่ละตัว
 * ระบุคอลัมน์/แถวของตัวเอง จึงไม่ต้องมีแท็กที่ต้องจำไปปิดที่อื่น
 *
 * ใช้เฉพาะหน้าที่ล็อกอินแล้ว (body.app) — หน้า login กับหน้าสมัครสมาชิก
 * ไม่มี sidebar เพราะยังไม่รู้ว่าใครเข้ามาและยังไม่มีเมนูให้ไปไหน
 * ═══════════════════════════════════════════════════════════════ */
.wrap {
  width: 100%;
  max-width: var(--read-width);
  margin: 0 auto;
  padding: 0 16px 64px;
}

body.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100dvh;
}
body.app > .sidebar { grid-column: 1; grid-row: 1 / -1; }
body.app > .topbar  { grid-column: 2; grid-row: 1; }
body.app > main     { grid-column: 2; grid-row: 2; }

/* ลิงก์ข้ามไปเนื้อหา — มองไม่เห็นจนกว่าจะ tab มาโดน */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  background: var(--bg-card);
  color: var(--accent-primary);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-raised);
  font-weight: 600;
}
.skip-link:focus { left: 8px; text-decoration: none; }

/* ── sidebar ── */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 6px;
  min-width: 0;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--accent-primary), var(--accent-primary-light));
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
}
.brand-text { min-width: 0; }
.brand b {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.brand span {
  display: block;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  border: 0;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.nav-item:hover { background: rgba(15, 23, 42, 0.04); color: var(--text-primary); text-decoration: none; }
.nav-item svg { flex: 0 0 auto; }

/*
 * หน้าที่กำลังเปิดอยู่: พื้นขาว + ตัวหนังสือน้ำเงิน ตามภาพอ้างอิง
 * เกาะกับ aria-current="page" ที่มีอยู่แล้ว ไม่เพิ่มคลาสซ้ำซ้อนให้มี
 * สองแหล่งความจริงว่า "ตอนนี้อยู่หน้าไหน"
 */
.nav-item[aria-current="page"] {
  background: var(--bg-card);
  color: var(--accent-primary);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

.nav-foot { margin-top: auto; }
.nav-foot .logout-form { margin: 0; }
.nav-item.logout { color: var(--text-secondary); }
.nav-item.logout:hover { color: var(--status-warn-text); background: var(--status-warn-bg); }

/* ── แถบบนของเนื้อหา: ปุ่มเฉพาะหน้า + ปุ่มแฮมเบอร์เกอร์บนมือถือ ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-page);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}
/*
 * ปุ่มบนแถบบนเป็น "ตัวช่วยนำทาง" ไม่ใช่เนื้อหา — ขนาดและน้ำหนักจึงต้องต่ำกว่า
 * ตัวเลข KPI ซึ่งเป็นสิ่งที่คนเปิดหน้านี้มาดูจริงๆ
 *
 * ที่สำคัญกว่าขนาดคือ "สี": ปุ่มดาวน์โหลดเคยเป็นปุ่มทึบสีน้ำเงินอันเดียวในหน้า
 * จึงกลายเป็นจุดที่ตาไปตกก่อนตัวเลขทุกตัว (ดู src/views/report.js ที่เปลี่ยนเป็น
 * secondary แล้ว) — ความกล้าใช้ที่จุดเดียวคือที่เนื้อหา ไม่ใช่ที่ปุ่ม
 */
.topbar-actions .btn { min-height: 32px; padding: 5px 12px; font-size: 13px; border-radius: 9px; }

/*
 * ปุ่มแฮมเบอร์เกอร์ — ซ่อนบนจอกว้างที่ sidebar กางอยู่แล้ว
 * ใช้ display:none ไม่ใช่ visibility เพราะปุ่มที่มองไม่เห็นแต่ยัง tab ไปโดนได้
 * คือกับดักคลาสสิกของ accessibility (คนใช้คีย์บอร์ดเจอโฟกัสหายไปเฉยๆ)
 */
.nav-toggle { display: none; }

/* ── จอแคบ: sidebar ยุบเป็นลิ้นชักที่เลื่อนเข้ามา ── */
@media (max-width: 639px) {
  body.app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  body.app > .topbar { grid-column: 1; grid-row: 1; }
  body.app > main { grid-column: 1; grid-row: 2; }

  /*
   * ปุ่มแฮมเบอร์เกอร์โผล่เฉพาะตอนที่ JS ทำงานแล้วเท่านั้น (body.js-nav)
   * ปุ่มที่กดแล้วไม่มีอะไรเกิดขึ้นแย่กว่าไม่มีปุ่ม
   */
  body.js-nav .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    flex: 0 0 auto;
    padding: 0;

  }

  /*
   * ─── แถบบนต้องอยู่เหนือทั้งฉากหลัง (30) และตัวลิ้นชัก (40) ───
   *
   * ตอนลิ้นชักเปิด ปุ่มแฮมเบอร์เกอร์เปลี่ยนป้ายเป็น "ปิดเมนู" ถ้ามันถูกบังอยู่
   * ปุ่มที่บอกว่ากดแล้วปิดได้ ก็กดไม่ได้จริง
   *
   * กับดักที่เสียเวลาไปหนึ่งรอบ: ครั้งแรกใส่ z-index: 50 ที่ตัว .nav-toggle
   * เอง แล้วยังโดนลิ้นชักบังอยู่เหมือนเดิม เพราะ .topbar มี position: sticky
   * + z-index อยู่แล้ว = มันสร้าง "stacking context" ของตัวเอง ค่า z-index
   * ของลูกจึงแข่งกันได้แค่ในกล่องของแม่ ไม่ได้ยกตัวเองข้ามพี่น้องของแม่
   * ต้องยกที่ตัวแม่ (.topbar) เท่านั้น
   */
  body.app.js-nav > .topbar { z-index: 45; }

  /*
   * ลิ้นชักซ่อนอยู่นอกจอเฉพาะตอน JS พร้อมใช้งาน — ถ้า JS พังหรือโหลดไม่ทัน
   * sidebar จะยังกางอยู่บนสุดของหน้าตามลำดับ HTML ปกติ เข้าทุกหน้าได้เหมือนเดิม
   * แค่หน้าตาไม่สวย ซึ่งดีกว่าเมนูหายไปทั้งอันจนไปไหนไม่ได้
   */
  body.app.js-nav > .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(276px, 84vw);
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: var(--shadow-raised);
    overflow-y: auto;

    /*
     * visibility: hidden ไม่ใช่แค่เรื่องความสวยงาม — มันคือสิ่งที่ทำให้ลิงก์
     * ในลิ้นชักที่ปิดอยู่ "หลุดออกจากลำดับ tab" ด้วย
     *
     * ถ้าเลื่อนออกนอกจอด้วย transform อย่างเดียว ตัวลิงก์ยังอยู่ในหน้าและยัง
     * โฟกัสได้ตามปกติ คนที่ใช้คีย์บอร์ดกด Tab จากปุ่มแฮมเบอร์เกอร์แล้วโฟกัส
     * จะหายเข้าไปในเมนูที่มองไม่เห็น 4 จุดติดกันโดยไม่มีอะไรบอก — เป็นบั๊ก
     * ที่เห็นได้จากการวัดเท่านั้น มองภาพหน้าจอเฉยๆ ไม่มีทางเจอ
     *
     * หน่วงการซ่อนไว้จนแอนิเมชันเลื่อนออกจบก่อน (visibility 0s linear 180ms)
     * ไม่งั้นเมนูจะหายวับตอนเริ่มปิดแทนที่จะค่อยๆ เลื่อนออก
     */
    visibility: hidden;
    transition: transform 180ms ease-out, visibility 0s linear 180ms;

    /* เว้นที่ด้านบนให้ปุ่มแฮมเบอร์เกอร์ที่ลอยทับอยู่ ไม่ให้ไปทับชื่อเว็บ */
    padding-top: 62px;
  }
  body.app.js-nav > .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 180ms ease-out, visibility 0s;
  }

  /* ฉากหลังทึบตอนลิ้นชักเปิด — กดที่ไหนก็ปิด */
  .nav-scrim {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.38);
    z-index: 30;
    border: 0;
    padding: 0;
  }
  .topbar { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  body.app.js-nav > .sidebar,
  body.app.js-nav > .sidebar.is-open { transition: none; }
}

/* ── กริดแดชบอร์ด: กราฟกว้าง 2 ส่วน + แผงสรุป 1 ส่วน (ตามภาพอ้างอิง) ── */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.dash-grid > * { margin-bottom: 0; min-width: 0; }
@media (min-width: 900px) {
  .dash-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  /*
   * แต่ละการ์ดสูงเท่าเนื้อของตัวเอง ไม่ยืดให้เท่าการ์ดที่สูงที่สุดในแถว
   * (ค่าเริ่มต้นของ grid คือ stretch) — วันที่มีแอดมินคนเดียว การ์ดขวา
   * เคยจองที่ว่างสูงเท่ากราฟทั้งอัน ทั้งที่ข้างในมีแถบเดียว
   */
  .dash-grid { align-items: start; }
}

/* หัวการ์ดแบบมีของอยู่สองฝั่ง (ชื่อซ้าย · legend/ปุ่มขวา) */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2, .card-head .card-title { margin: 0; }

h1, h2, h3 {
  line-height: var(--lh-tight);
  color: var(--text-primary);
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.005em;
}
h1 { font-size: var(--fs-2xl); }
h2 {
  font-size: var(--fs-xl);
  margin-top: 36px;
  letter-spacing: -0.01em;
}

h3 { font-size: var(--fs-lg); margin-top: 26px; }
p { margin: 0 0 14px; max-width: var(--measure); }
li { max-width: var(--measure); }

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

.lead { color: var(--text-secondary); font-size: 15px; }
.muted { color: var(--text-secondary); }
.dim { color: var(--text-secondary); font-size: var(--fs-sm); }
.small { font-size: var(--fs-sm); }

/* ── การ์ด ───────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 0;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 16px;
}
.card > :last-child { margin-bottom: 0; }
.card-title {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-weight: 500;
  margin: 0 0 10px;
}

/* ── KPI ─────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--bg-card);
  border: 0;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px 20px;
  min-width: 0;
}
.kpi-label {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
  line-height: 1.4;
}
/*
 * ตัวเลข KPI: Inter ตัวหนา ไม่ใช้ฟอนต์ monospace
 * font-variant-numeric: tabular-nums ทำให้ตัวเลขทุกตัวกว้างเท่ากัน ค่าจึงไม่
 * ขยับซ้ายขวาเวลาอัปเดต — ได้ความนิ่งแบบ mono โดยไม่ต้องเสียรูปทรงตัวอักษร
 */
.kpi-value {
  font-size: var(--fs-kpi);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-value .unit {
  font-size: 0.5em;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
  letter-spacing: 0;
}
.kpi-value.na { color: var(--text-secondary); font-size: var(--fs-lg); font-weight: 500; }

/*
 * วันที่/เวลาในการ์ด — เป็นข้อมูลอ้างอิง ไม่ใช่ตัวเลขชี้วัด
 *
 * ขนาด --fs-kpi (32px) ถูกออกแบบมาให้ตัวเลขอย่าง "30%" ดึงสายตาข้ามหน้าจอ
 * พอเอามาใช้กับ "03/09/2026 22:26:22" มันกลายเป็นของที่ใหญ่ที่สุดในหน้า
 * ทั้งที่คนดูหน้าซิงค์เพื่อรู้ว่า "สดพอไหม" ซึ่งอ่านจากบรรทัด "ผ่านมาแล้ว..."
 * ข้างล่างเร็วกว่าอ่านตัวเลขวินาที
 */
.kpi-value.stamp {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 6px; line-height: 1.5; }

/* แถบสีบางด้านบนแทนขอบซ้ายหนาแบบธีมเดิม — บอกโทนโดยไม่ทำให้การ์ดดูมีกรอบ */
.kpi.tone-good, .kpi.tone-bad, .kpi.tone-warn { position: relative; overflow: hidden; }
.kpi.tone-good::before, .kpi.tone-bad::before, .kpi.tone-warn::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
}
.kpi.tone-good::before { background: var(--status-good-text); }
.kpi.tone-bad::before { background: var(--status-warn-text); }
.kpi.tone-warn::before { background: var(--amber); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 0;
  background: var(--blue-soft);
  color: var(--accent-primary);
  white-space: nowrap;
  line-height: 1.6;
}
.tag.good { color: var(--status-good-text); background: var(--status-good-bg); }
.tag.bad { color: var(--status-warn-text); background: var(--status-warn-bg); }
.tag.warn { color: var(--amber); background: var(--amber-soft); }

.chart { display: block; width: 100%; height: auto; overflow: visible; }

/* กราฟถูกวาดมาสองขนาด — โชว์ทีละขนาดตามความกว้างจอ ไม่ต้องใช้ JS
   (SVG ที่ยืดตาม viewBox จะขยายตัวหนังสือไปด้วย ชุดเดียวจึงครอบคลุมทั้ง
   390px และ 1920px ไม่ได้) */
.chart-wide { display: none; }
.chart-panel > .chart { max-width: 560px; margin: 0 auto; }

.chart-panel + .chart-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.chart-panel-title {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin: 0 0 6px;
  text-align: center;
}
.chart-empty {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  text-align: center;
  padding: 10px 0 4px;
}

/* คำอธิบายเมื่อกราฟรายชั่วโมงถูกซูมเข้าเฉพาะช่วงที่มีแชท —
   ต้องเห็นก่อนกราฟ ไม่งั้นคนอ่านนึกว่าข้อมูลหายหรือกราฟพัง */
.chart-zoom-note {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  background: var(--paper);
  border-left: 3px solid var(--accent-blue);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 0 0 12px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  justify-content: center;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.minibar { vertical-align: middle; }

/* กราฟแท่งแนวนอน: ป้ายชื่อเป็น HTML ตัวแท่งเป็น SVG */
/*
 * ─── สัดส่วนของกราฟแท่งแนวนอน ───
 *
 * เดิมแท่งสูง ~54px ต่อแถว 9 หัวข้อกินความสูง 706px ทั้งที่ข้อมูลคือตัวเลข 9 ตัว
 * และ border-radius: 999px ทำให้ปลายมนกลืนความยาวของแท่งสั้นจนค่า 1 กับ 2
 * ดูขนาดเท่ากัน — บิดเบือนข้อมูลจริง ไม่ใช่แค่เรื่องความสวยงาม
 *
 * ความสูงของ element ควรสะท้อนปริมาณข้อมูลที่มันบรรจุ ไม่ใช่ทุกอย่างใหญ่เท่ากันหมด
 */
.hbar { display: flex; flex-direction: column; gap: 7px; }
.hbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: 'label value' 'track track';
  align-items: center;
  gap: 3px 10px;
}
.hbar-label { grid-area: label; font-size: 14px; color: var(--text-primary); line-height: 1.4; }
.hbar-value { grid-area: value; font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar-track { grid-area: track; background: #EDF1F7; border-radius: 3px; overflow: hidden; height: 14px; }
.hbar-svg { display: block; height: 14px; }

@media (min-width: 620px) {
  .hbar-row {
    grid-template-columns: 190px minmax(0, 1fr) 92px;
    grid-template-areas: 'label track value';
    gap: 12px;
  }
  .hbar-label { text-align: right; }
}

/*
 * แถบแนวนอนที่อยู่ในแผงแคบของกริดแดชบอร์ด
 *
 * กฎข้างบนเป็น media query ที่วัดจาก "ความกว้างจอ" แต่ .hbar-row ตอนนี้ไปอยู่ใน
 * แผงที่กว้างแค่ 1 ใน 3 ของเนื้อหาด้วย พอจอกว้างพอ กฎ 3 คอลัมน์จึงทำงาน
 * ทั้งที่กล่องแม่แคบ: 190px (ป้าย) + 92px (ตัวเลข) + ช่องไฟ กินไปเกือบหมด
 * เหลือที่ให้ "รางบาร์" ไม่กี่พิกเซลจนมองไม่เห็นว่ามีบาร์อยู่
 *
 * นี่คือข้อจำกัดของ media query โดยตรง — มันไม่รู้จักขนาดของกล่องที่
 * คอมโพเนนต์ไปอยู่ รู้แค่ขนาดจอ วิธีแก้ที่ตรงจุดคือย้อนกลับไปใช้ผังสองบรรทัด
 * เฉพาะในแผงแคบ (ผังเดียวกับที่ใช้บนมือถืออยู่แล้ว จึงไม่มีอะไรใหม่ต้องดูแล)
 *
 * ต้องวางไว้ "หลัง" บล็อกข้างบนเสมอ: @media ไม่ได้เพิ่ม specificity ให้
 * ตัวที่มาทีหลังในไฟล์เท่านั้นที่ชนะ (บทเรียนเดียวกับตอนแก้ปุ่มล้นจอใน PR #11)
 */
@media (min-width: 620px) {
  .dash-grid .hbar-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'label value' 'track track';
    gap: 3px 10px;
  }
  .dash-grid .hbar-label { text-align: left; }
}

/* ── ตาราง ───────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 520px; }
th, td { text-align: right; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
/*
 * หัวตารางแยกจากเนื้อด้วยขนาด สี และน้ำหนัก — พอแล้ว ไม่ต้องพิมพ์ใหญ่ซ้ำอีก
 *
 * text-transform: uppercase ไม่มีผลกับตัวอักษรไทยซึ่งเป็นหัวตารางเกือบทั้งหมด
 * แต่ไปตะโกนใส่เศษภาษาอังกฤษที่ปนอยู่ ("med." กลายเป็น "MED.") ผลคือหัวตาราง
 * เดียวกันดังไม่เท่ากันโดยไม่มีเหตุผลทางความหมายรองรับ
 *
 * letter-spacing ก็เช่นกัน — เป็นเทคนิคของตัวพิมพ์ใหญ่ภาษาอังกฤษ พอใช้กับไทย
 * มันดันสระและวรรณยุกต์ให้ห่างจากพยัญชนะที่มันเกาะอยู่ อ่านยากขึ้นเปล่าๆ
 */
thead th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: var(--fs-xs);
}
tbody tr:hover td { background: var(--bg-page); }
tbody tr:last-child td { border-bottom: none; }
td { font-variant-numeric: tabular-nums; color: var(--text-body); }
tbody td:first-child { color: var(--text-primary); }

/* ── ตัวอย่างแชท ─────────────────────────────────────────────────────── */
.sample {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  margin-bottom: 14px;
  overflow: hidden;
}
.sample-head { padding: 13px 15px; border-bottom: 1px solid var(--border); background: var(--card); }
.sample-who {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.sample-user { font-weight: 600; font-size: 15px; color: var(--text-primary); }
.sample-reasons { margin: 8px 0 0; padding-left: 18px; font-size: var(--fs-sm); color: var(--text-secondary); line-height: 1.65; }
.sample-reasons li { margin-bottom: 3px; }

/* ผลตรวจจาก Claude API — วางท้ายการ์ดตัวอย่าง ใต้บทสนทนา จึงใช้เส้นคั่นด้านบน */
.sample-semantic { padding: 11px 15px 13px; border-top: 1px solid var(--border); }

.transcript { padding: 12px 15px 15px; }
.msg { display: flex; gap: 10px; padding: 7px 0; align-items: flex-start; }
.msg + .msg { border-top: 1px solid var(--border); }
.msg-time {
  flex: 0 0 auto;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
  min-width: 42px;
}
.msg-body { flex: 1 1 auto; min-width: 0; }
.msg-who { font-size: var(--fs-xs); font-weight: 600; margin-bottom: 2px; }
.msg.visitor .msg-who { color: var(--amber); }
.msg.agent .msg-who { color: var(--green); }
.msg.trigger .msg-who { color: var(--text-secondary); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.65; color: var(--text-body); }
.msg.trigger .msg-text { color: var(--text-secondary); }
.msg-attach { font-size: var(--fs-sm); color: var(--text-secondary); font-style: italic; }

/* ── ฟอร์ม ───────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
label { display: block; font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: 6px; }
input[type="text"], input[type="date"], input[type="password"], input[type="url"], select {
  width: 100%;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 15.5px;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 44px;
}
input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
  border-color: var(--accent-blue);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 10px 18px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: var(--accent-primary);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn.secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); box-shadow: var(--shadow-card); }
.btn.secondary:hover { background: var(--bg-page); }
.btn.small { padding: 7px 12px; min-height: 36px; font-size: var(--fs-sm); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── ตัวเลือกโหมดช่วงเวลา (ทำงานได้โดยไม่ต้องพึ่ง JS) ────────────────── */
.mode-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.radio-row label {
  margin: 0;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
#mode-day:checked ~ .radio-row label[for="mode-day"],
#mode-range:checked ~ .radio-row label[for="mode-range"],
#mode-month:checked ~ .radio-row label[for="mode-month"] {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: var(--blue-soft);
  font-weight: 500;
}
#mode-day:focus-visible ~ .radio-row label[for="mode-day"],
#mode-range:focus-visible ~ .radio-row label[for="mode-range"],
#mode-month:focus-visible ~ .radio-row label[for="mode-month"] {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* แต่ละโหมดโชว์เฉพาะช่องที่ตัวเองต้องใช้ — สลับด้วย CSS ล้วน */
.mode-fields { display: none; }
#mode-day:checked ~ .mode-fields.for-day,
#mode-range:checked ~ .mode-fields.for-range,
#mode-month:checked ~ .mode-fields.for-month { display: block; }

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-pair > .field { min-width: 0; }
/* ช่องวันที่ของเบราว์เซอร์มีความกว้างขั้นต่ำในตัว ต้องปลดออกไม่งั้นล้นจอแคบ */
.field-pair input, .field-pair select { min-width: 0; }
/* คู่ "ตั้งแต่–ถึง" ใช้ input วันที่ซึ่งกว้างกว่า select มาก จอแคบจึงวางซ้อนกันแทน */
.field-pair.dates { grid-template-columns: 1fr; }
@media (min-width: 420px) {
  .field-pair.dates { grid-template-columns: 1fr 1fr; }
}

.notice {
  background: var(--blue-soft);
  border: 0;
  border-left: 3px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.notice.bad { border-left-color: var(--red); background: var(--red-soft); }
.notice.good { border-left-color: var(--green); background: var(--green-soft); }
.notice.plain { background: var(--bg-card); border-left-color: var(--border-strong); box-shadow: var(--shadow-card); }
.notice p:last-child { margin-bottom: 0; }

.login-page, .register-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg-page);
}
.login-card { width: 100%; max-width: 380px; }
.pin-input { text-align: center; letter-spacing: 0.5em; font-size: 24px !important; padding: 14px 12px; }

/* ── แท็บเลือกวิธีเข้าสู่ระบบ (หน้า /login) ───────────────────────────────
   ใช้โทน Paper เดิมทั้งหมด: พื้นกระดาษอุ่น เส้นขอบสีเดียวกับการ์ด
   และฟ้า Facebook เป็นสีเน้นของแท็บที่เลือกอยู่ ไม่มีสีใหม่ */
.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;   /* 2 ช่องเท่ากัน — ตัวชี้จึงเลื่อนด้วย % ได้ ไม่ต้องวัดด้วย JS */
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  padding: 11px 8px 13px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { color: var(--text-primary); background: var(--bg-page); text-decoration: none; }
.tab[aria-selected="true"] { color: var(--accent-primary); }

/* โฟกัสต้องเห็นชัดทุก state — คนที่ใช้คีย์บอร์ดล้วนต้องรู้ว่าตอนนี้อยู่ตรงไหน */
.tab:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: -3px;
  background: var(--blue-soft);
}

/* เส้นใต้ที่เลื่อนไปหาแท็บที่เลือก — จุดเดียวที่มี animation */
.tab-indicator {
  position: absolute;
  left: 0;
  bottom: -1px;                     /* ทับเส้น border-bottom ของ .tabs พอดี */
  width: 50%;
  height: 2px;
  background: var(--accent-blue);
  border-radius: 2px 2px 0 0;
  transition: transform 180ms ease;
  pointer-events: none;
}
/*
 * เส้นใต้เลื่อนเมื่อแท็บที่สองถูกเลือก — เขียนเป็นกฎเดียวที่ครอบทุกชุดแท็บ
 * แทนที่จะผูกกับชื่อโหมดของหน้าใดหน้าหนึ่ง (เดิมผูกกับ "username" ของหน้า
 * เข้าสู่ระบบอย่างเดียว พอหน้ารายงานมีแท็บบ้าง เส้นใต้เลยค้างอยู่ที่แท็บแรก)
 */
.tabs[data-active="username"] .tab-indicator,
.tabs[data-active="agents"] .tab-indicator { transform: translateX(100%); }

.tabpanel { animation: tabpanel-in 160ms ease-out; }
@keyframes tabpanel-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: none; }
}

/* เคารพการตั้งค่าของผู้ใช้ที่ขอให้ลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
  .tab-indicator { transition: none; }
  .tabpanel { animation: none; }
}

.section-note { color: var(--text-secondary); font-size: 14px; margin: -4px 0 14px; }

/* ── กล่องเกณฑ์ท้ายบทวิเคราะห์ ─────────────────────────────────────── */
.criteria {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 10px 14px;
  margin: 18px 0 8px;
  font-size: var(--fs-sm);
}
.criteria summary { cursor: pointer; color: var(--text-secondary); }
.criteria dl { margin: 12px 0 4px; display: grid; grid-template-columns: 1fr; gap: 2px 14px; }
.criteria dt { color: var(--text-primary); }
.criteria dd { margin: 0 0 8px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
@media (min-width: 560px) {
  .criteria dl { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .criteria dt { text-align: right; }
  .criteria dd { margin-bottom: 2px; }
}

/* ── หน้าจัดการผู้ใช้ /admin/users ───────────────────────────────────── */
.btn.danger { background: var(--bg-card); color: var(--status-warn-text); border-color: #F3C9C4; box-shadow: var(--shadow-card); }
.btn.danger:hover { background: var(--status-warn-bg); }

/* ปุ่มที่กดไม่ได้ (แถวของตัวเอง) — ยังอ่านออกว่าปุ่มนี้คือปุ่มอะไร แต่ต้องดูจืดพอ
   ที่จะไม่ชวนให้กด และเคอร์เซอร์บอกทันทีว่ากดไม่ได้ (มี title อธิบายเหตุผลกำกับ) */
.btn[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
  filter: none;
}
.btn[disabled]:hover { filter: none; background: var(--bg-card); }

/* ตารางผู้ใช้มีไม่กี่คอลัมน์และไม่มีตัวเลขยาว จึงไม่ต้องบังคับความกว้างขั้นต่ำ
   เหมือนตารางรายงาน — บนมือถือให้ยุบลงมาพอดีจอแทนที่จะต้องเลื่อนแนวนอน */
.user-table { min-width: 0; }
.user-table th, .user-table td { padding: 10px 8px; vertical-align: top; }
.user-table th:nth-child(2), .user-table td:nth-child(2),
.user-table th:nth-child(3), .user-table td:nth-child(3),
.user-table th:nth-child(4), .user-table td:nth-child(4) { text-align: left; }
.user-table td:last-child, .user-table th:last-child { text-align: right; }
.user-name { color: var(--text-primary); font-weight: 500; }
.user-table td:first-child .tag { margin-left: 6px; }

/*
 * ─── ตาราง KPI รายแอดมิน ───
 *
 * ตารางนี้กว้างกว่าตารางอื่นในระบบเพราะมี 11 คอลัมน์ (metric ระดับเว็บทั้งชุด
 * แตกเป็นรายคน) ที่ padding มาตรฐาน 11px 12px มันล้นขอบจอ 1280px ไป 8px
 * ทำให้ต้องเลื่อนแนวนอนทั้งที่เกือบพอดีอยู่แล้ว
 *
 * บีบเฉพาะตารางนี้ ไม่แตะตารางอื่นซึ่งมีคอลัมน์น้อยและอ่านสบายอยู่แล้ว —
 * การลดช่องไฟทั้งระบบเพราะตารางเดียวคือการทำให้ที่เหลือแย่ลงโดยไม่จำเป็น
 */
.agent-table th, .agent-table td { padding: 11px 8px; }
.agent-table th:first-child, .agent-table td:first-child { padding-left: 0; }
.agent-table th:last-child, .agent-table td:last-child { padding-right: 0; }

/*
 * ─── หน้าประเมินคุณภาพ /admin/quality ───
 *
 * ตารางผลรายมิติ: คอลัมน์แรกเป็นชื่อมิติ (ข้อความ) ที่เหลือเป็นจำนวนนับ
 * ชิดขวาทั้งหมดเพื่อให้หลักของตัวเลขตรงกันเวลากวาดตาเทียบข้ามแถว
 */
.eval-table { min-width: 0; }
.eval-table th, .eval-table td { padding: 10px 8px; vertical-align: top; text-align: right; }
.eval-table th:first-child, .eval-table td:first-child { text-align: left; padding-left: 0; }
.eval-table th:last-child, .eval-table td:last-child { padding-right: 0; }

/*
 * ─── เมนูที่จัดเป็นกลุ่ม ───
 *
 * หัวกลุ่มเป็นตัวเล็กสีจาง ทำหน้าที่แค่แบ่งสายตา ไม่ใช่ของที่ต้องอ่าน
 * ไม่ใช้ ALL CAPS ตามหลักเดียวกับหัวตาราง (ไม่มีผลกับไทย แต่ตะโกนใส่เศษอังกฤษ)
 */
.nav-group + .nav-group { margin-top: 14px; }
.nav-group-title {
  margin: 0 0 4px 12px;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-weight: 600;
}
/* มุมมองรายงานเยื้องเข้ามาเล็กน้อย บอกว่าเป็นของที่อยู่ใต้ "เลือกช่วงเวลา" */
.nav-item.nav-sub { padding-left: 26px; }

/*
 * ─── บทวิเคราะห์ ───
 *
 * เด่นขึ้นเพราะเป็นข้อสรุปที่คนอ่านจริง แต่ยังไม่แย่งความเด่นจากตัวเลข KPI
 * ที่อยู่เหนือมัน — ใช้ขนาดกับน้ำหนัก ไม่ใช้สีหรือกรอบเพิ่ม
 */
.narrative-lead .narrative p { font-size: var(--fs-lg); line-height: 1.65; }
.narrative-lead .narrative > *:first-child p { font-weight: 500; }

/*
 * ─── กราฟใยแมงมุมเทียบกันเองในทีม ───
 * เรียงเป็นตารางที่ไหลตามความกว้าง — เทียบข้ามคนได้ด้วยการกวาดตา
 */
.radar-head { margin: 26px 0 4px; }
.radar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.agent-radar {
  margin: 0;
  padding: 8px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  text-align: center;
}
.agent-radar svg { max-width: 100%; height: auto; }
.agent-radar figcaption { font-size: var(--fs-sm); padding-top: 2px; }

/* คำอธิบายวิธีอ่านตาราง — กางเมื่ออยากรู้ ไม่กินที่ตอนไม่ต้องการ */
.metric-guide { margin-top: 12px; }
.metric-guide > summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--accent-primary);
}
.metric-guide-body { padding-top: 8px; }
.metric-guide-body p { margin-bottom: 6px; }

/*
 * ─── แท็บของหน้ารายงาน ───
 *
 * ใช้คลาส .tabs ชุดเดียวกับหน้าเข้าสู่ระบบ เพิ่มแค่ระยะห่างให้เข้ากับหน้าที่
 * มีหัวข้อใหญ่อยู่ข้างบน — ไม่ทำสไตล์แท็บชุดที่สองขึ้นมาให้ต้องคอยดูแลให้ตรงกัน
 */
.report-tabs { margin: 18px 0 22px; }
.report-panel > h2:first-child { margin-top: 0; }

/*
 * ─── แถบความคืบหน้าของรอบประเมิน ───
 *
 * รางกับตัวเติมใช้มุมโค้งเล็ก (3px) ชุดเดียวกับ .hbar-track ในหน้ารายงาน
 * ไม่ใช่ 999px แบบแคปซูล — ของสองอย่างนี้คือ "แถบวัดปริมาณ" เหมือนกัน
 * ควรอ่านเป็นภาษาเดียวกัน
 */
.progress { margin-top: 12px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--fs-sm);
  margin-bottom: 6px;
}
.progress-track {
  height: 8px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent-primary);
  /* ขยับนุ่มๆ ตามค่าที่ถามมาได้ — เป็น motion ที่ตอบสนองข้อมูลจริง ไม่ใช่ของประดับ */
  transition: width 400ms ease-out;
}
.progress-detail { margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}

/* ปุ่มสั่งประเมินในแท็บรายแอดมิน — ปุ่มกับคำอธิบายอยู่บรรทัดเดียวกันบนจอกว้าง */
.quality-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

/*
 * ─── ผลประเมินรายบุคคลในหน้ารายงาน ───
 *
 * ใช้ <details> เพื่อให้กางดูได้โดยไม่ต้องมี JS (ไฟล์รายงานสแตนด์อโลนที่ส่งต่อ
 * กันในไลน์จึงกางได้เหมือนกัน) — สไตล์ตรงนี้ทำแค่ให้ summary ดูกดได้
 */
.agent-quality { padding: 0; }
.agent-quality > summary {
  cursor: pointer;
  padding: 13px 16px;
  list-style: none;
  border-radius: inherit;
}
.agent-quality > summary::-webkit-details-marker { display: none; }
.agent-quality > summary::before {
  content: "▸";
  display: inline-block;
  width: 15px;
  color: var(--text-secondary);
}
.agent-quality[open] > summary::before { content: "▾"; }
.agent-quality[open] > summary { border-bottom: 1px solid var(--border); }
.agent-quality > *:not(summary) { margin: 13px 16px; }

/* กราฟกับตารางคะแนนอยู่ข้างกันบนจอกว้าง และเรียงลงมาบนจอแคบ */
.radar-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.radar-wrap { flex: 0 0 auto; }
.radar-legend { flex: 1 1 260px; min-width: 240px; }
.radar-legend .right { text-align: right; }

.advice-head { font-size: var(--fs-sm); margin: 16px 0 8px; }
.advice-group + .advice-group { margin-top: 12px; }
.advice-list { list-style: none; margin: 0; padding: 0; }
.advice-list > li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.advice-list > li:last-child { border-bottom: none; }

/* หัวข้อระบุตัวแชทเหนือผลประเมิน — ชื่อคนตอบเด่นกว่ารายละเอียดที่เหลือ */
.chat-head { margin: 0 0 6px; }

/* รายการผลรายมิติของแชทตัวอย่าง — ไม่ใช้ bullet เพราะป้ายสีทำหน้าที่นำสายตาอยู่แล้ว */
.eval-list { list-style: none; margin: 0; padding: 0; }
.eval-list > li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.eval-list > li:last-child { border-bottom: none; }

/*
 * ข้อความที่ยกมาจากแชทจริง — ต้องแยกออกจาก "คำอธิบายของโมเดล" ด้วยสายตา
 * เพราะสองอย่างนี้เชื่อถือได้ไม่เท่ากัน: อันหนึ่งคือคำพูดที่เกิดขึ้นจริงในแชท
 * อีกอันคือการตีความ ขีดข้างซ้ายทำหน้าที่บอกว่า "บรรทัดนี้คือหลักฐาน"
 */
.quote {
  margin-top: 4px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  color: var(--text-secondary);
}

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.row-actions .btn { white-space: nowrap; }

/* มือถือ: ตารางแนวนอนใส่ 5 คอลัมน์ไม่ลงแน่นอน (ปุ่มจะโดนตัดหาย) จึงพลิกให้แต่ละแถว
   เป็นการ์ดเรียงลงมาแทน — หัวคอลัมน์ย้ายไปอยู่หน้าค่าแต่ละบรรทัดด้วย data-label
   ได้ทั้งอ่านครบและกดปุ่มถึงโดยไม่ต้องเลื่อนแนวนอน */
/*
 * มือถือ: 5 คอลัมน์ในความกว้าง 390px ทำให้ชื่อมิติถูกบีบจนตัดเป็นแนวตั้งทีละคำ
 * ("ตรง / คำถาม/ / แก้ / ปัญหาได้") อ่านไม่ออกในทางปฏิบัติ — ให้มันเลื่อนแนวนอน
 * ในกรอบ .table-scroll แทน ซึ่งเป็นวิธีที่ตารางรายงานหน้าอื่นใช้อยู่แล้ว
 */
@media (max-width: 559px) {
  .eval-table { min-width: 430px; }
}

@media (max-width: 559px) {
  .user-table, .user-table tbody, .user-table tr, .user-table td { display: block; width: 100%; }
  .user-table thead { display: none; }
  .user-table tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
  .user-table tr:last-child { border-bottom: none; }
  .user-table td { border-bottom: none; padding: 3px 0; text-align: left; white-space: normal; }
  .user-table td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--text-secondary);
    font-size: var(--fs-xs);
  }
  .user-table td:first-child { font-size: 16px; margin-bottom: 3px; }
  .user-table td.row-actions { display: flex; justify-content: flex-start; text-align: left; padding-top: 9px; }
}

.checkbox-field { margin-bottom: 10px; }
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 0;
}
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 auto; accent-color: var(--accent-primary); }

/* PIN ที่สุ่มให้ผู้ใช้ใหม่ — ตัวใหญ่ อ่านง่าย จดง่าย เพราะจะเห็นแค่ครั้งเดียว */
.pin-reveal-code {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  margin: 4px 0 12px;
  user-select: all;
}

/* ── ลิงก์เชิญสมัคร + หน้าสมัครสมาชิก ────────────────────────────────── */

/* ลิงก์ยาวมากและต้องคัดลอกทั้งก้อน — ให้ตัดบรรทัดได้ทุกตำแหน่งและเลือกทั้งหมดด้วยคลิกเดียว */
.invite-link {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13.5px;
  line-height: 1.6;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  margin: 4px 0 10px;
  overflow-wrap: anywhere;
  user-select: all;
  color: var(--text-primary);
}

/* ตัวนับถอยหลังต้องอ่านออกจากมุมตา — ตัวเลขความกว้างคงที่ไม่ให้กระตุกทุกวินาที */
.invite-countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 20px;
  color: var(--amber);
}
.invite-countdown.is-expired { color: var(--red); }

.register-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.register-card { width: 100%; max-width: 420px; }

footer.page-footer {
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  line-height: 1.7;
}

/* ── จอใหญ่ขึ้น ──────────────────────────────────────────────────────── */

/* ── จอใหญ่ขึ้น ──────────────────────────────────────────────────────── */
@media (min-width: 560px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  :root {
    --fs-base: 16.5px;
    --fs-2xl: 30px;
    --fs-xl: 22px;
    --fs-kpi: 34px;
    --read-width: 1080px;
  }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .wrap { padding: 0 24px 64px; }
  .topbar { padding: 16px 24px; }
}

/* ── จอเดสก์ท็อป: หน้าจอหลักที่หัวหน้าทีมใช้ตรวจแชทจริง ─────────────────
   ระยะสายตาไกลกว่ามือถือ ตัวอักษรจึงใหญ่ขึ้น และเนื้อหากว้างขึ้นเพราะ
   บทวิเคราะห์เป็นย่อหน้ายาว — แต่ยังคุมความยาวบรรทัดของย่อหน้าไว้ด้วย
   --measure ไม่ให้สายตาหลงบรรทัด */
@media (min-width: 1024px) {
  :root {
    --read-width: 1180px;
    --measure: 82ch;
    --fs-base: 16.5px;
    --fs-sm: 14px;
    --fs-xs: 12.5px;
    --fs-lg: 19px;
    --fs-xl: 23px;
    --fs-2xl: 32px;
    --fs-kpi: 38px;
  }
  .wrap { padding-bottom: 80px; }
  h2 { margin-top: 40px; }
  .kpi-grid { gap: 16px; margin-bottom: 26px; }
  .kpi { padding: 20px 22px 22px; }

  /* กราฟชุดกว้าง */
  .chart-narrow { display: none; }
  .chart-wide { display: block; }
  .chart-panel > .chart { max-width: 100%; }

  /* ตารางกว้างพอแล้ว ไม่ต้องเลื่อนแนวนอน */
  table { font-size: 15px; }
  th, td { padding: 12px 14px; }

  /* transcript อ่านสบายขึ้นบนจอกว้าง */
  .msg-text { font-size: 15.5px; }
  .msg-time { min-width: 52px; font-size: 13px; }
}

@media print {
  body { background: #fff; }
  body.app { display: block; }
  .sidebar, .topbar, .nav-scrim, .skip-link, .btn, .no-print { display: none !important; }
  .card, .kpi, .sample { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
}

/*
 * ค่าที่จะบันทึกในหน้าตรวจข้อมูลอ้างอิง — ต้องอ่านได้ว่าจะเก็บอะไรลงไปจริง
 *
 * จำกัดความสูงไว้เพราะบางรายการยาวมาก (ข้อความสำเร็จรูปของ CS มีทั้งเงื่อนไข
 * และอีโมจิเต็มไปหมด) แต่ยังเลื่อนดูได้ทั้งหมด — คนที่กดยืนยันต้องเห็นของครบ
 */
.entry-body {
  max-height: 220px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ฟอร์มแก้ไขรายการในตาราง — ช่องกว้างพอให้เห็นค่าที่กำลังแก้ */
.entry-edit input[type="text"],
.entry-edit textarea {
  width: 100%;
  min-width: 240px;
  margin-bottom: 6px;
}

.entry-edit textarea {
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: 1.6;
  resize: vertical;
}

/*
 * รายการ credential ที่ต้องตัดสินก่อนบันทึก
 *
 * ช่องติ๊กกับคำอธิบายต้องอยู่บรรทัดเดียวกันแต่ข้อความห่อได้ — ค่าที่ปิดบังแล้ว
 * ยาวไม่เท่ากันและเหตุผลเป็นภาษาไทยที่กินสองบรรทัดบนจอแคบ
 */
.cred-list { list-style: none; margin: 6px 0 12px; padding: 0; }

.cred-list li { margin-bottom: 6px; }

.cred-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

.cred-row input[type="checkbox"] { margin-top: 4px; flex: none; }
.cred-row code { word-break: break-all; }
/*
 * หน้าตรวจลิงก์ — จัดกลุ่มตามเกณฑ์ ไม่ใช่ไล่เรียงทีละแถว
 *
 * ในฐานจริงรายการที่ตกเกณฑ์เป็นโดเมนเดียวกันซ้ำ 400 กว่าครั้ง หน้านี้จึงต้อง
 * อ่านเป็น "โดเมนอะไรบ้างที่ต้องตัดสิน" ไม่ใช่ "เกิดอะไรขึ้นเมื่อไหร่บ้าง"
 */
.verdict-block { margin-top: 1.75rem; }

.verdict-block > h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.link-findings {
  margin: 8px 0 0;
  padding-left: 1.1rem;
  font-size: var(--fs-sm);
  line-height: 1.7;
}

.link-findings code {
  word-break: break-all;
}

/* แถวตัวกรองด้านบน — เรียงในบรรทัดเดียวบนจอกว้าง ตกลงมาเป็นแถวบนจอแคบ */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.filter-row .field { margin: 0; }

/*
 * รายการลิงก์รอตรวจสอบ — ต้องอ่านแล้วตัดสินได้ในที่เดียว
 *
 * บริบทการคุยเป็นส่วนที่กินพื้นที่มากที่สุดแต่ก็สำคัญที่สุด บรรทัดที่มีลิงก์
 * จึงถูกเน้นไว้ ไม่งั้นตาจะหาไม่เจอว่าลิงก์อยู่ตรงไหนในบทสนทนา
 */
.link-domain-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.link-domain-head code { word-break: break-all; }

.link-urls { list-style: none; margin: 12px 0 0; padding: 0; }

.link-url {
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
}

.link-url.is-new { box-shadow: inset 3px 0 0 var(--amber); }

.link-url-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.link-url-head code { word-break: break-all; }

.link-context {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  font-size: var(--fs-sm);
  line-height: 1.65;
}

.link-context .is-link {
  font-weight: 600;
  /* ลิงก์อาจยาวมากและไม่มีช่องว่างให้ตัดบรรทัด ปล่อยไว้จะดันหน้าจนเลื่อนแนวนอน */
  word-break: break-word;
}

.link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.link-actions form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0;
}

.link-actions input[type="text"] { min-width: 200px; }

.link-watch {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 460px;
}

/* แชทเต็ม — ข้อความที่ถูกอ้างถึงต้องหาเจอทันทีหลังกดลิงก์มา */
.chat-full { list-style: none; margin: 0; padding: 0; }

.chat-line {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--bg-page);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-line.is-agent { background: var(--bg-card); box-shadow: inset 3px 0 0 var(--border); }
.chat-line.is-highlight { box-shadow: inset 3px 0 0 var(--amber); }

/*
 * คำบรรยายที่ส่งมากับไฟล์แนบ
 *
 * ต้องแยกออกจากตัวข้อความให้เห็นชัด เพราะ body ของข้อความชนิดไฟล์เป็นป้ายที่
 * ระบบเขียนเอง ส่วนบรรทัดนี้คือคำที่คนพิมพ์จริง — คนละที่มา คนละความน่าเชื่อถือ
 */
.link-caption {
  margin-top: 4px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
}
