/* ============================================
   BROWSER COMPATIBILITY & DEBUGGING FIXES
   Rise Above Partners - Complete Audit Fixes
   ============================================ */

/* ===========================================
   1. BROWSER COMPATIBILITY FIXES
   =========================================== */

/* Safari-specific fixes */
@supports (-webkit-backdrop-filter: blur(1px)) {
  .hero-overlay,
  .glass-effect,
  .grant-card,
  .filter-tag {
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
  }
}

/* Firefox button appearance fix */
button,
.btn,
input[type="submit"],
input[type="button"] {
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

/* Edge/IE11 Flexbox fixes */
.navbar,
.hero-cta-group,
.grants-grid {
  display: -ms-flexbox;
  display: flex;
}

/* Smooth scroll polyfill for Safari */
@supports not (scroll-behavior: smooth) {
  html {
    scroll-behavior: auto;
  }
}

/* ===========================================
   2. MOBILE RESPONSIVENESS FIXES
   =========================================== */

/* Small Mobile (320px) */
@media (max-width: 320px) {
  .container {
    padding: 0 1rem;
  }
  
  .hero h1 {
    font-size: 1.75rem;
    line-height: 1.2;
  }
  
  .btn {
    padding: 0.875rem 1.5rem !important;
    font-size: 0.875rem;
    min-height: 44px; /* iOS touch target */
    min-width: 44px;
  }
  
  .nav-links {
    padding: 1rem;
  }
  
  .grant-card {
    padding: 1.5rem !important;
  }
  
  .filter-tag {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.75rem;
  }
}

/* iPhone Standard (375px) */
@media (min-width: 321px) and (max-width: 375px) {
  .container {
    padding: 0 1.25rem;
  }
  
  .hero h1 {
    font-size: 2rem;
  }
  
  .btn {
    padding: 1rem 1.75rem !important;
    min-height: 48px; /* Better touch target */
  }
  
  .grant-card {
    padding: 1.75rem !important;
  }
}

/* Touch Target Improvements for All Mobile */
@media (max-width: 768px) {
  /* Ensure all interactive elements meet 44x44px minimum */
  a, button, .btn, .filter-tag, .faq-toggle {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Improve tap spacing */
  .nav-links a {
    padding: 1rem;
    margin: 0.25rem 0;
  }
  
  /* Fix mobile menu close button */
  .menu-toggle {
    width: 48px;
    height: 48px;
    padding: 12px;
  }
}

/* ===========================================
   3. CRITICAL FUNCTIONALITY FIXES
   =========================================== */

/* Fix Header Height Consistency */
header {
  height: 84px;
  position: fixed;
  top: 0;
  z-index: 1000;
}

@media (min-width: 769px) {
  header {
    height: 100px;
  }
}

/* Fix Button Clickability in Hero Sections */
.hero .btn,
.hero-cta-group .btn {
  position: relative;
  z-index: 10;
  pointer-events: auto !important;
  cursor: pointer !important;
}

.hero-overlay,
.hero-background {
  pointer-events: none !important;
  z-index: 1;
}

/* Fix Smooth Scroll Anchor Offsets */
html {
  scroll-padding-top: 84px; /* Mobile header height */
}

@media (min-width: 769px) {
  html {
    scroll-padding-top: 100px; /* Desktop header height */
  }
}

/* Target sections for proper spacing */
section:target::before {
  content: "";
  display: block;
  height: 84px;
  margin-top: -84px;
}

@media (min-width: 769px) {
  section:target::before {
    height: 100px;
    margin-top: -100px;
  }
}

/* Fix Mobile Menu Toggle Animation */
.menu-toggle span {
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
  transform: translateX(20px);
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* Fix Z-index Stacking Conflicts */
.header { z-index: 1000; }
.menu-toggle { z-index: 1001; }
.nav-links.active { z-index: 999; }
.hero-overlay { z-index: 1; }
.hero-content { z-index: 2; }
.btn { z-index: 10; }
.featured-badge { z-index: 11; }

/* ===========================================
   4. PERFORMANCE OPTIMIZATIONS
   =========================================== */

/* Optimize Font Loading */
@font-face {
  font-family: 'Montserrat';
  font-display: swap; /* Show fallback immediately */
  font-weight: 500 600;
}

/* Lazy Loading Enhancement */
img[loading="lazy"] {
  background: #f0f0f0; /* Placeholder color */
}

/* Reduce Paint Areas */
.grant-card,
.filter-tag,
.btn {
  will-change: transform;
}

.grant-card:hover,
.filter-tag:hover,
.btn:hover {
  will-change: auto;
}

/* ===========================================
   5. SPECIFIC PAGE FIXES
   =========================================== */

/* Index.html - Hero CTA Group Mobile Fix */
@media (max-width: 768px) {
  .hero-cta-group {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .hero-cta-group .btn {
    width: 100%;
    max-width: 280px;
  }
}

/* Services.html - Timeline Mobile Fix */
@media (max-width: 768px) {
  .timeline-container {
    padding-left: 0;
  }
  
  .timeline-step::before {
    display: none; /* Remove line on mobile */
  }
  
  .timeline-content {
    margin-left: 0;
    padding: 1.5rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
}

/* Grants.html - Dynamic Content Loading Fix */
.loading-spinner {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Loading state for grants */
#grants-container:empty::after {
  content: "Loading grants...";
  display: block;
  text-align: center;
  padding: 2rem;
  color: #666;
}

/* Contact.html - Tally Form Embed Fix */
iframe[src*="tally.so"] {
  width: 100% !important;
  min-height: 500px;
  border: none;
}

/* ===========================================
   6. CRITICAL BUG FIXES
   =========================================== */

/* Fix Horizontal Scroll on Mobile */
body {
  overflow-x: hidden;
}

.container {
  max-width: 100%;
  overflow-x: hidden;
}

/* Fix Grant Cards Grid on Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .grants-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Fix FAQ Toggle Click Area */
.faq-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 1rem;
}

/* Fix Navigation Active States */
.nav-links a.nav-active {
  color: var(--primary);
  font-weight: 600;
}

.nav-links a.nav-active::after {
  content: '';
  display: block;
  width: 100%;
  height: 2px;
  background: var(--primary);
  margin-top: 0.25rem;
}

/* ===========================================
   7. ACCESSIBILITY IMPROVEMENTS
   =========================================== */

/* Focus Visible for Keyboard Navigation */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Skip to Content Link */
.skip-to-content {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
}

.skip-to-content:focus {
  left: 50%;
  transform: translateX(-50%);
  padding: 1rem 2rem;
  background: var(--primary);
  color: white;
}

/* ===========================================
   8. PRINT STYLES
   =========================================== */

@media print {
  header, footer, .hero-overlay, .btn {
    display: none;
  }
  
  .container {
    max-width: 100%;
  }
  
  a {
    text-decoration: none;
    color: black;
  }
}

/* ===========================================
   9. REDUCE MOTION SUPPORT
   =========================================== */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================================
   10. HIGH CONTRAST MODE SUPPORT
   =========================================== */

@media (prefers-contrast: high) {
  .btn-primary {
    background: var(--primary);
    color: white;
    border: 2px solid white;
  }
  
  .grant-card {
    border: 2px solid black;
  }
}