:root {
    --bg-main: #020617;
    --bg-sidebar: #0f172a;
    --bg-card: #0f172a;
    --bg-card-hover: #1e293b;
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-dark: #2563eb;
    --secondary: #8b5cf6;
    --accent: #06b6d4;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.08);
    --border-hover: rgba(148, 163, 184, 0.2);
    --success: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --card-shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    --sidebar-gradient: linear-gradient(180deg, #0f172a 0%, #020617 100%);
    --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    font-family: 'Inter', sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

.dashboard-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: visible;
}

/* Scrollbar Styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.4); }

/* Top Navigation Bar */
.top-bar {
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    flex-shrink: 0;
}

.top-bar-inner {
    display: flex;
    justify-content: flex-start;
    gap: 40px;
    align-items: center;
    width: 100%;
    max-width: 1600px;
    padding: 0 40px;
    margin: 0 auto;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 48px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 1px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i { width: 18px; height: 18px; }

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-light);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.update-info-top {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.03);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

#last-update-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.btn-refresh-small {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

.btn-refresh-small:hover { transform: rotate(180deg); }

.search-container {
    position: relative;
    width: 280px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 16px;
    height: 16px;
}

#global-search {
    width: 100%;
    padding: 10px 16px 10px 40px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: #fff;
    font-size: 0.85rem;
}

#global-search:focus {
    outline: none;
    background: rgba(15, 23, 42, 0.9);
    border-color: var(--primary);
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    left: auto;
    right: 0;
    width: 350px;
    background: #1e293b;
    border: 2px solid var(--primary);
    border-radius: 16px;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.7);
    z-index: 9999;
    max-height: 450px;
    overflow-y: auto;
    padding: 8px;
    animation: fadeIn 0.2s ease-out;
}

.search-result-item {
    padding: 14px 18px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
    margin-bottom: 4px;
}

.search-result-item:last-child { border-bottom: none; }

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.search-result-item .item-name {
    font-weight: 700;
    color: #fff;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.search-result-item .item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content Area */
.main-content {
    flex: 1;
    min-height: 0;
    overflow-y: visible;
    padding-bottom: 80px;
    background: radial-gradient(circle at top right, #0f172a 0%, #020617 40%);
}

.content-section {
    padding: 24px 40px 80px 40px;
    width: 100%;
    box-sizing: border-box;
    max-width: 1600px;
    margin: 0 auto;
    overflow: visible;
}

.section-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    gap: 20px;
}

.section-header-filters {
    display: flex;
    gap: 16px;
}

.header-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-filter-group label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-select {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    color: white;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
    min-width: 150px;
}

.header-select:focus {
    border-color: var(--primary);
}

.section-header h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.section-header p {
    font-size: 0.85rem;
    margin-top: 0;
    opacity: 0.7;
}

/* Stats Grid & Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: rgba(15, 23, 42, 0.6);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.stat-card:hover {
    transform: translateY(-5px);
    background: rgba(30, 41, 59, 0.4);
    border-color: var(--primary);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.stat-icon.portfolio { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.stat-icon.arrears { background: rgba(244, 63, 94, 0.1); color: #f43f5e; }
.stat-icon.efficiency { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.stat-icon.par { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.stat-icon.active-loans { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }

.stat-label { font-size: 0.75rem; color: var(--text-muted); }
.stat-data h2 {
    margin: 2px 0 0;
    font-size: 1.25rem;
}

/* Charts Section */
.charts-row {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
    height: 300px;
}

.chart-container h3 {
    margin: 0 0 16px;
    font-size: 1rem;
}

.chart-wrapper {
    position: relative;
    height: 200px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.arrears-rate-box {
    text-align: center;
    margin-top: 10px;
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    justify-content: center;
    gap: 12px;
    align-items: center;
}

.arrears-rate-box .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.arrears-rate-box .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--danger);
}

/* Table Design */
.table-container {
    background: var(--bg-card);
    border-radius: 20px;
    border: 1px solid var(--border);
    overflow: auto;
    box-shadow: var(--card-shadow);
    width: 100%;
    max-width: 100%;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }

th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    padding: 8px 10px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
}

td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-main);
}

tr:last-child td { border-bottom: none; }

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Modal / Profile Styles */
.profile-card {
    background: #0f172a;
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 1000px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
}

#customer-profile-content .profile-card {
    max-width: 100%;
    width: 100%;
    max-height: none;
    overflow: visible;
    box-sizing: border-box;
}

.profile-banner {
    background: var(--primary-gradient);
    padding: 48px 40px;
}

