/* HIDE OLD / YELLOW FLOATING DONATE BUTTONS */
.donate-btn,
.donate-float,
.floating-donate,
.floating-donate-btn-old,
.btn-donate,
.campaign-donate-float,
a[href*="/donate/"].floating,
a[href*="/donate/"].donate-btn {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}


/* NEW BLUE FLOATING DONATE BUTTON */
.floating-donate-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  min-width: 140px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
  color: #ffffff !important;
  background: linear-gradient(135deg, #1f46d8, #315df3, #1f46d8);
  background-size: 200% 200%;
  box-shadow:
    0 10px 25px rgba(37, 71, 208, 0.35),
    0 0 0 rgba(37, 71, 208, 0.0);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    filter 0.25s ease;
  animation:
    donateGradientMove 4s ease infinite,
    donatePulse 2s ease-in-out infinite;
}

/* SHINE SWEEP */
.floating-donate-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -75%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    120deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,0.18) 45%,
    rgba(255,255,255,0.55) 50%,
    rgba(255,255,255,0.18) 55%,
    rgba(255,255,255,0) 100%
  );
  transform: skewX(-25deg);
  pointer-events: none;
  animation: donateShine 3s ease-in-out infinite;
  border-radius: 999px;
}

/* KEEP TEXT ABOVE SHINE */
.floating-donate-btn {
  overflow: hidden;
}

.floating-donate-btn:hover,
.floating-donate-btn:focus {
  transform: translateY(-3px) scale(1.03);
  filter: brightness(1.05);
  box-shadow:
    0 14px 32px rgba(37, 71, 208, 0.45),
    0 0 22px rgba(49, 93, 243, 0.35);
  color: #ffffff !important;
}

/* MOBILE */
@media (max-width: 768px) {
  .floating-donate-btn {
    right: 14px;
    bottom: 14px;
    padding: 12px 18px;
    min-width: 120px;
    font-size: 16px;
  }
}

/* ANIMATIONS */
@keyframes donateGradientMove {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes donatePulse {
  0% {
    box-shadow:
      0 10px 25px rgba(37, 71, 208, 0.35),
      0 0 0 0 rgba(49, 93, 243, 0.30);
  }
  70% {
    box-shadow:
      0 10px 25px rgba(37, 71, 208, 0.35),
      0 0 0 14px rgba(49, 93, 243, 0.00);
  }
  100% {
    box-shadow:
      0 10px 25px rgba(37, 71, 208, 0.35),
      0 0 0 0 rgba(49, 93, 243, 0.00);
  }
}

@keyframes donateShine {
  0% {
    left: -75%;
  }
  60% {
    left: 130%;
  }
  100% {
    left: 130%;
  }
}
.floating-donate-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  padding: 14px 24px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
  color: #fff !important;
  background: linear-gradient(135deg, #1f46d8, #3c6cff, #1f46d8);
  background-size: 200% 200%;
  box-shadow:
    0 10px 28px rgba(31, 70, 216, 0.38),
    0 0 0 0 rgba(60, 108, 255, 0.38);
  transition: transform 0.25s ease, box-shadow 0.25s ease, filter 0.25s ease;
  animation: donateGradientMove 4s ease infinite, donatePulse 2s ease-in-out infinite;
  overflow: hidden;
}

.floating-donate-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -80%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    120deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,0.12) 40%,
    rgba(255,255,255,0.55) 50%,
    rgba(255,255,255,0.12) 60%,
    rgba(255,255,255,0) 100%
  );
  transform: skewX(-25deg);
  pointer-events: none;
  animation: donateShine 3.2s ease-in-out infinite;
  border-radius: 999px;
}

.floating-donate-btn:hover,
.floating-donate-btn:focus {
  transform: translateY(-3px) scale(1.03);
  color: #fff !important;
  filter: brightness(1.05);
  box-shadow:
    0 16px 34px rgba(31, 70, 216, 0.48),
    0 0 24px rgba(60, 108, 255, 0.42);
}

@media (max-width: 768px) {
  .floating-donate-btn {
    right: 14px;
    bottom: 14px;
    min-width: 125px;
    padding: 12px 18px;
    font-size: 16px;
  }
}

