/* =======================================================================
   เงินกรู Affiliate — สไตล์กลางของ Dashboard / หน้าเจ้าของระบบ / หน้าล็อกอิน (TASK-121 · UI ข้อ 3 ของเจ้าของ 12 ต.ค. 2569)
   token ชุดเดียวกับหน้าแรก (public/landing.css · ไฟล์แบรนด์เงินกรู): หมึก #111418 · เขียวมะนาว #C8FF3D · เขียว #3F6B00
     · พื้น #F5F7F2 · เทา #525A54 — ธีมสว่าง + ธีมมืดตาม prefers-color-scheme (สีปุ่มหลัก: สว่าง = เขียวตัวขาว · มืด = มะนาวตัวหมึก)
   ฟอนต์ = ฟอนต์ไทยในเครื่อง (ไม่โหลดจากโดเมนอื่น · privacy 6.2) · ใช้บนมือถือได้ตั้งแต่ 375px (ไม่เลื่อนข้าง)
   ตัวอักษรทุกคู่สีผ่าน WCAG AA (≥ 4.5:1) · ขอบช่องกรอก ≥ 3:1 · public/setup.css ใช้ token ชุดนี้ (มืดตามเอง)
   ไม่มี inline style ในหน้า — ความกว้างแท่งกราฟตั้งผ่าน JS (element.style / --w)
   ======================================================================= */

/* หน้าแบรนด์รอยืนยันตัวตนก่อนเผยเมนูหรือช่องตั้งค่าของเจ้าของ */
.app-auth-pending #main { visibility: hidden; }
.app-auth-pending noscript { visibility: visible; }

:root {
  color-scheme: light;

  /* สี */
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-muted: #f3f6ef;
  --surface-hover: #ebf0e4;
  --border: #d6ddcf;
  --border-strong: #7c857e; /* ขอบช่องกรอก ≥ 3:1 กับพื้นขาว (WCAG 1.4.11) */
  --border-hover: #4f5751;
  --text: #111418;
  --text-muted: #525a54;
  --placeholder: #656d67;
  --primary: #3f6b00; /* เขียวเงินกรู (ตัวขาวบนปุ่ม 6.3:1) · มืด = มะนาว */
  --primary-hover: #335700;
  --primary-soft: #eef8dc;
  --primary-border: #b9d98a;
  --on-primary: #ffffff;
  --accent: #c8ff3d; /* เขียวมะนาว — แถบเมนูที่เลือก · ตกแต่ง (ไม่ใช้เป็นสีตัวอักษรบนพื้นสว่าง) */
  --on-accent: #111418;
  --danger: #b42318;
  --danger-hover: #912018;
  --danger-soft: #fdecea;
  --danger-text: #8f1d1d;
  --danger-border: #f3b4b4;
  --on-danger: #ffffff;
  --success: #3f6b00;
  --success-hover: #335700;
  --success-soft: #eef8dc;
  --success-text: #2d4d00;
  --success-border: #b9d98a;
  --on-success: #ffffff;
  --warning-text: #7a4a00;
  --warning-soft: #fff4d6;
  --warning-border: #f0d083;
  --info-text: #173f8a;
  --info-soft: #e8f0fd;
  --info-border: #b7cdf5;
  --focus: #3f6b00;
  --link: #3f6b00;
  --link-hover: #2d4d00;
  --selection: #dff5b0;
  --row-hover: #f7f9f4;
  --backdrop: rgba(17, 20, 24, 0.5);
  --sticky-shadow: rgba(17, 20, 24, 0.16);
  /* กล่องตัวอย่างข้อความบอท (หน้าตาแชท LINE) */
  --chat-bubble-bg: #e7f6ec;
  --chat-bubble-border: #bfe3cb;

  /* ป้ายสถานะ */
  --badge-pending-bg: #fff4d6;
  --badge-pending-text: #7a4a00;
  --badge-pending-border: #f0d083;
  --badge-fired-bg: #eef8dc;
  --badge-fired-text: #2d4d00;
  --badge-fired-border: #b9d98a;
  --badge-muted-bg: #eef1ea;
  --badge-muted-text: #4b524c;
  --badge-muted-border: #d6ddcf;
  /* Phase 3: ฟ้า = ตั้งแอดแล้ว · แดง = ไม่ผ่าน / ไม่ตั้ง (ตัวอักษร ≥ 7:1 กับพื้นป้าย) */
  --badge-info-bg: #e8f0fd;
  --badge-info-text: #173f8a;
  --badge-info-border: #b7cdf5;
  --badge-danger-bg: #fdecec;
  --badge-danger-text: #8f1d1d;
  --badge-danger-border: #f3b4b4;

  /* แท่งกราฟ */
  --bar-track: #e9eee3;
  --bar-fill: #75b900;
  --bar-fired: #2d4d00;

  /* toast */
  --toast-info-bg: #111418;
  --toast-success-bg: #2d4d00;
  --toast-error-bg: #b42318;
  --toast-text: #ffffff;

  /* ตัวอักษร / ขนาด (ชุดเดียวกับหน้าแรก) */
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", "Thonburi", "Sarabun", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(17, 20, 24, 0.05);
  --shadow: 0 1px 2px rgba(17, 20, 24, 0.06), 0 8px 24px rgba(17, 20, 24, 0.06);
  --shadow-lg: 0 12px 32px rgba(17, 20, 24, 0.2);
  --container: 1100px;
  --gutter: 16px;
  --control-h: 40px;
}

