/* ============================================================
   mobile-polish.css — global responsive refinements
   Non-invasive: no layout rewrites. Fluid type, touch sizing,
   media containment, and cleaner spacing on phones.
   Loaded last so it overrides page-specific styles.
   ============================================================ */

/* ---------- global base ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }

img, video, iframe { max-width: 100%; height: auto; }
.sc-img, .card .img, [style*="background-image"] { background-size: cover; background-position: center; }

/* ---------- fluid typography (kicks in below 1024px) ---------- */
@media (max-width: 1024px) {
  :root {
    --fluid-h1: clamp(28px, 8vw, 56px);
    --fluid-h2: clamp(22px, 5.5vw, 40px);
    --fluid-h3: clamp(18px, 4.5vw, 28px);
    --fluid-body: clamp(14px, 3.8vw, 17px);
  }
  h1, .display { font-size: var(--fluid-h1); line-height: 1.1; }
  h2 { font-size: var(--fluid-h2); line-height: 1.15; }
  h3 { font-size: var(--fluid-h3); line-height: 1.2; }
  p, li { font-size: var(--fluid-body); line-height: 1.55; }
}

/* ---------- touch-friendly interactive elements ---------- */
@media (max-width: 768px) {
  button, .btn, .sc-fav, .sc-rm, .chip, .acc-tab, input, select, textarea, a.btn, a.chip, a.sc-sa-btn {
    min-height: 44px;
  }
  .chip, .sc-chip { padding: 10px 14px; }
  .acc-tab { padding: 14px 12px; font-size: 14px; }
  input[type="text"], input[type="email"], input[type="password"], input[type="url"], textarea {
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }
}

