/* ============================================================================
   RICH-LINKS.CSS - Styles for YouTube, TikTok, Instagram embeds
   ============================================================================ */

/* ================== RICH LINK PREVIEW IN CHAT ================== */
.rich-links-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

.rich-link-preview {
  width: 100%;
  max-width: 280px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  background: var(--surface);
  border: 1px solid var(--border);
}

.rich-link-preview:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.rich-link-preview:active {
  transform: scale(0.98);
}

.rich-link-inner {
  position: relative;
  width: 100%;
}

/* Thumbnail area */
.rich-link-thumb {
  width: 100%;
  height: 158px; /* 16:9 aspect ratio for 280px width */
  background-size: cover;
  background-position: center;
  background-color: var(--surface);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Placeholder backgrounds for platforms without thumbnails */
.rich-link-placeholder {
  background: linear-gradient(135deg, var(--surface) 0%, var(--panel) 100%);
}

.rich-link-placeholder[data-platform="tiktok"] {
  background: linear-gradient(135deg, #010101 0%, #25F4EE 50%, #FE2C55 100%);
}

.rich-link-placeholder[data-platform="instagram"] {
  background: linear-gradient(135deg, #405DE6 0%, #5851DB 20%, #833AB4 40%, #C13584 60%, #E1306C 80%, #FD1D1D 100%);
}

.rich-link-placeholder[data-platform="youtube"] {
  background: linear-gradient(135deg, #FF0000 0%, #CC0000 100%);
}

/* Play button overlay */
.rich-link-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}

.rich-link-preview:hover .rich-link-play {
  background: rgba(0, 0, 0, 0.85);
  transform: translate(-50%, -50%) scale(1.1);
}

.rich-link-play svg {
  margin-left: 4px; /* Optical centering for play icon */
}

/* Platform badge */
.rich-link-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rich-link-icon {
  font-size: 14px;
  line-height: 1;
}

.rich-link-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Platform-specific colors */
.rich-link-youtube .rich-link-badge {
  background: rgba(255, 0, 0, 0.9);
}

.rich-link-tiktok .rich-link-badge {
  background: rgba(0, 0, 0, 0.9);
}

.rich-link-instagram .rich-link-badge {
  background: linear-gradient(135deg, #E4405F 0%, #C13584 100%);
}

/* ================== RICH LINK MODAL ================== */
.rich-link-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.75);
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden !important;
}

.rich-link-modal.show {
  opacity: 1;
  visibility: visible;
}

.rich-link-container {
  background: #1a1a1a;
  border-radius: 20px;
  box-shadow: 
    0 0 0 1px rgba(255, 255, 255, 0.15),
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 80px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 380px;
  height: 80vh;
  height: 80dvh;
  max-height: 750px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.3s;
  position: relative;
  /* Visible border */
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.rich-link-modal.show .rich-link-container {
  transform: scale(1);
}

/* Close button - floating over content */
.rich-link-modal .modal-close-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.rich-link-modal .modal-close-badge:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.1);
}

.rich-link-modal .modal-close-badge:active {
  transform: scale(0.95);
}

.rich-link-body {
  position: relative;
  background: #000;
  width: 100%;
  height: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 0 0 18px 18px;
}

/* Dark background layer behind iframe */
.rich-link-body::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 0;
}

.rich-link-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  background: #000;
  color-scheme: dark;
  position: relative;
  z-index: 1;
}

/* Custom video player for TikTok */
.rich-link-video {
  width: 100%;
  height: 100%;
  display: none;
  background: #000;
  object-fit: contain;
  border-radius: 16px;
  position: relative;
  z-index: 2;
  /* Prevent iOS fullscreen */
  -webkit-playsinline: true;
}

/* Hide all native controls by default */
.rich-link-video:not([controls])::-webkit-media-controls {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}

.rich-link-video:not([controls])::-webkit-media-controls-panel {
  display: none !important;
}

.rich-link-video:not([controls])::-webkit-media-controls-start-playback-button {
  display: none !important;
}

/* When controls are explicitly enabled, show them */
.rich-link-video[controls]::-webkit-media-controls {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Video overlay - captures taps to prevent iOS native controls */
.rich-link-video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  cursor: pointer;
  display: none;
}

.rich-link-video-overlay.hidden {
  display: none !important;
}

/* Show overlay when video is visible */
.rich-link-modal[data-platform="tiktok"] .rich-link-video-overlay {
  display: block;
}

/* Tap indicator (play/pause icon) */
.video-tap-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-tap-indicator.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* When using custom player, ensure it fills the space */
.rich-link-modal[data-platform="tiktok"] .rich-link-video {
  object-fit: cover;
  border-radius: 16px;
}

