/* =====================================================================
   patch13 (Phase 3 patch3): Design System v2 — "Vibrant & Friendly" (teal)
   ---------------------------------------------------------------------
   แทนที่ธีม violet จาก patch11 ด้วยธีมใหม่ตามภาพตัวอย่างที่ผู้ใช้ให้มา: โทนฟ้าอม
   เขียว (teal) สดใส การ์ด/ปุ่มโค้งมนขึ้นอีกขั้น เงานุ่มนวลอิงสีธีม + ไซด์บาร์แบบ
   ไอคอนล้วน (icon rail) พร้อม tooltip ตอนชี้เมาส์ และปุ่มพับ/กางไซด์บาร์ได้ (จำค่าไว้
   ใน localStorage ของเบราว์เซอร์ผู้ใช้ ค่าเริ่มต้น = กาง) — ย้ายข้อมูลผู้ใช้/ปุ่มออกจาก
   ระบบไปไว้ที่เมนู avatar มุมขวาบนของ topbar แทน (topbar เปลี่ยนจากโผล่แค่มือถือ
   เป็นโผล่ทุกขนาดหน้าจอ) ให้ใกล้เคียงภาพตัวอย่างมากที่สุด
   คลาสเดิมจาก patch9/10/12 (ด้านล่างของไฟล์นี้) คงชื่อไว้ทุกตัวที่ JS อ้างอิงอยู่
   (message-box, tab-btn/tab-panel, data-table, po-item-row, pos-product-card,
   pos-cart-row, pos-failed-row, btn/btn-secondary/btn-inline ฯลฯ) — รีสไตล์ผ่าน
   design token ชุดใหม่ + ปรับโครงสร้าง markup บางจุด (sidebar/topbar shell, การ์ด
   สินค้ามีรูป) ตามที่ตกลงกันไว้ก่อนเริ่ม (ดู CLAUDE.md patch13)
   ===================================================================== */

:root {
  /* ---------- สี: โทนหลัก (teal สดใส เป็นมิตร) ---------- */
  --color-primary: #0d9488;
  --color-primary-dark: #0f766e;
  --color-primary-darker: #115e59;
  --color-primary-soft: #e6faf6;
  --color-primary-soft-hover: #cdf3ea;
  --color-primary-text: #ffffff;
  --gradient-primary: linear-gradient(135deg, #14b8a6 0%, #0d9488 55%, #0f766e 100%);

  /* ---------- สี: accent รอง (ส้มคอรัล — ใช้แต่จุดเน้นเล็กๆ ไม่ใช้เป็นสีหลัก) ---------- */
  --color-accent: #fb923c;
  --color-accent-dark: #ea580c;
  --color-accent-soft: #fff3e8;

  /* ---------- สี: พื้นหลัง/พื้นผิว/ตัวหนังสือ ---------- */
  --color-bg: #f2faf8;
  --color-surface: #ffffff;
  --color-border: #d7ece7;
  --color-border-soft: #e7f4f1;
  --color-text: #0f2a27;
  --color-muted: #5f7d78;

  /* ---------- สี: semantic (success/error/warn/info) ---------- */
  --color-success: #16a34a;
  --color-success-bg: #e9faf0;
  --color-success-text: #15803d;
  --color-error: #e11d48;
  --color-error-bg: #fef1f4;
  --color-error-text: #be123c;
  --color-warn: #d97706;
  --color-warn-bg: #fef8e8;
  --color-warn-text: #92400e;
  --color-info: #2563eb;
  --color-info-bg: #eef4ff;
  --color-info-text: #1d4ed8;

  /* ---------- รัศมีขอบ (โค้งมนขึ้นอีกขั้นจาก patch11) ---------- */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-full: 999px;

  /* ---------- เงา (นุ่มนวล อิงสี teal หลักแทนสีม่วงเดิม) ---------- */
  --shadow-xs: 0 1px 2px rgba(15, 42, 39, 0.06);
  --shadow-sm: 0 3px 10px -3px rgba(13, 148, 136, 0.20);
  --shadow-md: 0 14px 30px -14px rgba(13, 148, 136, 0.32);
  --shadow-lg: 0 22px 48px -18px rgba(13, 148, 136, 0.36);

  --transition: 150ms ease;

  /* ---------- ไซด์บาร์ไอคอนล้วน (patch13) ---------- */
  --sidebar-width: 76px;
  --sidebar-width-expanded: 232px;
  --sidebar-width-mobile: 248px;

  /* ---------- ฟอนต์: Mitr (หัวข้อ/ปุ่ม/nav) + Noto Sans Thai (เนื้อหา) — คงจาก patch11 ---------- */
  --font-heading: 'Mitr', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  font-family: var(--font-body);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden; /* patch14: กันหน้าล้นแนวนอนทั้งเว็บ (safety net) — สาเหตุจริงแก้ด้วย
    min-width:0 ไล่ทั้งสาย app-main/app-content/page ด้านล่างแล้ว อันนี้กันเผื่อจุดที่พลาดไป
    ตั้งใจใส่ที่ html ไม่ใช่ body เพราะใส่ overflow-x เดี่ยวๆ ที่ body จะทำให้ overflow-y ที่ browser
    คำนวณให้กลายเป็น auto ไปด้วย (ตาม spec) ซึ่งจะสร้าง scroll container ใหม่ซ้อนกับ html แล้ว
    ทำให้ position:sticky ของ topbar เพี้ยน (ไม่ยึดกับ viewport จริงอีกต่อไป) — ใส่ที่ html แทน
    ปลอดภัยกว่าเพราะ html เป็น root scrolling element อยู่แล้วโดย spec */
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

h1, h2, h3, .section-title, .app-sidebar__brand-name, .app-nav__link, button {
  font-family: var(--font-heading);
}

/* ===================== Cards (auth pages: login/register/forgot/reset) ===================== */

.auth-page-bg {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(760px 420px at 12% -8%, rgba(20, 184, 166, 0.16), transparent 60%),
    radial-gradient(620px 380px at 108% 18%, rgba(251, 146, 60, 0.12), transparent 55%),
    var(--color-bg);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.card--wide {
  max-width: 560px;
}

.auth-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--gradient-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.auth-mark svg {
  width: 24px;
  height: 24px;
}

h1 {
  font-size: 21px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--color-text);
}

.subtitle {
  color: var(--color-muted);
  font-size: 14px;
  margin: 0 0 24px;
  font-family: var(--font-body);
}

/* ===================== Forms ===================== */

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  margin-top: 16px;
  color: var(--color-text);
}

label:first-of-type {
  margin-top: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="file"],
select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-primary-soft);
}

