/* ธีม: กรมท่า–ทอง (โรงเรียนละหานทรายรัชดาภิเษก) — หัวเว็บกรมท่าไล่เฉด เส้นทองบาง การ์ดขาวสะอาด */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --ink: #14213d;
  --muted: #5b6680;
  --line: #dfe5ef;
  --navy: #0b2a5b;
  --navy-2: #1d4e9e;
  --gold: #c9a227;
  --gold-soft: #fbf3d9;
  --gold-ink: #6b5200;
  --brand: var(--navy);
  --brand-ink: #ffffff;
  --danger: #c0352b;
  --danger-soft: #fde6e3;

  --st-available: #16a37a;
  --st-pending: #f0a020;
  --st-paid: #3b82f6;
  --st-confirmed: #9aa6ba;

  --radius: 16px;
  --shadow: 0 10px 30px rgba(11, 42, 91, .10);
  --f-display: "Prompt", "Sarabun", system-ui, sans-serif;
  --f-body: "Sarabun", system-ui, sans-serif;
  --f-mono: ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1222; --surface: #121c33; --ink: #e8edf7; --muted: #95a1ba; --line: #24314f;
    --brand: #2c62c0; --gold: #e0bd4f; --gold-soft: #2e2710; --gold-ink: #f1d57e;
    --danger: #f2877d; --danger-soft: #3a1b1a; --st-confirmed: #56627a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--f-body); font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy-2); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; text-wrap: balance; }

.wrap { max-width: 1100px; margin: 0 auto; padding-inline: 16px; }

/* ----- header ----- */
.hero { position: relative; overflow: hidden; color: #fff; padding-block: 26px 22px;
  background: radial-gradient(120% 140% at 100% 0%, var(--navy-2) 0%, var(--navy) 55%, #071a3a 100%);
  border-bottom: 3px solid var(--gold); }
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 240px; height: 240px; border-radius: 50%;
  border: 1px solid rgba(233, 201, 106, .35); box-shadow: 0 0 0 26px rgba(233, 201, 106, .06), 0 0 0 56px rgba(233, 201, 106, .04); pointer-events: none; }
.hero .wrap { position: relative; z-index: 1; }
.eyebrow { color: #e9c96a; font-family: var(--f-display); font-weight: 500; font-size: .92rem; letter-spacing: .04em; }
.hero h1 { margin: 2px 0 0; font-size: clamp(1.45rem, 4.6vw, 2.2rem); line-height: 1.3; }
.hero .meta { margin-top: 6px; opacity: .88; }
.hero .price { display: inline-block; margin-top: 12px; background: var(--gold); color: #1d1600; border-radius: 999px; padding: 4px 14px; font-weight: 700; font-family: var(--f-display); }

.banner { margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--gold-soft); color: var(--gold-ink); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); }
.banner a { color: inherit; font-weight: 700; }

