/* Mini App: один экран, переходы вместо прокрутки ленты.
   Цвета берём у Telegram, чтобы приложение не спорило с темой клиента. */

:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --muted: var(--tg-theme-hint-color, #8d9aa8);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 16px;
  --gap: 12px;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

/* ───────── загрузка ───────── */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 50; transition: opacity .3s var(--ease);
}
.boot.gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--muted) 35%, transparent);
  border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── экраны: сдвиг, а не перезагрузка ───────── */
.view {
  position: absolute; inset: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  opacity: 0; transform: translateX(28px);
  transition: opacity .26s var(--ease), transform .26s var(--ease);
  pointer-events: none; visibility: hidden;
}
.view.active { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.view.leaving-left { transform: translateX(-22px); opacity: 0; }

/* содержимое проявляется лесенкой — взгляд успевает за экраном */
.view.active > * { animation: rise .32s var(--ease) backwards; }
.view.active > *:nth-child(1) { animation-delay: .02s; }
.view.active > *:nth-child(2) { animation-delay: .06s; }
.view.active > *:nth-child(3) { animation-delay: .10s; }
.view.active > *:nth-child(4) { animation-delay: .14s; }
.view.active > *:nth-child(5) { animation-delay: .18s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  .view, .view.active > * { transition: none; animation: none; }
}

/* ───────── шапка ───────── */
.hero {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: var(--gap);
}
.hero-row { display: flex; gap: 8px; }
.hero-cell {
  flex: 1; min-width: 0; background: none; border: 0; padding: 0;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: opacity .15s var(--ease);
}
.hero-cell:active { opacity: .55; }
.hero-cell.right { text-align: right; }
.hero-note { font-size: 11px; color: var(--muted); margin-top: 3px; }
.hero-label { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.hero-value { font-size: 22px; font-weight: 650; margin-top: 2px; }
.hero-folder {
  margin-top: 12px; padding-top: 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid color-mix(in srgb, var(--muted) 18%, transparent);
  word-break: break-all;
}

/* ───────── плитки ───────── */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-bottom: var(--gap); }
.tile {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  background: var(--card); border: 0; border-radius: var(--radius);
  padding: 16px 14px; color: var(--text); font: inherit; cursor: pointer;
  transition: transform .14s var(--ease), background .14s var(--ease);
}
.tile:active { transform: scale(.96); background: color-mix(in srgb, var(--card) 80%, var(--accent)); }
.tile-ico { font-size: 22px; line-height: 1.2; }
.tile-name { font-weight: 600; margin-top: 6px; }
.tile-sub { font-size: 12px; color: var(--muted); }

/* ───────── кнопки ───────── */
.wide {
  display: block; width: 100%; padding: 14px; border: 0; border-radius: 14px;
  font: inherit; font-weight: 600; cursor: pointer; margin-top: var(--gap);
  transition: transform .14s var(--ease), opacity .2s var(--ease);
}
.wide:active { transform: scale(.98); }
.wide:disabled { opacity: .45; pointer-events: none; }
.primary { background: var(--accent); color: var(--accent-text); }
.ghost { background: var(--card); color: var(--text); }
.danger { background: var(--danger); color: #fff; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.actions-row .wide { margin-top: 0; }
.actions { margin-top: 20px; display: grid; gap: var(--gap); }
.sticky { position: sticky; bottom: 0; margin-top: 20px; }

/* ───────── списки ───────── */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 0; border-radius: 12px; padding: 13px 14px;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: transform .14s var(--ease), background .14s var(--ease);
  animation: rise .3s var(--ease) backwards;
}
.item:active { transform: scale(.985); background: color-mix(in srgb, var(--card) 82%, var(--accent)); }
.item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: normal; }
.item-meta { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.lock { flex-shrink: 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ───────── поля и чипы ───────── */
.bar { display: flex; gap: 8px; margin-bottom: var(--gap); }
.field {
  flex: 1; background: var(--card); border: 0; border-radius: 12px;
  padding: 12px 14px; color: var(--text); font: inherit; outline: none;
  transition: box-shadow .18s var(--ease);
}
.field:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.field::placeholder { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card); border: 0; border-radius: 999px; padding: 9px 14px;
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
  transition: transform .14s var(--ease), background .18s var(--ease), color .18s var(--ease);
}
.chip:active { transform: scale(.94); }
.chip.on { background: var(--accent); color: var(--accent-text); }

/* ───────── группы ───────── */
.group { margin-bottom: 20px; }
.group-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; padding-left: 4px; }
.group-note { font-size: 12px; color: var(--muted); margin-top: 8px; padding-left: 4px; }