/* ===================== Buttons ===================== */

button.btn {
  width: 100%;
  padding: 12px 18px;
  margin-top: 24px;
  background: var(--gradient-primary);
  color: var(--color-primary-text);
  border: none;
  border-radius: var(--radius-full);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-heading);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition), filter var(--transition);
}

button.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

button.btn:hover:not(:disabled) {
  filter: brightness(1.05);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

button.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  border: 1.5px solid transparent;
  box-shadow: none;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-primary-soft-hover);
  box-shadow: none;
  transform: none;
  filter: none;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--color-muted);
  font-size: 12px;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-heading);
  text-decoration: none;
  box-sizing: border-box;
  transition: background var(--transition), border-color var(--transition);
}
.google-btn:hover {
  background: var(--color-bg);
  border-color: var(--color-primary);
}

.links {
  margin-top: 20px;
  font-size: 13px;
  text-align: center;
  color: var(--color-muted);
}
.links a {
  color: var(--color-primary-dark);
  text-decoration: none;
  font-weight: 600;
}
.links a:hover {
  text-decoration: underline;
}

.message-box {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 16px;
  display: none;
  border-left: 3px solid transparent;
}
.message-box.visible {
  display: block;
}
.message-box.error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-left-color: var(--color-error);
}
.message-box.success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-left-color: var(--color-success);
}

.field-error {
  color: var(--color-error-text);
  font-size: 12px;
  margin-top: 4px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-soft);
  font-size: 14px;
}
.info-row:last-child {
  border-bottom: none;
}
.info-row .label {
  color: var(--color-muted);
}
.info-row .value {
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}
.badge--warn {
  background: var(--color-warn-bg);
  color: var(--color-warn-text);
}
.badge--ok {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}
.badge--info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}
.badge--muted {
  background: var(--color-bg);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
}

.loading-text {
  text-align: center;
  color: var(--color-muted);
  font-size: 14px;
}

/* =====================================================================
   patch13/14: App Shell v2 — ไซด์บาร์ไอคอนล้วน (icon rail) + topbar ถาวรทุกขนาดจอ
   (dashboard.html / products.html / purchase-orders.html / pos.html)
   mount โดย assets/js/layout.js หลัง requireAuth() สำเร็จ (ดูไฟล์นั้น)

   โครงสร้างสถานะ:
   - .sidebar-open     : มือถือ/แท็บเล็ต (<900px) เท่านั้น — ไซด์บาร์กลายเป็น off-canvas
                          drawer แบบเดิม (ปิดเป็นค่าเริ่มต้น เปิดด้วยปุ่ม hamburger, ไม่จำค่า)
   - .sidebar-expanded : เดสก์ท็อป (>=900px) เท่านั้น — กางไซด์บาร์เต็ม (เห็นไอคอน+ชื่อเมนู)
                          (ค่าเริ่มต้น patch14 = ไม่กาง คือย่อเป็นไอคอนล้วน 76px + tooltip ตอนชี้เมาส์)
                          จำค่าไว้ใน localStorage
   ปุ่มเดียวใน topbar สลับพฤติกรรมให้เองอัตโนมัติตามความกว้างจอ (ดู layout.js)
   ===================================================================== */

body.app-page {
  display: block;
  padding: 0;
  align-items: normal;
  justify-content: normal;
  min-height: 100vh;
  background: var(--color-bg);
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-primary-darker);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  overflow: hidden;
  transition: width var(--transition), padding var(--transition), transform var(--transition);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0 18px;
  flex-shrink: 0;
}
.app-sidebar__brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-sidebar__brand-mark svg {
  width: 20px;
  height: 20px;
}
.app-sidebar__brand-name {
  display: none; /* โผล่เฉพาะมือถือ (drawer มีที่พอ) — ดู media query ด้านล่าง */
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  width: 100%;
  align-items: center;
}
.app-nav__link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.app-nav__link svg {
  width: 21px;
  height: 21px;
  flex-shrink: 0;
}
.app-nav__link .app-nav__label {
  display: none; /* โผล่ตอน sidebar กางเต็ม (.sidebar-expanded) บนเดสก์ท็อป หรือบนมือถือเสมอ — ดู media query/state ด้านล่าง */
}
.app-nav__link:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.app-nav__link.active {
  background: rgba(255, 255, 255, 0.96);
  color: var(--color-primary-dark);
  box-shadow: var(--shadow-sm);
}