/* ----- legend & toolbar ----- */
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 10px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .92rem; }
.chip b { font-variant-numeric: tabular-nums; font-family: var(--f-display); }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.available { background: var(--st-available); }
.dot.pending { background: var(--st-pending); }
.dot.paid { background: var(--st-paid); }
.dot.confirmed { background: var(--st-confirmed); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .grow { flex: 1; min-width: 140px; }
.zoom { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.zoom button { border: 0; background: none; width: 42px; height: 40px; font-size: 1.2rem; cursor: pointer; }
.zoom button + button { border-left: 1px solid var(--line); }

/* ----- map ----- */
.map-scroll { position: relative; max-width: 720px; margin-inline: auto; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 72vh; }
.map-canvas { position: relative; width: 100%; container-type: inline-size; background-size: 100% 100%; background-repeat: no-repeat; background-color: var(--surface); }
.map-canvas:not(.has-bg) { background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px; }
.map-canvas:not(.has-bg)::before { content: "เวที"; position: absolute; left: 30%; right: 30%; top: 2%; height: 7%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; border-radius: 10px; border-bottom: 3px solid var(--gold);
  font-family: var(--f-display); font-weight: 600; font-size: 2.2cqw; letter-spacing: .12em; }

.tbl { position: absolute; transform: translate(-50%, -50%); width: calc(var(--tsize) * 1%); aspect-ratio: 1; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.9); color: #fff; font-family: var(--f-display); font-weight: 600; padding: 0; cursor: pointer;
  font-size: calc(var(--tsize) * .34cqw); line-height: 1; display: grid; place-items: center; font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 5px rgba(11, 42, 91, .25); transition: transform .12s, box-shadow .12s, background-color .3s; -webkit-tap-highlight-color: transparent; }
.tbl.st-available { background: var(--st-available); }
.tbl.st-pending { background: var(--st-pending); }
.tbl.st-paid { background: var(--st-paid); }
.tbl.st-confirmed { background: var(--st-confirmed); }
.tbl:not(.st-available) { cursor: default; }
.tbl.st-available:hover { transform: translate(-50%, -50%) scale(1.15); z-index: 2; box-shadow: 0 6px 14px rgba(11, 42, 91, .3); }
.tbl:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.tbl.sel, .tbl.hit { outline: 3px solid var(--gold); outline-offset: 2px; z-index: 3; }
.tbl.mine { box-shadow: 0 0 0 3px var(--gold); }
.editing .tbl { cursor: grab; touch-action: none; }
.editing .tbl.dragging { cursor: grabbing; transform: translate(-50%, -50%) scale(1.25); z-index: 5; box-shadow: var(--shadow); }

/* ----- cards / forms ----- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.section-title { font-size: 1.15rem; margin: 26px 0 10px; }
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: .95rem; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 9px 16px; cursor: pointer; font-weight: 600; min-height: 42px; font-family: var(--f-display); transition: filter .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--navy), var(--navy-2)); border-color: var(--navy); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1d1600; }
.btn.ok { background: var(--st-available); border-color: var(--st-available); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 5px 11px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

/* ----- sheet (modal) ----- */
.overlay { position: fixed; inset: 0; background: rgba(5, 14, 32, .6); backdrop-filter: blur(3px); display: none; align-items: flex-end; justify-content: center; z-index: 50; }
.overlay.open { display: flex; }
.sheet { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--shadow); border-top: 4px solid var(--gold); }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.x { border: 0; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }

