/**
 * CTR Charts CSS
 * Scoped styles for bar charts and line charts
 * 
 * All styles are prefixed with .ctr-chart to avoid conflicts with themes,
 * page builders (Elementor, Oxygen, etc.), and other plugins.
 */

/* ==========================================================================
   Chart Container Base Styles
   ========================================================================== */

/* Main stages container - ensure it respects parent width */
.ctr-stages-container {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.ctr-stage-items {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.ctr-chart-container {
    position: relative;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 500px;
    margin: 2rem auto;
    padding: 2rem;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    overflow: visible; /* Allow chart to be fully visible */
    grid-column: 1 / -1 !important; /* Break out of grid columns */
}

.ctr-chart-container * {
    box-sizing: border-box;
}

/* Ensure no negative margins or padding issues */
.ctr-chart-container > * {
    width: 100%;
    max-width: 100%;
}

/* Dark background support */
.ctr-chart-container.ctr-dark-mode {
    background: #1a1a1a;
    color: #ffffff;
}

/* ==========================================================================
   Chart Header
   ========================================================================== */

.ctr-chart-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #f0f0f0;
}

.ctr-chart-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.ctr-chart-subtitle {
    font-size: 0.875rem;
    color: #666666;
    margin: 0;
    font-weight: 400;
}

.ctr-dark-mode .ctr-chart-title {
    color: #ffffff;
}

.ctr-dark-mode .ctr-chart-subtitle {
    color: #cccccc;
}

/* ==========================================================================
   Chart Canvas Wrapper
   ========================================================================== */

.ctr-chart-wrapper {
    position: relative;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 400px;
    margin: 0;
    padding: 0;
    overflow: visible; /* Allow chart to be fully visible */
    box-sizing: border-box;
}

/* Responsive canvas sizing */
.ctr-chart-wrapper canvas {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto;
    box-sizing: border-box;
}

/* ==========================================================================
   Stage Grouping (for per-stage charts)
   ========================================================================== */

.ctr-stage-chart-group {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 3rem;
    padding: 1.5rem;
    background: #fafafa;
    box-sizing: border-box;
    border-radius: 8px;
    border-left: 4px solid #0074f8;
    box-sizing: border-box;
    overflow: hidden;
}

.ctr-stage-chart-group:last-child {
    margin-bottom: 1.5rem;
}

.ctr-stage-chart-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    color: #0074f8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.ctr-chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: #666666;
    font-size: 1rem;
}

.ctr-chart-loading::before {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-right: 12px;
    border: 3px solid #f0f0f0;
    border-top-color: #0074f8;
    border-radius: 50%;
    /* Animation removed for debugging */
}

/* Animation keyframe removed for debugging */

/* ==========================================================================
   Error State
   ========================================================================== */

.ctr-chart-error {
    padding: 1.5rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    color: #856404;
    margin: 1rem 0;
}

.ctr-chart-error strong {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media screen and (max-width: 768px) {
    .ctr-chart-container {
        padding: 1rem;
        margin: 1rem auto;
        border-radius: 8px;
    }
    
    .ctr-chart-title {
        font-size: 1.25rem;
    }
    
    .ctr-chart-subtitle {
        font-size: 0.75rem;
    }
    
    .ctr-stage-chart-group {
        padding: 1rem;
    }
    
    .ctr-chart-wrapper {
        min-height: 250px;
    }
}

@media screen and (max-width: 480px) {
    .ctr-chart-container {
        padding: 0.75rem;
        margin: 0.75rem auto;
    }
    
    .ctr-chart-title {
        font-size: 1.125rem;
    }
    
    .ctr-chart-wrapper {
        min-height: 200px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .ctr-chart-container {
        box-shadow: none;
        border: 1px solid #e0e0e0;
        page-break-inside: avoid;
    }
    
    .ctr-stage-chart-group {
        page-break-inside: avoid;
    }
}

/* ==========================================================================
   Page Builder Compatibility
   ========================================================================== */

/* Elementor */
.elementor-widget-container .ctr-chart-container {
    margin-top: 0;
    margin-bottom: 0;
}

/* Oxygen Builder */
.ct-section .ctr-chart-container,
.oxy-post-content .ctr-chart-container {
    max-width: 100%;
}

/* Divi Builder */
.et_pb_module .ctr-chart-container {
    margin-top: 0;
    margin-bottom: 0;
}

/* Beaver Builder */
.fl-module-content .ctr-chart-container {
    max-width: 100%;
}

/* WPBakery Page Builder */
.wpb_wrapper .ctr-chart-container {
    margin: 1rem 0;
}

/* ==========================================================================
   Chart.js Tooltip Override (Scoped to CTR charts only)
   ========================================================================== */

.ctr-chart-wrapper .chartjs-tooltip {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.ctr-chart-fullwidth {
    max-width: 100% !important;
    width: 100% !important;
}

.ctr-chart-centered {
    margin-left: auto;
    margin-right: auto;
}

.ctr-chart-no-shadow {
    box-shadow: none;
}

.ctr-chart-bordered {
    border: 1px solid #e0e0e0;
}

/* Hide on mobile if needed */
.ctr-chart-hide-mobile {
    display: block;
}

@media screen and (max-width: 768px) {
    .ctr-chart-hide-mobile {
        display: none;
    }
}

/* Hide on desktop if needed */
.ctr-chart-hide-desktop {
    display: none;
}

@media screen and (max-width: 768px) {
    .ctr-chart-hide-desktop {
        display: block;
    }
}

/* ==========================================================================
   Theme Compatibility & Safety Overrides
   ========================================================================== */

/* Prevent theme styles from breaking charts */
.ctr-stages-container,
.ctr-stage-items,
.ctr-chart-container,
.ctr-chart-wrapper {
    /* Reset any theme-imposed constraints */
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Ensure content width is respected */
.entry-content .ctr-chart-container,
.post-content .ctr-chart-container,
.page-content .ctr-chart-container,
article .ctr-chart-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Fix for full-width themes */
.alignfull .ctr-chart-container {
    width: 100%;
    max-width: 100%;
}

/* Fix for centered content themes */
.site-content .ctr-chart-container,
.content-area .ctr-chart-container {
    width: 100%;
    max-width: 100%;
}

/* Prevent flexbox issues */
.ctr-chart-container {
    flex-shrink: 1;
    min-width: 0;
}
