/* Каркас: приложение, шапка, нижнее меню, экраны стека, нижняя панель действий, шторки, тосты, ворота. */
.ap-app {
  position: relative; width: 100%; max-width: 520px; margin: 0 auto;
  height: 100vh; height: var(--tg-viewport-stable-height, 100dvh);
  overflow: hidden; background: var(--bg-app); color: var(--text);
  display: flex; flex-direction: column; isolation: isolate;
  padding-top: var(--safe-t);
}
@media (min-width: 521px) { .ap-app { box-shadow: 0 0 80px rgba(15, 25, 45, 0.12); } }

.ap-main { position: relative; flex: 1; min-height: 0; z-index: 2; }
.ap-layer { position: absolute; inset: 0; display: flex; flex-direction: column; z-index: 2; }
.ap-layer[hidden] { display: none !important; }
.ap-stack-screen { background: var(--bg-app); z-index: 4; }
.ap-stack-screen > .app-bg { z-index: 0; }

.ap-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior-x: none; -webkit-overflow-scrolling: touch;
  padding: 4px var(--gutter) 24px; position: relative; z-index: 2;
  scrollbar-width: none;
}
.ap-scroll::-webkit-scrollbar { display: none; }
body.sheet-open .ap-scroll { overflow: hidden !important; }
.ap-screen { display: flex; flex-direction: column; gap: 12px; }

/* шапка вкладок: аватар + чип тарифа | колокольчик + шестерёнка */
.topbar {
  position: relative; z-index: 5; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 64px; padding: 8px var(--gutter);
}
.topbar-l, .topbar-r { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-ava { appearance: none; border: 0; padding: 4px; margin: -4px; background: transparent; cursor: pointer; border-radius: 50%; }
.plan-chip {
  appearance: none; border: 0; cursor: pointer;
  min-height: 40px; padding: 0 14px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-head); font-size: 15px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--bg-input); color: var(--text-soft);
  position: relative;
}
.plan-chip::after { content: ""; position: absolute; inset: -4px 0; }
.plan-chip.is-pro { background: linear-gradient(150deg, var(--accent-2), var(--accent)); color: #fff; box-shadow: 0 6px 16px var(--accent-glow); }
.badge {
  position: absolute; top: 4px; right: 4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--bg-app);
  font-variant-numeric: tabular-nums;
}

/* шапка внутреннего экрана: назад + заголовок + действие */
.scr-head {
  position: relative; z-index: 5; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px; min-height: 64px; padding: 8px var(--gutter) 8px 8px;
}
.scr-head .h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 20px; }
.scr-head .icon-btn.back { background: transparent; color: var(--text); }
.scr-head.no-back { padding-left: var(--gutter); }

/* нижняя панель действия над меню / у края экрана */
.actionbar {
  position: relative; z-index: 6; flex-shrink: 0;
  display: flex; gap: 10px; padding: 10px var(--gutter) calc(10px + var(--safe-b));
  background: color-mix(in oklab, var(--bg-app) 86%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 0.5px solid var(--border);
}
.actionbar .btn { flex: 1; }
.actionbar-note { font-size: 15px; color: var(--text-soft); text-align: center; padding: 0 var(--gutter) 2px; }

/* нижнее меню (vMarket .tabbar, 4 вкладки) */
.tabbar {
  position: relative; z-index: 6; flex-shrink: 0;
  display: flex; align-items: stretch; justify-content: space-around;
  min-height: var(--tabbar-h); padding: 4px 6px calc(4px + var(--safe-b));
  background: var(--bg-elev); border-top: 0.5px solid var(--border);
  box-shadow: 0 -10px 28px -8px rgba(15, 25, 45, 0.14), 0 -1px 0 rgba(15, 25, 45, 0.05);
}
[data-theme="dark"] .tabbar { box-shadow: 0 -10px 28px -8px rgba(0, 0, 0, 0.5), 0 -1px 0 rgba(0, 0, 0, 0.3); }
.tab-indicator {
  position: absolute; top: 0; left: 0; width: 0; height: 3px; border-radius: 0 0 4px 4px;
  background: var(--accent); pointer-events: none;
  transition: transform 0.34s cubic-bezier(0.5, 0, 0.15, 1), width 0.34s cubic-bezier(0.5, 0, 0.15, 1);
  will-change: transform, width;
}
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  flex: 1; min-width: 0; min-height: 56px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-mute); transition: color 0.2s ease;
}
.tab span { font-size: 15px; font-weight: 600; white-space: nowrap; }
.tab.active { color: var(--accent); }
.tab-ico { position: relative; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; }
.tab-ico::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border-radius: 50%; background: radial-gradient(circle, var(--accent-glow), var(--accent-soft) 45%, transparent 72%);
  opacity: 0; pointer-events: none;
}
.tab-ico.anim { animation: tabIcoPop 0.54s cubic-bezier(0.16, 1, 0.3, 1) both; }
.tab-ico.anim::before { animation: tabIcoGlow 0.66s cubic-bezier(0.16, 1, 0.3, 1) both; }
.tab .badge { top: 2px; right: calc(50% - 26px); }

