/* MenuDed — ลูกค้าสั่งอาหารผ่าน QR ที่โต๊ะ (มือถือเป็นหลัก) */
:root {
  --to-green: #80bb01;
  --to-green-dark: #5f8c00;
  --to-green-soft: #f3f9e6;
  --to-ink: #1f2937;
  --to-muted: #6b7280;
  --to-line: #e5e7eb;
  --to-bg: #f5f6f2;
  --to-red: #dc2626;
  --to-font: "Noto Sans Thai", "Noto Sans", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans", "Microsoft YaHei", "Noto Sans Myanmar", "Noto Sans Khmer", "Noto Sans Lao", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--to-bg); color: var(--to-ink); font-family: var(--to-font); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.to { max-width: 720px; margin: 0 auto; min-height: 100vh; background: var(--to-bg); }

/* หัว */
.to-head { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: #fff; border-bottom: 1px solid var(--to-line); }
.to-logo { width: 42px; height: 42px; border-radius: 12px; object-fit: cover; flex-shrink: 0; background: #f3f4f6; }
.to-shop { flex: 1; min-width: 0; line-height: 1.25; }
.to-shop b { display: block; font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.to-table { display: inline-flex; align-items: center; gap: 5px; margin-top: 2px; font-size: 13px; font-weight: 700; color: var(--to-green-dark); background: var(--to-green-soft); border-radius: 999px; padding: 1px 10px; }
.to-icon { position: relative; width: 42px; height: 42px; border-radius: 12px; border: 1.5px solid var(--to-line); background: #fff; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.to-dot { position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--to-red); color: #fff; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }

/* ปุ่มภาษา (ธง) */
.lang-dd { position: relative; display: inline-block; }
.lang-btn { height: 42px; width: 46px; border-radius: 12px; border: 1.5px solid var(--to-line); background: #fff; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.lang-btn img { width: 26px; height: 19.5px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }
.lang-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; background: #fff; border: 1px solid var(--to-line); border-radius: 14px; box-shadow: 0 14px 34px rgba(0, 0, 0, .2); padding: 6px; z-index: 60; }
.lang-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 10px; text-align: left; font-size: 15px; font-weight: 700; }
.lang-menu button.on { background: var(--to-green-soft); }
.lang-menu img { width: 24px; height: 18px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }

.to-msg { margin: 10px 14px 0; padding: 10px 12px; border-radius: 12px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; font-size: 14px; line-height: 1.5; }

/* หมวด */
.to-cats { position: sticky; top: 63px; z-index: 20; display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px; background: var(--to-bg); scrollbar-width: none; }
.to-cats::-webkit-scrollbar { display: none; }
.to-cats button { flex-shrink: 0; height: 36px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--to-line); background: #fff; font-size: 14px; font-weight: 700; white-space: nowrap; }
.to-cats button.on { background: var(--to-ink); border-color: var(--to-ink); color: #fff; }

/* รายการเมนู */
.to-list { padding: 0 14px; }
.to-sec { padding-top: 6px; scroll-margin-top: 120px; }
.to-sec h3 { margin: 10px 2px 8px; font-size: 17px; font-weight: 800; }
.to-card { position: relative; display: flex; gap: 12px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--to-line); border-radius: 16px; padding: 12px; margin-bottom: 10px; }
.to-card .tx { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.to-card .nm { font-size: 16px; font-weight: 800; line-height: 1.35; }
.to-card .sub { font-size: 12.5px; color: var(--to-muted); margin-top: 1px; }
.to-card .ds { font-size: 13px; color: var(--to-muted); margin-top: 4px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.to-card .ft { margin-top: auto; padding-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.to-card .pr { font-size: 16px; font-weight: 800; color: var(--to-green-dark); }
.to-card .rec { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; margin-bottom: 3px; padding: 1px 7px; border-radius: 6px; background: #fef3c7; color: #b45309; font-size: 11.5px; font-weight: 800; }
.to-card .rec i { font-size: 10px; color: #f59e0b; }
.to-card.star { border-color: #fcd34d; }
.to-sec + .to-sec { margin-top: 6px; padding-top: 12px; border-top: 1px dashed var(--to-line); }
.to-card .ph { position: relative; width: 96px; height: 96px; flex-shrink: 0; border-radius: 12px; overflow: hidden; background: #f3f4f6; display: flex; align-items: center; justify-content: center; color: #cbd5e1; font-size: 26px; }
.to-card .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.to-card .plus { flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px; background: var(--to-green); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; box-shadow: 0 3px 10px rgba(95, 140, 0, .3); }
.to-card .qty { position: absolute; left: -6px; top: -6px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 999px; background: var(--to-green); color: #fff; font-size: 13px; font-weight: 800; display: none; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.to-card.in .qty { display: inline-flex; }
.to-card.in { border-color: var(--to-green); }
.to-card.off { opacity: .55; }
.to-card.off .plus { display: none; }
.to-card.off .ph::after { content: attr(data-off); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(17, 24, 39, .55); color: #fff; font-weight: 800; font-size: 14px; }
.to-empty { text-align: center; color: var(--to-muted); padding: 50px 10px; }
.to-empty i { font-size: 36px; display: block; margin-bottom: 10px; color: #cbd5e1; }

/* แถบล่าง */
.to-foot-space { height: 96px; }
.to-bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; gap: 10px; max-width: 720px; margin: 0 auto; padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--to-bg) 70%, rgba(245, 246, 242, 0)); }
.to-call { flex-shrink: 0; height: 54px; padding: 0 14px; border-radius: 16px; border: 1.5px solid var(--to-line); background: #fff; font-weight: 800; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.to-call.on { background: #fffbeb; border-color: #f59e0b; color: #b45309; }
.to-cartbtn { flex: 1; height: 54px; border-radius: 16px; border: 0; background: var(--to-green); color: #fff; font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 10px; padding: 0 16px; box-shadow: 0 8px 20px rgba(95, 140, 0, .3); }
.to-cartbtn b { margin-left: auto; }
.to-cartbtn .n { min-width: 28px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, .25); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
.to-cartbtn:disabled { background: #cbd5a8; box-shadow: none; }

/* หน้าต่างเลื่อนขึ้นจากล่าง */
.to-sheet { position: fixed; inset: 0; z-index: 70; background: rgba(17, 24, 39, .5); display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .18s; }
.to-sheet.show { opacity: 1; pointer-events: auto; }
.to-panel { position: relative; width: 100%; max-width: 720px; max-height: 92vh; background: #fff; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; transform: translateY(30px); transition: transform .2s; }
.to-sheet.show .to-panel { transform: none; }
.to-panel-body { overflow-y: auto; padding: 18px 16px 10px; -webkit-overflow-scrolling: touch; }
.to-panel-body h2 { margin: 0 40px 4px 0; font-size: 20px; font-weight: 800; line-height: 1.3; }
.to-panel-foot { display: flex; gap: 10px; align-items: center; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--to-line); }
.to-panel-foot.two > * { flex: 1; }
.to-panel.center { text-align: center; }
.to-panel.center h2 { margin: 10px 0 6px; }
.to-close { position: absolute; right: 12px; top: 12px; z-index: 2; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); font-size: 17px; }
.to-item-img { display: block; width: calc(100% + 32px); max-width: none; margin: -18px -16px 14px; height: 210px; object-fit: cover; border-radius: 22px 22px 0 0; background: #f3f4f6; }
.to-sub { color: var(--to-muted); font-size: 14px; }
.to-desc { color: var(--to-muted); font-size: 14px; line-height: 1.55; margin: 8px 0 4px; }
.to-desc:empty { display: none; }
.to-og { margin-top: 14px; }
.to-og-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; margin-bottom: 8px; }
.to-og-h span { font-size: 12px; font-weight: 700; color: var(--to-muted); background: #f3f4f6; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.to-og-h span.req { color: #b91c1c; background: #fee2e2; }
.to-og.err .to-og-h span.req { background: var(--to-red); color: #fff; }
.to-opt { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 8px 12px; margin-bottom: 6px; border: 1.5px solid var(--to-line); border-radius: 12px; background: #fff; text-align: left; font-size: 15px; font-weight: 600; }
.to-opt .bx { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #cbd5e1; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #fff; }
.to-opt.multi .bx { border-radius: 6px; }
.to-opt.on { border-color: var(--to-green); background: var(--to-green-soft); }
.to-opt.on .bx { background: var(--to-green); border-color: var(--to-green); }
.to-opt .p { margin-left: auto; color: var(--to-muted); font-size: 14px; white-space: nowrap; }
.to-opt-img { width: 64px; height: 64px; flex-shrink: 0; margin: -2px 0; border-radius: 10px; object-fit: cover; background: #f3f4f6; }
.to-input { display: block; width: 100%; margin-top: 14px; padding: 12px; border: 1.5px solid var(--to-line); border-radius: 12px; font: inherit; font-size: 16px; background: #fff; resize: none; }
.to-input:focus { outline: none; border-color: var(--to-green); }
.to-step { display: inline-flex; align-items: center; border: 1.5px solid var(--to-line); border-radius: 14px; height: 52px; flex-shrink: 0; }
.to-step button { width: 46px; height: 100%; border: 0; background: none; font-size: 22px; font-weight: 700; }
.to-step b { min-width: 28px; text-align: center; font-size: 18px; }
.to-primary { flex: 1; height: 52px; border: 0; border-radius: 14px; background: var(--to-green); color: #fff; font-weight: 800; font-size: 16px; padding: 0 14px; }
.to-primary:disabled { opacity: .55; }
.to-primary.wide { width: 100%; }
.to-ghost { height: 52px; border: 1.5px solid var(--to-line); border-radius: 14px; background: #fff; font-weight: 800; font-size: 15px; padding: 0 12px; }
.to-ghost.on { background: #fffbeb; border-color: #f59e0b; color: #b45309; }
.to-ghost:disabled { opacity: .6; }

/* ตะกร้า */
.to-line { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px dashed var(--to-line); }
.to-line .x { flex: 1; min-width: 0; }
.to-line .nm { font-weight: 800; font-size: 15px; }
.to-line .op { font-size: 13px; color: var(--to-green-dark); margin-top: 2px; }
.to-line .nt { font-size: 13px; color: #b45309; margin-top: 2px; }
.to-line .rt { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.to-line .rt b { font-size: 15px; }
.to-line.bad { background: #fef2f2; }
.to-mini { display: inline-flex; align-items: center; border: 1.5px solid var(--to-line); border-radius: 10px; height: 34px; }
.to-mini button { width: 34px; height: 100%; border: 0; background: none; font-size: 18px; font-weight: 700; }
.to-mini span { min-width: 20px; text-align: center; font-weight: 800; }
.to-sum { margin-top: 12px; font-size: 14px; }
.to-sum div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--to-muted); }
.to-sum .grand { color: var(--to-ink); font-size: 18px; font-weight: 800; padding-top: 6px; }
.to-hint { color: var(--to-muted); font-size: 13px; line-height: 1.5; margin: 8px 0 0; }

/* สถานะออเดอร์ของโต๊ะ */
.to-ord { border: 1px solid var(--to-line); border-radius: 14px; padding: 10px 12px; margin-top: 12px; }
.to-ord-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--to-muted); margin-bottom: 4px; }
.to-badge { font-size: 12px; font-weight: 800; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.to-badge.wait { background: #fef3c7; color: #92400e; }
.to-badge.new { background: #e0f2fe; color: #075985; }
.to-badge.cooking { background: #ffedd5; color: #9a3412; }
.to-badge.ready { background: #dcfce7; color: #166534; }
.to-badge.rejected { background: #fee2e2; color: #991b1b; }
.to-ord-i { display: flex; gap: 8px; padding: 5px 0; font-size: 14.5px; }
.to-ord-i .q { font-weight: 800; min-width: 28px; }
.to-ord-i .x { flex: 1; }
.to-ord-i small { display: block; color: var(--to-muted); font-size: 12.5px; }
.to-ord-i .ok { color: #16a34a; }
.to-ord-i.done .x { color: var(--to-muted); }
.to-ord .why { font-size: 13px; color: #991b1b; margin-top: 4px; }

.to-ok { width: 66px; height: 66px; border-radius: 50%; background: var(--to-green-soft); color: var(--to-green-dark); display: inline-flex; align-items: center; justify-content: center; font-size: 30px; margin-top: 6px; }

.to-toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); z-index: 90; max-width: calc(100% - 32px); background: #111827; color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 14.5px; font-weight: 700; opacity: 0; pointer-events: none; transition: all .2s; text-align: center; }
.to-toast.show { opacity: 1; transform: translateX(-50%); }

/* สั่งล่วงหน้า (/pre/{รหัส}) */
.to-table.to-pre-chip { border-radius: 8px; color: #9a3412; background: #ffedd5; }
.to-pre-intro { display: flex; align-items: flex-start; gap: 10px; margin: 10px 14px 0; padding: 11px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--to-line); font-size: 14px; line-height: 1.5; }
.to-pre-intro i { color: #ea580c; font-size: 18px; margin-top: 2px; flex-shrink: 0; }
.to-pre { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--to-line); }
.to-pre h3 { margin: 0 0 2px; font-size: 16px; font-weight: 800; }
.to-fl { display: block; margin-top: 10px; font-size: 13.5px; font-weight: 700; color: #374151; }
.to-fl .to-input { margin-top: 5px; }
.to-fl-row { display: flex; gap: 10px; align-items: flex-end; }
.to-fl-row .grow { flex: 1; min-width: 0; }
.to-step.sm { display: flex; height: 50px; margin-top: 5px; border-radius: 12px; }
.to-step.sm button { width: 42px; }
select.to-input { height: 50px; padding: 0 10px; }
.to-input.err { border-color: var(--to-red); background: #fef2f2; }
.to-hint.to-bad { color: var(--to-red); font-weight: 700; }
.to-badge.off { background: #f3f4f6; color: #6b7280; }
.to-ord.off { opacity: .6; }
.to-ord .info { font-size: 13.5px; color: #374151; margin: 2px 0 4px; }
.to-ord .info b { color: #9a3412; }
.to-ord .ok-t { font-size: 13.5px; color: #166534; font-weight: 700; margin-top: 6px; }
.to-ord .act { margin-top: 4px; text-align: right; }
.to-link { border: 0; background: none; color: var(--to-red); font-weight: 700; font-size: 13.5px; padding: 6px 0; }

/* ใส่รหัส 4 หลักก่อนสั่งล่วงหน้า (/preorder/{id}) */
.pu { padding: 16px 14px 40px; }
.pu-card { background: #fff; border: 1px solid var(--to-line); border-radius: 16px; padding: 22px 16px 18px; text-align: center; }
.pu-ico { width: 60px; height: 60px; border-radius: 16px; background: #ffedd5; color: #c2410c; display: inline-flex; align-items: center; justify-content: center; font-size: 26px; }
.pu-card h1 { margin: 12px 0 6px; font-size: 22px; font-weight: 800; }
.pu-sub { margin: 0; color: var(--to-muted); font-size: 14.5px; line-height: 1.55; }
.pu-sub .en { font-size: 12.5px; }
.pu-state { margin: 14px auto 0; display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 10px; background: #f3f4f6; color: #4b5563; font-size: 13.5px; font-weight: 700; }
.pu-state.ok { background: var(--to-green-soft); color: var(--to-green-dark); }
.pu-state.bad { background: #fef2f2; color: #b91c1c; }
.pu-input { display: block; width: 236px; max-width: 100%; height: 72px; margin: 16px auto 0; border: 2px solid var(--to-line); border-radius: 14px; text-align: center; font: inherit; font-size: 38px; font-weight: 800; letter-spacing: 20px; padding-left: 20px; background: #fff; color: var(--to-ink); }
.pu-input::placeholder { color: #d1d5db; }
.pu-input:focus { outline: none; border-color: var(--to-green); box-shadow: 0 0 0 4px rgba(128, 187, 1, .15); }
.pu-input:disabled { background: #f9fafb; }
.pu-input.shake { animation: puShake .4s; border-color: var(--to-red); }
@keyframes puShake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pu-err { margin: 10px 0 0; color: var(--to-red); font-size: 14px; font-weight: 700; }
.pu-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.pu-btns .to-primary, .pu-btns .to-ghost { width: 100%; flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: inherit; }
.pu-btns .to-primary { color: #fff; }
.pu-note { margin: 12px 0 0; color: var(--to-muted); font-size: 12.5px; line-height: 1.5; }
.pu-steps { list-style: none; margin: 16px 0 0; padding: 14px; background: #fff; border: 1px solid var(--to-line); border-radius: 16px; display: grid; gap: 10px; }
.pu-steps li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.pu-steps b { width: 26px; height: 26px; border-radius: 8px; background: var(--to-green-soft); color: var(--to-green-dark); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.pu-form { text-align: left; margin-top: 6px; }
.pu-form .to-input { margin-top: 5px; }
.pu-who { margin: 14px 0 0; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 12px; border-radius: 12px; background: #fff7ed; color: #9a3412; font-weight: 800; font-size: 14.5px; }
.pu-edit, .to-pre-edit { border: 0; background: none; color: var(--to-green-dark); font-weight: 800; font-size: 13.5px; padding: 2px 4px; display: inline-flex; align-items: center; gap: 5px; }
.pu-loading { color: #cbd5e1; font-size: 28px; padding: 40px 0; }
.to-pre-sum { margin-top: 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #fff7ed; color: #9a3412; font-weight: 700; font-size: 14px; line-height: 1.5; }
.pu-back { display: inline-flex; align-items: center; gap: 6px; margin-top: 16px; color: var(--to-muted); font-weight: 700; font-size: 14px; text-decoration: none; }

/* QR ใช้ไม่ได้ */
.to-closed { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 16px; }
.to-closed i { font-size: 48px; color: #cbd5e1; }
.to-closed h1 { font-size: 22px; margin: 14px 0 6px; }
.to-closed p { color: var(--to-muted); line-height: 1.6; margin: 6px 0; }
.to-closed .en { font-size: 14px; }
.to-brand { margin-top: 18px; color: var(--to-green-dark); font-weight: 800; text-decoration: none; }

@media (min-width: 560px) {
  .to-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .to-grid .to-card { margin-bottom: 0; }
  .to-sheet { align-items: center; }
  .to-panel { border-radius: 22px; max-width: 520px; max-height: 86vh; }
  .to-item-img { border-radius: 22px 22px 0 0; }
}
