/* ============================================================
   Bai Jamjuree — โหลดจากโฟลเดอร์ตัวเอง ไม่พึ่ง Google Fonts
   (AGENTS.md ระบุว่าโปรเจกต์นี้ไม่พึ่ง dependency ภายนอก)
   เอาเฉพาะ subset ไทย/ละติน 3 น้ำหนักที่ CSS ใช้จริง 400/500/600
   unicode-range ทำให้เบราว์เซอร์ดึงเฉพาะชุดอักษรที่หน้านั้นใช้
   ============================================================ */
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-thai-400.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-thai-500.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-latin-500.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-thai-600.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Bai Jamjuree';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/bai-jamjuree-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================================
   สบายสโตร์ — design system  ·  Apple monochrome "glass" theme
   frosted glass surfaces + hairline borders + soft layered depth
   accent is pure ink black — status color is the only hue allowed
   type: SF (บนเครื่อง Apple) / Bai Jamjuree (ภาษาไทย)
   ============================================================ */

:root {
  /* โทน "ม่วง" (p) โหมดสว่าง — ค่าเริ่มต้นของทั้งระบบ
     อยู่ใน :root ตรง ๆ ไม่ใช่ [data-color] เพราะเป็นค่าตั้งต้นจริง
     หน้าจึงขึ้นเป็นม่วงตั้งแต่ก่อน JS รัน ไม่มีจังหวะสีเก่าแวบ */
  --bg: #f3f0f9;
  --ink: #1e1a26;
  --ink-soft: #4c4459;
  --ink-mute: #71697d;

  --accent: #6d3fc4;
  --accent-hover: #7d4dd4;
  --accent-press: #5c33a9;
  --accent-ring: rgba(109, 63, 196, 0.18);
  --on-accent: #ffffff;

  --green: #2f7a4f;
  --green-bg: rgba(47, 122, 79, 0.14);
  --amber: #8a5a00;
  --amber-bg: rgba(200, 140, 20, 0.16);
  --blue: #3f5aa8;
  --blue-bg: rgba(63, 90, 168, 0.12);
  --red: #b93a4a;
  --red-bg: rgba(185, 58, 74, 0.12);
  --gray-bg: rgba(70, 50, 100, 0.07);

  /* glass surfaces */
  --glass: rgba(255, 253, 255, 0.64);
  --glass-2: rgba(255, 253, 255, 0.78);
  --glass-line: rgba(255, 253, 255, 0.75);
  --hairline: rgba(50, 30, 90, 0.11);
  --blur: saturate(120%) blur(20px);

  /* card/panel surfaces — themed independently so dark themes don't render white cards */
  --surface: rgba(255, 253, 255, 0.74);
  --surface-strong: rgba(255, 253, 255, 0.82);
  --surface-soft: rgba(255, 253, 255, 0.55);
  --surface-faint: rgba(255, 253, 255, 0.45);
  --surface-input: rgba(255, 253, 255, 0.75);
  --surface-solid: #fffdff;
  --scrollbar-thumb: rgba(50, 30, 90, 0.22);
  --scrollbar-thumb-hover: rgba(50, 30, 90, 0.38);

  /* พื้นตกแต่ง — swatch หมวดหมู่, รูปสินค้าที่ยังไม่มีภาพ, avatar, แท่งกราฟ
     เข้มสุด decor-1 ไล่ไปอ่อนสุด decor-4  ทุกธีมประกาศชุดของตัวเอง */
  --decor-1: #2e1a52;
  --decor-2: #4a2a80;
  --decor-3: #6d3fc4;
  --decor-4: #a385e0;
  --on-decor: #ffffff;

  /* พื้นของ UI ที่ลอยเหนือเนื้อหา — dropdown / modal / toast / เมนูมือถือ
     เป็นกระจก: โปร่ง 80% แล้วพึ่ง backdrop-filter เบลอสิ่งที่อยู่ข้างหลัง
     ตัวเลขนี้อ่านออกได้ก็ต่อเมื่อ blur ทำงานจริง element ที่ใช้ --overlay จึง
     ต้องไม่อยู่ใต้ ancestor ที่มี backdrop-filter (ดู "ผิวกระจกของเมนูลอย") */
  --overlay: color-mix(in srgb, var(--surface-solid) 80%, transparent);

  --shimmer: rgba(255, 255, 255, 0.55);   /* แถบวิ่งบน skeleton */
  --scrim: rgba(20, 23, 28, 0.28);        /* ฉากหลัง modal / เมนูมือถือ */
  --glow: rgba(109, 63, 196, 0.07);       /* แสงจาง ๆ หลังหน้าเว็บ */
  --glow-soft: rgba(109, 63, 196, 0.045);

  --shadow-xs: 0 1px 2px rgba(20, 20, 22, 0.05);
  --shadow: 0 1px 2px rgba(20, 20, 22, 0.04), 0 8px 24px rgba(20, 20, 22, 0.07);
  --shadow-lg: 0 2px 6px rgba(20, 20, 22, 0.06), 0 24px 60px rgba(20, 20, 22, 0.16);
  --radius: 18px;
  --radius-sm: 12px;

  /* ระยะห่าง — สเกลเดียวใช้ทั้งระบบ ปุ่ม/อินพุต/การ์ด/เมนูจะได้จังหวะตรงกัน
     (เมื่อก่อนเป็นค่า rem ตายตัวกระจายทั้งไฟล์ padding แต่ละ component เลยไม่ตรงกัน) */
  --space-1: 0.25rem;
  --space-2: 0.4rem;
  --space-3: 0.62rem;
  --space-4: 0.9rem;
  --space-5: 1.2rem;
  --space-6: 1.6rem;

  --sans: -apple-system, BlinkMacSystemFont, 'Bai Jamjuree', 'Segoe UI', system-ui, sans-serif;
  --serif: var(--sans);
}

/* ============================================================
   ธีม 2 แกน — สี (data-color) x โหมดสว่าง/มืด (data-mode)
   :root ด้านบน = สีขาวดำ (e) โหมดสว่าง

   data-mode ถูกเขียนเป็นค่าจริง light/dark เสมอโดย assets/js/theme-init.js
   ตัวเลือก "ตามระบบ" ถูกแปลงเป็น light/dark ตั้งแต่ก่อนวาดหน้า CSS จึงไม่ต้อง
   มี @media prefers-color-scheme ซ้ำอีกชุด (ลดโค้ดครึ่งหนึ่ง)

   ทุกสีมีทั้งโหมดสว่างและมืด — ธีม "มืดหรู" (Midnight) เดิมคือ ฟ้า + มืด
   ============================================================ */

/* ── โหมดสว่าง ─────────────────────────────────────────────── */

/* E — ขาวดำ (iPhone Mono) — เดิมเคยเป็นค่าเริ่มต้นใน :root */
[data-color="e"] {
  --bg: #f5f5f7;
  --ink: #1d1d1f; --ink-soft: #4b4b50; --ink-mute: #707074;
  --accent: #1d1d1f; --accent-hover: #000000; --accent-press: #000000;
  --accent-ring: rgba(29, 29, 31, 0.14); --on-accent: #ffffff;
  --green: #1f7a41; --green-bg: rgba(31, 122, 65, 0.12);
  --amber: #8a5a00; --amber-bg: rgba(29, 29, 31, 0.07);
  --blue: #2b5fa8; --blue-bg: rgba(43, 95, 168, 0.1);
  --red: #c22a2a; --red-bg: rgba(194, 42, 42, 0.1);
  --gray-bg: rgba(60, 60, 67, 0.07);
  --glass: rgba(255, 255, 255, 0.64); --glass-2: rgba(255, 255, 255, 0.78); --glass-line: rgba(255, 255, 255, 0.75);
  --hairline: rgba(0, 0, 0, 0.08);
  --surface: rgba(255, 255, 255, 0.72); --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-soft: rgba(255, 255, 255, 0.5); --surface-faint: rgba(255, 255, 255, 0.45);
  --surface-input: rgba(255, 255, 255, 0.7); --surface-solid: #ffffff;
  --scrollbar-thumb: rgba(0, 0, 0, 0.2); --scrollbar-thumb-hover: rgba(0, 0, 0, 0.36);
  --decor-1: #1d1d1f; --decor-2: #4b4b50; --decor-3: #7c7c82; --decor-4: #97979d; --on-decor: #ffffff;
  --glow: rgba(0, 0, 0, 0.05); --glow-soft: rgba(0, 0, 0, 0.03);
  --radius: 18px; --radius-sm: 12px;
}

/* A — ฟ้า (Apple Blue) */
[data-color="a"] {
  --bg: #eef1f6;
  --ink: #1d1d1f; --ink-soft: #4b4b50; --ink-mute: #6c6c70;
  --accent: #0071e3; --accent-hover: #0077ed; --accent-press: #0060c8;
  --accent-ring: rgba(0, 113, 227, 0.16); --on-accent: #ffffff;
  --green: #217e38; --green-bg: rgba(52, 199, 89, 0.16);
  --amber: #956100; --amber-bg: rgba(255, 159, 10, 0.18);
  --blue: #0068c9; --blue-bg: rgba(10, 132, 255, 0.15);
  --red: #d70015; --red-bg: rgba(255, 59, 48, 0.14);
  --gray-bg: rgba(60, 60, 67, 0.08);
  --glass: rgba(255, 255, 255, 0.6); --glass-2: rgba(255, 255, 255, 0.72); --glass-line: rgba(255, 255, 255, 0.7);
  --hairline: rgba(0, 0, 0, 0.08);
  --surface: rgba(255, 255, 255, 0.72); --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-soft: rgba(255, 255, 255, 0.55); --surface-faint: rgba(255, 255, 255, 0.45);
  --surface-input: rgba(255, 255, 255, 0.7); --surface-solid: #ffffff;
  --decor-1: #0a3f76; --decor-2: #0f5fa8; --decor-3: #3c8fd8; --decor-4: #7bb8ea; --on-decor: #ffffff;
  --glow: rgba(0, 80, 180, 0.055); --glow-soft: rgba(0, 80, 180, 0.035);
  --radius: 14px; --radius-sm: 10px;
}