/* ธีมมืด (ตามเครื่อง) — สีชุดเดียวกับหน้าแรกตอนมืด · เฉพาะ Dashboard / เจ้าของระบบ / ล็อกอิน / ตัวช่วยตั้งค่า
   ไม่ใช้กับฟอร์มในไลน์ (body.form-body) · หน้าชวนสมัคร (body.join-body) · ใบกำกับภาษี (body.inv-body = กระดาษขาว)
   — หน้าเหล่านั้นมีสีตายตัวของตัวเองสำหรับพื้นสว่าง · เบราว์เซอร์ที่ไม่รู้จัก :has() = ธีมสว่างทุกหน้า */
@media (prefers-color-scheme: dark) {
  :root:not(:has(body.form-body, body.join-body, body.inv-body)) {
    color-scheme: dark;
    --bg: #0c0f12;
    --surface: #161a1f;
    --surface-muted: #11151a;
    --surface-hover: #1f252b;
    --border: #2a3037;
    --border-strong: #6b746d;
    --border-hover: #9aa39c;
    --text: #f5f7f2;
    --text-muted: #a9b2ab;
    --placeholder: #8f9891;
    --primary: #c8ff3d;
    --primary-hover: #b4ec22;
    --primary-soft: #1f2a0f;
    --primary-border: #4d6b16;
    --on-primary: #111418;
    --danger: #ff8a80;
    --danger-hover: #ff6f63;
    --danger-soft: #2a1514;
    --danger-text: #ffb4ab;
    --danger-border: #6e2a26;
    --on-danger: #111418;
    --success: #a6e05a;
    --success-hover: #94d042;
    --success-soft: #1b2410;
    --success-text: #c8ff3d;
    --success-border: #4d6b16;
    --on-success: #111418;
    --warning-text: #ffd27a;
    --warning-soft: #2a2110;
    --warning-border: #6b5320;
    --info-text: #a8c7fa;
    --info-soft: #14213a;
    --info-border: #2d4a7c;
    --focus: #c8ff3d;
    --link: #c8ff3d;
    --link-hover: #e3ff9a;
    --selection: #3a4a14;
    --row-hover: #1a1f25;
    --backdrop: rgba(0, 0, 0, 0.65);
    --sticky-shadow: rgba(0, 0, 0, 0.55);
    --chat-bubble-bg: #173a24;
    --chat-bubble-border: #2b5c3c;
    --badge-pending-bg: #2a2110;
    --badge-pending-text: #ffd27a;
    --badge-pending-border: #6b5320;
    --badge-fired-bg: #1b2410;
    --badge-fired-text: #c8ff3d;
    --badge-fired-border: #4d6b16;
    --badge-muted-bg: #1f252b;
    --badge-muted-text: #c3cbc5;
    --badge-muted-border: #3a414a;
    --badge-info-bg: #14213a;
    --badge-info-text: #a8c7fa;
    --badge-info-border: #2d4a7c;
    --badge-danger-bg: #2a1514;
    --badge-danger-text: #ffb4ab;
    --badge-danger-border: #6e2a26;
    --bar-track: #242a31;
    --bar-fill: #4d6b16;
    --bar-fired: #c8ff3d;
    --toast-info-bg: #2b3136;
    --toast-success-bg: #2d4d00;
    --toast-error-bg: #8f1d1d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- พื้นฐาน ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  line-height: 1.35;
  font-weight: 700;
}
h1 { font-size: 1.375rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.75em; }

a {
  color: var(--link);
  text-underline-offset: 2px;
}
a:hover { color: var(--link-hover); }

img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* attribute hidden ต้องชนะ display ของ class (.btn, .flex ฯลฯ) */
[hidden] { display: none !important; }

/* โฟกัสเห็นชัดทุกปุ่ม/ลิงก์/ช่องกรอก */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--selection); }

/* ---------- โครงหน้า ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.page {
  padding-block: 20px 48px;
}

/* หน้าที่ตารางกว้าง (รายการ code มีคอลัมน์สินค้า + 3 ปุ่ม) → ขยายกรอบทั้งหน้า รวมแถบบน (ตัวแปรสืบทอดจาก <body>) */
.layout-wide { --container: 1440px; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.page-header > * { min-width: 0; }

.page-title {
  margin: 0;
  font-size: 1.375rem;
}

.section { margin-top: 24px; }
.section-title {
  font-size: 1.0625rem;
  margin: 0 0 12px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 1100;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.skip-link:focus { top: 8px; }

/* ---------- แถบบน (renderHeader) ---------- */
/* โลโก้เงินกรู + wordmark · ชื่อแบรนด์ · เมนู 5 เมนู (รายการ code · ไลฟ์ · ยอดขาย · สรุป · ตั้งค่า) (+ "ตั้งค่าเริ่มต้น" ระหว่างยังไม่ครบ) · ออกจากระบบ
   (ไม่มีแท็บย่อยแล้ว — รางวัล / Tier เลิก 12 ต.ค. 2569) · ?removed= → แถบ "เมนู … ถูกเอาออกแล้ว — …" (.removed-notice) */
.app-header,
#app-header {
  display: block;
  min-height: 57px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding-block: 8px;
}

.app-header-id {
  display: flex;
  flex-direction: column;
  /* basis 0 = ชื่อแบรนด์ยาวแค่ไหนก็ย่อ (…) ไม่ดันปุ่มออกจากระบบลงบรรทัดใหม่ */
  flex: 1 1 0;
  min-width: 0;
  line-height: 1.35;
}

.app-product {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  white-space: nowrap;
}
.app-product:hover { color: var(--text); }
.app-logo { flex: none; width: 28px; height: 28px; background: url("/brand/ngerngru-mark.svg") center / contain no-repeat; }
.app-wordmark-gru { color: var(--primary); }
.app-wordmark-sub { color: var(--text-muted); font-weight: 700; }

.app-brand {
  /* ชื่อแบรนด์ใต้ wordmark (ตรงกับตัวอักษร ไม่ตรงกับโลโก้) */
  padding-left: 36px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-brand:empty { display: none; }

/* จอแคบกว่า 1024px: เมนูลงบรรทัดที่สองเต็มความกว้าง · ลิงก์ตัดขึ้นบรรทัดใหม่เอง (มือถือ 375px = 2 บรรทัด ไม่ต้องเลื่อนข้าง)
   overflow-x: auto คงไว้เป็นกันชน (ลิงก์ยาวผิดปกติจะเลื่อนในเมนู ไม่ดันทั้งหน้าให้เลื่อนข้าง) */
.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  order: 3;
  flex-basis: 100%;
  min-width: 0;
  overflow-x: auto;
}

.app-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  white-space: nowrap;
}
.app-nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}
/* หน้าปัจจุบัน / อยู่ในกลุ่ม: พื้นเขียวอ่อน + เส้นมะนาวใต้ลิงก์ (ไม่ใช้สีอย่างเดียว: ตัวหนา + เส้น) */
.app-nav-link[aria-current="page"],
.app-nav-link[aria-current="true"] {
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 800;
  box-shadow: inset 0 -3px 0 var(--primary);
}
/* .app-nav เป็นกล่องเลื่อน (overflow-x) สูงเท่าลิงก์พอดี → วาดวงโฟกัสไว้ด้านในลิงก์ ไม่ให้ถูกตัดบน/ล่าง */
.app-nav-link:focus-visible { outline-offset: -3px; }