.rich-link-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* YouTube gets wider container for horizontal video */
.rich-link-modal[data-platform="youtube"] .rich-link-container {
  max-width: 720px;
  height: auto;
  max-height: 80vh;
  max-height: 80dvh;
  aspect-ratio: 16 / 9;
}

/* TikTok/Instagram stay tall and narrow like the apps */
.rich-link-modal[data-platform="tiktok"] .rich-link-container,
.rich-link-modal[data-platform="instagram"] .rich-link-container {
  max-width: 380px;
  height: 80vh;
  height: 80dvh;
  max-height: 750px;
}

/* ================== ERROR STATE ================== */
.rich-link-error {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #000;
  color: #ffffff;
  padding: 24px;
  text-align: center;
}

.rich-link-error-icon {
  font-size: 56px;
  opacity: 0.7;
}

.rich-link-error-text {
  font-size: 17px;
  font-weight: 600;
  opacity: 0.9;
}

.rich-link-external-btn {
  display: inline-block;
  padding: 14px 32px;
  background: linear-gradient(135deg, #FE2C55 0%, #FF0050 100%);
  color: white;
  text-decoration: none;
  border-radius: 24px;
  font-weight: 700;
  font-size: 15px;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-top: 12px;
  box-shadow: 0 4px 20px rgba(254, 44, 85, 0.4);
}

.rich-link-external-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 30px rgba(254, 44, 85, 0.5);
}

.rich-link-external-btn:active {
  transform: translateY(0) scale(0.98);
}

/* Platform-specific external button colors */
.rich-link-modal[data-platform="youtube"] .rich-link-external-btn {
  background: linear-gradient(135deg, #FF0000 0%, #CC0000 100%);
  box-shadow: 0 4px 20px rgba(255, 0, 0, 0.4);
}

.rich-link-modal[data-platform="youtube"] .rich-link-external-btn:hover {
  box-shadow: 0 8px 30px rgba(255, 0, 0, 0.5);
}

.rich-link-modal[data-platform="instagram"] .rich-link-external-btn {
  background: linear-gradient(135deg, #833AB4 0%, #E4405F 50%, #FCAF45 100%);
  box-shadow: 0 4px 20px rgba(225, 48, 108, 0.4);
}

.rich-link-modal[data-platform="instagram"] .rich-link-external-btn:hover {
  box-shadow: 0 8px 30px rgba(225, 48, 108, 0.5);
}

/* ================== MOBILE OPTIMIZATIONS ================== */
@media (max-width: 640px) {
  .rich-link-preview {
    max-width: 240px;
  }
  
  .rich-link-thumb {
    height: 135px;
  }
  
  .rich-link-play {
    width: 56px;
    height: 56px;
  }
  
  .rich-link-play svg {
    width: 40px;
    height: 40px;
  }
  
  /* Modal stays visible as overlay on mobile too */
  .rich-link-modal {
    padding: 20px;
  }
  
  .rich-link-container {
    border-radius: 16px;
    height: 75vh;
    height: 75dvh;
    max-height: 650px;
  }
  
  .rich-link-modal[data-platform="youtube"] .rich-link-container {
    height: auto;
    max-height: 75vh;
    max-height: 75dvh;
  }
  
  .rich-link-modal[data-platform="tiktok"] .rich-link-container,
  .rich-link-modal[data-platform="instagram"] .rich-link-container {
    max-width: 340px;
    width: 90%;
    height: 75vh;
    height: 75dvh;
    border-radius: 16px;
  }
  
  /* Larger close button on mobile for easier tapping */
  .rich-link-modal .modal-close-badge {
    width: 44px;
    height: 44px;
    font-size: 28px;
    top: 16px;
    right: 16px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  .rich-link-preview {
    max-width: 200px;
  }
  
  .rich-link-thumb {
    height: 112px;
  }
  
  .rich-link-badge {
    padding: 4px 8px;
  }
  
  .rich-link-name {
    font-size: 10px;
  }
}

/* ================== DARK MODE ADJUSTMENTS ================== */
[data-theme="dark"] .rich-link-preview {
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .rich-link-preview:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .rich-link-play {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .rich-link-preview:hover .rich-link-play {
  background: rgba(255, 255, 255, 0.25);
}

/* ================== MESSAGE BUBBLE ADJUSTMENTS ================== */
/* When a message contains only a link, hide the text and show just the preview */
.chat-bubble.link-only {
  padding: 0 !important;
  background: transparent !important;
}

.chat-bubble.link-only .message-text {
  display: none;
}

/* Ensure rich links don't overflow the bubble */
.message-group .rich-links-container {
  max-width: 100%;
}

.message-group.left .rich-link-preview {
  margin-left: 0;
}

.message-group.right .rich-link-preview {
  margin-right: 0;
}
