/* Оболочка берёт цвета из темы Telegram; билет — отдельный «бумажный» объект. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff3);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #e0393e);
  --section-hint: var(--tg-theme-section-header-text-color, var(--hint));
  --bar: var(--tg-theme-bottom-bar-bg-color, var(--surface));
  --sep: color-mix(in srgb, var(--hint) 24%, transparent);
  --fill: color-mix(in srgb, var(--hint) 13%, transparent);

  --ok: #1d8a4b;
  --deny: #d23535;
  --warn: #b97300;
  --paper: #ffffff;
  --ink: #161616;
  --ink-soft: #6b6b70;

  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --tabbar-h: 56px;

  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.4; min-height: 100vh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { padding: 12px 16px calc(28px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; }
#app.with-tabs { padding-bottom: calc(var(--tabbar-h) + 28px + var(--safe-bottom)); }

/* ---------- загрузка, пустые состояния ---------- */
.boot { min-height: 70vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--fill); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 12px; color: var(--hint); }
.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 6px; letter-spacing: -.01em; }
.empty p { margin: 0 auto; max-width: 30ch; }
.empty .btn { margin-top: 18px; }

/* ---------- типографика ---------- */
.page-title { font-size: 28px; line-height: 1.1; font-weight: 750; letter-spacing: -.025em; margin: 8px 0 4px; }
.page-sub { color: var(--hint); margin: 0 0 18px; }
.section-label { color: var(--section-hint); font-size: 14px; margin: 22px 4px 8px; }
.hint { color: var(--hint); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.98); opacity: .85; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.block { width: 100%; }
.btn.tonal { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--link); }
.btn.plain { background: var(--fill); color: var(--text); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.link-btn { background: none; border: 0; padding: 6px 0; color: var(--link); font-size: 15px; }
.link-btn.danger { color: var(--danger); }

/* ---------- сгруппированные списки как в Telegram ---------- */
.group { background: var(--surface); border-radius: 14px; overflow: hidden; }
.group + .group { margin-top: 14px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 48px; padding: 10px 16px; background: none; border: 0; text-align: left;
  position: relative;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--sep);
}
button.row:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--hint); font-size: 14px; }
.row-end { color: var(--hint); font-size: 15px; flex: none; display: flex; align-items: center; gap: 6px; }
.row-end.ok { color: var(--ok); }
.row-end.deny { color: var(--deny); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- поля ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--section-hint); margin: 0 4px 6px; }
.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid transparent; background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); }
.sheet .input { background: var(--fill); }
textarea.input { min-height: 84px; resize: vertical; }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: -4px 4px 10px; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.pick {
  min-width: 46px; height: 46px; padding: 0 12px; border-radius: 12px; border: 0;
  background: var(--surface); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.sheet .pick { background: var(--fill); }
.pick[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ---------- чипы и сегменты ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 999px; border: 0;
  background: var(--surface); font-size: 15px; font-weight: 500; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.chip .count { opacity: .55; margin-left: 4px; font-variant-numeric: tabular-nums; }

.segmented { display: flex; background: var(--fill); border-radius: 10px; padding: 2px; margin-top: 10px; }
.segmented button {
  flex: 1; border: 0; background: none; height: 32px; border-radius: 8px; font-size: 13px; font-weight: 500;
  color: var(--text); white-space: nowrap; padding: 0 4px;
}
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- билет ---------- */
.profile-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 4px 16px; }
.profile-line .who { color: var(--hint); font-size: 15px; }

.ticket {
  position: relative; margin: 0 0 22px; border-radius: 20px; background: var(--paper); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 14px 32px -18px rgba(0, 0, 0, .45);
}
.ticket-main { padding: 20px 20px 18px; }
.ticket-event { font-size: 22px; line-height: 1.15; font-weight: 750; letter-spacing: -.02em; margin: 0; }
.ticket-date { color: var(--ink-soft); font-size: 15px; margin-top: 4px; }
.ticket-who { display: flex; align-items: flex-end; gap: 16px; margin-top: 22px; }
.ticket-class {
  font-size: 84px; line-height: .78; font-weight: 800; letter-spacing: -.055em;
  font-variant-numeric: tabular-nums; flex: none;
}
.ticket-name { font-size: 18px; line-height: 1.2; font-weight: 600; padding-bottom: 2px; min-width: 0; overflow-wrap: anywhere; }
.ticket-name small { display: block; font-weight: 500; color: var(--ink-soft); font-size: 16px; }

.ticket-perf { position: relative; height: 22px; }
.ticket-perf::before, .ticket-perf::after {
  content: ""; position: absolute; top: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--bg);
}
.ticket-perf::before { left: -11px; }
.ticket-perf::after { right: -11px; }
.ticket-perf span {
  position: absolute; left: 18px; right: 18px; top: 10px; height: 0;
  border-top: 2px dashed #d9d9de;
}
.ticket-stub { position: relative; padding: 14px 20px 20px; text-align: center; }
.qr {
  display: block; width: min(64vw, 240px); aspect-ratio: 1; margin: 0 auto; padding: 0; border: 0; background: none;
}
.qr svg { display: block; width: 100%; height: 100%; }
.ticket-note { color: var(--ink-soft); font-size: 14px; margin: 12px 0 0; }
.ticket-actions { margin-top: 6px; }
.ticket-actions .link-btn { color: var(--ink-soft); font-size: 14px; }