/* шторки (vMarket SheetShell) */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 90; display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px) saturate(135%); backdrop-filter: blur(8px) saturate(135%);
  animation: backdropFade 0.25s ease; transition: opacity 0.3s ease;
}
.sheet-backdrop.closing { opacity: 0; }
.sheet-backdrop.lvl-2 { z-index: 92; }
.sheet {
  width: 100%; max-height: 90%; overflow-y: auto; position: relative; z-index: 1;
  display: flex; flex-direction: column;
  border-radius: 28px 28px 0 0;
  padding: 0 var(--gutter) calc(18px + var(--safe-b));
  background: #f6f7fb; color: var(--text);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.7), inset 0 0 0 0.5px rgba(255, 255, 255, 0.55);
  scrollbar-width: none;
}
.sheet::-webkit-scrollbar { display: none; }
[data-theme="dark"] .sheet {
  -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--bg-elev);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.16), inset 0 0 0 0.5px rgba(255, 255, 255, 0.08);
}
.sheet.is-tall { height: 90%; }
.sheet-grip-zone { position: sticky; top: 0; z-index: 3; height: 24px; box-sizing: border-box; padding: 8px 0 0; margin: 0 calc(-1 * var(--gutter)); background: inherit; display: flex; justify-content: center; cursor: grab; touch-action: none; user-select: none; }
.sheet-grip { width: 38px; height: 4.5px; border-radius: 3px; background: var(--text-mute); opacity: 0.5; }
.sheet-head { display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 8px; }
.sheet-head .h2 { flex: 1; min-width: 0; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.sheet-foot { position: sticky; bottom: calc(-18px - var(--safe-b)); z-index: 3; margin: 12px calc(-1 * var(--gutter)) calc(-18px - var(--safe-b)); padding: 10px var(--gutter) calc(18px + var(--safe-b)); background: #f6f7fb; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 -10px 18px -12px rgba(15, 25, 45, 0.18); }
[data-theme="dark"] .sheet-foot { background: var(--bg-elev); box-shadow: 0 -10px 18px -12px rgba(0, 0, 0, 0.6); }
.sheet-foot .row .btn { flex: 1; }
.sheet .list-card { background: var(--bg-elev); border-radius: var(--r-lg); border: 0.5px solid var(--border); }
[data-theme="dark"] .sheet .list-card { background: rgba(255, 255, 255, 0.04); }

/* тост */
.toast-wrap { position: absolute; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 12px + var(--safe-b)); z-index: 120; display: flex; justify-content: center; padding: 0 var(--gutter); pointer-events: none; }
.toast-wrap.is-low { bottom: calc(84px + var(--safe-b)); }
.toast {
  pointer-events: auto; max-width: 100%;
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 16px;
  border-radius: var(--r-md); background: rgba(20, 21, 28, 0.94); color: #fff;
  font-size: 15px; font-weight: 550; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: fadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
[data-theme="dark"] .toast { background: rgba(250, 250, 255, 0.95); color: #111; }
.toast.is-err .toast-ico { color: oklch(0.72 0.18 25); }
.toast.is-ok .toast-ico { color: oklch(0.75 0.16 150); }

/* ворота на весь экран */
.gate {
  position: absolute; inset: 0; z-index: 200; background: var(--bg-app);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 32px 24px calc(32px + var(--safe-b)); text-align: center;
}
.gate .empty-ico { width: 84px; height: 84px; border-radius: 26px; }
.gate .h1 { font-size: 22px; }
.gate .cap { max-width: 320px; }
.gate .btn { max-width: 340px; }
.gate-list { width: 100%; max-width: 340px; }

/* конфетти (vMarket Confetti) */
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 150; }
.confetti span { position: absolute; left: 50%; top: 40%; animation: confettiBurst 1.2s cubic-bezier(0.1, 0.5, 0.3, 1) forwards; }

.dev-badge { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); z-index: 300; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--amber-soft); color: var(--amber); pointer-events: none; }

/* обёртка нижней панели: заметка + кнопки на одном стеклянном фоне */
.actionbar-wrap {
  position: relative; z-index: 6; flex-shrink: 0; padding-top: 6px;
  background: color-mix(in oklab, var(--bg-app) 86%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 0.5px solid var(--border);
}
.actionbar-wrap .actionbar { background: transparent; border-top: 0; -webkit-backdrop-filter: none; backdrop-filter: none; padding-top: 4px; }
