/* ระบบดีไซน์เดียวทั้งแอป: พื้น gradient อ่อน, การ์ดกระจกมุมโค้งมาก, แผงขาวซ้อน, ปุ่ม pill, สีเน้นน้ำเงินสีเดียว
   สีทั้งหมดอยู่ที่ token ด้านล่าง ธีมมืดเป็นค่าเริ่มต้น ธีมสว่างทับเฉพาะค่าที่ต่าง (theme.js ตั้ง data-theme ก่อนหน้าแรกวาด) */
:root {
  color-scheme: dark;
  --page: radial-gradient(1200px 700px at 10% -10%, #18264a 0%, transparent 60%), radial-gradient(900px 600px at 100% 110%, #2a2414 0%, transparent 55%), #0a0c12;
  --bg: #0d1018; --side: #0f121b; --glass: rgba(255, 255, 255, .045); --glass-line: rgba(255, 255, 255, .08);
  --panel: #161a26; --card: #131722; --raised: #1d2232; --line: #272d3d; --field-line: #697089;
  --text: #f2f4f9; --muted: #a6adbd; --accent: #8fb0ff; --accent-soft: #3d6cf529; --accent-line: #8fb0ff80;
  --green: #4ad295; --green-soft: #4ad2951f; --green-line: #4ad29566;
  --blue: #8fb0ff; --blue-soft: #3d6cf522; --blue-line: #8fb0ff59;
  --amber: #ffb648; --amber-soft: #ffb6481f; --amber-line: #ffb64866;
  --red: #ff7b7b; --red-soft: #ff5c5c26; --red-line: #ff7b7b80;
  --price: #b9cbff; --badge-ok: #4ad2951a; --badge-out: #ff5c5c22;
  --grid-line: #ffffff0d; --auth-bg: #131722f2; --shadow: #0009; --backdrop: rgba(4, 6, 12, .7);
  --hero-from: #a99cff; --hero-to: #4fe0cd; --logo-filter: none;
  --seg-cost: #5d6b8c; --seg-eat: #ffb648; --seg-profit: #4ad295; --seg-track: #ffffff14;
  /* ปุ่มสีทึบ ตัวอักษรบนปุ่มผ่าน AA ทั้งสองธีม จึงใช้ค่าเดียวกัน */
  --fill-accent: #2c5be6; --fill-accent-2: #2350d6; --fill-delete: #d12f36; --fill-restock: #2c5be6; --fill-consume: #ffb648;
  --radius-xl: 28px; --radius-lg: 20px; --radius-md: 14px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: radial-gradient(1100px 700px at 0% 0%, #dfe7fb 0%, transparent 60%), radial-gradient(900px 700px at 100% 100%, #f6ecd6 0%, transparent 55%), #eef1f7;
  --bg: #f4f6fb; --side: rgba(255, 255, 255, .6); --glass: rgba(255, 255, 255, .55); --glass-line: rgba(255, 255, 255, .95);
  --panel: #ffffff; --card: #ffffff; --raised: #edf0f6; --line: #dde2ec; --field-line: #858b99;
  --text: #11141b; --muted: #555c6b; --accent: #2350d6; --accent-soft: #2350d614; --accent-line: #2350d680;
  --green: #0b7244; --green-soft: #0b72441a; --green-line: #0b724466;
  --blue: #2350d6; --blue-soft: #2350d612; --blue-line: #2350d659;
  --amber: #8a4f00; --amber-soft: #e0900018; --amber-line: #b0700070;
  --red: #b4232b; --red-soft: #d12f3616; --red-line: #b4232b80;
  --price: #2350d6; --badge-ok: #0b724414; --badge-out: #d12f3614;
  --grid-line: #0000000d; --auth-bg: #fffffff0; --shadow: #1c2a5520; --backdrop: rgba(30, 40, 70, .35);
  --hero-from: #2350d6; --hero-to: #0b7268; --logo-filter: brightness(0) invert(.08);
  --seg-cost: #9aa5bd; --seg-eat: #e09000; --seg-profit: #0b7244; --seg-track: #e6eaf2;
}
* { box-sizing: border-box; }
/* hidden ต้องชนะ display ที่ตั้งไว้ใน class เสมอ */
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: "IBM Plex Sans Thai", system-ui, "Leelawadee UI", sans-serif; background: var(--page); background-attachment: fixed; color: var(--text); }
h1, h2, h3, .stat b, .earned b, .hero-num b, .subs b, .prices .sell td { font-family: Prompt, "IBM Plex Sans Thai", sans-serif; }
svg { flex: none; }

/* ---------- ช่องกรอก ---------- */
input, select { font: inherit; width: 100%; padding: 10px 14px; border: 1px solid var(--field-line); border-radius: var(--radius-md); background: var(--panel); color: var(--text); }
label { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 12px; }
label input, label select { margin-top: 4px; }
fieldset { border: 0; margin: 0; padding: 0; }

/* ---------- ปุ่ม: pill ทั้งแอป สีบอกหน้าที่ (หลัก = น้ำเงินทึบ, รอง = ขอบ, เบา = โปร่ง, อันตราย = แดง) ---------- */
button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .12s ease-out, box-shadow .15s; touch-action: manipulation; }
button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
/* จังหวะกด: ย่อเล็กน้อยตอนกดค้าง ไม่หน่วงการคลิก */
button:active:not(:disabled) { transform: scale(.97); }
button:hover:not(:disabled) { border-color: var(--accent-line); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, button.btn-accent, button.btn-sell { background: var(--fill-accent); border-color: transparent; color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled), button.btn-accent:hover:not(:disabled), button.btn-sell:hover:not(:disabled) { background: var(--fill-accent-2); border-color: transparent; box-shadow: 0 6px 18px #2350d640; }
button.large { padding: 11px 24px; }
button.pill { background: transparent; }
button.btn-restock { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue); font-weight: 500; }
button.btn-consume { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber); font-weight: 500; }
button.btn-delete { background: var(--red-soft); border-color: var(--red-line); color: var(--red); font-weight: 600; }
button.btn-delete:hover:not(:disabled) { border-color: var(--red); }
button.btn-plain { background: transparent; color: var(--text); }
/* ปุ่มยืนยันในหน้าต่าง: ลบเป็นแดงทึบตัวอักษรขาว ให้ต่างจากปุ่มยกเลิกชัด ๆ */
button.confirm.btn-delete { background: var(--fill-delete); border-color: transparent; color: #fff; }
button.confirm.btn-restock { background: var(--fill-restock); border-color: transparent; color: #fff; }
button.confirm.btn-consume { background: var(--fill-consume); border-color: transparent; color: #1d1204; }

/* ---------- โครงหน้า: แถบไอคอนแคบ (มีป้ายชื่อใต้ไอคอน) + เนื้อหา ---------- */
.shell { display: grid; grid-template-columns: 108px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 8px;
  background: var(--side); border-right: 1px solid var(--glass-line); backdrop-filter: blur(14px); }
.side .brand { margin: 2px 0 16px; }
.side .brand img { width: 88px; }
.side .tabs, .side .tools { display: flex; flex-direction: column; align-items: stretch; gap: 4px; width: 100%; }
.side button { flex-direction: column; gap: 4px; padding: 6px 2px; width: 100%; border: 0; border-radius: var(--radius-md); background: none; color: var(--muted); font-size: 12px; line-height: 1.25; text-align: center; }
.side button:hover:not(:disabled) { color: var(--text); }
.side button .ico, .side .tools button svg { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); }
.side button .ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .tools button svg { padding: 11px; }
.side button.on { color: var(--text); font-weight: 600; }
.side button.on .ico { background: var(--fill-accent); border-color: transparent; color: #fff; box-shadow: 0 8px 18px #2350d655; }
.side .spacer { flex: 1; }
/* ออกจากระบบ: แดงชัด แยกจากปุ่มอื่นด้วยเส้นคั่น */
.side button.leave { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); border-radius: 0; color: var(--red); font-weight: 600; }
.side button.leave svg { background: var(--red-soft); border-color: var(--red-line); }
.lbl-short { display: none; }
main { padding: 24px 36px 40px; min-width: 0; max-width: 1760px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; }
.brand img { width: 132px; max-width: 100%; height: auto; display: block; filter: var(--logo-filter); }
.who { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); }
.who b { display: block; font-size: 14px; font-weight: 600; }
.who small { display: block; font-size: 12px; color: var(--muted); }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--fill-accent); color: #fff; font-weight: 600; }
/* หัวหน้าเพจ: ข้อความใหญ่ น้ำหนักบางสลับหนา + วันที่ + ปุ่ม pill หลัก/รอง */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; margin-bottom: 20px; flex-wrap: wrap; }
.head-actions .who { margin-right: 6px; }
.hello h1 { margin: 0; font-size: clamp(26px, 2.3vw, 36px); line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.hello h1 span { font-weight: 300; }
.hello .date { margin: 6px 0 2px; font-size: 14px; color: var(--muted); }
.top small, .meta { font-weight: 400; color: var(--muted); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.section { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 12px; font-size: 19px; font-weight: 500; }
.section small { font-size: 13px; font-weight: 400; color: var(--muted); }
/* ปุ่มเลือกสมาชิกในหน้าภาพรวมกลุ่ม */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chips button.on { background: var(--fill-accent); border-color: transparent; color: #fff; font-weight: 600; }

/* ---------- การ์ดกระจก + แผงขาวซ้อน ---------- */
.panel, .sumcard, .stat, .card, .libtile, .libbar { border: 1px solid var(--glass-line); background: var(--glass); backdrop-filter: blur(16px); }
.panel { border-radius: var(--radius-xl); padding: 20px 22px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 18px; font-weight: 500; }
.sumgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; margin-bottom: 18px; }
.sumcard { border-radius: var(--radius-xl); padding: 16px 20px 18px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: center; gap: 12px 18px; }
.sumcard header, .sumcard .ratio { grid-column: 1 / -1; }
.sumcard header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sumcard h3 { margin: 0; font-size: 18px; font-weight: 500; }
.hero-num { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--radius-lg); background: var(--panel); border: 1px solid var(--line); }
.hero-num .ico { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); color: var(--accent); }
.hero-num .ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hero-num b { display: block; font-size: 28px; font-weight: 600; line-height: 1.2; }
.hero-num small { display: block; font-size: 13px; color: var(--muted); }
.hero-num em { width: 100%; font-style: normal; font-size: 13px; color: var(--muted); }
.subs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; text-align: center; }
.subs b { display: block; font-size: 18px; font-weight: 500; }
.subs small { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.subs b .good, .subs b .bad, .hero-num b .good, .hero-num b .bad { padding: 0 10px; }
.dot.seg-cost { background: var(--seg-cost); } .dot.seg-eat { background: var(--seg-eat); }
.ratio { width: 100%; height: 10px; display: block; border-radius: 99px; overflow: hidden; background: var(--seg-track); }
.ratio .seg-cost { fill: var(--seg-cost); } .ratio .seg-eat { fill: var(--seg-eat); } .ratio .seg-profit { fill: var(--seg-profit); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { border-radius: var(--radius-lg); padding: 16px 18px; }
.stat b { display: block; font-size: 24px; font-weight: 600; margin: 4px 0; }
.stat small { color: var(--muted); }

/* ---------- Dashboard: มุมมอง เทียบเดือนก่อน แนวโน้ม และรายการสินค้า ---------- */
.viewbar { justify-content: space-between; }
.viewbar .chips { margin: 0; }
.viewbar .month { margin: 0; }
.compare { margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.compare.partial { display: inline-block; padding: 6px 14px; border-radius: 999px; background: var(--amber-soft); border: 1px solid var(--amber-line); color: var(--amber); font-weight: 500; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi b { margin: 0; }
.chg { font-size: 13px; font-weight: 600; }
.chg.up-good, .chg.down-good { color: var(--green); }
.chg.down-bad, .chg.up-bad { color: var(--red); }
.chg.same { color: var(--muted); }
.panel h3 small, .panel h4 { font-size: 13px; font-weight: 400; color: var(--muted); }
.panel h4 { margin: 16px 0 8px; font-weight: 500; color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -4px 0 8px; font-size: 13px; color: var(--muted); }
.dot.bar-rev { background: var(--fill-accent); } .dot.bar-profit { background: var(--seg-profit); } .dot.bar-loss { background: var(--red); }
.trend { width: 100%; max-width: 860px; height: auto; display: block; }
.trend .bar-rev { fill: var(--fill-accent); } .trend .bar-profit { fill: var(--seg-profit); } .trend .bar-loss { fill: var(--red); }
.trend .axis { stroke: var(--line); stroke-width: 1.5; }
.trend text { fill: var(--muted); font-size: 13px; }
.trend text.cur { fill: var(--text); font-weight: 600; }
details { margin-top: 10px; }
details summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; }
details .scroll { margin-top: 8px; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 0 18px; }
.plist { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.prow { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); }
.pthumb { width: 44px; height: 44px; border-radius: 14px; overflow: hidden; display: grid; place-items: center; background: var(--raised); font-size: 22px; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; }
.pname { min-width: 0; display: flex; flex-direction: column; }
.pname b { font-weight: 500; overflow-wrap: anywhere; }
.pname small { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pvals { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.pvals small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tag { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.tag.warn { background: var(--amber-soft); border-color: var(--amber-line); color: var(--amber); }

/* ---------- สวิตช์หน้าร้านบนการ์ด และหน้าต่างตั้งค่าหน้าร้าน ---------- */
.ttl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
button.switch { gap: 6px; padding: 2px 10px 2px 3px; min-height: 0; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); }
button.switch i { position: relative; width: 26px; height: 16px; border-radius: 99px; background: var(--raised); border: 1px solid var(--field-line); transition: background-color .15s; }
button.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: transform .15s, background-color .15s; }
button.switch[aria-checked="true"] { color: var(--accent); border-color: var(--accent-line); }
button.switch[aria-checked="true"] i { background: var(--fill-accent); border-color: transparent; }
button.switch[aria-checked="true"] i::after { transform: translateX(10px); background: #fff; }
.shoplink { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-lg); background: var(--accent-soft); }
.shoplink small { display: block; color: var(--muted); margin-bottom: 6px; }
.shoplink div { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.shoplink input { flex: 1 1 220px; }
a.pill-link { display: inline-flex; align-items: center; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); font-weight: 600; text-decoration: none; }
dialog .fields > .pill { justify-self: start; margin-top: 8px; }

/* ---------- การ์ดสินค้า: กระชับ ปุ่มทั้งหมดอยู่ในจอแรก ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { border-radius: var(--radius-lg); padding: 14px; display: flex; flex-direction: column; gap: 10px; container-type: inline-size; content-visibility: auto; contain-intrinsic-size: auto 380px; }
@media (hover: hover) { .card, .libtile { transition: border-color .15s, transform .18s ease-out, box-shadow .18s ease-out; }
  .card:hover, figure.libtile:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--shadow); border-color: var(--accent-line); } }
.card-top { display: flex; gap: 12px; align-items: center; min-width: 0; }
.pic { position: relative; flex: none; width: 64px; height: 64px; border-radius: 18px; overflow: hidden; display: grid; place-items: center; font-size: 32px; background: var(--panel); border: 1px solid var(--line); }
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ttl { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.ttl h3 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.ttl .meta { font-size: 12px; }
.badge { font-size: 12px; font-weight: 600; line-height: 1.5; padding: 2px 10px; border-radius: 99px; background: var(--badge-ok); border: 1px solid var(--green-line); color: var(--green); }
.badge.out { background: var(--badge-out); border-color: var(--red-line); color: var(--red); }
.body { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.meta b { font-weight: 500; color: var(--text); }
.card table.prices { table-layout: fixed; white-space: normal; font-size: 12.5px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md); border-collapse: separate; border-spacing: 0; overflow: hidden; }
.card .prices th, .card .prices td { padding: 5px 10px; border: 0; background: none; text-align: right; overflow-wrap: anywhere; }
.card .prices th { font-weight: 400; color: var(--muted); }
.card .prices th:first-child { width: 96px; text-align: left; white-space: nowrap; }
.card .prices .sell td { font-size: 15px; font-weight: 600; color: var(--price); }
.card .prices .good, .card .prices .bad { padding: 1px 6px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; flex-wrap: wrap; }
.row > span:first-child { color: var(--muted); }
.hint { font-size: 12px; padding: 6px 10px; border-radius: var(--radius-md); background: var(--amber-soft); border: 1px solid var(--amber-line); color: var(--amber); }
.earned { margin-top: auto; padding-top: 2px; }
.earned > div { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
.earned small { font-size: 12px; color: var(--muted); }
.earned b { font-size: 16px; font-weight: 600; }
/* ลำดับปุ่ม: ขายสินค้า (หลัก เต็มแถว) / รับเข้า + ตัดสต็อก (รอง) / แก้ไข + ยกเลิกรายการล่าสุด (เบา) + ลบ (แดง) */
.actions { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; }
.actions button { grid-column: span 6; font-size: 12.5px; line-height: 1.25; padding: 7px 6px; }
.actions .btn-sell { grid-column: 1 / -1; font-size: 14.5px; padding: 9px; }
.actions [data-do="edit"] { grid-column: span 3; }
.actions [data-do="undo"] { grid-column: span 6; }
.actions .btn-delete { grid-column: span 3; }
.actions .btn-plain { border-color: var(--line); }
/* การ์ดแคบ ย่อตัวเลขลง ราคาจะได้ไม่ตกบรรทัด */
@container (max-width: 260px) {
  .card table.prices { font-size: 11.5px; table-layout: auto; }
  .card .prices .sell td { font-size: 12.5px; }
  .card .prices th, .card .prices td { padding: 4px 4px; }
  .card .prices td { white-space: nowrap; }
  .card .prices th:first-child { width: auto; font-size: 10.5px; }
  .actions [data-do="edit"], .actions [data-do="undo"], .actions .btn-delete { grid-column: 1 / -1; }
}

/* ---------- ตาราง: อยู่บนแผงขาวในการ์ดกระจก ---------- */
.scroll { overflow-x: auto; border-radius: var(--radius-lg); background: var(--panel); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
th { font-weight: 400; color: var(--muted); background: var(--raised); }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: right; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { text-align: left; }
th.txt, td.txt { text-align: left; }
/* ปุ่มในตาราง (เบิกของส่วนกลาง / ลบ) ชิดขวาสุด ขนาดเท่ากัน */
.act { display: flex; justify-content: flex-end; gap: 6px; }
.act button { font-size: 12.5px; padding: 5px 12px; }
tr.total td { font-weight: 600; border-top: 2px solid var(--accent); }
.good, .bad { padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.good { color: var(--green); background: var(--green-soft); }
.bad { color: var(--red); background: var(--red-soft); }
td.good, td.bad { border-radius: 0; background: none; }
/* กราฟ SVG ขยายตามความกว้าง จำกัดไว้ไม่ให้ตัวอักษรในกราฟใหญ่เกินบนจอกว้าง */
.chart { width: 100%; max-width: 820px; height: auto; display: block; font-size: 13px; }
.chart text { fill: var(--text); }
.chart .up { fill: var(--green); }
.chart .down { fill: var(--red); }
.month { max-width: 240px; margin: 0 0 16px; }

/* ---------- หน้าต่างและข้อความแจ้ง ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius-xl); padding: 24px 24px 0; width: min(640px, 94vw); max-height: 92vh; overflow-y: auto; background: var(--card); color: var(--text); box-shadow: 0 30px 80px var(--shadow); }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
/* ช่องกรอก: จอกว้าง 3 คอลัมน์ ช่องตัวเลขอยู่ข้างกัน มือถือเหลือคอลัมน์เดียว */
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 12px; align-items: start; }
/* บรรทัดช่วยใต้ช่องกรอก */
label .help { display: block; margin-top: 4px; font-size: 12px; line-height: 1.45; font-weight: 400; color: var(--muted); }
.fields > *, .fields > fieldset > * { grid-column: 1 / -1; }
.fields .num { grid-column: auto; }
.fields .span2 { grid-column: span 2; }
.fields fieldset { display: contents; }
.fields fieldset[hidden] { display: none; }
@media (max-width: 560px) { .fields { grid-template-columns: minmax(0, 1fr); } .fields .num, .fields .span2 { grid-column: 1 / -1; } }
/* ช่องรูป: รูปย่อ + ปุ่มเปลี่ยน/ลบ */
.imgpick { margin-top: 12px; }
.imgpick-main { display: flex; gap: 12px; align-items: center; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
label.check input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--fill-accent); }
.imgpick .thumb { width: 72px; height: 72px; flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 18px; border: 1px dashed var(--field-line); background: var(--raised); font-size: 26px; }
.imgpick .thumb img { width: 100%; height: 100%; object-fit: cover; }
.imgpick small { display: block; font-size: 13px; color: var(--muted); }
.imgpick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.imgpick-actions button { font-size: 13px; padding: 6px 14px; }
/* คลังรูป: กริดรูปย่อ ใช้ทั้งหน้าคลังรูปและช่องเลือกรูปในฟอร์ม */
.libpick { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--bg); }
.libpick .libgrid { max-height: 240px; overflow-y: auto; margin-top: 8px; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.libgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.libtile { margin: 0; padding: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: var(--radius-lg); text-align: left; color: var(--text); }
button.libtile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md); align-items: stretch; gap: 0; }
.libtile[hidden] { display: none; }
.libtile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--raised); }
button.libtile span { padding: 4px 8px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.libtile[aria-pressed="true"] { border-color: var(--accent); outline: 2px solid var(--accent); }
.libtile figcaption { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.libtile figcaption b { font-weight: 500; overflow-wrap: anywhere; }
.libtile figcaption small { font-size: 12px; color: var(--muted); }
.libtile .act { padding: 6px 12px 12px; justify-content: flex-start; flex-wrap: wrap; }
.libbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius-xl); }
.libbar input[type=search] { max-width: 340px; }
/* หน้าต่าง: เปิดแบบจางเข้า+เลื่อนขึ้น ปิดแบบจางออก (core.js ใส่ .closing ก่อนปิดจริง 140ms) */
dialog[open] { animation: dialog-in .2s ease-out; }
dialog[open]::backdrop { animation: fade-in .2s ease-out; }
dialog.closing { animation: dialog-out .14s ease-in forwards; }
dialog.closing::backdrop { animation: fade-out .14s ease-in forwards; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
/* เปลี่ยนเมนู: เนื้อหาจางเข้าสั้น ๆ */
main.enter { animation: page-in .18s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }
dialog h2 { margin: 0; font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.preview { margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-lg); background: var(--accent-soft); font-size: 14px; white-space: pre-line; }
.preview.rows { white-space: normal; display: flex; flex-direction: column; gap: 4px; }
.preview .line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.preview .line span { color: var(--muted); }
.preview .line b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.preview hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
/* ปุ่มบันทึกติดขอบล่างของหน้าต่าง เห็นเสมอแม้ฟอร์มยาว */
.foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .foot { position: sticky; bottom: 0; margin: 18px -24px 0; padding: 14px 24px 18px; background: var(--card); border-top: 1px solid var(--line); }
.err { color: var(--red); font-size: 14px; margin-top: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 10px 20px; border-radius: 999px; display: none;
  background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: 0 12px 30px var(--shadow); }
#toast.show { display: block; animation: toast-in .18s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
/* ผู้ใช้ตั้งลดการเคลื่อนไหวไว้: ปิดแอนิเมชันและการย่อ/ยกทั้งหมด */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  button:active:not(:disabled), .card:hover, figure.libtile:hover { transform: none !important; }
}

