/*
 * HOPE Health — Global Design System
 * ====================================
 * Single source of truth for base styles, shared animations, and UI components.
 * All 19 pages link to this file. Page-specific overrides live in each page's <style> block.
 *
 * Design Tokens (also in each page's Tailwind config):
 *   Navy        #1a2a1a  Navy-light  #2d4a22  (page-level use only)
 *   Sage        #4A7C59  Sage-dark   #3a6347  (btn-primary hover)
 *   Sage-light  #6B8E23  (page-level use only)
 *   Sand        #e9c46a  Cream       #F5F1E8
 *   Coral       #e76f51  Slate       #64748b  (Tailwind only)
 */

/* =============================================
   Reset & Base
   ============================================= */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'General Sans', system-ui, sans-serif;
  color: #1a2a1a;
  background: #F5F1E8;
  overflow-x: hidden;
}

/* =============================================
   Grain Texture Overlay
   ============================================= */

body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
}

/* =============================================
   Accessibility Utilities
   ============================================= */

/* Skip to main content — visible on focus */
.skip-nav {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 100000;
  padding: 12px 24px;
  background: #1a2a1a;
  color: white;
  font-size: 14px;
  font-weight: 600;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
  transition: top 0.2s ease;
}
.skip-nav:focus {
  top: 0;
}

/* Visually hidden but screen-reader accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion — respect user OS preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* =============================================
   Navigation
   ============================================= */

/* Frosted-glass nav on scroll — targets pill container child */
.nav-scrolled > div:first-child {
  background: rgba(255, 255, 255, 0.97) !important;
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 24px rgba(26, 42, 26, 0.08);
}

/* =============================================
   Animations — Scroll Reveal
   ============================================= */

.reveal {
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.7s cubic-bezier(0.22, 1, 0.36, 1), transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered reveal — children animate in sequence */
.stagger > .reveal:nth-child(1) { transition-delay: 0ms; }
.stagger > .reveal:nth-child(2) { transition-delay: 100ms; }
.stagger > .reveal:nth-child(3) { transition-delay: 200ms; }
.stagger > .reveal:nth-child(4) { transition-delay: 300ms; }
.stagger > .reveal:nth-child(5) { transition-delay: 400ms; }
.stagger > .reveal:nth-child(6) { transition-delay: 500ms; }

/* =============================================
   Animations — Hero Entrance
   ============================================= */

.hero-fade { animation: heroFade 1s cubic-bezier(0.22, 1, 0.36, 1) forwards; opacity: 0; }
.hero-fade-delay { animation: heroFade 1s cubic-bezier(0.22, 1, 0.36, 1) 0.2s forwards; opacity: 0; }
.hero-fade-delay-2 { animation: heroFade 1s cubic-bezier(0.22, 1, 0.36, 1) 0.4s forwards; opacity: 0; }

@keyframes heroFade {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================
   Animations — Organic Shapes
   ============================================= */

/* Organic blob morph */
.blob {
  border-radius: 42% 58% 62% 38% / 38% 42% 58% 62%;
  animation: morph 12s ease-in-out infinite;
}

@keyframes morph {
  0%,  100% { border-radius: 42% 58% 62% 38% / 38% 42% 58% 62%; }
  25%       { border-radius: 52% 48% 38% 62% / 58% 32% 68% 42%; }
  50%       { border-radius: 38% 62% 52% 48% / 42% 58% 42% 58%; }
  75%       { border-radius: 62% 38% 42% 58% / 48% 62% 38% 52%; }
}

/* Floating decorative elements */
.float       { animation: float 6s ease-in-out infinite; }
.float-delay { animation: float 6s ease-in-out 2s infinite; }

@keyframes float {
  0%,  100% { transform: translateY(0px); }
  50%       { transform: translateY(-12px); }
}

/* =============================================
   Components — Buttons
   ============================================= */

/* Primary CTA — sage blue pill with arrow */
.btn-primary {
  background: #4A7C59;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.btn-primary:hover:not(:disabled) {
  background: #3a6347;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(74, 124, 89, 0.3);
}
.btn-primary .btn-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: background 0.3s ease;
}
.btn-primary:hover .btn-arrow {
  background: rgba(255,255,255,0.3);
}

/* Secondary CTA — outlined / ghost */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.btn-secondary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(26, 42, 26, 0.15);
}