.profile-avatar-large {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-radius: 30px;
    font-size: 2.5rem;
}

.detail-card {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(12px);
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 24px;
    transition: all 0.3s ease;
}

.detail-card:hover {
    border-color: rgba(59, 130, 246, 0.4);
    background: rgba(30, 41, 59, 0.65);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.profile-card {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 28px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.profile-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9));
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 28px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.profile-avatar-large {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    padding: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
    flex-shrink: 0;
}

.profile-avatar-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #60a5fa;
}

.detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    gap: 16px;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row .label {
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 500;
    min-width: 130px;
    flex-shrink: 0;
}

.detail-row .value {
    font-size: 0.9rem;
    color: #f1f5f9;
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

/* Buttons */
.btn-generate {
    background: var(--primary-gradient);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-generate:hover {
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.5);
}

.badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.7rem;
}

.badge-success { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-danger { background: rgba(244, 63, 94, 0.1); color: #f43f5e; border: 1px solid rgba(244, 63, 94, 0.2); }

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

.content-section {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: var(--border-hover);
}

.pagination-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 20px;
}

.pagination-controls button {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

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

.pagination-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    margin-left: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Reporting Section Specifics */
.report-tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    background: rgba(15, 23, 42, 0.4);
    padding: 6px;
    border-radius: 14px;
    width: fit-content;
    border: 1px solid var(--border);
}

.report-tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-tab-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.report-tab-btn.active {
    background: var(--bg-card);
    color: var(--primary-light);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.report-filter-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
}

.report-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    align-items: flex-end;
}

.report-filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.report-filter-group label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.report-input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-main);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.report-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.9);
}

