/* Mobile optimizations for reports */
@media (max-width: 768px) {
    .card-body {
        padding: 1rem;
    }
    .table-responsive {
        font-size: 0.875rem;
    }
    .btn-group .btn {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    .fixed-bottom {
        z-index: 1030;
    }
}

/* Print styles for reports */
@media print {
    .sidebar, .fixed-bottom, .btn-toolbar, .card-header .btn {
        display: none !important;
    }
    .card {
        border: 1px solid #000 !important;
        break-inside: avoid;
    }
    .card-header {
        background: #f8f9fa !important;
        color: #000 !important;
    }
}

/* Hover effects for better UX */
.card:hover {
    transform: translateY(-2px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.table-hover tbody tr:hover {
    background-color: rgba(0,123,255,0.05);
}


.select2-container--default .select2-selection--single {
    border: 1px solid #ced4da;
    height: 38px;
    padding: 5px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ced4da;
    padding: 6px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #007bff;
}

/* Ensure Select2 dropdown appears above other elements */
.select2-container {
    z-index: 1060;
}

/* Chart Styles */
.chart-container {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
}

.btn-group .btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* Responsive chart adjustments */
@media (max-width: 768px) {
    .chart-container {
        height: 300px !important;
    }
    
    .btn-group .btn {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Print styles for chart */
@media print {
    .chart-container {
        height: 500px !important;
        page-break-inside: avoid;
    }
}

/* Enhanced Brand Chart Styles */
.bg-orange {
    background-color: #fd7e14 !important;
}

.color-box {
    border: 1px solid #dee2e6;
    border-radius: 3px;
}

/* Horizontal bar chart improvements */
@media (max-width: 768px) {
    .chart-container {
        height: 600px !important;
    }
    
    .btn-group .btn {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
}

/* Print styles for brand chart */
@media print {
    .chart-container {
        height: 700px !important;
        page-break-inside: avoid;
    }
    
    .btn-group {
        display: none !important;
    }
}

/* Scrollbar styling for chart container */
.chart-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.chart-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chart-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.chart-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* PDF Export Styles */
.export-toast {
    min-width: 300px;
}

.btn-group .dropdown-toggle-split {
    border-left: 1px solid rgba(255,255,255,0.3);
}

/* Print optimization for PDF */
@media print {
    .btn-toolbar,
    .fixed-bottom,
    .sidebar,
    .card-header .btn-group {
        display: none !important;
    }
    
    .card {
        break-inside: avoid;
        border: 1px solid #000 !important;
    }
}

/* Loading state for export buttons */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Add loading state for tables */
.table-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Smooth transitions for table updates */
.card {
    transition: all 0.3s ease;
}

/* Enhanced loading states */
.card .spinner-border {
    width: 2rem;
    height: 2rem;
}

.table-loading {
    position: relative;
}

.table-loading::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 1000;
}

/* Add to your existing CSS */
.pagination-loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.ajax-pagination {
    cursor: pointer;
}

/* Sorting arrow styles */
.table th.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
}

.table th.sortable:hover {
    background-color: #f8f9fa;
}

.sort-arrow {
    margin-left: 5px;
    font-size: 0.8em;
    opacity: 0.6;
}

.sort-arrow.active {
    opacity: 1;
    color: #007bff;
}

.table th.sortable .sort-arrow {
    transition: transform 0.2s ease;
}

.table th.sortable.asc .sort-arrow.desc {
    display: none;
}

.table th.sortable.desc .sort-arrow.asc {
    display: none;
}

/* Loading state for tables during sorting */
.table-sorting {
    opacity: 0.7;
    pointer-events: none;
}

/* Ensure chart container has enough space for labels */
.chart-container {
    position: relative;
    height: 500px;
    width: 100%;
}

/* Make Detailed Records table rows clickable */
#detailedTable tbody tr {
    /* Remove cursor: pointer from default rule */
    transition: background-color 0.15s ease-in-out;
}
/* Hover effect for better UX */
#detailedTable tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05) !important;
}

/* Ensure action buttons don't trigger the row click */
#detailedTable tbody tr .btn-group,
#detailedTable tbody tr .btn {
    cursor: default;
}

/* Prevent text selection on double-click */
#detailedTable tbody tr {
    user-select: none;
    -webkit-user-select: none;
}

