/* energy-bot — мини-приложение. Одна тема из themeParams Telegram, один акцент,
   8-пиксельная сетка, радиусы 12/16, без теней и градиентов. */

:root {
  color-scheme: light dark;
  /* Страница — secondary_bg_color, карточки — section_bg_color/bg_color: так
     выглядят нативные экраны Telegram, и приложение не спорит с клиентом. */
  --bg: #efeff4;
  --card: #ffffff;
  --text: #000000;
  --hint: #8a8a8e;
  --accent: #2481cc;
  --accent-text: #ffffff;
  --link: #2481cc;
  --danger: #d9363e;
  --ok: #2f9e44;
  --warn: #c77d00;
  --sep: rgba(0, 0, 0, .08);
  --fill: rgba(120, 120, 128, .12);
  --fill-2: rgba(120, 120, 128, .22);
  --r: 16px;
  --r-s: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Roboto", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
}

:root[data-scheme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #ffffff;
  --hint: #8e8e93;
  --danger: #ff6b6b;
  --ok: #51cf66;
  --warn: #ffc078;
  --sep: rgba(255, 255, 255, .09);
  --fill: rgba(120, 120, 128, .20);
  --fill-2: rgba(120, 120, 128, .32);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme]) {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --hint: #8e8e93;
    --danger: #ff6b6b;
    --ok: #51cf66;
    --warn: #ffc078;
    --sep: rgba(255, 255, 255, .09);
    --fill: rgba(120, 120, 128, .20);
    --fill-2: rgba(120, 120, 128, .32);
  }
}

/* Полупрозрачные заливки от цвета текста — подстраиваются под любую тему клиента. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --sep: color-mix(in srgb, var(--text) 10%, transparent);
    --fill: color-mix(in srgb, var(--text) 7%, transparent);
    --fill-2: color-mix(in srgb, var(--text) 14%, transparent);
    --ok-bg: color-mix(in srgb, var(--ok) 14%, transparent);
    --danger-bg: color-mix(in srgb, var(--danger) 14%, transparent);
    --warn-bg: color-mix(in srgb, var(--warn) 16%, transparent);
    --accent-bg: color-mix(in srgb, var(--accent) 12%, transparent);
  }
}

/* ===== База ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px) + var(--tg-safe-area-inset-bottom, 0px));
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; margin: 0; transition: opacity .08s; }
button:active { opacity: .65; }
button:disabled { opacity: .45; cursor: default; }
a { color: var(--link); text-decoration: none; }
b, strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.hint { color: var(--hint); }
.ok { color: var(--ok); }
.danger { color: var(--danger); }
.warn { color: var(--warn); }
.center { text-align: center; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(8px + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px)) 16px 0;
}

/* ===== Иконки (Lucide, inline SVG) ===== */
.ic { display: inline-flex; width: 20px; height: 20px; flex: none; vertical-align: middle; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic.sm { width: 16px; height: 16px; }
.ic.lg { width: 28px; height: 28px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Шапка экрана ===== */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0 16px; min-height: 56px; }
.top h1 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.top .sub { margin: 2px 0 0; font-size: 14px; color: var(--hint); }
.top .right { font-size: 14px; color: var(--hint); text-align: right; white-space: nowrap; }
.top .right b { color: var(--text); }

.sec { margin: 24px 4px 8px; font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; align-items: baseline; }
.sec a, .sec button { font-size: 13px; font-weight: 500; color: var(--link); text-transform: none; letter-spacing: 0; }

/* ===== Карточки и списки ===== */
.card { background: var(--card); border-radius: var(--r); padding: 16px; }
.card + .card { margin-top: 12px; }
.card .label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 8px; }
.card .label.row-label { display: flex; justify-content: space-between; align-items: center; }
.card .label button { color: var(--link); font-size: 13px; font-weight: 600; }