/* "ตั้งค่าเริ่มต้น" (ตัวช่วยตั้งค่ายังไม่ครบ) — ปุ่มมะนาวเด่นกว่าเมนูอื่น */
.app-nav-setup {
  background: var(--accent);
  color: var(--on-accent);
}
.app-nav-setup:hover {
  background: var(--accent);
  color: var(--on-accent);
  filter: brightness(0.95);
}
.app-nav-count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--on-accent);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

.app-logout { flex: 0 0 auto; }

/* แถบ "เมนู … ถูกเอาออกแล้ว — …" (มาจาก /rewards · /tiers เดิม · app.js removedNotice) */
.removed-notice { margin: 8px 0; overflow-wrap: anywhere; }

@media (min-width: 640px) {
  .app-nav-link { padding: 6px 12px; font-size: 0.9375rem; }
}

/* จอกว้าง: ชื่อระบบ · เมนู · ออกจากระบบ อยู่บรรทัดเดียว (เมนู 5 เมนู + ตั้งค่าเริ่มต้น แคบกว่า 700px) */
@media (min-width: 1024px) {
  .app-header-inner {
    flex-wrap: nowrap;
    padding-block: 8px;
  }
  .app-nav {
    order: 0;
    flex-basis: auto;
    flex-wrap: nowrap;
  }
  .app-nav-link { padding: 6px 10px; }
}
@media (min-width: 1200px) {
  .app-nav-link { padding: 6px 12px; }
}

/* ---------- การ์ด ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  min-width: 0;
}
.card + .card { margin-top: 16px; }

.card-title {
  margin: 0 0 12px;
  font-size: 1.0625rem;
  font-weight: 700;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
}
.card-header .card-title { margin: 0; }

@media (min-width: 640px) {
  .card { padding: 20px; }
}

/* ตัวเลขสรุป */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}
.stat-label {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

/* หน้าล็อกอิน / ฟอร์มกลางจอ */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px var(--gutter);
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
}
/* โลโก้เงินกรู + wordmark แบบหน้าแรก / หน้าเอกสาร ("เงิน" หมึก · "กรู" เขียวแบรนด์ · "Affiliate" สีรอง) */
.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-weight: 800;
  font-size: 1.0625rem;
  line-height: 1.2;
  color: var(--text);
}
.auth-brand img { flex: none; width: 32px; height: 32px; }
.auth-brand-gru { color: var(--primary); }
.auth-brand-sub { color: var(--text-muted); font-weight: 700; }

/* ---------- ฟอร์ม ---------- */
label,
.label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field + .field { margin-top: 12px; }

.form-stack {
  display: grid;
  gap: 12px;
}
.form-stack .field + .field { margin-top: 0; }

/* แถวตัวกรอง: มือถือ 2 คอลัมน์ → จอกว้างเรียงเต็มแถว */
.filters,
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}
.filters .field + .field,
.form-row .field + .field { margin-top: 0; }
.field-wide { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .field-wide { grid-column: span 2; }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
select,
textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: var(--control-h);
  padding: 7px 12px;
  /* 16px กันมือถือ iOS ซูมเข้าตอนแตะช่องกรอก */
  font-size: 16px;
  line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:hover,
select:hover,
textarea:hover { border-color: var(--border-hover); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}

input::placeholder,
textarea::placeholder { color: var(--placeholder); opacity: 1; }

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

/* ตัวเลือกเล็กในแถวตาราง (เช่น สินค้าของคลิป) · ตัวอักษรยัง 16px กัน iOS ซูม */
select.select-compact {
  display: inline-block;
  width: auto;
  min-width: 7.5rem;
  max-width: 12rem;
  min-height: 32px;
  padding: 3px 8px;
}
select.select-compact[aria-busy="true"] { cursor: progress; }

/* ช่องวันที่บน iOS Safari: ให้เต็มความกว้างและชิดซ้าย */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.5em;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
  vertical-align: middle;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}

.help {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 0;
}

.field-error,
.error-text {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0;
}
.field-error:empty { display: none; }

