:root {
  --bg: #f4f6fa; --card: #fff; --ink: #172033; --muted: #5d6a80; --line: #e2e7ef;
  --brand: #2b4c7e; --brand-weak: #e8eef8;
  --ok: #1f7a4d; --ok-weak: #e3f4ea; --warn: #9a5b00; --warn-weak: #fff2d9; --bad: #b42318; --bad-weak: #fde8e6;
  --idle: #6b7280; --idle-weak: #eef0f3;
  --r: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 "IBM Plex Sans Thai", system-ui, sans-serif; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo > div { min-width: 0; }
.brand { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 13px; color: var(--muted); }
.hdr-acts { display: flex; gap: 6px; flex: none; }
.demo-note { background: var(--warn-weak); color: var(--warn); font-size: 14px; padding: 8px 16px; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
h3 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; border: 0; background: none; padding: 9px 4px 10px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav button .i { display: block; }
nav button.on { color: var(--brand); font-weight: 600; }

button { cursor: pointer; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--brand); color: #fff; font-weight: 600; min-height: 44px; }
.btn.secondary { background: var(--brand-weak); color: var(--brand); }
.btn.danger { background: var(--bad-weak); color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.ghost { border: 1px solid var(--line); background: var(--card); border-radius: 9px; padding: 6px 11px; font-size: 14px; min-height: 36px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--muted); }
.bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--brand); }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; }
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .d { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.item .r { text-align: right; font-size: 14px; flex: none; }
.empty { padding: 18px 14px; color: var(--muted); text-align: center; }

.tag { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.tag.ok { background: var(--ok-weak); color: var(--ok); }
.tag.warn { background: var(--warn-weak); color: var(--warn); }
.tag.bad { background: var(--bad-weak); color: var(--bad); }
.tag.idle { background: var(--idle-weak); color: var(--idle); }
.tag.info { background: var(--brand-weak); color: var(--brand); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 14px; white-space: nowrap; min-height: 36px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.floor { margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.room { border: 0; border-radius: 12px; padding: 10px; text-align: left; background: var(--card); box-shadow: var(--shadow); border-left: 5px solid var(--idle); min-height: 74px; }
.room b { display: block; font-size: 17px; }
.room span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room.occupied { border-left-color: var(--brand); }
.room.vacant { border-left-color: var(--ok); }
.room.ending { border-left-color: var(--warn); }
.room.overdue { border-left-color: var(--bad); }
.room.hold { border-left-color: var(--idle); background: var(--idle-weak); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

input[type=search], .field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 44px; }
input[type=search] { margin-bottom: 10px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field textarea { min-height: 70px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 2px; margin: 0 0 12px; }
legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet.hidden { display: none; }
.sheet-in { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-in { border-radius: 18px; } }
.sheet-hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sheet-hd h2 { margin: 0; }
.x { border: 0; background: var(--card); border-radius: 50%; width: 36px; height: 36px; font-size: 18px; box-shadow: var(--shadow); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; padding: 12px 14px; }
dl.kv dt { color: var(--muted); font-size: 14px; }
dl.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .btn { flex: 1 1 140px; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); font-size: 15px; box-shadow: var(--shadow); }
.login { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.login input { text-align: center; font-size: 22px; letter-spacing: 6px; }
.reveal { border: 0; background: none; color: var(--brand); padding: 0 0 0 6px; font-size: 14px; }

/* ---- tables (wide screens) */
.tbl-wrap { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-weight: 600; font-size: 13.5px; color: var(--muted); border-bottom: 1px solid var(--line); background: #fafbfd; position: sticky; top: 0; }
.tbl th button { border: 0; background: none; padding: 10px 12px; font: inherit; color: inherit; width: 100%; text-align: inherit; white-space: nowrap; }
.tbl th[aria-sort="ascending"], .tbl th[aria-sort="descending"] { color: var(--brand); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--brand-weak); }
.tbl tbody tr:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.empty { cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: 8px 14px; font-size: 14px; min-height: 40px; }
.seg button.on { background: var(--brand); color: #fff; }
.cols { display: block; }

/* ---- wide screens: side menu, wider content, side panel */
@media (min-width: 1024px) {
  body { padding-bottom: 0; padding-left: 220px; }
  header { margin-left: -220px; padding-left: 20px; }
  nav { top: 0; bottom: 0; right: auto; width: 220px; flex-direction: column; justify-content: flex-start; gap: 2px;
    border-top: 0; border-right: 1px solid var(--line); padding: 76px 12px 16px; z-index: 4; }
  nav button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  nav button.on { background: var(--brand-weak); }
  nav button:hover:not(.on) { background: var(--bg); }
  main { max-width: 1180px; padding: 24px 28px 40px; }
  h1 { font-size: 26px; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .sheet { justify-content: flex-end; align-items: stretch; }
  .sheet-in { max-width: 520px; max-height: none; height: 100%; border-radius: 0; padding: 20px 22px; box-shadow: -8px 0 24px rgba(16, 24, 40, .12); }
  .toast { bottom: 24px; left: calc(50% + 110px); }
}
