/* CSS Reset & Variables */
:root {
    --primary: #1976d2;
    --primary-dark: #1565c0;
    --primary-light: #42a5f5;
    --accent: #ff9800;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --text-primary: #212121;
    --text-secondary: #757575;
    --background: #f5f5f5;
    --surface: #ffffff;
    --border: #e0e0e0;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-sm: 4px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 500;
    margin-bottom: 0.5rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navigation */
.navbar {
    background: var(--primary);
    color: white;
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    text-decoration: none;
}

.navbar-nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.navbar-nav a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.navbar-nav a:hover {
    background: rgba(255,255,255,0.1);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255,255,255,0.9);
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #43a047;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #e53935;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--background);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}

.form-control:disabled {
    background: var(--background);
    cursor: not-allowed;
}

.form-control.is-invalid {
    border-color: var(--danger);
}

.form-error {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Checkbox */
.form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 0.125rem;
    cursor: pointer;
}

.form-check-label {
    cursor: pointer;
    font-size: 0.875rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.table tr:hover {
    background: #fafafa;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
}

.badge-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-warning {
    background: #fff3e0;
    color: #ef6c00;
}

.badge-danger {
    background: #ffebee;
    color: #c62828;
}

.badge-info {
    background: #e3f2fd;
    color: #1565c0;
}

/* Statistics Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Alerts */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.alert-danger {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

.alert-warning {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffe0b2;
}

.alert-info {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
}

/* Loan Acceptance Page */
.acceptance-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 2rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.acceptance-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    overflow: hidden;
}

.acceptance-header {
    background: var(--primary);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

.acceptance-body {
    padding: 2rem;
}

.loan-detail {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.loan-detail:last-of-type {
    border-bottom: none;
}

.loan-detail-label {
    color: var(--text-secondary);
}

.loan-detail-value {
    font-weight: 600;
}

.loan-detail-value.total {
    color: var(--primary);
    font-size: 1.25rem;
}

.terms-box {
    background: var(--background);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 1.5rem 0;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 1.5rem;
}

.pagination-btn {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--background);
}

.pagination-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Filters */
.filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filters .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-backdrop.show {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* WhatsApp Message Box */
.whatsapp-box {
    background: #dcf8c6;
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 1rem;
    position: relative;
}

.whatsapp-box pre {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.875rem;
    margin: 0;
}

.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* Filter Tabs */
.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.filter-tab:hover {
    background: var(--background);
    border-color: var(--primary);
    color: var(--text-primary);
}

.filter-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    background: rgba(0,0,0,0.1);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.filter-tab.active .tab-count {
    background: rgba(255,255,255,0.2);
}

.tab-count-danger {
    background: #ffebee;
    color: var(--danger);
}

.filter-tab.active .tab-count-danger {
    background: rgba(255,255,255,0.2);
    color: white;
}

.tab-count-success {
    background: #e8f5e9;
    color: var(--success);
}

.filter-tab.active .tab-count-success {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* Status Indicators */
.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
    vertical-align: middle;
}

.status-overdue {
    background: var(--danger);
    animation: pulse 1.5s ease-in-out infinite;
}

.status-due-soon {
    background: var(--warning);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Row Status Colors */
.table tbody tr.row-overdue {
    background: #fff5f5;
    border-left: 3px solid var(--danger);
}

.table tbody tr.row-overdue:hover {
    background: #ffebee;
}

.table tbody tr.row-due-soon {
    background: #fffbf0;
    border-left: 3px solid var(--warning);
}

.table tbody tr.row-due-soon:hover {
    background: #fff3e0;
}

.table tbody tr.row-completed {
    background: #f0fdf4;
    opacity: 0.8;
}

.table tbody tr.row-completed:hover {
    background: #e8f5e9;
}

/* Aged Receivables Grid */
.aged-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
}

.aged-card {
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    border: 2px solid;
}

.aged-header {
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.aged-amount {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.aged-count {
    font-size: 0.875rem;
    opacity: 0.9;
}

.aged-label {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.5rem;
}

.aged-current {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #2e7d32;
}

.aged-30 {
    background: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

.aged-60 {
    background: #fff8e1;
    border-color: #ffc107;
    color: #ff8f00;
}

.aged-90 {
    background: #ffebee;
    border-color: #f44336;
    color: #c62828;
}

.aged-over90 {
    background: #fce4ec;
    border-color: #e91e63;
    color: #ad1457;
}

/* Text Colors */
.text-warning { color: var(--warning); }

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Responsive - Tablet */
@media (max-width: 768px) {
    .navbar {
        padding: 0.75rem 1rem;
    }

    .navbar-content {
        flex-direction: column;
        gap: 0.75rem;
    }

    .navbar-nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

    .navbar-nav a {
        padding: 0.4rem 0.75rem;
        font-size: 0.875rem;
    }

    .navbar-user {
        flex-wrap: wrap;
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .table {
        font-size: 0.8125rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
    }

    .filters {
        flex-direction: column;
    }

    .filters .form-group {
        width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 1rem;
    }

    .modal {
        width: 95%;
        margin: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }

    .d-flex.justify-between {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .d-flex.justify-between .btn {
        width: 100%;
    }

    .login-card {
        padding: 1.5rem;
        margin: 0.5rem;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .pagination-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .filter-tabs {
        gap: 0.4rem;
    }

    .filter-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
        flex: 1;
        justify-content: center;
    }

    .tab-count {
        min-width: 1.25rem;
        height: 1.25rem;
        font-size: 0.7rem;
    }

    .aged-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .aged-card:last-child {
        grid-column: span 2;
    }

    .aged-amount {
        font-size: 1.25rem;
    }
}

/* Responsive - Mobile (increased breakpoint to 768px for tables) */
@media (max-width: 768px) {
    /* Mobile table - card style */
    .table-container {
        margin: 0 -0.5rem;
    }

    .table thead {
        display: none !important;
    }

    .table tbody tr {
        display: block !important;
        background: var(--surface);
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        border-radius: var(--radius-sm);
        box-shadow: var(--shadow);
        border: none;
    }

    .table tbody tr:hover {
        background: var(--surface);
    }

    .table tbody td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border);
        text-align: right;
    }

    .table tbody td:last-child {
        border-bottom: none;
        padding-top: 0.75rem;
    }

    .table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        font-size: 0.7rem;
        text-align: left;
        flex-shrink: 0;
        margin-right: 1rem;
    }

    .table-actions {
        flex-direction: row;
        justify-content: flex-end;
        width: 100%;
        gap: 0.5rem;
    }

    .table-actions .btn {
        flex: 1;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 0.9375rem;
    }

    .container {
        padding: 0 0.75rem;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    .navbar-nav {
        width: 100%;
        justify-content: space-around;
    }

    .navbar-nav a {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem;
        text-align: center;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .btn-sm {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    .card-header {
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .acceptance-body {
        padding: 1rem;
    }

    .loan-detail {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .loan-detail-value.total {
        font-size: 1.1rem;
    }

    .modal-header {
        padding: 0.75rem 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }

    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.1rem; }
    h3 { font-size: 1rem; }
}

/* Very small screens */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .navbar-nav {
        flex-direction: column;
        width: 100%;
    }

    .navbar-nav a {
        text-align: center;
        padding: 0.5rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }
}
