/*
 * Standardized Chart Styles for Synthetic Audiences Research Briefs
 * Version: 1.0
 * Last Updated: March 2026
 *
 * This stylesheet provides consistent styling for Chart.js visualizations
 * across all 55 research documents while respecting each document's unique
 * color scheme defined in their gradient backgrounds.
 */

/* ============================================
   CHART CONTAINER STYLES
   ============================================ */

.chart-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 30px;
    margin: 30px 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.3s ease;
}

.chart-container:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.chart-container h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.3em;
    text-align: center;
}

/* ============================================
   CHART WRAPPER - ENSURES PROPER SIZING
   ============================================ */

.chart-wrapper {
    position: relative;
    height: 400px;
    margin: 20px 0;
}

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

/* Fallback for canvases directly inside chart-container without chart-wrapper */
.chart-container > canvas {
    display: block;
    max-width: 100%;
    height: 400px !important;
    max-height: 400px !important;
    margin: 20px 0;
}

/* Smaller charts for compact data */
.chart-wrapper.compact {
    height: 300px;
}

/* Larger charts for complex visualizations */
.chart-wrapper.expanded {
    height: 500px;
}

/* ============================================
   CHART CAPTIONS
   ============================================ */

.chart-caption {
    margin-top: 15px;
    font-size: 0.95em;
    color: #555;
    text-align: center;
    font-style: italic;
    line-height: 1.5;
}

.chart-caption strong {
    font-weight: 600;
    font-style: normal;
}

/* ============================================
   CHART METADATA (Source, N-size, etc.)
   ============================================ */

.chart-metadata {
    margin-top: 10px;
    font-size: 0.85em;
    color: #777;
    text-align: center;
    border-top: 1px solid #e0e0e0;
    padding-top: 10px;
}

.chart-metadata .chart-source {
    display: inline-block;
    margin-right: 15px;
}

.chart-metadata .chart-sample-size {
    display: inline-block;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Tablet devices (portrait) */
@media (max-width: 992px) {
    .chart-container {
        padding: 25px;
        margin: 25px 0;
    }

    .chart-wrapper {
        height: 350px;
    }

    .chart-wrapper.compact {
        height: 280px;
    }

    .chart-wrapper.expanded {
        height: 450px;
    }

    .chart-container h3 {
        font-size: 1.2em;
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    .chart-container {
        padding: 20px;
        margin: 20px 0;
        border-radius: 6px;
    }

    .chart-wrapper {
        height: 300px;
    }

    .chart-wrapper.compact {
        height: 250px;
    }

    .chart-wrapper.expanded {
        height: 350px;
    }

    .chart-container h3 {
        font-size: 1.1em;
        margin-bottom: 15px;
    }

    .chart-caption {
        font-size: 0.9em;
    }

    .chart-metadata {
        font-size: 0.8em;
    }

    /* Stack metadata on mobile */
    .chart-metadata .chart-source,
    .chart-metadata .chart-sample-size {
        display: block;
        margin: 5px 0;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .chart-container {
        padding: 15px;
        margin: 15px -10px;
    }

    .chart-wrapper {
        height: 250px;
    }

    .chart-wrapper.compact {
        height: 220px;
    }

    .chart-wrapper.expanded {
        height: 300px;
    }

    .chart-container h3 {
        font-size: 1em;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .chart-container {
        background: white;
        border: 1px solid #ddd;
        box-shadow: none;
        page-break-inside: avoid;
        margin: 20px 0;
        padding: 20px;
    }

    .chart-wrapper {
        height: 300px;
    }

    .chart-caption {
        color: #000;
        page-break-before: avoid;
    }

    .chart-metadata {
        color: #333;
    }

    /* Ensure charts are visible in print */
    .chart-wrapper canvas {
        max-height: 300px;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus states for keyboard navigation */
.chart-container:focus-within {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chart-container {
        border: 2px solid currentColor;
    }

    .chart-caption {
        color: #000;
    }
}

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

    /* Chart.js animations should also be disabled via JS */
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* For side-by-side charts on larger screens */
.chart-row {
    display: flex;
    gap: 20px;
    margin: 30px 0;
}

.chart-row .chart-container {
    flex: 1;
    margin: 0;
}

@media (max-width: 992px) {
    .chart-row {
        flex-direction: column;
        gap: 0;
    }

    .chart-row .chart-container {
        margin: 20px 0;
    }
}

/* For charts that need extra emphasis */
.chart-container.featured {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 249, 250, 0.9) 100%);
    border: 2px solid rgba(0, 0, 0, 0.05);
    padding: 35px;
}

/* For inline/embedded charts within text */
.chart-container.inline {
    margin: 20px 0;
    padding: 20px;
}

.chart-container.inline .chart-wrapper {
    height: 300px;
}
