/**
 * Rich Media Components CSS
 * Styling for images, videos, charts, and other media in chat
 */

/* ============================================
   Base Rich Media Container
   ============================================ */
.rich-media-container {
  margin: 12px 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bs-light);
  border: 1px solid var(--bs-border-color);
}

/* ============================================
   Image Components
   ============================================ */
.rich-media-image-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.rich-media-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.rich-media-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.rich-media-image-wrapper:hover .rich-media-overlay {
  opacity: 1;
}

.rich-media-zoom,
.rich-media-download {
  background: rgba(255, 255, 255, 0.9) !important;
  backdrop-filter: blur(4px);
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.rich-media-zoom:hover,
.rich-media-download:hover {
  background: rgba(255, 255, 255, 1) !important;
  transform: scale(1.05);
}

/* ============================================
   Image Grid
   ============================================ */
.rich-media-grid {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.rich-media-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.rich-media-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.rich-media-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
  .rich-media-grid-3,
  .rich-media-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .rich-media-grid-2,
  .rich-media-grid-3,
  .rich-media-grid-4 {
    grid-template-columns: 1fr;
  }
}

.rich-media-grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
}

.rich-media-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ============================================
   Screenshot Component
   ============================================ */
.rich-media-screenshot {
  background: white;
}

.rich-media-screenshot-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bs-light);
  border-bottom: 1px solid var(--bs-border-color);
  font-size: 0.875rem;
}

.rich-media-screenshot-header code {
  margin-left: auto;
  font-size: 0.75rem;
  background: var(--bs-secondary-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.rich-media-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bs-light);
  border-top: 1px solid var(--bs-border-color);
}

/* ============================================
   Video Components
   ============================================ */
.rich-media-video {
  width: 100%;
  max-height: 500px;
  display: block;
  background: black;
}

.rich-media-youtube {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
}

.rich-media-youtube-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ============================================
   Chart Components
   ============================================ */
.rich-media-chart-wrapper {
  padding: 16px;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
}

.rich-media-chart-wrapper canvas {
  max-width: 100%;
  height: auto !important;
}

/* ============================================
   Mermaid Diagrams
   ============================================ */
.rich-media-mermaid-wrapper {
  padding: 16px;
  background: white;
  overflow-x: auto;
}

.rich-media-mermaid-wrapper .mermaid {
  display: flex;
  justify-content: center;
}

.rich-media-mermaid-wrapper svg {
  max-width: 100%;
  height: auto;
}

/* ============================================
   File Attachments
   ============================================ */
.rich-media-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: white;
}

.rich-media-file > i {
  font-size: 2rem;
  color: var(--bs-primary);
}

.rich-media-file-info {
  flex: 1;
  min-width: 0;
}

.rich-media-file-info strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rich-media-file-info small {
  display: inline-block;
  margin-right: 8px;
}

/* ============================================
   Caption
   ============================================ */
.rich-media-caption {
  padding: 8px 12px;
  font-size: 0.875rem;
  color: var(--bs-secondary);
  background: var(--bs-light);
  border-top: 1px solid var(--bs-border-color);
  font-style: italic;
}

/* ============================================
   Error State
   ============================================ */
.rich-media-error .alert {
  margin: 8px;
}

/* ============================================
   Lightbox
   ============================================ */
.rich-media-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rich-media-lightbox-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}

.rich-media-lightbox-content {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rich-media-lightbox-content img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.rich-media-lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: background 0.2s;
}

.rich-media-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
  .rich-media-container {
    margin: 8px 0;
  }

  .rich-media-lightbox-content {
    max-width: 95vw;
    max-height: 95vh;
  }

  .rich-media-youtube {
    padding-bottom: 75%; /* More square on mobile */
  }
}

/* ============================================
   Dark Mode Support
   ============================================ */
body[data-theme="dark"] .rich-media-container {
  background: var(--bg-secondary);
  border-color: var(--border);
}

body[data-theme="dark"] .rich-media-screenshot,
body[data-theme="dark"] .rich-media-chart-wrapper,
body[data-theme="dark"] .rich-media-mermaid-wrapper,
body[data-theme="dark"] .rich-media-file {
  background: var(--bg-secondary);
}

body[data-theme="dark"] .rich-media-screenshot-header,
body[data-theme="dark"] .rich-media-metadata,
body[data-theme="dark"] .rich-media-caption {
  background: var(--bg-tertiary);
  border-color: var(--border);
  color: var(--text-secondary);
}

body[data-theme="dark"] .rich-media-overlay button {
  background: rgba(0, 0, 0, 0.7) !important;
  color: var(--text-primary);
}

body[data-theme="dark"] .rich-media-overlay button:hover {
  background: rgba(0, 0, 0, 0.9) !important;
}

/* ============================================
   Animation
   ============================================ */
.rich-media-container {
  animation: fadeIn 0.3s ease-out;
}

/* ============================================
   Loading State
   ============================================ */
.rich-media-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: var(--bs-secondary);
}

.rich-media-loading::after {
  content: '';
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--bs-secondary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 8px;
}