/* B — อบอุ่น (Warm Amber) */
[data-color="b"] {
  --bg: #f6f1e8;
  --ink: #2a2016; --ink-soft: #5c4e3c; --ink-mute: #776c5e;
  --accent: #b0621c; --accent-hover: #a35a17; --accent-press: #8b4a13;
  --accent-ring: rgba(181, 101, 29, 0.18); --on-accent: #ffffff;
  --green: #3d7938; --green-bg: rgba(63, 125, 58, 0.15);
  --amber: #92630a; --amber-bg: rgba(214, 146, 17, 0.2);
  --blue: #2f6f9e; --blue-bg: rgba(47, 111, 158, 0.12);
  --red: #b3402c; --red-bg: rgba(179, 64, 44, 0.13);
  --gray-bg: rgba(120, 90, 40, 0.08);
  --glass: rgba(255, 253, 248, 0.62); --glass-2: rgba(255, 253, 248, 0.78); --glass-line: rgba(255, 253, 248, 0.72);
  --hairline: rgba(120, 90, 40, 0.14);
  --surface: rgba(255, 253, 248, 0.72); --surface-strong: rgba(255, 253, 248, 0.78);
  --surface-soft: rgba(255, 253, 248, 0.55); --surface-faint: rgba(255, 253, 248, 0.45);
  --surface-input: rgba(255, 253, 248, 0.75); --surface-solid: #fffdf8;
  --decor-1: #4a2a0c; --decor-2: #8f4c14; --decor-3: #b5651d; --decor-4: #d59a55; --on-decor: #ffffff;
  --glow: rgba(150, 100, 30, 0.07); --glow-soft: rgba(150, 100, 30, 0.045);
  --radius: 22px; --radius-sm: 15px;
}

/* C — เขียวธรรมชาติ (Sage) */
[data-color="c"] {
  --bg: #eef3ef;
  --ink: #182420; --ink-soft: #465850; --ink-mute: #64706b;
  --accent: #2f7a5c; --accent-hover: #296b50; --accent-press: #235c44;
  --accent-ring: rgba(47, 122, 92, 0.17); --on-accent: #ffffff;
  --green: #347957; --green-bg: rgba(52, 121, 87, 0.15);
  --amber: #956100; --amber-bg: rgba(255, 159, 10, 0.18);
  --blue: #2c6b9c; --blue-bg: rgba(44, 107, 156, 0.12);
  --red: #b94545; --red-bg: rgba(185, 69, 69, 0.13);
  --gray-bg: rgba(30, 70, 50, 0.07);
  --glass: rgba(255, 255, 255, 0.6); --glass-2: rgba(255, 255, 255, 0.72); --glass-line: rgba(255, 255, 255, 0.7);
  --hairline: rgba(30, 70, 50, 0.1);
  --surface: rgba(255, 255, 255, 0.72); --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-soft: rgba(255, 255, 255, 0.55); --surface-faint: rgba(255, 255, 255, 0.45);
  --surface-input: rgba(255, 255, 255, 0.7); --surface-solid: #ffffff;
  --decor-1: #143426; --decor-2: #235c44; --decor-3: #2f7a5c; --decor-4: #6aa88d; --on-decor: #ffffff;
  --glow: rgba(30, 90, 65, 0.06); --glow-soft: rgba(30, 90, 65, 0.04);
  --radius: 16px; --radius-sm: 11px;
}

/* F — แดง (Crimson)
   ธีมเดียวที่ accent ชนกับสีสถานะ "ลบ" จึงดัน --red ไปทางเลือดหมูให้เข้มกว่า
   accent ชัด ๆ ป้าย "ยกเลิก/สินค้าหมด" จะได้ไม่กลืนไปกับปุ่มหลัก */
[data-color="f"] {
  --bg: #f7f0f1;
  --ink: #241819; --ink-soft: #55464a; --ink-mute: #75686b;
  --accent: #c0263c; --accent-hover: #ad2135; --accent-press: #941b2c;
  --accent-ring: rgba(192, 38, 60, 0.17); --on-accent: #ffffff;
  --green: #2f7a4f; --green-bg: rgba(47, 122, 79, 0.14);
  --amber: #956100; --amber-bg: rgba(255, 159, 10, 0.18);
  --blue: #2f5f9e; --blue-bg: rgba(47, 95, 158, 0.11);
  --red: #8f1d24; --red-bg: rgba(143, 29, 36, 0.13);
  --gray-bg: rgba(70, 30, 40, 0.07);
  --glass: rgba(255, 252, 252, 0.62); --glass-2: rgba(255, 252, 252, 0.76); --glass-line: rgba(255, 252, 252, 0.72);
  --hairline: rgba(90, 30, 40, 0.11);
  --surface: rgba(255, 252, 252, 0.72); --surface-strong: rgba(255, 252, 252, 0.8);
  --surface-soft: rgba(255, 252, 252, 0.55); --surface-faint: rgba(255, 252, 252, 0.45);
  --surface-input: rgba(255, 252, 252, 0.75); --surface-solid: #fffcfc;
  --decor-1: #5c0f1c; --decor-2: #8f1826; --decor-3: #c0263c; --decor-4: #dd7080; --on-decor: #ffffff;
  --glow: rgba(170, 30, 55, 0.06); --glow-soft: rgba(170, 30, 55, 0.04);
  --radius: 20px; --radius-sm: 13px;
}

/* ── โหมดมืด ────────────────────────────────────────────────
   บล็อกนี้คุมพื้นผิว/ตัวหนังสือ/สีสถานะ ที่ใช้ร่วมกันทุกสี และเป็นชุดสีของ
   "ขาวดำ" (e) ไปในตัว  แต่ละสีด้านล่างค่อย override เฉพาะที่ต่างจริง

   พื้นผิวทั้งหมดคิดจาก --surface-solid ด้วย color-mix จึงรับ tint ของแต่ละสี
   เองอัตโนมัติ ไม่ต้องไล่ประกาศ rgba ซ้ำทีละธีม
   ------------------------------------------------------------ */
[data-mode="dark"] {
  --bg: #121017;
  --ink: #f1ecfa; --ink-soft: #c6bcd8; --ink-mute: #968aa8;

  --accent: #a98bff; --accent-hover: #b99cff; --accent-press: #9576ec;
  --accent-ring: rgba(169, 139, 255, 0.24); --on-accent: #150f22;

  --green: #5fd382; --green-bg: rgba(52, 199, 89, 0.18);
  --amber: #f5b942; --amber-bg: rgba(255, 159, 10, 0.18);
  --blue: #9db8ff; --blue-bg: rgba(157, 184, 255, 0.15);
  --red: #ff6b7d; --red-bg: rgba(255, 107, 125, 0.16);
  --gray-bg: rgba(255, 255, 255, 0.06);

  --surface-solid: #1e1a29;
  --glass: color-mix(in srgb, var(--surface-solid) 72%, transparent);
  --glass-2: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  --glass-line: rgba(255, 255, 255, 0.09);
  --hairline: rgba(255, 255, 255, 0.09);
  --surface: color-mix(in srgb, var(--surface-solid) 76%, transparent);
  --surface-strong: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  --surface-soft: rgba(255, 255, 255, 0.05);
  --surface-faint: rgba(255, 255, 255, 0.035);
  --surface-input: rgba(255, 255, 255, 0.06);
  --scrollbar-thumb: rgba(255, 255, 255, 0.18);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);

  --decor-1: #241d38; --decor-2: #362a55; --decor-3: #4d3b7a; --decor-4: #6f57ad;
  --on-decor: #f0eaff;

  --shimmer: rgba(255, 255, 255, 0.08);
  --scrim: rgba(0, 0, 0, 0.55);
  --glow: rgba(169, 139, 255, 0.08);
  --glow-soft: rgba(255, 255, 255, 0.03);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.35), 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* E มืด — ขาวดำ */
[data-mode="dark"][data-color="e"] {
  --bg: #0f0f11;
  --ink: #f2f2f5; --ink-soft: #c4c4ca; --ink-mute: #8a8a92;
  --accent: #f5f5f7; --accent-hover: #ffffff; --accent-press: #e3e3e8;
  --accent-ring: rgba(245, 245, 247, 0.2); --on-accent: #17171a;
  --blue: #7fb2ff; --blue-bg: rgba(127, 178, 255, 0.14);
  --red: #ff6b60; --red-bg: rgba(255, 69, 58, 0.16);
  --surface-solid: #1b1b1e;
  --decor-1: #232327; --decor-2: #303036; --decor-3: #45454e; --decor-4: #63636e;
  --on-decor: #f2f2f5;
  --glow: rgba(255, 255, 255, 0.05); --glow-soft: rgba(255, 255, 255, 0.03);
}

/* A มืด — คือธีม "มืดหรู" (Midnight) เดิม */
[data-mode="dark"][data-color="a"] {
  --bg: #101114;
  --ink: #f0f1f4; --ink-soft: #c2c5cc; --ink-mute: #8b8f98;
  --accent: #5aa9ff; --accent-hover: #78b8ff; --accent-press: #3d92f2;
  --accent-ring: rgba(90, 169, 255, 0.22); --on-accent: #0f1115;
  --blue: #8fc7ff; --blue-bg: rgba(143, 199, 255, 0.16);
  --surface-solid: #1c1f26;
  --decor-1: #1a2130; --decor-2: #26314a; --decor-3: #35456a; --decor-4: #4b6493;
  --on-decor: #eaf1fb;
  --glow: rgba(90, 169, 255, 0.07); --glow-soft: rgba(255, 255, 255, 0.03);
}

