:root {
  --brand: #0b5e8a;
  --brand-2: #1386b8;
  --accent: #b4475a;
  --bg: #eef6fa;
  --card: #ffffff;
  --text: #1c2526;
  --muted: #66727a;
  --line: #d4e3ea;
  --ok: #1f8a4c;
  --ok-bg: #e5f4ea;
  --warn: #b26a00;
  --warn-bg: #fff3dc;
  --bad: #c0392b;
  --bad-bg: #fbe7e5;
  --radius: 12px;
  font-family: "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body { font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 26px; } h2 { font-size: 21px; } h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: 28px; font-weight: 700; }
.huge { font-size: 44px; font-weight: 800; letter-spacing: .5px; }
.right { text-align: right; }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.logo { font-weight: 800; font-size: 19px; white-space: nowrap; }
.logo span { color: var(--accent); }
.nav { display: flex; gap: 6px; overflow-x: auto; flex: 1 1 auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button { background: transparent; border: 0; color: #cfe6f3; padding: 10px 14px; border-radius: 10px; white-space: nowrap; cursor: pointer; font-weight: 600; }
.nav button.active { background: #fff; color: var(--brand); }
.who { text-align: right; white-space: nowrap; font-size: 14px; }
.who button { margin-left: 8px; background: transparent; border: 1px solid #7fb3d1; color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid.visits { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------- controls ---------- */
.btn { border: 0; border-radius: 10px; padding: 12px 18px; min-height: 48px; font-weight: 700; cursor: pointer; background: #e4eff5; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.lg { min-height: 60px; font-size: 19px; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.input, select.input { width: 100%; min-height: 50px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: #fff; font-size: 17px; }
.input:focus { outline: 3px solid #b6dcef; border-color: var(--brand-2); }
label.field { display: block; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.seg { display: flex; background: #e4eff5; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 12px; border-radius: 9px; font-weight: 700; cursor: pointer; }
.seg button.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); color: var(--brand); }

.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: #e4eff5; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.notice { border-radius: 10px; padding: 12px 14px; }
.notice.warn { background: var(--warn-bg); color: #6b4300; }
.notice.bad { background: var(--bad-bg); color: #7d241b; }
.notice.ok { background: var(--ok-bg); color: #145c33; }

/* ---------- lists ---------- */
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.list > .item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.list > .item:first-child { border-top: 0; }
.list > .item:hover { background: #f3f9fc; }
.list > .item.selected { background: #e2f0f8; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.visit { cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.visit .band { font-size: 30px; font-weight: 800; color: var(--brand); line-height: 1; }
.visit:hover { border-color: var(--brand-2); }

.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 96px; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; text-align: left; }
.tile:active { transform: scale(.98); }
.tile .price { font-weight: 800; color: var(--brand); }
.tile.selected { border: 2px solid var(--brand); background: #e8f4fb; }

table.lines { width: 100%; border-collapse: collapse; }
table.lines td, table.lines th { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.lines th { text-align: left; font-size: 13px; color: var(--muted); }
table.lines td.num, table.lines th.num { text-align: right; white-space: nowrap; }
.totals { margin-top: 10px; }
.totals .row { justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 24px; font-weight: 800; border-top: 2px solid var(--text); padding-top: 8px; margin-top: 6px; }
.discount { color: var(--ok); }
.strike { text-decoration: line-through; color: var(--muted); }

.qty { display: inline-flex; align-items: center; gap: 6px; }
.qty button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 20px; font-weight: 800; cursor: pointer; }
.qty b { min-width: 26px; text-align: center; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #1aa0d8, var(--brand) 55%, #8f3446); }
.login .card { width: 100%; max-width: 400px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 16px 0; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); display: block; }
.pin-dots i.on { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { min-height: 62px; font-size: 24px; font-weight: 700; border-radius: 12px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.keypad button:active { background: #e2f0f8; }

/* ---------- modal & toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 30, 30, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; }
#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 520px); }
.toast { padding: 14px 16px; border-radius: 12px; color: #fff; background: #26343a; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-weight: 600; }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }

/* ---------- receipt ---------- */
.receipt { max-width: 380px; margin: 0 auto; font-size: 15px; }
.receipt h2 { text-align: center; margin-bottom: 2px; }
.receipt .dash { border-top: 1px dashed #999; margin: 10px 0; }
@media print {
  body { background: #fff; }
  .topbar, .no-print, #toasts { display: none !important; }
  main { padding: 0; }
  .card { border: 0; padding: 0; }
  .receipt { max-width: 72mm; font-size: 12px; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; }
  .huge { font-size: 34px; }
}

/* ---------- batch 2 ---------- */
.accent-text { color: var(--accent); }
.logo span { color: #ffc9d2; }
.grid.two-tight { grid-template-columns: 1fr 1fr; }
.grid.keys { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.keybtn { min-height: 58px; border-radius: 10px; border: 2px solid var(--brand-2); background: #fff; color: var(--brand); font-weight: 800; font-size: 18px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.keybtn small { font-size: 11px; font-weight: 600; }
.keybtn:hover { background: #e4f3fb; }
.keybtn.in_use { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); }
.keybtn.lost, .keybtn.retired { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
label.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
label.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--brand); }
textarea.input { min-height: 70px; resize: vertical; }
.stat.good .big { color: var(--ok); }
.stat.badc .big { color: var(--bad); }
.stat { border-top: 4px solid var(--brand-2); }
.bad-text { color: var(--bad); }
.ok-text { color: var(--ok); }
.table-wrap { overflow-x: auto; }
.btn.accent:hover, .btn.primary:hover { filter: brightness(1.08); }
.login .card { border-top: 6px solid var(--accent); }
@media (max-width: 560px) { .grid.two-tight { grid-template-columns: 1fr; } .who .wn { display: none; } }
.band { font-size: 26px; font-weight: 800; color: var(--brand); line-height: 1.1; }
.nav .badge { display: inline-block; min-width: 20px; margin-left: 6px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; line-height: 18px; }
img.slip { display: block; max-width: 100%; max-height: 360px; margin: 0 auto; border-radius: 10px; border: 1px solid var(--line); }
.list > .item.disabled { opacity: .55; }
.script { background: #f3f9fc; border-left: 4px solid var(--brand-2); padding: 10px 14px; border-radius: 8px; font-size: 15px; line-height: 1.6; }
.who .clock { border-color: #ffb3bf; }
.who .clock.on { border-color: #8fe0b0; }
.who .adminlink { margin-left: 8px; color: #fff; font-size: 13px; text-decoration: underline; }
.narrow { max-width: 760px; }

/* ---------- batch 6: chips, descriptions, toasts ---------- */
.toast.warn { background: #a8640a; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
details.quick-tags { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; }
details.quick-tags summary { cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 600; }
.tile .desc, .desc { display: block; text-align: left; font-weight: 400; font-size: 13px; line-height: 1.5; color: var(--text); margin-top: 4px; }

/* ---------- screen sizes: computer / tablet / phone ---------- */
/* Tables never push the page sideways: they scroll inside their card */
.card > table.lines, .card > .stack > table.lines { display: block; overflow-x: auto; }
img, svg { max-width: 100%; }

/* Large computer screens: use the width */
@media (min-width: 1400px) {
  main { max-width: 1360px; }
  .grid.visits { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* Tablet (portrait and landscape): big touch targets, nav scrolls sideways */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .topbar .nav { order: 3; flex-basis: 100%; }
  .nav button { padding: 10px 12px; }
  .who { margin-left: auto; }
  .btn { min-height: 50px; }
  .tile { min-height: 96px; }
}

/* Phone */
@media (max-width: 600px) {
  body { font-size: 15px; }
  main { padding: 12px 10px 80px; }
  h1 { font-size: 21px; }
  .huge { font-size: 34px; }
  .big { font-size: 22px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .logo { font-size: 17px; }
  .who { font-size: 12px; }
  .who button, .who .adminlink { padding: 5px 8px; margin-left: 4px; font-size: 12px; }
  .grid.two, .grid.visits { grid-template-columns: 1fr; }
  .grid.tiles { grid-template-columns: repeat(2, 1fr); }
  .grid.keys { grid-template-columns: repeat(4, 1fr); }
  .card { padding: 14px; }
  .seg { flex-wrap: wrap; }
  .seg button { flex: 1 1 45%; padding: 10px 6px; font-size: 14px; }
  .btn.lg { min-height: 54px; font-size: 17px; }
  .row > .btn.grow { flex-basis: 100%; }
  .modal { padding: 16px; border-radius: 14px; }
  .overlay { padding: 8px; align-items: flex-end; }
  .keypad button { min-height: 56px; }
  .list > .item { flex-wrap: wrap; }
  .kpi { grid-template-columns: 1fr 1fr; }
  .kpi .big { font-size: 19px; }
}
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; }

.input:disabled { background: #eef2f6; color: #5b6b7a; cursor: not-allowed; border-style: dashed; }
