/**
 * RMA Analysis System - Custom CSS
 * Modern and light design
 */

:root {
    --primary-color: #4f46e5;
    --secondary-color: #818cf8;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;
    --light-bg: #f8fafc;
    --white: #ffffff;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
}

/* General Styles */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--light-bg);
    color: var(--text-dark);
}

/* Navigation */
.navbar {
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
}

.nav-link {
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-link:hover {
    color: var(--primary-color) !important;
    transform: translateY(-1px);
}

.nav-link.active {
    color: var(--primary-color) !important;
    position: relative;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
    border-radius: 3px 3px 0 0;
}

/* Cards */
.card {
    border-radius: 12px;
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08) !important;
}

.card-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    font-weight: 600;
}

/* Stat Cards */
.stat-card {
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12) !important;
}

.stat-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.5rem;
}

/* Buttons */
.btn {
    font-weight: 600;
    border-radius: 8px;
    padding: 0.5rem 1.25rem;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4338ca, #6366f1);
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
}

/* Forms */
.form-control,
.form-select {
    border-radius: 8px;
    border: 2px solid var(--border-color);
    padding: 0.625rem 1rem;
    transition: all 0.3s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
}

/* Tables */
.table {
    border-collapse: separate;
    border-spacing: 0 0.5rem;
}

.table thead th {
    border: none;
    background-color: var(--light-bg);
    color: var(--text-dark);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 1rem;
}

.table tbody tr {
    background: var(--white);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;
}

.table tbody tr:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.table tbody td {
    border: none;
    padding: 1rem;
    vertical-align: middle;
}

.table tbody tr td:first-child {
    border-radius: 8px 0 0 8px;
}

.table tbody tr td:last-child {
    border-radius: 0 8px 8px 0;
}

/* Badges */
.badge {
    padding: 0.375rem 0.75rem;
    font-weight: 600;
    border-radius: 6px;
}

/* Progress Bar */
.progress {
    border-radius: 8px;
    overflow: hidden;
    background-color: #e2e8f0;
}

.progress-bar {
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}

/* Alerts */
.alert {
    border-radius: 12px;
    border: none;
    padding: 1rem 1.25rem;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Charts */
canvas {
    max-height: 300px;
}

/* Specific height for parts chart with 20 items */
#partsChart {
    height: 600px !important;
    max-height: 600px !important;
}

/* Compact styling for parts duration table with 20 entries on full width */
#partsDurationTable {
    font-size: 0.85rem;
}

#partsDurationTable thead th {
    padding: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
}

#partsDurationTable tbody td {
    padding: 0.4rem 0.5rem;
    line-height: 1.3;
}

#partsDurationTable tbody .badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
}

#partsDurationTable tbody tr:hover {
    background-color: #f8f9fa;
}

.card:has(#partsDurationTable) {
    overflow: hidden !important;
}

.card:has(#partsDurationTable) .card-body {
    overflow: hidden !important;
}

.card:has(#partsDurationTable) .table-responsive {
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
}

/* Compact styling for errors table with 16 entries */
#errorsTable {
    font-size: 0.8rem;
}

#errorsTable thead th {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
}

#errorsTable tbody td {
    padding: 0.35rem 0.5rem;
    line-height: 1.2;
}

#errorsTable tbody .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
}

#errorsTable tbody tr:hover {
    background-color: #f8f9fa;
}

.card:has(#errorsTable) {
    overflow: hidden !important;
}

.card:has(#errorsTable) .card-body {
    overflow: hidden !important;
}

.card:has(#errorsTable) .table-responsive {
    overflow: hidden !important;
    overflow-x: hidden !important;
    overflow-y: hidden !important;
}

/* Pagination */
.pagination .page-link {
    border-radius: 8px;
    margin: 0 0.25rem;
    border: 2px solid var(--border-color);
    color: var(--text-dark);
    font-weight: 600;
    transition: all 0.3s ease;
}

.pagination .page-link:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white);
    transform: translateY(-2px);
}