.list { background: var(--card); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px; width: 100%; text-align: left; color: inherit; }
.row + .row { border-top: 1px solid var(--sep); }
.row .lead { width: 40px; height: 40px; border-radius: 12px; background: var(--fill); display: flex; align-items: center; justify-content: center; flex: none; }
.row .lead .ic { width: 20px; height: 20px; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .subtitle { font-size: 13px; color: var(--hint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row .amount { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .chev { color: var(--hint); width: 18px; height: 18px; }

.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; font-size: 15px; }
.kv + .kv { border-top: 1px solid var(--sep); }
.kv span:first-child { color: var(--hint); flex: none; }
.kv span:last-child { text-align: right; font-variant-numeric: tabular-nums; word-break: break-all; }

/* ===== Баланс ===== */
.balance .label { margin-bottom: 4px; }
.balance .amt { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.balance .amt b { font-size: 36px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; word-break: break-all; }
.balance .amt span { font-size: 18px; font-weight: 600; color: var(--hint); }
.balance .fiat { margin-top: 4px; font-size: 15px; color: var(--hint); font-variant-numeric: tabular-nums; }
.balance .usdt { display: flex; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--sep); font-size: 15px; }
.balance .usdt b { font-variant-numeric: tabular-nums; }

/* ===== Действия на главной ===== */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 84px; padding: 12px 4px; border-radius: var(--r); background: var(--card);
  font-size: 13px; font-weight: 500; line-height: 1.2; text-align: center;
}
.action .ic { width: 24px; height: 24px; color: var(--accent); }
.action.primary { background: var(--accent); color: var(--accent-text); }
.action.primary .ic { color: inherit; }

/* ===== Кнопки ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 16px; border-radius: var(--r-s);
  font-size: 16px; font-weight: 600; background: var(--fill); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; color: var(--link); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }
.btns { display: flex; gap: 8px; }
.btns .btn { flex: 1; }
.icon-btn { width: 44px; height: 44px; border-radius: var(--r-s); background: var(--fill); display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--text); }
.icon-btn.plain { background: transparent; color: var(--hint); }
.icon-btn .ic { width: 20px; height: 20px; }
.link-btn { color: var(--link); font-weight: 600; font-size: 15px; min-height: 44px; display: inline-flex; align-items: center; }

/* ===== Сегменты и чипы ===== */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: var(--r-s); background: var(--fill); }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; font-size: 15px; color: var(--text); padding: 0 8px; }
.seg button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.seg button:active { opacity: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: var(--r-s); background: var(--fill); font-size: 15px; font-variant-numeric: tabular-nums; color: var(--text); display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.chip.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip .ic { width: 16px; height: 16px; }
.chip .mono { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Поля ===== */
.field + .field { margin-top: 12px; }
.input {
  width: 100%; min-height: 48px; border: 0; border-radius: var(--r-s);
  background: var(--fill); color: var(--text); padding: 0 14px; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: var(--hint); }
.input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.input.invalid { box-shadow: inset 0 0 0 2px var(--danger); }
.input.mono { font-family: var(--mono); font-size: 14px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1; min-width: 0; }
.input-row .icon-btn { width: 48px; height: 48px; }
.amount-box { display: flex; align-items: center; gap: 8px; background: var(--fill); border-radius: var(--r-s); padding: 0 14px; min-height: 60px; }
.amount-box .input { background: transparent; padding: 0; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 60px; }
.amount-box .input:focus { box-shadow: none; }
.amount-box:focus-within { box-shadow: inset 0 0 0 2px var(--accent); }
.amount-box.invalid { box-shadow: inset 0 0 0 2px var(--danger); }
.amount-box .unit { font-size: 16px; font-weight: 600; color: var(--hint); flex: none; }
.helper { margin-top: 8px; font-size: 13px; color: var(--hint); line-height: 1.4; }
.helper.danger { color: var(--danger); }
.summary { margin-top: 12px; }

/* ===== Цена ===== */
.price { display: flex; align-items: baseline; gap: 8px; min-height: 34px; }
.price b { font-size: 28px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.price span { font-size: 16px; font-weight: 600; color: var(--hint); }
.price-sub { margin-top: 2px; font-size: 14px; color: var(--hint); font-variant-numeric: tabular-nums; min-height: 20px; }
.pay { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--sep); }

/* ===== Статусы ===== */
.pill { display: inline-block; font-size: 12px; font-weight: 600; line-height: 1; padding: 5px 8px; border-radius: 999px; background: var(--fill); color: var(--hint); white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg, var(--fill)); }
.pill.bad { color: var(--danger); background: var(--danger-bg, var(--fill)); }
.pill.warn { color: var(--warn); background: var(--warn-bg, var(--fill)); }
.pill.wait { color: var(--accent); background: var(--accent-bg, var(--fill)); }

/* ===== Заметки ===== */
.note { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-s); background: var(--card); font-size: 14px; line-height: 1.4; }
.note + .note { margin-top: 8px; }
.note .ic { width: 20px; height: 20px; margin-top: 1px; color: var(--hint); }
.note.warn .ic { color: var(--warn); }
.note.info .ic { color: var(--accent); }
.note b { color: var(--text); }

