/*! Social Embeds CSS (editor + frontend)
 * Supports: YouTube, Instagram, Facebook, X/Twitter, TikTok
 */

/* Base container */
.social-embed {
  margin: 1.5rem auto;
  display: block;
  max-width: 550px;
  text-align: center;
  clear: both;
}

/* Alignment classes */
.social-embed.align-left { 
  margin-left: 0; 
  margin-right: auto; 
  text-align: left; 
}
.social-embed.align-center { 
  margin-left: auto; 
  margin-right: auto; 
  text-align: center; 
}
.social-embed.align-right { 
  margin-right: 0; 
  margin-left: auto; 
  text-align: right; 
}

/* Constrain all embed elements */
.social-embed iframe,
.social-embed blockquote,
.social-embed .fb-post,
.social-embed .fb-video,
.social-embed .tiktok-embed,
.social-embed .twitter-tweet,
.social-embed .instagram-media {
  max-width: 100% !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* YouTube 16:9 aspect ratio container */
.ratio-16x9 {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}
.ratio-16x9 > iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* YouTube specific */
.embed-youtube {
  max-width: 100%;
}
.embed-youtube .ratio-16x9 {
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Instagram */
.embed-instagram {
  min-height: 450px;
}
.embed-instagram blockquote.instagram-media {
  margin: 0 auto !important;
  min-width: 326px;
  max-width: 540px !important;
  width: 100% !important;
  background: #FFF;
  border: 1px solid #dbdbdb;
  border-radius: 4px;
  box-shadow: none;
}

/* X/Twitter */
.embed-x {
  min-height: 200px;
}
.embed-x blockquote.twitter-tweet {
  margin: 0 auto !important;
  max-width: 550px !important;
}
/* Override Twitter widget inline styles */
.twitter-tweet-rendered {
  margin: 0 auto !important;
}

/* Facebook */
.embed-facebook {
  min-height: 200px;
}
.embed-facebook .fb-post,
.embed-facebook .fb-video {
  margin: 0 auto !important;
  max-width: 550px;
}
/* Facebook SDK iframe overrides */
.fb_iframe_widget {
  display: block !important;
  margin: 0 auto !important;
}
.fb_iframe_widget > span {
  display: block !important;
  max-width: 100% !important;
}
.fb_iframe_widget iframe {
  max-width: 100% !important;
}

/* TikTok */
.embed-tiktok {
  min-height: 600px;
}
.embed-tiktok blockquote.tiktok-embed {
  margin: 0 auto !important;
  max-width: 605px !important;
  min-width: 325px;
}

/* Loading state - show placeholder before scripts load */
.social-embed blockquote:not(:empty):before {
  content: "";
  display: block;
  width: 40px;
  height: 40px;
  margin: 20px auto;
  border: 3px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: social-embed-spin 0.8s linear infinite;
}
.social-embed blockquote iframe ~ *:before,
.social-embed blockquote:has(iframe):before {
  display: none;
}

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

/* Legacy lb-embed container support */
figure.lb-embed-container {
  margin: 1.5rem auto;
  display: block;
  max-width: 550px;
  text-align: center;
}
figure.lb-embed-container .lb-embed {
  display: block;
}
figure.lb-embed-container .lb-embed a {
  color: #3b82f6;
  text-decoration: underline;
}

/* When embed is rendered, hide the raw link */
figure.lb-embed-container:has(.twitter-tweet) .lb-embed a,
figure.lb-embed-container:has(.instagram-media) .lb-embed a,
figure.lb-embed-container:has(.fb-post) .lb-embed a,
figure.lb-embed-container:has(.fb-video) .lb-embed a,
figure.lb-embed-container:has(.tiktok-embed) .lb-embed a,
figure.lb-embed-container:has(iframe) .lb-embed a {
  display: none;
}

/* Mobile responsive */
@media (max-width: 600px) {
  .social-embed {
    margin: 1rem auto;
    max-width: 100%;
  }
  
  .embed-instagram {
    min-height: 400px;
  }
  
  .embed-tiktok {
    min-height: 500px;
  }
  
  .embed-instagram blockquote.instagram-media,
  .embed-tiktok blockquote.tiktok-embed {
    min-width: 280px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .social-embed blockquote:not(:empty):before {
    border-color: #374151;
    border-top-color: #60a5fa;
  }
}