/* Tooltip — โผล่ตอนชี้เมาส์/โฟกัส เฉพาะตอน sidebar อยู่ในโหมด "ย่อ" (ไอคอนล้วน) เท่านั้น
   (ค่าเริ่มต้นบนเดสก์ท็อป — ถ้ากางเต็มแล้วมี label โชว์อยู่แล้วไม่ต้อง tooltip ซ้อน ดูด้านล่าง) */
.app-nav__link::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--color-text);
  color: #fff;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: var(--font-body);
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 60;
  box-shadow: var(--shadow-md);
}
.app-nav__link:hover::after,
.app-nav__link:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

.app-sidebar__footer {
  flex-shrink: 0;
  padding-top: 10px;
  width: 100%;
  display: flex;
  justify-content: center;
}
/* หมายเหตุ patch13: ย้ายข้อมูลผู้ใช้ + ปุ่ม logout จาก sidebar footer ไปรวมที่เมนู
   avatar มุมขวาบนของ topbar แล้ว (ดูหัวข้อ Topbar ด้านล่าง) ให้ตรงกับภาพตัวอย่าง
   ที่ผู้ใช้ให้มา — sidebar เหลือแค่โลโก้ + เมนูไอคอนล้วนๆ */

.app-main {
  flex: 1;
  min-width: 0; /* patch14: กัน flex item ถูกดันกว้างเกิน parent ตาม min-width:auto default ของ
    flexbox ตอนลูกหลานมีตารางกว้าง (white-space:nowrap) — ต้นตอจริงของบั๊กหน้าล้นแนวนอน */
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition);
}

/* ===== patch14: sidebar เดสก์ท็อป เปิด(กางเต็ม มีชื่อเมนู)/ปิด(ย่อ ไอคอนล้วน) ได้ ค่าเริ่มต้น = ปิด(ย่อ)
   ค่าเริ่มต้น (ไม่มี class .sidebar-expanded) = โหมดย่อ ไอคอนล้วน 76px ใช้ CSS ฐานด้านบนตรงๆ
   อยู่แล้ว ไม่ต้องเพิ่มอะไร — ด้านล่างนี้คือ override ตอนกางเต็มเท่านั้น (มีผลเฉพาะเดสก์ท็อป >=900px
   เพราะมือถือใช้ .sidebar-open ควบคุม drawer แยกกันคนละกลไก ดู media query ท้ายไฟล์) */
@media (min-width: 900px) {
  .app-shell.sidebar-expanded .app-sidebar {
    width: var(--sidebar-width-expanded);
    align-items: stretch;
    padding: 16px 12px;
  }
  .app-shell.sidebar-expanded .app-main {
    margin-left: var(--sidebar-width-expanded);
  }
  .app-shell.sidebar-expanded .app-sidebar__brand {
    justify-content: flex-start;
    padding: 4px 8px 20px;
    gap: 10px;
  }
  .app-shell.sidebar-expanded .app-sidebar__brand-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    line-height: 1.25;
  }
  .app-shell.sidebar-expanded .app-sidebar__brand-name small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-body);
  }
  .app-shell.sidebar-expanded .app-nav {
    align-items: stretch;
  }
  .app-shell.sidebar-expanded .app-nav__link {
    width: 100%;
    height: auto;
    justify-content: flex-start;
    gap: 12px;
    padding: 11px 12px;
  }
  .app-shell.sidebar-expanded .app-nav__link .app-nav__label {
    display: inline;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-body);
  }
  .app-shell.sidebar-expanded .app-nav__link::after {
    display: none; /* กางเต็มแล้วมี label โชว์ตรงๆ อยู่แล้ว ไม่ต้อง tooltip ซ้อน */
  }
}

/* ===== Topbar — โผล่ทุกขนาดจอตั้งแต่ patch13 (เดิมโผล่แค่มือถือ) ===== */

.app-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.app-topbar__menu-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}
.app-topbar__menu-btn:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-soft-hover);
}
.app-topbar__menu-btn svg {
  width: 20px;
  height: 20px;
}
.app-topbar__title {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-heading);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-topbar__spacer {
  flex: 1;
}

/* ----- เมนู avatar ผู้ใช้ (มุมขวาบน) — ย้ายมาจาก sidebar footer เดิม ----- */
.app-user-menu {
  position: relative;
  flex-shrink: 0;
}
.app-user-menu__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.app-user-menu__trigger:hover,
.app-user-menu.open .app-user-menu__trigger {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-soft-hover);
}
.app-user__avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  font-family: var(--font-heading);
}
.app-user-menu__trigger svg {
  width: 15px;
  height: 15px;
  color: var(--color-muted);
  flex-shrink: 0;
}
.app-user-menu__name {
  display: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 560px) {
  .app-user-menu__name {
    display: block;
  }
}