/* ---------- หน้า login: grid จาง ๆ แสงฟุ้ง และอนุภาคลอย (คงเอฟเฟกต์เดิม) ---------- */
.login-page { position: relative; isolation: isolate; min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; overflow: hidden; }
.login-page::before { content: ""; position: absolute; inset: 0; z-index: -2;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 25%, transparent 78%);
  mask-image: radial-gradient(ellipse at center, #000 25%, transparent 78%); }
.login-page::after { content: ""; position: absolute; inset: 0; z-index: -3;
  background: radial-gradient(600px circle at 18% 28%, #8b7cf62b, transparent 70%), radial-gradient(520px circle at 85% 78%, #35d0c01c, transparent 70%); }
.particles { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.hero-wrap { width: 100%; max-width: 1040px; display: grid; grid-template-columns: 1.2fr 400px; gap: 64px; align-items: center; }
.hero .brand { display: flex; }
.hero .brand img { width: 250px; }
.hero h1 { font-size: clamp(38px, 5.4vw, 62px); font-weight: 600; line-height: 1.3; margin: 28px 0 14px; }
.hero h1 span { display: block; font-weight: 300; background: linear-gradient(90deg, var(--hero-from), var(--hero-to)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero h2 { font-family: inherit; font-size: 18px; font-weight: 300; line-height: 1.7; color: var(--muted); margin: 0; }
/* พื้นเกือบทึบแทน backdrop-filter ซึ่งกินเครื่องเมื่อมีอนุภาคขยับอยู่ข้างหลัง */
.auth { margin: 0; padding: 30px; border-radius: var(--radius-xl); background: var(--auth-bg); backdrop-filter: none; box-shadow: 0 30px 80px var(--shadow); }
.auth h3 { margin: 0 0 18px; font-size: 22px; font-weight: 600; text-align: center; }
.auth .primary { width: 100%; padding: 12px; }

/* ---------- จอเล็ก ---------- */
@media (max-width: 880px) {
  .hero-wrap { grid-template-columns: minmax(0, 420px); justify-content: center; gap: 24px; }
  .hero { text-align: center; }
  .hero .brand { justify-content: center; }
  .hero .brand img { width: 200px; }
  .hero h1 { margin-top: 16px; }
  main { padding: 18px 20px 32px; }
  .sumgrid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) { .sumcard { grid-template-columns: minmax(0, 1fr); } }
/* ---------- มือถือ: แถบบน (โลโก้ + เครื่องมือ) แถบเมนูล่าง ปุ่มสูงอย่างน้อย 44px การ์ดคอลัมน์เดียว หน้าต่างเต็มจอ ---------- */
@media (max-width: 640px) {
  body { overflow-x: hidden; }
  .shell { display: block; }
  /* ห้ามใส่ backdrop-filter ที่ .side บนมือถือ: จะทำให้แถบเมนูล่าง (position: fixed) ไปยึดกับ .side แทนจอ */
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 2px; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--line); backdrop-filter: none; background: var(--card); }
  .side .mark { display: none; }
  .side .brand { display: flex; margin-right: auto; }
  .side .brand img { width: 104px; }
  .side .spacer { display: none; }
  .side .tools { flex-direction: row; width: auto; gap: 2px; }
  .side .tools .lbl { display: none; }
  .side .tools button { width: 46px; min-height: 46px; padding: 0; }
  .side .tools button svg { width: 40px; height: 40px; padding: 10px; }
  .side button.leave { margin: 0 0 0 4px; padding: 0; border-top: 0; border-left: 1px solid var(--line); border-radius: 0; }
  .side .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px var(--shadow); }
  .side .tabs button { gap: 2px; min-height: 54px; padding: 2px 1px; font-size: 11px; overflow-wrap: anywhere; }
  .side .tabs button .ico { width: 34px; height: 30px; border-radius: 999px; border: 0; background: none; }
  .side .tabs button.on .ico { background: var(--fill-accent); box-shadow: none; }
  .side .tabs .lbl-long { display: none; }
  .side .tabs .lbl-short { display: inline; }
  .head-actions .who { width: 100%; margin: 0; }
  main { padding: 14px 12px calc(88px + env(safe-area-inset-bottom)); }
  .top { align-items: stretch; }
  .head-actions, .head-actions button { width: 100%; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .subs { gap: 6px; }
  .subs b { font-size: 15px; }
  .hero-num b { font-size: 24px; }
  .hero-num em { margin-left: 0; width: 100%; }
  .panel, .sumcard { padding: 16px; border-radius: 24px; }
  .pgrid { grid-template-columns: minmax(0, 1fr); }
  .prow { grid-template-columns: 40px minmax(0, 1fr); }
  .pvals { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
  .viewbar .month { max-width: none; width: 100%; }
  .libgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .libpick .libgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  label.check { min-height: 44px; }
  button, input, select, a.pill-link { min-height: 44px; }
  button.switch { min-height: 44px; padding: 4px 12px 4px 6px; }
  input, select { font-size: 16px; } /* 16px กัน iOS ซูมหน้าเมื่อแตะช่องกรอก */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 18px 16px 0; }
  dialog .foot { margin: 16px -16px 0; padding: 12px 16px 16px; }
  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
  /* ตาราง .stack: แต่ละแถวเป็นการ์ด ชื่อคอลัมน์ซ้าย ค่าขวา ตัดบรรทัดได้ */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; white-space: normal; }
  table.stack tr:first-child { display: none; }
  table.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.stack tr.total { border-top: 2px solid var(--accent); }
  table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; border: 0; text-align: right; overflow-wrap: anywhere; }
  table.stack td::before { content: attr(data-label); flex: none; max-width: 48%; text-align: left; color: var(--muted); }
  table.stack tr.total td { border-top: 0; }
}

/* ---------- หน้าร้านสาธารณะ (/shop): ออกแบบมือถือก่อน ลูกค้าส่วนใหญ่เปิดจาก IG บนมือถือ ---------- */
.shop-page { padding: 0 14px calc(24px + env(safe-area-inset-bottom)); }
.shop-head, #shop, .shop-foot { max-width: 1320px; margin-left: auto; margin-right: auto; }
.shop-head { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px 12px; padding: 16px 0 8px; }
.shop-logo { width: 112px; height: auto; filter: var(--logo-filter); }
.shop-head #theme { min-height: 44px; font-size: 13px; }
.shop-hello { grid-column: 1 / -1; }
.shop-hello h1 { margin: 6px 0 4px; font-size: clamp(26px, 6vw, 40px); line-height: 1.25; font-weight: 600; }
.shop-hello h1 span { font-weight: 300; }
.shop-hello p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 640px; }
.shop-tools { position: sticky; top: 0; z-index: 5; display: flex; flex-direction: column; gap: 8px; margin: 12px -14px 14px; padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.shop-tools input[type=search] { min-height: 46px; font-size: 16px; }
.shop-tools .chips { margin: 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.shop-tools .chips button { flex: none; min-height: 40px; }
.shop-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.shop-card { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; padding: 12px; border-radius: var(--radius-lg); border: 1px solid var(--glass-line); background: var(--glass); backdrop-filter: blur(16px); }
.shop-pic { position: relative; aspect-ratio: 1; border-radius: 18px; overflow: hidden; display: grid; place-items: center; font-size: 40px; background: var(--panel); border: 1px solid var(--line); align-self: start; }
.shop-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.shop-pic .badge { position: absolute; left: 6px; bottom: 6px; background: var(--panel); }
.shop-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.shop-body h2 { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.shop-by { color: var(--muted); font-size: 12.5px; }
.shop-price { margin: 0; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; }
.shop-price b { font-family: Prompt, sans-serif; font-size: 19px; font-weight: 600; color: var(--price); }
.shop-price span b { font-size: 15px; }
.seg { display: inline-flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--raised); width: fit-content; }
.seg button { min-height: 44px; padding: 4px 16px; border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px var(--shadow); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; padding: 0; font-size: 20px; font-weight: 600; }
.stepper input { width: 64px; min-height: 44px; text-align: center; font-size: 16px; padding: 6px; }
.stepper .unit { color: var(--muted); font-size: 14px; }
.shop-total { margin: 0; font-size: 14px; color: var(--muted); }
.shop-total b { color: var(--text); font-size: 16px; }
/* ปุ่มสั่งซื้อ: ปุ่มหลักที่เด่นที่สุดบนการ์ด เต็มความกว้างการ์ด ปุ่มละแถว (มีช่องทางเดียวก็เต็มความกว้าง) */
.orders { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
a.order { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 10px 18px; border-radius: 999px;
  font-family: Prompt, "IBM Plex Sans Thai", sans-serif; font-size: 16px; font-weight: 600; letter-spacing: .01em; text-decoration: none; color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35); box-shadow: 0 6px 16px rgba(0, 0, 0, .18); transition: transform .12s ease-out, filter .15s; }
a.order svg, a.contact svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
a.order svg .dot, a.order svg .fill, a.contact svg .dot, a.contact svg .fill { fill: currentColor; stroke: none; }
a.order:hover { filter: brightness(1.06); }
a.order:active { transform: scale(.97); }
a.order:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
/* Instagram: เหลือง/ส้มอยู่แค่มุมซ้ายล่างเป็นแสงตกแต่ง ส่วนที่มีตัวอักษรอยู่บนโทนชมพู-ม่วง-น้ำเงิน และมีชั้นเข้มบาง ๆ ให้ตัวอักษรขาวผ่าน AA */
a.order.c-instagram { background:
  linear-gradient(rgba(25, 0, 40, .16), rgba(25, 0, 40, .16)),
  radial-gradient(90% 180% at 0% 100%, #feda75 0%, #fa7e1e 16%, rgba(250, 126, 30, 0) 38%),
  linear-gradient(100deg, #d62976 0%, #c1307d 28%, #962fbf 62%, #4f5bd5 100%); }
/* Telegram: ฟ้าโทน Telegram เข้มขึ้นเล็กน้อยให้ตัวอักษรขาวผ่าน AA */
a.order.c-telegram { background: linear-gradient(100deg, #1878ba 0%, #1569a6 100%); }
.shop-hint { color: var(--muted); font-size: 12.5px; text-align: center; }
a.order.c-messenger { background: linear-gradient(100deg, #0a5ce0 0%, #6b3fd6 100%); }
a.order.c-tiktok { background: #111111; box-shadow: inset 3px 0 0 #25f4ee, inset -3px 0 0 #fe2c55, 0 6px 16px rgba(0, 0, 0, .18); }
a.order.c-phone { background: var(--fill-accent); color: var(--on-accent, #fff); text-shadow: none; }
/* ช่องทางที่ไม่ได้ใช้เป็นปุ่มสั่งซื้อ: ปุ่มรองแบบขอบ */
.contacts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
a.contact { flex: 1 1 140px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 500; text-decoration: none; }
a.contact svg { width: 18px; height: 18px; color: var(--accent); }
/* ประกาศ แบนเนอร์ โลโก้ ป้าย คำอธิบาย และอนุภาคพื้นหลังของหน้าร้าน */
.shop-notice { margin: 0 -14px; padding: 10px 16px; text-align: center; font-weight: 600; font-size: 14px; background: var(--fill-accent); color: var(--on-accent, #fff); overflow-wrap: anywhere; }
.shop-particles { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.shop-logo.custom { width: auto; max-width: 160px; height: 56px; object-fit: contain; border-radius: 14px; filter: none; }
.shop-banners { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 6px -14px 4px; padding: 4px 14px 10px; max-width: none; }
.shop-banners img { flex: 0 0 88%; max-width: 760px; aspect-ratio: 16 / 7; object-fit: cover; border-radius: 22px; scroll-snap-align: start; border: 1px solid var(--line); background: var(--raised); }
.shop-badge { position: absolute; top: 6px; left: 6px; max-width: calc(100% - 12px); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--fill-accent); color: var(--on-accent, #fff); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-desc { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.shop-card.pinned { border-color: var(--accent-line); }
.shop-page .chips button.on { color: var(--on-accent, #fff); }
.shop-empty { padding: 40px 12px; text-align: center; color: var(--muted); }
.shop-foot { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 28px; padding: 18px 0; border-top: 1px solid var(--line); text-align: center; color: var(--muted); }
.shop-foot a { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-size: 13px; padding: 10px; }
@media (min-width: 640px) {
  .shop-page { padding: 0 28px 32px; }
  .shop-grid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
  .shop-card { grid-template-columns: minmax(0, 1fr); padding: 14px; align-content: start; }
  .shop-pic { aspect-ratio: 16 / 10; }
  .shop-tools { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; margin: 14px 0 18px; padding: 12px 16px; border: 1px solid var(--glass-line); border-radius: var(--radius-xl); background: var(--glass); }
  .shop-tools input[type=search] { flex: 1 1 260px; max-width: 420px; }
  .shop-tools .chips { flex-wrap: wrap; }
  .shop-notice { margin: 0 -28px; }
  .shop-banners { margin: 10px auto 4px; padding: 4px 0 10px; max-width: 1320px; }
  .shop-banners img { flex-basis: 70%; }
}

/* ---------- ตั้งค่าหน้าร้าน (หลังบ้าน) ---------- */
.sf-status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.sf-status b { display: block; font-size: 16px; }
.sf-link { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 420px; }
.sf-link input { flex: 1 1 220px; }
.sf-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 0 18px; align-items: start; }
.sf-main { grid-column: 1; grid-row: 1; min-width: 0; }
.sf-preview-wrap { grid-column: 2; grid-row: 1; position: sticky; top: 16px; }
.sf-text { position: relative; }
.sf-text .count { float: right; font-size: 12px; color: var(--muted); }
textarea { font: inherit; width: 100%; padding: 10px 14px; border: 1px solid var(--field-line); border-radius: var(--radius-md); background: var(--panel); color: var(--text); resize: vertical; margin-top: 4px; }
code { font-size: 12.5px; padding: 1px 6px; border-radius: 6px; background: var(--raised); }
.sf-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.sf-swatch { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 6px 14px 6px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); font-weight: 500; cursor: pointer; }
.sf-swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sf-swatch i { width: 22px; height: 22px; border-radius: 50%; }
.sf-swatch:has(input:checked) { border-color: var(--accent); outline: 2px solid var(--accent); }
.sf-swatch:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.sw-blue i { background: #2350d6; } .sw-pink i { background: #c2185b; } .sw-green i { background: #0b7a4b; }
.sw-orange i { background: #b5400a; } .sw-purple i { background: #6d28d9; } .sw-black i { background: #1f2937; }
.sf-accent { margin-top: 4px; }
.sf-accent input[type=color] { padding: 4px; height: 44px; cursor: pointer; }
.sf-contrast { grid-column: 1 / -1; margin: 8px 0 0; font-size: 13.5px; font-weight: 600; }
.sf-contrast.pass { color: var(--green); } .sf-contrast.fail { color: var(--red); }
.sf-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 16px; }
.sf-thumb { flex: none; width: 64px; height: 64px; border-radius: 16px; overflow: hidden; display: grid; place-items: center; background: var(--raised); border: 1px solid var(--line); font-size: 24px; }
.sf-thumb.wide { width: 128px; }
.sf-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sf-logo { display: flex; gap: 14px; align-items: center; }
.sf-logo b, .sf-logo small { display: block; }
.sf-logo button { margin-top: 6px; }
.sf-banners, .sf-products { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sf-banners li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); }
.sf-contact { display: grid; grid-template-columns: 160px minmax(0, 1.3fr) minmax(0, 1fr); gap: 0 10px; align-items: end; padding: 10px 12px 12px; margin-top: 10px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); }
.sf-contact .check { margin-top: 10px; }
.sf-contact .act { grid-column: 3; justify-content: flex-end; margin-top: 8px; }
.sf-product { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); }
.sf-pfields { flex: 1; min-width: 0; }
.sf-pfields > label.check { margin-top: 6px; }
.sf-prow { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto auto; gap: 0 10px; align-items: end; }
/* พรีวิวแบบย่อ ใช้ตัวแปรสีที่ตั้งผ่าน CSSOM บนกล่องนี้ */
.sf-preview { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 20px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.pv-notice { margin: -12px -12px 0; padding: 8px 12px; text-align: center; font-size: 13px; font-weight: 600; background: var(--fill-accent); color: var(--on-accent, #fff); overflow-wrap: anywhere; }
.pv-head img { max-height: 40px; max-width: 120px; border-radius: 10px; display: block; margin-bottom: 6px; }
.pv-title { display: block; font-family: Prompt, sans-serif; font-size: 20px; overflow-wrap: anywhere; }
.pv-tagline { margin: 2px 0 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.pv-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.pv-desc, .pv-msg, .pv-foot { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.pv-price { font-weight: 600; color: var(--price); }
.pv-order { display: flex; align-items: center; justify-content: center; min-height: 46px; padding: 8px 14px; border-radius: 999px; font-weight: 600; color: #fff; text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35); background: var(--fill-accent); overflow-wrap: anywhere; }
.pv-order.c-instagram { background: linear-gradient(rgba(25, 0, 40, .16), rgba(25, 0, 40, .16)), radial-gradient(90% 180% at 0% 100%, #feda75 0%, #fa7e1e 16%, rgba(250, 126, 30, 0) 38%), linear-gradient(100deg, #d62976 0%, #c1307d 28%, #962fbf 62%, #4f5bd5 100%); }
.pv-order.c-telegram { background: linear-gradient(100deg, #1878ba 0%, #1569a6 100%); }
.pv-order.c-messenger { background: linear-gradient(100deg, #0a5ce0 0%, #6b3fd6 100%); }
.pv-order.c-tiktok { background: #111; }
.pv-order.c-phone { color: var(--on-accent, #fff); text-shadow: none; }
@media (max-width: 1100px) {
  .sf-grid { grid-template-columns: minmax(0, 1fr); }
  .sf-preview-wrap { grid-column: 1; grid-row: auto; position: static; }
  .sf-main { grid-row: auto; }
}
@media (max-width: 640px) {
  .sf-contact { grid-template-columns: minmax(0, 1fr); }
  .sf-contact .act { grid-column: 1; }
  .sf-prow { grid-template-columns: minmax(0, 1fr) 90px; }
  .sf-thumb.wide { width: 96px; }
  .sf-actions button { flex: 1 1 100%; }
  textarea { font-size: 16px; }
}