/* Highlight clickable rows */
#detailedTable tbody tr.clickable-row {
    cursor: pointer;
}

/* Hover effect only for clickable rows */
#detailedTable tbody tr.clickable-row:hover {
    background-color: rgba(0, 123, 255, 0.05) !important;
}

/* Search loading state */
.table-loading .input-group {
    opacity: 0.6;
    pointer-events: none;
}

/* Search input specific styles */
#detail_search_input:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}


/* Chart clickable elements */
.chartjs-render-monitor {
    cursor: pointer !important;
}

/* Modal animations */
.modal.fade .modal-dialog {
    transform: translate(0, -50px);
    transition: transform 0.3s ease-out;
}

.modal.show .modal-dialog {
    transform: translate(0, 0);
}

/* Hover effects for chart elements */
canvas:hover {
    cursor: pointer;
}

/* Modal content styling */
.brand-details .card,
.product-details .card {
    transition: transform 0.2s ease;
}

.brand-details .card:hover,
.product-details .card:hover {
    transform: translateY(-2px);
}

/* Performance badges */
.performance-badge {
    font-size: 0.9em;
    padding: 0.3em 0.6em;
}

/* Responsive modal adjustments */
@media (max-width: 768px) {
    .modal-lg {
        margin: 0.5rem;
    }
}

/* Enhanced modal styles */
.brand-details .nav-tabs .nav-link {
    border: none;
    color: #6c757d;
    font-weight: 500;
}

.brand-details .nav-tabs .nav-link.active {
    background: none;
    border: none;
    border-bottom: 3px solid #0d6efd;
    color: #0d6efd;
}

.brand-details .table th {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    font-size: 0.875rem;
}

.brand-details .table td {
    font-size: 0.85rem;
    vertical-align: middle;
}

.brand-details .list-group-item {
    border: none;
    padding: 0.75rem 0;
}

.brand-details .card {
    border: 1px solid #e3e6f0;
    box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
}

.brand-details .alert {
    border-left: 4px solid;
}

/* Responsive adjustments for modal */
@media (max-width: 768px) {
    .brand-details .card .card-body {
        padding: 1rem;
    }
    
    .brand-details .table-responsive {
        font-size: 0.8rem;
    }
    
    .brand-details .nav-tabs .nav-link {
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
    }
}


/* Defect pagination styles */
.defect-details .pagination {
    margin: 1rem 0;
}

.defect-details .page-link {
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.defect-details .page-item.active .page-link {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #000;
}

.defect-details .page-link:hover {
    color: #000;
    background-color: #e9ecef;
    border-color: #dee2e6;
}


/* Fix modal backdrop issues */
.modal-backdrop {
    z-index: 1040;
}

.modal {
    z-index: 1050;
}

.modal-open {
    overflow: hidden;
    padding-right: 0 !important;
}

/* Ensure modal content is properly structured */
.defect-details .tab-content {
    min-height: 400px;
}

.defect-details .table-responsive {
    max-height: 500px;
    overflow-y: auto;
}

.sort-arrow.active {
    opacity: 1;
    color: #007bff;
    font-weight: bold;
}

.table th.sortable.asc .sort-arrow.asc.active,
.table th.sortable.desc .sort-arrow.desc.active {
    display: inline;
}

.sort-arrow:not(.active) {
    opacity: 0.3;
}

.table th.sortable {
    position: relative;
    transition: background-color 0.2s ease;
}

.table th.sortable:hover {
    background-color: #f8f9fa;
}

.table th.sortable.sorting-active {
    background-color: #e3f2fd;
}

.sort-arrow {
    margin-left: 5px;
    font-size: 0.8em;
    transition: all 0.2s ease;
}

.sort-arrow.active {
    opacity: 1;
    color: #007bff;
    font-weight: bold;
}

.sort-arrow:not(.active) {
    opacity: 0.3;
}

/* Loading state for tables during sorting */
.table-sorting {
    position: relative;
}

.table-sorting::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

.table-sorting::before {
    content: "Sorting...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #007bff;
    color: white;
    padding: 5px 10px;
    border-radius: 3px;
    z-index: 11;
    font-size: 0.875rem;
}

/* Enhanced sorting visual feedback */
.table-sorting {
    position: relative;
    min-height: 100px;
}

.table-sorting::before {
    content: "Updating table...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #007bff;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 100;
    font-size: 0.9rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Ensure tables are properly styled during updates */
.table-loading .table {
    opacity: 0.6;
}

/* Pagination loading state */
.pagination-loading {
    pointer-events: none;
    opacity: 0.6;
}

.pagination-loading .page-link {
    cursor: not-allowed;
}

/* Mobile responsiveness for Total Damage table */
@media (max-width: 768px) {
    #totalDamageTable th,
    #totalDamageTable td {
        font-size: 0.75rem;
        padding: 0.4rem;
    }
    
    #totalDamageTable .badge {
        font-size: 0.7rem;
    }
}

