@font-face { font-family: Sarabun; font-weight: 400; font-display: swap;
  src: url(fonts/sarabun-thai-400.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: Sarabun; font-weight: 400; font-display: swap;
  src: url(fonts/sarabun-latin-400.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Sarabun; font-weight: 600; font-display: swap;
  src: url(fonts/sarabun-thai-600.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: Sarabun; font-weight: 600; font-display: swap;
  src: url(fonts/sarabun-latin-600.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Sarabun; font-weight: 700; font-display: swap;
  src: url(fonts/sarabun-thai-700.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: Sarabun; font-weight: 700; font-display: swap;
  src: url(fonts/sarabun-latin-700.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* แบบ 1b จาก Claude Design: มือถือแถบแดงบน + เมนูล่าง, คอมเมนูซ้าย */
:root {
  --red: #c1272d;
  --red-d: #9e1f24;
  --pink: #fbe9e9;
  --pink-t: #ffe2e2;
  --bg: #f7f4ef;
  --ink: #1f1b18;
  --muted: #6e6862;
  --line: #f0ebe4;
  --edge: #d9d3ca;
  --ok: #1e7a3c;
  --shadow: 0 0 0 1px rgba(60, 30, 10, .06), 0 1px 3px rgba(60, 30, 10, .06);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.5 Sarabun, sans-serif; }
input, select, textarea, button { font: inherit; color: inherit; }
a { color: var(--red-d); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
small { font-size: 14px; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--red-d); }

/* ---------- โครงหน้า ---------- */
.side { display: none; }
.content { min-height: 100vh; }
.main { padding: 14px 16px 120px; display: grid; gap: 14px; align-content: start; }

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 50%; background: #fff; border: 2px solid #fff; flex: none; }
.brand b { font-size: 18px; display: block; line-height: 1.2; }
.brand small { color: var(--pink-t); display: block; }

/* แถบบนของแต่ละหน้า มือถือเป็นแถบแดง คอมเป็นหัวข้อธรรมดา */
.pbar {
  position: sticky; top: 0; z-index: 20; background: var(--red); color: #fff;
  display: grid; grid-template-columns: 84px minmax(0, 1fr) 84px; align-items: center;
  min-height: 56px; padding: 6px 12px;
}
.pbar h1 { font-size: 18px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbar .pb-act { display: flex; justify-content: flex-end; gap: 6px; }
.pbar a, .pbar button.pbtn { color: #fff; text-decoration: none; }
.pb-back { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; font-weight: 600; }
.pbar.tab { grid-template-columns: minmax(0, 1fr) auto; padding: 10px 16px; }
.pbar.tab h1 { text-align: left; font-size: 22px; }
.pill {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, .75); color: #fff; font-size: 15px; white-space: nowrap;
  background: none; cursor: pointer; text-decoration: none;
}

/* หน้าแรก: แถบแดงสูง การ์ดยอดขายลอยทับ */
.hero { background: var(--red); color: #fff; padding: 14px 16px 60px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.home-title { display: none; }
.dash { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: -60px; }
.dash .c1 { grid-column: 1 / -1; }
.big { font-size: 36px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.mid-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; }
.home-grid { display: grid; gap: 14px; }
.qa { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qa .btn { min-height: 54px; }

/* ---------- การ์ด รายการ ---------- */
.card { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; }
.lbl { font-size: 14.5px; color: var(--muted); display: block; }
.sec { font-size: 15px; font-weight: 600; color: var(--muted); margin: 6px 4px -6px; }
.list { background: #fff; border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.li:last-child { border-bottom: 0; }
.li small { display: block; color: var(--muted); }
a.li { transition: background .15s; }
a.li:hover, .li.sel { background: var(--pink); }
.li.void, .li.void .amt { color: #8f8780; }
.li.void .amt { text-decoration: line-through; }
.tag { font-size: 12.5px; padding: 0 8px; border-radius: 99px; background: var(--pink); color: var(--red-d); margin-left: 6px; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 16px; text-align: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat4 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat4 .card { padding: 10px 12px; }
.stat4 b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.split3 { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; gap: 8px; }
.split3 b { display: block; font-variant-numeric: tabular-nums; }
.month { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.month b { font-size: 18px; }
.chg {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--edge); background: #fff; color: var(--ink); font-size: 15px; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links form { margin: 0; }
.flash { background: #eaf6ee; color: var(--ok); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.err { background: var(--pink); color: var(--red-d); border-radius: 12px; padding: 10px 14px; }
.err p + p { margin-top: 2px; }

/* ---------- ช่องกรอก: กล่องครีม ป้ายเล็กด้านบน ---------- */
.fld { display: block; background: var(--bg); border-radius: 10px; padding: 5px 12px 4px; min-height: 54px; position: relative; transition: box-shadow .15s; }
.fld > small { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.25; }
.fld input, .fld select, .fld textarea {
  display: block; width: 100%; border: 0; background: transparent; padding: 2px 0 4px; font-size: 18px;
  font-weight: 600; outline: none; min-height: 30px; font-variant-numeric: tabular-nums;
}
.fld input[type=file] { font-size: 15px; font-weight: 400; }
.fld input::placeholder, .fld textarea::placeholder { color: #a39b92; font-weight: 400; }
.fld:focus-within { box-shadow: 0 0 0 2px var(--red); }
.fld select { appearance: none; -webkit-appearance: none; padding-right: 22px; cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236e6862' stroke-width='2'/%3E%3C/svg%3E") right 2px center no-repeat; }
.fld.num input { text-align: right; }
.form { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.chip span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--edge); background: #fff; font-size: 15px; transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.chip input:checked + span { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.chip input:focus-visible + span { box-shadow: 0 0 0 2px var(--ink); }
.search { display: block; }
.search input {
  width: 100%; min-height: 46px; border: 0; border-radius: 12px; padding: 0 14px; background: #fff;
  box-shadow: 0 0 0 1px rgba(60, 30, 10, .12); font-size: 17px;
}
.search input:focus { outline: 2px solid var(--red); }
details.card > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 32px; }
details.card > summary::after { content: "เปิด"; font-weight: 400; font-size: 14px; color: var(--muted); }
details.card[open] > summary::after { content: "ปิด"; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 12px; }
.edit-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 70px auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.edit-row.cat { grid-template-columns: minmax(0, 1fr) 70px auto; }
.edit-row .fld { min-height: 46px; }
.edit-row .hid { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); }
.edit-row .hid input { width: 20px; height: 20px; accent-color: var(--red); }
.edit-row .acts { justify-content: flex-end; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 50px; padding: 0 18px;
  border: 0; border-radius: 12px; background: #fff; box-shadow: 0 0 0 1px var(--edge); color: var(--ink);
  font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap; text-align: center;
}
.btn.red { background: var(--red); color: #fff; box-shadow: none; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn.xs { min-height: 30px; padding: 0 10px; font-size: 14px; font-weight: 600; border-radius: 99px; color: var(--red-d); box-shadow: 0 0 0 1px #ecc7c8; }
.btn.danger { color: var(--red-d); }
.btn.dashed { background: none; box-shadow: none; border: 1.5px dashed #cfc6ba; width: 100%; color: #4c4640; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.acts { display: flex; flex-wrap: wrap; gap: 8px; }
.acts form { margin: 0; }

/* ---------- เมนูล่าง (มือถือ) ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid #e8e1d7;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; padding: 6px 6px calc(10px + env(safe-area-inset-bottom));
}
.tabs a { text-align: center; padding: 10px 0 6px; font-size: 14px; color: var(--muted); text-decoration: none; position: relative; }
.tabs a.on { color: var(--red); font-weight: 700; }
.tabs a.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 3px; background: var(--red); }
.tabs a.mid { background: var(--red); color: #fff; border-radius: 16px; padding: 13px 0; font-weight: 700; font-size: 15.5px; margin-top: -24px; box-shadow: 0 4px 12px rgba(193, 39, 45, .32); }

/* ---------- ฟอร์มบิล ---------- */
.bf { display: grid; gap: 14px; }
.items { padding-top: 2px; padding-bottom: 2px; }
.items-head { display: none; }
.item { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.item:last-child { border-bottom: 0; }
.it-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; }
.it-head .fld { background: none; padding: 0; min-height: 0; }
.it-head .fld:focus-within { box-shadow: none; }
.it-head .fld select { font-size: 18px; font-weight: 700; }
.it-head .fld > small { display: none; }
.it-amt { font-size: 18px; }
.x { border: 0; background: none; color: var(--muted); font-size: 14px; min-height: 36px; padding: 0 4px; cursor: pointer; }
.it-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.last { font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trays { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trays > .lbl, .trays .last { grid-column: 1 / -1; }
.paybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--red); color: #fff;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.paybar .pb-sum small { display: block; color: var(--pink-t); }
.paybar .pb-sum b { font-size: 26px; font-variant-numeric: tabular-nums; display: inline-block; }
.paybar .pb-name, .paybar .pb-back2 { display: none; }
.paybar .btn.red { background: #fff; color: var(--red-d); }

/* ---------- หน้าบิล ---------- */
.bill-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 18px 18px 16px; }
.bill-card .lg { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); text-align: center; }
.bill-card .lg img { width: 52px; height: 52px; border-radius: 50%; }
.sep { border: 0; border-top: 1.5px dashed #ddd5ca; margin: 12px 0; }
.rl { display: grid; grid-template-columns: 1fr auto; padding: 4px 0; }
.rl small { color: var(--muted); font-variant-numeric: tabular-nums; }
.rl b { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.rt { display: flex; justify-content: space-between; align-items: baseline; }
.rt b { font-size: 28px; color: var(--red-d); font-variant-numeric: tabular-nums; }
.bv { display: grid; gap: 14px; }
.bv-side { display: grid; gap: 10px; }
.bv-side .sumcard { display: none; }
.actbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid #e8e1d7;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px;
}
.paper { display: none; }
.paper.show { display: block; overflow-x: auto; }

/* ---------- เข้าสู่ระบบ ---------- */
body.login { background: var(--red); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: grid; align-content: center; justify-items: center; padding: 24px 16px; gap: 26px; }
.login-brand { display: grid; justify-items: center; gap: 6px; color: #fff; text-align: center; }
.login-brand img { width: 120px; height: 120px; border-radius: 50%; background: #fff; border: 4px solid #fff; }
.login-brand b { font-size: 24px; margin-top: 6px; }
.login-brand span { color: var(--pink-t); }
.login-box { width: 100%; max-width: 380px; display: grid; gap: 12px; padding: 20px; }
.login-box h2 { font-size: 22px; }

/* ---------- คอม: เมนูซ้าย ---------- */
/* ซ่อนอย่างเดียว ไม่ตั้ง display ตอนโชว์ ไม่งั้นทับ display ของปุ่ม (เคยทำ a.pill กลายเป็น inline) */
@media (max-width: 959px) { .d-only { display: none !important; } }
@media (min-width: 960px) {
  .m-only { display: none !important; }
  .app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
  .side {
    display: block; position: sticky; top: 0; height: 100vh; overflow-y: auto; background: #fff;
    border-right: 1px solid #e8e1d7; padding: 18px 14px;
  }
  .side .brand { color: var(--ink); margin-bottom: 22px; }
  .side .brand img { border-color: #f1e9e0; }
  .snav { display: grid; gap: 2px; }
  .snav a { padding: 9px 12px; border-radius: 10px; color: #4c4640; text-decoration: none; transition: background .15s, color .15s; }
  .snav a:hover { background: var(--bg); }
  .snav a.on { background: var(--pink); color: var(--red-d); font-weight: 700; }
  .snav a.go { background: var(--red); color: #fff; font-weight: 700; text-align: center; margin-bottom: 8px; }
  .main { padding: 24px 28px 48px; max-width: 1180px; gap: 18px; }

  .pbar { position: static; background: none; color: var(--ink); display: flex; justify-content: space-between; padding: 24px 28px 0; max-width: 1180px; min-height: 0; }
  .pbar h1, .pbar.tab h1 { font-size: 26px; text-align: left; }
  .pbar a, .pbar button.pbtn { color: var(--red-d); }
  .pb-back { display: none; }
  .pbar .pill { border-color: var(--edge); color: var(--ink); min-height: 40px; background: #fff; }
  .pbar + .main { padding-top: 16px; }

  .hero { display: none; }
  .home-title { display: block; font-size: 26px; font-weight: 700; }
  .dash { grid-template-columns: repeat(3, 1fr); margin-top: 0; }
  .dash .c1 { grid-column: auto; }
  .home-grid { grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
  .home-grid .qa { grid-template-columns: 1fr; grid-column: 2; grid-row: 1 / span 6; }
  .home-grid > :not(.qa) { grid-column: 1; }

  .split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px 20px; align-items: start; }
  .split > .aside { grid-column: 2; grid-row: 1 / span 20; position: sticky; top: 20px; }
  .split > :not(.aside) { grid-column: 1; }
  .split-l { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
  .split-l > .d-only { display: grid; gap: 12px; position: sticky; top: 20px; }
  .stat4 { grid-template-columns: repeat(4, 1fr); }

  .bf { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .bf > :not(.paybar) { grid-column: 1; }
  .paybar {
    grid-column: 2; grid-row: 1 / span 10; position: sticky; top: 20px; left: auto; right: auto; bottom: auto;
    background: #fff; color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); padding: 16px;
    flex-direction: column; align-items: stretch;
  }
  .paybar .pb-sum small { color: var(--muted); }
  .paybar .pb-sum b { font-size: 34px; color: var(--red-d); }
  .paybar .pb-name, .paybar .pb-back2 { display: block; }
  .paybar .btn.red { background: var(--red); color: #fff; }
  .items-head, .item { display: grid; grid-template-columns: 2.2fr 1.6fr 1fr 1fr 1fr 1.2fr 44px; gap: 8px; align-items: center; }
  .items-head { font-size: 13.5px; color: var(--muted); padding: 10px 0 2px; }
  .item { padding: 6px 0; border-bottom: 0; }
  .it-head, .it-nums { display: contents; }
  .it-head .fld { background: var(--bg); padding: 5px 12px; min-height: 44px; }
  .it-head .fld:focus-within { box-shadow: 0 0 0 2px var(--red); }
  .it-head .fld select { font-size: 17px; font-weight: 600; }
  .item .fld { min-height: 44px; padding: 7px 12px; }
  .item .fld > small { display: none; }
  .item .fld input { font-size: 17px; }
  .it-grade { grid-column: 1; grid-row: 1; }
  .it-extra { grid-column: 2; grid-row: 1; }
  .item .it-nums .fld:nth-child(1) { grid-column: 3; grid-row: 1; }
  .item .it-nums .fld:nth-child(2) { grid-column: 4; grid-row: 1; }
  .item .it-nums .fld:nth-child(3) { grid-column: 5; grid-row: 1; }
  .it-amt { grid-column: 6; grid-row: 1; text-align: right; }
  .item .x { grid-column: 7; grid-row: 1; }
  .item .last { grid-column: 1 / -1; grid-row: 2; }
  .trays { grid-template-columns: repeat(4, 1fr); }

  .bv { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .bv .bill-card { display: none; }
  .paper { display: block; }
  .bv-side { position: sticky; top: 20px; }
  .bv-side .sumcard { display: block; }
  .actbar { position: static; padding: 0; border: 0; background: none; grid-template-columns: 1fr; }

  body.login { background: var(--bg); }
  .login-wrap { grid-template-columns: 1fr 1fr; padding: 0; gap: 0; align-content: stretch; }
  .login-brand { background: var(--red); min-height: 100vh; align-content: center; width: 100%; }
  .login-brand img { width: 180px; height: 180px; border-width: 6px; }
  .login-box { justify-self: center; align-self: center; padding: 28px; max-width: 400px; }
}

/* ---------- การเคลื่อนไหว ---------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }

  /* backwards ไม่ใช่ both: ถ้าแอนิเมชันค้างค่า transform ไว้ แถบ position:fixed ข้างในจะไม่ติดขอบจอ */
  .main > * { animation: rise .5s var(--ease) backwards; }
  .main > .bf, .main > .bv { animation: none; }
  .bf > :not(.paybar), .bv-main > *, .bv-side > :not(.actbar) { animation: rise .5s var(--ease) backwards; }
  .bf > :nth-child(3), .bv-side > :nth-child(2) { animation-delay: .06s; }
  .bf > :nth-child(n+4) { animation-delay: .12s; }
  .paybar, .actbar { animation: slideup .45s .1s var(--ease) backwards; }
  .main > *:nth-child(2) { animation-delay: .05s; }
  .main > *:nth-child(3) { animation-delay: .1s; }
  .main > *:nth-child(4) { animation-delay: .15s; }
  .main > *:nth-child(5) { animation-delay: .2s; }
  .main > *:nth-child(6) { animation-delay: .25s; }
  .main > *:nth-child(n+7) { animation-delay: .3s; }
  .list > .li { animation: rise .45s var(--ease) backwards; }
  .list > .li:nth-child(2) { animation-delay: .04s; }
  .list > .li:nth-child(3) { animation-delay: .08s; }
  .list > .li:nth-child(4) { animation-delay: .12s; }
  .list > .li:nth-child(n+5) { animation-delay: .16s; }
  .dash > .card { animation: rise .55s var(--ease) backwards; }
  .dash > .card:nth-child(2) { animation-delay: .07s; }
  .dash > .card:nth-child(3) { animation-delay: .14s; }
  .tabs a.mid { animation: pop .55s .12s var(--ease) both; }
  .login-brand img { animation: pop .7s var(--ease) both; }
  .login-box { animation: rise .6s .15s var(--ease) both; }

  .btn, .chg, .pill { transition: transform .15s var(--ease), box-shadow .15s, background .15s; }
  .btn:active, .chg:active, .pill:active, .tabs a:active { transform: scale(.96); }
  .chip input:active + span { transform: scale(.94); }
  .item.in { animation: rise .35s var(--ease) backwards; }
  .item.out { animation: out .22s ease forwards; }
  .bump { animation: bump .35s var(--ease); }
  .flash { animation: drop .4s var(--ease) both; }
  .flash.gone { animation: fade .5s ease forwards; }
  .fill { animation: fill .7s ease; }
  .paper.show { animation: rise .4s var(--ease) backwards; }
  details.card[open] > summary ~ * { animation: rise .35s var(--ease) backwards; }
  .card.lift { transition: transform .2s var(--ease), box-shadow .2s; }
  @media (hover: hover) {
    .btn:hover { box-shadow: 0 0 0 1px var(--ink); }
    .btn.red:hover { background: var(--red-d); box-shadow: 0 4px 12px rgba(193, 39, 45, .25); }
    .card.lift:hover { transform: translateY(-2px); box-shadow: 0 0 0 1px rgba(60, 30, 10, .06), 0 8px 18px rgba(60, 30, 10, .08); }
  }
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { opacity: 0; transform: scale(.6); } 60% { opacity: 1; transform: scale(1.06); } 100% { transform: none; } }
@keyframes out { to { opacity: 0; transform: translateX(-16px); } }
@keyframes bump { 40% { transform: scale(1.08); } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes fade { to { opacity: 0; } }
@keyframes fill { 0% { background: var(--pink); } 100% { background: var(--bg); } }

/* ---------- ใบบิล A4 และสรุปเดือนที่ปริ้น ---------- */
.sheet {
  position: relative; max-width: 190mm; margin: 0 auto 24px; padding: 14mm 12mm; color: var(--ink);
  background: #fff; font-size: 15px; line-height: 1.5; box-shadow: 0 1px 4px rgba(60, 30, 10, .14);
}
.sh-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.sh-logo { width: 84px; height: 84px; object-fit: contain; }
.sh-title { text-align: right; }
.sh-title h2 { margin: 0; font-size: 24px; color: var(--red); }
.sh-copy { color: var(--muted); }
.sh-top { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.sh-party { display: grid; grid-template-columns: 96px 1fr; gap: 0 8px; margin: 0 0 10px; }
.sh-party dt { color: var(--muted); }
.sh-party dd { margin: 0; }
.sh-doc { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 0; padding: 8px 12px; background: #f5f5f2; border-radius: 6px; }
.sh-doc dt { color: var(--muted); }
.sh-doc dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.sh-buyer { border-top: 1px solid #e5e2dc; padding-top: 10px; }
.sh-items { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
.sh-items th { background: #f5f5f2; font-weight: 600; text-align: left; }
.sh-items th, .sh-items td { padding: 6px 8px; border-bottom: 1px solid #e5e2dc; }
.sh-items th.num, .sh-items td.num { text-align: right; }
.sh-items .n { width: 32px; text-align: center; }
.sh-items tfoot th { background: none; border-top: 2px solid var(--ink); }
.sh-sum { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid #e5e2dc; padding-bottom: 8px; }
.sh-total { font-size: 17px; }
.sh-total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.sh-pay, .sh-note { margin-top: 10px; }
.bank-ic { width: 18px; height: 18px; border-radius: 3px; vertical-align: -3px; margin-right: 5px; }
.sh-note span { margin-left: 10px; white-space: nowrap; }
.sh-terms { margin-top: 6px; font-size: 14px; }
.sh-terms b { color: var(--red); }
.sh-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 48px; text-align: center; }
.sh-sign .line { display: block; border-bottom: 1px dotted var(--ink); height: 28px; margin-bottom: 4px; }
/* บิล: ลูกค้าขอสีแดงเพิ่ม (ตัวอย่าง Canva) เฉพาะใบบิล ไม่ยุ่งกับสรุปเดือน */
.paper .sh-party dt, .paper .sh-pay b, .paper .sh-note b { color: var(--red); }
.paper .sh-doc { background: var(--red); color: #fff; }
.paper .sh-doc dt { color: rgba(255, 255, 255, .85); }
.paper .sh-buyer { border-top-color: var(--red); }
.paper .sh-items thead, .paper .sh-items th { background: var(--red); color: #fff; border-bottom: 0; }
.paper .sh-items td { border-bottom: 1px dashed #e3b8ba; }
.paper .sh-sum { background: var(--red); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; align-items: center; }
.void-mark {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg);
  border: 4px solid var(--red); color: var(--red); font-size: 56px; font-weight: 700; padding: 0 24px; opacity: .55;
}
.big3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.big3 p { padding: 10px; border: 1px solid #e5e2dc; border-radius: 6px; }
.big3 span { display: block; color: var(--muted); font-size: 14px; }
.big3 b { font-size: 20px; font-variant-numeric: tabular-nums; }
.report h3 { margin: 16px 0 6px; font-size: 17px; }
.print-only { display: none; }

@page { size: A4; margin: 10mm; }
@media print {
  body { background: #fff; font-size: 14px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .side, .pbar, .hero, .tabs, .flash, .bill-card, .bv-side, .paybar, .noprint { display: none !important; }
  .app { display: block; }
  .main { padding: 0; display: block; max-width: none; }
  /* ปริ้นทันทีที่เปิดหน้า ของที่ยังเล่นแอนิเมชันจางเข้าอยู่จะออกมาเป็นหน้าว่าง */
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .main > :not(.bv):not(.print-only) { display: none !important; }
  .bv { display: block; }
  .paper, .print-only { display: block !important; }
  .sheet { max-width: none; margin: 0; padding: 0; box-shadow: none; break-after: page; }
  .sheet:last-child { break-after: auto; }
  .sh-sign { margin-top: 40px; }
  /* สรุปเดือนแน่นกว่าบิล เดือนปกติให้จบในหน้าเดียว ยาวกว่านั้นตัดหน้าระหว่างแถว ไม่ตัดกลางแถว */
  .report { font-size: 13px; line-height: 1.35; }
  .report .sh-logo { width: 64px; height: 64px; }
  .report h3 { margin: 10px 0 4px; break-after: avoid; }
  .report .sh-items { margin: 4px 0 6px; }
  .report .sh-items th, .report .sh-items td { padding: 3px 8px; }
  .report .big3 p { padding: 6px 10px; }
  .report tr { break-inside: avoid; }
}

/* ตัวช่วยเล็กๆ (ห้ามใช้ style="" ในหน้า CSP ไม่ยอม) */
.blk { display: block; }
.mt { margin-top: 12px; }
.card.li { border-bottom: 0; }
.chg.danger { color: var(--red-d); }
.sum-dash { margin-top: 0; }
.sum-grid, .set-grid { display: grid; gap: 14px; align-items: start; }
.logo-form { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; align-items: center; }
.logo-form img { width: 72px; height: 72px; object-fit: contain; border-radius: 50%; }
.logo-form .btn { grid-column: 1 / -1; }
@media (min-width: 960px) {
  .sum-grid, .set-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
}
@media (max-width: 520px) {
  .edit-row { grid-template-columns: 1fr 1fr; }
  .edit-row.cat { grid-template-columns: 1fr 1fr; }
  .edit-row > .fld:first-child, .edit-row > .acts { grid-column: 1 / -1; }
}
/* ปุ่มท้ายหน้าไม่โดนแถบปุ่มล่างบัง */
.links > *, .acts > * { scroll-margin-bottom: 120px; }
.li .acts { flex-wrap: nowrap; align-items: center; }
@media (max-width: 520px) {
  .row2:not(.keep) { grid-template-columns: 1fr; }
}
