/* 3TON — оформление мини-приложения.
 *
 * Направление: «ledger» — тихий технический интерфейс. Графитовый нейтральный
 * фон, один акцент (TON blue) только на главном действии, фокусе и живых
 * данных, моноширинные цифры и идентификаторы. Без градиентов, свечений,
 * emoji-иконок и карточек-плиток.
 */

:root {
  --bg: #0e0f11;
  --surface: #16181b;
  --surface-2: #1c1f23;
  --line: #262a2f;
  --line-strong: #363c43;
  --text: #eceef0;
  --muted: #9aa2ab;
  --faint: #6f767e;
  --accent: #0a9bea;
  --accent-soft: rgba(10, 155, 234, 0.14);
  --accent-line: rgba(10, 155, 234, 0.42);
  --pos: #3fbf87;
  --neg: #e0684f;
  --warn: #d9a441;
  --radius: 12px;
  --radius-sm: 9px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "SF Pro Text",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --pad: 16px;
  --maxw: 560px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

body { min-height: 100vh; }

h1, h2, h3, h4 { text-wrap: balance; margin: 0; }
p { text-wrap: pretty; }

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) var(--pad)
           calc(env(safe-area-inset-bottom, 0px) + 28px);
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- типографика ---------- */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- верхняя полоса ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 0 14px;
}

.top .back {
  width: 34px;
  height: 34px;
  margin-left: -6px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
}
.top .back:active { background: var(--surface-2); color: var(--text); }

.wordmark {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
}
.wordmark i { color: var(--accent); font-style: normal; }

.top .spacer { flex: 1; }
.top .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--faint);
}

h1 {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.015em;
  margin: 2px 0 16px;
}

/* ---------- баланс ---------- */
.balance { padding: 4px 0 18px; }
.balance .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 42px;
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin: 6px 0 8px;
}
.balance .value span { font-size: 26px; color: var(--muted); margin-right: 2px; letter-spacing: 0; }
.balance .sub { color: var(--muted); font-size: 13px; }
.balance .sub b { color: var(--text); font-weight: 550; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:active { transform: scale(0.995); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #001521;
}
.btn.primary:disabled { background: var(--surface-2); border-color: var(--line); color: var(--muted); }
.btn.danger {
  background: transparent;
  border-color: rgba(224, 104, 79, 0.45);
  color: var(--neg);
}
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.wide { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }

.actions { display: flex; gap: 10px; margin-bottom: 22px; }
.actions .btn { flex: 1; }

/* ---------- строки-ссылки ---------- */
.rows { border-top: 1px solid var(--line); }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  /* Слева текст прижат к линии сетки (как h1 и подписи), справа — отступ,
     чтобы значения не липли к краю строки. */
  padding: 11px 4px 11px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.row:active { background: var(--surface); }
.row .k { color: var(--muted); font-size: 14px; flex: 1; min-width: 0; }
.row .k strong { color: var(--text); font-weight: 550; display: block; }
.row code, .row .v {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  flex: 0 0 auto;
  max-width: 55%;
  text-align: right;
  overflow-wrap: anywhere;
}
.row .chev { color: var(--faint); display: grid; place-items: center; }
.row .count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* ---------- карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 10px;
}
.card .hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

/* ---------- поля ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 7px;
}
.input, select.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  appearance: none;
}
.input::placeholder { color: var(--faint); font-family: var(--font-ui); }
.input:focus { border-color: var(--accent-line); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { font-family: var(--font-ui); }

.hint { color: var(--muted); font-size: 12.5px; margin-top: 7px; }
.hint.err { color: var(--neg); }

/* ---------- чипы ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
}
.chip.on {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
}
.chip.static { cursor: default; }

/* ---------- логотипы ---------- */
.logo {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}
.logo svg, .logo img { width: 100%; height: 100%; display: block; }
.logo.round img { border-radius: 50%; }
.logo.sq img { border-radius: 24%; }

.cluster { display: inline-flex; align-items: center; gap: 2px; }

