/**
 * Link Preview Tooltips - Enhanced Tooltip Styles
 * Screenshot-based link previews for external links
 * Provides rich previews with screenshots, titles, and favicons
 */

 .ce-tooltip {
  position: fixed;
  z-index: 9999;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--ll-bg-primary, #ffffff);
  border: 1px solid var(--ll-border-primary, rgba(0, 0, 0, 0.1));
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  overflow: hidden !important; /* CRITICAL: Ensures border-radius clips children */
}

.ce-tooltip__inner {
  display: flex;
  flex-direction: column;
  /* CRITICAL FIXES: Remove all spacing that creates top gap */
  padding: 0 !important;
  margin: 0 !important;
  line-height: 0 !important; /* Collapses any text nodes between block elements */
}

.ce-tooltip__preview {
  width: 100%;
  height: 171px; /* Reduced by 5% from 180px */
  background: var(--ll-bg-secondary, #f5f5f5);
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--ll-border-primary, rgba(0, 0, 0, 0.1));
  
  /* CRITICAL FIXES: Remove all spacing */
  margin: 0 !important;
  padding: 0 !important;
  display: block !important; /* Ensures proper block layout */
}

.ce-tooltip__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
  
  /* CRITICAL FIXES: Remove all spacing and fix alignment */
  display: block !important; /* Makes image behave as block element */
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  line-height: normal !important; /* Reset any inherited line-height */
}

.ce-tooltip__image.loaded {
  opacity: 1;
}

.ce-tooltip__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ll-bg-secondary, #f5f5f5);
}

.ce-tooltip__spinner {
  color: var(--ll-text-tertiary, rgba(0, 0, 0, 0.4));
  opacity: 0.6;
}

.ce-tooltip__meta {
  /* Adjusted padding: 8px top, 12px bottom, 14px right, 12px left for better visual balance */
  padding: 8px 14px 12px 12px !important;
  
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
  align-items: flex-start;
  background: var(--ll-bg-primary, #ffffff);
  
  /* Reset any inherited spacing */
  margin: 0 !important;
  line-height: normal !important; /* Reset line-height for text content */
}

.ce-tooltip__favicon {
  width: 16px !important;
  height: 16px !important;
  border-radius: 4px;
  flex-shrink: 0;
  
  /* CRITICAL: Override global img margins from style.css */
  margin-top: 0 !important; /* Overrides 24px !important from global stylesheet */
  margin-bottom: 0 !important; /* Overrides 48px from global stylesheet */
  margin-left: 0 !important;
  margin-right: 0 !important;
  
  /* Reset any other global img styles that might interfere */
  border-width: 0 !important;
  padding: 0 !important;
  display: block !important; /* Prevent inline spacing issues - block elements don't use vertical-align */
}

/* Even more specific selector to ensure override of global img styles */
.ce-tooltip .ce-tooltip__favicon,
.ce-tooltip__meta .ce-tooltip__favicon,
img.ce-tooltip__favicon {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  border-width: 0 !important;
  padding: 0 !important;
}

.ce-tooltip__text {
  display: flex;
  flex-direction: column;
  
  /* FIX: Changed gap from 1px to 0 */
  gap: 0 !important;
  
  min-width: 0;
  margin: 0 !important;
  padding: 0 !important;
}

.ce-tooltip__domain {
  font-size: 11px;
  font-weight: 600;
  color: var(--ll-text-tertiary, rgba(0, 0, 0, 0.5));
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
  
  /* FIX: Added controlled margin for spacing */
  margin: 0 0 2px 0 !important;
  padding: 0 !important;
}

.ce-tooltip__title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ll-text-primary, #000000);
  
  /* FIX: Tighter line-height */
  line-height: 1.2 !important;
  
  /* REMOVED: display: -webkit-box; */
  /* REMOVED: -webkit-line-clamp: 2; */
  /* REMOVED: -webkit-box-orient: vertical; */
  
  /* NEW APPROACH: Simple overflow with dynamic height */
  display: block !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  max-height: 2.4em !important; /* 2 lines max (1.2em * 2) */
  
  margin: 0 !important;
  padding: 0 !important;
}

/* Dynamic adjustment when title is only 1 line (applied via JS) */
.ce-tooltip__title[data-lines="1"] {
  max-height: 1.2em !important;
  min-height: 1.2em !important; /* Prevent any minimum height */
  height: 1.2em !important; /* Force exact 1-line height */
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  line-height: 1.2 !important; /* Ensure line-height matches height */
}

/* Dynamic adjustment when title is 2 lines (applied via JS) */
.ce-tooltip__title[data-lines="2"] {
  max-height: 2.4em !important; /* 2 lines max */
  white-space: normal !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
}

/* Enhanced link styling */
a.ce-enhanced {
  position: relative;
}

a.ce-enhanced:hover {
  text-decoration-thickness: 2px;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .ce-tooltip {
    width: 280px;
  }
  
  .ce-tooltip__preview {
    height: 142px; /* Reduced by 5% from 150px */
  }
  
  .ce-tooltip__meta {
    /* Adjusted padding for mobile: slightly smaller but proportional to desktop */
    padding: 8px 12px 12px 10px !important; /* Top, Right, Bottom, Left */
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .ce-tooltip {
    background: #1a1a1a;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  }
  
  .ce-tooltip__preview {
    background: rgba(255, 255, 255, 0.03);
    border-bottom-color: rgba(255, 255, 255, 0.1);
  }
  
  .ce-tooltip__loading {
    background: rgba(255, 255, 255, 0.03);
  }
  
  .ce-tooltip__spinner {
    color: rgba(255, 255, 255, 0.4);
  }
  
  .ce-tooltip__meta {
    background: #1a1a1a;
  }
  
  .ce-tooltip__domain {
    color: rgba(255, 255, 255, 0.5);
  }
  
  .ce-tooltip__title {
    color: #ffffff;
  }
}

/* Dark theme attribute support */
[data-theme="dark"] .ce-tooltip {
  background: #1a1a1a;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .ce-tooltip__preview {
  background: rgba(255, 255, 255, 0.03);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ce-tooltip__loading {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .ce-tooltip__spinner {
  color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .ce-tooltip__meta {
  background: #1a1a1a;
}

[data-theme="dark"] .ce-tooltip__domain {
  color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .ce-tooltip__title {
  color: #ffffff;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .ce-tooltip {
    transition: none;
  }
  
  .ce-tooltip__image {
    transition: none;
  }
}