/* styles/diagram.css - Specific styling for interactive charts and diagrams */

/* Chart Container Styling */
.message-bubble .chart-container {
    width: 100%;
    margin: var(--spacing-lg) 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--secondary-dark);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

/* Plotly Chart Specific Styling */
.message-bubble .plotly-chart,
.message-bubble div[id*="chart"],
.message-bubble div[id*="sankey"] {
    width: 100% !important;
    min-height: 400px;
    border-radius: var(--radius-lg);
    background: white;
}

/* Ensure Plotly containers take full width */
.message-bubble .plotly-graph-div {
    width: 100% !important;
    margin: 0 !important;
}

/* Style for embedded HTML content with charts */
.message-bubble iframe {
    width: 100%;
    min-height: 500px;
    border: none;
    border-radius: var(--radius-lg);
    background: white;
    margin: var(--spacing-md) 0;
}

/* Chart loading state */
.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: var(--text-secondary);
    background: var(--secondary-dark);
    border-radius: var(--radius-lg);
    margin: var(--spacing-md) 0;
}

.chart-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--spacing-md);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Chart error state */
.chart-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-secondary);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-lg);
    margin: var(--spacing-md) 0;
    padding: var(--spacing-lg);
    text-align: center;
}

.chart-error-icon {
    width: 48px;
    height: 48px;
    color: #ef4444;
    margin-bottom: var(--spacing-md);
}

/* Enhanced styling for HTML content within message bubbles */
.message-bubble html,
.message-bubble body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    background: transparent !important;
}

/* Override any conflicting styles from embedded HTML */
.message-bubble .container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: var(--spacing-md) !important;
    background: white !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: none !important;
}

/* Chart title styling within message bubbles */
.message-bubble .title,
.message-bubble h1.title {
    color: var(--primary-dark) !important;
    margin-bottom: var(--spacing-md) !important;
    font-size: 1.3em !important;
    text-align: center !important;
}

/* Metadata styling */
.message-bubble .metadata {
    color: #666 !important;
    font-size: 0.85em !important;
    margin-bottom: var(--spacing-md) !important;
    text-align: center !important;
}

/* Legend styling */
.message-bubble .legend-container {
    display: flex !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    margin-bottom: var(--spacing-md) !important;
    gap: var(--spacing-sm) !important;
}

.message-bubble .legend-item {
    display: flex !important;
    align-items: center !important;
    font-size: 0.8em !important;
    margin: 0 var(--spacing-xs) !important;
}

.message-bubble .legend-color {
    width: 20px !important;
    height: 12px !important;
    margin-right: var(--spacing-xs) !important;
    border-radius: 3px !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

/* Responsive design for charts */
@media (max-width: 768px) {
    .message-bubble .plotly-chart,
    .message-bubble div[id*="chart"],
    .message-bubble div[id*="sankey"] {
        min-height: 300px !important;
    }
    
    .message-bubble iframe {
        min-height: 350px !important;
    }
    
    .message-bubble .container {
        padding: var(--spacing-sm) !important;
    }
    
    .message-bubble .title,
    .message-bubble h1.title {
        font-size: 1.1em !important;
    }
    
    .message-bubble .legend-container {
        flex-direction: column !important;
        align-items: center !important;
    }
    
    .message-bubble .legend-item {
        margin: var(--spacing-xs) 0 !important;
    }
}

@media (max-width: 480px) {
    .message-bubble .plotly-chart,
    .message-bubble div[id*="chart"],
    .message-bubble div[id*="sankey"] {
        min-height: 250px !important;
    }
    
    .message-bubble iframe {
        min-height: 300px !important;
    }
    
    .message-bubble .title,
    .message-bubble h1.title {
        font-size: 1em !important;
    }
    
    .message-bubble .legend-item {
        font-size: 0.75em !important;
    }
}

/* Animation for chart appearance */
.chart-fade-in {
    animation: chartFadeIn 0.5s ease-in-out;
}

@keyframes chartFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Ensure charts are above other content */
.message-bubble .chart-container,
.message-bubble .plotly-graph-div {
    position: relative;
    z-index: 1;
}

/* Better scrolling for wide charts on mobile */
.message-bubble .chart-scroll-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--spacing-md) 0;
}

/* Custom scrollbar for chart containers */
.message-bubble .chart-scroll-container::-webkit-scrollbar {
    height: 6px;
}

.message-bubble .chart-scroll-container::-webkit-scrollbar-track {
    background: var(--secondary-dark);
    border-radius: 3px;
}

.message-bubble .chart-scroll-container::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

.message-bubble .chart-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========================================
   PROFESSIONAL APPLE-STYLE ENHANCEMENTS
   ======================================== */

/* Professional Sankey Container */
.plotly-chart-container.professional-sankey {
    background: linear-gradient(145deg, #f8f9fa 0%, #ffffff 100%) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08) !important;
    border: 1px solid rgba(255,255,255,0.18) !important;
    backdrop-filter: blur(10px) !important;
    position: relative !important;
    overflow: hidden !important;
    margin: 15px 0 !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.plotly-chart-container.professional-sankey:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.1) !important;
}

/* Professional Chart Titles */
.chart-title.professional {
    font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    color: #1a202c !important;
    text-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
    letter-spacing: -0.5px !important;
    line-height: 1.2 !important;
    margin-bottom: 8px !important;
}

.chart-subtitle {
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #718096 !important;
    opacity: 0.8 !important;
    margin-bottom: 25px !important;
}

/* Professional Legend Styling */
.professional-legend {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 20px !important;
    margin-bottom: 25px !important;
    position: relative !important;
    z-index: 2 !important;
}