/* B มืด — อบอุ่น */
[data-mode="dark"][data-color="b"] {
  --bg: #14100b;
  --ink: #f5efe6; --ink-soft: #d0c3b1; --ink-mute: #998b78;
  --accent: #e09a4e; --accent-hover: #eba95f; --accent-press: #c9883f;
  --accent-ring: rgba(224, 154, 78, 0.22); --on-accent: #1a1208;
  --blue: #7cb0e8; --blue-bg: rgba(124, 176, 232, 0.15);
  --surface-solid: #221b13;
  --glass-line: rgba(255, 226, 189, 0.1);
  --hairline: rgba(255, 226, 189, 0.1);
  --decor-1: #2c1d0e; --decor-2: #4a2f14; --decor-3: #7a4e1e; --decor-4: #b0763a;
  --on-decor: #fdf3e6;
  --glow: rgba(224, 154, 78, 0.07); --glow-soft: rgba(255, 226, 189, 0.03);
}

/* C มืด — เขียวธรรมชาติ */
[data-mode="dark"][data-color="c"] {
  --bg: #0c1310;
  --ink: #eaf2ed; --ink-soft: #b7c8bf; --ink-mute: #7f9289;
  --accent: #52bb8d; --accent-hover: #66c99b; --accent-press: #45a67a;
  --accent-ring: rgba(82, 187, 141, 0.22); --on-accent: #08140e;
  --green: #6ed49b; --green-bg: rgba(110, 212, 155, 0.16);
  --blue: #6fa8dc; --blue-bg: rgba(111, 168, 220, 0.15);
  --surface-solid: #16201b;
  --glass-line: rgba(190, 240, 215, 0.1);
  --hairline: rgba(190, 240, 215, 0.1);
  --decor-1: #10281d; --decor-2: #1b4331; --decor-3: #2a6a4c; --decor-4: #4a9b74;
  --on-decor: #eafaf1;
  --glow: rgba(82, 187, 141, 0.06); --glow-soft: rgba(190, 240, 215, 0.03);
}

/* F มืด — แดง */
[data-mode="dark"][data-color="f"] {
  --bg: #150a0c;
  --ink: #f7eaec; --ink-soft: #d4bec2; --ink-mute: #9d858a;
  --accent: #ff6b7d; --accent-hover: #ff8291; --accent-press: #e8556a;
  --accent-ring: rgba(255, 107, 125, 0.22); --on-accent: #1a0509;
  --blue: #7fb2ff; --blue-bg: rgba(127, 178, 255, 0.14);
  --red: #ff9270; --red-bg: rgba(255, 146, 112, 0.16);
  --surface-solid: #231317;
  --glass-line: rgba(255, 205, 212, 0.1);
  --hairline: rgba(255, 205, 212, 0.1);
  --decor-1: #2e1015; --decor-2: #4d1a22; --decor-3: #7d2836; --decor-4: #b04a5c;
  --on-decor: #ffeef1;
  --glow: rgba(255, 107, 125, 0.07); --glow-soft: rgba(255, 205, 212, 0.03);
}

/* สลับธีมแบบค่อย ๆ จางเข้าหากัน — transition ใส่ที่ตัวแปร CSS ไม่ได้
   จึงให้ View Transitions จับภาพก่อน/หลังมา crossfade ทั้งหน้าแทน
   (assets/js/app.js เรียก startViewTransition ให้ เบราว์เซอร์ที่ไม่รองรับก็แค่สลับทันทีเหมือนเดิม) */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.34s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

/* แถบเลื่อน (scrollbar) แบบเล็ก minimal — แทนของ browser ทั้งหน้าและกล่องที่เลื่อนได้ */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

body {
  font-family: var(--sans);
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  font-size: 15px;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
/* แสงจาง ๆ ให้ผิวกระจกมีมิติ — สีมาจาก --glow ของแต่ละธีม (ธีมมืดใช้แสงสว่างแทนเงา) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42rem 42rem at 12% 4%, var(--glow), transparent 60%),
    radial-gradient(38rem 38rem at 92% 8%, var(--glow-soft), transparent 60%),
    radial-gradient(44rem 44rem at 76% 96%, var(--glow), transparent 62%),
    radial-gradient(36rem 36rem at 14% 98%, var(--glow-soft), transparent 60%);
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

p { max-width: 66ch; }
a { color: inherit; }
img, svg { max-width: 100%; display: block; }
code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 0.85em; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ── utilities ─────────────────────────────────────────────── */

.container { max-width: 1160px; margin-inline: auto; padding-inline: clamp(1.25rem, 5vw, 3rem); }

.eyebrow {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 0.65rem 1.35rem;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease,
              transform 0.12s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, a:focus-visible, button:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 6px 16px color-mix(in srgb, var(--accent) 24%, transparent);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18), 0 8px 20px color-mix(in srgb, var(--accent) 32%, transparent); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.97) translateY(0); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15); }
.btn-ghost { border-color: var(--hairline); color: var(--ink); background: var(--surface-soft); }
.btn-ghost:hover { border-color: rgba(127, 127, 127, 0.35); background: var(--surface-strong); }
.btn-soft { background: var(--surface-input); border-color: var(--hairline); color: var(--ink); box-shadow: var(--shadow-xs); }
.btn-soft:hover { background: var(--surface-solid); border-color: rgba(127, 127, 127, 0.3); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: var(--red); color: var(--on-accent); }
.btn-sm { padding: var(--space-2) var(--space-4); font-size: 0.82rem; border-radius: 10px; }
.btn-block { width: 100%; }
/* ปุ่มเฉพาะไอคอน (เช่น แก้ไข/ลบในตาราง) — สี่เหลี่ยมจัตุรัส ไอคอนกลาง */
.btn-icon { padding: var(--space-3); }
.btn-icon.btn-sm { padding: var(--space-2); }
.btn-icon .icon-svg { display: block; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 1em; height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--on-accent);
  animation: spin 0.7s linear infinite;
}
.btn-ghost.is-loading::after, .btn-soft.is-loading::after, .btn-danger.is-loading::after { color: var(--ink); }

.link-btn { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; }

/* ── badges ────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.22rem 0.68rem 0.22rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
/* บวก / เสร็จสิ้น — ตัวหนังสือเข้มสุด อ่านง่ายที่สุดในกลุ่ม */
.badge-active, .badge-done, .badge-paid { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink); }
/* รอดำเนินการ — น้ำหนักอ่อนกว่า ให้รู้สึกว่ายังไม่นิ่ง */
.badge-pending, .badge-draft { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink-soft); }
.badge-shipped { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink-soft); }
/* สถานะเชิงลบ (ยกเลิก / สินค้าหมด / หยุด / ไม่พร้อม) → จุดสีแดงเพียงจุดเดียวในทั้งระบบ ไว้ให้สายตาสะดุด */
.badge-out, .badge-cancelled, .badge-paused, .badge-inactive, .badge-failed, .badge-rejected { background: var(--red-bg); color: var(--red); }
/* สถานะกลาง ๆ ที่ยังคงเป็นสีเทา */
.badge-neutral { background: var(--gray-bg); color: var(--ink-mute); }
.badge-neutral::before { display: none; }

/* ── spinner ───────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--ink) 14%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner-box { display: grid; place-items: center; gap: 0.8rem; padding: 2.2rem 1rem; color: var(--ink-mute); }
.spinner-text { font-size: 0.85rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── loader overlay (opt-in) ───────────────────────────────── */

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: grid;
  place-items: center;
  background: var(--glass-2);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.loader-overlay.is-active { opacity: 1; visibility: visible; }

/* ============================================================
   Toast
   ============================================================ */

.toast-stack {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(92vw, 360px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.8rem 0.95rem;
  border-radius: 14px;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(120%) scale(0.96);
  transition: opacity 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.is-shown { opacity: 1; transform: translateX(0) scale(1); }
.toast.is-leaving { opacity: 0; transform: translateX(120%) scale(0.96); }
.toast-icon {
  flex-shrink: 0;
  display: flex;
  margin-top: 0.05rem;
  color: var(--green);
}
.toast-error .toast-icon { color: var(--red); }
.toast-info .toast-icon { color: var(--accent); }
.toast-msg { flex: 1; font-size: 0.88rem; line-height: 1.5; color: var(--ink); max-width: none; }
.toast-close {
  all: unset;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--ink-mute);
  padding: 0 0.15rem;
  transition: color 0.2s ease;
}
.toast-close:hover { color: var(--ink); }

/* ============================================================
   Modal
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  padding: 1.4rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.modal-dialog {
  position: relative;
  width: min(100%, 540px);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-line);
  border-radius: 20px;
  padding: 1.7rem clamp(1.3rem, 4vw, 1.9rem);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-dialog.modal-wide { width: min(100%, 660px); }
.modal.is-open .modal-backdrop { opacity: 1; }
.modal.is-open .modal-dialog { opacity: 1; transform: none; }
.modal-close {
  all: unset;
  position: absolute;
  top: 0.9rem; right: 1rem;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-mute);
  transition: color 0.2s ease, transform 0.2s ease;
}
.modal-close:hover { color: var(--ink); transform: rotate(90deg); }
.modal-close .icon-svg, .toast-close .icon-svg, .sh-del .icon-svg, .chip-remove .icon-svg { display: block; }
.modal-dialog h2 { font-size: 1.25rem; margin-bottom: 0.3rem; }
.modal-dialog .modal-sub { color: var(--ink-mute); font-size: 0.88rem; margin-bottom: 1.3rem; }
.modal-foot { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1.4rem; flex-wrap: wrap; }
.confirm-icon {
  width: 2.7rem; height: 2.7rem;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--red-bg);
  color: var(--red);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
}

/* ============================================================
   Alert (inline)
   ============================================================ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: var(--surface-soft);
  font-size: 0.88rem;
}
.alert p { max-width: none; }
.alert-icon {
  flex-shrink: 0;
  display: flex;
  margin-top: 0.05rem;
}
.alert-success { background: var(--green-bg); border-color: transparent; }
.alert-success .alert-icon { color: var(--green); }
.alert-error { background: var(--red-bg); border-color: transparent; }
.alert-error .alert-icon { color: var(--red); }
.alert-info { background: var(--blue-bg); border-color: transparent; }
.alert-info .alert-icon { color: var(--accent); }

/* ── form validation (แจ้งฟิลด์ที่ยังไม่กรอก/ไม่ถูกต้อง เป็นข้อความสีแดง
   ใต้ช่อง แทน bubble ค่าเริ่มต้นของ browser) ─────────────────── */
.field-error {
  display: block;
  flex-basis: 100%;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--red);
}