/* ===== QR и адрес ===== */
.qr { width: 216px; height: 216px; margin: 4px auto 16px; padding: 12px; background: #fff; border-radius: var(--r-s); }
.qr svg { width: 100%; height: 100%; display: block; }
.addr { font-family: var(--mono); font-size: 14px; line-height: 1.5; word-break: break-all; text-align: center; padding: 12px 14px; border-radius: var(--r-s); background: var(--fill); user-select: all; -webkit-user-select: all; }

/* ===== Результат ===== */
.result { text-align: center; padding: 24px 16px 16px; }
.result .badge { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; background: var(--fill); }
.result .badge .ic { width: 36px; height: 36px; }
.result .badge.ok { color: var(--ok); background: var(--ok-bg, var(--fill)); }
.result .badge.bad { color: var(--danger); background: var(--danger-bg, var(--fill)); }
.result .badge.warn { color: var(--warn); background: var(--warn-bg, var(--fill)); }
.result .badge.wait { color: var(--accent); background: var(--accent-bg, var(--fill)); }
.result h2 { margin: 0; font-size: 20px; font-weight: 700; }
.result p { margin: 6px 0 0; color: var(--hint); font-size: 15px; }

/* ===== Статистика ===== */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stat { background: var(--card); border-radius: var(--r); padding: 14px 16px; }
.stat b { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--hint); }

/* ===== Пустые состояния и скелетоны ===== */
.empty { padding: 28px 16px; text-align: center; color: var(--hint); font-size: 15px; }
.skel { display: block; background: var(--fill); border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.skel.line { height: 14px; margin: 6px 0; }
.skel.line.w40 { width: 40%; }
.skel.line.w60 { width: 60%; }
.skel.line.w80 { width: 80%; }
.skel.big { height: 40px; width: 55%; }
.skel.row { height: 56px; border-radius: 0; }
.skel.card { height: 120px; border-radius: var(--r); }

/* ===== Тост, оверлей, заглушка ===== */
#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px));
  transform: translateX(-50%) translateY(-8px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: var(--r-s);
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; line-height: 1.35;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

#overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
#overlay .box { text-align: center; max-width: 320px; }
#overlay .box .ic { width: 40px; height: 40px; color: var(--accent); margin-bottom: 16px; }
#overlay h2 { margin: 0; font-size: 20px; font-weight: 700; }
#overlay p { margin: 8px 0 0; color: var(--hint); font-size: 15px; }

.gate { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 24px; }
.gate .ic { width: 48px; height: 48px; color: var(--accent); margin-bottom: 8px; }
.gate h1 { margin: 0; font-size: 22px; }
.gate p { margin: 0 0 16px; color: var(--hint); }

.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r-s); background: var(--warn-bg, var(--fill)); color: var(--text); font-size: 14px; margin-bottom: 12px; }
.banner .ic { color: var(--warn); }

.footer-space { height: 24px; }
