/* ============================================================
 * FREEZE ADS BOT — App Layout
 * ============================================================
 * 
 * Structural layout for the Telegram Mini App:
 *
 *   .app-container          — viewport wrapper
 *     #chocolate-particles  — canvas (z: 0, dark only)
 *     .app-header           — fixed top bar
 *     .app-content          — scrollable middle area
 *     .app-nav              — fixed bottom navigation
 *     .support-fab          — floating support tab
 *
 * Max-width 480px, centred horizontally for tablet/desktop.
 * All spacing accounts for safe-area insets (set by JS).
 * ========================================================== */


/* ══════════════════════════════════════════════════════════
 * APP CONTAINER
 * ════════════════════════════════════════════════════════ */

.app-container {
  position: relative;
  width: 100%;
  max-width: var(--max-app-width);
  margin: 0 auto;
  height: 100%;
  overflow: hidden;

  /* Contain child z-indices within this stacking context */
  isolation: isolate;
}

/* Full-bleed background behind the centred column */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: -1;
}


/* ══════════════════════════════════════════════════════════
 * APP HEADER — Fixed Top Bar
 * ════════════════════════════════════════════════════════ */

.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-app-width);
  height: calc(var(--header-height) + var(--safe-area-top, 0px));
  padding-top: var(--safe-area-top, 0px);
  z-index: var(--z-header);

  /* Layout */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: var(--content-padding);
  padding-right: var(--content-padding);
  gap: var(--space-3);

  /* Glassmorphic background */
  background: var(--bg-nav);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-bottom: 1px solid var(--border-light);

  /* Prevent content from appearing above during scroll */
  will-change: transform;
}

/* ── Header: Avatar Group (left side) ────────────────────── */
.header-avatar-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.header-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#header-avatar {
  border: 2px solid var(--border);
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.15);
}

/* 'Free plan' badge below avatar */
.header-plan-badge {
  /* Uses .badge-plan from components.css */
  margin-top: -2px;
}

/* ── Header: Center area (balance pill) ──────────────────── */
.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

/* ── Header: Right actions (icon buttons) ────────────────── */
.header-right,
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════════════
 * APP CONTENT — Scrollable Main Area
 * ════════════════════════════════════════════════════════ */

.app-content {
  position: relative;
  z-index: var(--z-base);

  /* Space for fixed header + fixed nav */
  padding-top: calc(var(--header-height) + var(--safe-area-top, 0px) + var(--space-2));
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom, 0px) + var(--space-2));
  padding-left: var(--content-padding);
  padding-right: var(--content-padding);

  /* Fill viewport */
  height: 100%;

  /* Smooth scroll */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}


/* ══════════════════════════════════════════════════════════
 * APP NAV — Fixed Bottom Navigation
 * ════════════════════════════════════════════════════════ */

.app-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-app-width);
  height: calc(var(--nav-height) + var(--safe-area-bottom, 0px));
  padding-bottom: var(--safe-area-bottom, 0px);
  z-index: var(--z-nav);

  /* Layout: 6 equal columns */
  display: flex;
  align-items: stretch;

  /* Glassmorphic background */
  background: var(--bg-nav);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  border-top: 1px solid var(--border-light);

  /* No user-select on nav */
  user-select: none;
  -webkit-user-select: none;
}

/* ── Individual Nav Item ─────────────────────────────────── */
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-2) 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  transition:
    color var(--transition-fast),
    background var(--transition-fast),
    transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover {
  color: var(--text-secondary);
}

.nav-item:active {
  transform: scale(0.95);
}

.nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform var(--transition-fast);
}

.nav-icon svg,
.nav-icon img {
  width: 24px;
  height: 24px;
}

/* Nav label */
.nav-label {
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  line-height: 1;
  white-space: nowrap;
}

/* ── Active Nav Item ─────────────────────────────────────── */
.nav-item.active {
  color: var(--accent);
}

.nav-item.active .nav-icon {
  transform: scale(1.05);
}

/* Sliding indicator bar below active tab */
.nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 var(--radius-full) var(--radius-full);
  animation: navIndicatorSlide 0.25s var(--ease-out-expo) both;
}

/* Inactive items don't have the bar */
.nav-item:not(.active)::after {
  content: none;
}

/* ── Nav item notification dot ───────────────────────────── */
.nav-item .nav-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--danger);
  border: 2px solid var(--bg-primary);
}


/* ══════════════════════════════════════════════════════════
 * SUPPORT FAB — Floating Support Button
 * ════════════════════════════════════════════════════════ */

.support-fab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-fab);

  /* Sizing */
  width: 32px;
  padding: var(--space-3) var(--space-1);

  /* Style */
  background: var(--info);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-md);

  /* Vertical text */
  writing-mode: vertical-rl;
  text-orientation: mixed;

  /* Text */
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  line-height: 1;

  /* Layout */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);

  /* Interaction */
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.support-fab:hover {
  background: #1a6baa;
  box-shadow: var(--shadow-lg);
}

.support-fab:active {
  transform: translateY(-50%) scale(0.95);
}

.support-fab .support-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Clamp to max-width on wide screens */
@media (min-width: 480px) {
  .support-fab {
    right: calc(50% - var(--max-app-width) / 2);
  }
}


/* ══════════════════════════════════════════════════════════
 * PAGE CONTAINER
 * ════════════════════════════════════════════════════════ */

.page {
  display: none;
}

.page.active {
  display: block;
  animation: fadeInUp 0.3s var(--ease-out-expo) both;
}

/* Stack pages for transition (JS toggles classes) */
.page.page-transitioning {
  position: absolute;
  inset: 0;
  padding: inherit;
}


/* ══════════════════════════════════════════════════════════
 * SECTION TITLES (used across pages)
 * ════════════════════════════════════════════════════════ */

.section-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  padding-left: var(--space-1);
}

.section-gap {
  margin-top: var(--space-5);
}


/* ══════════════════════════════════════════════════════════
 * RESPONSIVE: DESKTOP PREVIEW
 * On wider viewports, show the app with a device frame feel.
 * ════════════════════════════════════════════════════════ */

@media (min-width: 600px) {
  body {
    background: var(--bg-secondary);
  }

  .app-container {
    margin-top: var(--space-6);
    margin-bottom: var(--space-6);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    height: calc(100vh - var(--space-12));
    height: calc(100dvh - var(--space-12));
  }

  /* Constrain fixed elements within the frame */
  .app-header {
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  }

  .app-nav {
    border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
  }
}