/* ---------- список ключей ---------- */
.keys { list-style: none; margin: 0; padding: 0; }
.key {
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.key + .key { margin-top: 10px; }
.key:active { border-color: var(--line-strong); }
.key-top { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.key-top .name { font-size: 15px; font-weight: 600; }
.key-top .prefix { font-family: var(--font-mono); font-size: 12px; color: var(--faint); }
.meter {
  height: 3px;
  margin: 12px 0 8px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.meter i { display: block; height: 100%; background: var(--accent); }
.meter i.full { background: var(--warn); }
.key-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

/* ---------- ключ и его статистика ---------- */
.keybox {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 10px 8px 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.keybox .val {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.keybox .val .blurred { filter: blur(4px); }
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); color: var(--text); }

.table { width: 100%; border-collapse: collapse; }
.table th {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
  text-align: left;
  padding: 0 0 8px;
}
.table td {
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  vertical-align: top;
}
.table td.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.table .when { color: var(--faint); font-family: var(--font-mono); font-size: 11.5px; }

/* ---------- модели ---------- */
.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 4px 14px 0;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: 0 0 auto; }

.model {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.model:first-of-type { border-top: 1px solid var(--line); }
.model .logo { width: 26px; height: 26px; margin-top: 2px; }
.model .main { flex: 1; min-width: 0; }
.model .name { font-size: 15px; font-weight: 600; }
.model .slug { font-family: var(--font-mono); font-size: 12px; color: var(--faint); margin-top: 1px; }
.prices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin-top: 10px;
}
.model .unit {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--faint);
  white-space: nowrap;
}
.model .head { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.prices div { min-width: 0; }
.prices .k {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
.prices .v {
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.model .ctx {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- оплата ---------- */
.methods { display: grid; gap: 8px; }
.method {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.method.on { border-color: var(--accent-line); background: var(--accent-soft); }
.method[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.method .logo { width: 28px; height: 28px; }
.method .t { flex: 1; min-width: 0; }
.method .t span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.method .t b { display: block; font-size: 14.5px; font-weight: 600; }
.method .t span { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.method .mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
}
.method.on .mark { border: 5px solid var(--accent); }

.coins {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.coin {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
}
.coin.on { border-color: var(--accent-line); background: var(--accent-soft); }
.coin .logo { width: 20px; height: 20px; }
.coin .t { min-width: 0; flex: 1; }
.coin .t b { display: block; font-size: 13.5px; font-weight: 600; }
.coin .t span {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pay-note { color: var(--muted); font-size: 12.5px; margin: 12px 2px 0; }

.wait { display: grid; gap: 8px; }
.wait .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
.wait .line { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 12.5px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- профиль ---------- */
.identity { display: flex; gap: 13px; align-items: center; padding: 2px 0 18px; }
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--muted);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.identity .nm { font-size: 18px; font-weight: 620; letter-spacing: -0.01em; }
.identity .un { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

.ledger { margin-top: 4px; }
.ledger .row { cursor: default; align-items: flex-start; }
.ledger .amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  text-align: right;
  white-space: nowrap;
}
.ledger .amount.pos { color: var(--pos); }
.ledger .amount.neg { color: var(--neg); }
.ledger .date { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

/* ---------- пустые состояния ---------- */
.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.empty b { display: block; color: var(--text); font-size: 15px; font-weight: 600; margin-bottom: 6px; }

/* ---------- скелетоны ---------- */
.skeleton {
  height: 14px;
  margin-bottom: 12px;
  border-radius: 6px;
  background: var(--surface-2);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ---------- тосты ---------- */
.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 40;
}
.toast {
  max-width: calc(var(--maxw) - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  animation: toast-in 160ms ease-out;
}
.toast.bad { border-color: rgba(224, 104, 79, 0.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- нижний лист ---------- */
.sheet-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 180ms ease;
  z-index: 30;
}
.sheet-back.on { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateY(12px);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 31;
  max-width: var(--maxw);
  margin: 0 auto;
}
.sheet.on { transform: none; opacity: 1; }
.sheet .grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  margin: 4px auto 10px;
}
.sheet .head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; }
.sheet .head b { flex: 1; font-size: 15px; }
.opt {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.opt .nm { flex: 1; font-size: 14.5px; }
.opt .nm .cnt { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.check {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
}
.check.on { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }

/* ---------- документация ---------- */
.docs-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
  scrollbar-width: none;
}
.docs-nav::-webkit-scrollbar { display: none; }
.docs-nav button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}
.docs-nav button.on { border-color: var(--accent-line); background: var(--accent-soft); color: var(--text); }

.doc h3 { font-size: 18px; font-weight: 640; letter-spacing: -0.01em; margin-bottom: 12px; }
.doc h4 {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 22px 0 8px;
  font-weight: 500;
}
.doc p { color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 65ch; margin: 0 0 12px; }
.doc ul { color: var(--muted); font-size: 14px; line-height: 1.6; padding-left: 18px; margin: 0 0 14px; }
.doc li { margin-bottom: 6px; }
.doc code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--text);
}
.code {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  margin: 0 0 14px;
  overflow: hidden;
}
.code .bar2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}
.code pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: #d6dbe0;
}
.cbtn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.play { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 16px; }
.play .out {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  color: var(--text);
}

/* ---------- успех создания ключа ---------- */
.success { padding: 8px 0 4px; }
.success .mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: var(--accent);
  margin-bottom: 14px;
}
.success h2 { font-size: 21px; font-weight: 650; letter-spacing: -0.015em; }
.success .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.foot {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.foot button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 0;
  cursor: pointer;
  min-height: 34px;
}
.foot .ver { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

@media (min-width: 480px) {
  .app { padding-left: 20px; padding-right: 20px; }
  .balance .value { font-size: 48px; }
  .prices { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  :root { --maxw: 640px; }
  .app { padding-top: 28px; }
}