/* Ensure table doesn't break on smaller screens */
.table-responsive {
    overflow-x: auto;
}

/* Compact table styling for better mobile display */
#totalDamageTable {
    width: 100%;
}

#totalDamageTable th:nth-child(1), /* Product */
#totalDamageTable td:nth-child(1) {
    min-width: 120px;
}

#totalDamageTable th:nth-child(2), /* Class 1 */
#totalDamageTable td:nth-child(2),
#totalDamageTable th:nth-child(3), /* Class 2 */
#totalDamageTable td:nth-child(3),
#totalDamageTable th:nth-child(4), /* Damage */
#totalDamageTable td:nth-child(4) {
    min-width: 80px;
}

#totalDamageTable th:nth-child(5), /* Damage Rate */
#totalDamageTable td:nth-child(5) {
    min-width: 90px;
}

/* Summary Statistics Card Styling */
.summary-card .card-body {
    padding: 0.75rem;
}

.summary-card .card-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.summary-card .card-text {
    font-size: 0.75rem;
    line-height: 1.2;
}

/* Purple color for areas card */
.bg-purple {
    background-color: #6f42c1 !important;
}

/* Make cards more compact */
.col-4.col-md-3.col-lg-2 .card {
    height: 100%;
}

.col-4.col-md-3.col-lg-2 .card-body {
    padding: 0.6rem 0.4rem;
}

/* Mobile adjustments */
@media (max-width: 576px) {
    .col-4 .card-title {
        font-size: 1rem;
    }
    
    .col-4 .card-text {
        font-size: 0.7rem;
    }
    
    .col-4 .card-body {
        padding: 0.5rem 0.3rem;
    }
}

/* Mobile responsiveness for Damaged Rate table */
@media (max-width: 768px) {
    .card:has(.bg-warning) table th,
    .card:has(.bg-warning) table td {
        font-size: 0.7rem;
        padding: 0.3rem;
    }
    
    .card:has(.bg-warning) table .badge {
        font-size: 0.65rem;
    }
}

/* Compact table styling */
.card:has(.bg-warning) table {
    width: 100%;
}

.card:has(.bg-warning) table th:nth-child(1), /* Product */
.card:has(.bg-warning) table td:nth-child(1) {
    min-width: 100px;
}

.card:has(.bg-warning) table th:nth-child(2), /* Records */
.card:has(.bg-warning) table td:nth-child(2),
.card:has(.bg-warning) table th:nth-child(3), /* Damage Rate */
.card:has(.bg-warning) table td:nth-child(3) {
    min-width: 70px;
}

.card:has(.bg-warning) table th:nth-child(4), /* Class 1 */
.card:has(.bg-warning) table td:nth-child(4),
.card:has(.bg-warning) table th:nth-child(5), /* Class 2 */
.card:has(.bg-warning) table td:nth-child(5),
.card:has(.bg-warning) table th:nth-child(6), /* Damaged */
.card:has(.bg-warning) table td:nth-child(6) {
    min-width: 75px;
}

/* Purple color for origin chart */
.bg-purple {
    background-color: #6f42c1 !important;
}
/* Fix Quick Select button alignment */
.btn-group-sm > .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Ensure proper spacing in filter row */
.col-12.col-sm-6.col-md-2 {
    margin-bottom: 1rem;
}