.row {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: var(--card); border: 0; border-radius: 12px; padding: 14px;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; gap: 10px;
}
.row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-go { color: var(--muted); flex-shrink: 0; }

.options { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--card); border: 0; border-radius: 12px; padding: 13px 14px;
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: background .18s var(--ease);
}
.option.on { background: color-mix(in srgb, var(--card) 70%, var(--accent)); }
.option-dot {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--muted); transition: border-color .18s var(--ease);
}
.option.on .option-dot { border-color: var(--accent); border-width: 6px; }
.option-hint { font-size: 12px; color: var(--muted); }

.switches { display: flex; flex-direction: column; gap: 8px; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 0; border-radius: 12px; padding: 13px 14px;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; width: 100%;
}
.knob {
  width: 44px; height: 26px; border-radius: 999px; flex-shrink: 0; position: relative;
  background: color-mix(in srgb, var(--muted) 40%, transparent);
  transition: background .22s var(--ease);
}
.knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .22s var(--ease);
}
.switch.on .knob { background: var(--accent); }
.switch.on .knob::after { transform: translateX(18px); }

/* ───────── ПИН ───────── */
.pin-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 10vh; }
.pin-lock { font-size: 40px; animation: pop .4s var(--ease); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.pin-title { font-size: 20px; font-weight: 650; margin: 14px 0 4px; }
.pin-note { color: var(--muted); font-size: 13px; margin: 0 0 24px; text-align: center; }
.pin-dots { display: flex; gap: 14px; margin-bottom: 32px; }
.pin-dots i {
  width: 13px; height: 13px; border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 35%, transparent);
  transition: background .18s var(--ease), transform .18s var(--ease);
}
.pin-dots i.on { background: var(--accent); transform: scale(1.18); }
.pin-dots.bad { animation: shake .4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-4px); } 30%, 70% { transform: translateX(7px); }
  50% { transform: translateX(-7px); }
}
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 16px; }
.key {
  height: 72px; border-radius: 50%; border: 0; background: var(--card);
  color: var(--text); font: inherit; font-size: 26px; font-weight: 500; cursor: pointer;
  transition: transform .12s var(--ease), background .12s var(--ease);
}
.key:active { transform: scale(.9); background: var(--accent); color: var(--accent-text); }
.key.blank { background: none; pointer-events: none; }

/* ───────── прогресс ───────── */
.prog-head { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.prog-ring { position: relative; width: 190px; margin: 0 auto 22px; }
.prog-ring svg { width: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring-bg { stroke: color-mix(in srgb, var(--muted) 22%, transparent); }
.ring-fg {
  stroke: var(--accent); stroke-dasharray: 327; stroke-dashoffset: 327;
  transition: stroke-dashoffset .5s var(--ease);
}
.ring-text {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.ring-text b { font-size: 32px; font-weight: 650; }
.ring-text span { font-size: 12px; color: var(--muted); }

.prog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cell { background: var(--card); border-radius: 12px; padding: 12px 14px; }
.cell-label { font-size: 11px; color: var(--muted); }
.cell-value { font-size: 17px; font-weight: 600; margin-top: 2px; }
.prog-file {
  margin-top: var(--gap); font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 18px;
}
.prog-summary {
  margin-top: var(--gap); background: var(--card); border-radius: var(--radius);
  padding: 16px; white-space: pre-wrap; font-size: 14px; line-height: 1.6;
  animation: rise .4s var(--ease);
}

/* ───────── прочее ───────── */
.picked {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  font-weight: 600; margin-bottom: 18px; word-break: break-word;
}
.path { font-size: 13px; color: var(--text); word-break: break-all; margin-bottom: 4px; }
.path-meta { font-size: 12px; color: var(--muted); margin-bottom: var(--gap); }
.log {
  background: var(--card); border-radius: 12px; padding: 12px; margin: 0;
  font-size: 11px; line-height: 1.5; overflow-x: auto; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}

.doc {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  font-size: 15px; line-height: 1.6; animation: rise .3s var(--ease);
  overflow-wrap: anywhere;
}
.doc b { font-weight: 650; }
.doc pre {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border-radius: 10px; padding: 12px; overflow-x: auto;
  font-size: 12.5px; line-height: 1.45; margin: 10px 0; white-space: pre;
}
.doc code {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border-radius: 5px; padding: 1px 5px; font-size: 13px;
}
.doc a { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--card); color: var(--text); padding: 12px 18px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; z-index: 60; max-width: 86vw;
  text-align: center; box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