/* ============================================================
   หน้าร้านสาธารณะ (storefront)
   ============================================================ */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  transition: background-color 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease;
  border-bottom: 1px solid transparent;
}
.site-header.is-scrolled {
  background: var(--glass);
  backdrop-filter: var(--blur);
  border-bottom-color: var(--hairline);
}

/* ── ผิวกระจกของเมนูลอย ──────────────────────────────────────
   แถบหัวที่มี backdrop-filter กลายเป็น backdrop root ทำให้เมนูที่เป็นลูกของมัน
   เบลอได้แค่พื้นหลังของแถบหัวเอง ไม่ใช่เนื้อหาหน้าเว็บที่อยู่ข้างหลังจริง ๆ
   ผลคือแผงดูใสแต่ตัวหนังสือด้านหลังทะลุขึ้นมาคมชัดจนอ่านชนกัน

   ระหว่างที่มีเมนูกางอยู่จึงยกภาระ blur จากแถบหัวไปให้แผงแทน แถบหัวสลับไปใช้
   พื้นกระจกที่ทึบขึ้นหนึ่งขั้น สายตาแทบไม่เห็นความต่างเพราะแผงบังอยู่แล้ว
   (.cselect-menu กับ .search-hist ไม่ต้องพึ่งท่านี้ เพราะ JS ย้ายไปแขวนที่ body
   ตั้งแต่แรก จึงอยู่นอก backdrop root อยู่แล้ว) */
.site-header.is-scrolled:has(.dropdown.is-open),
.site-header.nav-open,
.app-topbar:has(.dropdown.is-open) {
  backdrop-filter: none;
  background: var(--glass-2);
}

/* เบราว์เซอร์ที่ไม่รู้จัก :has() ยกภาระ blur ไม่ได้ เมนูจะโปร่งแบบไม่มีอะไรเบลอ
   ให้กลับไปใช้พื้นทึบแทน เสียผิวกระจกแต่ยังอ่านออก */
@supports not selector(:has(*)) {
  :root { --overlay: var(--surface-solid); }
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 4.2rem; }
.brand {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.02em;
}
.brand small {
  display: block;
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.site-nav { display: flex; align-items: center; gap: clamp(1rem, 3vw, 1.9rem); }
.site-nav a { font-size: 0.88rem; text-decoration: none; color: var(--ink-soft); transition: color 0.2s ease; }
.site-nav a:hover { color: var(--accent); }
.site-nav .nav-login {
  color: var(--on-accent); background: var(--accent);
  padding: 0.42rem 1rem; border-radius: 999px;
}
.site-nav .nav-login:hover { color: var(--on-accent); background: var(--accent-hover); }
.site-nav .nav-links { display: contents; }
.cart-pill { position: relative; display: inline-flex; align-items: center; gap: 0.35rem; }
.cart-count {
  min-width: 1.25rem; height: 1.25rem;
  padding: 0 0.32rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.7rem;
  display: grid; place-items: center;
}
.cart-count.is-empty { background: var(--ink-mute); color: var(--bg); }
.cart-pill {
  all: unset;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  border-radius: 999px;
  color: var(--ink-soft);
  transition: color 0.2s ease;
}
.cart-pill:hover { color: var(--ink); }

/* แผงตะกร้า */
.cart-panel { min-width: 264px; max-width: 300px; }
.cart-list { display: grid; gap: var(--space-1); max-height: 15rem; overflow-y: auto; }
.cart-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: 9px;
  font-size: 0.86rem;
}
.cart-row:hover { background: var(--surface-soft); }
.cart-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-row-name small { display: block; font-size: 0.74rem; color: var(--ink-mute); }
.cart-row-sum { font-variant-numeric: tabular-nums; font-weight: 500; }
.cart-row-del {
  all: unset;
  cursor: pointer;
  width: 1.3rem; height: 1.3rem;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--ink-mute);
  transition: color 0.15s ease, background-color 0.15s ease;
}
.cart-row-del:hover { color: var(--red); background: var(--red-bg); }
.cart-empty { padding: var(--space-3) var(--space-4) var(--space-4); font-size: 0.85rem; color: var(--ink-mute); }
.cart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-1);
  border-top: 1px solid var(--hairline);
  font-size: 0.86rem;
  color: var(--ink-soft);
}
.cart-foot strong { font-size: 1rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.cart-foot[hidden] { display: none; }
.nav-toggle { display: none; }

@media (max-width: 760px) {
  /* จอเล็ก: ลิงก์ย้ายลงไปอยู่ในแผ่นเมนูที่กางจากปุ่มขีดสามขีด */
  .nav-toggle {
    all: unset;
    display: grid;
    gap: 4px;
    cursor: pointer;
    padding: var(--space-3);
    border-radius: 10px;
  }
  .nav-toggle span {
    width: 18px; height: 1.5px;
    background: var(--ink);
    border-radius: 2px;
    transition: transform 0.25s ease, opacity 0.2s ease;
  }
  .site-header.nav-open .nav-toggle span:first-child { transform: translateY(5.5px) rotate(45deg); }
  .site-header.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
  .site-header.nav-open .nav-toggle span:last-child { transform: translateY(-5.5px) rotate(-45deg); }

  .site-nav .nav-links {
    position: absolute;
    top: 100%; left: 0; right: 0;
    display: grid;
    gap: var(--space-1);
    padding: var(--space-3) clamp(1.25rem, 5vw, 3rem) var(--space-5);
    background: var(--overlay);
    backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--hairline);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
  }
  .site-header.nav-open .site-nav .nav-links {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
  }
  .site-nav .nav-links a {
    padding: var(--space-3) var(--space-2);
    font-size: 0.95rem;
    border-radius: 9px;
  }
}

/* ── hero ──────────────────────────────────────────────────── */

.hero {
  min-height: 90svh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  text-align: center;
}
/* แสงสองก้อนหลังหัวเรื่อง ให้ hero ไม่ใช่ตัวหนังสือลอยกลางที่ว่าง
   สีมาจาก --decor-* จึงเปลี่ยนตามธีมไปด้วย */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(30rem 22rem at 78% 16%, color-mix(in srgb, var(--decor-3) 24%, transparent), transparent 68%),
    radial-gradient(26rem 20rem at 16% 80%, color-mix(in srgb, var(--decor-2) 20%, transparent), transparent 68%);
}
.hero-inner { position: relative; padding: 8rem 1.5rem 4rem; max-width: 780px; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); font-weight: 600; letter-spacing: -0.03em; }
.hero .hero-sub { margin: 1.2rem auto 2rem; color: var(--ink-soft); font-size: clamp(1rem, 2vw, 1.15rem); font-weight: 400; }
.hero .hero-cta { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }
.hero-badges { display: flex; gap: 1.4rem; justify-content: center; flex-wrap: wrap; margin-top: 2.6rem; font-size: 0.85rem; color: var(--ink-mute); }
.hero-badges span { display: inline-flex; align-items: center; gap: 0.4rem; }
.hero-badges b { color: var(--ink); font-weight: 600; }

/* ── sections ──────────────────────────────────────────────── */

.section { padding: clamp(4rem, 10vh, 6.5rem) 0; }
.section-head { max-width: 640px; margin-bottom: clamp(2rem, 5vh, 3rem); }
.section-head.center { margin-inline: auto; text-align: center; }
.section-head h2 { font-size: clamp(1.7rem, 3.6vw, 2.4rem); font-weight: 600; }
.section-head p { color: var(--ink-soft); margin-top: 0.7rem; }
.section-alt { position: relative; }
.section-alt::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: var(--surface-faint);
  border-block: 1px solid var(--hairline);
}

.reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.is-visible { opacity: 1; transform: none; }

/* ── card (glass) ──────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.card > h2 { font-size: 1.05rem; margin-bottom: 0.9rem; }
.card-narrow { max-width: 520px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-head h2 { font-size: 1.05rem; }

/* ── categories ────────────────────────────────────────────── */

.category-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1.1rem; }
.category {
  padding: 1.7rem 1.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--glass-line);
  background: var(--surface-input);
  box-shadow: var(--shadow);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.category:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.category .swatch { width: 40px; height: 40px; border-radius: 12px; margin-bottom: 1rem; box-shadow: var(--shadow-xs); }
