/* Тема берётся из Telegram (var(--tg-theme-*)), с запасными значениями для обычного браузера. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f86e0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f86e0);
  --border: color-mix(in srgb, var(--hint) 28%, transparent);
  --radius: 16px;
  --up: #17a76a;
  --down: #e0554c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17191c);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #232629);
    --text: var(--tg-theme-text-color, #f1f2f4);
    --hint: var(--tg-theme-hint-color, #8f959d);
    --up: #34c98a;
    --down: #f0736a;
  }
}

* { box-sizing: border-box; }

/* Иконки — инлайновый SVG-спрайт: цвет наследуется от текста, размер задаётся здесь. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px; height: 20px;
  flex: 0 0 auto;
  display: inline-block; vertical-align: middle;
}
.icon-lg { width: 26px; height: 26px; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--secondary-bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.gate {
  max-width: 420px; margin: 0 auto; padding: 64px 24px;
  text-align: center; color: var(--text);
}
.gate-icon { width: 44px; height: 44px; color: var(--accent); }
.gate h1 { font-size: 20px; margin: 16px 0 10px; letter-spacing: -0.02em; }
.gate p { color: var(--hint); font-size: 14px; margin: 8px 0; }
.gate-note { font-size: 13px; opacity: 0.8; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.head h1 {
  margin: 0 0 6px; font-size: 22px; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 10px;
}
.head h1 .icon { color: var(--accent); }
.head .sub { margin: 0 0 18px; color: var(--hint); font-size: 13px; }

.card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  /* minmax(0, 1fr) вместо auto: иначе колонка растягивается под min-content
     поля ввода (у <input> она равна ширине ~20 символов) и карточка вылезает за экран */
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.label {
  color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chips-toggle {
  border: 0; background: none; color: var(--link);
  font-size: 12px; cursor: pointer; padding: 0;
  flex: 0 0 auto; white-space: nowrap;
}

.row-body { display: flex; align-items: center; gap: 10px; min-width: 0; }

.amount {
  flex: 1 1 0%; width: 100%; min-width: 0;
  border: 0; background: none; color: var(--text);
  font-size: 28px; font-weight: 650; letter-spacing: -0.02em;
  padding: 4px 0; outline: none; font-variant-numeric: tabular-nums;
}
.amount:focus-visible { border-bottom: 2px solid var(--accent); }
.result { overflow-x: auto; white-space: nowrap; }
.result.loading { opacity: 0.45; }
.result.error { color: var(--down); font-size: 16px; font-weight: 500; }

.picker {
  display: flex; align-items: center; gap: 6px;
  flex: 0 1 auto; min-width: 0; max-width: 46%;
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px 7px 8px;
  color: var(--text); font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.picker:active { transform: scale(0.97); }
.picker-icon { width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto; }
.picker-code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { width: 14px; height: 14px; color: var(--hint); }

.swap-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.swap-row::before, .swap-row::after {
  content: ""; flex: 1 1 0%; height: 1px; background: var(--border);
}

.swap {
  flex: 0 0 auto;
  width: 38px; height: 38px; border-radius: 50%; border: 0; padding: 0;
  background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.swap .icon { width: 19px; height: 19px; }
.swap:active { transform: scale(0.92); }

.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick[hidden] { display: none; }
.quick button {
  border: 1px solid var(--border); background: var(--secondary-bg); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer;
}

.rate {
  margin: 12px 4px 22px;
  color: var(--hint); font-size: 13px; text-align: center;
}

.favs h2 { font-size: 13px; color: var(--hint); font-weight: 600; margin: 0 4px 10px; text-transform: uppercase; letter-spacing: 0.06em; }
.favs-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }

.fav {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 0; border-radius: 12px;
  padding: 10px; cursor: pointer; text-align: left; color: var(--text);
}
.fav:active { opacity: 0.7; }
.fav img { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; }
.fav-info { min-width: 0; }
.fav-code { display: block; font-weight: 650; font-size: 14px; }
.fav-price { display: block; font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up { color: var(--up); }
.down { color: var(--down); }

.foot { margin-top: 26px; color: var(--hint); font-size: 12px; text-align: center; }
.foot p { margin: 6px 0; }
.note {
  display: flex; align-items: flex-start; justify-content: center; gap: 8px;
  text-align: left; max-width: 360px; margin: 6px auto;
}
.note .icon { width: 15px; height: 15px; margin-top: 1px; }
.src { opacity: 0.75; }

/* Шторка выбора валюты */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 82vh; display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: 0.4; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 16px; margin: 0 0 10px; }
.sheet-close {
  border: 0; background: none; color: var(--hint); cursor: pointer;
  padding: 4px; margin: -4px -4px 10px 0;
  display: flex; align-items: center;
}
.sheet-close .icon { width: 18px; height: 18px; }

.search-wrap { position: relative; margin-bottom: 10px; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--hint); pointer-events: none;
}

.search {
  width: 100%; border: 1px solid var(--border); background: var(--secondary-bg);
  color: var(--text); border-radius: 12px; padding: 10px 12px 10px 38px;
  font-size: 15px; outline: none;
}
.search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search:focus { border-color: var(--accent); }

.sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; gap: 2px; }

.opt {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: none; color: var(--text);
  padding: 10px 8px; border-radius: 12px; cursor: pointer; text-align: left; width: 100%;
}
.opt:hover, .opt:focus-visible { background: var(--secondary-bg); }
.opt[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.opt img { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; }
.opt-main { flex: 1 1 auto; min-width: 0; }
.opt-code { font-weight: 650; font-size: 15px; }
.opt-name { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt-price { font-size: 13px; color: var(--hint); text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--hint); font-size: 14px; padding: 18px 8px; text-align: center; }
