:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #5d6470;
  --border: #e1e4e9;
  --primary: #2453d6;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefc;
  --ok: #18794e;
  --ok-soft: #e3f5ec;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --danger: #c4302b;
  --danger-soft: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #eceef2;
    --muted: #9aa2af;
    --border: #2a2f39;
    --primary: #6f94ff;
    --primary-ink: #0b1020;
    --primary-soft: #1c2742;
    --ok: #4cc38a;
    --ok-soft: #13291e;
    --warn: #f0b045;
    --warn-soft: #2e2311;
    --danger: #ff6b63;
    --danger-soft: #34171a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

/* ---------- Form controls ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field { margin-bottom: 1rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; font-weight: 400; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .7rem .8rem;
  min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .95rem;
  min-height: 42px; padding: .55rem 1rem;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; 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(--primary-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.alert { border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: .95rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--primary-soft); color: var(--primary); }

.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.pill.open { background: var(--ok-soft); color: var(--ok); }
.pill.closed, .pill.ended { background: var(--surface-2); color: var(--muted); }
.pill.scheduled { background: var(--primary-soft); color: var(--primary); }
.flag { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin: 0 .25rem .25rem 0; }
.flag.bad { background: var(--danger-soft); color: var(--danger); }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Check-in page ---------- */
.checkin { max-width: 440px; margin: 0 auto; padding: 24px 16px 48px; min-height: 100vh; }
.checkin .brand { font-weight: 700; color: var(--muted); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 1rem; }
.checkin h1 { font-size: 1.6rem; }
.checkin .venue { color: var(--muted); margin-bottom: 1.25rem; }
.checkin input[type=tel], .checkin input[type=text] { font-size: 1.15rem; min-height: 52px; }
.result { text-align: center; padding: 1.5rem .5rem; }
.result .icon { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 1rem; font-size: 2.2rem; }
.result.ok .icon { background: var(--ok-soft); color: var(--ok); }
.result.bad .icon { background: var(--danger-soft); color: var(--danger); }
.result.wait .icon { background: var(--primary-soft); color: var(--primary); }
.result .time { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .5rem 0; }
.notice { font-size: .8rem; color: var(--muted); margin-top: 1rem; }

/* ---------- Admin ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar .inner { max-width: 1120px; margin: 0 auto; padding: .75rem 16px; display: flex; align-items: center; gap: 1rem; }
.topbar .logo { font-weight: 800; text-decoration: none; color: var(--text); }
.topbar .spacer { flex: 1; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head .title { min-width: 0; }
.page-head h1 { word-break: break-word; }
.back { display: inline-block; margin-bottom: .5rem; text-decoration: none; font-size: .9rem; }

.event-list { display: grid; gap: .75rem; }
.event-item { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; text-decoration: none; color: inherit; }
.event-item:hover { border-color: var(--primary); }
.event-item .meta { color: var(--muted); font-size: .875rem; }
.event-item .count { text-align: right; font-variant-numeric: tabular-nums; }
.event-item .count strong { font-size: 1.4rem; display: block; line-height: 1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 1.9rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat .sub { font-size: .8rem; color: var(--muted); }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: .5rem; }
.progress > div { height: 100%; background: var(--ok); width: 0; transition: width .4s; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 300px 1fr; } }
.qr-box { text-align: center; }
.qr-box img { width: 100%; max-width: 240px; aspect-ratio: 1; background: #fff; border-radius: 8px; padding: 6px; }
.url-box { display: flex; gap: .5rem; margin: .5rem 0 1rem; }
.url-box input { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab { background: none; border: none; font: inherit; font-weight: 600; color: var(--muted); padding: .6rem .9rem; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: .75rem; }
.toolbar input[type=search] { max-width: 280px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.new td { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--ok-soft); } to { background: transparent; } }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.form-card { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1rem .25rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .35rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; font-size: .9rem; z-index: 100; max-width: calc(100% - 32px); }

.login { max-width: 380px; margin: 10vh auto; padding: 0 16px; }

/* ---------- Display (projector) ---------- */
.display { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3vh 16px; text-align: center; gap: 2vh; }
.display h1 { font-size: clamp(1.6rem, 4vw, 3.2rem); }
.display .qr { background: #fff; padding: 2vmin; border-radius: 16px; width: min(60vh, 86vw); aspect-ratio: 1; }
.display .qr svg { width: 100%; height: 100%; display: block; }
.display .instr { font-size: clamp(1rem, 2.2vw, 1.6rem); color: var(--muted); }
.display .live { font-size: clamp(1.2rem, 3vw, 2.2rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.display .rot { font-size: .9rem; color: var(--muted); }
.display .closed { font-size: clamp(1.4rem, 3vw, 2.4rem); color: var(--danger); font-weight: 700; }
.display-controls { position: fixed; top: 12px; right: 12px; display: flex; gap: .5rem; opacity: .35; }
.display-controls:hover { opacity: 1; }