.app-user-menu__panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 130ms ease, transform 130ms ease, visibility 130ms;
  z-index: 60;
}
.app-user-menu.open .app-user-menu__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.app-user-menu__info {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--color-border-soft);
  margin-bottom: 6px;
}
.app-user-menu__info .app-user__name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-user-menu__info .app-user__role {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 1px;
}

button.app-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 10px;
  margin-top: 0;
  background: transparent;
  color: var(--color-error-text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font-heading);
  cursor: pointer;
  box-shadow: none;
  transition: background var(--transition);
}
button.app-logout-btn:hover {
  background: var(--color-error-bg);
  transform: none;
  box-shadow: none;
  filter: none;
}
button.app-logout-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
}

.app-content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
  display: flex;
  flex-direction: column; /* patch14: เดิมไม่ได้ตั้งค่านี้ ค่า default ของ flex คือ row ทำให้หน้าที่มี
    การ์ดมากกว่า 1 ใบใน .app-content โดยตรง (เช่น dashboard.html: content-card + shop-settings-card)
    เรียงชิดกันแนวนอนแทนที่จะเรียงต่อกันลงมา จนดันหน้าล้นจอมือถือ — นี่คือสาเหตุจริงของบั๊กที่แจ้งมา */
  align-items: center;
  gap: 20px; /* ระยะห่างระหว่างการ์ดตอนมีมากกว่า 1 ใบเรียงลงมา (เช่นหน้า dashboard) */
}
.app-content > .card,
.app-content > .page {
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 899px) {
  .app-sidebar {
    width: var(--sidebar-width-mobile);
    align-items: stretch;
    padding: 20px 14px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-shell.sidebar-open .app-sidebar {
    transform: translateX(0);
  }
  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 42, 39, 0.42);
    z-index: 35;
  }
  .app-main {
    margin-left: 0;
  }
  .app-sidebar__brand {
    justify-content: flex-start;
    padding: 4px 10px 20px;
    gap: 10px;
  }
  .app-sidebar__brand-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    line-height: 1.25;
  }
  .app-sidebar__brand-name small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-body);
  }
  .app-nav {
    align-items: stretch;
  }
  .app-nav__link {
    width: 100%;
    height: auto;
    justify-content: flex-start;
    gap: 12px;
    padding: 11px 12px;
  }
  .app-nav__link .app-nav__label {
    display: inline;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-body);
  }
  .app-nav__link::after {
    display: none; /* มือถือโชว์ label ตรงๆ อยู่แล้ว ไม่ต้อง tooltip ซ้อน */
  }
  .app-content {
    padding: 20px 16px;
  }
  .page {
    padding: 20px;
  }
}

/* ===== หน้าเนื้อหาทั่วไป (products/purchase-orders) — โครงสร้าง/ชื่อคลาสเดิมจาก patch9/10
   คงไว้ทั้งหมด (patch13: รีสไตล์ตาม token ชุดใหม่ + เพิ่มส่วนหัวหน้าแบบมีไอคอน) ===== */

.page {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  min-width: 0;
  max-width: 1080px;
  box-shadow: var(--shadow-sm);
}

.page-header {
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.page-header__icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: var(--gradient-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.page-header__icon svg {
  width: 23px;
  height: 23px;
}
.page-header h1 {
  margin: 0 0 2px;
}
.page-header .subtitle {
  margin: 0;
}

.btn-link {
  color: var(--color-primary-dark);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.btn-link:hover {
  text-decoration: underline;
}

button.btn-inline {
  width: auto;
  margin-top: 0;
  padding: 9px 16px;
  font-size: 13px;
}

button.btn-small {
  width: auto;
  margin-top: 0;
  padding: 9px 16px;
  font-size: 13px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--color-border);
  margin-bottom: 20px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 10px 6px;
  margin-right: 20px;
  margin-bottom: -1.5px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-heading);
  color: var(--color-muted);
  cursor: pointer;
}
.tab-btn.active {
  color: var(--color-primary-dark);
  border-bottom-color: var(--color-primary);
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar input[type="text"],
.toolbar input[type="number"],
.toolbar select {
  width: auto;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}
.toolbar .spacer {
  flex: 1;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: normal;
  color: var(--color-text);
  margin: 0;
  cursor: pointer;
}
.checkbox-label input {
  width: auto;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th,
table.data-table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--color-border-soft);
  white-space: nowrap;
}
table.data-table th {
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: 12px;
  background: var(--color-primary-soft);
}
table.data-table td.wrap {
  white-space: normal;
}
table.data-table tbody tr:last-child td {
  border-bottom: none;
}
table.data-table tbody tr:hover {
  background: var(--color-bg);
}

/* ----- รูปสินค้าเล็กในตาราง (patch13 — feature ใหม่: อัปโหลดรูปสินค้า) ----- */
.product-thumb {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  background: var(--color-primary-soft);
  display: block;
}
.product-thumb--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font-heading);
}
/* ----- คอลัมน์แรก sticky ตอนเลื่อนตารางแนวนอน (patch14) — เปิดใช้ผ่าน class
   .data-table--sticky-col บน <table> + class .sticky-col บน th/td ตัวที่ต้องการค้างไว้
   (ตารางสินค้า = คอลัมน์รูป, ตารางใบสั่งซื้อ = คอลัมน์เลขที่) ----- */
