/* หน้าสมาชิกของลูกค้า (crm.html) — เอกลักษณ์ CHOKDEE POS: แดงของโลโก้ + ใบโคลเวอร์สี่หัวใจ ("โชคดี")
   หน้าตาตั้งใจไม่เหมือนระบบสะสมแต้มเจ้าอื่น: หัวแดงทึบมีลายน้ำโคลเวอร์ ไม่ใช่ไล่สีพีช,
   แต้มเป็นใบโคลเวอร์ไม่ใช่เหรียญ "P", ของรางวัลเป็นตั๋วมีต้นขั้วบอกแต้ม, แถบเมนูลอยมีปุ่มบัตรสมาชิกยกขึ้นตรงกลาง */
:root {
  --red: #E5232B;
  --red-deep: #B3141B;
  --danger: #B3141B;
  --red-tint: #FDEBEC;
  --red-wash: #FFF5F5;
  --ink: #1F1A1B;
  --muted: #776C6E;
  --line: #EDE4E5;
  --ground: #F4F2F2;
  --card: #FFFFFF;
  --line-green: #06C755;
  --ok: #138A4B;
  --radius: 18px;
  --tabbar-h: 66px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--ground); color: var(--ink); font-size: 15px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #1D4ED8; outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; background: var(--ground); }

