/* Enhanced Machine Stats CSS - Professional and Responsive Design */

.stats-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.stats-popup-content {
    background: #ffffff;
    color: #333;
    border-radius: 20px;
    width: 95%;
    height: 95%;
    max-width: 1400px;
    max-height: 90vh;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.stats-popup-overlay.show .stats-popup-content {
    transform: scale(1);
    opacity: 1;
}

.stats-popup-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: none;
    position: relative;
    overflow: hidden;
}

.stats-popup-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    pointer-events: none;
}

.stats-popup-header h4 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.stats-popup-header small {
    opacity: 0.9;
    font-size: 0.9rem;
    margin-top: 0.25rem;
    display: block;
}

.stats-popup-close {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.stats-popup-close:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.stats-popup-body {
    padding: 2rem;
    overflow-y: auto;
    flex-grow: 1;
    background: #f8fafc;
}

/* Date Range Controls */
.date-range-controls {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
}

.date-range-controls h6 {
    color: #2d3748;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-input-group {
    position: relative;
}

.date-input-group input {
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    background: #ffffff;
}

.date-input-group input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
}

.btn-date-filter {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.5rem;
    color: white;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-date-filter:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    color: white;
}

.btn-secondary-outline {
    border: 2px solid #e2e8f0;
    color: #64748b;
    background: transparent;
    border-radius: 10px;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-secondary-outline:hover {
    border-color: #cbd5e0;
    background: #f7fafc;
    color: #4a5568;
}

/* Summary Statistics Grid */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    text-align: center;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.stat-card .stat-icon {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.9rem;
    color: #718096;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Performance Metrics */
.performance-metrics {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
}

.performance-metrics h5 {
    color: #2d3748;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.efficiency-score {
    text-align: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    color: white;
    margin-bottom: 1rem;
}

.efficiency-score .score-value {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.efficiency-score .score-label {
    font-size: 1rem;
    opacity: 0.9;
}

/* Charts Section */
.stats-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    position: relative;
}

.chart-container h5 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #2d3748;
    font-weight: 600;
    font-size: 1.1rem;
}

.chart-container canvas {
    max-height: 300px !important;
}

/* Site Statistics Table */
.site-stats-section {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
}

.site-stats-section h5 {
    color: #2d3748;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-responsive {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.table thead th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    padding: 1rem 0.75rem;
    text-align: center;
}

.table tbody td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.9rem;
}

.table tbody tr:hover {
    background-color: #f7fafc;
    transition: all 0.3s ease;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Operator Statistics */
.operator-stats-section {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
}

.operator-stats-section h5 {
    color: #2d3748;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.operator-card {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.operator-card:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
    transform: translateY(-2px);
}

.operator-card .card-body {
    padding: 1.25rem;
}

.operator-card .card-title {
    color: #2d3748;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 1rem;
}

/* Export Actions */
.export-actions {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
    text-align: center;
}

.export-actions h6 {
    color: #2d3748;
    font-weight: 600;
    margin-bottom: 1rem;
}

.btn-export {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.5rem;
    color: white;
    font-weight: 600;
    margin: 0.25rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(72, 187, 120, 0.3);
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(72, 187, 120, 0.4);
    color: white;
}

/* Loading States */
#machineStatsLoader {
    color: #4a5568;
    text-align: center;
    font-size: 1.2rem;
    padding: 3rem;
    background: white;
    border-radius: 15px;
    margin: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.loading-spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Badges and Status Indicators */
.badge {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-weight: 600;
}

.badge.bg-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%) !important;
}

.badge.bg-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.badge.bg-warning {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%) !important;
}

.badge.bg-danger {
    background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%) !important;
}

.badge.bg-info {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%) !important;
}

/* Clickable Machine Links */
.clickable-machine {
    color: #667eea;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s ease;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    background: rgba(102, 126, 234, 0.1);
}

.clickable-machine:hover {
    color: #764ba2;
    background: rgba(102, 126, 234, 0.2);
    text-decoration: none;
    transform: scale(1.05);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .stats-charts {
        grid-template-columns: 1fr;
    }
    
    .chart-container canvas {
        max-height: 250px !important;
    }
}

@media (max-width: 992px) {
    .stats-popup-content {
        width: 98%;
        height: 98%;
        border-radius: 15px;
    }
    
    .stats-popup-header {
        padding: 1.25rem 1.5rem;
    }
    
    .stats-popup-header h4 {
        font-size: 1.5rem;
    }
    
    .stats-popup-body {
        padding: 1.5rem;
    }
    
    .stats-summary {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1.5rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.75rem;
    }
    
    .chart-container {
        padding: 1.5rem;
    }
    
    .chart-container canvas {
        max-height: 220px !important;
    }
}