table.data-table--sticky-col th.sticky-col,
table.data-table--sticky-col td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--color-surface);
}
table.data-table--sticky-col th.sticky-col {
  z-index: 2;
  background: var(--color-primary-soft);
}
table.data-table--sticky-col tbody tr:hover td.sticky-col {
  background: var(--color-bg);
}
table.data-table--sticky-col th.sticky-col::after,
table.data-table--sticky-col td.sticky-col::after {
  content: '';
  position: absolute;
  top: 0;
  right: -6px;
  bottom: 0;
  width: 6px;
  background: linear-gradient(to right, rgba(15, 42, 39, 0.07), transparent);
  pointer-events: none;
}

.row-actions {
  display: flex;
  gap: 6px;
}
.row-actions button {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
  color: var(--color-text);
  font-family: inherit;
}
.row-actions button:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-soft);
}

.panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  background: var(--color-bg);
}
.panel h3 {
  margin: 0 0 16px;
  font-size: 15px;
}

/* ----- แผงอัปโหลดรูปสินค้า (patch13) ในฟอร์มเพิ่ม/แก้ไขสินค้า ----- */
.image-upload-field {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}
.image-upload-preview {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  color: var(--color-muted);
}
.image-upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-upload-preview svg {
  width: 26px;
  height: 26px;
}
.image-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.image-upload-actions input[type="file"] {
  padding: 8px 10px;
  font-size: 12.5px;
}
.image-upload-actions .hint-text {
  margin: 0;
}
button.btn-remove-image {
  width: auto;
  margin-top: 0;
  padding: 7px 14px;
  font-size: 12px;
  background: transparent;
  color: var(--color-error-text);
  border: 1.5px solid var(--color-border);
  box-shadow: none;
}
button.btn-remove-image:hover:not(:disabled) {
  background: var(--color-error-bg);
  border-color: var(--color-error-bg);
  transform: none;
  filter: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-grid .field-full {
  grid-column: 1 / -1;
}
.form-grid label {
  margin-top: 14px;
}
.form-grid label:first-of-type {
  margin-top: 0;
}
@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.form-actions button.btn {
  margin-top: 0;
  width: auto;
  flex: none;
  padding: 11px 22px;
}

.hint-text {
  color: var(--color-muted);
  font-size: 12px;
  margin: 4px 0 0;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 28px 0 12px;
}
.section-title:first-child {
  margin-top: 0;
}

/* ===== หน้าใบสั่งซื้อ (Purchase Order) — โครงสร้าง/ชื่อคลาสเดิมจาก patch10 ไม่เปลี่ยน ===== */

.po-items-header,
.po-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.po-items-header {
  padding: 9px 12px;
  background: var(--color-primary-soft);
  font-size: 12px;
  color: var(--color-primary-dark);
  font-weight: 700;
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.po-items-editor {
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow: hidden;
}

.po-item-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-soft);
}
.po-item-row:last-child {
  border-bottom: none;
}
.po-item-row select,
.po-item-row input {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}

.remove-item-btn {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--color-error-text);
  font-size: 12px;
  white-space: nowrap;
}
.remove-item-btn:hover {
  background: var(--color-error-bg);
}

.po-total-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .po-items-header {
    display: none;
  }
  .po-item-row {
    grid-template-columns: 1fr;
  }
}

/* ===== หน้าหลัก (dashboard) — การ์ดลิงก์ด่วน (patch13, ใหม่ — ลิงก์จริงทั้งหมด ไม่มีข้อมูลปลอม) ===== */

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 22px 0 6px;
}
.quick-link-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.quick-link-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
  border-color: var(--color-primary-soft-hover);
}
.quick-link-card__icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quick-link-card__icon svg {
  width: 21px;
  height: 21px;
}
.quick-link-card__label {
  font-size: 14px;
  font-weight: 600;
}
.quick-link-card__desc {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 1px;
}

.welcome-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.welcome-banner__text h1 {
  margin-bottom: 4px;
}
.welcome-banner__mark {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--gradient-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}
.welcome-banner__mark svg {
  width: 30px;
  height: 30px;
}

/* =====================================================================
   patch12/patch13: POS หน้าร้าน — layout, การ์ดสินค้า (มีรูป), ตะกร้า, checkout, ใบเสร็จ
   patch13: ปรับการ์ดสินค้าให้มีรูปภาพ (ฟีเจอร์ใหม่) + ตะกร้าโทนทีล ตามภาพตัวอย่าง
   ===================================================================== */

.app-content--pos {
  align-items: flex-start;
}

.pos-layout {
  width: 100%;
  max-width: 1160px;
  display: flex;
  flex-direction: column;
  gap: 20px; /* patch14: เพิ่มจาก 16px ให้เห็นช่องว่างระหว่างบล็อกเปิดกะกับบล็อกสินค้าชัดขึ้น ตามที่แจ้งมาว่าดูติดกันเกินไป */
}

.pos-shift-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--color-muted);
  flex-wrap: wrap;
}
.pos-shift-bar__info b {
  color: var(--color-text);
}
.pos-shift-bar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pos-failed-banner {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-text);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-error-text);
}
.pos-failed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.pos-failed-row button {
  flex-shrink: 0;
}