/* ---------- containers + grid (fluid) ---------- */
@media (max-width: 768px) {
  .wrap, .container, main > section { padding-left: 18px; padding-right: 18px; }
  section { padding-top: 48px; padding-bottom: 48px; }
  .grid, #grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
}
@media (min-width: 481px) and (max-width: 900px) {
  .grid, #grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- nav / header on mobile ---------- */
@media (max-width: 768px) {
  nav, .nav, header nav { flex-wrap: wrap; gap: 8px; }
  .nav-links, .nav-menu { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav-links::-webkit-scrollbar, .nav-menu::-webkit-scrollbar { display: none; }
  .nav-links a, .nav-menu a { white-space: nowrap; }
}

/* ---------- card internals ---------- */
@media (max-width: 640px) {
  .sc-card { border-radius: 14px; }
  .sc-body { padding: 14px 16px 18px; gap: 8px; }
  .sc-name { font-size: 17px; }
  .sc-tagline { font-size: 13px; }
  .sc-meta { font-size: 10px; gap: 10px; }
  .sc-num, .sc-badge, .sc-ready { font-size: 9.5px; padding: 5px 9px; }
}

/* ---------- modals, overlays ---------- */
@media (max-width: 768px) {
  .modal, .overlay, .buy-modal, [role="dialog"] {
    width: min(96vw, 520px) !important;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 16px;
  }
}

/* ---------- footer ---------- */
@media (max-width: 768px) {
  footer, .footer { padding: 40px 18px; text-align: center; }
  .footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 20px; }
}

/* ======================================================
   view.html — mobile-first logical layout
   - iframe: explicit vh height (auto-height parent collapses iframe:100%)
   - preview: reflowed as vertical stack, specs become sticky bottom CTA
   - topbar: compact, single row, brand+close only
   - AI chat panel: full-screen bottom sheet on phones
   ====================================================== */

@media (max-width: 1024px) {
  .stage { padding: 60px 10px 16px; }
  .frame {
    position: relative; /* anchor absolute children like .tg-reader */
    min-height: calc(100vh - 76px);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    background: #0a0a0b; /* match tg-reader fallback */
  }
  .frame iframe {
    height: calc(100vh - 76px);
    min-height: 560px;
  }
  .preview-body { min-height: calc(100vh - 76px); }

  /* compact topbar */
  .topbar { padding: 10px 12px !important; gap: 8px !important; flex-wrap: nowrap !important; }
  .brand { padding: 6px 10px !important; font-size: 12px !important; }
  .brand small { display: none; }
  .concept-chip { padding: 6px 10px !important; font-size: 10.5px !important; max-width: 55vw !important; }
  .btn-close { padding: 6px 10px !important; font-size: 11px !important; }
}

@media (max-width: 640px) {
  /* preview hero — smaller + sharper */
  .preview-hero {
    aspect-ratio: auto !important;
    min-height: 260px !important;
    padding: 20px !important;
  }
  .preview-hero h1 { font-size: clamp(22px, 6vw, 32px) !important; line-height: 1.05; }
  .preview-hero .tag { font-size: 12px !important; }
  .preview-hero .glyph { font-size: 120px !important; }

  /* body inner is single column already; tighten padding */
  .preview-body-inner {
    padding: 20px 18px 100px 18px !important; /* reserve room for sticky CTA */
    gap: 18px !important;
  }
  .preview-body-inner h2 { font-size: 17px !important; }
  .preview-body-inner p { font-size: 14px; line-height: 1.55; }

  /* specs block — remove sticky from inner, let the CTA be sticky at the bottom */
  .specs { padding: 16px !important; border-radius: 14px; }
  .specs .price { font-size: 34px !important; margin-bottom: 4px; }
  .specs .row { padding: 8px 0; font-size: 12.5px; }

  /* deliverables: scrollable row on phone */
  .deliverables {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scrollbar-width: none;
  }
  .deliverables::-webkit-scrollbar { display: none; }
  .dlv { scroll-snap-align: start; flex-shrink: 0; }

  /* buy CTA — turn into sticky bottom bar on mobile */
  .buy-cta, .specs .btn {
    position: sticky !important;
    bottom: 12px;
    z-index: 30;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
  }

  /* bonus note smaller */
  .bonus-note { font-size: 10.5px !important; padding: 10px 12px !important; }

  /* AI chat — bottom-sheet on phones (target ONLY the sidebar, not child ids) */
  #ai-chat-sidebar {
    top: 10vh !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 90vh !important;
    border-radius: 20px 20px 0 0 !important;
    box-shadow: 0 -20px 60px rgba(0,0,0,0.45) !important;
  }
  #ai-chat-body { font-size: 14.5px; line-height: 1.55; }
  #ai-chat-input { font-size: 16px !important; min-height: 48px; }

  /* frame/iframe: tighter padding, fuller height */
  .stage { padding: 54px 6px 12px !important; }
  .frame { border-radius: 12px; min-height: calc(100vh - 64px); }
  .frame iframe { height: calc(100vh - 64px); min-height: 520px; }

  /* hide decor watermarks on phone — take up RAM on animation */
  #brand-decor { display: none !important; }
}

/* very narrow — drop chip to second row so brand+close remain tappable */
@media (max-width: 380px) {
  .topbar { flex-wrap: wrap !important; }
  .concept-chip { order: 3; width: 100%; max-width: none !important; margin-top: 6px; text-align: center; }
}

/* (deprecated — old generic selector left off; see #ai-chat-sidebar rule above) */

/* ---------- shop / admin tables become cards on mobile ---------- */
@media (max-width: 768px) {
  table.responsive-table,
  table.responsive-table thead,
  table.responsive-table tbody,
  table.responsive-table th,
  table.responsive-table td,
  table.responsive-table tr {
    display: block; width: 100%;
  }
  table.responsive-table thead { display: none; }
  table.responsive-table tr { margin-bottom: 12px; border: 1px solid var(--line, #1e1e25); border-radius: 10px; padding: 10px; }
  table.responsive-table td { border: 0; padding: 6px 4px; }
  table.responsive-table td::before {
    content: attr(data-label) ': ';
    font-weight: 600;
    color: var(--text-3, #94a3b8);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.06em;
    display: block;
    margin-bottom: 2px;
  }
}

/* ---------- safe-area for iOS notch ---------- */
@supports (padding: env(safe-area-inset-top)) {
  body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  nav.fixed, .nav.scrolled { padding-top: max(12px, env(safe-area-inset-top)); }
}