.btn-generate {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.btn-view {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-light);
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.report-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.report-stat-card {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.report-stat-card:hover {
    transform: translateY(-5px);
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(255, 255, 255, 0.1);
}

.par-card:hover {
    transform: translateY(-6px) !important;
    background: rgba(30, 41, 59, 0.7) !important;
}


.report-stat-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.report-stat-card.success::before { background: #10b981; }
.report-stat-card.info::before { background: #3b82f6; }
.report-stat-card.warning::before { background: #f59e0b; }
.report-stat-card.danger::before { background: #f43f5e; }
.report-stat-card.lost::before { background: #ef4444; }
.report-stat-card.arrears::before { background: #8b5cf6; }

.report-stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.report-stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: 4px;
}

.report-stat-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.charts-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
    margin-top: 24px;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--card-shadow);
}

.chart-container h3 {
    margin-top: 0;
    margin-bottom: 24px;
    font-size: 1rem;
    color: var(--text-main);
}

.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: auto;
    max-height: 70vh;
    box-shadow: var(--card-shadow);
    width: 100%;
    max-width: 100%;
}

.table-container table {
    min-width: 1200px;
}

.hidden { display: none !important; }

/* Modal & Overlay Styles */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

/* Loader Styles */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Extra utility for status badges in reports */
.status-badge {
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-block;
    text-align: center;
}
.status-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.status-danger { background: rgba(244, 63, 94, 0.15); color: #f87171; border: 1px solid rgba(244, 63, 94, 0.3); }
.status-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }

.full-width-table {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-top: 20px;
}
.full-width-table table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.full-width-table th {
    position: sticky;
    top: 0;
    background: #1e293b;
    z-index: 10;
    text-align: left;
    padding: 16px 12px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #cbd5e1;
    border-bottom: 2px solid var(--border);
}
.full-width-table td {
    border-bottom: 1px solid rgba(255,255,255,0.05);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.full-width-table tr:hover {
    background: rgba(255,255,255,0.02);
}

/* Data Management Styles */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.upload-card {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.2s;
    position: relative;
}

.upload-card:hover {
    background: rgba(30, 41, 59, 0.6);
    border-color: var(--primary);
}

.upload-card.empty {
    border-style: dashed;
    border-width: 2px;
}
.upload-card.warning {
    border-color: var(--warning);
    border-style: dashed;
    border-width: 2px;
    background: rgba(245, 158, 11, 0.03);
}

.upload-card h4 {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-main);
}

.upload-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    font-weight: 600;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.status-online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-indicator.status-offline { background: var(--text-muted); }
.status-indicator.status-warning { background: var(--warning); box-shadow: 0 0 8px var(--warning); }

.file-info {
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.75rem;
}

.file-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--primary-light);
    font-weight: 600;
    margin-bottom: 4px;
}

.file-meta {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.upload-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.btn-upload-small {
    flex: 1;
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-light);
    border: 1px solid rgba(59, 130, 246, 0.2);
    padding: 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

.btn-delete-small {
    background: rgba(244, 63, 94, 0.1);
    color: var(--danger);
    border: 1px solid rgba(244, 63, 94, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.health-alerts-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 600px;
    overflow-y: auto;
    padding-right: 8px;
}

.health-alert-item {
    background: rgba(244, 63, 94, 0.05);
    border-left: 4px solid var(--danger);
    padding: 16px;
    border-radius: 0 12px 12px 0;
    position: relative;
    animation: slideInRight 0.3s ease-out;
}

.health-alert-item.warning {
    background: rgba(245, 158, 11, 0.05);
    border-left-color: var(--warning);
}

.health-alert-item h5 {
    margin: 0 0 4px 0;
    font-size: 0.8rem;
    color: #fff;
}

.health-alert-item p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.health-alert-date {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-family: monospace;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(244, 63, 94, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

/* ==========================================================================
   Responsive Styling for Dashboard Layout
   ========================================================================== */

@media (max-width: 1400px) {
    .top-bar-inner {
        padding: 0 20px;
    }
    .top-bar-left {
        gap: 20px;
    }
    .nav-item {
        padding: 8px 12px;
        font-size: 0.8rem;
        gap: 8px;
    }
    .nav-item i {
        width: 16px;
        height: 16px;
    }
    .top-bar-right {
        gap: 16px;
    }
    .search-container {
        width: 180px;
    }
    .update-info-top {
        padding: 4px 10px;
    }
    #last-update-time {
        display: none; /* Hide timestamp on laptops/desktops <= 1400px to avoid nav clipping */
    }
}

@media (max-width: 1200px) {
    .top-bar-left {
        gap: 12px;
    }
    .nav-item {
        padding: 8px 10px;
        gap: 6px;
    }
    .nav-item span {
        font-size: 0.75rem;
    }
    .logo span {
        font-size: 0.95rem;
    }
    .search-container {
        width: 140px;
    }
    #last-update-time {
        display: none; /* Hide timestamp text to save space, keeping refresh btn */
    }
}

@media (max-width: 1024px) {
    .nav-item span {
        display: none; /* Hide text, only show icons on tablets */
    }
    .nav-item {
        padding: 10px;
    }
    .logo span {
        display: none;
    }
    .logo::after {
        content: "JI";
        font-weight: 800;
        font-size: 1.1rem;
        background: var(--primary-gradient);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    .charts-row {
        grid-template-columns: 1fr;
    }
}

/* Force layout reset for top-bar elements to group them together on the left */
.top-bar-inner { justify-content: flex-start !important; gap: 40px !important; }
.top-bar-right { margin-left: 0 !important; justify-content: flex-start !important; flex: 0 0 auto !important; width: max-content !important; gap: 16px !important; }
.search-container { margin-left: 0 !important; margin-right: 0 !important; flex: 0 0 auto !important; }
.update-info-top { margin-right: 0 !important; margin-left: 0 !important; flex: 0 0 auto !important; }


/* Override max-height to show full table without internal scroll */
.table-responsive, .table-container, .card {
    max-height: none !important;
    overflow-y: visible !important;
}

.table-responsive::-webkit-scrollbar {
    height: 10px;
    width: 8px;
}
.table-responsive::-webkit-scrollbar-track, .routes-sticky-wrap::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.8);
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb, .routes-sticky-wrap::-webkit-scrollbar-thumb {
    background: #3b82f6;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb:hover, .routes-sticky-wrap::-webkit-scrollbar-thumb:hover {
    background: #60a5fa;
}

/* Live Route Tracking Sticky Left Columns & Freeze Panes - Light Table Theme */
.routes-sticky-wrap {
    max-height: calc(100vh - 120px) !important;
    overflow: auto !important;
    position: relative !important;
    border-radius: 8px !important;
    border: 1px solid #cbd5e1 !important;
    background: #ffffff !important;
}

.routes-table-sticky {
    background: #ffffff !important;
    color: #0f172a !important;
}

.routes-table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f1f5f9 !important;
    color: #334155 !important;
    font-weight: 700 !important;
    border-bottom: 2px solid #cbd5e1 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

.routes-table-sticky td {
    color: #0f172a !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

.routes-table-sticky td b,
.routes-table-sticky td strong {
    color: #0f172a !important;
}

.routes-table-sticky td span:not(.badge) {
    color: #0f172a;
}

.routes-table-sticky td span[style*="var(--text-main)"] {
    color: #0f172a !important;
}

.routes-table-sticky td span[style*="var(--text-muted)"],
.routes-table-sticky td div[style*="var(--text-muted)"] {
    color: #475569 !important;
}

.routes-table-sticky select.report-input,
.routes-table-sticky input.report-input {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1 !important;
}

.routes-table-sticky select.report-input:focus,
.routes-table-sticky input.report-input:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.r-col-1 { position: sticky; left: 0px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 35px; width: 35px; }
.r-col-2 { position: sticky; left: 35px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 100px; }
.r-col-3 { position: sticky; left: 135px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 100px; }
.r-col-4 { position: sticky; left: 235px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 90px; }
.r-col-5 { position: sticky; left: 325px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 170px; }
.r-col-6 { position: sticky; left: 495px; z-index: 15; background: var(--row-sticky-bg, #ffffff) !important; min-width: 85px; border-right: 2px solid #3b82f6 !important; box-shadow: 4px 0 8px rgba(0,0,0,0.06); }

thead th.r-col-1 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; }
thead th.r-col-2 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; }
thead th.r-col-3 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; }
thead th.r-col-4 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; }
thead th.r-col-5 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; }
thead th.r-col-6 { z-index: 35 !important; background: #e2e8f0 !important; color: #1e293b !important; border-right: 2px solid #3b82f6 !important; box-shadow: 4px 0 8px rgba(0,0,0,0.06); }

/* Live Route Table Row Status Colors - Light Theme Pastels */
.route-row {
    transition: background 0.15s ease;
}
.route-row-pending {
    background-color: #fffbeb !important;
    --row-sticky-bg: #fef3c7;
}
.route-row-pending:hover {
    background-color: #fef3c7 !important;
}
.route-row-done {
    background-color: #ecfdf5 !important;
    --row-sticky-bg: #d1fae5;
}
.route-row-done:hover {
    background-color: #d1fae5 !important;
}
.route-row-promised {
    background-color: #eef2ff !important;
    --row-sticky-bg: #e0e7ff;
}
.route-row-promised:hover {
    background-color: #e0e7ff !important;
}
.route-row-arrived {
    background-color: #eff6ff !important;
    --row-sticky-bg: #dbeafe;
}
.route-row-arrived:hover {
    background-color: #dbeafe !important;
}
.route-row-paid {
    background-color: #f0fdf4 !important;
    --row-sticky-bg: #dcfce7;
}
.route-row-paid:hover {
    background-color: #dcfce7 !important;
}
.route-row-notfound {
    background-color: #fef2f2 !important;
    --row-sticky-bg: #fee2e2;
}
.route-row-notfound:hover {
    background-color: #fee2e2 !important;
}
.route-row-skipped {
    background-color: #f8fafc !important;
    --row-sticky-bg: #f1f5f9;
}
.route-row-skipped:hover {
    background-color: #f1f5f9 !important;
}



/* ========================================================
   STICKY TABLE & CLEAN PROMISE DIRECTORY LAYOUT
   ======================================================== */
.table-container th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #0f172a !important;
}

/* Sticky First Column (Customer & Loan Info) */
.table-container table.sticky-first-col td:first-child,
.table-container table.sticky-first-col th:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: #0b1120 !important;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.4);
}

/* Intersection cell: Top Left Corner Header */
.table-container table.sticky-first-col th:first-child {
    z-index: 30 !important;
    background-color: #0f172a !important;
}

/* Hover background for sticky column cells */
.table-container table.sticky-first-col tr:hover td:first-child {
    background-color: #151e32 !important;
}

/* Action Cell Buttons in Table */
.action-cell-flex {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-wa-sm {
    background: #25D366;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    transition: transform 0.15s, background 0.15s;
}
.btn-wa-sm:hover { transform: translateY(-1px); background: #20ba5a; }

.btn-sms-sm {
    background: #0284c7;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: transform 0.15s, background 0.15s;
}
.btn-sms-sm:hover { transform: translateY(-1px); background: #0369a1; }

.btn-del-sm {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: transform 0.15s, background 0.15s;
}
.btn-del-sm:hover { background: rgba(239, 68, 68, 0.25); }

/* ========================================================
   Notice Table: Freeze Panes, Sticky Header & Compact Layout
   ======================================================== */
#notice-table-container {
    height: calc(100vh - 100px) !important;
    max-height: calc(100vh - 100px) !important;
    min-height: 520px !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    position: relative;
    width: 100%;
}

#notice-table tbody tr:last-child td {
    padding-bottom: 28px !important;
}

#notice-table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
#notice-table-container::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}
#notice-table-container::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.5);
    border-radius: 4px;
}
#notice-table-container::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.8);
}