.pos-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  align-items: start;
}

.pos-catalog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.pos-catalog input[type="text"] {
  margin-bottom: 14px;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: var(--radius-full);
}

.pos-product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 2px;
}

.pos-product-card {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--color-surface);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.pos-product-card:hover:not(:disabled) {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}
.pos-product-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.pos-product-card__thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--color-primary-soft);
  flex-shrink: 0;
}
.pos-product-card__thumb--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: 26px;
  font-family: var(--font-heading);
  background: var(--color-primary-soft);
}
.pos-product-card__body {
  padding: 10px 11px 12px;
}
.pos-product-card__name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  line-height: 1.3;
}
.pos-product-card__price {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-primary-dark);
}
.pos-product-card__stock {
  font-size: 11px;
  color: var(--color-muted);
  margin-top: 4px;
}

.pos-cart {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 16px;
}
.pos-cart h3 {
  margin: 0;
  padding: 18px 20px;
  font-size: 15px;
  color: #fff;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pos-cart-items {
  max-height: 40vh;
  overflow-y: auto;
  padding: 6px 20px 0;
}
.pos-cart-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border-soft);
  font-size: 13px;
}
.pos-cart-row__name {
  min-width: 0;
}
.pos-cart-row__name small {
  display: block;
  color: var(--color-muted);
  font-size: 11px;
}
.pos-cart-row__qty {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pos-cart-row__qty button {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.pos-cart-row__subtotal {
  font-weight: 700;
  white-space: nowrap;
}
#cart-empty {
  padding: 20px 0;
}
.pos-cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 20px;
  margin: 6px 20px 0;
  background: var(--color-primary-soft);
  border-radius: var(--radius);
  color: var(--color-primary-darker);
}
#checkout-btn {
  margin: 14px 20px 20px;
  width: calc(100% - 40px);
}

@media (max-width: 900px) {
  .pos-grid {
    grid-template-columns: 1fr;
  }
  .pos-cart {
    position: static;
  }
}

/* ----- Checkout / close-shift modal ----- */
.pos-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 42, 39, 0.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pos-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.pos-modal h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-family: var(--font-heading);
}
.pos-modal__total {
  color: var(--color-muted);
  font-size: 14px;
  margin: 0 0 18px;
}
.pos-modal__total b {
  color: var(--color-text);
  font-size: 16px;
}

/* patch20: ขยาย modal ให้กว้างขึ้น + บีบทุกส่วนให้กระชับลง ให้ทั้ง 3 ส่วนพอดีจอไม่ต้องเลื่อน
   (ผู้ใช้แนบ screenshot จริงจากคอมมาว่ายังต้องเลื่อน + ปุ่ม/ช่องอินพุตใหญ่เกินไป) — scope เฉพาะใน
   `.pos-modal--checkout-combined` เท่านั้น ไม่แตะ label/input/button.btn ตัวเดิมที่ใช้ทั่วทั้งแอป */
.pos-modal--checkout-combined {
  max-width: 560px;
  position: relative; /* patch22: จุดยึดให้ปุ่มกากบาทมุมขวาบน (position:absolute) */
}
/* patch22: ปุ่มกากบาทมุมขวาบน แทนปุ่ม "← กลับ" เดิมด้านล่างซ้าย */
.pos-modal__close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-muted);
  font-size: 16px;
  line-height: 30px;
  text-align: center;
  cursor: pointer;
  box-shadow: none;
  border-radius: 50%;
}
.pos-modal__close-btn:hover {
  color: var(--color-text);
  background: var(--color-primary-soft);
  transform: none;
}
/* patch22: ปุ่ม "ยืนยันการขาย" ที่ย้ายมาอยู่คู่กับ "เปลี่ยน" ในการ์ดสมาชิกที่เลือกแล้ว ต้อง auto
   width (ปกติ button.btn กว้างเต็ม 100%) ไม่งั้นดันปุ่ม "เปลี่ยน" ตกไปคนละบรรทัด */
.pos-modal--checkout-combined .card-status-box__actions button.btn {
  width: auto;
  margin-top: 0;
  padding: 8px 16px;
  font-size: 13px;
}
/* patch21: หัวข้อ + ยอดที่ต้องชำระ แถวเดียวกัน ตาม mockup ที่แนบมา */
.pos-modal--checkout-combined .pos-modal__header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.pos-modal--checkout-combined .pos-modal__header-row h2 {
  margin: 0;
}
.pos-modal--checkout-combined h2 {
  font-size: 16px;
  margin-bottom: 2px;
}
.pos-modal--checkout-combined .pos-modal__total {
  font-size: 13px;
  margin: 0;
}
.pos-modal--checkout-combined .pos-pay-section {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
}
.pos-modal--checkout-combined .pos-pay-section__header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 8px;
  gap: 8px;
  border-bottom: 1px dashed var(--color-border);
}
.pos-modal--checkout-combined .pos-pay-section__title {
  font-weight: 600;
  font-family: var(--font-heading);
  font-size: 13px;
}
.pos-modal--checkout-combined .pos-pay-section__icon {
  font-size: 16px;
}
.pos-modal--checkout-combined label {
  margin-top: 0;
  margin-bottom: 4px;
  font-size: 11.5px;
}
.pos-modal--checkout-combined input[type="text"] {
  padding: 7px 10px;
  font-size: 13px;
}
.pos-modal--checkout-combined .hint-text {
  font-size: 11px;
  margin: 6px 0;
}
.pos-modal--checkout-combined .toolbar {
  gap: 6px;
  margin-top: 6px;
}
/* patch21: toolbar ในส่วน wallet ตอนนี้มี 3 อย่าง (ช่องค้นหา + ปุ่มค้นหา + ปุ่มยืนยัน) — ให้ช่อง
   ค้นหากินพื้นที่ที่เหลือ ปุ่มทั้งสองเรียงชิดขวาแบบ auto width ตาม mockup */
