:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #1f2937;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 12px;
  font-family: system-ui, "Noto Sans Thai", "Sukhumvit Set", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.45; }
main { max-width: 560px; margin: 0 auto; padding: 12px 14px 96px; }
h1 { font-size: 1.25rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; }
p { margin: 6px 0; }
.boot, .muted { color: var(--muted); }
.small { font-size: .85rem; }

.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.bar h1 { flex: 1; margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 11px 14px; min-height: 46px; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); border-color: #fecaca; }
button.link { border: 0; background: none; padding: 6px 4px; min-height: 0; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: .5; }
.stack { display: grid; gap: 8px; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row-buttons > * { flex: 1 1 auto; }

label.field { display: grid; gap: 4px; margin: 10px 0; }
label.field > span { font-size: .9rem; color: var(--muted); }
input, textarea, select {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; width: 100%; background: #fff; color: var(--ink);
}
input.pin { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }
textarea { min-height: 120px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; background: #fff; font-size: .95rem; }
.chip input { width: auto; margin: 0; }
.chip.active, .chip:has(input:checked) { outline: 3px solid var(--accent); }

.zone { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 28px; border-radius: 8px; font-weight: 700; font-size: .9rem; color: #111; padding: 0 6px; }
.zone-M { background: #facc15; }
.zone-T { background: #f472b6; }
.zone-W { background: #22c55e; }
.zone-H { background: #fb923c; }
.zone-F { background: #38bdf8; }
.zone-S { background: #a855f7; color: #fff; }
.zone-U { background: #ef4444; color: #fff; }

.icons { font-size: 1.5rem; letter-spacing: 2px; }
.icons.big { font-size: 3rem; letter-spacing: 6px; text-align: center; display: block; }
.icon-names { text-align: center; color: var(--muted); }

.list { display: grid; gap: 6px; margin-top: 8px; }
.person-row {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 10px;
  text-align: left; width: 100%; background: var(--card);
}
.person-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: .75rem; border-radius: 999px; padding: 2px 8px; background: var(--warn-bg); color: var(--warn-ink); white-space: nowrap; }
.badge.closed { background: #e7e5e4; color: var(--muted); }

.qr { background: #fff; padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; max-width: 340px; margin: 0 auto; }
.mono { font-family: ui-monospace, "Roboto Mono", monospace; word-break: break-all; font-size: .95rem; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { border: 0; border-radius: 0; min-height: 60px; font-size: .85rem; background: none; }
.tabbar button.current { font-weight: 700; color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.step { display: grid; grid-template-columns: auto 1fr; gap: 8px; margin: 8px 0; }
.device { font-size: .75rem; border-radius: 6px; padding: 2px 6px; height: fit-content; white-space: nowrap; }
.device-android { background: #dcfce7; color: #166534; }
.device-iphone { background: #e0e7ff; color: #3730a3; }

.icon-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.icon-picker button { min-height: 44px; padding: 4px; font-size: 1.4rem; }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
#modal[hidden] { display: none; }
#modal .dialog { background: var(--card); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 420px; }
