/* DomainU Mini App.

   Цвета берём из темы Telegram (--tg-theme-*), чтобы приложение совпадало с
   клиентом, и подставляем тёмные значения, если Telegram их не прислал.
   Акцент — янтарный: он читается на обеих темах и не сливается с синим
   интерфейсом самого Telegram.
*/

:root {
  --bg: var(--tg-theme-bg-color, #0e1421);
  --surface: var(--tg-theme-secondary-bg-color, #18202f);
  --surface-2: color-mix(in srgb, var(--surface) 82%, #ffffff 7%);
  --text: var(--tg-theme-text-color, #f2f6fc);
  --muted: var(--tg-theme-hint-color, #8b98ad);
  --accent: #f5a524;
  --accent-2: #f97316;
  --on-accent: #1b1204;
  --ok: #2ecc71;
  --warn: #f5a524;
  --danger: #f2545b;
  --border: color-mix(in srgb, var(--text) 12%, transparent);

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  --tap: 44px;
  --tabbar: 60px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }

/* --- каркас --- */

.screens {
  padding: calc(env(safe-area-inset-top) + var(--s-4)) var(--s-4)
           calc(var(--tabbar) + env(safe-area-inset-bottom) + var(--s-6));
  min-height: 100dvh;
}
.screen[hidden] { display: none; }
.screen { animation: enter 240ms cubic-bezier(0.22, 1, 0.36, 1); }

.stack { display: flex; flex-direction: column; gap: var(--s-2); }

/* --- шапки --- */

.hero { padding: var(--s-2) 0 var(--s-5); }
.hero__eyebrow {
  margin: 0 0 var(--s-2);
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero__title {
  margin: 0;
  font-size: clamp(26px, 8vw, 34px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.hero__sub { margin: var(--s-2) 0 0; color: var(--muted); font-size: 14px; }

.page-head { padding: var(--s-2) 0 var(--s-4); }
.page-head__title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.page-head__sub { margin: var(--s-1) 0 0; color: var(--muted); font-size: 14px; }

.section {
  margin: var(--s-5) 0 var(--s-2);
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; gap: var(--s-2);
}
.section__badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px; letter-spacing: 0;
}

/* --- поиск --- */

.searchbar { position: relative; z-index: 5; }
.searchbar--flat { margin-bottom: var(--s-2); }

.searchbar__row {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.searchbar__row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.searchbar__icon { color: var(--muted); }
.searchbar__input {
  flex: 1; min-width: 0;
  min-height: 50px;
  border: 0; background: transparent; color: var(--text);
  /* 16px обязательны: меньше — и iOS зумит страницу при фокусе. */
  font-size: 16px;
  outline: none;
}
.searchbar__input::-webkit-search-cancel-button { display: none; }
.searchbar__input::placeholder { color: var(--muted); }
.searchbar__clear {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  cursor: pointer;
}

.segment {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: var(--s-1);
  margin-top: var(--s-2);
  padding: var(--s-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.segment__item {
  min-height: 38px;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease;
}
.segment__item.is-active { background: var(--surface-2); color: var(--text); }

/* --- карточки --- */

.card {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 140ms ease, background 180ms ease;
}
.card:active { transform: scale(0.985); background: var(--surface-2); }
.card--static { cursor: default; }
.card--static:active { transform: none; background: var(--surface); }

.card__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.card__name { display: block; font-size: 15px; font-weight: 600; word-break: break-all; letter-spacing: -0.01em; }
.card__meta { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.card__price { text-align: right; }
.card__price b {
  display: block;
  font-size: 16px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.card__price span { display: block; margin-top: 1px; color: var(--muted); font-size: 12px; }
.card__chev { color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted);
}
.pill--ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill--warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill--danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

.hint-card, .info-card {
  display: flex; gap: var(--s-3);
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 14px;
}
.hint-card svg { color: var(--accent); }
.hint-card strong { display: block; margin-bottom: 2px; color: var(--text); font-size: 15px; }
.hint-card p, .info-card p { margin: 0 0 var(--s-2); }
.info-card { flex-direction: column; }
.info-card p:last-child { margin-bottom: 0; }
.info-card strong { color: var(--text); }

.empty {
  padding: var(--s-6) var(--s-4);
  text-align: center; color: var(--muted); font-size: 14px;
}
.empty strong { display: block; margin-bottom: var(--s-2); color: var(--text); font-size: 17px; }

/* --- кнопки --- */

.btn {
  min-height: var(--tap);
  padding: 0 var(--s-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, opacity 180ms ease, background 180ms ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; transform: none; cursor: default; }
.btn--block { display: block; width: 100%; margin-top: var(--s-2); text-align: center; line-height: var(--tap); text-decoration: none; }
.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
}
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.btn-row { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.btn-row .btn { flex: 1; }

.amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-2); }

/* --- баланс --- */

.balance-hero {
  padding: var(--s-6) var(--s-4);
  background:
    radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  text-align: center;
}
.balance-hero__label { display: block; color: var(--muted); font-size: 13px; }
.balance-hero__value {
  display: block; margin: var(--s-2) 0 var(--s-1);
  font-size: 38px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: -0.03em;
}
.balance-hero__hint { display: block; color: var(--muted); font-size: 13px; }

/* --- нижняя навигация --- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: var(--s-1) var(--s-2) calc(var(--s-1) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: var(--tap);
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted);
  font-size: 10.5px; font-weight: 600;
  cursor: pointer;
  transition: color 180ms ease;
}
.tab.is-active { color: var(--accent); }
.tab:active { background: var(--surface); }
.tab__badge {
  position: absolute; top: 4px; right: calc(50% - 20px);
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-size: 10px; font-style: normal; font-weight: 700;
  line-height: 16px; text-align: center;
}

/* --- шторка --- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  animation: fade 200ms ease;
}
/* display: flex перебивает атрибут hidden, поэтому скрываем явно. */
.sheet[hidden], .sheet-backdrop[hidden] { display: none; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 90dvh;
  display: flex; flex-direction: column;
  padding: var(--s-2) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom));
  background: var(--bg);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: rise 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
.sheet__grabber {
  width: 38px; height: 4px; margin: 0 auto var(--s-3);
  border-radius: 999px; background: var(--muted); opacity: 0.35;
}
.sheet__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3);
  padding-bottom: var(--s-3);
}
.sheet__title { margin: 0; font-size: 19px; font-weight: 700; word-break: break-all; letter-spacing: -0.02em; }
.sheet__sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.sheet__body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: var(--s-2);
}
/* Во flex-колонке блоки сжимаются по умолчанию и обрезают содержимое,
   поэтому высоту фиксируем по контенту. */
.sheet__body > * { flex: 0 0 auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  cursor: pointer; flex: none;
}
.icon-btn:active { background: var(--surface); }

/* --- строки данных --- */

.rows {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: var(--tap);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row__label { flex: 1; color: var(--muted); font-size: 14px; }
.row__value { font-size: 14px; font-weight: 600; text-align: right; word-break: break-all; }

/* --- переключатели --- */

.toggle {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 56px;
  padding: var(--s-2) var(--s-4);
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text);
  text-align: left; cursor: pointer;
}
.toggle:last-child { border-bottom: 0; }
.toggle__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toggle__name { display: block; font-size: 15px; font-weight: 600; }
.toggle__hint { display: block; margin-top: 1px; color: var(--muted); font-size: 12px; }
.toggle__switch {
  position: relative; flex: none;
  width: 46px; height: 28px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 35%, transparent);
  transition: background 220ms ease;
}
.toggle__switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.toggle[aria-pressed="true"] .toggle__switch { background: var(--ok); }
.toggle[aria-pressed="true"] .toggle__switch::after { transform: translateX(18px); }
.toggle[aria-busy="true"] { opacity: 0.55; }

/* --- поля ввода в шторке --- */

.input-block { display: flex; flex-direction: column; gap: var(--s-2); }
.input-block textarea, .input-block input {
  width: 100%;
  min-height: 52px;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  outline: none;
  resize: vertical;
}
.input-block textarea { min-height: 92px; line-height: 1.5; }
.input-block textarea:focus, .input-block input:focus { border-color: var(--accent); }
.field-hint { color: var(--muted); font-size: 13px; }

.stepper {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.stepper__value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper button {
  width: 40px; height: 40px;
  border: 0; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.stepper button:disabled { opacity: 0.4; }

.total-line {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.total-line span { color: var(--muted); font-size: 14px; }
.total-line b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.code-box {
  padding: var(--s-4);
  background: var(--surface);
  border: 1px dashed color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: var(--r-md);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  word-break: break-all;
  text-align: center;
  user-select: all;
}

/* --- скелетоны, тосты --- */

.skeleton {
  height: 64px; border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + var(--s-4));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  font-size: 14px; text-align: center;
  animation: fade 200ms ease;
}
.toast--error { border-color: var(--danger); color: #ffd9db; }
.toast--ok { border-color: var(--ok); }

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