.tone-sage .swatch { background: linear-gradient(140deg, var(--decor-2), var(--decor-1)); }
.tone-terracotta .swatch { background: linear-gradient(140deg, var(--decor-3), var(--decor-2)); }
.tone-dusk .swatch { background: linear-gradient(140deg, var(--decor-4), var(--decor-3)); }
.tone-sand .swatch { background: linear-gradient(140deg, var(--decor-3), var(--decor-1)); }
.category h3 { font-size: 1.12rem; }
.category p { font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.4rem; }

/* ── product grid & card ───────────────────────────────────── */

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1.3rem; }
.product-card {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--glass-line);
  background: var(--surface-strong);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.product-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }
.product-photo {
  aspect-ratio: 4 / 3;
  position: relative;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--on-decor);
}
.product-photo .product-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.product-photo.ph-0 { background: linear-gradient(150deg, var(--decor-2), var(--decor-1)); }
.product-photo.ph-1 { background: linear-gradient(150deg, var(--decor-3), var(--decor-2)); }
.product-photo.ph-2 { background: linear-gradient(150deg, var(--decor-4), var(--decor-3)); }
.product-photo.ph-3 { background: linear-gradient(150deg, var(--decor-3), var(--decor-1)); }
.product-tag {
  position: absolute;
  top: 0.6rem; left: 0.6rem;
  font-size: 0.68rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: var(--glass-2);
  backdrop-filter: var(--blur);
  color: var(--ink-soft);
}
.product-body { padding: 1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.product-body h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; }
.product-cat { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-mute); }
.product-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 0.8rem; }
.product-price { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.add-cart {
  all: unset;
  cursor: pointer;
  width: 2.1rem; height: 2.1rem;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.1rem;
  transition: background-color 0.2s ease, transform 0.15s ease;
}
.add-cart:hover { background: var(--accent-hover); transform: scale(1.08); }

/* ── newsletter ────────────────────────────────────────────── */

.subscribe-panel {
  max-width: 640px;
  margin-inline: auto;
  text-align: center;
  padding: clamp(2.2rem, 5vw, 3.2rem);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow);
}
.subscribe-panel h2 { font-size: clamp(1.6rem, 3.6vw, 2.1rem); font-weight: 600; }
.subscribe-panel > p { margin: 0.8rem auto 1.6rem; color: var(--ink-soft); }
.subscribe-form { display: flex; gap: 0.6rem; max-width: 440px; margin-inline: auto; flex-wrap: wrap; }
.subscribe-form input { flex: 1; min-width: 200px; }

/* ── inputs ────────────────────────────────────────────────── */

input, textarea, select {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--ink);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-input);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
textarea { resize: vertical; min-height: 5rem; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
label { font-size: 0.82rem; color: var(--ink-soft); display: block; margin-bottom: 0.3rem; }

/* ── invalid / disabled — สถานะที่ JS ผูกไว้แล้ว (validation.js, Modal ฯลฯ)
   แต่ก่อนหน้านี้ไม่มี CSS รองรับเลย ฟอร์ม error จึงมีแค่ข้อความไม่มีเส้นแดง ── */
input:disabled, textarea:disabled, select:disabled,
input[readonly], textarea[readonly] {
  cursor: not-allowed;
  opacity: 0.55;
  background: var(--surface-faint);
}
input.is-invalid, textarea.is-invalid, select.is-invalid,
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"],
.cselect.is-invalid .cselect-trigger {
  border-color: var(--red);
}
input.is-invalid:focus, textarea.is-invalid:focus, select.is-invalid:focus,
input[aria-invalid="true"]:focus, textarea[aria-invalid="true"]:focus, select[aria-invalid="true"]:focus,
.cselect.is-invalid .cselect-trigger:focus-visible {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-bg);
}
.field-error { display: flex; align-items: center; gap: 0.3rem; }
.field-error::before { content: ''; width: 4px; height: 4px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none !important;
  box-shadow: none !important;
}

/* select: ซ่อนลูกศร native แล้ววาดลูกศร (chevron) ของเราเองให้เข้าธีม */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.3rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%2386868b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 12px 8px;
  cursor: pointer;
}
select:hover { border-color: rgba(127, 127, 127, 0.35); }
select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%231d1d1f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
select option { color: var(--ink); background: var(--surface-solid); }
/* โหมดมืด: ลูกศรของ native select เป็นรูปฝังใน url() ใส่ var() ไม่ได้ จึงต้องสลับรูปเอง
   (โดยเฉพาะตอนโฟกัส ที่เดิมเป็นเส้นเกือบดำ มองไม่เห็นบนพื้นมืด) */
[data-mode="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%238b8f98' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
[data-mode="dark"] select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%23f0f1f4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ── custom select (แทน dropdown ค่าเริ่มต้นของ browser ด้วย UI ของเราเอง)
   <select> จริงถูกซ่อนไว้ (.cselect-native) แต่ยังส่งฟอร์มได้ / ถ้าปิด JS ก็ยัง
   ใช้ตัว native ที่จัดสไตล์ไว้ด้านบนแทน  เมนูถูกย้ายไปไว้ที่ body (portal) แล้ว
   วางตำแหน่งแบบ fixed จึงไม่โดน overflow ของตาราง/modal หรือ backdrop-filter ตัด */
.cselect { position: relative; width: 100%; }
.status-form .cselect, .pagination .per-page .cselect { width: auto; }
.cselect-native { display: none !important; }

.cselect-trigger {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-input);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.cselect-trigger:hover { border-color: rgba(127, 127, 127, 0.3); }
.cselect-trigger:focus-visible,
.cselect.is-open .cselect-trigger {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.cselect-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-caret {
  flex-shrink: 0;
  width: 12px;
  height: 8px;
  background: currentColor;
  color: var(--ink-mute);
  -webkit-mask: center / 12px 8px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask: center / 12px 8px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  transition: transform 0.2s ease;
}
.cselect.is-open .cselect-caret { transform: rotate(180deg); }

/* เวอร์ชันเล็กสำหรับที่แคบ ๆ (แถวตาราง / ตัวเลือกต่อหน้า) */
.status-form .cselect-trigger,
.pagination .per-page .cselect-trigger { padding: 0.34rem 0.6rem; font-size: 0.8rem; }

.cselect-menu {
  position: fixed;
  z-index: 250;
  max-height: 15rem;
  max-width: calc(100vw - 16px);
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0.32rem;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}
.cselect-menu.is-shown { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
.cselect-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: var(--space-3) var(--space-4);
  border-radius: 9px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.cselect-option.is-active { background: var(--surface-soft); color: var(--ink); }
.cselect-option[aria-selected="true"] { color: var(--accent); font-weight: 500; }
.cselect-option[aria-selected="true"]::after { content: '✓'; font-size: 0.78rem; }

/* ── file drop zone (ลากรูปมาวาง / คลิกเลือกไฟล์) ─────────────── */
.filedrop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1.5px dashed var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-faint);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.filedrop:hover { border-color: rgba(127, 127, 127, 0.35); background: var(--surface-soft); }
.filedrop:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.filedrop.is-dragover {
  border-color: var(--accent);
  border-style: solid;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
/* ซ่อน input จริง แต่ยังโฟกัสด้วยคีย์บอร์ดได้ */
.filedrop input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.filedrop .thumb { width: 56px; height: 56px; }
.filedrop-text { font-size: 0.86rem; color: var(--ink-soft); line-height: 1.45; min-width: 0; }
.filedrop-text strong { color: var(--ink); font-weight: 500; }
.filedrop-browse { color: var(--accent); font-weight: 500; }
.filedrop:hover .filedrop-browse { text-decoration: underline; text-underline-offset: 2px; }
.filedrop-text small { display: block; color: var(--ink-mute); font-size: 0.76rem; margin-top: 0.15rem; }
.filedrop-text .filedrop-name {
  display: block;
  margin-top: 0.15rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── footer ────────────────────────────────────────────────── */

.site-footer {
  padding: 3rem 0 2.6rem;
  border-top: 1px solid var(--hairline);
  text-align: center;
  font-size: 0.83rem;
  color: var(--ink-mute);
}
.site-footer .brand { font-size: 1.05rem; }
.site-footer p { margin: 0.7rem auto 0; }

/* ============================================================
   หลังร้าน (dashboard)
   ============================================================ */

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

.app-sidebar {
  width: 244px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.4rem 0.9rem;
  background: var(--glass);
  backdrop-filter: var(--blur);
  border-right: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  height: 100svh;
}
.app-sidebar .brand { padding: 0 0.8rem 1.2rem; }
.sidebar-close { display: none; }
.app-nav { display: grid; gap: 0.12rem; overflow-y: auto; }
.app-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: var(--space-3) var(--space-4);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--ink-soft);
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.app-nav a:hover { background: var(--surface-soft); color: var(--ink); }
.app-nav a.is-active { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent); }
.app-nav a.is-active .nav-glyph { opacity: 1; }
.app-nav .nav-glyph {
  width: 17px; height: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.6;
  flex-shrink: 0;
}
.app-nav .nav-glyph .icon-svg { display: block; }
.app-nav .nav-section {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-mute);
  padding: 1rem 0.8rem 0.35rem;
}
.app-sidebar .sidebar-foot { margin-top: auto; padding-top: 1.2rem; }
.logout-form button {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 9px;
  font-size: 0.88rem;
  color: var(--red);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.logout-form button:hover { background: var(--red-bg); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1.2rem, 4vw, 2.4rem);
  border-bottom: 1px solid var(--hairline);
  background: var(--glass);
  backdrop-filter: var(--blur);
  position: sticky;
  top: 0;
  z-index: 40;
}
.app-topbar h1 { font-size: 1.25rem; font-weight: 600; }
.app-topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.user-menu { position: relative; }
.app-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.28rem 0.35rem 0.28rem 0.7rem;
  border-radius: 999px;
  transition: background-color 0.2s ease;
}
.app-user:hover { background: var(--surface-soft); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.95rem;
  font-weight: 600;
  flex-shrink: 0;
}
.avatar-lg { width: 42px; height: 42px; font-size: 1.15rem; }

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 244px;
  background: var(--surface-solid);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}
