:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1e1b16;
  --muted: #6f675c;
  --line: #e4e0d8;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --ok: #17734a;
  --warn: #9a6a00;
  --err: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 27, 22, .06), 0 8px 24px rgba(30, 27, 22, .07);
}

* { box-sizing: border-box; }

/* A display rule on a panel would otherwise beat the UA style for [hidden]. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Noto Sans Thai", -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.logo { font-size: 1.5rem; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.health { font-size: .8rem; color: var(--muted); }
.health.ok { color: var(--ok); }
.health.bad { color: var(--err); }

.cart-button {
  position: relative; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 8px 16px; font-size: 1rem; cursor: pointer;
}
.cart-button:hover { border-color: var(--accent); }
.badge {
  display: inline-block; min-width: 22px; margin-left: 4px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: .8rem; font-weight: 700; text-align: center;
}

main { max-width: 1080px; margin: 0 auto; padding: 28px 20px 64px; }

.hero h1 { margin: 0 0 6px; font-size: 1.7rem; }
.hero p { margin: 0 0 28px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }

.card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card .icon { font-size: 2.4rem; }
.card h3 { margin: 0; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .88rem; flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.price { font-weight: 700; font-size: 1.1rem; }
.stock { font-size: .78rem; color: var(--muted); }
.stock.low { color: var(--warn); }
.stock.out { color: var(--err); }

button.primary {
  border: none; background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; padding: 10px 16px; font-size: .95rem; font-weight: 600; cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { background: #cfc7bb; cursor: not-allowed; }

.icon-button { border: none; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--muted); }

.orders { margin-top: 44px; }
.orders h2 { font-size: 1.15rem; margin-bottom: 12px; }
.orders-list { display: flex; flex-direction: column; gap: 8px; }
.order-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  font-size: .9rem;
}
.order-row .ref { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.order-row .when { color: var(--muted); font-size: .8rem; }
.pill { border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 600; }
.pill.pending { background: #fdf3dc; color: var(--warn); }
.pill.paid    { background: #e2f3ea; color: var(--ok); }
.pill.failed, .pill.expired { background: #fbe6e4; color: var(--err); }

.cart-panel {
  position: fixed; top: 0; right: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 14px;
  width: min(380px, 100%); height: 100%; padding: 20px;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(30, 27, 22, .12); overflow-y: auto;
}
.cart-head { display: flex; align-items: center; justify-content: space-between; }
.cart-head h2 { margin: 0; font-size: 1.15rem; }
.cart-items { display: flex; flex-direction: column; gap: 10px; }
.cart-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: .9rem; }
.cart-row .qty { display: flex; align-items: center; gap: 8px; }
.cart-row button {
  width: 26px; height: 26px; border: 1px solid var(--line); background: var(--bg);
  border-radius: 6px; cursor: pointer; font-size: 1rem; line-height: 1;
}
.cart-empty { color: var(--muted); font-size: .9rem; }
.cart-total { display: flex; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.checkout-form { display: flex; flex-direction: column; gap: 10px; }
.checkout-form label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.checkout-form input {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: .95rem; font-family: inherit; color: var(--ink); background: var(--bg);
}
.checkout-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.error { color: var(--err); font-size: .85rem; margin: 0; }

.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(30, 27, 22, .35); }

.pay-dialog {
  border: none; border-radius: 18px; padding: 0; width: min(420px, 92vw);
  box-shadow: var(--shadow); background: var(--surface); color: var(--ink);
}
.pay-dialog::backdrop { background: rgba(30, 27, 22, .45); }
.pay-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.pay-head h2 { margin: 0; font-size: 1.1rem; }
.pay-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.qr-frame {
  align-self: center; width: 220px; height: 220px; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  display: grid; place-items: center;
}
.qr-frame img { width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.pay-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: .88rem; }
.pay-meta dt { color: var(--muted); }
.pay-meta dd { margin: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.pay-status { margin: 0; text-align: center; font-weight: 600; border-radius: 10px; padding: 10px; }
.pay-status.waiting { background: #fdf3dc; color: var(--warn); }
.pay-status.paid    { background: #e2f3ea; color: var(--ok); }
.pay-status.failed  { background: #fbe6e4; color: var(--err); }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: .78rem; }

@media (max-width: 520px) {
  .order-row { grid-template-columns: 1fr auto; }
  .order-row .when { display: none; }
}
