/* HARN KA KHAO — ขอบดำหนา เงาทึบ พื้นครีม (สไตล์เดิม) แต่ตัวหนังสือใหญ่ขึ้น ปุ่มกดง่ายขึ้น */
:root {
    --ink: #121212;
    --paper: #FAF9F6;
    --sand: #EAE8E1;
    --card: #FFFFFF;
    --muted: #595959;      /* 7:1 บนพื้นขาว */
    --accent: #F0A028;     /* ส้มจากโลโก้ */
    --ok: #0E7A4B;
    --ok-bg: #E7F6EE;
    --warn: #8A5300;
    --warn-bg: #FFF4E0;
    --danger: #B42318;
    --radius: 14px;
    --shadow: 4px 4px 0 var(--ink);
    --tap: 44px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Prompt', system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--paper);
    color: var(--ink);
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--accent); padding: 8px 12px; border-radius: 8px; color: var(--ink); }
.skip:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.topbar { background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.topbar-in { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 10px; background: #fff; }
.brand-name { margin: 0; font-weight: 800; letter-spacing: .12em; font-size: 14px; }
.brand-sub { margin: 0; font-size: 12px; color: #BDBDBD; }

/* ---------- layout ---------- */
main.wrap { padding-top: 20px; }   /* ต้องเจาะจงกว่า .wrap ไม่งั้นโดนทับเป็น 0 */
section > * + * { margin-top: 16px; }
.card {
    background: var(--card);
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.card > * + * { margin-top: 14px; }
.card-dark { background: var(--ink); color: #fff; }
.card-dark .eyebrow, .card-dark .small { color: #D4D4D4; }
.h { margin: 0; font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; }
.pill { margin-left: auto; font-size: 13px; font-weight: 600; background: var(--sand); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; margin: 0; }
.opt { font-weight: 400; color: var(--muted); }
.label { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.or { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid3 .field { margin: 0; }

/* ---------- segmented tabs ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--sand); border: 2px solid var(--ink); border-radius: var(--radius); }
.seg button { min-height: var(--tap); border: 0; border-radius: 10px; background: transparent; font-weight: 600; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--ink); color: #fff; font-weight: 800; }

/* ---------- form ---------- */
.field { display: block; }
.field > label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], select {
    width: 100%;
    min-height: var(--tap);
    padding: 8px 12px;
    border: 2px solid var(--ink);
    border-radius: 10px;
    background: #fff;
    font-size: 16px;   /* <16px แล้ว iPhone จะซูมเข้าเองตอนแตะ */
    font-weight: 600;
}
input::placeholder { color: #8C8C8C; font-weight: 400; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px; }
.input-xl { font-size: 28px !important; font-weight: 800 !important; min-height: 60px !important; }
.w-price { flex: 0 0 96px !important; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.hint.bad { color: var(--danger); font-weight: 600; }
.hint.good { color: var(--ok); font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; font-weight: 600; }
.check input { width: 24px; height: 24px; accent-color: var(--ink); flex: none; }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.stepper input { text-align: center; font-size: 20px; }
.stepper .btn { font-size: 26px; padding: 0; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--tap); padding: 8px 16px;
    border: 2px solid var(--ink); border-radius: 10px;
    background: #fff; font-weight: 800; font-size: 15px;
    cursor: pointer; text-decoration: none; color: var(--ink);
    transition: transform .08s, background .15s;
    touch-action: manipulation;
}
.btn:active { transform: translate(1px, 1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-accent { background: var(--accent); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.btn-outline:hover { background: var(--sand); }
.btn-ghost-dark { background: transparent; color: #fff; border-color: #555; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); }
.btn-text { border: 0; background: none; padding: 0; min-height: var(--tap); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.btn-text-light { border: 0; background: none; color: var(--accent); font-weight: 800; min-height: 36px; cursor: pointer; }
.btn-sm { min-height: 36px; font-size: 13px; padding: 4px 12px; }
.btn-block { display: flex; width: 100%; }
.grow { flex: 1; }
.actions { display: flex; gap: 10px; }
.actions > * { flex: 1; }
.actions form { display: flex; }
.actions form .btn { flex: 1; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center;
    min-height: 40px; border: 2px solid var(--ink); border-radius: 999px;
    background: #fff; font-weight: 600; font-size: 15px; overflow: hidden;
}
.chip > span { padding: 0 4px 0 14px; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip > button { min-width: 40px; min-height: 40px; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; }
.chip > button:hover { color: var(--danger); }
.chip-group { background: var(--sand); }
.chip-group > span { cursor: pointer; }
.groups { border-top: 2px dashed var(--sand); padding-top: 12px; }
.groups > * + * { margin-top: 8px; }

/* ---------- bills ---------- */
.bill-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.bill-bar::-webkit-scrollbar { display: none; }
.bill {
    flex: none; min-height: var(--tap); padding: 6px 16px;
    border: 2px solid var(--ink); border-radius: 999px; background: #fff;
    font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.bill[aria-current="true"] { background: var(--ink); color: #fff; font-weight: 800; }
.bill[aria-current="true"]::after { content: ' ✎'; font-weight: 400; }
.bill small { font-weight: 400; opacity: .8; }
.bill-add { border-style: dashed; }
.bill-tag { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.bill-tag:empty { display: none; }
.trip h3 { margin: 20px 0 0; font-size: 15px; font-weight: 800; }
.transfer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px; }
.transfer-who { flex: 1 1 60%; font-weight: 600; overflow-wrap: anywhere; }
.transfer-amt { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.transfer .actions { flex-basis: 100%; }
.transfer .qr-box { flex-basis: 100%; }
.done { background: var(--ok-bg); color: var(--ok); border: 2px solid var(--ok); border-radius: 12px; padding: 12px; font-weight: 800; text-align: center; margin: 0; }

/* ---------- items ---------- */
.items { list-style: none; margin: 0; padding: 0; }
.items:empty::before { content: 'ยังไม่มีเมนู — สแกนใบเสร็จหรือพิมพ์เพิ่มด้านบนได้เลย'; display: block; padding: 18px; text-align: center; color: var(--muted); font-size: 14px; border: 2px dashed var(--sand); border-radius: 10px; }
.item { border-top: 2px solid var(--sand); padding: 12px 0; }
.item:first-child { border-top: 0; }
.item.orphan { background: var(--warn-bg); margin: 0 -18px; padding: 12px 18px; }
.item-top { display: flex; align-items: flex-start; gap: 8px; }
.item-name { flex: 1; min-width: 0; font-weight: 800; overflow-wrap: anywhere; background: none; border: 0; text-align: left; padding: 6px 0; cursor: pointer; }
.item-name::after { content: ' ✎'; color: var(--muted); font-weight: 400; }
.item-price { font-weight: 800; white-space: nowrap; padding: 6px 0; font-variant-numeric: tabular-nums; }
.item-sub { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.eaters { display: flex; flex-wrap: wrap; gap: 6px; }
.eater {
    min-height: 40px; padding: 4px 14px;
    border: 2px solid #BDBDBD; border-radius: 999px; background: #fff;
    color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.eater[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.eater[aria-pressed="true"]::before { content: '✓ '; }
.eater-all { border-style: dashed; border-color: var(--ink); color: var(--ink); }

/* ---------- results ---------- */
.result-card { text-align: center; }
.big-amount { margin: 2px 0; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.qr-box { display: grid; justify-items: center; gap: 8px; background: var(--paper); border: 2px solid var(--ink); border-radius: var(--radius); padding: 14px; }
.qr { background: #fff; padding: 8px; border: 2px solid var(--ink); border-radius: 10px; }
.qr img, .qr canvas { width: 180px; height: 180px; }
.warn { background: var(--warn-bg); color: var(--warn); border: 2px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; font-weight: 600; margin: 0 0 16px; }
.check-line { margin: 0; padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.check-line.good { background: #10391F; color: #9BE3B8; }
.check-line.bad { background: #4A2600; color: #FFD08A; }
.people { display: grid; gap: 14px; margin-top: 16px; }
.person > * + * { margin-top: 10px; }
.person-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--ink); padding-bottom: 8px; }
.person-name { margin: 0; font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.person-amount { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; background: var(--ink); color: #fff; border-radius: 999px; padding: 0 8px; vertical-align: middle; }
.collect { background: var(--ok-bg); color: var(--ok); border: 2px solid var(--ok); border-radius: 10px; padding: 8px 12px; font-weight: 800; }
.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
.lines td { padding: 3px 0; vertical-align: top; }
.lines td:last-child { text-align: right; white-space: nowrap; padding-left: 8px; font-variant-numeric: tabular-nums; }
.lines .sum td { border-top: 1px dashed #BDBDBD; color: var(--muted); }
.lines .x { color: var(--muted); font-size: 12px; }

/* ---------- sticky total ---------- */
.sticky-total {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: min(608px, calc(100% - 32px)); z-index: 15;
    display: flex; justify-content: space-between; align-items: center;
    min-height: 52px; padding: 0 18px;
    background: var(--ink); color: #fff; border: 2px solid var(--ink); border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 15px; cursor: pointer;
}
.sticky-total b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
.toast {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 40;
    display: flex; align-items: center; gap: 12px;
    max-width: calc(100% - 32px); padding: 10px 16px;
    background: #2A2A2A; color: #fff; border-radius: 12px; font-weight: 600; font-size: 15px;
    box-shadow: 0 6px 20px rgba(0,0,0,.3);
}

/* ---------- dialogs ---------- */
.dlg {
    width: min(420px, calc(100% - 32px)); max-height: calc(100% - 32px);
    border: 2px solid var(--ink); border-radius: 18px; padding: 20px;
    box-shadow: 6px 6px 0 var(--ink); background: #fff; color: var(--ink);
}
.dlg::backdrop { background: rgba(18,18,18,.6); }
.dlg > * + *, .dlg form > * + * { margin-top: 14px; }
.dlg-text { white-space: pre-line; font-weight: 600; margin: 0; }
.dlg-title { font-size: 18px; font-weight: 800; margin: 0; }
#img-out { max-width: 100%; max-height: 60vh; margin: 0 auto; border: 2px solid var(--ink); border-radius: 12px; }

.dlg-full {
    width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none;
    background: var(--paper); flex-direction: column;
}
.dlg-full[open] { display: flex; }
.dlg-full > * + * { margin-top: 0; }
.as-head { display: flex; justify-content: space-between; align-items: center; background: var(--ink); color: #fff; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; }
.as-bar { height: 6px; background: var(--sand); }
.as-bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.as-body { flex: 1; overflow-y: auto; padding: 24px 16px; width: 100%; max-width: 560px; margin: 0 auto; text-align: center; }
.as-body > * + * { margin-top: 12px; }
.as-name { font-size: 26px; font-weight: 800; margin: 0; overflow-wrap: anywhere; }
.as-price { font-size: 20px; font-weight: 800; margin: 0; }
.as-body .row > .btn { flex: 1; }
.as-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.as-grid .eater { min-height: 60px; border-radius: 14px; font-size: 17px; }
.as-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ink); background: #fff; width: 100%; max-width: 560px; margin: 0 auto; }
.as-foot .btn { min-height: 56px; font-size: 17px; }
.as-foot #as-prev { flex: 0 0 72px; }

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; z-index: 60; background: rgba(18,18,18,.7); display: grid; place-items: center; padding: 16px; }
.loading-box { background: #fff; border: 2px solid var(--ink); border-radius: 18px; padding: 24px; display: grid; justify-items: center; gap: 12px; max-width: 320px; text-align: center; font-weight: 600; }
.loading-box p { margin: 0; }
.spin-logo { animation: bob 1s ease-in-out infinite; border-radius: 10px; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-6deg); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 380px) {
    .grid3 { grid-template-columns: 1fr 1fr; }
    .big-amount { font-size: 34px; }
}

/* ---------- ลิงก์เก็บเงิน (c.html) ---------- */
a.brand { color: inherit; text-decoration: none; }
.of { font-size: 18px; font-weight: 600; color: #BDBDBD; }
.bar { height: 10px; background: #333; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s; }
.dues > * + * { margin-top: 10px; }
.due { background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px 12px; }
.due > * + * { margin-top: 10px; }
.due-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; width: 100%; min-height: var(--tap); padding: 8px 0 0; border: 0; background: none; text-align: left; cursor: pointer; }
.due-head:disabled { cursor: default; color: inherit; }
.due-who { flex: 1 1 60%; overflow-wrap: anywhere; }
.due-who .x { font-weight: 400; color: var(--muted); }
.due-amt { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.due-status { flex-basis: 100%; font-size: 13px; font-weight: 600; color: var(--muted); }
.due.is-paid { box-shadow: none; border-color: var(--ok); background: var(--ok-bg); }
.due.is-paid .due-status { color: var(--ok); }
.due.is-review .due-status { color: var(--warn); }
.due-note { color: var(--muted); }
.due-pay { border-top: 2px dashed var(--sand); padding-top: 12px; }
.due-pay > * + * { margin-top: 10px; }
.due-pay .qr img { width: 220px; height: 220px; }
.due-admin { flex-wrap: wrap; }
#c-head { margin-top: 28px; }
