/**
 * Mpalo Chart System CSS Styles
 * Aligned with Mpalo Design System tokens and principles
 */

/* Chart Container Styles */
.mpalo-chart-canvas {
    width: 100%;
    height: 100%;
    min-height: 200px;
    /* Ensure proper containment and positioning for all zoom levels */
    position: relative;
    overflow: hidden; /* Clip to container */
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px; /* Squircle corners to match dashboard cards */
    padding: 0; /* No padding - chart fills container */
    box-sizing: border-box;
    /* Fix for zoom-level positioning issues */
    top: 0;
    left: 0;
    margin: 0;
    align-self: stretch; /* Ensure proper flex alignment */
}

/* Remove rounded corners from SVG - container handles it */
.mpalo-chart-canvas .apexcharts-svg {
    border-radius: 0;
}

/* ApexCharts specific fixes for responsive behavior and positioning */
.mpalo-chart-canvas .apexcharts-canvas {
    width: 100% !important;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
}

.mpalo-chart-canvas .apexcharts-svg {
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
}

/* Remove clip-path - let container overflow handle rounding */

/* Hide any unwanted axis labels or numbers that might appear */
.mpalo-chart-canvas .apexcharts-xaxis-label,
.mpalo-chart-canvas .apexcharts-yaxis-label,
.mpalo-chart-canvas .apexcharts-xaxis-title-text,
.mpalo-chart-canvas .apexcharts-yaxis-title-text,
.mpalo-chart-canvas .apexcharts-text {
    display: none !important;
}

/* Ensure charts fit within height-constrained containers */
.h-120 .mpalo-chart-canvas,
.h-80 .mpalo-chart-canvas,
.h-64 .mpalo-chart-canvas,
.h-40 .mpalo-chart-canvas {
    height: 100%;
}

.h-120 .mpalo-chart-canvas .apexcharts-canvas,
.h-80 .mpalo-chart-canvas .apexcharts-canvas,
.h-64 .mpalo-chart-canvas .apexcharts-canvas,
.h-40 .mpalo-chart-canvas .apexcharts-canvas {
    max-height: 100% !important;
}

.mpalo-chart-header {
    margin-bottom: var(--space-4, 16px);
}

.mpalo-chart-header .heading-3 {
    margin-bottom: var(--space-2, 8px);
}

.mpalo-chart-no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    height: 100%; /* Fill container height for equal spacing top/bottom */
    min-height: 300px; /* Match large dashboard card content */
    padding: 1.5rem; /* Give breathing room inside the dashed box */
    background-color: transparent; /* Let the card background show through */
    border: 2px dashed rgba(99, 102, 241, 0.3); /* Subtle dotted/dashed style */
    border-radius: 12px; /* Match dashboard card rounding */
    color: #cbd5e1; /* Muted slate text */
    text-align: center;
    box-sizing: border-box;
}

/* Optional title/subtitle helpers when markup includes them */
.mpalo-chart-no-data .empty-state-title { 
    font-size: 1.125rem; 
    font-weight: 600; 
    color: #e2e8f0; 
    margin-bottom: 0.5rem; 
}

.mpalo-chart-no-data .empty-state-subtitle { 
    font-size: 0.875rem; 
    color: #94a3b8; 
}

/* Ensure dashboard usage container lets the empty state fill available space */
#dashboard-usage-chart {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 300px; /* Minimum height for proper chart display */
    border-radius: 12px; /* ensure rounded corners */
    overflow: hidden; /* clip canvas to rounded corners */
    position: relative; /* Establish positioning context */
}

.mpalo-chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    gap: var(--space-3, 12px);
}


/* Override ApexCharts default tooltip styles */
.apexcharts-tooltip {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.apexcharts-tooltip.apexcharts-theme-light {
    border: none !important;
    background: transparent !important;
}

/* Custom Tooltip Styles - Clean Dark Mode */
.mpalo-chart-tooltip {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(20, 25, 35, 0.95) !important;
    backdrop-filter: blur(12px);
    border-radius: 6px !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6) !important;
}

.tooltip-time {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 400;
}

.tooltip-value {
    font-size: 16px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
}

/* Empty State Styles */
.mpalo-chart-empty-state {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* CENTER the empty state content */
    min-height: 300px;
    height: 100%;
    padding: 2rem;
    text-align: center;
    overflow: hidden;
}

.empty-state-spiral {
    position: absolute;
    inset: 0;
    opacity: 0.15;
    background-image: 
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 39px,
            rgba(0, 85, 255, 0.3) 39px,
            rgba(0, 85, 255, 0.3) 40px
        );
    mask-image: radial-gradient(
        ellipse 80% 60% at center,
        transparent 0%,
        transparent 20%,
        black 20%,
        black 25%,
        transparent 25%,
        transparent 35%,
        black 35%,
        black 40%,
        transparent 40%,
        transparent 50%,
        black 50%,
        black 55%,
        transparent 55%,
        transparent 65%,
        black 65%,
        black 70%,
        transparent 70%
    );
    pointer-events: none;
}

.empty-state-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.empty-state-icon {
    color: rgba(255, 255, 255, 0.3);
    margin-bottom: 1rem;
    stroke-width: 1.5;
}

.empty-state-title {
    font-size: 1.125rem; /* Match mpalo-chart-no-data styling */
    font-weight: 600;
    color: #e2e8f0; /* Match mpalo-chart-no-data styling */
    margin-bottom: 0.5rem;
    font-family: var(--font-family-display);
}

.empty-state-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
    font-family: var(--font-family-body);
}

/* Loading Animation */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-text-tertiary);
    border-top: 3px solid var(--color-brand-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive Design */
@media (max-width: 640px) {
    .mpalo-chart-tooltip {
        flex-direction: column;
        gap: var(--space-2, 8px);
        align-items: flex-start;
    }
    
    .tooltip-time,
    .tooltip-value {
        font-size: var(--font-size-300, 16px);
    }
}

/* Chart Card Integration - Fixed for zoom compatibility */
.card .mpalo-chart-canvas {
    /* Removed negative margins that cause floating at different zoom levels */
    margin: 0;
    border-radius: 0 0 var(--radius-200, 8px) var(--radius-200, 8px);
}

/* Dashboard-specific chart positioning fixes */
.dashboard-card .mpalo-chart-canvas,
#dashboard-usage-chart .mpalo-chart-canvas {
    /* Ensure proper positioning within dashboard cards at all zoom levels */
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    transform: none !important;
}

.dashboard-card .mpalo-chart-canvas .apexcharts-canvas,
#dashboard-usage-chart .mpalo-chart-canvas .apexcharts-canvas {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
}

/* Dashboard chart positioning - removed negative margin hack for zoom compatibility */
#dashboard-usage-chart .mpalo-chart-canvas {
    margin: 0 !important;
    height: 100% !important;
}

/* Remove focus from chart canvas */
.mpalo-chart-canvas:focus {
    outline: none;
}

/* Add focus to parent dashboard card instead */
.dashboard-card:focus-within {
    outline: 2px solid var(--color-brand-primary);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .mpalo-chart-tooltip {
        border-width: 2px;
        box-shadow: 0 0 0 1px var(--color-text-primary);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .loading-spinner {
        animation: none;
        border-top-color: transparent;
    }
}
