:root {
  --bg: #f4f6f8;
  --card: #fff;
  --ink: #1d2530;
  --muted: #637083;
  --line: #dde3ea;
  --brand: #2a6fdb;
  --brand-ink: #fff;
  --ok: #1f9d55;
  --warn: #c2410c;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: #fff3cd; color: #7a5b00; }
.badge.live { background: #dcfce7; color: #166534; }

.wrap { max-width: 880px; margin: 0 auto; padding: 32px 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.error { color: var(--warn); margin-top: 12px; }
.hidden { display: none !important; }

.btn { text-decoration: none; display: inline-block;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 12px 20px; border-radius: 10px; font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.big { font-size: 22px; padding: 18px 36px; border-radius: 14px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn { border: none; background: none; font-size: 22px; color: var(--muted); padding: 4px 8px; }

label.field { display: block; margin: 16px 0; font-weight: 600; }
label.field input, label.field select {
  display: block; width: 100%; margin-top: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  font-weight: 400; background: #fff;
}

/* ---- search ---- */
.welcome { font-size: 34px; margin: 8px 0 4px; }
.search-box {
  width: 100%; font-size: 34px; text-align: center; padding: 16px; margin: 24px 0 16px;
  border: 2px solid var(--line); border-radius: var(--radius); letter-spacing: 2px; background: #fff;
}
.search-box:focus { outline: none; border-color: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 420px; margin: 0 auto 20px; }
.keypad button {
  font-size: 30px; padding: 18px 0; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
}
.keypad button:active { background: #e8eef7; }

/* ---- households / people ---- */
.list { display: grid; gap: 12px; }
.row-btn {
  display: flex; justify-content: space-between; align-items: center; text-align: left;
  width: 100%; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  font-size: 20px;
}
.row-btn .muted { font-size: 15px; }

.person {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center;
  padding: 16px 18px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.person.selected { border-color: var(--brand); background: #f3f7fe; }
.person .check {
  width: 36px; height: 36px; border-radius: 10px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 22px; color: #fff; background: #fff;
}
.person.selected .check { background: var(--brand); border-color: var(--brand); }
.person .name { font-size: 22px; font-weight: 600; }
.person .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.person .alert { color: var(--warn); font-size: 14px; font-weight: 600; margin-top: 4px; }
.person select { padding: 10px; border-radius: 10px; border: 1px solid var(--line); min-width: 190px; background: #fff; }
.person .already { color: var(--ok); font-weight: 600; font-size: 14px; }

.actions { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 12px; }

.done-list { list-style: none; padding: 0; margin: 16px 0 28px; font-size: 20px; }
.done-list li { padding: 6px 0; }

/* ---- roster ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.toolbar select, .toolbar input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.stats { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; min-width: 140px; }
.stat b { display: block; font-size: 28px; }
.room { margin-bottom: 18px; }
.room h3 { margin: 0 0 8px; display: flex; justify-content: space-between; font-size: 17px; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 15px; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr.out td { color: var(--muted); }
.flag { color: var(--warn); font-weight: 600; }
.btn.sm { padding: 6px 12px; font-size: 14px; }

/* ---- admin ---- */
.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; padding: 12px 16px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.code-display {
  font-family: ui-monospace, Menlo, monospace; font-size: clamp(22px, 6vw, 40px); font-weight: 800; letter-spacing: 4px; white-space: nowrap;
  color: var(--brand); background: #f3f7fe; border: 2px dashed var(--brand); border-radius: var(--radius);
  padding: 12px 20px; display: inline-block;
}
.badge:empty { display: none; }
.status-pill { border: 1px solid #bbf7d0; background: #dcfce7; color: #166534; font-weight: 700; border-radius: 99px; padding: 6px 14px; }
.status-pill.closed { border-color: #fecaca; background: #fee2e2; color: #991b1b; }
.table-scroll { overflow-x: auto; }
.small { font-size: 12px; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.warn { background: #fef3c7; color: #92400e; }
.link-btn { border: none; background: none; color: var(--brand); padding: 0; font-size: 13px; }
tr.denied td { color: var(--warn); }
.settings { display: grid; gap: 16px; }
.settings .card h3 { margin-top: 0; }
.settings .field { margin: 12px 0; }
.switch { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-weight: 600; }
.switch input { width: 20px; height: 20px; }
details summary { cursor: pointer; }
.manual-household { border-top: 1px solid var(--line); padding: 12px 0; }
.manual-person { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0 6px 12px; }
.manual-person > span:first-child { min-width: 220px; }
.manual-person select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.already { color: var(--ok); font-weight: 600; font-size: 14px; }
.autoclose-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 24px; background: #fff7ed; border-bottom: 1px solid #fed7aa; color: #9a3412; font-weight: 600; font-size: 14px; }
.autoclose-bar input { padding: 6px 8px; border: 1px solid #fed7aa; border-radius: 8px; }
.tag.lock { background: #e0e7ff; color: #3730a3; }
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: grid; place-items: center; z-index: 50; }
.overlay .search-box { letter-spacing: 10px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
