/**
 * AISGUOB Chart.js Extension Styles
 * Version: 1.0.0
 */

/* Chart Container Styles */
.aisguob-chart-container {
    margin: 20px 0;
   /* font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
*/
}

.aisguob-chart-title {
    margin: 0 0 15px 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

/* Print Image - Hidden by default, shown for print/PDF */
.chart-print-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chart-container {
    width: 100%;
    position: relative;
    aspect-ratio: 3 / 1; /* Default: Desktop 3:1 */
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 20px;
    box-sizing: border-box;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .chart-container {
        aspect-ratio: 1 / 2; /* Tablet & Mobile: 1:2 */
        padding: 15px;
    }
    
    .aisguob-chart-title {
        font-size: 16px;
        margin-bottom: 10px;
    }
}

@media (max-width: 768px) {
    .chart-container {
        aspect-ratio: 1 / 1.5; /* Mobile: 1:1.5 */
        padding: 10px;
    }
    
    .aisguob-chart-title {
        font-size: 14px;
        margin-bottom: 8px;
    }
}

/* Canvas Styles */
.aisguob-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
}

/* Error Messages */
.aisguob-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 14px;
    line-height: 1.4;
}

/* Loading State */
.aisguob-chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    background: #f8f9fa;
    border-radius: 8px;
    color: #6c757d;
    font-size: 14px;
}

.aisguob-chart-loading::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #dee2e6;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: aisguob-spin 1s linear infinite;
    margin-right: 10px;
}

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

/* Chart Legend Customization */
.aisguob-chart-container .chartjs-legend {
    margin-top: 15px;
    text-align: center;
}

.aisguob-chart-container .chartjs-legend-item {
    display: inline-block;
    margin: 0 10px 5px 0;
    font-size: 12px;
    color: #666;
}

.aisguob-chart-container .chartjs-legend-item span {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 5px;
    border-radius: 2px;
}

/* Tooltip Customization */
.aisguob-chart-container .chartjs-tooltip {
    background: rgba(0, 0, 0, 0.8) !important;
    color: #fff !important;
    border-radius: 4px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

/* Accessibility */
.aisguob-chart-container canvas[aria-label] {
    outline: none;
}

.aisguob-chart-container canvas:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Disable print functionality on tablet and mobile screens */
@media (max-width: 1024px) {
    /* Hide print-related elements on tablet and mobile */
    .aisguob-chart-printable .chart-print-image {
        display: none !important;
    }
    
    /* Disable print button/links if any exist */
    .print-button,
    .pdf-button,
    .generate-pdf-btn,
    [href*="print=1"],
    [href*="pdf=1"] {
        display: none !important;
        visibility: hidden !important;
    }
}

/* Print Styles - Convert canvas to image for PDF compatibility */
/* Only enable print styles on desktop screens (1025px and above) */
@media print and (min-width: 1025px) {
    @page {
        size: portrait;
        margin: 0.5in;
    }
    
    /* Hide printthis div from PDF */
    #printthis,
    .result-displays {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    
    .aisguob-chart-container {
        page-break-inside: avoid;
        margin: 10px 0;
    }
    
    .chart-container {
        box-shadow: none;
        border: 1px solid #ddd;
        background: #fff;
    }
    
    .aisguob-chart-title {
        color: #000;
    }
    
    /* Show image, hide canvas for print */
    .aisguob-chart-printable canvas {
        display: none !important;
    }
    
    .aisguob-chart-printable .chart-print-image {
        display: block !important;
    }
    
    /* Page break control - Minimal spacing */
    .pagebreak {
        page-break-after: always !important;
        page-break-before: auto !important;
        page-break-inside: avoid !important;
        break-after: page !important;
        break-before: auto !important;
        break-inside: avoid !important;
        display: block !important;
        height: 0 !important;
        line-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        clear: both !important;
        overflow: hidden !important;
        font-size: 0 !important;
        visibility: hidden !important;
    }
    
    /* Aggressively remove spacing around page breaks */
    * + .pagebreak {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
    
    .pagebreak + * {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    
    /* Remove margins from elements immediately before page break */
    *:has(+ .pagebreak) {
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }
    
    /* Remove top margin from first element after page break */
    .pagebreak ~ *:first-child,
    .pagebreak + section > *:first-child,
    .pagebreak + div > *:first-child,
    .pagebreak + section h1,
    .pagebreak + section h2,
    .pagebreak + section h3,
    .pagebreak + div h1,
    .pagebreak + div h2,
    .pagebreak + div h3 {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    
    /* Prevent page breaks before headings */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        break-after: avoid;
        page-break-before: auto;
        break-before: auto;
    }
    
    /* Compact spacing for sections */
    section, div, article {
        margin-bottom: 1em;
    }
    
    /* Prevent orphaned content */
    p, li, div {
        orphans: 3;
        widows: 3;
    }
    
    /* Compact spacing for better page utilization */
    * {
        box-sizing: border-box;
    }
}

/* PDF Generation Mode - When ?print=1 or ?pdf=1 is in URL */
/* Only enable PDF generation on desktop screens (1025px and above) */
@media (min-width: 1025px) {
    body.pdf-mode .aisguob-chart-printable canvas,
    body.pdf-generation-mode .aisguob-chart-printable canvas,
    .pdf-generating .aisguob-chart-printable canvas {
        display: none !important;
    }

    body.pdf-mode .aisguob-chart-printable .chart-print-image,
    body.pdf-generation-mode .aisguob-chart-printable .chart-print-image,
    .pdf-generating .aisguob-chart-printable .chart-print-image {
        display: block !important;
    }
}

/* Hide WordPress admin elements during PDF generation */
body.pdf-generation-mode #wpadminbar,
body.pdf-generation-mode .wp-admin-bar,
body.pdf-generation-mode .elementor-editor-active,
body.pdf-generation-mode .wp-admin {
    display: none !important;
}

/* Hide printthis div during PDF generation */
body.pdf-mode #printthis,
body.pdf-generation-mode #printthis,
.pdf-generating #printthis,
body.pdf-mode .result-displays,
body.pdf-generation-mode .result-displays,
.pdf-generating .result-displays {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* PDF loading indicator */
.pdf-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    flex-direction: column;
    gap: 20px;
    pointer-events: none; /* Don't block interactions */
}

/* Hide loading overlay in print/PDF output */
@media print {
    .pdf-loading-overlay {
        display: none !important;
    }
}

.pdf-loading-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007cba;
    border-radius: 50%;
    animation: pdf-spin 1s linear infinite;
}

.pdf-loading-overlay .message {
    font-size: 18px;
    color: #333;
    font-weight: 500;
}

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

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .aisguob-chart-container {
        border: 2px solid #000;
    }
    
    .aisguob-error {
        border: 2px solid #000;
        background: #fff;
        color: #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .aisguob-chart-loading::before {
        animation: none;
    }
}