/* ตัวเลือกแบบปุ่มติดกัน (เช่น รอยิง / ยิงแล้ว / ทั้งหมด) ใช้ radio + label */
.segmented {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.segmented label {
  display: inline-flex;
  align-items: center;
  min-height: calc(var(--control-h) - 2px);
  padding: 6px 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.segmented label + input + label,
.segmented label + label { border-left: 1px solid var(--border-strong); }
.segmented input:checked + label {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.segmented input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  padding: 7px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--on-primary);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: var(--on-danger);
}

/* ปุ่มแดงแบบขอบ (เช่น "ไม่ผ่าน" ในแถวตาราง — เบากว่า .btn-danger ข้างปุ่มหลัก) */
.btn-danger-outline {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: var(--danger-soft);
  border-color: var(--danger-hover);
  color: var(--danger-hover);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: var(--on-success);
}
.btn-success:hover {
  background: var(--success-hover);
  border-color: var(--success-hover);
  color: var(--on-success);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
}
.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.875rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.btn[aria-busy="true"] { cursor: progress; }

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- ป้ายสถานะ ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-pending {
  background: var(--badge-pending-bg);
  color: var(--badge-pending-text);
  border-color: var(--badge-pending-border);
}
.badge-fired {
  background: var(--badge-fired-bg);
  color: var(--badge-fired-text);
  border-color: var(--badge-fired-border);
}
.badge-muted {
  background: var(--badge-muted-bg);
  color: var(--badge-muted-text);
  border-color: var(--badge-muted-border);
}
/* Phase 3: ป้ายสถานะกลางของ statusBadge(status, kind) ใน app.js — class = badge-<สถานะ> ใช้ได้ทุกหน้า
   เหลือง = รอ (pending · requested) · ฟ้า = ตั้งแอดแล้ว (scheduled)
   เขียว = สำเร็จ (fired) · แดง = ไม่ผ่าน / ไม่ตั้ง (rejected · declined) · เทา = ยกเลิก (cancelled)
   badge-info / badge-success / badge-danger = สีเดียวกันสำหรับป้ายอื่นที่ไม่ใช่สถานะ */
.badge-requested {
  background: var(--badge-pending-bg);
  color: var(--badge-pending-text);
  border-color: var(--badge-pending-border);
}
.badge-scheduled,
.badge-info {
  background: var(--badge-info-bg);
  color: var(--badge-info-text);
  border-color: var(--badge-info-border);
}
.badge-success {
  background: var(--badge-fired-bg);
  color: var(--badge-fired-text);
  border-color: var(--badge-fired-border);
}
.badge-rejected,
.badge-declined,
.badge-danger {
  background: var(--badge-danger-bg);
  color: var(--badge-danger-text);
  border-color: var(--badge-danger-border);
}
.badge-cancelled {
  background: var(--badge-muted-bg);
  color: var(--badge-muted-text);
  border-color: var(--badge-muted-border);
}

/* ---------- กล่องข้อความ ---------- */
.alert {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  font-size: 0.9375rem;
}
.alert-error {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger-text);
}
.alert-success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success-text);
}
.alert-info {
  background: var(--info-soft);
  border-color: var(--info-border);
  color: var(--info-text);
}
.alert-warning {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning-text);
}
.alert:empty { display: none; }

/* กล่อง <dialog> (เช่น ส่งข้อความแจ้งผล /js/feedback.js) · ฉากหลังมืดลง */
dialog::backdrop { background: var(--backdrop); }

/* กล่องยืนยัน + หมายเหตุ (openNoteDialog ใน app.js) · มือถือเหลือขอบ 16px ต่อข้าง (ไม่ล้นจอ 375px) */
.app-dialog {
  width: 30rem;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  margin: auto;
  overflow-y: auto;
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.app-dialog textarea { min-height: 80px; }

/* รายการขั้นตอน (คำแนะนำในหน้าเจ้าของระบบ) */
.steps {
  margin: 0;
  padding-left: 1.25rem;
}
.steps > li + li { margin-top: 4px; }

/* ---------- ตาราง (กว้างเกิน → เลื่อนในกล่องตัวเอง หน้าไม่เลื่อนข้าง) ---------- */
/* position: relative = กรอบอ้างอิงของลูกที่ position:absolute (เช่น .sr-only ในเซลล์) ไม่ให้หลุดออกไปขยายความกว้างหน้า */
.table-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.table-wrap:focus-visible { outline-offset: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.table thead th {
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.table tbody tr:last-child td,
.table tbody tr:last-child th { border-bottom: 0; }
.table tbody tr:hover { background: var(--row-hover); }
.table caption {
  caption-side: top;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
}
.table .num,
.table th.num { text-align: right; }
.table-wide { min-width: 760px; }
/* หน้ารายการ code: คอลัมน์ปุ่มติดขอบขวาเสมอ (ปุ่มยิงแล้วต้องเห็นโดยไม่ต้องเลื่อนตาราง) */
.table-sticky-actions th:last-child,
.table-sticky-actions td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: -8px 0 8px -8px var(--sticky-shadow);
}
.table-sticky-actions thead th:last-child { background: var(--surface-muted); }
.table-sticky-actions tbody tr:hover td:last-child { background: var(--row-hover); }
/* ปุ่มในแถวหน้ารายการ code (คัดลอก · ยิงแล้ว · ไม่ผ่าน · ส่งข้อความ) ในคอลัมน์ติดขวา
   จอแคบกว่า 1024px: 2 ปุ่มต่อบรรทัด → คอลัมน์ติดขวาไม่กว้างจนบังทั้งตาราง · จอกว้าง: บรรทัดเดียว */
.code-actions {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 6px;
}
@media (min-width: 1024px) {
  .code-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
  }
}
.table-compact th,
.table-compact td { padding: 6px 10px; }

.table-empty,
.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}

