:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --ink: #171a21;
  --ink-soft: #5b6273;
  --line: #e3e6ee;
  --accent: #4c3ee8;
  --accent-ink: #ffffff;
  --accent-soft: #ece9ff;
  --ok: #12855c;
  --ok-soft: #e2f6ee;
  --warn: #b4610b;
  --danger: #c02643;
  --free: #ffffff;
  --free-line: #c3c9d8;
  --selected: #4c3ee8;
  --sold: #dfe3ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 26, 33, .06), 0 8px 24px rgba(23, 26, 33, .06);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

/* ---------- Общие элементы ---------- */

.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pad {
  padding: 16px;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -.01em;
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.muted { color: var(--ink-soft); font-size: 13px; }
.small { font-size: 12px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: transform .06s ease, background .15s ease, opacity .15s ease;
}

.btn:active { transform: scale(.985); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Включённый режим (например, «Ряд»): кнопка показывает, что режим активен. */
.btn-mode-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.btn-ghost { background: transparent; }

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn-block { width: 100%; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

input[type="text"], input[type="password"], input[type="search"], select {
  font: inherit;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Места в SVG масштабируются вместе с залом, поэтому фокус рисуем обводкой. */
.hall-svg rect:focus {
  outline: none;
}

.hall-svg rect:focus-visible {
  stroke: #ff8a00;
  stroke-width: 1.2;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Навигация по чипам — удалена (пункт 4) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-soft { background: var(--accent-soft); color: var(--accent); }

/* ---------- Вход ---------- */

.login {
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.login-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 24px;
  margin-bottom: 8px;
}

/* ---------- Шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid transparent;
}

.topbar-solid {
  border-bottom-color: var(--line);
}

.topbar h1 { font-size: 17px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 18px;
  flex: none;
}

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 24px;
}

/* Контейнер схемы зала: занимает остаток высоты и не даёт странице скроллиться. */
.pick-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 16px 10px;
}

/* ---------- Сводка ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label { font-size: 12px; color: var(--ink-soft); }

.stat-accent { background: var(--accent); color: var(--accent-ink); }
.stat-accent .stat-label { color: rgba(255, 255, 255, .78); }

/* Кликабельные блоки сводки: ведут в отчёт по передачам и выдачам. */
.stat-link {
  position: relative;
  text-align: left;
  cursor: pointer;
  border: 0;
  font: inherit;
  color: inherit;
  transition: transform .06s ease, box-shadow .15s ease;
}

.stat-link:active { transform: scale(.985); }

.stat-link:disabled {
  cursor: default;
  opacity: .55;
}

.stat-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  color: var(--ink-soft);
  opacity: .5;
}

.picked-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Карточка выдачи: тап открывает QR этой же выдачи. */
.card-tappable {
  cursor: pointer;
  transition: transform .06s ease, box-shadow .15s ease;
}

.card-tappable:active { transform: scale(.99); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.session-date {
  flex: none;
  width: 54px;
  padding: 8px 0;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  text-align: center;
  font-weight: 700;
  line-height: 1.15;
}

.session-date .d { font-size: 18px; display: block; }
.session-date .m { font-size: 11px; text-transform: uppercase; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* ---------- Схема зала ---------- */

.hall-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}

.hall-svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

/* Места вне квоты: показываем для формы зала, но приглушённо. */
.seat {
  stroke: #e4e8f1;
  stroke-width: .2;
  fill: #eef1f7;
}

/* Квота пользователя: только эти места можно выбирать, рамка — цвет из 1С. */
.seat-inquota {
  stroke: var(--seat-stroke, #4c3ee8);
  stroke-width: .16;
  fill: #ffffff;
}

/* Недоступное место (вне квоты или продано): форма зала, заливка — цвет из 1С. */
.seat-off {
  fill: var(--seat-fill, #dfe3ec);
  stroke: var(--seat-fill, #dfe3ec);
}

.seat-sold {
  fill: #b9c0d0;
  stroke: #b9c0d0;
}

.seat-selected {
  fill: var(--selected);
  /* Обводка тем же цветом: зазоры между соседними местами создаёт геометрия,
     а не рамка — иначе она перекрывает зазор и места сливаются в полосу. */
  stroke: var(--selected);
  stroke-width: .05;
}

.seat-legend-free { fill: var(--free); stroke: var(--free-line); stroke-width: 1; }
.seat-legend-sold { fill: var(--sold); stroke: var(--sold); stroke-width: 1; }
.seat-legend-selected { fill: var(--selected); stroke: var(--selected); stroke-width: 1; }

.stage {
  fill: #eef0f6;
  stroke: var(--line);
  stroke-width: .5;
}

/* Подписи схемы (сцена, сегменты, ряды): рисуем текстом в сетке зала. */
.hall-label {
  fill: #8b93a7;
  font-weight: 600;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

.hall-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zoom-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 600;
}

.hall-hint {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(23, 26, 33, .78);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  max-width: 60%;
}

/* ---------- Нижняя панель выбора ---------- */

.selectbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}

.selectbar-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.selectbar-count { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Шторка ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 26, .42);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .16s ease;
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slide .2s ease;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 6px auto 2px;
}

.sheet h2 { font-size: 18px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide { from { transform: translateY(16px); } to { transform: translateY(0); } }

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.choice-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: none;
}

.choice-active .choice-icon { background: var(--accent); color: var(--accent-ink); }

.choice-title { font-weight: 600; }

/* ---------- QR ---------- */

.qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.qr-box {
  width: 220px;
  height: 220px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.qr-box svg { width: 100%; height: 100%; display: block; }

.link-box {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px dashed var(--line);
}

.link-text {
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.success-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 24px 16px;
}

.success-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  display: grid;
  place-items: center;
  font-size: 30px;
}

/* ---------- Списки ---------- */

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child { border-bottom: 0; }

.seat-tag {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Метка «Сегмент · ряд N» — заголовок группы мест. */
.seat-tag-row {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #1b1b2f;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 60;
  text-align: center;
}

.toast-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Пустое состояние ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 48px 24px;
  color: var(--ink-soft);
}

.empty-icon { font-size: 34px; }

.skeleton {
  background: linear-gradient(90deg, #eceef4, #f6f7fa, #eceef4);
  background-size: 200% 100%;
  animation: shimmer 1.1s infinite;
  border-radius: 12px;
  height: 72px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

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