@keyframes donateGradientMove {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes donatePulse {
  0% {
    box-shadow:
      0 10px 28px rgba(31, 70, 216, 0.38),
      0 0 0 0 rgba(60, 108, 255, 0.34);
  }
  70% {
    box-shadow:
      0 10px 28px rgba(31, 70, 216, 0.38),
      0 0 0 16px rgba(60, 108, 255, 0);
  }
  100% {
    box-shadow:
      0 10px 28px rgba(31, 70, 216, 0.38),
      0 0 0 0 rgba(60, 108, 255, 0);
  }
}

@keyframes donateShine {
  0% { left: -80%; }
  60% { left: 135%; }
  100% { left: 135%; }
}
a[href*="/donate/"] {
  display: none !important;
}
.mobile-menu[hidden] {
  display: none !important;
}

.mobile-menu {
  padding: 16px 0 20px;
}

.mobile-menu .mobile-nav-links,
.mobile-menu .nav-links {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-menu .mobile-nav-links a,
.mobile-menu .nav-links a {
  text-decoration: none;
  font-weight: 700;
  color: inherit;
}

.mobile-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

@media (min-width: 901px) {
  .mobile-toggle,
  .mobile-menu {
    display: none !important;
  }
}
(function(){
  const cfg = window.CAMPAIGN_CONFIG || {};
  const mobileToggle = document.querySelector('.mobile-toggle');
  const mobileMenu = document.querySelector('.mobile-menu');
  if(mobileToggle && mobileMenu){
    mobileToggle.addEventListener('click', ()=>{
      mobileMenu.classList.toggle('show');
      mobileToggle.setAttribute('aria-expanded', mobileMenu.classList.contains('show') ? 'true' : 'false');
    });
  }

  document.querySelectorAll('[data-phone]').forEach(el=>{
    if(cfg.phoneDisplay){ el.textContent = cfg.phoneDisplay; }
    if(cfg.phoneHref){ el.setAttribute('href', cfg.phoneHref); }
  });
  document.querySelectorAll('[data-website]').forEach(el=>{
    if(cfg.websiteUrl){ el.textContent = cfg.websiteUrl.replace(/^https?:\/\//,''); el.setAttribute('href', cfg.websiteUrl); }
  });
  document.querySelectorAll('[data-paid-for-by]').forEach(el=>{
    if(cfg.paidForBy){ el.textContent = cfg.paidForBy; }
  });
  document.querySelectorAll('[data-donate-email]').forEach(el=>{
    const to = cfg.donateEmail || cfg.generalEmail || '';
    if(to){ el.setAttribute('href', 'mailto:' + to); }
  });

  const donateButtons = document.querySelectorAll('[data-donate-link]');
  donateButtons.forEach(btn=>{
    if(cfg.donateUrl){
      btn.setAttribute('href', cfg.donateUrl);
      btn.setAttribute('target', '_blank');
      btn.setAttribute('rel', 'noopener');
    }else{
      btn.addEventListener('click', function(e){
        e.preventDefault();
        const subject = encodeURIComponent('Donation for ' + (cfg.candidateName || 'the campaign'));
        const body = encodeURIComponent('I would like to support the campaign. Please send me the donation link and instructions.\n\nName:\nPhone:\nPreferred amount:\n');
        window.location.href = 'mailto:' + (cfg.donateEmail || cfg.generalEmail || '') + '?subject=' + subject + '&body=' + body;
      });
    }
  });

  document.querySelectorAll('[data-generic-link="endorse"]').forEach(btn=>{
    if(cfg.endorsementFormUrl){
      btn.setAttribute('href', cfg.endorsementFormUrl);
      btn.setAttribute('target', '_blank');
      btn.setAttribute('rel', 'noopener');
    }else{
      btn.addEventListener('click', function(e){
        e.preventDefault();
        const subject = encodeURIComponent('Endorsement for ' + (cfg.candidateName || 'the campaign'));
        const body = encodeURIComponent('I would like to endorse the campaign.\n\nName:\nOrganization (if any):\nPhone:\nEmail:\nShort endorsement quote:\n');
        window.location.href = 'mailto:' + (cfg.endorsementEmail || cfg.generalEmail || '') + '?subject=' + subject + '&body=' + body;
      });
    }
  });

  document.querySelectorAll('[data-generic-link="volunteer"]').forEach(btn=>{
    if(cfg.volunteerFormUrl){
      btn.setAttribute('href', cfg.volunteerFormUrl);
      btn.setAttribute('target', '_blank');
      btn.setAttribute('rel', 'noopener');
    }else{
      btn.addEventListener('click', function(e){
        e.preventDefault();
        const subject = encodeURIComponent('Volunteer for ' + (cfg.candidateName || 'the campaign'));
        const body = encodeURIComponent('I would like to volunteer.\n\nName:\nPhone:\nEmail:\nAvailability:\nWays I can help:\n');
        window.location.href = 'mailto:' + (cfg.volunteerEmail || cfg.generalEmail || '') + '?subject=' + subject + '&body=' + body;
      });
    }
  });

  document.querySelectorAll('form[data-mailto]').forEach(form=>{
    form.addEventListener('submit', function(e){
      e.preventDefault();
      const type = form.getAttribute('data-mailto');
      const data = new FormData(form);
      const obj = {};
      data.forEach((v,k)=> obj[k]=v);
      let to = cfg.generalEmail || '';
      let subject = '';
      let lines = [];
      if(type === 'donate'){
        to = cfg.donateEmail || cfg.generalEmail || '';
        subject = 'Donation inquiry for ' + (cfg.candidateName || 'the campaign');
        lines = [
          'Name: ' + (obj.name || ''),
          'Email: ' + (obj.email || ''),
          'Phone: ' + (obj.phone || ''),
          'Preferred amount: ' + (obj.amount || ''),
          'Recurring?: ' + (obj.recurring || ''),
          'Employer / occupation: ' + (obj.compliance || ''),
          'Message: ' + (obj.message || '')
        ];
      } else if(type === 'endorse'){
        to = cfg.endorsementEmail || cfg.generalEmail || '';
        subject = 'Endorsement submission for ' + (cfg.candidateName || 'the campaign');
        lines = [
          'Name: ' + (obj.name || ''),
          'Organization: ' + (obj.organization || ''),
          'Title/Role: ' + (obj.role || ''),
          'Email: ' + (obj.email || ''),
          'Phone: ' + (obj.phone || ''),
          'Permission to publish name?: ' + (obj.publish || ''),
          'Endorsement quote: ' + (obj.quote || '')
        ];
      } else if(type === 'general') {
        to = cfg.generalEmail || '';
        subject = (obj.topic || 'Campaign inquiry') + ' for ' + (cfg.candidateName || 'the campaign');
        lines = [
          'Name: ' + (obj.name || ''),
          'Email: ' + (obj.email || ''),
          'Phone: ' + (obj.phone || ''),
          'Topic: ' + (obj.topic || ''),
          'Message: ' + (obj.message || '')
        ];
      } else {
        to = cfg.volunteerEmail || cfg.generalEmail || '';
        subject = 'Volunteer signup for ' + (cfg.candidateName || 'the campaign');
        lines = [
          'Name: ' + (obj.name || ''),
          'Email: ' + (obj.email || ''),
          'Phone: ' + (obj.phone || ''),
          'Neighborhood / precinct: ' + (obj.location || ''),
          'Availability: ' + (obj.availability || ''),
          'Ways to help: ' + (obj.help || ''),
          'Message: ' + (obj.message || '')
        ];
      }
      window.location.href = 'mailto:' + to + '?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(lines.join('\n'));
    });
  });

  document.querySelectorAll('[data-amount]').forEach(btn=>{
    btn.addEventListener('click', function(){
      const amount = btn.getAttribute('data-amount');
      const input = document.querySelector('input[name="amount"]');
      if(input){ input.value = amount; input.focus(); }
      const target = document.querySelector('#donate-form');
      if(target){ window.scrollTo({top: target.offsetTop - 90, behavior:'smooth'}); }
    });
  });
})();


document.addEventListener('DOMContentLoaded', function () {
  var fill = document.querySelector('.progress-fill');
  if (fill) {
    var pct = parseInt(fill.getAttribute('data-progress') || '0', 10);
    window.setTimeout(function(){ fill.style.width = pct + '%'; }, 300);
  }

  var slider = document.getElementById('endorsementSlider');
  var prev = document.getElementById('prevEndorsement');
  var next = document.getElementById('nextEndorsement');

  if (slider && prev && next) {
    prev.addEventListener('click', function(){ slider.scrollBy({ left: -360, behavior: 'smooth' }); });
    next.addEventListener('click', function(){ slider.scrollBy({ left: 360, behavior: 'smooth' }); });
  }

  var popup = document.getElementById('campaignPopup');
  var closeBtn = document.getElementById('closeCampaignPopup');

  if (popup && !sessionStorage.getItem('campaign_popup_seen')) {
    window.setTimeout(function(){
      popup.classList.add('active');
      sessionStorage.setItem('campaign_popup_seen', '1');
    }, 3500);
  }

  if (closeBtn) {
    closeBtn.addEventListener('click', function(){
      popup.classList.remove('active');
    });
  }

  if (popup) {
    popup.addEventListener('click', function(e){
      if (e.target === popup) popup.classList.remove('active');
    });
  }
});
document.addEventListener('DOMContentLoaded', function () {
  const toggle = document.querySelector('.mobile-toggle');
  const menu = document.getElementById('mobile-menu');

  if (!toggle || !menu) return;

  toggle.addEventListener('click', function () {
    const isOpen = toggle.getAttribute('aria-expanded') === 'true';

    toggle.setAttribute('aria-expanded', String(!isOpen));

    if (isOpen) {
      menu.setAttribute('hidden', '');
    } else {
      menu.removeAttribute('hidden');
    }
  });
});
