/**
 * cf-blocks.css
 * ─────────────────────────────────────────────────────────────────────────
 * Runtime styling for Page Builder blocks that need CSS, not just JS, to
 * actually work: Columns, Tabs, Drawer, and scroll-reveal animations.
 * Referenced by both the canvas iframe (app.js) and every published page
 * (worker.js) — must ship at /css/cf-blocks.css on both.
 *
 * Without this file:
 *  - Tabs: every panel has the SAME specificity/display as the active one,
 *    so all panels show at once instead of only the active tab.
 *  - Drawer: the panel and backdrop are position:fixed with no default
 *    hidden state, so they render open/visible immediately regardless of
 *    whether .cf-drawer-open has been toggled on yet.
 *  - Columns: .cf-cols/.cf-cols-2/3/4 have no grid rules, so columns
 *    stack as plain divs instead of laying out side by side.
 *  - Scroll animations: .cf-anim/.cf-in-view (toggled by interactions.js)
 *    have no opacity/transform rules, so the reveal never visibly happens.
 * ─────────────────────────────────────────────────────────────────────────
 */

/* ---------------- Global responsive foundation (published + canvas) ----
 * These rules keep builder pages from overflowing on phones/tablets even
 * when authors used fixed padding or free-moved absolute blocks.
 */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video, canvas, svg { max-width: 100%; height: auto; }
iframe { max-width: 100%; }
table { max-width: 100%; display: block; overflow-x: auto; }

/* :not([style*="width"]) — only guard blocks that DON'T yet have an
 * explicit width set. Applying max-width:100% to every [data-cf-id]
 * fought free-move resize handles (inline width % got capped). */
[data-cf-id]:not([style*="width"]) { max-width: 100%; }
.cf-block, .cf-section, .cf-row { box-sizing: border-box; }

/* Buttons */
[data-cf-btn] { max-width: 100%; box-sizing: border-box; white-space: normal; word-break: break-word; }

/* Form widgets: never wider than viewport; height stays content-driven */
.cf-form-widget, .cf-form-wrap {
  max-width: 100% !important;
  box-sizing: border-box;
  width: 100%;
}
.cf-form-widget iframe.cf-embed-frame,
.cf-form-wrap iframe.cf-embed-frame,
iframe[data-cf-embed] {
  max-width: 100%;
  width: 100%;
  border: 0;
  display: block;
}

/* Feature / team / logo / FAQ grids use auto-fit already; reinforce */
[data-cf-features],
[data-cf-team],
[data-cf-logos],
[data-cf-faq],
[data-cf-stats],
[data-cf-gallery] {
  max-width: 100%;
  box-sizing: border-box;
}

/* ---------------- Columns ---------------- */
.cf-cols {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}
.cf-cols-2 { grid-template-columns: repeat(2, 1fr); }
.cf-cols-3 { grid-template-columns: repeat(3, 1fr); }
.cf-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---- Tablet (≤768px) ---- */
@media (max-width: 768px) {
  .cf-cols-2:not(.cf-cols-nostack),
  .cf-cols-3:not(.cf-cols-nostack),
  .cf-cols-4:not(.cf-cols-nostack) { grid-template-columns: 1fr; }
  [data-cf-cols]:not(.cf-cols-nostack) { grid-template-columns: 1fr !important; }

  /* Free-moved absolute blocks: keep % coords but clamp width so they
     never spill past the viewport edge on narrow screens. */
  body > [style*="position: absolute"],
  body > [style*="position:absolute"] {
    max-width: 100vw !important;
  }

  /* Hero / section padding softens on tablet */
  section, header, footer, .cf-header {
    padding-left: max(1rem, env(safe-area-inset-left)) !important;
    padding-right: max(1rem, env(safe-area-inset-right)) !important;
  }

  /* Nav: already has toggle rules injected in canvas; reinforce links wrap */
  .cf-nav .cf-nav-links { flex-wrap: wrap; }

  [data-cf-features],
  [data-cf-team] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)) !important;
  }

  [data-cf-pricing],
  [data-cf-card] {
    max-width: 100% !important;
  }

  .cf-form-widget, .cf-form-wrap {
    max-width: 100% !important;
  }
}