#notice-table {
    width: 100%;
    min-width: 1250px;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

/* Sticky Header */
#notice-table thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 30 !important;
    background: #0b132b !important;
    color: var(--text-muted, #94a3b8);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 8px 8px !important;
    text-align: left;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
}

/* Compact Body Cells */
#notice-table tbody td {
    padding: 6px 8px !important;
    font-size: 0.8rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(15, 23, 42, 0.75);
}

/* Sticky Column 1: Checkbox */
#notice-table thead th:nth-child(1) {
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 40 !important;
    background: #0b132b !important;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    text-align: center;
}
#notice-table tbody td:nth-child(1) {
    position: sticky !important;
    left: 0 !important;
    z-index: 20 !important;
    background: #0b132b !important;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    text-align: center;
}

/* Sticky Column 2: Customer Name */
#notice-table thead th:nth-child(2) {
    position: sticky !important;
    left: 36px !important;
    top: 0 !important;
    z-index: 40 !important;
    background: #0b132b !important;
    min-width: 180px;
    max-width: 220px;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.4);
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
}
#notice-table tbody td:nth-child(2) {
    position: sticky !important;
    left: 36px !important;
    z-index: 20 !important;
    background: #0b132b !important;
    min-width: 180px;
    max-width: 220px;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.4);
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
    white-space: normal !important;
    word-break: break-word;
}

