:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #111214; --accent-text: #ffffff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --chip: #eef0f3; --chip-on: #111214; --chip-on-text: #fff; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1012; --card: #1a1c20; --text: #f3f4f6; --muted: #9ca3af; --line: #2a2d33;
    --accent: #f3f4f6; --accent-text: #111214; --chip: #24272d; --chip-on: #f3f4f6; --chip-on-text: #111214; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 17px/1.35 -apple-system, "SF Pro Text", Inter, Roboto, system-ui, sans-serif; }
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
#title { flex: 1; font-weight: 700; font-size: 18px; text-align: center; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--text); font-size: 26px; border-radius: 12px; }
.icon-btn:active { background: var(--chip); }
#view { flex: 1; padding: 14px 14px calc(90px + var(--safe-b)); max-width: 640px; width: 100%; margin: 0 auto; }
#tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 5; }
#tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); font-size: 22px; padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
#tabs button span { font-size: 11px; font-weight: 600; }
#tabs button.on { color: var(--text); }

h1 { font-size: 24px; margin: 6px 0 14px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button.btn { width: 100%; border: 0; border-radius: var(--radius); padding: 16px; font-size: 18px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); min-height: 56px; }
button.btn.secondary { background: var(--chip); color: var(--text); }
button.btn.danger { background: var(--bad); color: #fff; }
button.btn.warn { background: var(--warn); color: #fff; }
button.btn:disabled { opacity: .45; }
button.btn.tile { min-height: 96px; font-size: 20px; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; }
button.btn.tile .em { font-size: 34px; }

label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
input, select { width: 100%; font: inherit; font-size: 19px; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); min-height: 54px; }
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
input.num { font-size: 26px; font-weight: 700; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; border-radius: 999px; padding: 11px 16px; font-size: 16px; font-weight: 600; background: var(--chip); color: var(--text); min-height: 44px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.chips.sizes .chip { min-width: 56px; text-align: center; padding: 11px 0; }

.list .item { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 700; }
.item .sub { color: var(--muted); font-size: 14px; }
.item .amt { font-weight: 800; font-size: 18px; white-space: nowrap; }
.item.off { opacity: .5; text-decoration: line-through; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 700; background: var(--chip); }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fee2e2; color: #991b1b; }

/* PIN */
.pin-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; padding-top: 10vh; }
.pin-dots { display: flex; gap: 14px; height: 20px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; background: var(--chip); display: block; }
.pin-dots i.on { background: var(--text); }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.pad button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--card); color: var(--text); font-size: 28px; font-weight: 600; border: 1px solid var(--line); }
.pad button:active { background: var(--chip); }
.pad button.ghost { background: transparent; border: 0; font-size: 22px; }
.err { color: var(--bad); font-weight: 600; min-height: 22px; text-align: center; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 20; max-width: 90vw; text-align: center; }
.summary-line { display: flex; justify-content: space-between; padding: 6px 0; }
.sticky-bottom { position: sticky; bottom: calc(80px + var(--safe-b)); }
.pay-toggle { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.pay-toggle .chip { text-align: center; padding: 13px 6px; }
.split-box { margin-top: 10px; }
.small { font-size: 14px; }

/* Собственный диалог подтверждения (вместо системного confirm) */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); color: var(--text); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + var(--safe-b)); }
.sheet-text { font-size: 19px; font-weight: 700; line-height: 1.4; margin-bottom: 8px; }
