/* ══════════════════════════════════════════════════════════════════
   Tableory · แอปพนักงานหน้าฟลอร์
   จอมืดอย่างเดียวโดยตั้งใจ: บรอนซ์กับเทาอุ่นตกเกณฑ์คอนทราสต์บนพื้นสว่าง
   (2.86:1 และ 2.37:1) แต่ผ่านบนถ่าน (5.39:1 และ 6.50:1)
   และจอสว่างตอนตีหนึ่งทำลายการมองเห็นในที่มืดของพนักงาน แล้วยังสาดแสงเข้าร้าน
   ══════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* แบรนด์ */
  --charcoal: #1F1F1F;
  --bronze:   #B08D6B;
  --white:    #F9F7F4;
  --gray:     #A7A29A;
  --sand:     #DCCDBF;
  --sage:     #7F8C7A;
  --olive:    #3C4A3F;

  /* ที่ตรวจคอนทราสต์บนพื้นถ่านแล้ว */
  --rust-light:  #E0785C;  /* 5.50:1 */
  --olive-light: #8FA88C;  /* 6.40:1 */

  /* พื้นผิว */
  --ground:   #151310;
  --surface:  var(--charcoal);
  --surface-2:#262320;
  --line:     #35312C;
  --line-soft:#2A2723;

  --ink:      var(--white);
  --ink-dim:  var(--gray);
  --ink-mute: #7C776F;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;

  --tap: 48px;          /* ขนาดเป้าสัมผัสขั้นต่ำ ห้ามต่ำกว่านี้ */
  --pad: 14px;

  --font-latin: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-thai:  'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', 'Leelawadee UI', sans-serif;
  --font: var(--font-latin), var(--font-thai);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ground);
  color: var(--ink);
}

body {
  font-family: var(--font-latin), var(--font-thai);
  /* บรรทัดไทยต้องหายใจได้ 1.75 ขึ้นไป สระบนล่างจะได้ไม่ชนบรรทัดข้างเคียง */
  line-height: 1.75;
  font-size: 15px;
  /* ห้ามจัดระยะห่างตัวอักษรกับข้อความไทยเด็ดขาด
     ไทยไม่มีช่องว่างระหว่างคำ และ tracking ทำให้สระกับวรรณยุกต์เพี้ยนตำแหน่ง */
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;   /* ตัวเลขในคอลัมน์ต้องตรงกันทุกหลัก */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}

/* ระยะห่างตัวอักษรใช้ได้เฉพาะข้อความละตินล้วนที่ทำเครื่องหมายไว้เท่านั้น */
.latin { font-family: var(--font-latin); letter-spacing: .06em; }

button, input, select { font: inherit; color: inherit; letter-spacing: 0; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(.985); }

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

.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ───────────────────────── โครงหน้า ───────────────────────── */

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
}

.topbar {
  padding: max(8px, env(safe-area-inset-top)) var(--pad) 8px;
  background: linear-gradient(var(--ground), var(--ground) 70%, transparent);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 5;
}
.topbar-row { display: flex; align-items: baseline; gap: 10px; }
.venue-pick {
  font-size: 17px; font-weight: 600; color: var(--ink);
  background: none; padding: 6px 0; min-height: 36px;
}
.venue-pick::after { content: ' ▾'; color: var(--bronze); font-size: 12px; }
.topbar-date { color: var(--ink-dim); font-size: 13px; margin-left: auto; }
.topbar-clock { font-size: 15px; color: var(--sand); font-variant-numeric: tabular-nums; }

.summary { display: flex; gap: 16px; margin-top: 2px; flex-wrap: wrap; }
.summary b { font-size: 17px; font-weight: 600; color: var(--ink); }
.summary span { font-size: 12px; color: var(--ink-mute); margin-left: 4px; }
.summary .warn b { color: var(--bronze); }

main {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px var(--pad) 24px;
  overscroll-behavior: contain;
}

/* ───────────────────────── ผังโต๊ะ ───────────────────────── */

.area { margin: 18px 0 4px; }
.area:first-child { margin-top: 6px; }
.area-head {
  display: flex; align-items: baseline; gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 10px;
}
.area-name { font-size: 14px; color: var(--sand); font-weight: 600; }
.area-count { font-size: 12px; color: var(--ink-mute); margin-left: auto; }

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

.t {
  position: relative;
  display: block;
  width: 100%;
  min-height: 104px;
  padding: 10px 12px 12px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-left: 4px solid transparent;
  text-align: left;
  color: var(--ink);
  transition: background .12s ease;
}
.t:active { background: var(--surface-2); }