/* code คลิป / ลิงก์ยาว */
.code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}
.code { overflow-wrap: anywhere; word-break: break-all; }

.code-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.code-cell .code {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

/* แบ่งหน้า */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-top: 12px;
}
.pager-info {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* แถวข้อความ + ปุ่มคัดลอก (เช่น ลิงก์รับข้อความ) */
.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.copy-row > .code,
.copy-row > .mono {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* textarea ซ่อนของ copyText() */
.copy-buffer {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- กราฟแท่งแนวนอน ---------- */
.bar-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(64px, 7.5rem) minmax(0, 1fr) minmax(4.5rem, auto);
  align-items: center;
  gap: 8px 12px;
  font-size: 0.875rem;
}
/* ใน .bar-list ทุกแถวใช้คอลัมน์ร่วมกัน → แท่งเริ่ม/จบตรงกัน เทียบความยาวได้ */
@supports (grid-template-columns: subgrid) {
  .bar-list {
    grid-template-columns: minmax(64px, 7.5rem) minmax(0, 1fr) auto;
    column-gap: 12px;
  }
  .bar-list > .bar-row {
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
  }
}
.bar-label {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.bar-track {
  position: relative;
  height: 12px;
  min-width: 0;
  background: var(--bar-track);
  border-radius: 999px;
  overflow: hidden;
}
/* ใช้เดี่ยวหรือใส่ใน .bar-track · ความกว้าง: el.style.width = '40%' หรือ --w */
.bar {
  display: block;
  height: 12px;
  width: var(--w, 0%);
  max-width: 100%;
  background: var(--bar-fill);
  border-radius: 999px;
}
.bar-track > .bar + .bar {
  position: absolute;
  top: 0;
  left: 0;
}
.bar-fired { background: var(--bar-fired); }
.bar-muted { background: var(--border-strong); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--bar-fill);
}
.legend-swatch.bar-fired { background: var(--bar-fired); }

/* ---------- toast ---------- */
.toast-region {
  position: fixed;
  z-index: 1000;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
/* ห้ามซ่อน (display:none) ตอนว่าง: live region ต้องอยู่ใน accessibility tree ก่อนมีข้อความ ไม่งั้น screen reader อาจไม่อ่าน */

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--toast-info-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-lg);
  font-size: 0.9375rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  cursor: pointer;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
/* ไอคอนนำหน้า (สีไม่ใช่ตัวบอกประเภทอย่างเดียว) · alt ว่าง = screen reader ไม่อ่าน */
.toast::before {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  content: "i";
  content: "i" / "";
}
.toast-success { background: var(--toast-success-bg); }
.toast-success::before {
  content: "✓";
  content: "✓" / "";
}
.toast-error { background: var(--toast-error-bg); }
.toast-error::before {
  content: "!";
  content: "!" / "";
}
.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 640px) {
  .toast-region {
    left: auto;
    right: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    width: 380px;
    align-items: flex-end;
  }
}

/* ---------- ยูทิลิตี ---------- */
.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.xsmall { font-size: 0.8125rem; }
.bold { font-weight: 700; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-word; }
.truncate {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.num { font-variant-numeric: tabular-nums; }
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1 1 0%; min-width: 0; }
.spacer { flex: 1 1 auto; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.stack > * + * { margin-top: 12px; }

.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- หน้าตั้งค่า (/settings) — สินค้า / ข้อความบอท / หน้าชวนสมัคร ---------- */
/* ลิงก์ข้ามหัวข้อ = ปุ่มเม็ดยา (TASK-121) · ตัดบรรทัดเอง (375px ไม่เลื่อนข้าง) */
.st-jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; font-size: 0.875rem; }
.st-jump a { display: inline-flex; align-items: center; min-height: 36px; padding: 4px 12px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; }
.st-jump a:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
/* ตัวเลือกที่ใช้ไม่บ่อย (progressive disclosure) — <details class="st-more"> */
.st-more { min-width: 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-muted); }
.st-more > summary { min-height: 32px; cursor: pointer; font-weight: 700; color: var(--text); }
.st-more > summary:focus-visible { outline-offset: 2px; }
.st-more[open] > summary { margin-bottom: 4px; }
/* การ์ด "การเชื่อมต่อ LINE" (/js/settings-line.js) */
.st-checks { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.st-check { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.st-check-icon { display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border-strong); color: var(--text-muted); font-weight: 800; font-size: 0.875rem; }
.st-check.is-done .st-check-icon { border-color: var(--success); background: var(--success); color: var(--on-success); }
.st-check.is-skipped .st-check-icon { border-style: dashed; }
.st-check-text { flex: 1 1 14rem; display: grid; gap: 2px; min-width: 0; }
.st-check-label { font-weight: 600; overflow-wrap: anywhere; }
.st-check-note { color: var(--text-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
.st-check-go { flex: 0 0 auto; }
/* การ์ด "ข้อตกลง" */
.st-doc-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 12px 0; padding: 0; list-style: none; }
.st-doc-links a { display: inline-block; padding-block: 4px; font-weight: 600; }
/* กลุ่มข้อความบอท (<details> · หัวข้อกลุ่มใน summary) */
.st-tpl-summary { display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; list-style: none; }
.st-tpl-summary::-webkit-details-marker { display: none; }
/* ลูกศรพับ / กาง (summary แบบ flex ไม่มี marker ของเบราว์เซอร์) */
.st-tpl-summary::before { content: "▸"; flex: none; width: 1em; color: var(--text-muted); }
.st-tpl-group[open] > .st-tpl-summary::before { content: "▾"; }
.st-tpl-summary > h3 { display: inline; margin: 0; font-size: 1.0625rem; }
.st-session { position: sticky; top: 8px; z-index: 20; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
.st-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.st-product { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.st-product.is-inactive { background: var(--surface-muted); }
.st-product-main { flex: 1 1 14rem; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.st-product-order { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.st-product-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.st-product.is-inactive .st-product-name { color: var(--text-muted); }
.st-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.st-arrow { min-width: 36px; }
.st-edit { flex: 1 1 100%; display: grid; gap: 4px; min-width: 0; }
.st-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.st-inline > input { flex: 1 1 12rem; width: auto; }
.st-tpl-group { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.st-tpl-group:first-child { margin-top: 8px; }
.st-tpl-group > h3 { margin: 0 0 4px; font-size: 1.0625rem; }
.st-tpl { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); min-width: 0; }
.st-tpl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.st-tpl-head h4 { margin: 0; font-size: 1rem; }
.st-tpl-grid { display: grid; gap: 12px; margin-top: 8px; }
@media (min-width: 860px) { .st-tpl-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; } }
.st-tpl-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 0.8125rem; color: var(--text-muted); }
.st-counter { font-variant-numeric: tabular-nums; }
.st-counter.is-over { color: var(--danger); font-weight: 700; }
.st-dirty { color: var(--warning-text); font-weight: 600; }
.st-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.st-chip { gap: 6px; font-weight: 500; white-space: normal; text-align: left; }
.st-chip-token { font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 700; }
.st-chip.is-required { border-color: var(--primary); }
.st-chip.is-required .st-chip-token { color: var(--primary); }
.st-preview { margin: 0; padding: 10px 14px; min-height: 2.75em; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--chat-bubble-bg); border: 1px solid var(--chat-bubble-border); border-radius: 16px 16px 16px 4px; font-size: 0.9375rem; line-height: 1.55; }
.st-preview.is-empty { color: var(--text-muted); background: var(--surface-muted); border-color: var(--border); }
.st-errors:empty { display: none; }
.st-errors .field-error + .field-error { margin-top: 2px; }
.st-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.st-fieldset > legend { padding: 0; margin-bottom: 8px; font-weight: 600; font-size: 0.875rem; }

/* ---------- โหมดบอท (hotfix โหมดเงียบ) — หน้าตั้งค่า /js/bot-mode.js · แถบหน้ารายการ code /js/bot-mode-banner.js ---------- */
.bm-root { margin-bottom: 24px; }
.bm-root:empty { display: none; }
.bm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 8px; }
.bm-head .card-title { margin: 0; }
.bm-options { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
@media (min-width: 640px) { .bm-options { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* ทั้งกล่องเป็น label ของ radio → แตะตรงไหนก็เลือกได้ · กล่องที่เลือกขอบน้ำเงิน (ไม่ใช้สีอย่างเดียว: radio ยังติ๊กอยู่) */
.bm-option { display: flex; align-items: flex-start; gap: 10px; min-width: 0; padding: 12px 14px; font-size: 1rem; font-weight: 400;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.bm-option:hover { background: var(--surface-hover); }
.bm-option > input { flex: 0 0 auto; margin-top: 4px; }
.bm-option.is-checked { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.bm-option-text { display: grid; gap: 2px; min-width: 0; }
.bm-option-title { font-weight: 700; font-size: 0.9375rem; }
.bm-option-desc { color: var(--text-muted); font-size: 0.8125rem; line-height: 1.5; overflow-wrap: anywhere; }
.bm-save { min-height: 1.5em; margin: 8px 0 0; }
.bm-sub { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); min-width: 0; }
.bm-sub > h3 { margin: 0 0 4px; font-size: 1.0625rem; }
.bm-steps { margin-top: 8px; font-size: 0.9375rem; }
.bm-list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 16px 0 8px; }
/* หัวข้อผลค้นมีคำค้นของผู้ใช้ (ยาวต่อกันไม่มีช่องว่างได้) → ต้องหดได้ + ตัดบรรทัด ไม่ดันหน้าให้เลื่อนข้างที่ 375px */
.bm-list-head h4 { margin: 0; font-size: 0.9375rem; min-width: 0; overflow-wrap: anywhere; }
.bm-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.bm-list + .bm-empty, .bm-list + .bm-list-head { margin-top: 8px; }
.bm-person { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.bm-person-main { flex: 1 1 12rem; display: grid; gap: 2px; min-width: 0; }
.bm-person-name { font-weight: 600; overflow-wrap: anywhere; }
.bm-person-name.is-unknown { color: var(--text-muted); font-weight: 500; }
.bm-person-meta { color: var(--text-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
.bm-person-note { color: var(--text-muted); font-size: 0.8125rem; }
.bm-person-action { flex: 0 0 auto; }
.bm-empty { margin: 0; padding: 12px; color: var(--text-muted); font-size: 0.875rem; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius); overflow-wrap: anywhere; }
/* รหัสยืนยันบัญชีทดสอบ: กล่องเดียว · รหัสตัวใหญ่ตัวอักษรกว้างเท่ากัน (อ่านแล้วพิมพ์ตามง่าย) · แตะทีเดียวเลือกทั้งรหัส */
.bm-code { display: grid; gap: 8px; min-width: 0; margin-top: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-muted); }
.bm-code-title { margin: 0; font-weight: 600; }
.bm-code-shown { display: grid; gap: 6px; min-width: 0; }
.bm-code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.bm-code-value { font-family: var(--font-mono); font-size: 1.375rem; font-weight: 700; letter-spacing: 0.08em;
  user-select: all; overflow-wrap: anywhere; min-width: 0; }
.bm-code-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bm-pick-intro { margin: 8px 0 0; }
.bm-search { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.bm-search > input { flex: 1 1 12rem; }
/* แถบโหมดเงียบหน้ารายการ code: ข้อความ + ลิงก์ · จอแคบลิงก์ลงบรรทัดใหม่ */
.bm-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 16px; }
.bm-banner-text { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.bm-banner a { color: inherit; font-weight: 600; }
/* แถบ "ตั้งค่าเริ่มต้นยังไม่ครบ" หน้ารายการ code (/js/setup-banner.js · migration 0010) */
.setup-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 12px; }
.setup-banner-text { flex: 1 1 16rem; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
/* แถบโควตาข้อความ LINE OA ใกล้เต็ม / เต็มแล้ว หน้ารายการ code (/js/line-quota-banner.js) */
.lq-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 16px; }
.lq-banner-text { flex: 1 1 100%; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.lq-banner-help { min-width: 0; overflow-wrap: anywhere; }
.lq-banner a { color: inherit; font-weight: 600; }

/* ---------- ค่าบริการ (Phase 23 · CONTEXT § 5.7) ----------
   แถบเตือนใต้เมนู (app.js renderHeader) · หน้าระงับเต็มจอ (app.js enterSuspendedMode)
   · ส่วน "ค่าบริการ" ของแบรนด์ (/js/billing-section.js · .bl-*) — ไม่มีความกว้างตายตัว · ข้อความยาวตัดบรรทัด (375px ไม่เลื่อนข้าง) */
.billing-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0 0 8px; }
.billing-banner-text { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.billing-banner a { color: inherit; font-weight: 600; }
.suspended-notice { border-left: 4px solid var(--danger); }
.suspended-notice .page-title { margin-bottom: 4px; }
.suspended-lead { margin: 0 0 4px; font-weight: 700; font-size: 1.0625rem; color: var(--danger-text); overflow-wrap: anywhere; }
.suspended-notice .form-actions { flex-wrap: wrap; }
/* รอชำระเดือนแรก (หน้าเดียวกับหน้าระงับ) = ไม่ใช่ความผิดพลาด → กรอบสีหลัก ตัวอักษรปกติ */
.suspended-notice.is-awaiting { border-left-color: var(--primary); }
.suspended-notice.is-awaiting .suspended-lead { color: var(--text); }
.bl-root .card-header { flex-wrap: wrap; gap: 4px 10px; }
.bl-facts { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 16px; margin: 0; }
.bl-fact { display: contents; }
.bl-fact dt { color: var(--text-muted); font-size: 0.875rem; }
.bl-fact dd { margin: 0; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
@media (max-width: 30em) {
  .bl-facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .bl-fact dd { margin-bottom: 6px; }
}
.bl-sub { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); min-width: 0; }
.bl-sub > h3 { margin: 0 0 6px; font-size: 1.0625rem; }
.bl-payto { min-width: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-muted); }
.bl-account { font-size: 1.0625rem; font-weight: 700; letter-spacing: 0.02em; user-select: all; overflow-wrap: anywhere; }
.bl-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.bl-item { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.bl-item.is-void { background: var(--surface-muted); }
.bl-item-main { flex: 1 1 14rem; display: grid; gap: 2px; min-width: 0; }
.bl-item-title { font-weight: 600; overflow-wrap: anywhere; }
.bl-item-meta { color: var(--text-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
.bl-item-meta.text-danger { color: var(--danger); }
.bl-empty { margin: 0; padding: 12px; color: var(--text-muted); font-size: 0.875rem; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius); overflow-wrap: anywhere; }
.bl-root .form-row { align-items: start; }
/* จอแคบ: ฟอร์มค่าบริการเรียงช่องลงมาทีละช่อง (ป้ายยาวไม่ทำให้ช่องคู่กันเหลื่อม) */
@media (max-width: 30em) {
  .bl-root .form-row,
  .ob-form .form-row { grid-template-columns: minmax(0, 1fr); }
}
/* หน้าเจ้าของระบบ (/js/owner-billing.js · .ob-*): ภาพรวม · ไฟล์ CSV · กรอง / เรียง · ฟอร์มในหัวข้อ "ค่าบริการ / ใบกำกับภาษี" */
.ob-stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); }
.ob-csv { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; min-width: 0; }
.ob-csv > .field { margin: 0; }
.ob-csv > .help { flex: 1 1 100%; }
.ob-tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-bottom: 12px; min-width: 0; }
.ob-tools > .field { margin: 0; min-width: 0; }
.ob-tools select { max-width: 100%; }
.ob-form { margin-top: 8px; }
.ob-form .form-row { align-items: start; }
.ob-sub-title { margin: 0 0 6px; font-size: 1rem; }
.ob-billing .bl-item .btn-group { flex-wrap: wrap; }
.ob-payment-filters, .ob-payment-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.ob-payment-filters { margin-bottom: 12px; }
.ob-slip-dialog { width: 44rem; }
.ob-slip-image { display: block; width: auto; max-width: 100%; max-height: 65vh; margin: 12px auto; object-fit: contain; }
.ob-slip-image[hidden] { display: none; }

/* หน้าเจ้าของระบบ: การ์ดสรุปงานบนสุด (/js/owner-summary.js · TASK-121) — 3 การ์ด: แถวละ 1 บนมือถือ · 3 คอลัมน์ตั้งแต่ 640px · ทั้งการ์ดเป็นลิงก์ */
.ow-summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-bottom: 8px; }
@media (min-width: 640px) { .ow-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.ow-card { display: grid; align-content: start; gap: 2px; min-width: 0; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text); text-decoration: none; }
.ow-card:hover { border-color: var(--primary); color: var(--text); }
.ow-card.has-work { border-color: var(--primary); box-shadow: inset 0 4px 0 var(--accent), var(--shadow-sm); }
.ow-card-num { font-size: 1.75rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.ow-card-label { font-weight: 700; overflow-wrap: anywhere; }
.ow-card-hint { color: var(--text-muted); font-size: 0.8125rem; overflow-wrap: anywhere; }
[id="billing-notices-title"], [id="billing-overview-title"], [id="brands-title"] { scroll-margin-top: 12px; }

/* ---------- ข้อตกลง (Phase 24 · TASK-105 · app.js enterLegalMode / renderFooter) ----------
   หน้า "ยอมรับข้อตกลงก่อนใช้งานต่อ" เต็มจอ (โครงเดียวกับหน้าระงับ) · ท้ายหน้าทุกหน้า Dashboard (ลิงก์ /legal/*)
   ไม่มีความกว้างตายตัว · ข้อความยาวตัดบรรทัด (375px ไม่เลื่อนข้าง) */
.legal-notice { border-left: 4px solid var(--primary); }
.legal-notice .page-title { margin-bottom: 4px; }
.legal-lead { margin: 0 0 8px; overflow-wrap: anywhere; }
.legal-docs { display: grid; gap: 6px; margin: 0 0 12px; padding-left: 1.25rem; min-width: 0; }
.legal-docs li { overflow-wrap: anywhere; }
.legal-docs a { font-weight: 600; }
.legal-form { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.legal-check { display: flex; align-items: flex-start; line-height: 1.55; min-width: 0; overflow-wrap: anywhere; }
.legal-check input { flex: 0 0 auto; margin-top: 3px; }
.legal-more { flex-wrap: wrap; }
.app-footer { margin-top: 24px; padding-block: 16px 24px; border-top: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); font-size: 0.8125rem; }
.app-footer-inner { display: grid; gap: 6px; min-width: 0; }
.app-footer-links { display: flex; flex-wrap: wrap; gap: 0 16px; min-width: 0; }
.app-footer-links a { display: inline-block; padding-block: 6px; }
.app-footer-links a,
.app-footer-contact a { color: inherit; }
.app-footer-contact { margin: 0; overflow-wrap: anywhere; }

/* สีแบรนด์: ตัวเลือก/ตัวอย่างใช้ร่วมกันใน /settings และ /setup · .bc-* เท่านั้น */
.bc-editors { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
@media (min-width: 960px) { .bc-editors { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.bc-editor { min-width: 0; }
.bc-picker { min-width: 0; margin: 0; padding: 0; border: 0; }
.bc-picker-title { padding: 0; margin-bottom: 10px; font-size: 1rem; font-weight: 700; }
.bc-input-row { display: flex; align-items: flex-end; gap: 12px; }
.bc-native { flex: 0 0 3.5rem; width: 3.5rem; height: 2.75rem; padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.bc-hex-field { min-width: 0; max-width: 14rem; margin: 0; }
.bc-hex { width: 100%; }
.bc-presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.bc-preset { display: inline-flex; align-items: center; gap: 5px; }
.bc-preset[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.bc-swatch { width: 1rem; height: 1rem; flex: none; border-radius: 50%; background: var(--bc-swatch); border: 1px solid var(--border-strong); }
.bc-preview-note { margin: 12px 0 6px; }
.bc-menu-preview { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
/* ฟอร์มจริงมีพื้นสว่างเสมอ: ตัวอย่างยังอ่านได้แม้ Dashboard ใช้ธีมมืด */
.bc-form-preview { --text: rgb(17 20 24); --text-muted: rgb(78 87 88); --surface: rgb(255 255 255); --border: rgb(202 211 203); color-scheme: light; color: var(--text); background: var(--bg); padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.bc-preview-kicker { margin: 0; color: var(--text-muted); font-size: 0.75rem; }
.bc-preview-brand { margin: 2px 0 12px; font-size: 1.125rem; overflow-wrap: anywhere; }
.bc-preview-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 10px; }
.bc-preview-tab { padding: 7px 2px; font: inherit; font-size: 0.75rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.bc-preview-tab[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.bc-preview-card { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.bc-preview-label { margin: 0 0 4px; color: var(--text); font-size: 0.8125rem; font-weight: 600; }
.bc-preview-field { padding: 7px 9px; margin-bottom: 10px; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.8125rem; overflow-wrap: anywhere; }
.bc-preview-submit { display: block; width: 100%; padding: 8px 12px; border: 1px solid var(--primary-border); border-radius: var(--radius); background: var(--primary); color: var(--on-primary); font: inherit; font-size: 0.875rem; font-weight: 700; cursor: pointer; }
.bc-preview-submit:hover { background: var(--primary-hover); }
.bc-preview-tab:focus-visible, .bc-preview-submit:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.bc-preview-success { margin: 10px 0 0; padding: 8px 10px; color: var(--success-text); background: var(--success-soft); border: 1px solid var(--success-border); border-radius: var(--radius); font-size: 0.8125rem; }

/* คู่มือวิดีโอรายงาน: โหลดเมื่อผู้ใช้เปิดดู ไม่มี autoplay หรือบริการวิดีโอภายนอก */
.tutorial-video > summary { cursor:pointer; font-weight:700; }
.tutorial-video > summary:focus-visible { outline:3px solid var(--focus); outline-offset:4px; }
.tutorial-video video { display:block; width:100%; max-width:960px; height:auto; margin:16px auto 0; background:var(--bg); }
