/* CoDicts Chart Widget Styles */

.codicts-chart-widget-container {
    width: 100%;
    max-width: 100%;
    position: relative;
    box-sizing: border-box;
    margin: 0 auto; /* Default center alignment */
}

.codicts-chart-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Transparent background */
    background: transparent;
}

.codicts-chart-canvas {
    max-width: 100%;
    height: auto !important;
    /* Improve rendering quality */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    position: relative;
    z-index: 1;
}

/* Ensure Chart.js tooltips appear above all elements */
.chartjs-tooltip {
    z-index: 9999 !important;
    position: absolute !important;
}

/* Center Content for Donut/Pie Charts */
.codicts-chart-center-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    /*
     * BEHIND the canvas, not above it.
     *
     * This sat at z-index 10 and the canvas at 1, so the centre figure
     * painted straight through any tooltip that crossed the middle of the
     * donut - the two sets of text overlapped and neither was readable.
     *
     * Chart.js draws its tooltip INSIDE the canvas, so the only way for the
     * tooltip to win is for this to sit underneath. It stays visible because
     * the hole is transparent: nothing is painted there to hide it.
     */
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.codicts-chart-center-icon {
    /* Font size now controlled by Elementor settings */
    margin-bottom: 10px;
    line-height: 1;
}

.codicts-chart-center-icon i,
.codicts-chart-center-icon svg {
    display: inline-block;
    vertical-align: middle;
}

.codicts-chart-center-value {
    font-size: 3.5em;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
    color: #ffffff;
    /* Text shadow now controlled by Elementor settings */
}

.codicts-chart-center-label {
    font-size: 0.85em;
    font-weight: 400;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.6);
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 768px) {
    .codicts-chart-center-value {
        font-size: 2em;
    }
    
    .codicts-chart-center-label {
        font-size: 0.75em;
    }
    
    .codicts-chart-center-icon {
        font-size: 1.5em;
        margin-bottom: 6px;
    }
}

@media (max-width: 480px) {
    .codicts-chart-center-value {
        font-size: 1.5em;
    }
    
    .codicts-chart-center-label {
        font-size: 0.65em;
    }
    
    .codicts-chart-center-icon {
        font-size: 1.2em;
        margin-bottom: 4px;
    }
}

/* Loading State */
.codicts-chart-widget-container.loading {
    opacity: 0.6;
    pointer-events: none;
}

.codicts-chart-widget-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: codicts-chart-spin 0.8s linear infinite;
    z-index: 100;
}

@keyframes codicts-chart-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Elementor Editor Placeholder */
.elementor-placeholder,
.codicts-chart-editor-placeholder {
    text-align: center;
    padding: 60px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 8px;
}

.elementor-placeholder i,
.codicts-chart-editor-placeholder i {
    font-size: 48px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 15px;
    display: block;
}

.elementor-widget-title-text {
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 8px;
}

.elementor-widget-description-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.5;
}

/* Elementor Editor Mode - ensure canvas is visible */
.elementor-editor-active .codicts-chart-widget-container {
    min-height: 200px;
}

.elementor-editor-active .codicts-chart-canvas {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Chart Container Background Options */
.codicts-chart-widget-container.has-background {
    padding: 20px;
    border-radius: 8px;
}

/* Ensure proper sizing in Elementor columns */
.elementor-widget-codicts-chart-widget {
    width: 100%;
}

.elementor-widget-codicts-chart-widget .elementor-widget-container {
    width: 100%;
}

/* Print Styles */
@media print {
    .codicts-chart-widget-container {
        page-break-inside: avoid;
    }
}

/* High DPI / Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .codicts-chart-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark Mode Support (if theme has dark mode) */
@media (prefers-color-scheme: dark) {
    .codicts-chart-center-value {
        color: #ffffff;
    }
    
    .codicts-chart-center-label {
        color: #dddddd;
    }
}

/* Accessibility - Focus States */
.codicts-chart-canvas:focus {
    outline: 2px solid rgba(66, 153, 225, 0.6);
    outline-offset: 4px;
}

/* Animation Classes for Dynamic Updates */
.codicts-chart-updating {
    transition: opacity 0.3s ease;
}

.codicts-chart-updating.fade-out {
    opacity: 0.3;
}

/* RTL Support */
[dir="rtl"] .codicts-chart-center-content {
    text-align: center; /* Keep centered for RTL */
}

/* Improved Legend Spacing */
.codicts-chart-wrapper canvas {
    margin: 0 auto;
}


/*
 * Let a chart's canvas fill its wrapper.
 *
 * .codicts-chart-wrapper centres its canvas with flex, and a flex item that
 * is not told to grow keeps its intrinsic width - 300px, however wide the
 * container. EVERY chart type has always been capped there: a widget set to
 * 100% width drew a 300px chart with dead space beside it.
 *
 * This widens charts that already exist, which is why it is a deliberate
 * change rather than a side effect of the polar work. min-width:0 matters as
 * much as the grow: without it a flex item refuses to shrink below its
 * intrinsic size, and a narrow column overflows instead of scaling down.
 */
.codicts-chart-wrapper > .codicts-chart-canvas {
	flex: 1 1 auto;
	min-width: 0;
	width: 100% !important;
}

.codicts-chart-wrapper--fill {
	/*
	 * A wheel is square, so it is sized by a 1:1 box that fills the column
	 * rather than by a height in pixels - which either leaves dead space
	 * beside it or crops it on a phone, and never grows with its container.
	 * Maximum size sets the max-width; the ratio does the rest at every
	 * breakpoint without a per-device height.
	 */
	aspect-ratio: 1 / 1;
	height: auto !important;
	width: 100%;
	margin-inline: auto;
}

.codicts-chart-wrapper--fill > .codicts-chart-canvas {
	flex: 1 1 auto;
	min-width: 0;
	width: 100% !important;
	height: 100% !important;
}

/*
 * Readout for the segment ring.
 *
 * The band is painted onto the canvas and has no element of its own, so this
 * is positioned from the pointer by the chart's hover handler. pointer-events
 * is off: the tooltip follows the cursor, and a tooltip that could be hovered
 * would sit under the pointer and flicker the segment off and on.
 */
.codicts-ring-tip {
	position: absolute;
	z-index: 2;
	pointer-events: none;
	/*
	 * Faded and slid rather than switched on, to match the segment easing up
	 * underneath it. visibility rather than display: display cannot be
	 * transitioned, so a display-toggled tooltip appears instantly however
	 * gently the segment moves.
	 */
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, calc(-100% - 4px));
	transition: opacity .16s ease, transform .16s ease, border-color .16s ease;
	padding: 7px 11px;
	border: 1px solid currentColor;
	border-left-width: 3px;
	border-radius: 6px;
	background: #fff;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .13);
	font-size: 13px;
	line-height: 1.35;
	color: #23282d;
	white-space: nowrap;
}

.codicts-ring-tip.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, calc(-100% - 12px));
}

/* Someone who has asked for less motion gets none of it. */
@media (prefers-reduced-motion: reduce) {
	.codicts-ring-tip {
		transition: none;
	}
}

.codicts-ring-tip strong {
	display: block;
	font-weight: 600;
}

.codicts-ring-tip span {
	display: block;
	opacity: .7;
	font-size: 12px;
}
