/* «Кто крайний?» — стили мини-приложения.
   Цвета берутся из темы Telegram (переменные --tg-theme-*), запасные — из макета.
   Чтобы поменять фирменный цвет или скругления — правьте блок :root ниже. */

:root {
  --radius: 16px;
  --radius-s: 12px;
  --gap: 12px;
  --pad: 16px;
  --font: -apple-system, "SF Pro Text", Inter, Roboto, system-ui, sans-serif;

  --bg-fallback: #F1F2F6;
  --card-fallback: #FFFFFF;
  --text-fallback: #0B0B0D;
  --hint-fallback: #66666C;
  --accent-fallback: #1E6FB8;
  --onaccent-fallback: #FFFFFF;
  --danger-fallback: #B3261E;

  --sep: #E3E4E9;
  --soft: #E8F1FA;
  --ok: #1C7C45;
  --oksoft: #E3F3E9;
  --warn: #9A5400;
  --warnsoft: #FBEEDD;
  --chip: #E3E4E9;
  --overlay: rgba(0, 0, 0, 0.38);
}

:root[data-theme="dark"] {
  --bg-fallback: #101012;
  --card-fallback: #1D1D20;
  --text-fallback: #F2F2F5;
  --hint-fallback: #A3A3AB;
  --accent-fallback: #5AA6EE;
  --onaccent-fallback: #06121F;
  --danger-fallback: #FF8A80;

  --sep: #2C2C31;
  --soft: #17293B;
  --ok: #4CC27E;
  --oksoft: #14301F;
  --warn: #F0A54A;
  --warnsoft: #3A2810;
  --chip: #2C2C31;
  --overlay: rgba(0, 0, 0, 0.55);
}

:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--bg-fallback));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--card-fallback)));
  --text: var(--tg-theme-text-color, var(--text-fallback));
  --hint: var(--tg-theme-hint-color, var(--hint-fallback));
  --accent: var(--tg-theme-button-color, var(--accent-fallback));
  --onaccent: var(--tg-theme-button-text-color, var(--onaccent-fallback));
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, var(--danger-fallback));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { font-size: 15px; line-height: 1.4; min-height: 100vh; overscroll-behavior-y: none; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--text); }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; gap: var(--gap); padding: 14px var(--pad) 16px; }
.screen.has-bar { padding-bottom: 104px; }

/* ---------- заголовок экрана */
.top { display: flex; align-items: flex-start; gap: 10px; }
.top .t { flex: 1; min-width: 0; }
.top h1 { margin: 0; font-size: 22px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.top .sub { font-size: 13px; color: var(--hint); margin-top: 3px; }
.switcher { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; display: inline-flex; align-items: center; gap: 4px; }
.switcher h1 { display: inline; }
.switcher .caret { color: var(--hint); font-size: 16px; }

/* ---------- карточки и текст */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card.tight { padding: 0 14px; gap: 0; }
.card.center { align-items: center; text-align: center; }
.card.ok { background: var(--oksoft); }
.card.warn { background: var(--warnsoft); }
.card.soft { background: var(--soft); }
.label { font-size: 13px; color: var(--hint); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.label.ok { color: var(--ok); } .label.warn { color: var(--warn); } .label.accent { color: var(--accent); }
.hint { font-size: 13px; color: var(--hint); line-height: 1.45; }
.p { font-size: 15px; line-height: 1.45; margin: 0; }
.h2 { font-size: 20px; font-weight: 800; line-height: 1.2; margin: 0; }
.h2.ok { color: var(--ok); } .h2.warn { color: var(--warn); }
.big { font-size: 56px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.big.ok { color: var(--ok); } .big.warn { color: var(--warn); } .big.accent { color: var(--accent); }
.mid { font-size: 34px; font-weight: 800; line-height: 1.05; }
.bullets { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.5; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mono { font-family: ui-monospace, Menlo, monospace; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- кнопки */
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 50px; border: 0; border-radius: var(--radius-s);
  padding: 0 16px; font-size: 17px; font-weight: 700; cursor: pointer; background: var(--accent); color: var(--onaccent); width: 100%; text-align: center; }
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.45; cursor: default; transform: none; }
.btn.soft { background: var(--soft); color: var(--accent); }
.btn.ok { background: var(--ok); color: #FFFFFF; }
.btn.danger { background: var(--danger); color: #FFFFFF; }
.btn.ghost { background: transparent; color: var(--link); min-height: 44px; font-weight: 600; font-size: 16px; }
.btn.plain { background: var(--bg); color: var(--text); }
.btn.small { min-height: 40px; font-size: 15px; padding: 0 12px; border-radius: 10px; }
.btn.xl { min-height: 64px; font-size: 20px; }
.btn.busy { opacity: 0.6; pointer-events: none; }

.bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px var(--pad) calc(16px + env(safe-area-inset-bottom)); background: var(--bg);
  display: flex; flex-direction: column; gap: 6px; max-width: 560px; margin: 0 auto; z-index: 5; }

/* ---------- списки */
.item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--sep); background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; cursor: pointer; color: var(--text); }
.item:last-child { border-bottom: 0; }
.item .num { width: 52px; font-size: 15px; font-weight: 800; color: var(--accent); flex-shrink: 0; }
.item .ttl { font-size: 15px; font-weight: 600; }
.item .meta { font-size: 12px; color: var(--hint); }
.chev { color: var(--hint); flex-shrink: 0; }
.qcard { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 12px; border: 0; width: 100%; text-align: left; cursor: pointer; color: var(--text); }
.qcard .badge-num { min-width: 56px; height: 52px; border-radius: 12px; background: var(--soft); color: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; flex-shrink: 0; padding: 0 6px; }
.qcard .badge-num.ok { background: var(--oksoft); color: var(--ok); }
.qcard .badge-num.warn { background: var(--warnsoft); color: var(--warn); }

/* ---------- метки */
.tag { font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 8px; flex-shrink: 0; background: var(--chip); color: var(--hint); }
.tag.ok { background: var(--oksoft); color: var(--ok); }
.tag.warn { background: var(--warnsoft); color: var(--warn); }
.tag.accent { background: var(--soft); color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 16px; background: var(--card); color: var(--text); border: 0; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--onaccent); }
.numchip { background: var(--bg); border-radius: 10px; padding: 6px 12px; font-size: 18px; font-weight: 700; border: 0; cursor: pointer; color: var(--text); }

/* ---------- сегменты, переключатели, счётчики */
.seg { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; background: var(--chip); border-radius: 10px; padding: 3px; }
.seg button { border: 0; padding: 8px 4px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; background: transparent; color: var(--text); }
.seg button.on { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.switch { width: 51px; height: 31px; border-radius: 16px; border: 0; padding: 2px; cursor: pointer; flex-shrink: 0; display: flex; background: var(--chip); justify-content: flex-start; transition: background .15s; }
.switch.on { background: var(--ok); justify-content: flex-end; }
.switch span { width: 27px; height: 27px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.stepper { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--soft); color: var(--accent); font-size: 20px; font-weight: 700; cursor: pointer; }
.stepper button[disabled] { opacity: .4; }
.stepper b { min-width: 24px; text-align: center; font-size: 18px; }
.setrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--sep); }
.setrow:last-child { border-bottom: 0; }
.setrow .grow .t { font-size: 15px; }
.setrow .grow .s { font-size: 12px; color: var(--hint); }

