/* Delivery Turn Time Charts CSS */
#truckVisitsChart {
    background: transparent;
    padding: 0;
    margin: 20px 0;
    border-radius: 0;
    box-shadow: none;
}

.bar-wrapper {
    background: #ededed !important;
    padding: 25px !important;
    margin: 20px 0 !important;
    border-radius: 12px !important;
    height: 300px !important;
    max-height: 300px !important;
    overflow: hidden !important;
    position: relative !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.bar-wrapper h4 {
    margin: 0 0 20px 0 !important;
    font-size: 16px !important;
    font-weight: bold !important;
    color: #333 !important;
    font-family: sans-serif !important;
}

.bar-wrapper > div:last-child {
    background: #ededed !important;
    border-radius: 8px !important;
    padding: 20px !important;
    height: 220px !important;
    position: relative !important;
}

#truckVisitsChart canvas {
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    display: block;
}

/* Bar chart specific styling */
.bar-chart-container {
    position: relative;
    height: 220px;
    background: #ededed;
    border-radius: 8px;
    padding: 15px;
}

.bar-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Mobile legend for bar chart - hidden by default */
.mobile-bar-legend {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    align-items: center; /* Center the legend items */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center; /* Center each legend item */
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-label {
    font-size: 12px;
    font-weight: bold;
    color: #333;
    text-align: center; /* Center the text */
}

#deliveryTurnCharts {
    background: #ededed;
    padding: 25px;
    margin: 20px 0;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: relative;
}

/* Header styling for donut charts section */
.donut-section-header {
    margin: 0 0 20px 0 !important;
    font-size: 16px !important;
    font-weight: bold !important;
    color: #333 !important;
    font-family: sans-serif !important;
}

/* Container for the actual donut charts */
.donut-charts-wrapper {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.turn-tile {
    background: white;
    padding: 20px;
    border-radius: 12px;
    width: 320px; /* Increased from 280px for better spacing */
    min-width: 320px; /* Ensure minimum size */
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    font-family: sans-serif;
    position: relative;
    display: flex;
    align-items: center;
    gap: 20px;
}

.turn-tile .date-section {
    flex: 1;
    text-align: left;
}

.turn-tile .chart-section {
    flex-shrink: 0;
    width: 160px; /* Fixed width for chart container */
    height: 160px; /* Fixed height for chart container */
    position: relative;
}

.turn-tile .week-label {
    margin-bottom: 4px;
    font-size: 14px;
    color: #333;
    line-height: 1.2;
    white-space: nowrap; /* Prevent text wrapping within each line */
}

/* Ensure year part styling for donut chart labels */
.turn-tile .week-label div:first-child {
    font-weight: bold;
}

.turn-tile .week-label div:last-child {
    font-weight: normal;
}

.turn-tile .week-date {
    font-size: 13px;
    font-weight: normal;
    margin-bottom: 10px;
    color: #666;
}

.turn-tile canvas {
    width: 100% !important; /* Let Chart.js responsive mode control size */
    height: 100% !important; /* Let Chart.js responsive mode control size */
    display: block;
}

.turn-tile .avg-time {
    font-size: 18px;
    font-weight: bold;
    color: #2271b1;
    margin-top: 10px;
}

.delivery-turn-charts-container .loading {
    text-align: center;
    padding: 20px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px; /* Ensure loading text is properly centered */
}

.delivery-turn-charts-container .error {
    text-align: center;
    padding: 20px;
    color: #d63638;
    background: #fff;
    border: 1px solid #d63638;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px; /* Match loading height */
}

/* Accessibility improvements */
.delivery-turn-charts-container [aria-live] {
    position: relative;
}

.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
}

/* WP Engine CDN compatibility */
.delivery-turn-charts-container {
    position: relative;
}

/* Modern WordPress alignment */
.delivery-turn-charts-container h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    line-height: 1.4;
}

/* Responsive design for tablets and smaller screens */
@media (max-width: 1024px) {
    #deliveryTurnCharts {
        padding: 25px;
    }
    
    .donut-charts-wrapper {
        gap: 15px;
    }
    
    .turn-tile {
        width: 100%;
        max-width: 450px; /* Increased to accommodate larger charts */
        min-width: 320px;
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #truckVisitsChart {
        min-height: 250px; /* Adjust for mobile bar chart height */
    }

    #deliveryTurnCharts {
        padding: 20px;
        min-height: 400px; /* Accommodate stacked donut charts on mobile */
    }
    
    .donut-charts-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .turn-tile {
        width: 100%;
        max-width: 380px; /* Increased from 350px */
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .turn-tile .date-section {
        text-align: center;
    }
    
    .turn-tile .chart-section {
        width: 140px; /* Increased from 120px for mobile */
        height: 140px;
    }
    
    .bar-wrapper {
        height: auto !important;
        max-height: none !important;
        padding: 20px !important;
    }
    
    .bar-wrapper > div:last-child {
        height: 200px !important;
        padding: 15px !important;
    }
    
    .bar-chart-container {
        height: 200px;
        padding: 10px 5px; /* Reduced left/right padding on mobile */
    }
    
    .bar-wrapper h4 {
        font-size: 14px !important;
        margin-bottom: 15px !important;
    }
    
    .donut-section-header {
        font-size: 14px !important;
        margin-bottom: 15px !important;
    }
    
    /* Show mobile legend on devices below 768px */
    .mobile-bar-legend {
        display: flex !important;
    }
}

@media (max-width: 480px) {
    .delivery-turn-charts-container {
        margin: 15px 0;
    }
    
    #deliveryTurnCharts {
        padding: 15px;
    }
    
    .turn-tile {
        padding: 15px;
        max-width: 100%;
        min-width: 280px; /* Maintained minimum for small screens */
    }
    
    .turn-tile .chart-section {
        width: 120px; /* Kept reasonable size for very small screens */
        height: 120px;
    }
    
    .bar-wrapper {
        padding: 15px !important;
        margin: 15px 0 !important;
        height: 280px !important;
    }
    
    .bar-wrapper > div:last-child {
        height: 180px !important;
    }
    
    .bar-chart-container {
        height: 180px;
    }
}

/* Print styles */
@media print {
    .delivery-turn-charts-container {
        page-break-inside: avoid;
    }
    
    .bar-wrapper,
    .turn-tile {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bar-wrapper {
        border: 2px solid #000;
    }
    
    .turn-tile {
        border: 1px solid #000;
    }
    
    .delivery-turn-charts-container .error {
        border: 2px solid #d63638;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .delivery-turn-charts-container * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}