/* ============================================================
   Rich-UX layer: WebGL backdrop, glass surfaces, 3D/spotlight cards,
   HTMX transitions, toasts, command palette, page transitions.
   Scoped so that with effects off (html.fx-off) or before WebGL is ready
   the original solid design renders unchanged.
   ============================================================ */
[x-cloak] { display: none !important; }

/* ---- WebGL canvas --------------------------------------------------- */
#fx-canvas {
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: -1; pointer-events: none;
  opacity: 0; transition: opacity 1.2s ease;
}
#fx-canvas.on { opacity: 1; }
html.fx-off #fx-canvas, html.no-webgl #fx-canvas { display: none; }

/* ---- progress bars -------------------------------------------------- */
#top-loader, #scroll-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; transform: scaleX(0); transform-origin: 0 50%;
  z-index: 4000; pointer-events: none;
}
#top-loader { background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent)); opacity: 0;
  transition: transform .25s ease, opacity .3s ease; box-shadow: 0 0 12px var(--secondary); }
#scroll-progress { height: 2px; top: 3px; background: var(--secondary); opacity: .55; transition: transform .1s linear; }

/* ---- glass surfaces (only while the scene is live) ------------------- */
html.fx-ready:not(.fx-off) .hero { background: transparent; }
html.fx-ready:not(.fx-off) .section-features,
html.fx-ready:not(.fx-off) .section-testimonials,
html.fx-ready:not(.fx-off) .section-faq { background: color-mix(in srgb, var(--bg-white) 58%, transparent); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
html.fx-ready:not(.fx-off) .section-how,
html.fx-ready:not(.fx-off) .section-pricing { background: color-mix(in srgb, var(--bg-cream) 40%, transparent); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
html.fx-ready:not(.fx-off) .help-hero,
html.fx-ready:not(.fx-off) .ind-hero,
html.fx-ready:not(.fx-off) .dir-hero,
html.fx-ready:not(.fx-off) .pp-hero { background: color-mix(in srgb, var(--bg-cream) 30%, transparent); }
html.fx-ready:not(.fx-off) .navbar { background: rgba(255,255,255,.62); backdrop-filter: blur(22px) saturate(1.5); -webkit-backdrop-filter: blur(22px) saturate(1.5); }
html.fx-ready:not(.fx-off) .navbar.scrolled { background: rgba(255,255,255,.82); }

html.fx-ready:not(.fx-off) :is(.visual-card, .feature-card, .pricing-card, .provider-card, .tool-card,
  .testimonial-card, .fav-card, .res-card, .booking-card, .panel, .form-card, .faq-item) {
  background-color: rgba(255,255,255,.74);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-color: rgba(255,255,255,.7);
}

/* ---- 3D tilt + spotlight (driven by ui.js CSS vars) ------------------- */
:is(.visual-card, .feature-card, .pricing-card, .provider-card, .tool-card, .testimonial-card,
    .fav-card, .res-card, .booking-card, [data-tilt]) {
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform .18s ease-out, box-shadow .3s ease, background-color .3s ease;
  will-change: transform;
}
:is(.visual-card, .feature-card, .pricing-card, .provider-card, .tool-card, .testimonial-card,
    .fav-card, .res-card, .booking-card, [data-tilt]).fx-hot {
  background-image: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--secondary) 16%, transparent), transparent 55%);
  box-shadow: var(--shadow-xl);
}
.visual-card { animation: none; }                      /* tilt replaces the idle float on the hero card */
html.fx-off .visual-card { animation: float 6s ease-in-out infinite; }

/* magnetic primary buttons */
.btn-primary { transform: translate(var(--tx, 0px), var(--ty, 0px)); transition: transform .22s ease-out, box-shadow var(--transition), background var(--transition); }
.btn-primary:hover { transform: translate(var(--tx, 0px), calc(var(--ty, 0px) - 3px)); }
.btn:active { transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(.97); }

/* loading state on any HTMX-triggering control */
.btn.is-loading { pointer-events: none; opacity: .85; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; animation: fx-spin .7s linear infinite; }
input.is-loading { background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--secondary) 18%, transparent), transparent);
  background-size: 200% 100%; animation: fx-shimmer 1s linear infinite; }
@keyframes fx-spin { to { transform: rotate(360deg); } }
@keyframes fx-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---- HTMX swap choreography ------------------------------------------- */
.htmx-swapping { opacity: 0; transform: translateY(6px); transition: opacity .16s ease-out, transform .16s ease-out; }
.htmx-added { opacity: 0; }
.htmx-settling { opacity: 1; transition: opacity .28s ease-out; }
.htmx-request:not(.btn):not(input) { opacity: .65; transition: opacity .2s; }
[data-stagger] > * { animation: fx-rise .5s cubic-bezier(.2,.7,.2,1) both; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes fx-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.reveal { transition-delay: calc(var(--i, 0) * 70ms); }

/* ---- toasts -------------------------------------------------------------- */
.fx-toasts { position: fixed; bottom: 22px; right: 22px; z-index: 5000; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.fx-toast { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: 14px; font-size: .88rem; font-weight: 500;
  background: rgba(255,255,255,.88); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.8); box-shadow: var(--shadow-lg); border-left: 4px solid var(--secondary); cursor: pointer; }
.fx-toast i { margin-top: 2px; color: var(--secondary); }
.fx-toast.success { border-left-color: var(--success); } .fx-toast.success i { color: var(--success); }
.fx-toast.error { border-left-color: var(--accent); } .fx-toast.error i { color: var(--accent); }
.fx-toast.warning { border-left-color: var(--warning); } .fx-toast.warning i { color: var(--warning); }

/* ---- command palette ------------------------------------------------------ */
.cmdk-backdrop { position: fixed; inset: 0; z-index: 6000; background: rgba(20,18,46,.38); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 0; }
.cmdk { width: min(640px, 100%); border-radius: 22px; overflow: hidden; background: rgba(255,255,255,.92);
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(255,255,255,.8); box-shadow: 0 30px 90px rgba(30,20,80,.35); }
.cmdk-input { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid rgba(79,70,229,.1); }
.cmdk-input i { color: var(--secondary); }
.cmdk-input input { flex: 1; border: 0; outline: 0; background: transparent; font: inherit; font-size: 1.02rem; color: var(--text-primary); }
.cmdk-input kbd, .cmdk-hint kbd, .kbd { font: 600 .7rem var(--font-primary); padding: 3px 7px; border-radius: 6px; background: var(--bg-light); color: var(--text-muted); border: 1px solid rgba(0,0,0,.06); }
.cmdk-list { max-height: min(56vh, 440px); overflow: auto; padding: 8px; }
.cmdk-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 12px; border-radius: 12px; text-align: left; cursor: pointer;
  font: inherit; font-size: .92rem; color: var(--text-primary); background: transparent; border: 0; }