/* =============================================
   Components — Cards
   ============================================= */

/* Hover lift — used on feature / info cards */
.card-lift {
  transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.card-lift:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(26, 42, 26, 0.08);
}

/* Treatment card — gradient top-border on hover */
.treatment-card {
  position: relative;
  overflow: hidden;
}
.treatment-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #4A7C59, #e9c46a, #e76f51);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.treatment-card:hover::before {
  opacity: 1;
}

/* =============================================
   Components — FAQ Accordion
   ============================================= */

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.22, 1, 0.36, 1), padding 0.4s ease;
  padding: 0 24px;
}
.faq-item.active .faq-answer {
  max-height: 300px;
  padding: 0 24px 20px;
}
.faq-item.active .faq-icon {
  transform: rotate(45deg);
}
.faq-icon {
  transition: transform 0.3s ease;
}

/* =============================================
   Components — Decorative
   ============================================= */

/* Gradient accent line (sage → sand) */
.accent-line {
  width: 48px;
  height: 3px;
  background: linear-gradient(90deg, #4A7C59, #e9c46a);
  border-radius: 2px;
}

/* Star ratings */
.star { color: #e9c46a; }

/* Animated number counters */
.counter { display: inline-block; }

/* =============================================
   Components — Announcement Banner
   ============================================= */

/* Announcement banner */
.announcement-bar {
  background: #1a2a1a;
  color: rgba(255,255,255,0.9);
  font-size: 0.8125rem;
  text-align: center;
  padding: 10px 24px;
  letter-spacing: 0.01em;
  position: relative;
  z-index: 51;
}
.announcement-bar a {
  color: #e9c46a;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}
.announcement-bar a:hover { color: #fff; }

/* =============================================
   Components — Stats Accent Bars
   ============================================= */

/* Stats with colored accent bars (Ada-style) */
.stat-bar { position: relative; padding-left: 20px; }
.stat-bar::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  height: 48px;
  width: 4px;
  border-radius: 2px;
}
.stat-bar--sage::before { background: #4A7C59; }
.stat-bar--coral::before { background: #e76f51; }
.stat-bar--sand::before { background: #e9c46a; }
.stat-bar--navy::before { background: #1a2a1a; }

/* =============================================
   Components — Dark Section Utility
   ============================================= */

/* Dark section — trust/compliance blocks */
.section-dark {
  background: #1a2a1a;
  color: #fff;
}
.section-dark .accent-line {
  background: linear-gradient(90deg, #4A7C59, #e9c46a);
}

/* =============================================
   Components — Dot-Grid Background
   ============================================= */

/* Dot-grid pattern (Ada-style CTA bg) */
.dot-grid {
  background-image: radial-gradient(circle, rgba(255,255,255,0.15) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* =============================================
   Components — Scrolling Logo Ticker
   ============================================= */

/* Scrolling logo ticker */
@keyframes ticker {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}
.logo-ticker {
  display: flex;
  overflow: hidden;
  mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
}
.logo-ticker-track {
  display: flex;
  align-items: center;
  gap: 48px;
  animation: ticker 30s linear infinite;
  flex-shrink: 0;
}

/* =============================================
   Components — Footer
   ============================================= */

/* Footer column headers — colored */
.footer-heading {
  color: #4A7C59;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

/* =============================================
   PWA — App Shell Styles
   ============================================= */

/* ── Page Transitions ── */
.pwa-page-enter {
  opacity: 0;
  transform: translateY(8px);
}
.pwa-page-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.pwa-page-exit {
  opacity: 0 !important;
  transform: translateY(-6px) !important;
  transition: opacity 0.18s ease, transform 0.18s ease !important;
}

/* ── Bottom Navigation Bar ── */
#pwa-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: none;
  align-items: stretch;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(26, 42, 26, 0.06);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 20px rgba(26, 42, 26, 0.06);
}

@media (max-width: 768px) {
  #pwa-bottom-nav { display: flex; }
  /* Add padding at bottom of page so content isn't hidden behind nav */
  body { padding-bottom: 76px !important; }
  /* Hide footer on mobile in standalone mode */
}

/* In standalone mode, always show bottom nav */
.pwa-standalone #pwa-bottom-nav { display: flex; }
.pwa-standalone body { padding-bottom: 76px !important; }

.pwa-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 16px;
  text-decoration: none;
  color: #64748b;
  transition: color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.pwa-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.pwa-nav-label {
  font-family: 'General Sans', system-ui, sans-serif;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.pwa-nav-active {
  color: #4A7C59;
}
.pwa-nav-active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: #4A7C59;
  border-radius: 0 0 2px 2px;
}

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

/* ── Install Banner ── */
#pwa-install-banner {
  position: fixed;
  bottom: 80px;
  left: 12px;
  right: 12px;
  z-index: 10000;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

#pwa-install-banner.pwa-install-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.pwa-install-inner {
  background: white;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(26, 42, 26, 0.12), 0 2px 8px rgba(26, 42, 26, 0.06);
  border: 1px solid rgba(26, 42, 26, 0.06);
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pwa-install-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-install-action-btn {
  padding: 8px 18px;
  background: #4A7C59;
  color: white;
  border: none;
  border-radius: 9999px;
  font-family: 'General Sans', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, transform 0.15s;
}
.pwa-install-action-btn:active { transform: scale(0.96); background: #3a6347; }

.pwa-dismiss-action-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.pwa-dismiss-action-btn:active { background: rgba(0,0,0,0.04); }

/* ── Pull to Refresh Indicator ── */
#pwa-pull-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-40px);
  z-index: 10001;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(26, 42, 26, 0.12);
  transition: opacity 0.3s ease;
  opacity: 0;
}

.pwa-pull-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(74, 124, 89, 0.2);
  border-top-color: #4A7C59;
  border-radius: 50%;
  animation: pwa-spin 0.6s linear infinite;
}

@keyframes pwa-spin {
  to { transform: rotate(360deg); }
}

/* ── Connectivity Toast ── */
.pwa-toast {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 10002;
  padding: 10px 20px;
  border-radius: 9999px;
  font-family: 'General Sans', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.pwa-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.pwa-toast-online {
  background: #4A7C59;
  color: white;
}

.pwa-toast-offline {
  background: #e76f51;
  color: white;
}

/* ── Standalone Mode Adjustments ── */
.pwa-standalone {
  /* Account for iOS notch / status bar */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

.pwa-standalone body {
  padding-top: var(--sat);
  padding-bottom: calc(76px + var(--sab));
}

/* In standalone mode, adjust top nav for status bar */
.pwa-standalone nav[style*="position: fixed"],
.pwa-standalone nav[style*="position:fixed"],
.pwa-standalone .announcement-bar {
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
}

/* ── Touch Feedback ── */
@media (hover: none) and (pointer: coarse) {
  /* Native-feel tap states */
  a, button {
    -webkit-tap-highlight-color: transparent;
  }

  .btn-primary:active {
    transform: scale(0.97) !important;
    transition-duration: 0.1s !important;
  }

  .btn-secondary:active {
    transform: scale(0.97) !important;
    transition-duration: 0.1s !important;
  }

  .card-lift:active {
    transform: scale(0.98) !important;
    transition-duration: 0.1s !important;
  }
}

/* ── Mobile-First Scroll Snap (dashboard views) ── */
@media (max-width: 768px) {
  .pwa-standalone .announcement-bar {
    display: none;
  }

  /* Smoother scrolling on iOS */
  main, [role="main"], .overflow-y-auto {
    -webkit-overflow-scrolling: touch;
  }

  /* Prevent text selection on nav elements */
  #pwa-bottom-nav {
    -webkit-user-select: none;
    user-select: none;
  }
}