.ticket.used .qr { opacity: .28; }
.stamp {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) rotate(-9deg);
  border: 3px solid var(--ok); color: var(--ok); background: rgba(255, 255, 255, .9);
  border-radius: 10px; padding: 6px 14px 7px; font-weight: 800; font-size: 22px; line-height: 1.1;
  white-space: nowrap; letter-spacing: -.01em; animation: stamp .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
.stamp small { display: block; font-size: 14px; font-weight: 700; }
@keyframes stamp { from { transform: translate(-50%, -50%) rotate(-9deg) scale(1.6); opacity: 0; } }

.ticket.void { color: #8b8b90; }
.ticket.void .ticket-class { color: #c4c4c8; }
.void-note { color: var(--deny); font-weight: 600; margin: 4px 0 2px; }

/* карточка «записаться» */
.card { background: var(--surface); border-radius: 16px; padding: 18px; margin-bottom: 14px; }
.card h2 { font-size: 20px; line-height: 1.2; margin: 0; letter-spacing: -.015em; }
.card .meta { color: var(--hint); margin: 4px 0 14px; font-size: 15px; }
.notice {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.35;
  background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--text);
}
.ticket-doc { color: var(--ink); font-weight: 600; font-size: 15px; margin: 12px 0 0; }
.ticket-doc + .ticket-note { margin-top: 2px; }
.card .as { color: var(--hint); font-size: 14px; margin: 10px 0 0; text-align: center; }

/* полноэкранный QR */
.qr-full {
  position: fixed; inset: 0; z-index: 60; background: #fff; color: #111;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px;
  border: 0; width: 100%;
}
.qr-full .qr { width: min(86vw, 420px); }
.qr-full .who { font-size: 22px; font-weight: 700; text-align: center; }
.qr-full .hint { color: #777; }

/* ---------- вход ---------- */
.event-switch { margin-bottom: 14px; }
.event-title-static { font-weight: 650; font-size: 17px; margin: 4px 4px 12px; }
.counter {
  background: var(--surface); border-radius: 16px; padding: 16px 18px; display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 12px;
}
.counter b { font-size: 44px; line-height: 1; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.counter span { color: var(--hint); }
.counter .bar { flex: 1; align-self: center; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; margin-left: 6px; }
.counter .bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

.scan-btn { min-height: 64px; font-size: 18px; border-radius: 16px; }
.scan-btn svg { width: 24px; height: 24px; }

.result {
  margin-top: 14px; border-radius: 18px; padding: 22px 20px 20px; color: #fff; background: var(--hint);
  animation: pop .22s ease-out;
}
.result.ok { background: var(--ok); }
.result.deny { background: var(--deny); }
.result.warn { background: var(--warn); }
.result .verdict { font-size: 15px; font-weight: 700; opacity: .9; }
.result .person { font-size: 30px; line-height: 1.08; font-weight: 800; letter-spacing: -.025em; margin-top: 8px; overflow-wrap: anywhere; }
.result .cls { font-size: 22px; font-weight: 700; margin-top: 4px; opacity: .95; }
.result .extra { margin-top: 10px; font-size: 15px; opacity: .92; }
.result .btn { margin-top: 16px; background: rgba(255, 255, 255, .22); color: #fff; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } }

/* ---------- списки ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--hint); }
.search .input { padding-left: 38px; min-height: 42px; border-radius: 11px; }
.summary { color: var(--hint); font-size: 14px; margin: 14px 4px 0; }
.class-head { display: flex; justify-content: space-between; color: var(--section-hint); font-size: 14px; margin: 20px 4px 7px; }
.class-head b { color: var(--text); font-size: 15px; }

/* ---------- мероприятия ---------- */
.ev-card { background: var(--surface); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.ev-card .head { padding: 16px 16px 12px; }
.ev-card h3 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -.01em; }
.ev-card .meta { color: var(--hint); font-size: 14px; margin-top: 3px; }
.stats { display: flex; gap: 20px; padding: 0 16px 14px; }
.stats div { font-size: 13px; color: var(--hint); }
.stats b { display: block; font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ev-card .row { border-top: 1px solid var(--sep); }
.ev-card .row + .row::before { display: none; }
.ev-card .actions { display: flex; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--sep); }
.state-open { color: var(--ok); font-weight: 600; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--fill); transition: background .2s; pointer-events: none; }
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- команда ---------- */
.role-tag { font-size: 13px; padding: 3px 8px; border-radius: 6px; background: var(--fill); color: var(--hint); }
.role-tag.founder { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--link); }
.roles-legend { margin: 10px 4px 0; color: var(--hint); font-size: 14px; }
.roles-legend p { margin: 4px 0; }
.invite-box {
  background: var(--fill); border-radius: 12px; padding: 12px 14px; font-size: 14px; word-break: break-all;
  user-select: all; margin: 12px 0;
}

/* ---------- нижняя панель ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: var(--bar); border-top: 1px solid var(--sep); padding-bottom: var(--safe-bottom);
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; height: var(--tabbar-h); border: 0; background: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 500;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- шторка ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 8px 18px calc(22px + var(--safe-bottom));
  animation: up .24s cubic-bezier(.2, .9, .3, 1);
}
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 14px; }
.sheet h2 { margin: 0; font-size: 24px; line-height: 1.15; letter-spacing: -.02em; }
.sheet .sub { color: var(--hint); margin: 4px 0 16px; }
.sheet .stack { display: grid; gap: 10px; margin-top: 18px; }
.facts { margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--sep); font-size: 15px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; text-align: right; }
.facts .ok { color: var(--ok); font-weight: 600; }
.facts .deny { color: var(--deny); font-weight: 600; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }

/* ---------- тост ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 18px); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(30, 30, 32, .94); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 15px;
  max-width: calc(100% - 32px); width: max-content; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.has-tabs #toast { bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 14px); }

/* в тёмной теме Telegram зелёный и красный чуть светлее, чтобы читались на чёрном */
:root[data-scheme="dark"] { --ok: #23a058; --deny: #e04646; --warn: #c88400; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- фото участников ---------- */
.photo {
  position: relative; overflow: hidden; background: var(--fill); color: var(--hint);
  display: grid; place-items: center; text-align: center; font-size: 13px; line-height: 1.3; flex: none;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo span { padding: 8px; }
.photo.big { height: min(44vh, 400px); max-width: 100%; aspect-ratio: 3 / 4; margin: 0 auto; border-radius: 16px; font-size: 15px; }
.photo.mid { width: 72px; height: 96px; border-radius: 12px; }
.photo.mini { width: 54px; height: 72px; border-radius: 10px; background: rgba(255, 255, 255, .2); }
.photo.thumb { width: 42px; height: 56px; border-radius: 8px; background: #ececf0; }
.spinner.small { width: 20px; height: 20px; border-width: 2px; }

.person-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.person-head .sub { margin-bottom: 0; }

/* своё фото на билете */
.ticket-selfie {
  display: flex; align-items: center; gap: 12px; text-align: left; margin: 16px 0 0;
  padding: 10px 12px; border-radius: 12px; background: #f3f3f6;
}
.ticket-selfie.missing { background: #fdf0d9; }
.ticket-selfie-text { display: flex; flex-direction: column; font-size: 14px; color: var(--ink); line-height: 1.3; }
.ticket-selfie-text .link-btn { padding: 2px 0 0; font-size: 14px; color: #2481cc; align-self: flex-start; }

/* проверяющий: сверка лица */
.verify { margin-top: 4px; background: var(--surface); border-radius: 18px; padding: 16px 16px 18px; animation: pop .22s ease-out; }
.verify-title { color: var(--hint); font-size: 15px; font-weight: 600; text-align: center; margin-bottom: 12px; }
.verify-name { font-size: 26px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; text-align: center; margin-top: 12px; overflow-wrap: anywhere; }
.verify-cls { color: var(--hint); font-size: 18px; font-weight: 600; text-align: center; margin-top: 4px; }
.verify-actions { display: grid; gap: 8px; margin-top: 14px; }
.verify-yes { background: var(--ok); color: #fff; min-height: 56px; font-size: 17px; }

.result-who { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.result-who .person { margin-top: 0; }

/* экран камеры */
.cam {
  position: fixed; inset: 0; z-index: 80; background: #000; color: #fff;
  display: flex; flex-direction: column; padding-bottom: var(--safe-bottom);
}
.cam-top { display: flex; align-items: center; justify-content: center; position: relative; height: 52px; flex: none; }
.cam-top b { font-size: 17px; }
.cam-close { position: absolute; left: 8px; top: 8px; height: 36px; padding: 0 10px; border: 0; background: none; color: #fff; font-size: 16px; }
.cam-stage { position: relative; flex: 1; min-height: 0; margin: 0 16px; border-radius: 22px; overflow: hidden; background: #111; }
.cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
video.cam-video { transform: scaleX(-1); } /* как в зеркале, привычно для селфи */
.cam-oval {
  position: absolute; left: 50%; top: 46%; width: 62%; aspect-ratio: 3 / 4; transform: translate(-50%, -50%);
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .38);
}
.cam-bottom { flex: none; padding: 14px 20px 18px; text-align: center; }
.cam-status { margin: 0 0 6px; font-weight: 600; }
.cam-note { margin: 0 auto 14px; max-width: 34ch; font-size: 13px; line-height: 1.35; color: rgba(255, 255, 255, .7); }
.cam-shutter {
  width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: #fff;
  box-shadow: inset 0 0 0 4px #000; display: block; margin: 0 auto;
}
.cam-shutter:active { transform: scale(.94); }
.cam-shutter[disabled] { opacity: .35; }
.cam .btn.plain { background: rgba(255, 255, 255, .14); color: #fff; }