/* ---- Phone (≤480px) ---- */
@media (max-width: 480px) {
  html { font-size: 15px; }

  /* Stack multi-column grids hard */
  [data-cf-features],
  [data-cf-team],
  [data-cf-stats],
  [data-cf-gallery] {
    grid-template-columns: 1fr !important;
  }

  /* Large type in hero-like blocks scales down */
  h1 { font-size: clamp(1.5rem, 8vw, 2.25rem) !important; }
  h2 { font-size: clamp(1.25rem, 6vw, 1.75rem) !important; }

  /* Buttons full-bleed friendly */
  [data-cf-btn],
  a[data-cf-btn],
  .cf-form-modal-trigger {
    max-width: 100%;
    width: auto;
    display: inline-block;
  }

  /* Form modal dialog fills nearly the full phone width */
  .cf-form-modal-dialog {
    max-width: 96vw !important;
    margin: 0 auto;
  }

  /* Countdown cells shrink */
  [data-cf-countdown] > div {
    gap: 0.5rem !important;
  }

  /* Avoid horizontal scroll from absolute free-move leftovers */
  body {
    overflow-x: hidden;
  }
}

/* ---------------- Tabs ---------------- */
.cf-tabs .cf-tab-panel { display: none; }
.cf-tabs .cf-tab-panel.cf-tab-panel-active { display: block; }
.cf-tabs .cf-tabs-nav button[data-cf-tab-btn] { color: #64748b; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color .15s, border-color .15s; }
.cf-tabs .cf-tabs-nav button.cf-tab-active { color: #3b82f6; border-bottom-color: #3b82f6; }

/* ---------------- Drawer ---------------- */
[data-cf-drawer] {
  transform: translateX(105%);
  transition: transform .28s ease;
}
[data-cf-drawer].cf-drawer-open { transform: translateX(0); }
[data-cf-drawer-backdrop] {
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
[data-cf-drawer-backdrop].cf-drawer-open {
  opacity: 1;
  pointer-events: auto;
}

/* ---------------- Modal (native <dialog>) ---------------- */
dialog[data-cf-modal] { margin: auto; }
dialog[data-cf-modal]::backdrop { background: rgba(0, 0, 0, .5); }

/* ---------------- Scroll-reveal animations ---------------- */
.cf-anim {
  opacity: 0;
  transition-property: opacity, transform;
  transition-duration: var(--cf-anim-duration, 600ms);
  transition-delay: var(--cf-anim-delay, 0ms);
  transition-timing-function: ease-out;
}
.cf-anim-fade-up    { transform: translateY(24px); }
.cf-anim-fade-down  { transform: translateY(-24px); }
.cf-anim-fade-left  { transform: translateX(24px); }
.cf-anim-fade-right { transform: translateX(-24px); }
.cf-anim-fade-in    { transform: none; }
.cf-anim-zoom-in    { transform: scale(.92); }

.cf-anim.cf-in-view {
  opacity: 1;
  transform: none;
}

/* Device visibility — set via Settings / Layout power tools */
@media (max-width: 480px) {
  .cf-hide-mobile { display: none !important; }
}
@media (min-width: 481px) and (max-width: 768px) {
  .cf-hide-tablet { display: none !important; }
}
@media (min-width: 769px) {
  .cf-hide-desktop { display: none !important; }
}

/* Sticky utility when data-cf-sticky is applied */
[data-cf-sticky="yes"] {
  position: sticky;
  top: 0;
  z-index: 40;
}


/* Fluid absolute blocks: width is %; height follows aspect-ratio or content.
   Never overflow the viewport on small screens. */
[data-cf-abs="1"], [style*="position: absolute"], [style*="position:absolute"] {
  max-width: 100%;
  box-sizing: border-box;
}
[data-cf-user-sized="1"] {
  /* aspect-ratio set inline; height:auto keeps mobile fluid */
  height: auto !important;
}

/* ── Nav dropdown (works in editor + published) ── */
.cf-nav-item { position: relative; }
.cf-nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 11rem;
  background: #fff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.4rem 0;
  box-shadow: 0 0.75rem 1.5rem rgba(15, 23, 42, 0.14);
  z-index: 100;
}
.cf-nav-item:hover > .cf-nav-dropdown,
.cf-nav-item:focus-within > .cf-nav-dropdown,
.cf-nav-item.is-open > .cf-nav-dropdown { display: block; }
.cf-nav-dropdown a:hover { background: #f1f5f9; }
.cf-nav-links { margin-left: auto; }
.cf-nav, .cf-header {
  position: relative;
  z-index: 20;
}
@media (max-width: 720px) {
  .cf-nav-toggle { display: inline-block !important; }
  .cf-nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    margin-left: 0;
    padding-top: 0.75rem;
  }
  .cf-nav.is-open .cf-nav-links { display: flex; }
  .cf-nav-dropdown { position: static; box-shadow: none; border: none; padding-left: 0.75rem; }
}

/* CTA background image support */
.cf-cta[style*="background-image"] { background-color: transparent; }
