/* Касса турнира — оформление. Раскладка и типографика по образцу проекта SOBAM (шрифт Onest, плоские карточки,
   три размера скруглений, переносы текста по смыслу), палитра своя: тёплый серый и винный акцент.
   Тема — как в системе телефона. */
:root {
  --bg: #ECEAE7;
  --sf: #FFFFFF;
  --sf2: #F3F1EF;
  --ink: #141213;
  --mu: #67615F;
  --ln: #E4E0DD;
  --ac: #8F1D4A;
  --aci: #FFFFFF;
  --acs: #F4E4EA;
  --pos: #2F7A3E;
  --pos-s: #E3F1E6;
  --wrn: #9A5F14;
  --wrn-s: #FBEFD9;
  --neg: #C23E31;
  --neg-s: #FBE6E3;
  --nav: #141213;
  --navt: #B9B3B0;
  --navA: #FFFFFF;
  --navAt: #141213;
  --ovl: rgba(20, 18, 19, .4);
  /* скругления — всё приложение на этих трёх размерах */
  --r-card: 12px; /* карточки, большие кнопки кассы, окна */
  --r-ctl: 8px;   /* кнопки, поля, блоки внутри карточек */
  --r-tag: 6px;   /* метки, пункты меню */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C0B0C;
    --sf: #181617;
    --sf2: #232022;
    --ink: #F3F1F2;
    --mu: #A39C9F;
    --ln: #2A2729;
    --ac: #E0628F;
    --aci: #160A0F;
    --acs: #35192A;
    --pos: #6CC383;
    --pos-s: #15291B;
    --wrn: #F2B35E;
    --wrn-s: #31240F;
    --neg: #F37669;
    --neg-s: #361917;
    --nav: #232022;
    --navt: #A39C9F;
    --navA: #F3F1F2;
    --navAt: #0C0B0C;
    --ovl: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.4 'Onest', -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
/* переносы: заголовки и подписи — ровными строками, абзацы — без висящих слов, суммы — не разрываются */
h1, h2, h3, .t-name, .name, .k-name, .lead, .role b, .stat span, .banner span { text-wrap: balance; }
p, .hint, .sheet .lead, .empty { text-wrap: pretty; }
b, .stat b, .num, .k-price, .k-count, .chip { white-space: nowrap; }
.muted { color: var(--mu); }
.small { font-size: 13px; }
.neg { color: var(--neg); }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.boot { padding: 40vh 16px 0; text-align: center; color: var(--mu); }
.wrap { max-width: 760px; margin: 0 auto; padding: 4px 16px calc(40px + env(safe-area-inset-bottom)); }
.page-title { font: 700 32px/1.05 'Onest', sans-serif; letter-spacing: -.025em; margin: 12px 0 18px; }

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--r-ctl); border: 0;
  background: var(--sf); color: var(--ink); font-weight: 600; text-decoration: none; text-align: center;
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--ac); color: var(--aci); }
.btn-danger { color: var(--neg); }
.btn-danger.solid { background: var(--neg); color: #fff; }
.sheet .btn:not(.btn-primary):not(.solid), .card .btn:not(.btn-primary):not(.solid) { background: var(--sf2); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; border-radius: var(--r-ctl); border: 0; background: transparent; color: var(--ink);
}
.icon-btn:hover { background: var(--sf2); }
.icon-btn[disabled] { opacity: .3; pointer-events: none; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font: 500 13px/1.2 'Onest', sans-serif; color: var(--mu); }
.input, .field input, .field select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--ln); background: var(--sf); font-size: 16px;
}
.sheet .field input, .sheet .field select, .card .input { background: var(--sf2); border-color: transparent; }
.input:focus, .field input:focus, .field select:focus { outline: 2px solid var(--ac); outline-offset: -1px; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--ac); flex: none; }
.err { color: var(--neg); font-size: 14px; min-height: 1em; margin: 8px 0 0; }

/* ---------- шапка ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: var(--bg);
}
.topbar .title { flex: 1; min-width: 0; padding: 0 6px; }
.topbar .title b { display: block; font: 600 17px/1.2 'Onest', sans-serif; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { display: block; font-size: 13px; color: var(--mu); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-title { flex: 1; padding: 0 8px; font: 700 15px/1 'Onest', sans-serif; letter-spacing: .08em; text-transform: uppercase; }

h2 { font: 600 20px/1.2 'Onest', sans-serif; letter-spacing: -.01em; margin: 32px 0 12px; }
h3 { font: 600 18px/1.2 'Onest', sans-serif; margin: 0 0 12px; }

.card { background: var(--sf); border-radius: var(--r-card); padding: 18px; min-width: 0; }
.card + .card { margin-top: 12px; }
.hint { font-size: 13px; line-height: 1.45; color: var(--mu); margin: 10px 2px 0; }

.banner { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--r-ctl); padding: 12px 14px; margin: 12px 0; font-size: 14px; line-height: 1.4; }
.banner > .i { margin-top: 1px; }
.banner > span { flex: 1; min-width: 0; }
.banner.warn { background: var(--wrn-s); color: var(--wrn); }
.banner.err { background: var(--neg-s); color: var(--neg); }
.banner.info { background: var(--acs); color: var(--ac); }
.banner .btn { min-height: 36px; padding: 0 12px; flex: none; background: var(--sf); }

/* ---------- первая страница и вход ---------- */