.timer { text-align: center; margin: 12px 0; padding: 12px; border-radius: 14px; background: var(--gold-soft); color: var(--gold-ink); }
.timer .t { font-family: var(--f-display); font-size: 2.3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.timer.urgent { background: var(--danger-soft); color: var(--danger); }

.bank { border-radius: 14px; padding: 14px 16px; margin: 10px 0; color: #fff; background: linear-gradient(135deg, var(--navy), var(--navy-2)); position: relative; overflow: hidden; }
.bank::after { content: ""; position: absolute; inset: auto -30px -40px auto; width: 120px; height: 120px; border-radius: 50%; border: 18px solid rgba(233, 201, 106, .18); }
.bank .acc { font-family: var(--f-display); font-size: 1.5rem; font-weight: 600; letter-spacing: .06em; font-variant-numeric: tabular-nums; color: #f3d67a; }
.bank .muted { color: rgba(255,255,255,.75); }
.bank .btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.code { font-family: var(--f-mono); font-weight: 700; letter-spacing: .06em; }

.slip-preview { margin-top: 10px; max-width: 100%; max-height: 260px; border-radius: 12px; border: 1px solid var(--line); display: none; }
.success { text-align: center; padding: 8px 0; }
.success .big { font-size: 3rem; line-height: 1; }

/* ----- my bookings ----- */
.mine-list { display: grid; gap: 10px; }
.mine-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .84rem; font-weight: 600; color: #fff; background: var(--muted); white-space: nowrap; }
.badge.pending { background: var(--st-pending); }
.badge.paid { background: var(--st-paid); }
.badge.confirmed { background: var(--st-available); }
.badge.expired, .badge.cancelled { background: var(--st-confirmed); }
.badge.rejected { background: var(--danger); }

footer { padding: 30px 0 40px; color: var(--muted); font-size: .9rem; text-align: center; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 30px); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }
#toast.good { background: var(--st-available); color: #fff; }

/* ----- admin ----- */
.topbar { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; border-bottom: 3px solid var(--gold); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar .muted { color: rgba(255,255,255,.75); }
.topbar .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px; cursor: pointer; font-weight: 600; color: rgba(255,255,255,.7); border-bottom: 3px solid transparent; white-space: nowrap; font-family: var(--f-display); margin-bottom: -3px; }
.tabs button.on { color: #fff; border-bottom-color: var(--gold); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.stat .n { font-family: var(--f-display); font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .88rem; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select { width: auto; }
.filters input { flex: 1; min-width: 180px; }
.blist { display: grid; gap: 10px; }
.bitem { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.bitem.need { border-color: var(--st-paid); box-shadow: inset 4px 0 0 var(--st-paid); }
.bitem .top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.bitem .tno { font-family: var(--f-display); font-size: 1.25rem; font-weight: 600; }
.bitem .info { margin: 6px 0 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2px 16px; font-size: .95rem; }
.bitem .info > div { min-width: 0; overflow-wrap: anywhere; }
.bitem .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.checks { display: grid; gap: 4px; margin: 0 0 8px; }
.flag { padding: 6px 10px; border-radius: 10px; font-size: .92rem; }
.flag.red { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.flag.amber { background: var(--gold-soft); color: var(--gold-ink); }
.check-ok { font-size: .9rem; color: var(--st-available); }
.slip-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.hidden { display: none !important; }
.login { max-width: 420px; margin: 12vh auto; text-align: center; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ----- sold out ----- */
.sold-stamp { position: absolute; right: 16px; bottom: -6px; transform: rotate(-8deg); font-family: var(--f-display); font-weight: 700;
  font-size: clamp(1.3rem, 5vw, 2rem); letter-spacing: .08em; color: #fff; background: #c0352b; border: 3px solid #fff;
  padding: 2px 16px; border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.3); }
.banner.sold { background: var(--danger-soft); color: var(--danger); border-color: transparent; font-weight: 600; }
.is-soldout .map-scroll { filter: grayscale(.4); }

/* ----- crest / lookup / line ----- */
.hero-grid { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.hero-grid > div { min-width: 0; }
.crest { width: 64px; height: auto; filter: drop-shadow(0 3px 8px rgba(0,0,0,.35)); }
@media (max-width: 480px) { .crest { width: 52px; } }
.hero-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.hero-actions .price { margin-top: 0; }
.hero-link { color: #fff; font-family: var(--f-display); font-weight: 500; text-decoration: none; border: 1px solid rgba(255,255,255,.35); padding: 3px 12px; border-radius: 999px; }
.hero-link:hover { background: rgba(255,255,255,.12); }
.info-card { margin-top: 22px; }
.line-card { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.line-card img { width: 140px; height: 140px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.line-card > div { flex: 1; min-width: 180px; }
.line-btn { background: #06c755; border-color: #06c755; color: #fff; text-decoration: none; }
.lk-item { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.lk-item .tno { font-family: var(--f-display); font-weight: 600; font-size: 1.3rem; }

/* การ์ดสถิติกดได้ */
button.stat { text-align: left; cursor: pointer; font: inherit; color: inherit; transition: border-color .15s, transform .1s, box-shadow .15s; }
button.stat:hover { border-color: var(--navy-2); box-shadow: 0 4px 14px rgba(11,42,91,.12); }
button.stat:active { transform: translateY(1px); }
button.stat.on { border-color: var(--gold); box-shadow: inset 0 -3px 0 var(--gold); }

/* ----- VIP กลางผัง + โต๊ะเครื่องดื่ม (ตำแหน่งเป็น % ตรงกับกริดใน seedTables) ----- */
.decor-layer { position: absolute; inset: 0; pointer-events: none; }
.decor-layer[hidden] { display: none; }
.vip-block { position: absolute; left: 50%; top: 10.27%; height: 38.27%; width: 7.2%; transform: translateX(-50%);
  display: grid; grid-template-rows: repeat(7, 1fr); border: 2px solid var(--gold); border-radius: 8px; overflow: hidden;
  pointer-events: auto; cursor: not-allowed; box-shadow: 0 2px 6px rgba(11,42,91,.25); }
.vip-block span { display: grid; place-content: center; text-align: center; line-height: 1; gap: 1px;
  background: linear-gradient(135deg, #e7c766, #c9a227); color: #2a1f00; font-family: var(--f-display); font-weight: 700;
  font-size: 1.6cqw; border-bottom: 1px solid rgba(42,31,0,.25); }
.vip-block span:last-child { border-bottom: 0; }
.vip-block small { font-size: 1.2cqw; font-weight: 600; opacity: .7; }
.drink-table { position: absolute; left: 50%; top: 56.73%; width: 7.2%; aspect-ratio: 1; transform: translate(-50%, -50%);
  display: grid; place-content: center; text-align: center; line-height: 1.1; border-radius: 8px;
  background: #7c5cc4; color: #fff; border: 2px solid rgba(255,255,255,.85); box-shadow: 0 2px 6px rgba(11,42,91,.25);
  font-family: var(--f-display); font-size: 1.15cqw; pointer-events: auto; cursor: help; }
.drink-table b { font-size: 2.2cqw; }
.sq { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sq.vip { background: linear-gradient(135deg, #e7c766, #c9a227); }
.sq.drink { background: #7c5cc4; }

/* ----- ลบรูปสลิป ----- */
.slip-wrap { position: relative; display: inline-block; margin-top: 10px; max-width: 100%; }
.slip-wrap .slip-preview { display: block; margin-top: 0; }
.slip-x { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(20,24,40,.75); color: #fff; font-size: 1.3rem; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.slip-x:hover { background: var(--danger); }

/* โครงผังระหว่างโหลด */
.tbl.st-loading { background: var(--line); color: var(--muted); border-color: transparent; box-shadow: none; cursor: progress; animation: tblPulse 1.2s ease-in-out infinite; }
@keyframes tblPulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .tbl.st-loading { animation: none; } }

/* ----- เลือกหลายโต๊ะ ----- */
.tbl.picked { outline: 3px solid var(--gold); outline-offset: 2px; z-index: 4; transform: translate(-50%, -50%) scale(1.12); }
.tbl.picked::after { content: "✓"; position: absolute; top: -18%; right: -18%; width: 46%; aspect-ratio: 1; border-radius: 50%;
  background: var(--gold); color: #1d1600; display: grid; place-items: center; font-size: 70%; font-weight: 700; border: 1.5px solid #fff; }
.pick-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface); border-top: 3px solid var(--gold);
  box-shadow: 0 -8px 24px rgba(11,42,91,.18); padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
.pb-inner { display: flex; gap: 8px; align-items: center; }
.pb-info { flex: 1; min-width: 0; }
.pb-total { color: var(--muted); font-weight: 600; }
.pb-labels { font-family: var(--f-display); font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-bar .btn { flex: 0 0 auto; }
body.has-pickbar { padding-bottom: 90px; }
body.has-pickbar #toast { bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }

/* ----- แนบสลิปหลายรูป ----- */
.slip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.slip-grid:empty { display: none; }
.slip-grid .slip-wrap { margin-top: 0; display: block; }
.slip-grid .slip-preview { width: 100%; height: 150px; object-fit: cover; max-height: none; }
.slip-no { position: absolute; left: 6px; top: 6px; background: var(--navy); color: #fff; border-radius: 999px; font-size: .78rem; padding: 0 8px; font-weight: 700; }
.slip-add { margin-top: 8px; border-style: dashed; width: 100%; }
/* ----- จ่ายภายหลัง ----- */
.paylater { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); text-align: center; }
.paylater p { margin: 6px 0 0; }
.timer.later { background: var(--gold-soft); color: var(--gold-ink); }
.timer.later .t { font-size: 1.5rem; }
.badge.later { background: #7c5cc4; }
.slip-list { display: grid; gap: 10px; }

.about-card p { line-height: 1.7; }
.safe-list { margin: 8px 0 12px; padding-left: 1.2em; line-height: 1.7; }
.safe-list li { margin: 2px 0; }
footer .small { margin-top: 6px; opacity: .85; }
