/* MK Coin: ใช้ร่วมกันทั้งหน้าร้าน (index.html) และหลังร้าน (admin.html) โทนน้ำเงินเข้ม + ม่วง + ทองตามป้ายเรทของร้าน */
:root {
  --bg: #0b1030;
  --bg-2: #10173f;
  --surface: #151d4a;
  --surface-2: #1c2658;
  --surface-3: #243064;
  --ink: #eef1ff;
  --muted: #a3acd6;
  --line: #2c3770;
  --primary: #7b6cff;
  --primary-2: #2fc7ff;
  --primary-ink: #ffffff;
  --gold: #ffc94a;
  --gold-2: #f29a1f;
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, .14);
  --warn: #ffc14d;
  --warn-soft: rgba(255, 193, 77, .14);
  --bad: #ff6b7d;
  --bad-soft: rgba(255, 107, 125, .14);
  --info: #6cc8ff;
  --info-soft: rgba(108, 200, 255, .14);
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(3, 6, 25, .45);
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Kanit', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --top-bg: rgba(11, 16, 48, .84);
  --card-end: rgba(21, 29, 74, .92);
  --save-bg: rgba(21, 29, 74, .96);
  --placeholder: #6f79a8;
  --toast-bg: #f2f4ff;
  --toast-ink: #121a45;
  --glow-1: rgba(123, 108, 255, .28);
  --glow-2: rgba(47, 199, 255, .14);
  --nav-h: 68px;
  color-scheme: dark;
}
/* โหมดสว่าง (ค่าเริ่มต้นคือมืด ตั้งโดย theme.js) */
:root[data-theme="light"] {
  --bg: #f3f4fb;
  --bg-2: #f6f7fd;
  --surface: #ffffff;
  --surface-2: #eef0fa;
  --surface-3: #e2e6f5;
  --ink: #161b3f;
  --muted: #5a6288;
  --line: #dde1f0;
  --primary: #6352f5;
  --primary-2: #0b93cf;
  --gold: #b36b00;
  --gold-2: #e98a0c;
  --ok: #0d8f5a;
  --ok-soft: rgba(13, 143, 90, .12);
  --warn: #9a5c00;
  --warn-soft: rgba(232, 150, 20, .16);
  --bad: #d23347;
  --bad-soft: rgba(210, 51, 71, .1);
  --info: #0a76b3;
  --info-soft: rgba(10, 118, 179, .1);
  --shadow: 0 14px 40px rgba(30, 40, 90, .12);
  --top-bg: rgba(243, 244, 251, .88);
  --card-end: #ffffff;
  --save-bg: rgba(255, 255, 255, .97);
  --placeholder: #8a91b3;
  --toast-bg: #161b3f;
  --toast-ink: #ffffff;
  --glow-1: rgba(99, 82, 245, .12);
  --glow-2: rgba(11, 147, 207, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(1200px 600px at 85% -10%, var(--glow-1), transparent 60%),
              radial-gradient(900px 500px at -10% 20%, var(--glow-2), transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--ink); font: 16px/1.6 var(--font);
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.3; margin: 0; letter-spacing: .01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; }
h4 { font-size: .95rem; margin-top: 8px; }
p { margin: 0; }
a { color: var(--primary-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; letter-spacing: .02em; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.flip { transform: scaleX(-1); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: 1240px; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 16px; }
.demo-bar { margin: 0; padding: 7px 16px; background: linear-gradient(90deg, var(--gold-2), var(--gold)); color: #3b2200; font-size: .84rem; font-weight: 600; text-align: center; }

/* ---------- แถบบน ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--top-bg); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 4px 12px rgba(255, 201, 74, .35)); }
.brand span { display: grid; line-height: 1.15; min-width: 0; }
.brand b { font-family: var(--font-head); font-size: 1.15rem; }
.brand small { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-nav { display: flex; gap: 4px; }
.top-nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 10px; font-weight: 500; }
.top-nav a:hover { color: var(--ink); background: var(--surface); }
.top-tools { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mode-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); max-width: 280px; }
.mode-pill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-pill .ic { width: 16px; height: 16px; color: var(--gold); }

/* ---------- ปุ่ม / ฟอร์ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 20px; border: 1.5px solid transparent; border-radius: 14px;
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: filter .15s, background-color .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--primary-ink); box-shadow: 0 8px 24px rgba(123, 108, 255, .35); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger-ghost { color: var(--bad); }
.btn-danger-ghost:hover:not(:disabled) { border-color: var(--bad); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .86rem; border-radius: 11px; }
.btn-sm .ic { width: 17px; height: 17px; }
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--primary); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn .ic { width: 17px; height: 17px; }
.link { background: none; border: 0; padding: 0; color: var(--gold); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
:is(.btn, .icon-btn, .chip-btn, .link, .tabs button, .channel input, .mode-card input):focus-visible { outline: 3px solid rgba(47, 199, 255, .55); outline-offset: 2px; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: .9rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.field small { font-size: .8rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-width: 0; padding: 11px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--placeholder); }
select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(47, 199, 255, .2); }
input[type=number] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.check span { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check .ic { width: 18px; height: 18px; color: var(--gold); }
.hint { font-size: .88rem; padding: 9px 12px; border-radius: var(--radius-sm); }
.hint-error { background: var(--bad-soft); color: var(--bad); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: start; }
.row-actions { display: flex; gap: 10px; }
.row-actions .btn-primary { flex: 1; }

.chip-btn { border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .9rem; cursor: pointer; }
.chip-btn:hover { border-color: var(--primary); }
.chip-btn.is-active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.card { background: linear-gradient(180deg, var(--surface), var(--card-end)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 12px; }
.empty { text-align: center; color: var(--muted); padding: 16px 8px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 151, .5); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }

.status { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.status-ok { background: var(--ok-soft); color: var(--ok); }
.status-warn { background: var(--warn-soft); color: var(--warn); }
.status-bad { background: var(--bad-soft); color: var(--bad); }
.status-info { background: var(--info-soft); color: var(--info); }

.summary { margin: 0; display: grid; gap: 0; border-radius: 14px; background: var(--bg-2); border: 1px solid var(--line); overflow: hidden; }
.summary > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 14px; }
.summary > div + div { border-top: 1px solid var(--line); }
.summary dt { color: var(--muted); font-size: .88rem; }
.summary dd { margin: 0; font-weight: 600; text-align: right; display: inline-flex; align-items: center; gap: 6px; overflow-wrap: anywhere; justify-content: flex-end; }
.summary dd.big { font-family: var(--font-head); font-size: 1.35rem; color: var(--gold); }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 3px solid rgba(108, 200, 255, .25); border-top-color: var(--info); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; display: grid; gap: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; display: grid; font-size: .9rem; }
.timeline li::before { content: ''; position: absolute; left: 0; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary-2); }
.timeline li::after { content: ''; position: absolute; left: 4px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li:first-child::before { background: var(--gold); box-shadow: 0 0 0 4px rgba(255, 201, 74, .2); }
.timeline time { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline span { overflow-wrap: anywhere; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; font-weight: 600; color: var(--muted); padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.total-row td, .total-row { background: rgba(123, 108, 255, .1); }
.row-link { cursor: pointer; }
.row-link:hover td { background: rgba(123, 108, 255, .08); }
.row-link:focus-visible { outline: 2px solid var(--primary-2); outline-offset: -2px; }

.search { position: relative; display: block; flex: 1; min-width: 0; }
.search .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 42px !important; }
.track-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.track-item, .feed-item { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; }
.track-item:hover, .feed-item:hover { border-color: var(--primary); }
.t-main { display: grid; flex: 1; min-width: 0; }
.t-main small { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
/* ---------- toast + modal ---------- */
.toasts { position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 440px; padding: 12px 16px; border-radius: 14px; background: var(--toast-bg); color: var(--toast-ink); box-shadow: 0 12px 34px rgba(0, 0, 0, .3); font-size: .92rem; font-weight: 500; animation: toast-in .25s ease-out; }
.toast-success .ic { color: #0e8a55; }
[data-theme="light"] .toast-success .ic { color: #5fe3a6; }
.toast-error { background: var(--bad); color: #fff; }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity .3s, transform .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.modal { border: 1px solid var(--line); padding: 0; border-radius: var(--radius); background: var(--surface); color: var(--ink); width: min(430px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(4, 6, 22, .7); }
.modal[open] { animation: modal-in .2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-box { padding: 22px; display: grid; gap: 10px; }
.modal-box > p { color: var(--muted); }
.modal-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: rgba(123, 108, 255, .18); color: var(--primary-2); }
.modal-danger .modal-icon { background: var(--bad-soft); color: var(--bad); }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.modal-wide { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: hidden; }
.modal-wide .modal-box { max-height: calc(100vh - 34px); overflow-y: auto; }

/* ================= หลังร้าน ================= */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(410px, 100%); padding: 28px 24px; text-align: center; box-shadow: var(--shadow); }
.login-card .field, .login-card .otp-note { text-align: left; }
.login-logo { width: 60px; height: 60px; justify-self: center; }
.otp-note { display: flex; gap: 8px; font-size: .9rem; color: var(--muted); }
.otp-note .ic { color: var(--ok); }
.demo-hint { font-size: .84rem; color: var(--muted); background: var(--bg-2); border-radius: var(--radius-sm); padding: 9px; line-height: 1.7; }
.back-link { font-size: .9rem; }
.is-shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { position: relative; display: inline-flex; align-items: center; gap: 8px; flex: none; padding: 10px 14px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); font-weight: 600; cursor: pointer; }
.tabs button:hover { color: var(--ink); }
.tabs button.is-active { color: var(--ink); border-bottom-color: var(--primary-2); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .74rem; font-style: normal; display: inline-grid; place-items: center; }
.page { padding-top: 20px; padding-bottom: 40px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: grid; gap: 2px; min-width: 0; }
.tile-label { font-size: .82rem; color: var(--muted); }
.tile-value { font-family: var(--font-head); font-weight: 600; font-size: 1.55rem; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile small { font-size: .78rem; color: var(--muted); }
.tile-bad { border-color: rgba(255, 107, 125, .5); }
.tile-bad .tile-value { color: var(--bad); }
.tile-warn .tile-value { color: var(--warn); }
.tile-ok .tile-value { color: var(--ok); }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.ch-name { display: inline-flex; align-items: center; gap: 8px; }
.ch-name .ic { width: 18px; height: 18px; color: var(--primary-2); }
.share { display: inline-block; vertical-align: middle; width: 54px; height: 6px; border-radius: 99px; background: var(--surface-3); margin-right: 8px; overflow: hidden; }
.share i { display: block; height: 100%; background: var(--primary-2); border-radius: 99px; }

.bars { display: grid; grid-template-columns: repeat(14, 1fr); align-items: end; gap: 6px; height: 200px; padding-top: 22px; }
.bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar i { display: block; width: 100%; max-width: 24px; border-radius: 4px 4px 0 0; background: var(--primary); }
.bar.is-today i { background: var(--gold); }
.bar-value { position: absolute; top: -20px; font-size: .7rem; color: var(--muted); white-space: nowrap; }
.bar-label { font-size: .7rem; color: var(--muted); margin-top: 4px; }

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.feed-ch { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); color: var(--primary-2); flex: none; }

.queue { display: grid; gap: 10px; }
.q-card { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--bg-2); }
.q-slip { width: 64px; height: 84px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; color: var(--muted); cursor: pointer; overflow: hidden; padding: 0; }
.q-slip img { width: 100%; height: 100%; object-fit: cover; }
.q-body { display: grid; gap: 3px; min-width: 0; }
.q-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.q-top .muted { display: inline-flex; align-items: center; gap: 4px; }
.q-top .ic { width: 15px; height: 15px; }
.q-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-line > span:first-child { color: var(--muted); font-size: .82rem; width: 62px; }
.q-line .icon-btn { width: 28px; height: 28px; }
.q-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }

.filters { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 12px; }

.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head > div { flex: 1; min-width: 0; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 14px; align-items: start; }
.slip-view { border-radius: 14px; border: 1px solid var(--line); background: var(--bg-2); min-height: 160px; display: grid; place-items: center; padding: 8px; text-align: center; }
.slip-view img { max-width: 100%; max-height: 320px; border-radius: 8px; }
.slip-view p { display: grid; justify-items: center; gap: 6px; }

.stock-card { display: grid; gap: 10px; }
.stock-value { font-family: var(--font-head); font-size: clamp(2rem, 5vw, 2.8rem); line-height: 1.1; color: var(--gold); font-variant-numeric: tabular-nums; }
.stock-value.is-low { color: var(--bad); }

.report-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; }
.reject-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.reject-list li { display: flex; justify-content: space-between; padding: 9px 12px; border-radius: 12px; background: var(--bg-2); }
.reject-list li.total-row { background: rgba(123, 108, 255, .14); }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.mode-card { position: relative; cursor: pointer; }
.mode-card input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.mode-card span { display: grid; gap: 4px; padding: 14px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--bg-2); height: 100%; }
.mode-card .ic { color: var(--gold); width: 24px; height: 24px; }
.mode-card small { color: var(--muted); font-size: .82rem; }
.mode-card input:checked + span { border-color: var(--primary-2); background: rgba(47, 199, 255, .08); }
.mode-card input:focus-visible + span { outline: 3px solid rgba(47, 199, 255, .55); outline-offset: 2px; }
.tier-edit { display: grid; gap: 8px; }
.tier-row { display: grid; grid-template-columns: 1fr 1fr 34px; gap: 10px; align-items: center; }
.tier-head span { font-size: .8rem; color: var(--muted); font-weight: 600; }
.channel-toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.channel-toggles .check { padding: 10px 12px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.channel-toggles small { flex-basis: 100%; }
.save-bar { position: sticky; bottom: 12px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-radius: 16px; background: var(--save-bg); border: 1px solid var(--line); box-shadow: var(--shadow); }
.save-bar [data-dirty] { margin-right: auto; }
.save-bar .is-dirty { color: var(--warn); font-weight: 600; }
.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.user-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--bg-2); }
.user-list div { flex: 1; display: grid; min-width: 0; }
.user-list small { color: var(--muted); font-size: .8rem; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: linear-gradient(135deg, var(--primary), var(--primary-2)); flex: none; }
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 320px; overflow-y: auto; font-size: .86rem; }
.log-list li { display: grid; grid-template-columns: 110px 60px 1fr; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.log-list time { color: var(--muted); }
.log-list span { overflow-wrap: anywhere; }

/* แท็บเปิดใหม่: การ์ดและกล่องโผล่ไล่กัน */
.panel-in > *, .panel-in .tiles > * { animation: panel-up .5s cubic-bezier(.2, .8, .2, 1) backwards; }
.panel-in > :nth-child(2), .panel-in .tiles > :nth-child(2) { animation-delay: 60ms; }
.panel-in > :nth-child(3), .panel-in .tiles > :nth-child(3) { animation-delay: 120ms; }
.panel-in > :nth-child(4), .panel-in .tiles > :nth-child(4) { animation-delay: 180ms; }
.panel-in > :nth-child(5), .panel-in .tiles > :nth-child(5) { animation-delay: 240ms; }
.panel-in .bar i { animation: bar-grow .8s cubic-bezier(.2, .8, .2, 1) backwards; transform-origin: bottom; }
@keyframes panel-up { from { opacity: 0; transform: translateY(16px); } }
@keyframes bar-grow { from { transform: scaleY(0); } }
.chip-date { display: inline-flex; align-items: center; gap: 6px; }
.chip-date .ic { width: 16px; height: 16px; }
.tile, .q-card, .feed-item, .track-item { transition: transform .2s, border-color .2s, box-shadow .2s; }
@media (hover: hover) {
  .tile:hover { transform: translateY(-3px); border-color: var(--primary); box-shadow: 0 12px 30px rgba(3, 6, 25, .25); }
  .q-card:hover { border-color: var(--primary); }
}

/* ---------- จอเล็ก ---------- */
@media (max-width: 980px) {
  .rates-wrap, .grid-main { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border: 1px solid var(--line); border-radius: 14px; padding: 6px 4px; margin-bottom: 8px; background: var(--bg-2); }
  .table-cards td { border: 0; padding: 4px 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: right; }
  .table-cards td.num { text-align: right; }
  .table-cards td[data-label]::before { content: attr(data-label); font-size: .78rem; color: var(--muted); font-weight: 600; text-align: left; flex: none; }
  .table-cards td.empty { justify-content: center; }
  .q-card { grid-template-columns: 56px 1fr; }
  .q-slip { width: 56px; height: 74px; }
  .q-actions { grid-column: 1 / -1; flex-direction: row; }
  .q-actions .btn { flex: 1; }
  .detail-grid { grid-template-columns: 1fr; }
  .mode-pill { display: none; }
  .log-list li { grid-template-columns: 1fr auto; }
  .log-list span { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .card { padding: 16px; }
  .track-item, .feed-item { flex-wrap: wrap; }
  .t-main { flex-basis: calc(100% - 50px); }
  .t-main b { overflow-wrap: anywhere; }
  .filters { grid-template-columns: 1fr; }
  .top [data-logout] span { display: none; }
  .tile-value { font-size: 1.3rem; }
  .bars { gap: 3px; }
  .bar-value { display: none; }
  .modal-actions .btn { flex: 1; }
  .summary > div { flex-wrap: wrap; }
}
/* ---------- ปุ่มธีม ---------- */
.theme-btn { width: 40px; height: 40px; border-radius: 12px; }
.theme-btn .ic { width: 19px; height: 19px; color: var(--gold); }
.login { position: relative; }
.login-theme { position: absolute; top: 16px; right: 16px; }

/* ---------- เมนูล่าง + แผ่นเมนู (แบบแอปมือถือ) ---------- */
.bottom-nav { display: none; }
.sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85vh; background: transparent; color: var(--ink); }
.sheet::backdrop { background: rgba(4, 6, 22, .6); }
.sheet[open] .sheet-box { animation: sheet-up .25s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
.sheet-box { background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 6px; box-shadow: var(--shadow); max-width: 560px; margin: 0 auto; }
.sheet-grip { justify-self: center; width: 42px; height: 5px; border-radius: 99px; background: var(--line); margin-bottom: 8px; }
.sheet-user { color: var(--muted); font-size: .85rem; padding: 0 4px 6px; }
.sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 10px 14px; border-radius: 14px; border: 0; background: var(--bg-2); color: var(--ink); text-decoration: none; font-weight: 500; text-align: left; cursor: pointer; }
.sheet-item .ic { color: var(--primary-2); }
.sheet-item.is-danger, .sheet-item.is-danger .ic { color: var(--bad); }
.sheet-item:hover { background: var(--surface-2); }
.sheet .btn { margin-top: 6px; }

@media (max-width: 899px) {
  body { padding-bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); }
  .demo-bar { font-size: .76rem; padding: 5px 12px; }
  .top-in { min-height: 56px; }
  .brand-mark { width: 34px; height: 34px; }
  .top-nav, .tabs, .desktop-only { display: none !important; }
  .page { padding-top: 14px; }

  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; align-items: flex-end;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
    background: var(--top-bg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); box-shadow: 0 -8px 30px rgba(3, 6, 25, .18);
  }
  .bottom-nav > a, .bottom-nav > button {
    position: relative; flex: 1; min-width: 0; height: var(--nav-h);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: none; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav > * > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottom-nav .ic { width: 23px; height: 23px; }
  .bottom-nav .is-current, .bottom-nav .is-active { color: var(--primary-2); }
  .bottom-nav .badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; font-size: .68rem; }
  /* ปุ่ม Home วงกลมเด่นตรงกลาง */
  .bottom-nav .nav-home { justify-content: flex-end; padding-bottom: 9px; color: var(--ink); }
  .nav-home i {
    position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
    width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(145deg, #ffd66b, #f29a1f); color: #4a2600;
    border: 5px solid var(--bg); box-shadow: 0 10px 24px rgba(242, 154, 31, .45);
    transition: transform .15s;
  }
  .nav-home i .ic { width: 28px; height: 28px; stroke-width: 2.3; }
  .nav-home:active i { transform: translateX(-50%) scale(.93); }
  .nav-home.is-current, .nav-home.is-active { color: var(--gold); }
  .nav-home.is-current i, .nav-home.is-active i { box-shadow: 0 0 0 3px rgba(255, 201, 74, .35), 0 10px 24px rgba(242, 154, 31, .5); }
  .nav-home .badge { top: -4px; left: auto; right: -6px; }
  .bottom-nav > :focus-visible { outline: 3px solid rgba(47, 199, 255, .55); outline-offset: -4px; border-radius: 14px; }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; border-radius: 16px; }
  .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .tile-value { font-size: 1.25rem; }
  .toasts { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
  .save-bar { bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }

}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- VIP (ใช้ทั้งหน้าร้านและหลังร้าน) ---------- */
.vip-badge {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px 1px 6px; border-radius: 999px; flex: none;
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; white-space: nowrap;
  background: linear-gradient(135deg, #ffe08a, #f2a51f); color: #4a2600; box-shadow: 0 3px 10px rgba(242, 165, 31, .35);
}
.vip-badge .ic { width: 13px; height: 13px; stroke-width: 2.4; }
.vip-bar { display: block; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.vip-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold-2), var(--gold)); transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.tile-gold { border-color: rgba(255, 201, 74, .5); background: linear-gradient(135deg, rgba(255, 201, 74, .14), var(--surface) 70%); }
.tile-gold .tile-value { color: var(--gold); }
[data-theme="light"] .tile-gold .tile-value { color: #b86e00; }

/* ---------- หลังร้าน: ลูกค้า (อันดับ + VIP) ---------- */
.c-head { flex-wrap: wrap; gap: 10px; }
.c-head .chip-btn { display: inline-flex; align-items: center; gap: 6px; }
.c-head .chip-btn .ic { width: 16px; height: 16px; }
.c-search { display: block; max-width: 360px; margin: 12px 0 6px; }
.c-rank { width: 32px; height: 32px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--surface-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.c-top-1 .c-rank { background: linear-gradient(145deg, #ffe08a, #f29a1f); color: #3b2200; }
.c-top-2 .c-rank { background: linear-gradient(145deg, #eef2ff, #9aa6c8); color: #1d2440; }
.c-top-3 .c-rank { background: linear-gradient(145deg, #ffc9a1, #c26a2d); color: #3b1a00; }
.c-copy { width: 30px; height: 30px; margin-left: 6px; vertical-align: middle; }
.c-copy .ic { width: 15px; height: 15px; }
.c-progress { display: grid; gap: 4px; min-width: 150px; }
.c-progress small { color: var(--muted); font-size: .76rem; white-space: nowrap; }