.login { max-width: 420px; margin: 0 auto; padding: calc(9vh + env(safe-area-inset-top)) 16px 40px; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin-bottom: 20px; }
.login h1 { font: 700 32px/1.05 'Onest', sans-serif; letter-spacing: -.025em; margin: 0 0 10px; }
.login .lead { font-size: 15px; line-height: 1.45; color: var(--mu); margin: 0 0 24px; }
.role {
  display: flex; align-items: center; gap: 14px; padding: 16px; margin-bottom: 12px;
  background: var(--sf); border-radius: var(--r-card); text-decoration: none;
}
.role:active { opacity: .85; }
.role .grow, .role-head .grow { flex: 1; min-width: 0; }
.role b, .role-head b { display: block; font: 600 17px/1.2 'Onest', sans-serif; }
.role .grow > span, .role-head .grow > span { display: block; font-size: 14px; color: var(--mu); margin-top: 2px; }
.role > .i { color: var(--mu); }
.role-icon { width: 44px; height: 44px; border-radius: var(--r-ctl); display: inline-flex; align-items: center; justify-content: center; background: var(--acs); color: var(--ac); flex: none; }
.role-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.code-input { font: 700 26px/1 'Onest', sans-serif !important; letter-spacing: .12em; text-align: center; }

/* ---------- турниры и серии ---------- */

.series + .series { margin-top: 8px; }
.series-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.series-head span { font-size: 14px; color: var(--mu); white-space: nowrap; }
.series-sum, .t-nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.series-sum { margin-bottom: 12px; background: var(--nav); color: var(--navA); }
.series-sum span { color: var(--navt) !important; }
.series-sum .neg { color: var(--neg); }
.series-sum span, .t-nums span { display: block; font: 500 12px/1.2 'Onest', sans-serif; color: var(--mu); }
.series-sum b, .t-nums b { display: block; font: 700 16px/1.2 'Onest', sans-serif; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; }
.t-card { display: block; text-decoration: none; }
.t-card:active { opacity: .85; }
.t-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.t-name { font: 600 17px/1.25 'Onest', sans-serif; }
.t-date { color: var(--mu); font-size: 14px; margin-top: 2px; }
.t-nums { margin-top: 14px; }
.chip { font: 600 12px/1 'Onest', sans-serif; padding: 5px 8px; border-radius: var(--r-tag); }
.chip.live { background: var(--pos-s); color: var(--pos); }
.chip.hidden-chip { background: var(--sf2); color: var(--mu); }

.empty { text-align: center; padding: 40px 16px; color: var(--mu); line-height: 1.45; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* ---------- турнир ---------- */

.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  padding: 4px; margin: 6px 0 16px; border-radius: calc(var(--r-ctl) + 4px); background: var(--nav);
}
.tabs a {
  display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 4px; border-radius: var(--r-ctl);
  font: 500 14px/1 'Onest', sans-serif; color: var(--navt); text-decoration: none; white-space: nowrap;
}
.tabs a.on { background: var(--navA); color: var(--navAt); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--sf); border-radius: var(--r-card); padding: 16px; min-width: 0; }
.stat span { display: block; font: 500 14px/1.2 'Onest', sans-serif; color: var(--mu); }
.stat b { display: block; font: 700 clamp(24px, 7vw, 34px)/1 'Onest', sans-serif; letter-spacing: -.03em; margin-top: 12px; overflow: hidden; text-overflow: ellipsis; }
.stat.accent { background: var(--ac); color: var(--aci); }
.stat.accent span { color: inherit; opacity: .8; }
.stat.accent.neg { background: var(--neg); color: #fff; }
.stats + .banner { margin-top: 8px; }

.rows { margin: -6px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--ln); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--mu); margin-top: 2px; }
.row .num { text-align: right; }
.row .num b { display: block; }
.row .num span { font-size: 13px; color: var(--mu); }
.row.total { font-weight: 700; }
.row > .i { color: var(--mu); }
button.row { width: 100%; border: 0; border-top: 1px solid var(--ln); background: transparent; text-align: left; padding: 12px 0; }
button.row:first-child { border-top: 0; }
.row .order { display: flex; flex-direction: column; margin: -8px 0 -8px -10px; }
.row .order .icon-btn { width: 36px; height: 28px; color: var(--mu); }
.row-btn { all: unset; flex: 1; min-width: 0; cursor: pointer; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ln); flex: none; }
.dot.on { background: var(--pos); }
.dot.warn { background: var(--wrn); }

