:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #18202c;
  --muted: #5d6879;
  --border: #dbe1ea;
  --primary: #2357d9;
  --primary-hover: #1b47b8;
  --on-primary: #ffffff;
  --ok: #157a3c;
  --ok-bg: #dcf5e4;
  --warn: #a35a00;
  --warn-bg: #fdf0d5;
  --danger: #b42323;
  --danger-bg: #fde3e3;
  --info: #1d4ed8;
  --info-bg: #dde8fd;
  --guest: #8a3ffc;
  --guest-bg: #efe6ff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171d26;
    --surface-2: #1f2733;
    --text: #e7ecf3;
    --muted: #97a3b6;
    --border: #2b3542;
    --primary: #5b8cff;
    --primary-hover: #7aa2ff;
    --on-primary: #0b1020;
    --ok: #5fd68b;
    --ok-bg: #16351f;
    --warn: #f3b552;
    --warn-bg: #3a2a10;
    --danger: #ff7b7b;
    --danger-bg: #3d1616;
    --info: #8fb0ff;
    --info-bg: #1a2747;
    --guest: #c6a2ff;
    --guest-bg: #2c1f47;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.brand .dot.on { background: var(--ok); }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted);
  white-space: nowrap; font-weight: 500; position: relative;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--info-bg); color: var(--info); }
.nav .count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: .72rem; line-height: 18px; text-align: center;
}
.userbox { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
main.wide { max-width: none; padding: 16px 1.5vw; }

/* ---------- generic ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ok { color: var(--ok); border-color: var(--ok); }
.btn-ok:hover { background: var(--ok-bg); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-ghost { border-color: transparent; background: transparent; }

label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 2px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number],
input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
#c-probe .pill { white-space: normal; border-radius: 8px; padding: 6px 10px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.guest { background: var(--guest-bg); color: var(--guest); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  background: var(--surface-2); flex: none;
}
.avatar.lg { width: 72px; height: 72px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 4px solid var(--info); box-shadow: 0 6px 20px rgba(0,0,0,.15);
  animation: slidein .2s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.danger { border-left-color: var(--danger); }
.toast.guest { border-left-color: var(--guest); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 15, 25, .5); }
dialog form, dialog .dialog-body { padding: 20px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); }

/* ---------- dashboard ---------- */
.dash { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.dash > .full { grid-column: 1 / -1; }
@media (max-width: 900px) { .dash { grid-template-columns: minmax(0, 1fr); } }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stats .stat { text-align: center; padding: 14px 16px; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.guest .value { color: var(--guest); }

.hero { display: flex; gap: 20px; align-items: center; min-height: 220px; transition: background .3s; }
.hero .photos { display: flex; gap: 10px; align-items: flex-end; flex: none; }
.hero .photo { width: 170px; height: 170px; border-radius: 16px; object-fit: cover; background: var(--surface-2); }
.hero .snap { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; background: var(--surface-2); }
.hero .name { font-size: 2rem; font-weight: 800; line-height: 1.15; }
.hero .position { font-size: 1.15rem; color: var(--muted); margin: 4px 0 10px; }
.hero .pill { font-size: .95rem; padding: 4px 14px; }
.hero.flash-ok { background: var(--ok-bg); }
.hero.flash-info { background: var(--info-bg); }
.hero.flash-guest { background: var(--guest-bg); }
.hero.flash-warn { background: var(--warn-bg); }
@media (max-width: 600px) {
  .hero { flex-direction: column; text-align: center; }
  .hero .photo { width: 140px; height: 140px; }
  .hero .name { font-size: 1.5rem; }
}

.snap-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; background: var(--surface-2); }

/* checked-in roll: everyone who has checked in, in order, with full details */
.roll { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; padding: 2px; }
.roll-item { position: relative; display: flex; gap: 10px; align-items: center; padding: 8px 10px;
  border: 1px solid var(--border, rgba(128,128,128,.25)); border-radius: 14px; background: var(--surface-2);
  transition: background .4s, box-shadow .4s; }
.roll-item.late { border-left: 4px solid var(--warn); }
.roll-item.new { background: var(--ok-bg); box-shadow: 0 0 0 2px var(--ok); }
.roll-item .no { position: absolute; top: 6px; right: 10px; font-size: .8rem; color: var(--muted); font-weight: 700; }
.roll-item .photos { display: flex; gap: 6px; align-items: flex-end; flex: none; }
.roll-item .photo { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--surface); }
.roll-item .snap { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface); }
.roll-item .name { font-size: 1.1rem; font-weight: 800; line-height: 1.2; padding-right: 22px; }
.roll-item .position { color: var(--muted); font-size: .88rem; margin: 2px 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.roll-item .time { font-size: .9rem; }
/* large screen / meeting-room projector: 6 columns x 4 rows (24 people) fill one screen, no scrolling */
@media (min-width: 1200px) {
  .roll { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); grid-auto-rows: minmax(150px, 1fr); gap: 12px;
    height: calc(100vh - 330px); min-height: 460px; overflow-y: auto; }
  .roll-item { flex-direction: column; justify-content: center; text-align: center; gap: 6px; padding: 8px; min-height: 0; }
  .roll-item .photo { width: clamp(64px, 9vh, 150px); height: clamp(64px, 9vh, 150px); }
  .roll-item .name { font-size: clamp(.95rem, 1.35vw, 1.7rem); padding-right: 0; }
  .roll-item .position { font-size: clamp(.78rem, .95vw, 1.15rem); -webkit-line-clamp: 2; margin: 0 0 2px; }
  .roll-item .time { font-size: clamp(.78rem, .95vw, 1.1rem); }
  .roll-item .no { top: 4px; right: 8px; }
}
.alert-box { border-left: 4px solid var(--warn); }
.alert-box.danger { border-left-color: var(--danger); }
.names { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { color: var(--muted); font-size: .85rem; }
.list-item .times { text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; white-space: nowrap; }
.scroll { max-height: 520px; overflow-y: auto; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.thumbs figure { margin: 0; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.thumbs figcaption { font-size: .75rem; color: var(--muted); text-align: center; }

/* ---------- camera ---------- */
.stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.stage video { width: 100%; height: auto; display: block; }
.stage video.mirror { transform: scaleX(-1); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stage .placeholder { color: #ccd; padding: 80px 16px; text-align: center; }
.cam-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .cam-layout { grid-template-columns: minmax(0, 1fr); } }
.welcome { text-align: center; padding: 20px; }
.welcome .photo { width: 140px; height: 140px; margin: 0 auto 10px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.welcome .name { font-size: 1.6rem; font-weight: 800; }

/* ---------- persons / requests ---------- */
.person-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.person-card { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.person-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.person-card .name { font-weight: 700; }
.photo-preview { width: 160px; height: 160px; object-fit: cover; border-radius: 12px; background: var(--surface-2); margin-top: 8px; }

.req { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; }
.req .imgs { display: flex; gap: 8px; align-items: center; }
.req .imgs img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
@media (max-width: 600px) { .req { grid-template-columns: minmax(0, 1fr); } }
.diff del { color: var(--danger); }
.diff ins { color: var(--ok); text-decoration: none; font-weight: 600; }
