/* Mini App: фон и текст — из темы Telegram (--tg-theme-*), запасные — для обычного браузера;
   акцент — изумрудный, как в Kassa (кнопки, ссылки, активная вкладка). */
:root {
  --brand: #065f46;                 /* тёмный изумрудный — как в Kassa */
  --brand-dark: #022c22;
  --brand-text: #047857;
  --brand-bg: rgba(6, 95, 70, 0.14);
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: 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, #8e8e93);
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--brand-text);
  --accent: var(--brand-text);
  --btn: var(--brand);
  --btn-text: #ffffff;
  --sep: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --ok: #047857;
  --warn: #ff9500;
  --ok-bg: rgba(4, 120, 87, 0.14);
  --warn-bg: rgba(255, 149, 0, 0.16);
  --danger-bg: rgba(255, 59, 48, 0.12);
  --radius: 16px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --tabbar: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #047857;               /* на чёрном чуть светлее, чтобы кнопки читались */
    --brand-dark: #022c22;
    --brand-text: #34d399;
    --brand-bg: rgba(16, 185, 129, 0.16);
    --ok: #34d399;
    --ok-bg: rgba(52, 211, 153, 0.14);
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #98989e);
    --sep: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.1));
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none; min-height: 100vh;
}
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1 { font-size: 24px; line-height: 1.2; margin: 0 0 8px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0; font-weight: 600; }
p { margin: 0 0 12px; }
.hint { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; padding: 64px 24px; }
.big-icon { display: flex; justify-content: center; margin-bottom: 16px; color: var(--hint); }
.big-icon .ic { width: 64px; height: 64px; stroke-width: 1.5; }
.num { font-variant-numeric: tabular-nums; }

.ic {
  width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
  stroke-linejoin: round; vertical-align: -0.3em; flex: none;
}
.ic.sm { width: 1em; height: 1em; vertical-align: -0.15em; }
.btn .ic, .icon-btn .ic { width: 20px; height: 20px; }

.app { padding: calc(var(--safe-top) + 8px) 16px calc(var(--tabbar) + var(--safe-bottom) + 16px); max-width: 640px; margin: 0 auto; }
.app.no-tabs { padding-bottom: calc(var(--safe-bottom) + 96px); }
.boot { display: flex; justify-content: center; padding: 40vh 0; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--btn);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── шапка ── */
.header { display: flex; align-items: center; gap: 12px; padding: 6px 0 14px; }
.header .title { flex: 1; min-width: 0; }
.header h1 { font-size: 22px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .sub { color: var(--hint); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--accent); font-size: 18px; flex: none;
}
.icon-btn:active { opacity: 0.6; }

/* ── карточки и списки ── */
.card-block { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; margin: 20px 4px 8px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint); font-weight: 600;
}
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--accent); }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px; width: 100%; text-align: left;
  position: relative;
}
.row + .row::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; border-top: 1px solid var(--sep); }
.row.tappable:active { background: var(--sep); }
.list label.row { display: flex; font-size: inherit; color: inherit; margin: 0; }
.row .body { flex: 1; min-width: 0; }
.row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name.wrap { white-space: normal; }
.row .meta { color: var(--hint); font-size: 13px; line-height: 1.35; }
.row .right { text-align: right; flex: none; }
.row .right .big { font-weight: 700; font-variant-numeric: tabular-nums; }
.row .chev { color: var(--hint); flex: none; display: flex; }
.row .chev .ic { width: 20px; height: 20px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 15px;
}
.avatar.muted { opacity: 0.45; }
.avatar.ok { background: var(--ok); }
.avatar.warn { background: var(--warn); }
.avatar.gray { background: var(--hint); }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }

.chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--sep); color: var(--text); margin: 2px 4px 2px 0; white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.info { background: var(--brand-bg); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip-btn { padding: 7px 14px; border-radius: 999px; background: var(--card); font-weight: 500; font-size: 14px; }
.chip-btn.active { background: var(--btn); color: var(--btn-text); }
.scroll-x { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x .chip-btn { flex: none; }

/* ── главная ── */
.hero {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff;
  border-radius: 20px; padding: 18px 20px; margin-bottom: 12px; position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}
.hero.in { background: linear-gradient(135deg, #059669, #065f46); }
.hero.out { background: linear-gradient(135deg, #475569, #1e293b); }
.hero .label { opacity: 0.85; font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.hero .sum { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.hero .sum .cur { font-size: 16px; font-weight: 600; opacity: 0.85; margin-left: 6px; }
.hero .sub { opacity: 0.9; font-size: 14px; position: relative; }
.hero .btn { margin-top: 14px; background: rgba(255, 255, 255, 0.94); color: var(--brand-dark); position: relative; }
.hero.in .btn { color: #065f46; }
.hero .chip { background: rgba(255, 255, 255, 0.2); color: #fff; margin: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .v .cur { font-size: 12px; color: var(--hint); font-weight: 500; margin-left: 4px; }
.stat .k { color: var(--hint); font-size: 12px; margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--sep); font-size: 15px; }
.kv:first-child { border-top: 0; padding-top: 0; }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.kv.total { font-weight: 700; font-size: 17px; }
.kv .hint { font-weight: 400; }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px;
  font-size: 14px; width: 100%; text-align: left; line-height: 1.35;
}
.banner.warn { background: var(--warn-bg); color: var(--text); }
.banner.ok { background: var(--ok-bg); color: var(--text); }
.banner.danger { background: var(--danger-bg); color: var(--text); }
.banner.info { background: var(--card); color: var(--text); }
.banner .ico { flex: none; display: flex; }
.banner .ico .ic { width: 22px; height: 22px; }
.banner.warn .ico { color: var(--warn); }
.banner.ok .ico { color: var(--ok); }
.banner.danger .ico { color: var(--danger); }
.banner.info .ico { color: var(--accent); }
.banner .act { color: var(--accent); font-weight: 600; flex: none; }
.empty { text-align: center; padding: 28px 16px; color: var(--hint); }
.empty .ico { display: flex; justify-content: center; margin-bottom: 10px; }
.empty .ico .ic { width: 44px; height: 44px; stroke-width: 1.5; opacity: 0.6; }

/* ── кнопки и формы ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px 16px;
  border-radius: 14px; font-weight: 600; font-size: 16px; background: var(--card); color: var(--accent);
  transition: transform 0.05s;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }
.main-fallback { position: fixed; left: 16px; right: 16px; width: auto; bottom: calc(var(--safe-bottom) + 16px); z-index: 20; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 6px; font-weight: 500; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid transparent; background: var(--card);
  outline: none; font-size: 17px; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--btn); }
.input.code { font-size: 30px; letter-spacing: 8px; text-align: center; font-weight: 600; padding: 14px 8px; }
textarea.input { min-height: 80px; resize: vertical; }
select.input { background-image: none; }
.form-error { color: var(--danger); font-size: 14px; margin: -6px 4px 12px; min-height: 0; }
.form-error:empty { margin: 0; }
.links { text-align: center; margin-top: 16px; }
.links a { font-weight: 500; }
.links a + a::before { content: "·"; color: var(--hint); margin: 0 10px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 30px; background: var(--sep); transition: background 0.2s; }
.switch span::after {
  content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.segment { display: flex; background: var(--sep); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.segment button { flex: 1; padding: 8px; border-radius: 10px; font-weight: 500; }
.segment button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.copy-box {
  display: flex; align-items: center; gap: 10px; background: var(--bg); border-radius: 12px; padding: 12px 14px;
  font-size: 18px; font-weight: 600; letter-spacing: 0.03em; font-variant-numeric: tabular-nums; margin-bottom: 8px;
}
.copy-box span { flex: 1; word-break: break-all; }
.copy-box button { color: var(--accent); font-size: 14px; font-weight: 600; letter-spacing: 0; display: flex; align-items: center; gap: 4px; }
.copy-box button .ic { width: 18px; height: 18px; }
.copy-box.num span { white-space: nowrap; overflow: hidden; font-size: clamp(14px, 4.4vw, 18px); letter-spacing: 0.02em; }
.copy-box.link { font-size: 14px; letter-spacing: 0; font-weight: 500; }
.file-pick { display: flex; align-items: center; gap: 12px; }
.file-pick input { display: none; }
.file-pick .preview { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--bg); flex: none; }
.period { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border-radius: 14px; padding: 6px 8px; margin-bottom: 12px; }
.period b { flex: 1; text-align: center; font-size: 15px; }

/* ── экран QR-кода ── */
.qr-screen { text-align: center; padding-top: 8px; }
.qr-screen .branch { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.qr-box { background: #fff; border-radius: 20px; padding: 14px; display: inline-flex; margin: 12px auto 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14); }
.qr-box img { width: min(72vw, 320px); height: auto; aspect-ratio: 1; image-rendering: pixelated; display: block; }
.qr-code { font-size: 38px; font-weight: 800; letter-spacing: 8px; font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.qr-timer { height: 6px; border-radius: 3px; background: var(--sep); overflow: hidden; margin: 12px auto 8px; max-width: 320px; }
.qr-timer i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
.qr-screen .section-title, .qr-screen .list { text-align: left; }
.qr-screen .row.fresh { animation: flash 1.2s; }
@keyframes flash { from { background: var(--ok-bg); } }
.day-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--hint); font-weight: 600; margin: 16px 4px 6px; }
.day-title .day-sum { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty.small { padding: 16px; }

/* ── мастер ── */
.wiz { padding: 12px 0 40px; }
.wiz .logo {
  width: 84px; height: 84px; border-radius: 28px; margin: 20px auto 18px; display: flex; align-items: center;
  justify-content: center; color: var(--btn-text);
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  box-shadow: 0 8px 24px var(--brand-bg);
}
.wiz .logo .ic { width: 40px; height: 40px; stroke-width: 1.8; }
.wiz h1 { text-align: center; }
.wiz > p.hint { text-align: center; margin-bottom: 22px; }
.role-grid { display: grid; gap: 12px; margin-top: 20px; }
.role-btn { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: var(--radius); padding: 16px; text-align: left; }
.role-btn .avatar { width: 46px; height: 46px; border-radius: 14px; }
.role-btn .avatar .ic { width: 24px; height: 24px; }
.role-btn b { display: block; font-size: 17px; }
.role-btn small { color: var(--hint); font-size: 13px; }
.role-btn .chev { margin-left: auto; color: var(--hint); display: flex; }
.lang-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.lang-btn { background: var(--card); border-radius: var(--radius); padding: 26px 12px; font-size: 18px; font-weight: 600; }
.lang-btn .code { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 7px; background: var(--btn); color: var(--btn-text); margin-right: 8px; vertical-align: 2px; letter-spacing: 0.04em; }
.lang-btn:active { opacity: 0.7; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 6px; }

/* ── таббар ── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--sep); padding: 6px 8px calc(var(--safe-bottom) + 6px);
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--hint); font-size: 11px; font-weight: 500; padding: 2px 0; }
.tabbar button.active { color: var(--accent); }
.tabbar .ic { width: 24px; height: 24px; stroke-width: 1.8; }

/* ── шторка ── */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 30; animation: fade 0.15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 20px); max-height: 92vh; overflow-y: auto; animation: rise 0.2s ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet .grip { width: 36px; height: 4px; border-radius: 2px; background: var(--hint); opacity: 0.4; margin: 0 auto 14px; }
.sheet h2 { font-size: 20px; margin-bottom: 4px; }
.sheet .sub { color: var(--hint); margin-bottom: 14px; }
body.sheet-open { overflow: hidden; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.result { text-align: center; padding: 10px 0 6px; }
.result .big-icon { color: var(--ok); }
.result .time { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ── тост ── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-bottom) + 20px); transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40;
  max-width: calc(100% - 32px); text-align: center; animation: fade 0.15s;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

.skeleton { background: linear-gradient(90deg, var(--sep) 25%, transparent 50%, var(--sep) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.fade-in { animation: fade 0.2s; }