/* ── หัวร้าน: แดงทึบ ขอบล่างโค้ง ลายน้ำโคลเวอร์ ── */
.shop-head { position: relative; overflow: hidden; display: flex; align-items: center; gap: 12px;
  padding: 22px 18px 58px; color: #fff; background: var(--red); border-radius: 0 0 28px 28px; }
.shop-logo { width: 50px; height: 50px; border-radius: 14px; background: #fff center/cover no-repeat; flex: none; position: relative;
  display: grid; place-items: center; font-weight: 800; font-size: 20px; color: var(--red); overflow: hidden; }
.shop-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shop-text { min-width: 0; position: relative; }
.shop-name { font-weight: 800; font-size: 19px; line-height: 1.25; text-wrap: balance; }
.shop-branch { margin-top: 3px; font-size: 13px; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-branch::before { content: '●'; font-size: 8px; vertical-align: 2px; margin-right: 6px; opacity: .7; }

.view { padding: 0 16px calc(var(--tabbar-h) + 40px); }
.shop-head:not([hidden]) + .view { margin-top: -42px; position: relative; }
.shop-head[hidden] + .view { padding-top: 28px; }
.app.no-tabs .view { padding-bottom: 32px; }

.center-state { min-height: 50vh; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--red-tint); border-top-color: var(--red); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: 0 6px 20px rgba(31,26,27,.07); }
.card + .card { margin-top: 12px; }

/* ── การ์ดแต้ม ── */
.luck { padding: 18px 18px 16px; }
.luck-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.member-name { font-size: 17px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-sub { color: var(--muted); font-size: 13px; }
.points { text-align: right; flex: none; }
.points-num { display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 34px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; line-height: 1; }
.points-lbl { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .02em; margin-top: 4px; }
.goal { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.goal-text { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.goal-text b { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: var(--red-tint); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--red); }
.held { font-size: 12.5px; color: var(--red-deep); margin-top: 8px; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 4px 10px; }
.section-title h2 { font-size: 16px; margin: 0; }
.section-title span { font-size: 12.5px; color: var(--muted); }

/* ── ของรางวัล: ตั๋วมีต้นขั้วแต้ม ── */
.ticket { display: flex; background: var(--card); border-radius: 16px; box-shadow: 0 2px 10px rgba(31,26,27,.05); position: relative; min-height: 96px; }
.ticket + .ticket { margin-top: 10px; }
.stub { width: 86px; flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--red); color: #fff; border-radius: 16px 0 0 16px; position: relative; }
.stub .n { font-size: 26px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stub .u { font-size: 11px; font-weight: 700; opacity: .9; display: flex; align-items: center; gap: 3px; }
.ticket.locked .stub { background: #CDBFC1; }
.ticket::before, .ticket::after { content: ''; position: absolute; left: 77px; width: 18px; height: 18px; border-radius: 50%; background: var(--ground); }
.ticket::before { top: -9px; } .ticket::after { bottom: -9px; }
/* ของรางวัลที่ร้านใส่รูป: ช่องซ้ายเป็นรูปสี่เหลี่ยมจัตุรัส + ป้ายแต้มมุมล่าง */
.ticket.has-img .stub { width: 124px; padding: 10px; background: none; border-radius: 16px 0 0 16px; }
.ticket.has-img::before, .ticket.has-img::after { left: 115px; }
.stub-img { position: relative; width: 104px; height: 104px; border-radius: 12px; overflow: hidden; background: var(--red-tint); }
.stub-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stub-img .pts-badge { position: absolute; left: 6px; bottom: 6px; display: flex; align-items: center; gap: 3px; padding: 2px 8px 2px 6px;
  border-radius: 99px; background: var(--red); color: #fff; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ticket.locked .stub-img img { filter: grayscale(.85); opacity: .7; }
.ticket.locked .stub-img .pts-badge { background: #A8999B; }
.sheet-img { display: block; width: 120px; height: 120px; border-radius: 16px; object-fit: cover; margin: 0 auto 12px; background: var(--red-tint); }
.row .dot.img { padding: 0; overflow: hidden; background: var(--red-tint); }
.row .dot.img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ticket-body { flex: 1; min-width: 0; padding: 13px 14px 12px 16px; display: flex; flex-direction: column; gap: 3px; border-left: 2px dashed var(--line); }
.ticket-name { font-weight: 700; line-height: 1.35; }
.ticket-desc { color: var(--muted); font-size: 13px; }
.ticket-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 6px; }
.tag { font-size: 12px; font-weight: 700; color: var(--red-deep); background: var(--red-tint); padding: 2px 9px; border-radius: 99px; }
.lock-text { font-size: 12.5px; color: var(--muted); font-weight: 600; }

.btn { border: 0; border-radius: 12px; padding: 8px 18px; font-weight: 700; background: var(--red); color: #fff; min-height: 40px; }
.btn:disabled { background: #EEE6E7; color: #9C8F91; cursor: default; }
.btn.block { width: 100%; padding: 13px 18px; font-size: 16px; border-radius: 14px; min-height: 52px; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.btn.line { background: var(--line-green); gap: 10px; }
.btn.line svg { width: 24px; height: 24px; fill: #fff; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
a.btn.block { display: flex; }

/* ── ล็อกอิน / สมัคร / รับแต้ม ── */
.hero { text-align: center; padding: 28px 20px 22px; }
.hero h1 { font-size: 21px; margin: 4px 0 6px; text-wrap: balance; }
.hero p { margin: 0 0 18px; color: var(--muted); }
.hero .big-points { display: inline-flex; align-items: center; gap: 8px; font-size: 52px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; line-height: 1.05; }
.consent { display: flex; gap: 10px; align-items: flex-start; text-align: left; margin: 0 0 16px; font-size: 14px; padding: 12px; border-radius: 12px; background: var(--red-wash); }
.consent input { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; margin: 2px 0 0; flex: none; border: 2px solid var(--line-strong, #c9c3c3); border-radius: 6px; background: #fff; display: grid; place-items: center; cursor: pointer; }
.consent input:checked { background: var(--red); border-color: var(--red); }
.consent input:checked::after { content: ""; width: 5px; height: 10px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.consent input:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.err { color: var(--red-deep); font-weight: 600; font-size: 14px; margin-top: 10px; }
.powered { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 26px 0 0; color: #A79B9D; font-size: 12px; }

/* ── เข้าสู่ระบบด้วยเบอร์ + OTP / ฟอร์มสมัคร ── */
.auth-form { display: grid; gap: 14px; text-align: left; }
.auth .consent { margin: 0; }
.consent a { color: var(--red-deep); font-weight: 700; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input { width: 100%; min-height: 50px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; font: inherit; font-size: 17px; background: #fff; color: var(--ink); }
.field input:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px var(--red-tint); }
.field.static b { font-size: 17px; font-variant-numeric: tabular-nums; padding: 2px 2px 4px; }
.choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice button { min-height: 46px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-weight: 700; color: var(--muted); }
.choice button.on { border-color: var(--red); background: var(--red-wash); color: var(--red-deep); }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.otp-input { width: 100%; min-height: 62px; text-align: center; font: inherit; font-size: 30px; font-weight: 800; letter-spacing: 12px; padding: 8px 0 8px 12px;
  border: 1.5px solid var(--line); border-radius: 14px; font-variant-numeric: tabular-nums; background: #fff; color: var(--ink); }
.otp-input:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px var(--red-tint); }
.ref { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.otp-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; }
.link-btn { background: none; border: 0; padding: 8px 0; min-height: 40px; color: var(--red-deep); font-weight: 700; }
.link-btn:disabled { color: var(--muted); font-weight: 500; cursor: default; }
.sheet .auth p { color: var(--muted); margin: 0 0 16px; }
.sheet .auth h1 { font-size: 18px; margin: 0 34px 6px 0; }
a.row { color: inherit; text-decoration: none; }
.row .dot svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row .dot.line-dot { background: #E6F9EE; color: var(--line-green); }
.row .dot.line-dot svg { fill: currentColor; stroke: none; }

/* ── รหัสให้พนักงานสแกน ── */
.code-box { text-align: center; }
.code-panel { background: #fff; border-radius: 14px; padding: 14px 12px 12px; }
.code-box .qr { width: 210px; height: 210px; margin: 0 auto; display: block; }
.code-box .barcode { display: block; width: 100%; max-width: 290px; height: 60px; margin: 8px auto 0; }
.code-box .code { font-size: 24px; letter-spacing: 3px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 6px; }
.code-box .hint { color: var(--muted); font-size: 13.5px; margin-top: 8px; }
.countdown { display: inline-block; margin-top: 10px; padding: 4px 12px; border-radius: 99px; background: var(--ground); color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.countdown.warn { background: var(--red-tint); color: var(--red-deep); }
.scanned { color: var(--ok); font-weight: 700; margin-top: 10px; }

/* บัตรสมาชิก: การ์ดแดงเหมือนบัตรจริง */
.member-pass { background: linear-gradient(150deg, #C8161E 0%, var(--red-deep) 100%); color: #fff; border-radius: 22px; padding: 18px 16px 16px; border: 4px solid var(--ground); position: relative; overflow: hidden; box-shadow: 0 12px 28px rgba(179,20,27,.28); }
.pass-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; position: relative; text-align: left; }
.pass-head .avatar { width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.2) center/cover no-repeat; display: grid; place-items: center; font-weight: 800; font-size: 18px; flex: none; }
.pass-head .member-name { color: #fff; }
.pass-head .member-sub { color: rgba(255,255,255,.85); }
.pass-head .pts { margin-left: auto; text-align: right; font-weight: 800; font-size: 22px; line-height: 1; }
.pass-head .pts small { display: block; font-size: 11px; font-weight: 700; opacity: .85; margin-top: 3px; }
.member-pass .code-panel { position: relative; color: var(--ink); }

/* ── คูปองของฉัน / ประวัติ / บัญชี ── */
.row-list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 10px rgba(31,26,27,.05); }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 0; background: none; width: 100%; text-align: left; border-bottom: 1px solid var(--line); min-height: 58px; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 12.5px; color: var(--muted); display: block; }
.row .chev { color: var(--muted); font-size: 22px; }
.row .dot { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--red-tint); color: var(--red); font-size: 18px; }
.row .dot.minus { background: var(--ground); color: var(--muted); }
.row .dot.sign { font-size: 20px; font-weight: 800; line-height: 1; }
.amt { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ok); }
.amt.minus { color: var(--muted); }
.profile .avatar { width: 50px; height: 50px; border-radius: 50%; background: var(--red-tint) center/cover no-repeat; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: var(--red); flex: none; }
.seg { display: inline-flex; background: var(--ground); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--red); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.delete-link { display: block; margin: 26px auto 0; background: none; border: 0; color: var(--muted); font-size: 13.5px; text-decoration: underline; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ── แถบเมนูลอย ── */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); width: calc(100% - 24px); max-width: 456px; height: var(--tabbar-h);
  background: var(--card); border-radius: 22px; box-shadow: 0 10px 30px rgba(31,26,27,.16); display: grid; grid-template-columns: repeat(5, 1fr); z-index: 10; }
.tabbar button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--muted); position: relative; padding: 0 2px; }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabbar button.on { color: var(--red); font-weight: 700; }
.tab-card { justify-content: flex-end !important; padding-bottom: 7px !important; }
.tab-card-btn { width: 54px; height: 54px; border-radius: 18px; background: var(--red); color: #fff; display: grid; place-items: center; margin-top: -26px; box-shadow: 0 8px 18px rgba(229,35,43,.4); border: 4px solid var(--ground); }
.tab-card-btn svg { stroke: #fff !important; }
.badge { position: absolute; top: 8px; left: calc(50% + 5px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; line-height: 18px; font-style: normal; }

/* ── หน้าต่างล่าง ── */
.sheet-back { position: fixed; inset: 0; background: rgba(31,20,21,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 480px; border-radius: 24px 24px 0 0; padding: 24px 18px calc(22px + env(safe-area-inset-bottom)); position: relative; max-height: 92vh; overflow-y: auto; }
.sheet-close { position: absolute; top: 8px; right: 10px; width: 40px; height: 40px; border: 0; background: none; font-size: 28px; color: var(--muted); }
.sheet h2 { margin: 0 34px 6px 0; font-size: 18px; }
.sheet .code-panel { border: 1.5px dashed var(--line); margin-top: 12px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 30px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
/* หัวข้อแรกของหน้า (คูปอง/ประวัติ) อยู่บนพื้นแดงของหัวร้าน */
.shop-head:not([hidden]) + .view > .section-title:first-child { color: #fff; margin-top: 0; }
.shop-head:not([hidden]) + .view > .section-title:first-child span { color: rgba(255,255,255,.85); }