.t-top { display: flex; align-items: center; gap: 6px; }
.t-name { font-size: 19px; font-weight: 600; font-family: var(--font-latin); }
.t-cap  { font-size: 11px; color: var(--ink-mute); }
.t-party {
  margin-left: auto;
  font-size: 20px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.t-party i { font-style: normal; font-size: 11px; color: var(--ink-mute); margin-left: 2px; }

.t-guest {
  margin-top: 2px;
  font-size: 14px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.t-chip {
  margin-top: 6px;
  font-size: 11.5px; color: var(--ink-dim);
  display: flex; align-items: center; gap: 6px;
}
.t-money {
  margin-top: 8px;
  display: flex; align-items: baseline; gap: 5px;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.t-money b { font-weight: 600; color: var(--ink); }
.t-money span { color: var(--ink-mute); font-size: 11.5px; }

.bar { height: 4px; border-radius: 2px; background: #ffffff14; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--bronze); border-radius: 2px; }
.bar.met > i { background: var(--olive-light); }

/* จุดบรอนซ์เล็กๆ สำหรับ VIP — ไม่เปลี่ยนสีการ์ด เพราะสีคือภาษาของสถานะ ไม่ใช่ของระดับลูกค้า */
.vip {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--bronze); flex: none;
  box-shadow: 0 0 0 2px #b08d6b26;
}

/* ห้าสถานะ — แยกกันด้วย "รูปแบบเส้น" มากกว่าด้วยสี
   ถ้าเพิ่มสีไปเรื่อยๆ ฟลอร์จะกลายเป็นรุ้ง แล้วจะไม่มีสีไหนแปลว่าอะไรอีกเลย */
.t--free {
  background: transparent;
  border: 1px dashed var(--line);
  border-left: 1px dashed var(--line);
  color: var(--ink-mute);
  min-height: 84px;
}
.t--free .t-name { color: var(--ink-dim); font-weight: 500; }

.t--booked  { border-left-color: var(--bronze); }
.t--seated  { border-left-color: var(--sage); }

.t--at_risk {
  border: 1.5px dashed var(--bronze);
  background: #b08d6b0f;
}
.t--at_risk .t-chip { color: var(--bronze); }

.t--overdue { border-left-color: var(--rust-light); }
.t--overdue .t-chip { color: var(--rust-light); }

/* คำสั่งของโต๊ะนี้ยังส่งไม่ถึงเซิร์ฟเวอร์ */
.t.is-pending::after {
  content: '';
  position: absolute; top: 9px; right: 10px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--sand);
  animation: pulse 1.6s ease-in-out infinite;
}
.t.is-conflict::after {
  content: '!';
  position: absolute; top: 4px; right: 8px;
  font-size: 13px; font-weight: 700; color: var(--rust-light);
}
@keyframes pulse { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

/* กลุ่มหลายโต๊ะ = การจองเดียว — ทำเครื่องหมายว่าโต๊ะนี้เป็นลูกของกลุ่ม */
.t-group { font-size: 11px; color: var(--bronze); }

/* ───────────────────────── คืนนี้ ───────────────────────── */

.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 0; border-bottom: 1px solid var(--line-soft);
  background: none; text-align: left; color: var(--ink);
}
.row:active { background: var(--surface); }
.row-time { font-size: 17px; font-weight: 600; width: 52px; flex: none; font-variant-numeric: tabular-nums; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.row-sub  { font-size: 12px; color: var(--ink-mute); }
.row-right { text-align: right; flex: none; }
.row-party { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-dim);
  line-height: 1.6;
}
.tag--booked  { border-color: var(--bronze); color: var(--bronze); }
.tag--seated  { border-color: var(--sage); color: var(--olive-light); }
.tag--at_risk { border-style: dashed; border-color: var(--bronze); color: var(--bronze); }
.tag--overdue { border-color: var(--rust-light); color: var(--rust-light); }
.tag--free    { color: var(--ink-mute); }

.daybar { display: flex; gap: 8px; padding: 4px 0 10px; overflow-x: auto; }
.daybar button {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-dim); font-size: 13px; white-space: nowrap;
}
.daybar button[aria-pressed="true"] { border-color: var(--bronze); color: var(--sand); background: #b08d6b12; }

/* ───────────────────────── แผ่นซ้อน (แผงจัดการโต๊ะ · คิว · ชนกัน) ───────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: #0b0a08cc;
  backdrop-filter: blur(2px);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -18px 50px #00000080;
  animation: rise .18s ease-out;
  max-width: 900px; margin: 0 auto;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6 } }
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none }
  .t.is-pending::after { animation: none }
}

.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--line-soft);
}
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-sub { font-size: 12px; color: var(--ink-mute); }
.sheet-close {
  margin-left: auto; width: var(--tap); height: var(--tap);
  border-radius: 50%; color: var(--ink-dim); font-size: 22px;
}
.sheet-body {
  overflow-y: auto; padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}

.block { margin-bottom: 20px; }
.block > h3 {
  margin: 0 0 8px; font-size: 12px; font-weight: 600;
  color: var(--ink-mute);
}

/* ตัวปรับจำนวนคน — เป้าใหญ่ กดข้างเดียวได้ */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 64px; height: 64px; flex: none;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 30px; font-weight: 300; color: var(--ink);
  display: grid; place-items: center;
}
.stepper button:disabled { opacity: .3; }
.stepper-val {
  flex: 1; text-align: center;
  font-size: 40px; font-weight: 600; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stepper-val small { display: block; font-size: 11px; color: var(--ink-mute); font-weight: 400; line-height: 1.6; }

/* แถบความคืบหน้าขั้นต่ำ */
.minbar { background: var(--surface-2); border-radius: var(--r); padding: 12px; }
.minbar-top { display: flex; align-items: baseline; gap: 8px; }
.minbar-now { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.minbar-of { font-size: 13px; color: var(--ink-dim); }
.minbar-rest { margin-left: auto; font-size: 13px; color: var(--bronze); font-variant-numeric: tabular-nums; }
.minbar-rest.met { color: var(--olive-light); }
.minbar .bar { height: 8px; border-radius: 4px; margin-top: 10px; }
.split { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--ink-mute); }
.split b { color: var(--ink-dim); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ช่องกรอกยอด */
.spend { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--ink-dim); }
.field input {
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink);
  font-size: 19px; font-variant-numeric: tabular-nums;
  width: 100%;
}
.field input:focus { border-color: var(--bronze); outline: none; }
.field .hint { font-size: 11px; color: var(--ink-mute); }

.btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.btn {
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn--primary { background: var(--bronze); color: #1a1512; border-color: var(--bronze); font-weight: 600; }
.btn--sage { background: var(--olive); border-color: var(--olive); color: var(--white); }
.btn--ghost { background: transparent; }
.btn--danger { border-color: var(--rust-light); color: var(--rust-light); }
.btn--wide { grid-column: 1 / -1; }
.btn:disabled { opacity: .4; }

.tablepick { display: flex; flex-wrap: wrap; gap: 8px; }
.tablepick button {
  min-width: 56px; min-height: var(--tap);
  padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  font-family: var(--font-latin); font-size: 15px;
}
.tablepick button[aria-pressed="true"] { border-color: var(--bronze); background: #b08d6b26; color: var(--sand); }

.note {
  font-size: 13px; color: var(--ink-dim);
  background: var(--surface-2); border-left: 2px solid var(--bronze);
  padding: 8px 10px; border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.legal {
  font-size: 11.5px; color: var(--ink-mute);
  border-top: 1px solid var(--line-soft); padding-top: 10px; margin-top: 4px;
}

/* ───────────────────────── หน้าประตู ───────────────────────── */

.door-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.door-btn {
  min-height: 92px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; padding: 12px;
  text-align: left;
}
.door-btn b { font-size: 16px; font-weight: 600; }
.door-btn span { font-size: 11.5px; color: var(--ink-mute); }
.door-btn--ok { border-left: 4px solid var(--sage); }
.door-btn--warn { border-left: 4px solid var(--bronze); }
.door-btn--stop { border-left: 4px solid var(--rust-light); }
.door-btn:active { background: var(--surface-2); }

.log-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.log-item time { color: var(--ink-mute); font-size: 12px; width: 48px; flex: none; font-variant-numeric: tabular-nums; }
.log-item .who { color: var(--ink-mute); font-size: 12px; margin-left: auto; }
.log-item.pending { opacity: .65; }

/* ───────────────────────── แถบสถานะ + แท็บ ───────────────────────── */

footer { border-top: 1px solid var(--line); background: var(--ground); }

.netbar {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  min-height: 34px; padding: 4px var(--pad);
  font-size: 12.5px; color: var(--ink-dim);
  border-bottom: 1px solid var(--line-soft);
}
.netbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--olive-light); flex: none; }
.netbar.off .dot { background: var(--rust-light); }
.netbar.sync .dot { background: var(--bronze); animation: pulse 1.2s ease-in-out infinite; }
.netbar.bad .dot { background: var(--rust-light); }
.netbar .count { margin-left: auto; color: var(--sand); font-variant-numeric: tabular-nums; }
.netbar .count.zero { color: var(--ink-mute); }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); }
.tabs a {
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  text-decoration: none; color: var(--ink-mute); font-size: 12px;
  border-top: 2px solid transparent;
}
.tabs a b { font-size: 15px; font-weight: 500; color: var(--ink-dim); }
.tabs a[aria-current="page"] { border-top-color: var(--bronze); }
.tabs a[aria-current="page"] b { color: var(--sand); font-weight: 600; }

/* ───────────────────────── หน้าจอแก้การชนเวอร์ชัน ───────────────────────── */

.conflict { border-left: 3px solid var(--rust-light); padding-left: 12px; margin-bottom: 18px; }
.conflict h4 { margin: 0 0 4px; font-size: 15px; color: var(--ink); font-weight: 600; }
.conflict p { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-dim); }
.conflict .vs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.conflict .vs > div { background: var(--surface-2); border-radius: var(--r-sm); padding: 10px; }
.conflict .vs h5 { margin: 0 0 4px; font-size: 11px; color: var(--ink-mute); font-weight: 500; }
.conflict .vs p { margin: 0; font-size: 14px; color: var(--ink); }

.qitem { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.qitem .state { font-size: 11px; color: var(--ink-mute); flex: none; width: 62px; }
.qitem .state.err { color: var(--rust-light); }
.qitem .state.cfl { color: var(--bronze); }

.empty { text-align: center; color: var(--ink-mute); padding: 40px 20px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%);
  z-index: 60; max-width: 88vw;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink); padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; box-shadow: 0 8px 24px #00000066;
}