.user-menu.is-open .user-dropdown { opacity: 1; visibility: visible; transform: none; }
.user-dropdown-head {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--hairline);
}
.user-meta { display: grid; gap: 0.05rem; min-width: 0; }
.user-meta strong { font-size: 0.9rem; }
.user-meta span { font-size: 0.74rem; color: var(--ink-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-dropdown-list { display: grid; padding: 0.4rem; gap: 0.08rem; }
.user-dropdown-list a {
  padding: 0.55rem 0.7rem;
  border-radius: 9px;
  font-size: 0.88rem;
  text-decoration: none;
  color: var(--ink-soft);
  transition: background-color 0.2s ease, color 0.2s ease;
}
.user-dropdown-list a:hover { background: var(--surface-soft); color: var(--ink); }
.user-dropdown-foot { padding: 0.4rem; border-top: 1px solid var(--hairline); }
@media (max-width: 520px) { .app-user .user-name { display: none; } }
.app-content { padding: clamp(1.3rem, 3.5vw, 2.2rem); display: grid; gap: 1.3rem; align-content: start; }

.menu-toggle { display: none; }
@media (max-width: 860px) {
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-lg);
  }
  .app-shell.nav-open .app-sidebar { transform: none; }
  .menu-toggle { all: unset; display: grid; gap: 4px; cursor: pointer; padding: 0.5rem; border-radius: 10px; }
  .menu-toggle span {
    width: 20px; height: 1.5px;
    background: var(--ink);
    border-radius: 2px;
    transition: transform 0.25s ease, opacity 0.2s ease;
  }
  /* ปุ่มปิดในตัว drawer เอง — ปุ่มขีดสามขีดอยู่ใน topbar ซึ่งถูก drawer ทับตอนเปิด
     จะบิดเป็นกากบาทแบบเมนูหน้าร้านไม่ได้เพราะไม่มีใครเห็น */
  .sidebar-close {
    all: unset;
    position: absolute;
    top: 1rem; right: 0.9rem;
    display: grid;
    place-items: center;
    width: 2rem; height: 2rem;
    border-radius: 9px;
    color: var(--ink-mute);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .sidebar-close:hover { background: var(--surface-soft); color: var(--ink); }
  .app-backdrop {
    position: fixed; inset: 0; z-index: 65;
    background: var(--scrim);
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .app-shell.nav-open .app-backdrop { opacity: 1; pointer-events: auto; }
}

/* ── stats ─────────────────────────────────────────────────── */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1.1rem; }
.stat { position: relative; overflow: hidden; }
.stat .stat-label { font-size: 0.78rem; color: var(--ink-mute); }
.stat .stat-value { font-size: 1.9rem; font-weight: 600; line-height: 1.25; margin: 0.25rem 0 0.1rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat .stat-hint { font-size: 0.8rem; color: var(--green); }
.stat .stat-mark { position: absolute; top: 1.1rem; right: 1.2rem; width: 9px; height: 9px; border-radius: 50%; }
.stat.tone-sage .stat-mark { background: var(--accent); }
.stat.tone-terracotta .stat-mark { background: var(--decor-2); }
.stat.tone-dusk .stat-mark { background: var(--decor-4); }
.stat.tone-sand .stat-mark { background: var(--decor-3); }

/* ── tables ────────────────────────────────────────────────── */

/* เงาจาง ๆ ริมขอบบอกว่าตารางยังเลื่อนต่อได้ (สำคัญบนมือถือที่ไม่มี scrollbar)
   ชั้น local เลื่อนไปกับเนื้อหาแล้วบังเงาไว้ ชั้น scroll อยู่กับที่
   เงาจึงโผล่เฉพาะด้านที่ยังมีอะไรให้เลื่อนไปดู */
.table-wrap {
  overflow-x: auto;
  background:
    linear-gradient(to right, var(--surface-solid), transparent) 0 0 / 26px 100% no-repeat local,
    linear-gradient(to left, var(--surface-solid), transparent) 100% 0 / 26px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--ink) 16%, transparent), transparent) 0 0 / 13px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--ink) 16%, transparent), transparent) 100% 0 / 13px 100% no-repeat scroll;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }
thead { background: var(--surface-strong); }
th {
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-strong);
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
th:first-child { border-top-left-radius: 10px; border-bottom-left-radius: 10px; }
th:last-child { border-top-right-radius: 10px; border-bottom-right-radius: 10px; }
td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--hairline); vertical-align: middle; transition: background-color 0.15s ease; }
tbody tr:hover td { background: var(--surface-faint); }
.cell-actions { display: flex; gap: 0.4rem; white-space: nowrap; align-items: center; }
.status-form { display: flex; gap: 0.35rem; align-items: center; }
.status-form select { width: auto; padding: 0.38rem 0.55rem; font-size: 0.8rem; }
.num { font-variant-numeric: tabular-nums; }

/* จอเล็ก: ตาราง 6 คอลัมน์บีบใน ~400px อ่านไม่ออก ชื่อแตกเป็นสามบรรทัด
   คอลัมน์ท้าย ๆ ก็หลุดออกนอกจอ จึงคลี่แต่ละแถวเป็นการ์ดแทน ไม่ต้องเลื่อนแนวนอน
   ชื่อคอลัมน์มาจาก data-label ที่ app.js เติมให้จาก thead (ดู "ตารางเป็นการ์ด") */
@media (max-width: 640px) {
  .table-wrap {
    overflow-x: visible;
    background: none;
  }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }

  /* หัวตารางไม่ต้องแสดงแล้ว แต่ยังต้องให้ screen reader อ่านเจอ */
  .table-wrap thead {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .table-wrap tr {
    background: var(--surface-input);
    border: 1px solid var(--glass-line);
    border-radius: var(--radius-sm);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    box-shadow: var(--shadow-xs);
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap tbody tr:hover td { background: none; }

  .table-wrap td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: none;
    text-align: right;
  }
  .table-wrap td::before {
    content: attr(data-label);
    flex-shrink: 0;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-mute);
  }
  /* คอลัมน์ท้ายที่หัวว่าง (ปุ่มแก้ไข/ลบ) กับแถว "ไม่มีข้อมูล" ไม่มี label ให้แสดง */
  .table-wrap td:not([data-label])::before { content: none; }

  /* คอลัมน์แรกคือตัวระบุแถวเสมอ (ชื่อสินค้า/เลขออเดอร์/ชื่อลูกค้า) ทำเป็นหัวการ์ด */
  .table-wrap td:first-child {
    justify-content: flex-start;
    text-align: left;
    padding: 0 0 var(--space-3);
    margin-bottom: var(--space-2);
    border-bottom: 1px solid var(--hairline);
    font-weight: 500;
  }
  .table-wrap td:first-child::before { content: none; }

  /* แถวว่าง: ไม่ต้องมีกรอบการ์ดครอบข้อความ */
  .table-wrap tr:has(td[colspan]) {
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .table-wrap td[colspan] { display: block; padding: 0; }

  /* ช่องที่เนื้อหายาว (เช่น คำอธิบายในหน้าตั้งค่า) ถ้าวางคู่กับ label แนวนอน
     จะเหลือความกว้างนิดเดียวจนอ่านไม่ออก คลี่ลงเป็นแนวตั้งแทน
     app.js เป็นคนติด is-long ให้ตามความยาวข้อความจริง */
  .table-wrap td.is-long {
    display: block;
    text-align: left;
  }
  .table-wrap td.is-long::before {
    display: block;
    margin-bottom: var(--space-1);
  }

  /* ช่องที่หัวคอลัมน์ว่าง (แถวปุ่ม) เหลือลูกเดียว space-between เลยไม่ดันไปไหน */
  .table-wrap td:not([data-label]) { justify-content: flex-end; }
  .table-wrap .cell-actions { justify-content: flex-end; }
  /* ช่องคงเหลือมีทั้งแถบและตัวเลข จับสองอันไปอยู่ขวาคู่กัน ไม่ให้แถบไปลอยกลาง */
  .table-wrap .meter { margin-left: auto; width: 72px; }
}

.thumb { width: 42px; height: 42px; border-radius: 10px; background-size: cover; background-position: center; flex-shrink: 0; }
.thumb-empty {
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--decor-2), var(--decor-1));
  color: var(--on-decor);
  font-weight: 600;
  font-size: 1.05rem;
}
.prod-cell { display: flex; align-items: center; gap: 0.7rem; }
.prod-cell .prod-name { font-weight: 500; color: var(--ink); }
.prod-cell .prod-sku { font-size: 0.75rem; color: var(--ink-mute); }

