:root {
  --paper: #F3EFE7;
  --paper-2: #EAE4D8;
  --card: #FFFDF8;
  --ink: #151413;
  --ink-2: #57534C;
  --line: #D9D2C4;
  --green: #00B85C;
  --green-ink: #062B17;
  --green-deep: #008A45;
  --reserved: #A7A39C;
  --reserved-ink: #2D2B28;
  --occupied: #8E2434;
  --occupied-ink: #FFFFFF;
  --bar: #C9D0D9;
  --block: #A8A8A8;
  --danger: #B3261E;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(32, 24, 10, .14);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); min-height: 100dvh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; }
[hidden] { display: none !important; }
.g { color: var(--green-deep); }

.env-banner { background: repeating-linear-gradient(45deg, #FFD54A, #FFD54A 12px, #F6C700 12px, #F6C700 24px); color: #000; text-align: center; font-weight: 700; font-size: 13px; padding: 6px 12px; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; max-width: 760px; width: 100%; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark { width: 44px; height: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-word { height: 26px; width: auto; }
.brand-text small { font-size: 12px; color: var(--ink-2); letter-spacing: .04em; margin-top: 4px; }
.chip-btn { border: 1.5px solid var(--ink); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.dot-count { background: var(--green); color: var(--green-ink); border-radius: 999px; min-width: 20px; height: 20px; font-size: 12px; display: inline-grid; place-items: center; padding: 0 6px; }

main { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; flex: 1; }

/* Controls */
.controls { position: sticky; top: 0; z-index: 5; background: linear-gradient(var(--paper) 85%, rgba(243,239,231,0)); padding: 8px 0 10px; }
.date-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 10px; scroll-snap-type: x proximity; }
.date-row::-webkit-scrollbar { display: none; }
.date-chip { flex: 0 0 auto; scroll-snap-align: start; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 7px 12px; text-align: center; min-width: 64px; line-height: 1.15; }
.date-chip b { display: block; font-size: 15px; }
.date-chip small { font-size: 11.5px; color: var(--ink-2); }
.date-chip[aria-checked="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.date-chip[aria-checked="true"] small { color: #CFC8BA; }
.date-chip--pick { position: relative; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.date-chip--pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

.floor-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--paper-2); border-radius: 14px; padding: 4px; gap: 4px; }
.floor-tab { border: 0; background: transparent; border-radius: 11px; padding: 10px; font-weight: 600; font-size: 15px; }
.floor-tab.is-active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.avail { font-weight: 500; font-size: 12.5px; color: var(--green-deep); margin-left: 4px; }

.legend { display: flex; gap: 14px; list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw-available { background: var(--green); }
.sw-reserved { background: var(--reserved); }
.sw-occupied { background: var(--occupied); }

/* Alerts */
.alert { margin: 6px 0 10px; padding: 12px 14px; border-radius: 14px; background: #FBE9E7; color: #5F1410; border: 1px solid #F1C3BD; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.alert button { border: 0; background: var(--ink); color: #fff; border-radius: 10px; padding: 7px 12px; font-weight: 600; font-size: 13px; flex: none; }

/* Map */
.map-wrap { padding-bottom: 12px; }
.hint { margin: 2px 0 10px; font-size: 14px; color: var(--ink-2); }
.map { background: var(--card); border-radius: var(--radius); border: 1.5px solid var(--line); overflow: hidden; position: relative; min-height: 320px; }
.map.is-loading svg { opacity: .35; filter: grayscale(1); }
.map-skeleton { display: none; position: absolute; inset: 0; padding: 24px; gap: 14px; flex-direction: column; justify-content: center; }
.map.is-loading .map-skeleton { display: flex; }
.map-skeleton span { height: 18px; border-radius: 9px; background: linear-gradient(90deg, var(--paper-2), #F7F3EC, var(--paper-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.map-skeleton span:nth-child(2) { width: 70%; } .map-skeleton span:nth-child(3) { width: 45%; }
@keyframes shimmer { to { background-position: -200% 0; } }
.updated { font-size: 12px; color: var(--ink-2); text-align: right; margin: 8px 2px 0; }
.empty { background: var(--paper-2); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin: 10px 0 0; }

.fp { display: block; width: 100%; height: auto; color: var(--ink); }
.fp-bg { fill: var(--card); }
.fp-block { fill: var(--block); }
.fp-block-label { font: 700 30px 'IBM Plex Sans Thai', sans-serif; fill: #111; letter-spacing: .02em; }
.fp-block-label--lg { font-size: 44px; }
.fp-bar { fill: var(--bar); }
.fp-bar-label { font: 700 34px 'IBM Plex Mono', monospace; fill: #6B7684; letter-spacing: .4em; }
.fp-note { font: 600 24px 'IBM Plex Sans Thai', sans-serif; fill: var(--ink-2); letter-spacing: .08em; }
.fp-note--lg { font-size: 40px; }
.fp-table { cursor: pointer; outline: none; }
.fp-table polygon { transition: fill .2s, stroke .2s; stroke: transparent; stroke-width: 8; stroke-linejoin: round; }
.fp-label { font-family: 'IBM Plex Sans Thai', sans-serif; font-weight: 700; pointer-events: none; }
.fp-sub { font-family: 'IBM Plex Mono', monospace; font-weight: 600; pointer-events: none; }
.fp-table.is-available polygon { fill: var(--green); }
.fp-table.is-available .fp-label { fill: var(--green-ink); }
.fp-table.is-available:hover polygon, .fp-table.is-available:focus-visible polygon { fill: #12C96B; stroke: var(--ink); }
.fp-table.is-reserved polygon { fill: var(--reserved); }
.fp-table.is-reserved .fp-label, .fp-table.is-reserved .fp-sub { fill: var(--reserved-ink); }
.fp-table.is-occupied polygon { fill: var(--occupied); }
.fp-table.is-occupied .fp-label, .fp-table.is-occupied .fp-sub { fill: var(--occupied-ink); }
.fp-table.is-unavailable polygon { fill: #E3DED5; stroke: #C9C2B5; stroke-dasharray: 10 8; stroke-width: 4; }
.fp-table.is-unavailable .fp-label { fill: #9A948A; }
.fp-table.is-selected polygon { stroke: var(--ink); stroke-width: 12; fill: var(--green-deep); }
.fp-table.is-selected .fp-label { fill: #fff; }
.fp-table.is-seat polygon { stroke-width: 6; }
.fp-table.is-flash polygon { animation: flash .9s ease-out 2; }
@keyframes flash { 50% { stroke: var(--ink); stroke-width: 14; } }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(21, 20, 19, .45); z-index: 20; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + var(--safe-b)); max-height: 92dvh; overflow-y: auto; box-shadow: var(--shadow); animation: up .26s cubic-bezier(.2,.8,.2,1); max-width: 760px; margin: 0 auto; overscroll-behavior: contain; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 24px; line-height: 1.2; }
.eyebrow { margin: 0 0 2px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.icon-btn { border: 0; background: var(--paper-2); width: 38px; height: 38px; border-radius: 50%; font-size: 16px; flex: none; }

.field { display: block; margin: 14px 0 0; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field small { font-weight: 400; color: var(--ink-2); }
.field input { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 16px; background: #fff; transition: border-color .15s; }
.field input:focus { outline: none; border-color: var(--ink); }
.field.has-err input { border-color: var(--danger); }
.err { display: block; font-style: normal; color: var(--danger); font-size: 13px; min-height: 0; margin-top: 4px; }
.err:empty { display: none; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 0; font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 14px; }
.slot[aria-checked="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.slot:disabled { opacity: .35; text-decoration: line-through; }

.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; }
.stepper button { border: 0; background: transparent; width: 52px; height: 48px; font-size: 22px; }
.stepper button:disabled { opacity: .3; }
.stepper output { min-width: 48px; text-align: center; font-size: 20px; font-weight: 700; }

.btn-primary { margin-top: 20px; width: 100%; border: 0; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 700; font-size: 17px; padding: 15px; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 54px; }
.btn-primary:disabled { opacity: .7; }
.btn-primary .spinner { display: none; }
.btn-primary.is-busy .spinner { display: inline-block; }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ghost { border: 1.5px solid var(--ink); background: transparent; border-radius: 14px; padding: 13px 18px; font-weight: 600; width: 100%; }
.btn-danger { background: var(--danger) !important; }
.fine { font-size: 12.5px; color: var(--ink-2); text-align: center; margin: 10px 0 0; }
.form-err { background: #FBE9E7; color: #5F1410; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 14px 0 0; }

.info-text { font-size: 15px; color: var(--ink-2); margin: 4px 0 16px; }
.staff-box { border-top: 1.5px dashed var(--line); padding-top: 14px; }
.staff-label { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-2); margin: 0 0 10px; font-weight: 600; }
.staff-actions { display: grid; gap: 8px; }
.staff-actions button { border: 1.5px solid var(--ink); background: #fff; border-radius: 12px; padding: 12px; font-weight: 600; text-align: left; display: flex; justify-content: space-between; align-items: center; }
.staff-actions button.primary { background: var(--ink); color: #fff; }
.staff-actions button small { font-weight: 400; opacity: .7; }

/* PIN */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 6px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); transition: background .1s; }
.pin-dots i.on { background: var(--ink); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-err { text-align: center; color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 0 auto; }
.pin-pad button { height: 60px; border-radius: 16px; border: 0; background: var(--paper-2); font-size: 24px; font-weight: 600; }
.pin-pad button:active { background: var(--line); }
.pin-pad.is-busy { opacity: .5; pointer-events: none; }

/* Ticket */
.ticket-screen { position: fixed; inset: 0; z-index: 30; background: var(--ink); overflow-y: auto; padding: 20px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 16px; animation: fade .25s; }
.ticket { flex: none; width: 100%; max-width: 400px; background: var(--card); border-radius: 22px; overflow: hidden; position: relative; }
.ticket-top { text-align: center; padding: 24px 20px 18px; background: var(--paper); }
.ticket-logo { height: 30px; }
.ok-badge { width: 56px; height: 56px; margin: 14px auto 8px; border-radius: 50%; background: var(--green); color: var(--green-ink); display: grid; place-items: center; animation: pop .45s cubic-bezier(.2,1.6,.4,1); }
.ok-badge svg { width: 30px; height: 30px; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.ticket-top h2 { margin: 0; font-size: 28px; }
.ticket-sub { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.ticket-table { text-align: center; padding: 18px; border-bottom: 2px dashed var(--line); position: relative; }
.ticket-table::before, .ticket-table::after { content: ''; position: absolute; bottom: -13px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); }
.ticket-table::before { left: -12px; } .ticket-table::after { right: -12px; }
.ticket-table span { display: block; font-size: 13px; color: var(--ink-2); letter-spacing: .1em; }
.ticket-table strong { display: block; font-size: 64px; line-height: 1; font-weight: 700; letter-spacing: .02em; color: var(--green-deep); }
.ticket-table em { font-style: normal; font-size: 14px; color: var(--ink-2); }
.ticket-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; margin: 0; padding: 20px; }
.ticket-grid dt { font-size: 12px; color: var(--ink-2); }
.ticket-grid dd { margin: 2px 0 0; font-weight: 600; font-size: 16px; word-break: break-word; }
.ticket-code { margin: 0 20px; padding: 14px; background: var(--paper); border-radius: 14px; text-align: center; }
.ticket-code span { display: block; font-size: 12px; color: var(--ink-2); }
.ticket-code strong { display: block; font-family: 'IBM Plex Mono', monospace; font-size: 28px; letter-spacing: .14em; margin: 2px 0 6px; }
.status-pill { display: inline-block !important; padding: 3px 10px; border-radius: 999px; font-size: 12px !important; font-weight: 700; letter-spacing: .06em; color: var(--ink) !important; background: var(--reserved); }
.status-pill.is-occupied { background: var(--occupied); color: #fff !important; }
.status-pill.is-cleared { background: var(--paper-2); }
.live-clock { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px; font-family: 'IBM Plex Mono', monospace; font-size: 15px; color: var(--ink-2); }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(0,184,92,.6); } 100% { box-shadow: 0 0 0 10px rgba(0,184,92,0); } }
.ticket-actions { width: 100%; max-width: 400px; }
.ticket-actions .btn-ghost { color: #fff; border-color: #fff; }

/* My bookings */
.mine-list { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 10px; }
.mine-list li button { width: 100%; text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.mine-list b { font-size: 18px; }
.mine-list small { display: block; color: var(--ink-2); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; z-index: 40; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); max-width: calc(100% - 32px); animation: up .2s; }

.foot { display: flex; justify-content: space-between; align-items: center; max-width: 760px; width: 100%; margin: 0 auto; padding: 16px 16px calc(20px + var(--safe-b)); font-size: 13px; color: var(--ink-2); }
.foot p { margin: 0; }
.foot a { color: var(--ink-2); }

@media (min-width: 720px) {
  .sheet { border-radius: 22px; bottom: 24px; }
  .slots { grid-template-columns: repeat(6, 1fr); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
