/* ============================================================================
   MOOD — раздел «Купить криптовалюту» на странице кассы (#walletPanelBuy).

   Сценарий тут сквозной: купить крипту в обменнике → взять адрес в кассе →
   обменник отправляет крипту на этот адрес. Поэтому экран собран как
   последовательность шагов, а не как набор полей.

   Всё на токенах темы: своих hex-значений нет, кроме нейтральных теней.
   ========================================================================= */

.wallet-buy {
  display: flex;
  flex-direction: column;
  gap: var(--space-5, 24px);
}

/* --- Общие примитивы ----------------------------------------------------- */
.wallet-buy__label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim, var(--text-muted));
}

.wallet-buy__placeholder {
  margin: 0;
  padding: 18px 4px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-muted);
}

/* --- Шаг 0: как это работает -------------------------------------------- */
.wallet-buy__how {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 18px);
  background: var(--bg-card, var(--surface-2));
  overflow: hidden;
}

.wallet-buy__how-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-display, inherit);
  font-size: 0.95rem;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.wallet-buy__how-chev {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: transform 0.2s var(--ease-out, ease-out);
}

.wallet-buy__how-toggle[aria-expanded="false"] .wallet-buy__how-chev {
  transform: rotate(-90deg);
}

.wallet-buy__how-body {
  padding: 0 16px 16px;
}

.wallet-buy__how-toggle[aria-expanded="false"] + .wallet-buy__how-body {
  display: none;
}

.wallet-buy__steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.wallet-buy__step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

.wallet-buy__step-num {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent-deep, var(--accent));
  font-family: var(--font-display, inherit);
  font-size: 0.8rem;
  font-weight: 800;
}

.wallet-buy__disclaimer {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.wallet-buy__disclaimer a,
.wallet-buy__monitor {
  color: var(--accent-deep, var(--accent));
  font-weight: 600;
}

/* --- Шаг 1: пара «платите → получаете» ---------------------------------- */
.wallet-buy__pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5, 24px);
}

.wallet-buy__group {
  min-width: 0;
}

/* Кнопки выбора — плитки в сетке, а не переносящийся ряд «таблеток» */
.wallet-buy__opts {
  display: grid;
  gap: 8px;
}

