/* Цвета берутся из темы Telegram (переменные --tg-theme-* выставляет telegram-web-app.js).
   Значения после запятой — запасные, для открытия в обычном браузере в DEV_MODE. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111317);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #6b7079));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --section-head: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #6b7079));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--btn) 12%, transparent);
  --ok: #2fb35a;
  --warn: #e8a317;
  --radius: 16px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f1115; --card: #1b1e24; --text: #f2f3f5; --hint: #7d838d; --sub: #9aa0aa;
    --link: #5ea9ff; --accent: #5ea9ff; --btn: #3d8bfd; --section-head: #9aa0aa;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { min-height: 100vh; min-height: var(--tg-viewport-stable-height, 100vh); }
#screen { padding: 12px 16px calc(84px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; }

/* ---------- типографика ---------- */
h1 { font-size: 22px; line-height: 1.2; margin: 6px 4px 14px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--section-head);
     margin: 20px 16px 8px; font-weight: 600; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; font-size: 14px; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--ok); }
.down { color: var(--danger); }

/* ---------- карточки и списки ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card.flush { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%;
             background: none; border: 0; text-align: left; position: relative; }
.list-item + .list-item::before { content: ""; position: absolute; top: 0; left: 64px; right: 0;
                                  border-top: 1px solid var(--sep); }
.list-item.plain + .list-item.plain::before { left: 16px; }
button.list-item:active { background: var(--soft); }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; }
.kv + .kv { border-top: 1px solid var(--sep); }
.kv > :first-child { color: var(--sub); flex-shrink: 0; }
.kv > :last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }

.coin-ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
            background: var(--soft); font-size: 20px; flex-shrink: 0; }
.coin-ico.sm { width: 28px; height: 28px; font-size: 15px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px;
       background: var(--soft); color: var(--accent); vertical-align: 1px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
        padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.pill.new, .pill.paid { background: color-mix(in srgb, var(--warn) 18%, transparent); color: #b7790b; }
.pill.awaiting_payment { background: var(--soft); color: var(--accent); }
.pill.done { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.cancelled, .pill.rejected { background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--hint); }

/* ---------- кнопки ---------- */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
       min-height: 50px; padding: 12px 16px; border: 0; border-radius: 12px; font-weight: 600;
       background: var(--btn); color: var(--btn-text); transition: opacity .15s, transform .1s; }
