/* ============================================================
   Instagram Manual Embed — Frontend Styles
   ============================================================ */

/* ---------- Wrapper ---------- */
.igm-wrapper {
  --igm-bg:         #ffffff;
  --igm-border:     #dbdbdb;
  --igm-text:       #262626;
  --igm-dim:        #8e8e8e;
  --igm-hashtag:    #003569;
  --igm-radius:     12px;
  --igm-font:       -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --igm-transition: 0.2s ease;
  --igm-callout-bg: #f9f9f9;
  --igm-callout-border: #ebebeb;

  font-family:   var(--igm-font);
  background:    var(--igm-bg);
  border:        1px solid var(--igm-border);
  border-radius: var(--igm-radius);
  overflow:      hidden;
  width:         100%;
  margin:        0 auto 28px;
  box-shadow:    0 1px 4px rgba(0,0,0,.08);
}

.igm-wrapper.igm-dark {
  --igm-bg:             #1a1a1a;
  --igm-border:         #333;
  --igm-text:           #f5f5f5;
  --igm-dim:            #a0a0a0;
  --igm-hashtag:        #7eb3ff;
  --igm-callout-bg:     #242424;
  --igm-callout-border: #333;
  box-shadow: 0 1px 8px rgba(0,0,0,.4);
}

/* ---------- Header ---------- */
.igm-header {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     11px 14px;
  background:  var(--igm-bg);
}

.igm-avatar {
  position:    relative;
  width:       38px;
  height:      38px;
  flex-shrink: 0;
}

.igm-avatar img,
.igm-avatar-placeholder {
  width:         38px;
  height:        38px;
  border-radius: 50%;
  object-fit:    cover;
  display:       block;
}

.igm-avatar-placeholder {
  background:  linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  color:       #fff;
  font-size:   16px;
  font-weight: 700;
  line-height: 38px;
  text-align:  center;
}

.igm-avatar-ring {
  position:      absolute;
  inset:         -2px;
  border-radius: 50%;
  background:    linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  z-index:       -1;
  opacity:       0.85;
}

.igm-handle {
  font-size:   14px;
  font-weight: 600;
  color:       var(--igm-text);
  flex:        1;
}

.igm-ig-logo {
  flex-shrink: 0;
  opacity:     0.9;
  display:     block;
  transition:  opacity var(--igm-transition), transform var(--igm-transition);
}
.igm-ig-logo:hover { opacity:1; transform:scale(1.08); }

/* ---------- Media ---------- */
.igm-media-wrap {
  position:   relative;
  width:      100%;
  background: #000;
  overflow:   hidden;
  line-height: 0;
}

.igm-media-img {
  display:    block;
  width:      100%;
  height:     auto;
  max-height: 90vh;
  object-fit: contain;
  background: #000;
}

/* ---------- Video ---------- */
.igm-video-wrap {
  position: relative;
  width:    100%;
  line-height: 0;
}

.igm-media-video {
  display:    block;
  width:      100%;
  height:     auto;
  max-height: 90vh;
  background: #000;
}

.igm-reel-badge {
  position:       absolute;
  top:            10px;
  right:          10px;
  background:     rgba(0,0,0,.5);
  border-radius:  6px;
  padding:        4px 8px;
  display:        flex;
  align-items:    center;
  pointer-events: none;
}

/* ---------- Carousel ---------- */
.igm-carousel {
  position:     relative;
  overflow:     hidden;
  width:        100%;
  touch-action: pan-y;
  line-height:  0;
}

.igm-slides-track {
  width: 100%;
}

.igm-slide { display: none; }
.igm-slide.igm-slide-active { display: block; }

/* Nav buttons */
.igm-nav {
  position:        absolute;
  top:             50%;
  transform:       translateY(-50%);
  width:           32px;
  height:          32px;
  border-radius:   50%;
  border:          none;
  background:      rgba(255,255,255,.92);
  color:           #262626;
  display:         flex;
  align-items:     center;
  justify-content: center;
  cursor:          pointer;
  z-index:         10;
  box-shadow:      0 2px 8px rgba(0,0,0,.22);
  padding:         0;
  transition:      background var(--igm-transition), transform var(--igm-transition);
}
.igm-nav:hover        { background:rgba(255,255,255,1); transform:translateY(-50%) scale(1.06); }
.igm-nav[disabled]    { display:none; }
.igm-nav-prev         { left:  10px; }
.igm-nav-next         { right: 10px; }

