:root {
    --primary: #4e73df; --secondary: #858796; --success: #1cc88a; --info: #36b9cc;
    --warning: #f6c23e; --danger: #e74a3b; --light: #f8f9fc; --dark: #5a5c69;
}
body { background-color: var(--light); color: #333; font-family: 'Segoe UI', sans-serif; margin: 0; }
.container { width: 95%; max-width: 1400px; margin: 0 auto; padding: 20px; }
header { background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%); color: white; padding: 20px 0; border-radius: 0 0 10px 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 30px; }
.header-content { display: flex; justify-content: space-between; align-items: center; max-width: 1400px; margin: 0 auto; padding: 0 20px;}
.logo { font-size: 24px; font-weight: bold; }
nav ul { display: flex; list-style: none; margin: 0; padding: 0; }
nav ul li { margin-left: 20px; }
nav ul li a { color: white; text-decoration: none; font-weight: 500; padding: 5px 10px; border-radius: 4px; transition: background 0.3s; }
nav ul li a.active, nav ul li a:hover { background: rgba(255, 255, 255, 0.2); }
.card { background: white; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); padding: 25px; margin-bottom: 25px; }
.card-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--light); padding-bottom: 15px; margin-bottom: 20px;}
.card-header h3 { margin: 0; color: var(--primary); }
.btn { display: inline-block; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; font-weight: 500; transition: background 0.3s; color: white !important; font-size: 14px; margin-right: 10px; }
.btn-success { background-color: var(--success); } .btn-success:hover { background-color: #17a673; }
.btn-danger { background-color: var(--danger); } .btn-danger:hover { background-color: #d02a1a; }
.btn-info { background-color: var(--info); } .btn-info:hover { background-color: #2c9faf; }
.btn-secondary { background-color: var(--secondary); } .btn-secondary:hover { background-color: #717384; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
.form-control { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; }
.alert { padding: 15px; border-radius: 4px; margin-bottom: 20px; border: 1px solid transparent; }
.alert-success { background-color: #d4edda; color: #155724; border-color: #c3e6cb; }
.alert-error { background-color: #f8d7da; color: #721c24; border-color: #f5c6cb; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }
th { background-color: var(--primary); color: white; }
tr:hover { background-color: #f5f5f5; }
.payslip { border: 1px solid #ccc; padding: 20px; margin-bottom: 20px; border-radius: 8px; }
.payslip h3 { text-align: center; color: var(--dark); }
.payslip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.payslip-details p { margin: 5px 0; }
.payslip-details strong { display: inline-block; width: 150px; }
.payslip-summary { text-align: right; margin-top: 20px; }
/* --- PRINT STYLES --- */
@media print {
    /* Hide everything that should not be printed */
    .no-print {
        display: none !important;
    }
    
    /* Reset body for printing */
    body {
        background-color: #fff;
        font-size: 10pt;
    }
    
    .container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    /* Styles for printing MULTIPLE payslips (2 per page) */
    .payslip-print-container .payslip {
        width: 100%;
        display: block;
        page-break-inside: avoid; /* Try not to split a payslip over two pages */
        margin-bottom: 15mm; /* Space between slips */
    }
    
    /* Styles for printing a SINGLE payslip */
    .single-payslip-container {
        margin-top: -50px; /* Adjust top margin for better centering */
    }
}

/* Screen-only styles for the multi-print layout */
@media screen {
    .payslip-print-container {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
        gap: 20px;
    }
}

/* Mobile First Responsive Design */
* {
    box-sizing: border-box;
}

body {
    font-size: 14px;
    line-height: 1.4;
}

.container {
    width: 100%;
    padding: 0 15px;
    margin: 0 auto;
}

/* Header Mobile Styles */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        padding: 10px 0;
    }
    
    .logo {
        font-size: 1.2rem;
        margin-bottom: 10px;
        text-align: center;
    }
    
    .academic-year-selector {
        margin: 10px 0;
        width: 100%;
    }
    
    .academic-year-selector form {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .academic-year-selector select {
        width: 100%;
        margin: 5px 0;
    }
    
    nav ul {
        flex-direction: column;
        width: 100%;
    }
    
    nav ul li {
        margin: 2px 0;
        width: 100%;
    }
    
    nav ul li a {
        padding: 8px;
        text-align: center;
        display: block;
    }
    
    .dropdown-content {
        position: static;
        width: 100%;
        box-shadow: none;
    }
}

/* Card and Form Mobile Styles */
@media (max-width: 768px) {
    .card {
        margin: 10px 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .card-header h3 {
        font-size: 1.3rem;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .form-inline {
        flex-direction: column;
    }
    
    .form-inline .form-group {
        margin-bottom: 10px;
        width: 100%;
    }
    
    .form-control {
        width: 100%;
    }
    
    .btn {
        width: 100%;
        margin: 5px 0;
    }
}

/* Table Mobile Styles */
@media (max-width: 768px) {
    .table-responsive {
        border: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px; /* Force horizontal scroll on small screens */
        font-size: 12px;
    }
    
    th, td {
        padding: 4px 6px;
        white-space: nowrap;
    }
    
    /* Stack table headers for better mobile reading */
    .mobile-stack thead {
        display: none;
    }
    
    .mobile-stack tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 5px;
        padding: 10px;
    }
    
    .mobile-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 5px 0;
    }
    
    .mobile-stack tbody td::before {
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
        margin-right: 10px;
    }
}

/* Payroll Form Mobile Styles */
@media (max-width: 768px) {
    table {
        display: block;
        width: 100%;
    }
    
    table thead {
        display: none;
    }
    
    table tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 10px;
        background: #f9f9f9;
    }
    
    table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 8px 0;
        border-bottom: 1px solid #eee;
    }
    
    table tbody td:last-child {
        border-bottom: none;
    }
    
    table tbody td::before {
        content: attr(data-label);
        font-weight: bold;
        font-size: 0.9rem;
        color: #333;
        min-width: 120px;
    }
    
    .form-control {
        min-width: 120px;
        text-align: right;
    }
}

/* Print Styles for Mobile */
@media print and (max-width: 768px) {
    body {
        font-size: 10pt;
    }
    
    .payslip-grid-print-container {
        grid-template-columns: 1fr;
    }
    
    .payslip-compact {
        page-break-inside: avoid;
        margin-bottom: 10px;
    }
}

/* Utility Classes */
.mobile-hidden {
    display: none;
}

.mobile-visible {
    display: block;
}

@media (min-width: 769px) {
    .mobile-hidden {
        display: block;
    }
    
    .mobile-visible {
        display: none;
    }
}

/* Improved Button Styles for Mobile */
.btn {
    touch-action: manipulation; /* Better touch handling */
    min-height: 44px; /* Minimum touch target size */
    padding: 10px 15px;
}

/* Form improvements */
select, input, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px; /* Better touch targets */
}

/* Navigation improvements */
nav ul li a {
    padding: 12px 8px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}