.pos-modal--checkout-combined .toolbar input[type="text"] {
  flex: 1 1 100px;
}
.pos-modal--checkout-combined .toolbar button.btn {
  width: auto;
  flex: none;
  white-space: nowrap;
}
.pos-modal--checkout-combined .card-status-box {
  padding: 8px 10px;
  margin-bottom: 8px;
}
.pos-modal--checkout-combined .form-actions {
  margin-top: 8px;
}
.pos-modal--checkout-combined .form-actions button.btn {
  padding: 8px 16px;
  font-size: 13px;
}
/* patch22: ".pos-modal--checkout-combined > .btn-link" (ปุ่ม "← กลับ" เดิม) ถูกลบทิ้งแล้ว —
   ไม่มี direct-child .btn-link เหลืออยู่ในนี้อีกต่อไป (เอากฎที่ตายแล้วออกไปด้วย ไม่ปล่อยค้าง) */
/* patch21: เงินทอน (เต็มพื้นที่ที่เหลือ) + ปุ่มยืนยัน อยู่แถวเดียวกัน ตาม mockup */
.pos-modal--checkout-combined .pos-inline-confirm-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.pos-modal--checkout-combined .pos-inline-confirm-row .pos-change-row {
  flex: 1;
  margin: 0;
}
.pos-modal--checkout-combined .pos-inline-confirm-row button.btn {
  width: auto;
  flex: none;
  white-space: nowrap;
  padding: 8px 16px;
  font-size: 13px;
}
/* patch21: ปุ่มยืนยันที่ย้ายเข้า .toolbar/.pos-inline-confirm-row ไม่ผ่าน .form-actions แล้ว ต้องยก
   margin-top ที่เดิม button.btn ธรรมดาได้ (24px) ออกเองตรงนี้ ไม่งั้นชิดขอบบนเกินไป */
.pos-modal--checkout-combined #cash-confirm-btn,
.pos-modal--checkout-combined #wallet-confirm-btn {
  margin-top: 0;
}

.pos-cash-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}
.pos-cash-input-row input {
  flex: 1 1 140px;
}
.pos-quick-amounts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
button.pos-quick-amount-btn {
  width: auto;
  margin-top: 0;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--color-primary-soft);
  color: var(--color-primary-darker);
  border: none;
  box-shadow: none;
}
button.pos-quick-amount-btn:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-primary-text);
  transform: none;
  filter: none;
}

.pos-change-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 700;
  margin: 8px 0;
  padding: 8px 10px;
  background: var(--color-primary-soft);
  color: var(--color-primary-darker);
  border-radius: var(--radius-sm);
}

/* patch21: จัด 2 คอลัมน์ (QR ซ้าย, ข้อความ+ยอด+ปุ่มยืนยันขวา) ตาม mockup */
.pos-qr-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.pos-qr-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  flex: none;
}
.pos-qr-box svg {
  width: 140px;
  height: 140px;
}
.pos-qr-info {
  flex: 1 1 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pos-qr-info__title {
  font-weight: 600;
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--color-primary-darker);
  margin: 0;
}
.pos-qr-info__amount {
  font-size: 12.5px;
  color: var(--color-text);
  margin: 0 0 6px;
}
.pos-qr-info button.btn {
  width: auto;
  margin-top: 0;
  padding: 8px 16px;
  font-size: 13px;
}

/* ----- Receipt ----- */
.pos-modal--receipt {
  max-width: 340px;
}
.pos-receipt {
  font-size: 13px;
}
.pos-receipt h3 {
  margin: 0 0 4px;
  text-align: center;
  font-size: 16px;
}
.pos-receipt-sub {
  text-align: center;
  color: var(--color-muted);
  font-size: 11px;
  margin: 2px 0;
}
.pos-receipt hr {
  border: none;
  border-top: 1px dashed var(--color-border);
  margin: 10px 0;
}
.pos-receipt-item {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.pos-receipt-item--total {
  font-weight: 700;
  font-size: 15px;
}
.pos-receipt-footer {
  text-align: center;
  margin-top: 10px;
  color: var(--color-muted);
  font-size: 11px;
}
.pos-receipt-queued {
  text-align: center;
  color: var(--color-warn-text);
  background: var(--color-warn-bg);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12px;
  margin-top: 10px;
}

/* ===== patch16 (Phase 4 patch สอง): หน้าเติมเงิน & จัดการบัตรนักเรียน (topup.html) =====
   คลาสใหม่ล้วน ไม่แตะ rule เดิมด้านบนเลย — ใช้ token สี/รัศมี/ฟอนต์ชุดเดิมจาก :root ทั้งหมด */

.profile-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.profile-panel__header h3 {
  margin: 0;
  font-size: 17px;
}

.wallet-balance-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--gradient-primary);
  color: var(--color-primary-text);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 4px 0 20px;
}
.wallet-balance-box__label {
  font-size: 13px;
  opacity: 0.9;
  margin-right: auto;
}
.wallet-balance-box__amount {
  font-size: 30px;
  font-weight: 700;
  font-family: var(--font-heading);
}
.wallet-balance-box__unit {
  font-size: 13px;
  opacity: 0.9;
}