/* Counter */
.igm-counter {
  position:      absolute;
  top:           12px;
  right:         12px;
  background:    rgba(0,0,0,.55);
  color:         #fff;
  font-size:     12px;
  font-weight:   500;
  padding:       3px 9px;
  border-radius: 10px;
  pointer-events: none;
  font-family:   var(--igm-font);
}

/* Dots */
.igm-dots {
  display:         flex;
  justify-content: center;
  gap:             5px;
  padding:         8px 0 2px;
  background:      var(--igm-bg);
  line-height:     normal;
}

.igm-dot {
  width:         6px;
  height:        6px;
  border-radius: 50%;
  background:    var(--igm-border);
  border:        none;
  padding:       0;
  cursor:        pointer;
  transition:    background var(--igm-transition), transform var(--igm-transition);
}
.igm-dot.igm-dot-active { background:#0095f6; transform:scale(1.3); }

/* ---------- Icon row (heart, comment, repost, send ... bookmark) ---------- */
.igm-actions {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  padding:         10px 14px 2px;
  background:      var(--igm-bg);
  line-height:     normal;
}

.igm-actions-left {
  display:     flex;
  align-items: center;
  gap:         14px;
  min-width:   0;
}

.igm-action {
  display:         inline-flex;
  align-items:     center;
  gap:             5px;
  color:           var(--igm-text);
  font-size:       14px;
  font-weight:     600;
  text-decoration: none;
  white-space:     nowrap;
  font-variant-numeric: tabular-nums;
  transition:      opacity var(--igm-transition);
}
.igm-action svg { display: block; flex-shrink: 0; }
a.igm-action:hover { opacity: .65; }

/* ---------- Stats Bar (views line) ---------- */
.igm-stats-bar {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  padding:         6px 14px 2px;
  background:      var(--igm-bg);
  line-height:     normal;
}

.igm-stat-text {
  font-size:  14px;
  color:      var(--igm-text);
}
.igm-stat-text strong {
  font-weight: 700;
}
.igm-stat { white-space: nowrap; }
.igm-stat + .igm-stat::before {
  content: "\00B7";
  margin:  0 7px;
  color:   var(--igm-dim);
}

.igm-share-btn {
  display:         flex;
  align-items:     center;
  gap:             5px;
  font-size:       14px;
  font-weight:     500;
  color:           var(--igm-text);
  text-decoration: none;
  transition:      opacity var(--igm-transition);
}
.igm-share-btn:hover { opacity:.65; }

/* ---------- Caption ---------- */
.igm-caption {
  padding:     4px 14px 6px;
  font-size:   14px;
  line-height: 1.5;
  color:       var(--igm-text);
  background:  var(--igm-bg);
  word-break:  break-word;
}

.igm-caption-handle {
  font-weight:  700;
  margin-right: 5px;
  color:        var(--igm-text);
}

.igm-hashtag { color: var(--igm-hashtag); }
.igm-mention { color: var(--igm-hashtag); }

/* Caption truncation */
.igm-caption.igm-truncated .igm-caption-text {
  display:            -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow:           hidden;
}
.igm-more-btn {
  background:  none;
  border:      none;
  color:       var(--igm-dim);
  font-size:   13px;
  cursor:      pointer;
  padding:     0;
  margin-top:  2px;
  display:     block;
  font-family: var(--igm-font);
}
.igm-more-btn:hover { color: var(--igm-text); }

/* ---------- Date ---------- */
.igm-date {
  padding:        2px 14px 10px;
  font-size:      11px;
  color:          var(--igm-dim);
  background:     var(--igm-bg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Feed outer — carries theme class, wraps card + callout ---------- */
.igm-feed-outer {
  width:     100%;
  margin:    0 auto 28px;
}

/* ---------- Engagement Callout ---------- */
.igm-callouts {
  display:   flex;
  flex-wrap: wrap;
  gap:       4px 16px;
}

.igm-callout {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             12px;
  flex:            1 1 40%;
  min-width:       0;
  padding:         14px 4px 4px;
  background:      transparent;
  border:          none;
  border-radius:   0;
  position:        relative;
}

/* Two or more callouts side by side: slightly smaller so they fit at 480px */
.igm-callouts:not(.igm-callouts-1) .igm-callout-number { font-size: 30px; }
.igm-callouts:not(.igm-callouts-1) .igm-callout-icon   { width: 48px; height: 48px; }

.igm-callout-inner {
  display:        flex;
  flex-direction: column;
  gap:            2px;
}

.igm-callout-number {
  font-size:   36px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Light mode: black number */
.igm-feed-outer.igm-light .igm-callout-number,
.igm-feed-outer.igm-light .igm-callout-label {
  color: #111;
}

/* Dark mode: white number */
.igm-feed-outer.igm-dark .igm-callout-number,
.igm-feed-outer.igm-dark .igm-callout-label {
  color: #fff;
}

/* Reel callout inherits from reel-wrapper theme */
.igm-reel-wrapper.igm-light .igm-callout-number,
.igm-reel-wrapper.igm-light .igm-callout-label { color: #111; }
.igm-reel-wrapper.igm-dark .igm-callout-number,
.igm-reel-wrapper.igm-dark .igm-callout-label  { color: #fff; }

.igm-callout-label {
  font-size:      11px;
  font-weight:    600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.igm-callout-icon {
  width:       60px;
  height:      60px;
  flex-shrink: 0;
  opacity:     1;
}

/* Count-up animation */
.igm-count-up {
  display: inline-block;
  transition: none;
}

/* ---------- Error ---------- */
.igm-error {
  padding:       12px 16px;
  background:    #fff8f8;
  border:        1px solid #fca5a5;
  border-radius: 8px;
  color:         #991b1b;
  font-size:     13px;
  margin-bottom: 16px;
  font-family:   var(--igm-font);
}

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .igm-wrapper {
    border-left:   none;
    border-right:  none;
    border-radius: 0;
    margin-left:   -16px;
    margin-right:  -16px;
    width:         calc(100% + 32px);
    max-width:     none !important;
  }
  .igm-feed-outer { padding: 0 16px; }
  .igm-callout-number { font-size: 28px; }
  .igm-callouts:not(.igm-callouts-1) .igm-callout-number { font-size: 24px; }
  .igm-callouts:not(.igm-callouts-1) .igm-callout-icon   { width: 40px; height: 40px; }
  .igm-actions-left { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .igm-nav, .igm-ig-logo, .igm-share-btn, .igm-dot { transition: none; }
}

/* ============================================================
   Reel Layout (9:16 — format="reel")
   ============================================================ */

.igm-reel-wrapper {
  background:    transparent;
  border:        none;
  box-shadow:    none;
  border-radius: 0;
  max-width:     400px !important;
}

/* The 9:16 frame */
.igm-reel-frame {
  position:      relative;
  width:         100%;
  aspect-ratio:  9 / 16;
  background:    #000;
  border-radius: 16px;
  overflow:      hidden;
}

/* Video or image fills the frame entirely */
.igm-reel-media {
  position:   absolute;
  inset:      0;
  width:      100%;
  height:     100%;
  object-fit: cover;
  display:    block;
}

/* Bottom gradient fade — ensures text legibility over any media */
.igm-reel-overlay {
  position:   absolute;
  inset:      0;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.25) 0%,
    rgba(0,0,0,0)    25%,
    rgba(0,0,0,0)    45%,
    rgba(0,0,0,0.5)  70%,
    rgba(0,0,0,0.82) 100%
  );
  pointer-events: none;
  z-index:        1;
}

/* ---------- Reel header (top) ---------- */
.igm-reel-header {
  position:    absolute;
  top:         14px;
  left:        14px;
  right:       14px;
  display:     flex;
  align-items: center;
  gap:         9px;
  z-index:     10;
}

.igm-reel-avatar {
  width:         34px;
  height:        34px;
  border-radius: 50%;
  flex-shrink:   0;
  overflow:      hidden;
  border:        1.5px solid rgba(255,255,255,.5);
  background:    linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  display:       flex;
  align-items:   center;
  justify-content: center;
  font-size:     14px;
  font-weight:   700;
  color:         #fff;
}

.igm-reel-avatar img {
  width:      100%;
  height:     100%;
  object-fit: cover;
  display:    block;
}

.igm-reel-handle {
  font-size:   13px;
  font-weight: 600;
  color:       #fff;
  flex:        1;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

.igm-reel-type-badge {
  display:      flex;
  align-items:  center;
  gap:          5px;
  background:   rgba(0,0,0,.45);
  border-radius: 6px;
  padding:      3px 9px;
  color:        #fff;
  font-size:    11px;
  font-weight:  600;
}

/* ---------- Reel tap-to-play overlay (no native controls) ---------- */
.igm-reel-tap-overlay {
  position:   absolute;
  inset:      0;
  z-index:    9;   /* below UI chrome (z-index 10) but above video */
  cursor:     pointer;
  outline:    none;
}

/* Centred play/pause flash indicator */
.igm-reel-play-indicator {
  position:        absolute;
  top:             50%;
  left:            50%;
  transform:       translate(-50%, -50%);
  width:           72px;
  height:          72px;
  border-radius:   50%;
  background:      rgba(0,0,0,.45);
  display:         flex;
  align-items:     center;
  justify-content: center;
  opacity:         0;
  transition:      opacity 0.15s ease;
  pointer-events:  none;
}
.igm-reel-play-indicator.igm-indicator-show {
  opacity: 1;
  animation: igm-indicator-fade 0.8s ease forwards;
}
@keyframes igm-indicator-fade {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1);    }
  60%  { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1);    }
}
.igm-reel-sidebar {
  position:        absolute;
  right:           12px;
  bottom:          96px;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  gap:             14px;
  z-index:         10;
}

.igm-reel-action {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  gap:             2px;
  min-height:      44px;
  color:           #fff;
  text-decoration: none;
}
a.igm-reel-action:hover { opacity: .8; }

.igm-reel-action-icon {
  width:           32px;
  height:          32px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  color:           #fff;
  filter:          drop-shadow(0 1px 3px rgba(0,0,0,.6));
}

.igm-reel-action-count {
  font-size:   11px;
  color:       #fff;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  font-variant-numeric: tabular-nums;
}

.igm-reel-ig-logo {
  margin-top: 4px;
  filter:     drop-shadow(0 1px 3px rgba(0,0,0,.4));
}

/* ---------- Reel bottom content ---------- */
.igm-reel-bottom {
  position: absolute;
  bottom:   0;
  left:     0;
  right:    60px;
  padding:  0 14px 18px;
  z-index:  10;
}

.igm-reel-caption {
  font-size:   13px;
  line-height: 1.5;
  color:       #fff;
  word-break:  break-word;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

.igm-reel-caption-handle {
  font-weight:  700;
  margin-right: 5px;
}

.igm-reel-caption-text .igm-hashtag,
.igm-reel-caption-text .igm-mention {
  color: #a8d8ff;
}

.igm-reel-date {
  margin-top:     6px;
  font-size:      10px;
  color:          rgba(255,255,255,.65);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-shadow:    0 1px 3px rgba(0,0,0,.5);
}

/* Play count chip (views) under the caption */
.igm-reel-views {
  display:     inline-flex;
  align-items: center;
  gap:         5px;
  margin-top:  8px;
  font-size:   11px;
  font-weight: 600;
  color:       #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  font-variant-numeric: tabular-nums;
}

/* Callout sits below the reel frame, transparent bg */
.igm-reel-callout {
  margin:      12px 0 0;
  border:      none;
  background:  transparent;
  padding:     14px 4px 4px;
}
.igm-reel-wrapper .igm-callouts:not(.igm-callouts-1) .igm-callout-number { font-size: 26px; }

/* Reel on small screens — full bleed */
@media (max-width: 520px) {
  .igm-reel-wrapper {
    max-width: none !important;
  }
  .igm-reel-frame {
    border-radius: 0;
  }
  .igm-reel-callout {
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}