@media (max-width: 768px) {
    .stats-popup-content {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    
    .stats-popup-header {
        padding: 1rem;
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .stats-popup-header h4 {
        font-size: 1.25rem;
    }
    
    .stats-popup-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 35px;
        height: 35px;
        font-size: 1.25rem;
    }
    
    .stats-popup-body {
        padding: 1rem;
    }
    
    .stats-summary {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1.25rem;
    }
    
    .stat-card .stat-icon {
        font-size: 2rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    
    .stats-charts {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .chart-container {
        padding: 1rem;
    }
    
    .chart-container h5 {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    .chart-container canvas {
        max-height: 200px !important;
    }
    
    .date-range-controls {
        padding: 1rem;
    }
    
    .date-range-controls .row {
        margin: 0;
    }
    
    .date-range-controls .col-md-3,
    .date-range-controls .col-md-2 {
        padding: 0.25rem;
        margin-bottom: 0.5rem;
    }
    
    .btn-date-filter,
    .btn-secondary-outline {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .table-responsive {
        font-size: 0.85rem;
    }
    
    .table thead th {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }
    
    .table tbody td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
    
    .site-stats-section,
    .operator-stats-section,
    .performance-metrics,
    .export-actions {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .efficiency-score {
        padding: 1rem;
    }
    
    .efficiency-score .score-value {
        font-size: 2rem;
    }
    
    .export-actions .btn-export {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        margin: 0.25rem 0;
        width: 100%;
    }
}

@media (max-width: 576px) {
    .stats-summary {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.25rem;
    }
    
    .stat-card .stat-icon {
        font-size: 1.75rem;
    }
    
    .chart-container canvas {
        max-height: 180px !important;
    }
    
    .performance-metrics .row .col-md-4 {
        margin-bottom: 1rem;
    }
    
    .efficiency-score .score-value {
        font-size: 1.75rem;
    }
    
    .date-range-controls .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .table {
        font-size: 0.8rem;
    }
    
    .table thead th {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }
    
    .table tbody td {
        padding: 0.5rem 0.25rem;
        font-size: 0.8rem;
    }
    
    /* Hide less important table columns on very small screens */
    .table th:nth-child(5),
    .table td:nth-child(5),
    .table th:nth-child(6),
    .table td:nth-child(6) {
        display: none;
    }
}

/* Print Styles */
@media print {
    body {
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
    }

    .stats-popup-overlay {
        position: static;
        background: none;
        backdrop-filter: none;
        display: block !important;
    }
    
    .stats-popup-content {
        width: 100%;
        height: auto;
        max-width: none;
        max-height: none;
        box-shadow: none;
        border-radius: 0;
        transform: none;
        opacity: 1;
        border: none;
        display: block !important;
    }
    
    .stats-popup-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: white !important;
        padding: 1rem;
        text-align: center;
        page-break-after: avoid;
    }
    
    .stats-popup-close,
    .date-range-controls,
    .export-actions,
    .stats-popup-header small {
        display: none;
    }
    
    .stats-popup-body {
        padding: 0.5rem;
        overflow: visible;
    }

    .stat-card,
    .performance-metrics,
    .site-stats-section,
    .operator-stats-section,
    .chart-container {
        page-break-inside: avoid;
        margin-bottom: 1rem;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .stats-summary, .stats-charts {
        grid-template-columns: 1fr 1fr;
    }

    .stats-charts {
        grid-template-columns: 1fr; /* For PDF generation, stack charts vertically */
    }

    .table thead th {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: white !important;
    }

    .chart-container canvas {
       max-height: 250px !important;
    }
    
    h5, h6 {
        page-break-after: avoid;
    }
}


/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .stats-popup-content {
        background: #1a202c;
        color: #e2e8f0;
    }
    
    .stats-popup-body {
        background: #2d3748;
    }
    
    .stat-card,
    .chart-container,
    .site-stats-section,
    .operator-stats-section,
    .performance-metrics,
    .export-actions,
    .date-range-controls {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .stat-card .stat-value {
        color: #e2e8f0;
    }
    
    .stat-card .stat-label {
        color: #a0aec0;
    }
    
    .table {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .table tbody tr:hover {
        background-color: #4a5568;
    }
    
    .table tbody td {
        border-color: #4a5568;
    }
    
    .operator-card {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .operator-card:hover {
        background: #718096;
    }
    
    .date-input-group input {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .date-input-group input:focus {
        border-color: #667eea;
        background: #4a5568;
    }
    
    #machineStatsLoader {
        background: #2d3748;
        color: #e2e8f0;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .stat-card .stat-icon {
        font-size: 2.25rem;
    }
    
    .chart-container canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: optimize-contrast;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .stats-popup-content {
        transition: none;
    }
    
    .stat-card:hover,
    .clickable-machine:hover,
    .btn-date-filter:hover,
    .btn-export:hover {
        transform: none;
    }
    
    .loading-spinner {
        animation: none;
    }
    
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* Focus Styles for Accessibility */
.stats-popup-close:focus,
.btn-date-filter:focus,
.btn-secondary-outline:focus,
.btn-export:focus,
.date-input-group input:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Custom Scrollbar */
.stats-popup-body::-webkit-scrollbar {
    width: 8px;
}

.stats-popup-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.stats-popup-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.stats-popup-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Utility Classes */
.text-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.shadow-soft {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.shadow-medium {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.border-gradient {
    border: 2px solid transparent;
    background: linear-gradient(white, white) padding-box,
                linear-gradient(135deg, #667eea 0%, #764ba2 100%) border-box;
}