.op { display: grid; grid-template-columns: 44px 14px minmax(0, 1fr) auto; gap: 6px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--ln); font-size: 14px; }
.op:first-child { border-top: 0; padding-top: 0; }
.op .t { color: var(--mu); }
.op .s { font-weight: 700; }
.op .s.add { color: var(--pos); }
.op .s.cancel { color: var(--neg); }
.op .c { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .c small { color: var(--mu); font-size: 13px; }
.op.cancel .c, .op.cancel .v { color: var(--mu); text-decoration: line-through; }

.add-form { display: grid; grid-template-columns: minmax(0, 1fr) 110px auto; gap: 8px; }
.add-form .btn { padding: 0 16px; }

.qr { width: min(240px, 66vw); margin: 0 auto 10px; background: #fff; border-radius: var(--r-ctl); padding: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.code-box { text-align: center; background: var(--sf2); border-radius: var(--r-ctl); padding: 12px; margin-bottom: 12px; }
.code-box span { display: block; font: 500 13px/1.2 'Onest', sans-serif; color: var(--mu); }
.code-box b { display: block; font: 700 34px/1.1 'Onest', sans-serif; letter-spacing: .08em; margin-top: 4px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ---------- окна ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: 50; background: var(--ovl);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--sf); border-radius: var(--r-card) var(--r-card) 0 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .2s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 600px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: var(--r-card); padding: 24px; }
}
.sheet h3 { font: 600 20px/1.2 'Onest', sans-serif; margin: 0 0 6px; }
.sheet .lead { color: var(--mu); margin: 0 0 18px; line-height: 1.45; }
.sheet .actions { display: grid; gap: 8px; margin-top: 18px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 0 12px;
  border: 0; border-radius: var(--r-tag); background: transparent; text-align: left; font-weight: 500; text-decoration: none;
}
.menu-item:hover { background: var(--sf2); }
.menu-item.danger { color: var(--neg); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r-ctl); font-weight: 600;
  max-width: calc(100vw - 32px); width: max-content; text-align: center; text-wrap: balance;
  transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--neg); color: #fff; }

/* ---------- касса ---------- */

.k { max-width: 640px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.k-head { position: sticky; top: 0; z-index: 10; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); }
.k-title { display: flex; align-items: center; gap: 8px; }
.k-title .icon-btn { margin-left: -10px; }
.k-title b { flex: 1; min-width: 0; font: 700 20px/1.15 'Onest', sans-serif; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; }
.k-dev {
  display: inline-flex; align-items: center; gap: 6px; max-width: 48%; flex: none;
  border: 0; border-radius: var(--r-ctl); background: var(--sf); padding: 8px 12px 8px 10px;
  font: 600 13px/1 'Onest', sans-serif; color: var(--mu); white-space: nowrap;
}
.k-dev .i { width: 16px; height: 16px; }
.k-dev span { overflow: hidden; text-overflow: ellipsis; }
.sync { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 12px; border-radius: var(--r-ctl); font: 600 14px/1.3 'Onest', sans-serif; }
.sync .i { width: 18px; height: 18px; }
.sync.ok { background: var(--pos-s); color: var(--pos); }
.sync.busy { background: var(--sf); color: var(--mu); }
.sync.warn { background: var(--wrn-s); color: var(--wrn); }
.sync.err { background: var(--neg-s); color: var(--neg); }
.k-body { padding: 0 16px; }
.k-search { margin: 4px 0 0; position: relative; }
.k-search .i { position: absolute; left: 14px; top: 14px; color: var(--mu); }
.k-search input { padding-left: 44px; border-color: transparent; }

.k-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.k-item { display: flex; align-items: center; gap: 12px; background: var(--sf); border-radius: var(--r-card); padding: 12px 12px 12px 16px; }
.k-info { flex: 1; min-width: 0; }
.k-name { font: 600 17px/1.25 'Onest', sans-serif; overflow-wrap: anywhere; }
.k-price { color: var(--mu); font: 500 15px/1 'Onest', sans-serif; margin-top: 6px; }
.k-ctl { display: flex; align-items: center; gap: 4px; flex: none; }
.k-minus, .k-plus { display: inline-flex; align-items: center; justify-content: center; border: 0; transition: transform .08s; }
.k-minus { width: 48px; height: 48px; border-radius: var(--r-ctl); background: var(--sf2); color: var(--mu); }
.k-plus { width: 64px; height: 64px; border-radius: var(--r-card); background: var(--ac); color: var(--aci); }
.k-plus .i { width: 30px; height: 30px; stroke-width: 2.5; }
.k-minus:active, .k-plus:active { transform: scale(.92); }
.k-minus[disabled], .k-plus[disabled] { opacity: .3; pointer-events: none; }
.k-count { min-width: 48px; text-align: center; font: 700 26px/1 'Onest', sans-serif; letter-spacing: -.02em; }
.k-count.bump { animation: bump .35s ease-out; }
@keyframes bump { 30% { transform: scale(1.3); color: var(--ac); } }
.pending-list { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .add-form { grid-template-columns: minmax(0, 1fr) 96px; }
  .add-form .btn { grid-column: 1 / -1; }
  .tabs a { font-size: 13px; }
  .k-plus { width: 58px; height: 58px; }
  .k-minus { width: 44px; height: 44px; }
  .k-count { min-width: 40px; font-size: 24px; }
}