/* ---------- поля ввода */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--hint); padding-left: 4px; }
.input { height: 48px; border-radius: var(--radius-s); border: 1px solid var(--sep); background: var(--card); padding: 0 14px; font-size: 16px; width: 100%; outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { height: 110px; padding: 12px 14px; resize: none; line-height: 1.4; }
.input.code { text-align: center; font-size: 28px; font-weight: 800; letter-spacing: 8px; }

/* ---------- типы очереди (плитки) */
.tile { border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; text-align: left; cursor: pointer; min-height: 70px;
  border: 2px solid transparent; background: var(--card); color: var(--text); }
.tile.on { border-color: var(--accent); background: var(--soft); }
.tile b { font-size: 15px; }
.tile small { font-size: 12px; color: var(--hint); line-height: 1.35; }

/* ---------- шаги (прогресс) */
.steps { display: flex; flex-direction: column; gap: 0; }
.stp { display: flex; gap: 12px; align-items: flex-start; }
.stp .dot { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800;
  background: var(--chip); color: var(--hint); }
.stp.done .dot { background: var(--oksoft); color: var(--ok); }
.stp.current .dot { background: var(--accent); color: var(--onaccent); }
.stp .line { width: 2px; height: 14px; background: var(--sep); margin-left: 12px; }
.stp .nm { padding-top: 3px; font-size: 15px; }
.stp.current .nm { font-weight: 700; }

/* ---------- окна в пульте */
.win { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.win .head { display: flex; align-items: baseline; justify-content: space-between; }
.win .now { font-size: 44px; font-weight: 800; line-height: 1; }
.win .who { font-size: 14px; color: var(--hint); }

/* ---------- лист снизу, тосты */
.sheet-wrap { position: fixed; inset: 0; background: var(--overlay); display: flex; flex-direction: column; justify-content: flex-end; z-index: 20; animation: fade .15s; }
.sheet { background: var(--card); border-radius: 18px 18px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  max-height: 88vh; overflow-y: auto; max-width: 560px; width: 100%; margin: 0 auto; animation: up .18s ease-out; }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); align-self: center; margin-bottom: 6px; }
.sheet .act { min-height: 46px; border: 0; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; text-align: left; padding: 0 14px; background: var(--bg); color: var(--text); }
.sheet .act.accent { color: var(--accent); } .sheet .act.danger { color: var(--danger); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); background: rgba(20,20,22,0.92); color: #FFFFFF;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { transform: translateY(30px); } to { transform: none; } }

/* ---------- состояния загрузки */
.loading { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--hint); padding: 60px 0; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--hint); padding: 24px 12px; font-size: 15px; line-height: 1.5; }
.qr { width: 220px; height: 220px; border-radius: 12px; background: #FFFFFF; padding: 8px; }
.timer { font-variant-numeric: tabular-nums; }
.ad { border: 1px dashed var(--sep); }
.card.row { flex-direction: row; align-items: center; }
.card.row.between { justify-content: space-between; }
.top .btn { width: auto; flex-shrink: 0; }
:root[data-theme="dark"] .btn.ok { color: #04140A; }