.member-search-results {
  margin-top: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
}
button.member-search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid var(--color-border-soft);
  cursor: pointer;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--color-text);
  box-shadow: none;
  margin-top: 0;
}
button.member-search-result-row:last-child {
  border-bottom: none;
}
button.member-search-result-row:hover:not(:disabled) {
  background: var(--color-primary-soft);
  transform: none;
  filter: none;
}
.member-search-result-row .msr-name {
  font-weight: 600;
}
.member-search-result-row .msr-meta {
  color: var(--color-muted);
  font-size: 12px;
}

.card-status-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-status-box__code {
  font-weight: 700;
  font-family: var(--font-heading);
  font-size: 15px;
}
.card-status-box__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button.btn-outline-danger {
  width: auto;
  margin-top: 0;
  padding: 9px 14px;
  font-size: 13px;
  background: transparent;
  color: var(--color-error-text);
  border: 1.5px solid var(--color-border);
  box-shadow: none;
}
button.btn-outline-danger:hover:not(:disabled) {
  background: var(--color-error-bg);
  border-color: var(--color-error-bg);
  transform: none;
  filter: none;
}

/* patch25 (Phase 7): หน้า import.html — การ์ดสรุปผล 3 ช่อง (แถวทั้งหมด/สำเร็จ/ผิดพลาด) */
.import-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 4px 0 20px;
}
.import-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 10px;
  border-radius: var(--radius);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}
.import-stat__value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--color-text);
}
.import-stat__label {
  font-size: 12.5px;
  color: var(--color-muted);
}
.import-stat--success {
  background: var(--color-success-bg);
  border-color: transparent;
}
.import-stat--success .import-stat__value {
  color: var(--color-success-text);
}
.import-stat--error {
  background: var(--color-error-bg);
  border-color: transparent;
}
.import-stat--error .import-stat__value {
  color: var(--color-error-text);
}
@media (max-width: 480px) {
  .import-stat__value {
    font-size: 22px;
  }
}

/* patch29 (Phase 8 patch 3): หน้า reports.html — การ์ดสรุปตัวเลข "ยอดขายภาพรวม" (จำนวนคอลัมน์
   ปรับตามพื้นที่จออัตโนมัติ ต่างจาก .import-stats ที่ล็อกไว้ 3 คอลัมน์เสมอ เพราะจำนวนการ์ดที่นี่อาจ
   เปลี่ยนได้ในอนาคต เช่น เพิ่มการ์ดกำไรขั้นต้นตอน patch30) — ใช้ token สีเดียวกับ .import-stat ทุก
   ประการเพื่อความสม่ำเสมอของดีไซน์ */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 4px 0 20px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 10px;
  border-radius: var(--radius);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}
.stat-card__value {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--color-text);
}
.stat-card__label {
  font-size: 12.5px;
  color: var(--color-muted);
}
@media (max-width: 480px) {
  .stat-card__value {
    font-size: 20px;
  }
}

/* patch29: label ครอบ input[type=date] ในตัวกรองช่วงวันที่ของ reports.html — ให้ input มีขนาด
   กะทัดรัดเหมือน input[type=text]/select อื่นๆ ใน .toolbar (เดิม .toolbar ไม่ได้ครอบ type="date"
   ไว้เลย ปล่อยเป็น default ของเบราว์เซอร์ซึ่งบางเบราว์เซอร์กว้างเกินไปจนดูไม่เข้าชุดกับปุ่ม/ช่องอื่น) */
.toolbar input[type="date"] {
  width: auto;
  padding: 9px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}
.rpt-date-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: normal;
  color: var(--color-text);
  margin: 0;
}

/* patch31/32/34 (Phase 8 เพิ่มเติม): pagination component ใช้ร่วมกันทั้ง 3 หน้าที่มีการแบ่งหน้าจริง
   ฝั่ง server (product-sales.html, order-history.html, และแถบ "สินค้า" ในหน้าจัดการสินค้า & สต็อก) —
   ตั้งใจสร้างเป็น component กลางไว้ในนี้ที่เดียว ไม่ใช่ก็อปวางซ้ำ 3 รอบในแต่ละหน้า */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.pagination__btn {
  padding: 8px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--color-text);
}
.pagination__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pagination__btn:not(:disabled):hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.pagination__info {
  font-size: 13px;
  color: var(--color-muted);
  white-space: nowrap;
}

/* พิมพ์ใบเสร็จ: ซ่อนทุกอย่างยกเว้น #receipt-content เอง จัดหน้าให้พอดีม้วนกระดาษ 80mm */
@media print {
  body * {
    visibility: hidden;
  }
  #receipt-content, #receipt-content * {
    visibility: visible;
  }
  #receipt-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 80mm;
  }
  .pos-no-print {
    display: none !important;
  }
}
