@font-face { font-family: 'DM Sans'; font-weight: 100 1000; font-display: swap; src: url(/fonts/dm-sans.woff2) format('woff2'); }
@font-face { font-family: 'DM Serif Display'; font-weight: 400; font-display: swap; src: url(/fonts/dm-serif-display.woff2) format('woff2'); }

:root {
  --bg: #FBF5E2; --panel: #FFFDF6; --ink: #3A1F26; --muted: #6B4A52; --line: #E6D9B8;
  --green: #2F7A47; --green-soft: #E3F1E4; --pink: #C42B66; --brown: #6B3A2A; --brown-soft: #F3E3DC;
  --amber-soft: #FBEFC9;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 'DM Sans', system-ui, sans-serif; }
body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
h1, h2 { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 21px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--green); margin: 0; }
a { color: inherit; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
small, .muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; }
.main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; display: flex; flex-direction: column; gap: 18px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.empty { color: var(--muted); text-align: center; padding: 28px; margin: 0; }
.flash { background: var(--green-soft); color: var(--green); border-radius: 10px; padding: 10px 14px; font-weight: 500; }
.error { color: var(--pink); margin: 0; padding-left: 18px; }
p.error { padding: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--ink); background: var(--panel); color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: #276a3c; }
.btn.danger { border-color: var(--pink); color: var(--pink); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wa { border-color: #25A35A; color: #1d8a4b; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; cursor: pointer; }
.link.danger { color: var(--pink); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form .btn { align-self: flex-start; }
.form.inline { flex-direction: row; align-items: flex-end; }
.form.inline label { flex: 1; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 14px; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
input[type=file] { padding: 7px; }
textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.login img { align-self: center; }
.login h1 { text-align: center; font-size: 24px; }
.danger-zone { display: flex; justify-content: flex-end; }

.cards { display: grid; gap: 12px; }
.event-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; text-decoration: none; transition: border-color .15s; }
.event-card:hover { border-color: var(--green); }
.event-card.past { opacity: .65; }
.event-title { display: flex; flex-direction: column; gap: 2px; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 78px; padding: 8px 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.stat b { font-size: 20px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.yes b { color: var(--green); }
.stat.no b { color: var(--brown); }
.stat.in b { color: var(--pink); }

.add summary { cursor: pointer; font-weight: 700; }
.add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; margin-top: 16px; }

.add > p { margin: 8px 0 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; accent-color: var(--green); }
.fields { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.field-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.field-main .badge { align-self: flex-start; }
.field-actions { display: flex; gap: 6px; align-items: center; }
.field-actions form { margin: 0; }
.btn:disabled { opacity: .35; cursor: default; }
.opt-counts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.opt-counts span { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.opt-counts b { color: var(--green); margin-left: 2px; }
.opt-counts .other b { color: var(--muted); }
td.q-col, th.q-col { max-width: 200px; font-size: 13px; }
table.map td { vertical-align: middle; }
table.map select { min-width: 200px; }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.table-head input { width: 220px; }
.table-wrap { overflow-x: auto; margin: 0 -18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 18px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; border-top: 0; }
td form { margin: 0; }
.guest-cell { min-width: 220px; }
.guest-cell b { display: block; font-size: 13.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; line-height: 1.3; }
.contact { display: flex; flex-direction: column; gap: 2px; margin-top: 5px; }
.ci { display: flex; align-items: center; gap: 7px; max-width: 260px; font-size: 12.5px; line-height: 1.35; color: var(--muted); text-decoration: none; }
.ci span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci svg { flex: none; }
.ci:hover span { color: var(--ink); text-decoration: underline; }
.ci.email svg { color: #9A7B83; }
.ci.tg svg { color: #229ED9; }
.ci.phone svg { color: var(--green); }
.ci.phone span { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.ci.missing { display: none; }
.compact .contact { flex-direction: row; gap: 5px; margin-top: 6px; }
.compact .ci { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); background: #fff; }
.compact .ci span { display: none; }
.compact a.ci:hover { border-color: currentColor; background: var(--bg); }
.compact .ci.email { color: #9A7B83; }
.compact .ci.tg { color: #229ED9; }
.compact .ci.phone { color: var(--green); }
.compact .ci.missing { opacity: .3; background: transparent; border-style: dashed; color: var(--muted); }
.compact .guest-cell { min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: 4px; }
.row-actions form { margin: 0 0 0 6px; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; padding: 0; transition: background .15s, color .15s, border-color .15s; }
.icon-btn:hover { background: var(--bg); border-color: var(--ink); }
.icon-btn.wa { color: #1FA855; }
.icon-btn.wa:hover { background: #E4F7EA; border-color: #1FA855; }
.icon-btn.danger { color: #C8323C; }
.icon-btn.danger:hover { background: #FBE6E7; border-color: #C8323C; }
.icon-btn.copied { background: var(--green); border-color: var(--green); color: #fff; }
.icon-btn.placeholder { visibility: hidden; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--amber-soft); color: #7a5b12; border: 0; font-family: inherit; white-space: nowrap; }
.badge.yes { background: var(--green-soft); color: var(--green); }
.badge.no { background: var(--brown-soft); color: var(--brown); }
button.badge.in { background: var(--green); color: #fff; cursor: pointer; }
tr[hidden] { display: none; }

.scanner { display: flex; flex-direction: column; gap: 14px; max-width: 520px; width: 100%; margin: 0 auto; }
.viewport { position: relative; aspect-ratio: 1 / 1; background: #1f1215; border-radius: 18px; overflow: hidden; display: grid; place-items: center; }
.viewport video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.viewport .frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); pointer-events: none; }
.viewport #start { position: relative; z-index: 1; }
.result { border-radius: 14px; padding: 16px 18px; font-size: 16px; }
.result b { display: block; font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; font-size: 26px; line-height: 1.15; }
.result.ok { background: var(--green); color: #fff; }
.result.warn { background: var(--amber-soft); color: #5e450c; }
.result.bad { background: var(--pink); color: #fff; }

@media (max-width: 640px) {
  h1 { font-size: 25px; }
  .row { grid-template-columns: 1fr; }
  .table-head input { width: 100%; }
  .stat { min-width: 0; flex: 1; }
}

.live-badge { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; vertical-align: middle; font: 700 11px/1 'DM Sans', system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--green); }
.live-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 2s ease-in-out infinite; }
.live-badge.off { color: var(--muted); }
.live-badge.off::before { animation: none; }
@keyframes pulse { 50% { opacity: .3; } }
tr.changed td { animation: changed 2.5s ease-out; }
@keyframes changed { 0%, 30% { background: var(--green-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .live-badge::before, tr.changed td { animation: none; } }

label.toggle { font-size: 14px; white-space: nowrap; cursor: pointer; }
.legend { display: none; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; }
.legend span::before { content: ''; width: 10px; height: 10px; border-radius: 3px; }
.legend .here::before { background: var(--green); }
.legend .expected::before { background: #E0A526; }
.legend .other::before { background: var(--line); }
.highlighting .legend { display: flex; }
.highlighting tr[data-attendance] td:first-child { box-shadow: inset 4px 0 0 var(--bar, transparent); }
.highlighting tr[data-attendance="here"] { --bar: var(--green); }
.highlighting tr[data-attendance="here"] td { background: #DCEFDD; }
.highlighting tr[data-attendance="expected"] { --bar: #E0A526; }
.highlighting tr[data-attendance="expected"] td { background: #FCF1D2; }
.highlighting tr[data-attendance="other"] td { color: var(--muted); opacity: .7; }

/* Telegram panel */
#telegram-status { margin-top: 12px; display: grid; gap: 10px; }
#telegram-status p { margin: 0; }
.notice { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--bg); }
.notice.warn { background: var(--amber-soft); color: #5e450c; display: grid; gap: 8px; justify-items: start; }
.notice.bad { background: var(--brown-soft); color: var(--brown); }
.opt-counts form { display: inline; align-self: center; }
.pacing { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.pacing summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.pacing summary .muted { font-weight: 400; }
.pacing .form { margin-top: 12px; max-width: 480px; }
.failures summary { cursor: pointer; font-size: 13px; color: var(--pink); }
.failures ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.icon-btn.tg { color: #229ED9; }
.choices { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.choices a.badge { text-decoration: none; background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.choices a.badge:hover { border-color: var(--ink); }

/* Engagement */
.bar-actions { display: flex; align-items: center; gap: 16px; }
.count { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 999px; background: var(--pink); color: #fff; font-size: 12px; font-weight: 700; text-align: center; text-decoration: none; }
.funnel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 13px; color: var(--muted); }
.funnel span { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); }
.funnel b { color: var(--ink); margin-left: 2px; }
.funnel i { font-style: normal; }
.funnel .sep { padding: 0; border: 0; width: 8px; background: none; }
.activity { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; line-height: 1.35; white-space: nowrap; }
.act { color: var(--ink); text-decoration: none; }
.act.seen { color: var(--green); }
.act.bad { color: var(--pink); }
a.act.reply { color: #1d7fb0; text-decoration: underline; }
a.act.reply.unread { font-weight: 700; color: var(--pink); }

/* Conversation */
.chat { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: min(520px, 85%); padding: 8px 12px; border-radius: 14px; display: grid; gap: 4px; }
.msg pre { margin: 0; font: inherit; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg small { font-size: 11.5px; }
.msg.out { align-self: flex-end; background: var(--green-soft); border-bottom-right-radius: 4px; }
.msg.out.failed, .msg.out.skipped { background: var(--brown-soft); }
.msg.out.queued { background: var(--bg); border: 1px dashed var(--line); }
.msg.in { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.in.new { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink); }
.msg .seen { color: var(--green); font-weight: 700; }

/* Inbox */
.inbox { list-style: none; margin: 0; padding: 0; }
.inbox li { padding: 12px 4px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.inbox li:first-child { border-top: 0; }
.inbox li p { flex-basis: 100%; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.inbox li.unread p { color: var(--ink); font-weight: 500; }