.meter { width: 96px; height: 5px; border-radius: 999px; background: var(--gray-bg); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.meter.is-low i { background: var(--red); }
.w-0 { width: 0; } .w-10 { width: 10%; } .w-20 { width: 20%; } .w-30 { width: 30%; }
.w-40 { width: 40%; } .w-50 { width: 50%; } .w-60 { width: 60%; } .w-70 { width: 70%; }
.w-80 { width: 80%; } .w-90 { width: 90%; } .w-100 { width: 100%; }

/* ── activity feed ─────────────────────────────────────────── */

.feed { list-style: none; display: grid; gap: 0.1rem; }
.feed li {
  display: grid;
  grid-template-columns: 6rem 1fr auto auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.35rem;
  border-bottom: 1px solid var(--hairline);
}
.feed li:last-child { border-bottom: none; }
.feed-code { font-variant-numeric: tabular-nums; color: var(--ink-mute); font-size: 0.83rem; }

/* จอเล็ก: 4 คอลัมน์ตายตัวบีบจนชื่อลูกค้าแตกบรรทัด พับเป็นสองแถวแทน
   แถวบน = เลขออเดอร์ + ยอด, แถวล่าง = ชื่อ + สถานะ
   feed ที่ไม่มี badge (ตัวอย่างใน preloader) ก็ยังเรียงถูกเพราะระบุตำแหน่งไว้ตรง ๆ */
@media (max-width: 640px) {
  .feed li {
    grid-template-columns: 1fr auto;
    gap: 0.2rem 0.7rem;
    padding: 0.7rem 0.35rem;
  }
  .feed-code { grid-column: 1; grid-row: 1; }
  .feed-total { grid-column: 2; grid-row: 1; text-align: right; }
  .feed-name { grid-column: 1; grid-row: 2; }
  .feed li .badge { grid-column: 2; grid-row: 2; justify-self: end; }
}
.feed-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-mute); text-align: center; padding: 1.4rem; font-size: 0.88rem; }

/* ── sales chart ───────────────────────────────────────────── */

.chart { display: flex; align-items: flex-end; gap: 0.6rem; height: 170px; padding-top: 1rem; }
.chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.45rem; height: 100%; justify-content: flex-end; }
.chart .bar-fill {
  width: 100%;
  max-width: 40px;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--decor-4), var(--decor-2));
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.chart .bar:last-child .bar-fill { background: linear-gradient(180deg, var(--accent), var(--decor-1)); }
.chart .bar-label, .chart .bar-val { font-size: 0.7rem; color: var(--ink-mute); }
.h-0 { height: 0; } .h-10 { height: 10%; } .h-20 { height: 20%; } .h-30 { height: 30%; }
.h-40 { height: 40%; } .h-50 { height: 50%; } .h-60 { height: 60%; } .h-70 { height: 70%; }
.h-80 { height: 80%; } .h-90 { height: 90%; } .h-100 { height: 100%; }

/* ── toolbar & pagination ──────────────────────────────────── */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.toolbar .search { max-width: 340px; flex: 1; }