.professional-legend > div {
    display: flex !important;
    align-items: center !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    color: #4a5568 !important;
    background: rgba(255,255,255,0.7) !important;
    padding: 8px 14px !important;
    border-radius: 20px !important;
    backdrop-filter: blur(5px) !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: default !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
}

.professional-legend > div:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
    background: rgba(255,255,255,0.9) !important;
}

/* Enhanced Chart Div Styling */
div[id*="professional-chart"] {
    background: rgba(255,255,255,0.5) !important;
    border-radius: 8px !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    backdrop-filter: blur(3px) !important;
    position: relative !important;
    z-index: 2 !important;
}

/* Professional Typography for Embedded Charts */
.professional-sankey .js-plotly-plot {
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}

/* Enhanced Hover Effects for Chart Elements */
.professional-sankey .modebar {
    background: rgba(255,255,255,0.95) !important;
    border-radius: 8px !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
}

.professional-sankey .modebar-btn {
    border-radius: 6px !important;
    transition: all 0.2s ease !important;
}

.professional-sankey .modebar-btn:hover {
    background: rgba(0,171,181,0.1) !important;
    transform: scale(1.05) !important;
}

/* Professional Animation Keyframes */
@keyframes professionalFadeIn {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    50% {
        opacity: 0.7;
        transform: translateY(10px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes professionalSlideUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Apply professional animations */
.professional-sankey {
    animation: professionalFadeIn 0.8s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.professional-legend > div {
    animation: professionalSlideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.chart-title.professional,
.chart-subtitle {
    animation: professionalSlideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Professional Loading State Enhancement */
.chart-loading.professional {
    background: linear-gradient(145deg, #f8f9fa 0%, #ffffff 100%) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12) !important;
    border: 1px solid rgba(255,255,255,0.18) !important;
    backdrop-filter: blur(10px) !important;
}

/* Professional Error State Enhancement */
.chart-error.professional {
    background: linear-gradient(145deg, #fef2f2 0%, #ffffff 100%) !important;
    border: 1px solid rgba(252, 165, 165, 0.3) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.08) !important;
    backdrop-filter: blur(10px) !important;
}

/* Mobile Responsive Enhancements for Professional Style */
@media (max-width: 768px) {
    .plotly-chart-container.professional-sankey {
        margin: 10px 0 !important;
        padding: 20px !important;
        border-radius: 10px !important;
    }
    
    .chart-title.professional {
        font-size: 20px !important;
    }
    
    .chart-subtitle {
        font-size: 12px !important;
        margin-bottom: 20px !important;
    }
    
    .professional-legend {
        gap: 12px !important;
        margin-bottom: 20px !important;
    }
    
    .professional-legend > div {
        padding: 6px 10px !important;
        font-size: 12px !important;
        border-radius: 16px !important;
    }
    
    div[id*="professional-chart"] {
        height: 400px !important;
    }
}

@media (max-width: 480px) {
    .plotly-chart-container.professional-sankey {
        padding: 15px !important;
        border-radius: 8px !important;
        margin: 8px 0 !important;
    }
    
    .chart-title.professional {
        font-size: 18px !important;
        margin-bottom: 6px !important;
    }
    
    .chart-subtitle {
        font-size: 11px !important;
        margin-bottom: 15px !important;
    }
    
    .professional-legend {
        gap: 8px !important;
        margin-bottom: 15px !important;
    }
    
    .professional-legend > div {
        padding: 4px 8px !important;
        font-size: 11px !important;
        border-radius: 12px !important;
    }
    
    div[id*="professional-chart"] {
        height: 350px !important;
    }
}

/* Dark Mode Support for Professional Charts */
@media (prefers-color-scheme: dark) {
    .plotly-chart-container.professional-sankey {
        background: linear-gradient(145deg, #1a202c 0%, #2d3748 100%) !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    .chart-title.professional {
        color: #f7fafc !important;
        text-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
    }
    
    .chart-subtitle {
        color: #a0aec0 !important;
    }
    
    .professional-legend > div {
        background: rgba(45, 55, 72, 0.8) !important;
        color: #e2e8f0 !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    .professional-legend > div:hover {
        background: rgba(45, 55, 72, 0.95) !important;
    }
    
    div[id*="professional-chart"] {
        background: rgba(45, 55, 72, 0.3) !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
    }
}

/* High DPI Display Enhancements */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .plotly-chart-container.professional-sankey {
        box-shadow: 0 16px 64px rgba(0,0,0,0.12), 0 4px 16px rgba(0,0,0,0.08) !important;
    }
    
    .chart-title.professional {
        text-shadow: 0 2px 6px rgba(0,0,0,0.1) !important;
    }
    
    .professional-legend > div {
        box-shadow: 0 4px 16px rgba(0,0,0,0.05) !important;
    }
}

/* Accessibility Enhancements */
.professional-sankey [aria-label],
.professional-sankey [role="img"] {
    outline: none !important;
}

.professional-sankey:focus-within {
    box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08), 0 0 0 3px rgba(0,171,181,0.2) !important;
}

/* Print Styles for Professional Charts */
@media print {
    .plotly-chart-container.professional-sankey {
        background: white !important;
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        break-inside: avoid !important;
    }
    
    .chart-title.professional {
        color: #000 !important;
        text-shadow: none !important;
    }
    
    .chart-subtitle {
        color: #666 !important;
    }
    
    .professional-legend > div {
        background: white !important;
        border: 1px solid #ccc !important;
        color: #000 !important;
    }
}