/* Hover Rows preserving sticky columns */
#notice-table tbody tr:hover td {
    background: rgba(30, 41, 59, 0.95) !important;
}
#notice-table tbody tr:hover td:nth-child(1),
#notice-table tbody tr:hover td:nth-child(2) {
    background: #1e293b !important;
}

/* ========================================================
   Report Table (Arrears List): Sticky Header & Freeze Layout
   ======================================================== */
#report-table-container {
    height: calc(100vh - 120px) !important;
    max-height: calc(100vh - 120px) !important;
    min-height: 520px !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
    position: relative;
    width: 100%;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.6);
}

#report-table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
#report-table-container::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}
#report-table-container::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.5);
    border-radius: 4px;
}
#report-table-container::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.8);
}

#report-table {
    width: 100%;
    min-width: 1400px;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

/* Sticky Header (Freeze Row 1) */
#report-table thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 35 !important;
    background: #0b132b !important;
    color: var(--text-muted, #94a3b8);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 8px 8px !important;
    text-align: left;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
}

/* Compact Body Cells */
#report-table tbody td {
    padding: 6px 8px !important;
    font-size: 0.8rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(15, 23, 42, 0.75);
}

/* Sticky Column 1: Checkbox */
#report-table thead th:nth-child(1) {
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 45 !important;
    background: #0b132b !important;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    text-align: center;
}
#report-table tbody td:not([colspan]):nth-child(1) {
    position: sticky !important;
    left: 0 !important;
    z-index: 20 !important;
    background: #0b132b !important;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
    text-align: center;
}

/* Sticky Column 2: Index / # */
#report-table thead th:nth-child(2) {
    position: sticky !important;
    left: 36px !important;
    top: 0 !important;
    z-index: 45 !important;
    background: #0b132b !important;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: center;
}
#report-table tbody td:not([colspan]):nth-child(2) {
    position: sticky !important;
    left: 36px !important;
    z-index: 20 !important;
    background: #0b132b !important;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: center;
}

/* Sticky Column 3: Customer Name */
#report-table thead th:nth-child(3) {
    position: sticky !important;
    left: 76px !important;
    top: 0 !important;
    z-index: 45 !important;
    background: #0b132b !important;
    min-width: 170px;
    max-width: 200px;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.4);
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
}
#report-table tbody td:not([colspan]):nth-child(3) {
    position: sticky !important;
    left: 76px !important;
    z-index: 20 !important;
    background: #0b132b !important;
    min-width: 170px;
    max-width: 200px;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.4);
    border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
    white-space: normal !important;
    word-break: break-word;
}

/* Center group header row: sticky horizontally so center name stays visible on horizontal scroll */
#report-table tbody tr td[colspan] {
    position: sticky;
    left: 0;
    z-index: 22;
    background: rgba(15, 39, 68, 0.95) !important;
}

/* Hover Rows preserving sticky columns */
#report-table tbody tr:hover td {
    background: rgba(30, 41, 59, 0.95) !important;
}
#report-table tbody tr:hover td:not([colspan]):nth-child(1),
#report-table tbody tr:hover td:not([colspan]):nth-child(2),
#report-table tbody tr:hover td:not([colspan]):nth-child(3) {
    background: #1e293b !important;
}