/* ช่องค้นหา + ปุ่มค้นหา เป็นแถบเดียวกัน (input-group) ปุ่มเป็นสีหลัก + ไอคอนแว่นขยาย */
.search { display: flex; align-items: stretch; max-width: 380px; }
.search input[type="search"] { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.search input[type="search"]:focus { position: relative; z-index: 1; }
.search .search-btn {
  flex-shrink: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0 1rem;
  gap: 0;
}
.search .search-btn .icon-svg { display: block; }

/* ── ประวัติการค้นหา (dropdown แบบ Google, เก็บใน localStorage) ── */
.search-hist {
  position: fixed;
  z-index: 240;
  max-height: 18rem;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0.3rem;
  background: var(--overlay);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}
.search-hist.is-shown { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
.search-hist-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.55rem;
  border-radius: 9px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.search-hist-item.is-active, .search-hist-item:hover { background: var(--surface-soft); color: var(--ink); }
.sh-icon {
  flex-shrink: 0;
  width: 15px; height: 15px;
  background: currentColor;
  color: var(--ink-mute);
  -webkit-mask: center / 15px 15px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v5h5'/%3E%3Cpath d='M3.05 13A9 9 0 1 0 6 5.3L3 8'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
  mask: center / 15px 15px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v5h5'/%3E%3Cpath d='M3.05 13A9 9 0 1 0 6 5.3L3 8'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}
.sh-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-del {
  all: unset;
  flex-shrink: 0;
  width: 1.4rem; height: 1.4rem;
  display: grid; place-items: center;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink-mute);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.sh-del:hover { color: var(--red); background: var(--red-bg); }
.search-hist-foot {
  margin-top: 0.25rem;
  padding: 0.5rem 0.55rem;
  border-top: 1px solid var(--hairline);
}
.search-hist-clear {
  all: unset;
  display: block;
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 7px;
}
.search-hist-clear:hover { color: var(--red); background: var(--red-bg); }
.filter-tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.filter-tabs a {
  font-size: 0.83rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.filter-tabs a:hover { color: var(--ink); border-color: rgba(127, 127, 127, 0.35); }
.filter-tabs a.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.pagination { display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; margin-top: 1.1rem; flex-wrap: wrap; }
.pagination .page-info { margin-right: auto; font-size: 0.82rem; color: var(--ink-mute); }
.pagination .per-page { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; color: var(--ink-mute); }
.pagination .per-page select {
  width: auto;
  padding: 0.32rem 1.9rem 0.32rem 0.65rem;
  font-size: 0.8rem;
  background-position: right 0.55rem center;
}
.page-nav { display: inline-flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.pagination a, .pagination span.page-cur {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.55rem;
  display: inline-grid;
  place-items: center;
  border-radius: 9px;
  font-size: 0.83rem;
  text-decoration: none;
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.pagination a:hover { color: var(--ink); background: var(--surface-soft); border-color: rgba(127, 127, 127, 0.3); }
.pagination span.page-cur { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ── forms (dashboard) ─────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.9rem 1.2rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { margin-top: 1.4rem; display: flex; gap: 0.6rem; flex-wrap: wrap; }

.order-head { margin-bottom: 1.1rem; }
.order-head .order-code { font-size: 1.2rem; font-weight: 600; margin-right: 0.6rem; }
.order-head p { color: var(--ink-mute); font-size: 0.88rem; margin-top: 0.4rem; }
.order-total { text-align: right; margin-top: 0.9rem; font-size: 0.95rem; }
.order-total strong { font-size: 1.3rem; font-weight: 600; margin-left: 0.4rem; font-variant-numeric: tabular-nums; }

/* ── showcase (UI kit) ─────────────────────────────────────── */

.page-intro { color: var(--ink-soft); font-size: 0.95rem; max-width: 72ch; }
.ui-block { }
.ui-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.ui-head h2 { font-size: 1.05rem; display: flex; align-items: center; gap: 0.6rem; }
.ui-head code {
  background: var(--gray-bg);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  color: var(--ink-soft);
}
.ui-tag {
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--blue-bg);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}
.ui-desc { color: var(--ink-mute); font-size: 0.87rem; margin-bottom: 0.9rem; }
.ui-row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.ui-stack { display: grid; gap: 0.6rem; }
.ui-hr { border: none; border-top: 1px solid var(--hairline); margin: 1.3rem 0; }
.load-box { margin-top: 1rem; border: 1px solid var(--hairline); border-radius: var(--radius-sm); min-height: 90px; }
.ui-block .form-grid { margin-top: 0.2rem; }

/* ── auth ──────────────────────────────────────────────────── */

.auth-wrap { min-height: 100svh; display: grid; place-items: center; padding: 5rem 1.5rem 3rem; }
.auth-card {
  width: min(100%, 390px);
  padding: 2.4rem 2.2rem;
  border-radius: 22px;
  background: var(--surface-strong);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 1.55rem; font-weight: 600; text-align: center; }
.auth-card .auth-sub { text-align: center; font-size: 0.88rem; color: var(--ink-mute); margin: 0.4rem 0 1.6rem; }
.auth-card form { display: grid; gap: 0.9rem; }
.check-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.86rem; color: var(--ink-soft); }
.check-row input { width: auto; accent-color: var(--accent); }
.auth-card .btn { width: 100%; margin-top: 0.2rem; }
.auth-hint { text-align: center; font-size: 0.8rem; color: var(--ink-mute); margin-top: 0.9rem; }
.auth-back { display: block; text-align: center; margin-top: 1.3rem; font-size: 0.84rem; color: var(--ink-mute); }

/* ── error pages ───────────────────────────────────────────── */

.error-wrap { min-height: 100svh; display: grid; place-items: center; text-align: center; padding: 2rem; }
.error-wrap .code { font-size: clamp(3.6rem, 11vw, 6rem); font-weight: 700; color: var(--accent); line-height: 1.1; letter-spacing: -0.03em; }
.error-wrap h1 { font-size: 1.4rem; font-weight: 600; margin: 0.5rem 0 0.9rem; }
.error-wrap p { color: var(--ink-soft); margin-inline: auto; }
.error-wrap .btn { margin-top: 1.8rem; }

/* ── reduced motion ────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
  .spinner, .btn.is-loading::after { animation: spin 0.8s linear infinite !important; }
}

/* ============================================================
   Component library (ชุดเสริมตาม mvc-components-guide)
   ============================================================ */

/* icon */
.icon-svg { display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }

/* แกลเลอรีไอคอน (หน้ารวมคอมโพเนนต์) */
.icon-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 0.5rem; }
.icon-cell {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 0.85rem 0.3rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--ink-soft);
}
.icon-cell code { font-size: 0.67rem; color: var(--ink-mute); background: none; padding: 0; }

/* link */
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; text-underline-offset: 2px; }
.link.is-active { font-weight: 600; }

/* breadcrumb */
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--ink-mute); }
.breadcrumb li { display: inline-flex; align-items: center; gap: 0.4rem; }
.breadcrumb li:not(:first-child)::before { content: '/'; color: var(--ink-mute); opacity: 0.6; }
.breadcrumb a { color: var(--ink-soft); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb [aria-current="page"] { color: var(--ink); }

/* page-header */
.page-header { margin-bottom: 1.4rem; }
.page-header-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 0.5rem; }
.page-title { font-size: 1.4rem; font-weight: 600; }
.page-sub { color: var(--ink-mute); font-size: 0.9rem; margin-top: 0.3rem; }
.page-header-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* tabs */
.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.tab { padding: 0.6rem 0.95rem; font-size: 0.88rem; color: var(--ink-soft); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.2s ease, border-color 0.2s ease; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.tabs-pills { border-bottom: none; gap: 0.35rem; }
.tabs-pills .tab { border: 1px solid var(--hairline); border-radius: 999px; margin-bottom: 0; }
.tabs-pills .tab.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* dropdown-menu */
.dropdown { position: relative; display: inline-block; }
.dropdown-caret { transition: transform 0.2s ease; }
.dropdown.is-open .dropdown-caret { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; min-width: 190px;
  padding: 0.32rem; background: var(--overlay); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(-4px); pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}
.dropdown-menu-right { left: auto; right: 0; }
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
.dropdown-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: var(--space-3) var(--space-4); border-radius: 9px; font-size: 0.87rem;
  font-family: inherit; color: var(--ink-soft); text-decoration: none; white-space: nowrap;
  background: none; border: none; text-align: left; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.dropdown-item-icon { opacity: 0.75; flex-shrink: 0; }
.dropdown-item:hover { background: var(--surface-soft); color: var(--ink); }
.dropdown-item.is-danger { color: var(--red); }
.dropdown-item.is-danger:hover { background: var(--red-bg); }
.dropdown-sep { height: 1px; background: var(--hairline); margin: 0.3rem 0.1rem; }

/* theme-switcher (component) */
.theme-menu { min-width: 236px; }
.theme-item { position: relative; padding-right: 2rem; }
.theme-swatch { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 1px var(--hairline) inset, 0 1px 2px rgba(0, 0, 0, 0.15); }
.theme-swatch-p { background: #6d3fc4; }
.theme-swatch-e { background: #1d1d1f; }
.theme-swatch-a { background: #0071e3; }
.theme-swatch-b { background: #b5651d; }
.theme-swatch-c { background: #2f7a5c; }
.theme-swatch-f { background: #c0263c; }
/* วงพรีวิวต้องโชว์สีจริงของโหมดที่ใช้อยู่ ไม่งั้นวงขาวดำจมหายไปกับพื้นตอนโหมดมืด */
[data-mode="dark"] .theme-swatch-p { background: #a98bff; }
[data-mode="dark"] .theme-swatch-e { background: #f5f5f7; }
[data-mode="dark"] .theme-swatch-a { background: #5aa9ff; }
[data-mode="dark"] .theme-swatch-b { background: #e09a4e; }
[data-mode="dark"] .theme-swatch-c { background: #52bb8d; }
[data-mode="dark"] .theme-swatch-f { background: #ff6b7d; }
.theme-item-text { display: flex; flex-direction: column; line-height: 1.3; }
.theme-item-text small { font-size: 0.72rem; color: var(--ink-mute); font-weight: 400; }
.theme-item-check { position: absolute; right: 0.65rem; top: 50%; transform: translateY(-50%); opacity: 0; color: var(--accent); }
.theme-item.is-selected .theme-item-check { opacity: 1; }
.theme-item.is-selected { color: var(--ink); font-weight: 500; }

/* หัวข้อกลุ่ม + แถวเลือกโหมดสว่าง/มืด/ตามระบบ */
.theme-group-label {
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-mute);
  padding: var(--space-2) var(--space-4) var(--space-1);
}
.theme-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  padding: 0 var(--space-1) var(--space-1);
}
.theme-mode {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  padding: var(--space-3) var(--space-1);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.72rem;
  color: var(--ink-soft);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.theme-mode:hover { background: var(--surface-soft); color: var(--ink); }
.theme-mode.is-selected {
  background: var(--blue-bg);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
  font-weight: 500;
}

/* card body / footer (card-head มีอยู่แล้ว) */
.card-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.card-body { color: var(--ink-soft); font-size: 0.92rem; }
.card-foot { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--hairline); display: flex; gap: 0.6rem; justify-content: flex-end; flex-wrap: wrap; }

/* divider */
.divider { border: none; border-top: 1px solid var(--hairline); margin: 1.2rem 0; }
.divider-labelled { display: flex; align-items: center; gap: 0.8rem; color: var(--ink-mute); font-size: 0.8rem; }
.divider-labelled::before, .divider-labelled::after { content: ''; flex: 1; border-top: 1px solid var(--hairline); }
.divider-v { display: inline-block; width: 1px; align-self: stretch; min-height: 1em; background: var(--hairline); margin: 0 0.2rem; }

/* empty-state */
.empty-state { text-align: center; padding: 2.6rem 1.5rem; color: var(--ink-mute); }
.empty-state-icon { display: inline-grid; place-items: center; width: 3.2rem; height: 3.2rem; border-radius: 50%; background: var(--gray-bg); color: var(--ink-mute); margin-bottom: 0.9rem; }
.empty-state-title { color: var(--ink); font-weight: 500; }
.empty-state-msg { font-size: 0.88rem; margin: 0.3rem auto 0; }
.empty-state-action { margin-top: 1.1rem; }

/* tag */
.tag { display: inline-flex; align-items: center; padding: 0.18rem 0.6rem; border-radius: 7px; font-size: 0.76rem; font-weight: 500; background: var(--gray-bg); color: var(--ink-soft); }
.tag-accent { background: var(--blue-bg); color: var(--accent); }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }
.tag-red { background: var(--red-bg); color: var(--red); }

/* chip */
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.24rem 0.35rem 0.24rem 0.7rem; border-radius: 999px; font-size: 0.8rem; background: var(--gray-bg); color: var(--ink); }
.chip-remove { all: unset; cursor: pointer; width: 1.15rem; height: 1.15rem; display: grid; place-items: center; border-radius: 50%; color: var(--ink-mute); line-height: 1; }
.chip-remove:hover { background: var(--red); color: var(--on-accent); }

/* kbd */
.kbd-group { display: inline-flex; align-items: center; gap: 0.25rem; }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.74rem; padding: 0.1rem 0.4rem; border: 1px solid var(--hairline); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-input); color: var(--ink-soft); }
.kbd-plus { color: var(--ink-mute); font-size: 0.72rem; }

/* status-indicator */
.status-ind { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: var(--ink-soft); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-mute); flex-shrink: 0; }
.status-green .status-dot { background: var(--green); }
.status-red .status-dot { background: var(--red); }
.status-amber .status-dot { background: var(--amber); }
.status-dot.is-pulse { box-shadow: 0 0 0 0 currentColor; animation: statusPulse 1.6s ease-out infinite; }
.status-green .status-dot.is-pulse { color: var(--green); }
.status-red .status-dot.is-pulse { color: var(--red); }
@keyframes statusPulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 50%, transparent); } 100% { box-shadow: 0 0 0 7px transparent; } }

/* progress-bar */
.progress { display: flex; align-items: center; gap: 0.6rem; }
.progress-track { flex: 1; height: 7px; border-radius: 999px; background: var(--gray-bg); overflow: hidden; }
.progress-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s ease; }
.progress-green .progress-fill { background: var(--green); }
.progress-amber .progress-fill { background: var(--amber); }
.progress-red .progress-fill { background: var(--red); }
.progress-pct { font-size: 0.78rem; color: var(--ink-mute); min-width: 2.4rem; text-align: right; }

/* tooltip (CSS ล้วน) */
.tooltip { position: relative; display: inline-flex; cursor: help; }
.tooltip-mark { width: 1.15rem; height: 1.15rem; display: grid; place-items: center; border-radius: 50%; background: var(--gray-bg); color: var(--ink-mute); font-size: 0.72rem; font-weight: 600; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%) translateY(4px);
  background: var(--ink); color: var(--bg); font-size: 0.76rem; line-height: 1.4; white-space: nowrap;
  padding: 0.35rem 0.6rem; border-radius: 8px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.16s ease, transform 0.16s ease; z-index: 70;
}
.tooltip:hover::after, .tooltip:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.tooltip-bottom::after { bottom: auto; top: calc(100% + 7px); transform: translateX(-50%) translateY(-4px); }
.tooltip-bottom:hover::after, .tooltip-bottom:focus-visible::after { transform: translateX(-50%) translateY(0); }

/* form-group / help / required */
.form-group { min-width: 0; }
.form-group .req { color: var(--red); }
.form-help { display: block; font-size: 0.78rem; color: var(--ink-mute); margin-top: 0.3rem; }

/* reset checkbox/radio ไม่ให้รับสไตล์ base input (กันอาการกระพริบ/ขนาดเด้งตอนติ๊ก) */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  transition: none;
  accent-color: var(--accent);
  flex-shrink: 0;
}
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }

/* checkbox / radio line */
.check-line { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; color: var(--ink-soft); cursor: pointer; }
.check-line input { accent-color: var(--accent); }
.radio-group { display: grid; gap: 0.5rem; }
.radio-group-label { font-size: 0.82rem; color: var(--ink-soft); }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 40px; height: 23px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 20%, transparent); transition: background-color 0.2s ease; flex-shrink: 0; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: var(--surface-solid); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-ring); }
.switch-label { font-size: 0.88rem; color: var(--ink-soft); }

/* copy-button */
.copy-btn.is-copied { color: var(--green); border-color: transparent; background: var(--green-bg); }

/* skeleton */
.skeleton { position: relative; overflow: hidden; background: var(--gray-bg); border-radius: 7px; display: block; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, var(--shimmer), transparent); animation: shimmer 1.4s infinite; }
.skeleton-lines { display: grid; gap: 0.55rem; }
.skeleton-line { height: 0.8rem; }
.skeleton-thumb { height: 120px; border-radius: var(--radius-sm); margin-bottom: 0.6rem; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; }
.skeleton-row { display: flex; align-items: center; gap: 0.7rem; }
.skeleton-card { display: block; }
@keyframes shimmer { 100% { transform: translateX(100%); } }