.pagination .page-item.active .page-link {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Loading Spinner */
.spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Content Views */
.content-view {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Shadows */
.shadow-sm {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
}

.shadow {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
}

/* Dropdown */
.dropdown-menu {
    border-radius: 12px;
    border: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 0.5rem;
}

.dropdown-item {
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.dropdown-item:hover {
    background-color: var(--primary-color);
    color: var(--white);
}

/* Utilities */
.text-primary {
    color: var(--primary-color) !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

/* Responsive */
@media (max-width: 768px) {
    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.5rem;
    }

    .table {
        font-size: 0.875rem;
    }

    .card-body {
        padding: 1rem;
    }
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    /* Can be implemented if needed */
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Print Styles */
@media print {
    /* Hide non-essential elements */
    .navbar,
    .btn,
    .pagination,
    #uploadView,
    #rmasView,
    #loadingIndicator,
    .no-print,
    .nav-link.active::after {
        display: none !important;
    }

    /* Show print-only elements */
    .print-only {
        display: block !important;
    }

    /* Page setup */
    @page {
        size: A4 portrait;
        margin: 1.5cm 1cm;
    }

    * {
        box-sizing: border-box;
    }

    body {
        background: white !important;
        color: black !important;
        font-size: 9pt;
        line-height: 1.3;
        margin: 0;
        padding: 0;
    }

    /* Container adjustments */
    .container-fluid {
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Cards */
    .card {
        box-shadow: none !important;
        border: 1px solid #999 !important;
        border-radius: 4px !important;
        page-break-inside: avoid;
        margin-bottom: 0.75rem !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    .card-header {
        background-color: #f5f5f5 !important;
        border-bottom: 1px solid #999 !important;
        padding: 0.3rem 0.5rem !important;
        font-size: 9pt;
        font-weight: bold;
    }

    .card-body {
        padding: 0.4rem !important;
        overflow: hidden !important;
    }

    /* Stats cards layout - 2x2 grid for better fit */
    .stat-card {
        break-inside: avoid;
        border: 1px solid #ddd !important;
        margin-bottom: 0.5rem !important;
    }

    .stat-card .card-body {
        padding: 0.5rem !important;
    }

    .stat-card h3 {
        font-size: 14pt !important;
    }

    .stat-card p,
    .stat-card small {
        font-size: 8pt !important;
    }

    .stat-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    /* Grid adjustments for print - Stack vertically for A4 portrait */
    .row {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .row.g-4 {
        margin-bottom: 0.5rem !important;
    }

    /* Stats cards - 2 per row for better space usage */
    #dashboardContent > .row:first-of-type .col-xl-3 {
        width: 49% !important;
        display: inline-block !important;
        vertical-align: top !important;
        float: left !important;
        padding: 0 !important;
        margin-right: 1% !important;
        margin-bottom: 0.5rem !important;
    }

    #dashboardContent > .row:first-of-type .col-xl-3:nth-child(2n) {
        margin-right: 0 !important;
    }

    /* Charts - 2 per row (Status/Aging and Customers/Repair Groups) */
    .row.g-4 .col-lg-6 {
        width: 49% !important;
        display: inline-block !important;
        vertical-align: top !important;
        float: left !important;
        padding: 0 !important;
        margin-right: 1% !important;
        margin-bottom: 0.75rem !important;
    }

    .row.g-4 .col-lg-6:nth-child(2n) {
        margin-right: 0 !important;
    }

    /* Other columns */
    .col-md-6,
    .col-12 {
        width: 100% !important;
        display: block !important;
        float: none !important;
        padding: 0 !important;
        margin-bottom: 0.75rem !important;
    }

    /* Clear floats */
    .row::after {
        content: "";
        display: table;
        clear: both;
    }

    /* Charts - constrain size for A4 */
    canvas {
        max-height: 220px !important;
        max-width: 100% !important;
        height: auto !important;
        width: 100% !important;
        display: block !important;
        page-break-inside: avoid;
    }

    /* Parts chart needs more height for 20 items */
    #partsChart {
        height: 500px !important;
        max-height: 500px !important;
    }

    /* Container for parts chart should be taller */
    .card:has(#partsChart) {
        min-height: 550px !important;
    }

    .card:has(#partsChart) .card-body {
        min-height: 500px !important;
    }

    /* Parts duration table for print with 20 entries on full width */
    #partsDurationTable {
        font-size: 7pt !important;
    }

    #partsDurationTable thead th {
        padding: 0.2rem 0.3rem !important;
        font-size: 7pt !important;
        line-height: 1.2 !important;
    }

    #partsDurationTable tbody td {
        padding: 0.15rem 0.3rem !important;
        line-height: 1.2 !important;
    }

    #partsDurationTable .badge {
        font-size: 6pt !important;
        padding: 0.1rem 0.25rem !important;
    }

    /* Compact errors table for print with 10 entries */
    #errorsTable {
        font-size: 7pt !important;
    }

    #errorsTable thead th {
        padding: 0.2rem 0.3rem !important;
        font-size: 7pt !important;
    }

    #errorsTable tbody td {
        padding: 0.15rem 0.3rem !important;
        line-height: 1.2 !important;
    }

    #errorsTable .badge {
        font-size: 6pt !important;
        padding: 0.1rem 0.25rem !important;
    }

    .card:has(#partsDurationTable) {
        page-break-inside: avoid !important;
    }

    /* Ensure chart containers don't overflow */
    .card:has(canvas) {
        page-break-inside: avoid;
        width: 100% !important;
        overflow: hidden !important;
    }

    .card:has(canvas) .card-body {
        width: 100% !important;
        overflow: hidden !important;
        padding: 0.4rem !important;
    }

    /* Tables */
    .table-responsive {
        overflow: visible !important;
        width: 100% !important;
    }

    .table {
        border-collapse: collapse !important;
        border-spacing: 0 !important;
        font-size: 7pt;
        width: 100% !important;
        table-layout: fixed !important;
    }

    .table thead th {
        background-color: #f0f0f0 !important;
        border: 1px solid #999 !important;
        padding: 0.25rem !important;
        font-weight: bold;
        font-size: 7pt;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
        word-wrap: break-word;
    }

    .table tbody tr {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }

    .table tbody td {
        border: 1px solid #ddd !important;
        padding: 0.25rem !important;
        font-size: 7pt;
        word-wrap: break-word;
        overflow: hidden;
    }

    /* Make strong text slightly larger for readability */
    .table strong {
        font-size: 7.5pt;
    }

    /* Badges - smaller for print */
    .badge {
        border: 1px solid #999 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
        font-size: 6.5pt !important;
        padding: 0.15rem 0.3rem !important;
    }

    /* Text colors */
    .text-primary,
    .text-success,
    .text-info,
    .text-warning,
    .text-danger,
    .text-muted {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    /* Background colors for badges and stat icons */
    .bg-primary,
    .bg-success,
    .bg-info,
    .bg-warning,
    .bg-danger,
    .bg-secondary {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    /* Page breaks */
    .page-break-after {
        page-break-after: always;
    }

    .page-break-before {
        page-break-before: always;
    }

    /* Prevent page break inside rows */
    .row.g-4 {
        page-break-inside: avoid;
    }

    /* Avoid breaking these elements */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        page-break-inside: avoid;
    }

    /* Typography for print */
    h1 { font-size: 16pt; margin-bottom: 0.5rem; }
    h2 { font-size: 14pt; margin-bottom: 0.4rem; }
    h3 { font-size: 12pt; margin-bottom: 0.3rem; }
    h4 { font-size: 11pt; margin-bottom: 0.3rem; }
    h5 { font-size: 10pt; margin-bottom: 0.2rem; }

    /* Remove hover effects */
    .card:hover,
    .table tbody tr:hover,
    .btn:hover {
        transform: none !important;
        box-shadow: none !important;
    }

    /* Force visibility of dashboard content */
    #dashboardContent {
        display: block !important;
        width: 100% !important;
    }

    /* Print date styling */
    #print-date {
        font-weight: bold;
    }

    .print-only {
        margin-bottom: 1rem !important;
    }

    .print-only hr {
        border-top: 2px solid #333 !important;
        margin: 0.5rem 0 !important;
    }

    /* Ensure all content fits within page width */
    * {
        max-width: 100% !important;
    }

    /* Specific adjustments for better layout */
    .mb-4 {
        margin-bottom: 0.5rem !important;
    }

    /* Remove Bootstrap gutters that cause overflow */
    .g-4 {
        --bs-gutter-x: 0 !important;
        --bs-gutter-y: 0 !important;
    }
}