.wallet-buy__opts--payin {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wallet-buy__opts--coin {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wallet-buy__opts--net {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.wallet-buy__opt {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

.wallet-buy__opt:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.wallet-buy__opt[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: var(--accent-dim);
  color: var(--accent-deep, var(--accent));
}

.wallet-buy__net-row {
  margin-top: 10px;
}

.wallet-buy__net-row[hidden] {
  display: none;
}

.wallet-buy__net-hint {
  margin: 8px 0 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* --- Шаг 2: сумма в двух направлениях ----------------------------------- */
.wallet-buy__amount-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.wallet-buy__amount-field {
  display: block;
  min-width: 0;
}

.wallet-buy__amount-cap {
  display: block;
  margin-bottom: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
}

.wallet-buy__amount-input-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  background: var(--surface-2);
  transition: border-color 0.16s ease;
}

.wallet-buy__amount-input-wrap:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.wallet-buy__amount-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-display, inherit);
  /* не ниже 16px — иначе iOS зумит вьюпорт при фокусе */
  font-size: max(16px, 1.15rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.wallet-buy__amount-input:focus {
  outline: none;
  box-shadow: none;
}

.wallet-buy__amount-input::-webkit-outer-spin-button,
.wallet-buy__amount-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.wallet-buy__amount-cur {
  flex: none;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.wallet-buy__amount-swap {
  flex: none;
  align-self: center;
  padding-top: 22px;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 700;
}

.wallet-buy__presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.wallet-buy__preset {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 12px);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.16s ease, border-color 0.16s ease;
}

.wallet-buy__preset:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.wallet-buy__note {
  margin: 12px 0 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.wallet-buy__note:empty {
  display: none;
}

/* --- Шаг 3: обменники --------------------------------------------------- */
.wallet-buy__offers-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: -8px;
}

.wallet-buy__offers-title {
  font-family: var(--font-display, inherit);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.wallet-buy__refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius-md, 12px);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wallet-buy__refresh:hover {
  color: var(--text);
}

.wallet-buy__refresh svg {
  flex: none;
  width: 14px;
  height: 14px;
}

.wallet-buy--loading .wallet-buy__refresh svg {
  animation: wallet-buy-spin 0.9s linear infinite;
}

@keyframes wallet-buy-spin {
  to { transform: rotate(360deg); }
}

.wallet-buy__offers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wallet-buy__offer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    'name  cta'
    'get   cta'
    'meta  cta'
    'limit cta';
  align-items: center;
  gap: 2px 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 18px);
  background: var(--bg-card, var(--surface-2));
}

.wallet-buy__offer--best {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

/* Сумма вне лимитов обменника: гасим только информацию и объясняем причину.
   Кнопку не трогаем — затемнённая, она читается как сломанная, хотя ссылка
   рабочая и сумму можно поправить уже в обменнике. */
.wallet-buy__offer--off .wallet-buy__offer-name,
.wallet-buy__offer--off .wallet-buy__offer-get,
.wallet-buy__offer--off .wallet-buy__offer-meta {
  opacity: 0.55;
}

.wallet-buy__offer-name {
  grid-area: name;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-family: var(--font-display, inherit);
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text);
}

.wallet-buy__offer-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-buy__offer-badge {
  flex: none;
  padding: 3px 8px;
  border-radius: var(--radius-pill, 999px);
  background: var(--accent-dim);
  color: var(--accent-deep, var(--accent));
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.wallet-buy__offer-get {
  grid-area: get;
  margin-top: 4px;
  font-family: var(--font-display, inherit);
  font-size: 1.32rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}

.wallet-buy__offer-unit {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-muted);
}

.wallet-buy__offer-meta,
.wallet-buy__offer-limit {
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.wallet-buy__offer-meta {
  grid-area: meta;
  margin-top: 2px;
}

.wallet-buy__offer-limit {
  grid-area: limit;
}

.wallet-buy__offer-warn {
  grid-area: limit;
  font-size: 0.76rem;
  line-height: 1.45;
  font-weight: 600;
  color: var(--danger, #f3536b);
}

.wallet-buy__offer-go {
  grid-area: cta;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 18px;
  border-radius: var(--radius-md, 12px);
  background: var(--grad-brand, var(--accent));
  color: var(--btn-primary-text, #0b1210);
  font-size: 0.84rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.wallet-buy__offer-go:hover {
  filter: brightness(1.06);
}

.wallet-buy__more {
  align-self: center;
  min-height: 42px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.wallet-buy__more.hidden {
  display: none;
}

/* --- Шаг 4: мост обратно в кассу за адресом ----------------------------- */
.wallet-buy__bridge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--border));
  border-radius: var(--radius-lg, 18px);
  background: var(--accent-dim);
}

.wallet-buy__bridge-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.wallet-buy__bridge-title {
  font-family: var(--font-display, inherit);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.wallet-buy__bridge-sub {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.wallet-buy__bridge-btn {
  flex: none;
  min-height: 44px;
  padding: 10px 20px;
  border: 0;
  border-radius: var(--radius-md, 12px);
  background: var(--grad-brand, var(--accent));
  color: var(--btn-primary-text, #0b1210);
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wallet-buy__bridge-btn:hover {
  filter: brightness(1.06);
}

.wallet-buy__monitor {
  align-self: flex-start;
  font-size: 0.84rem;
  text-decoration: none;
}

.wallet-buy__monitor:hover {
  text-decoration: underline;
}

/* --- Телефон ------------------------------------------------------------- */
@media (max-width: 640px) {
  .wallet-buy {
    gap: var(--space-4, 16px);
  }

  /* Пара выборов встаёт в колонку — иначе плитки сжимаются до нечитаемых */
  .wallet-buy__pair {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4, 16px);
  }

  .wallet-buy__opts--coin {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Поля суммы друг под другом: в три колонки на 360px они нечитаемы */
  .wallet-buy__amount-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .wallet-buy__amount-swap {
    justify-self: center;
    padding-top: 0;
    transform: rotate(90deg);
  }

  /* Карточка обменника в одну колонку: раньше CTA сжимал текст в узкий столбец */
  .wallet-buy__offer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'name'
      'get'
      'meta'
      'limit'
      'cta';
    gap: 2px;
  }

  .wallet-buy__offer-go {
    margin-top: 12px;
    width: 100%;
    min-height: 46px;
  }

  .wallet-buy__offer-get {
    font-size: 1.5rem;
  }

  .wallet-buy__bridge {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .wallet-buy__bridge-btn {
    width: 100%;
  }

  .wallet-buy__more {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wallet-buy__how-chev,
  .wallet-buy__opt,
  .wallet-buy__preset {
    transition: none;
  }

  .wallet-buy--loading .wallet-buy__refresh svg {
    animation: none;
  }
}