.cmdk-item i { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--secondary-light); color: var(--secondary-dark); font-size: .82rem; }
.cmdk-item .kbd { margin-left: auto; }
.cmdk-item.active, .cmdk-item:hover { background: color-mix(in srgb, var(--secondary) 11%, transparent); }
#cmdk-results .search-results { display: block; margin: 0; } #cmdk-results .sr-item { border-radius: 12px; }
#cmdk-results .sr-item.active { background: color-mix(in srgb, var(--secondary) 11%, transparent); }
#cmdk-results > p { display: none; }
.cmdk-hint { display: flex; gap: 16px; padding: 10px 18px; font-size: .72rem; color: var(--text-muted); border-top: 1px solid rgba(79,70,229,.08); }

/* ---- navbar live search dropdown + controls ------------------------------- */
.ns-pop { position: absolute; top: calc(100% + 10px); right: 0; width: min(420px, 90vw); max-height: 60vh; overflow: auto; border-radius: 18px; padding: 8px;
  background: rgba(255,255,255,.94); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,.8); box-shadow: var(--shadow-xl); z-index: 1200; }
.ns-pop .search-results { margin: 0; display: block; } .ns-pop > p { display: none; }
.ns-pop .sr-item { border-radius: 12px; padding: 10px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--text-secondary);
  background: transparent; border: 1px solid rgba(79,70,229,.12); cursor: pointer; transition: all .25s; }
.icon-btn:hover { background: var(--secondary-light); color: var(--secondary-dark); transform: translateY(-2px); }
.icon-btn.on { background: var(--secondary); color: #fff; border-color: var(--secondary); box-shadow: var(--shadow-glow); }
.nav-kbd { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 99px; border: 1px solid rgba(79,70,229,.12);
  background: transparent; font-size: .74rem; color: var(--text-muted); cursor: pointer; }
.nav-kbd:hover { border-color: var(--secondary); color: var(--secondary-dark); }
@media (max-width: 900px) { .nav-kbd { display: none; } }

/* ---- cross-page transitions (Chrome/Safari): no white flash, nav stays put -- */
@view-transition { navigation: auto; }
.navbar { view-transition-name: site-nav; }
::view-transition-old(root) { animation: .22s ease both fx-out; }
::view-transition-new(root) { animation: .32s ease both fx-in; }
@keyframes fx-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes fx-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- accessibility ---------------------------------------------------------- */
:focus-visible { outline: 3px solid color-mix(in srgb, var(--secondary) 55%, white); outline-offset: 3px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  #fx-canvas { transition: none; }
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  :is(.visual-card, .feature-card, .pricing-card, .provider-card, .tool-card, .testimonial-card, [data-tilt]) { transform: none !important; }
}

/* ---- navbar: keep everything on one line with the extra controls ------- */
.navbar .nav-links a, .nav-actions .btn, .nav-signin, .nav-kbd, .theme-toggle button { white-space: nowrap; }
.nav-search input { width: 118px; } .nav-search input:focus { width: 200px; }
@media (max-width: 1500px) { .nav-kbd { display: none; } }
@media (max-width: 1180px) { .nav-search { display: none; } }
.nav-actions { gap: 12px; }

/* ---- dashboards: let the (calm) scene glow through the app chrome ------------ */
html.fx-ready:not(.fx-off) .app-shell { background: transparent; }
html.fx-ready:not(.fx-off) .app-side { background: rgba(255,255,255,.66); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); }
html.fx-ready:not(.fx-off) .app-top { background: rgba(255,255,255,.58); backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3); }

/* ---- remaining opaque page heroes / bands: let the themed scene run through the whole page ----------- */
html.fx-ready:not(.fx-off) .subpage-hero,
html.fx-ready:not(.fx-off) .tool-hero { background: color-mix(in srgb, var(--bg-cream) 28%, transparent); }
html.fx-ready:not(.fx-off) .section-lg.alt { background: color-mix(in srgb, var(--bg-white) 55%, transparent); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }

/* ---- one consistent public header: auth pages now carry the standard navbar too ------------------- */
.auth { padding-top: var(--header-height); }
.auth .am-theme, .auth .af-mobrand { display: none; }              /* theme switch + brand already live in the navbar */
.auth-status { padding-top: calc(var(--header-height) + 24px); }
