/* ============================================================================
   FIGURE DISPLAY AND INTERACTION STYLES
   ============================================================================ */

/* Figure Container */
.llm-referenced-figure {
    position: relative;
    margin: 1.5rem 0;
    max-width: 60%;
    display: inline-block;
}

/* Figure Image Styles */
.llm-referenced-figure .figure-image {
    max-width: 100%;
    width: 100%;
    height: auto;
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1),
                0 2px 4px rgba(0, 0, 0, 0.06);
    transition: box-shadow var(--transition-base, 0.2s ease);
}

.llm-referenced-figure .figure-image:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15),
                0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Loading State */
.llm-referenced-figure .figure-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: var(--radius-md, 8px);
    border: 1px dashed var(--border-color, #e1e8ed);
}

.llm-referenced-figure .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color, #e1e8ed);
    border-top-color: var(--primary-color, #1da1f2);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 0.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.llm-referenced-figure .figure-loading p {
    margin: 0;
    color: var(--text-secondary, #657786);
    font-size: var(--font-size-sm, 0.875rem);
}

.llm-referenced-figure .figure-loading .error {
    color: var(--error-color, #e74c3c);
}

/* Figure Caption */
.llm-referenced-figure figcaption {
    margin-top: 0.75rem;
    font-size: var(--font-size-sm, 0.75rem);
    color: var(--text-secondary, #657786);
    font-style: italic;
    text-align: left;
}

/* Details Icon Overlay */
.figure-details-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast, 0.15s ease);
    z-index: 10;
    opacity: 0;
    transform: scale(0.8);
}

.llm-referenced-figure:hover .figure-details-icon {
    opacity: 1;
    transform: scale(1);
}

.figure-details-icon:hover {
    background: var(--primary-color, #1da1f2);
    color: white;
    transform: scale(1.1);
}

.figure-details-icon svg {
    width: 18px;
    height: 18px;
}

/* Figure Details Popup Card (similar to citation hover card) */
.figure-details-card {
    position: fixed;
    background: var(--bg-color, white);
    border: 1px solid var(--border-color, #e1e8ed);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 0;
    max-width: 450px;
    width: 450px;
    z-index: 9999; /* Higher z-index than overlay */
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast, 0.15s ease);
    transform: translateY(-8px);
    color: var(--text-color, #333);
}

.figure-details-card.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.figure-details-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #f0f3f6);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.figure-details-card-title {
    font-weight: 600;
    color: var(--text-color, #2c3e50);
    margin: 0;
    font-size: var(--font-size-base, 1rem);
    flex: 1;
}

.figure-details-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary, #657786);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm, 4px);
    transition: all var(--transition-fast, 0.15s ease);
}

.figure-details-close:hover {
    background: var(--bg-secondary, #f8f9fa);
    color: var(--text-color, #333);
}

.figure-details-card-body {
    padding: 16px 20px;
    max-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
    overscroll-behavior: contain; /* Prevent scroll chaining */
}

.figure-details-image-preview {
    width: 100%;
    border-radius: var(--radius-md, 8px);
    margin-bottom: 16px;
}

.figure-details-metadata {
    font-size: var(--font-size-sm, 0.875rem);
}

.figure-details-metadata p {
    margin: 8px 0;
    color: var(--text-color, #4a5568);
    line-height: 1.6;
}

.figure-details-metadata strong {
    color: var(--text-color, #2c3e50);
    font-weight: 600;
}

.figure-details-metadata code {
    background: var(--bg-secondary, #f8f9fa);
    padding: 2px 6px;
    border-radius: var(--radius-sm, 4px);
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

/* Overlay for closing card when clicking outside */
.figure-details-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.02); /* Very subtle background to indicate clickable area */
    z-index: 9997; /* Lower z-index than card */
    display: none;
}

.figure-details-overlay.active {
    display: block;
}