.btn:active { transform: scale(0.985); opacity: .9; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.ghost { background: none; color: var(--accent); min-height: 40px; }
.btn.sm { min-height: 36px; width: auto; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn + .btn { margin-top: 8px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn + .btn { margin-top: 0; }
.icon-btn { border: 0; background: var(--soft); color: var(--accent); border-radius: 10px;
            padding: 6px 10px; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent;
           border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- обмен ---------- */
.swap-box { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.swap-box .label { font-size: 13px; color: var(--sub); margin-bottom: 8px; display: flex; justify-content: space-between; }
.swap-line { display: flex; align-items: center; gap: 10px; }
.coin-select { display: flex; align-items: center; gap: 8px; border: 0; background: var(--soft);
               border-radius: 999px; padding: 6px 12px 6px 6px; font-weight: 600; flex-shrink: 0; }
.coin-select .chev { color: var(--hint); font-size: 12px; }
.amount-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; text-align: right;
                font-size: 26px; font-weight: 600; padding: 4px 0; font-variant-numeric: tabular-nums; }
.amount-input::placeholder { color: var(--hint); opacity: .6; }
.amount-out { flex: 1; min-width: 0; text-align: right; font-size: 26px; font-weight: 600;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount-out.zero { color: var(--hint); opacity: .6; }
.swap-sub { display: flex; justify-content: space-between; font-size: 13px; color: var(--hint); margin-top: 6px; gap: 8px; }
.swap-flip-wrap { display: flex; justify-content: center; height: 10px; position: relative; z-index: 1; }
.swap-flip { position: absolute; top: -14px; width: 38px; height: 38px; border-radius: 50%;
             border: 4px solid var(--bg); background: var(--btn); color: var(--btn-text);
             font-size: 16px; display: grid; place-items: center; padding: 0; transition: transform .25s; }
.swap-flip:active { transform: rotate(180deg); }
.field { width: 100%; border: 1.5px solid var(--sep); background: var(--card); border-radius: 12px;
         padding: 12px 14px; font-size: 16px; outline: none; resize: vertical; }
.field:focus { border-color: var(--btn); }
.field.mono { font-size: 15px; }
.field.invalid { border-color: var(--danger); }
.field-label { font-size: 13px; color: var(--sub); margin: 0 4px 6px; display: block; }
.field-err { color: var(--danger); font-size: 13px; margin: 6px 4px 0; min-height: 0; }
.note { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; font-size: 13px;
        background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--text); }
.note.info { background: var(--soft); }
.note.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.note.bad { background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ---------- заявка ---------- */
.hero { text-align: center; padding: 22px 16px 18px; }
.hero .big-ico { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.hero .title { font-size: 19px; font-weight: 700; }
.steps { display: flex; gap: 4px; margin: 16px 0 4px; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--sep); }
.steps i.on { background: var(--btn); }
.steps.done i.on { background: var(--ok); }
.steps.off i.on { background: var(--hint); }
.steps-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--hint); }
.pay-box { border: 1.5px dashed color-mix(in srgb, var(--btn) 55%, transparent); border-radius: 14px;
           padding: 14px; margin: 12px 0; background: color-mix(in srgb, var(--btn) 5%, transparent); }
.pay-amount { font-size: 24px; font-weight: 700; margin: 2px 0 10px; }
.copy-line { display: flex; gap: 10px; align-items: flex-start; }
.copy-line .mono { flex: 1; }

/* ---------- профиль ---------- */
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
          background: linear-gradient(135deg, var(--btn), color-mix(in srgb, var(--btn) 55%, #9b5cff));
          color: #fff; font-size: 26px; font-weight: 700; margin: 6px auto 10px; }
.fee-big { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.progress { height: 8px; border-radius: 4px; background: var(--sep); overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--btn); border-radius: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--card); border-radius: 14px; padding: 12px; min-width: 0; }
.stat b { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat span { font-size: 12px; color: var(--hint); }
.level-row.current { color: var(--accent); font-weight: 600; }

/* ---------- таббар ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
          background: color-mix(in srgb, var(--card) 92%, transparent);
          backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
          border-top: 1px solid var(--sep); padding: 6px 4px calc(6px + var(--safe-bottom)); z-index: 10; }
.tabbar button { flex: 1; max-width: 110px; border: 0; background: none; color: var(--hint);
                 display: flex; flex-direction: column; align-items: center; gap: 2px;
                 font-size: 11px; font-weight: 500; padding: 4px 0; position: relative; }
.tabbar button .ti { font-size: 21px; line-height: 1.1; filter: grayscale(1); opacity: .65; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on .ti { filter: none; opacity: 1; }
.tabbar .badge { position: absolute; top: 0; left: calc(50% + 6px); min-width: 16px; height: 16px;
                 padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff;
                 font-size: 10px; font-weight: 700; line-height: 16px; }

/* ---------- шторка ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg);
         border-radius: 18px 18px 0 0; max-height: 86vh; display: flex; flex-direction: column;
         animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 560px; margin: 0 auto;
         padding-bottom: var(--safe-bottom); }
.sheet-head { padding: 10px 16px 8px; }
.sheet-head .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 10px; }
.sheet-head .t { font-weight: 700; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- прочее ---------- */
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
         background: rgba(20,22,26,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
         opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { text-align: center; padding: 40px 20px; color: var(--hint); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.loader { display: flex; justify-content: center; padding: 60px 0; color: var(--hint); }
.loader .spinner { width: 28px; height: 28px; border-width: 3px; }
.skeleton { background: linear-gradient(90deg, var(--sep), transparent, var(--sep)); background-size: 200% 100%;
            animation: sk 1.2s infinite; border-radius: 8px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }
.fatal { text-align: center; padding: 80px 24px; }
.fatal .e { font-size: 52px; }
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--hint); }
.seg button.on { background: var(--soft); color: var(--accent); }
.how { margin: 0; padding-left: 20px; }
.how li { padding: 4px 0 4px 4px; }
.how li::marker { color: var(--accent); font-weight: 700; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
