/* ===== DESIGN SYSTEM ===== */
:root {
    --bg-primary: #0a1628;
    --bg-secondary: #111d35;
    --bg-card: rgba(17, 29, 53, 0.7);
    --bg-glass: rgba(17, 29, 53, 0.5);
    --bg-input: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: #3b82f6;
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --blue: #3b82f6;
    --blue-glow: rgba(59, 130, 246, 0.3);
    --emerald: #10b981;
    --green: #10b981;
    --emerald-glow: rgba(16, 185, 129, 0.3);
    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.3);
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.3);
    --purple: #8b5cf6;
    --purple-glow: rgba(139, 92, 246, 0.3);
    --sidebar-width: 260px;
    --header-height: 60px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
    scrollbar-gutter: stable; /* Reserve space for scrollbar to prevent layout shift */
}
body::before {
    content: '';
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(ellipse at 20% 50%, rgba(59,130,246,0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 20%, rgba(139,92,246,0.06) 0%, transparent 50%),
                radial-gradient(ellipse at 60% 80%, rgba(16,185,129,0.05) 0%, transparent 50%);
    pointer-events: none; z-index: 0;
}

/* ===== LOGIN SCREEN ===== */
.login-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-primary); z-index: 1000;
}
.login-container {
    background: var(--bg-glass);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px; padding: 48px; width: 100%; max-width: 420px;
    text-align: center; box-shadow: var(--shadow);
    animation: fadeInUp 0.6s ease;
}
.login-logo .material-icons-round {
    font-size: 56px; color: var(--blue);
    background: var(--blue-glow); border-radius: 50%;
    padding: 16px; margin-bottom: 16px; display: inline-block;
}
.login-title { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 32px; }
.login-form .input-group { position: relative; margin-bottom: 16px; }
.toggle-password {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer;
}
.error-message { color: var(--red); font-size: 0.85rem; margin-bottom: 12px; text-align: left; }

/* ===== SIDEBAR ===== */
:root {
    --sidebar-collapsed-width: 64px;
}
.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width); background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}
.sidebar-header {
    padding: 20px 20px; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 68px;
}
.sidebar-logo { font-size: 28px; color: var(--blue); flex-shrink: 0; }
.sidebar-title { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.5px; white-space: nowrap; overflow: hidden; transition: opacity 0.2s ease, width 0.3s ease; }
.sidebar-toggle-btn {
    margin-left: auto; flex-shrink: 0;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 4px;
    border-radius: 6px; display: flex; align-items: center;
    transition: var(--transition);
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.sidebar-toggle-btn .material-icons-round { font-size: 20px; transition: transform 0.3s ease; }
.sidebar-nav { list-style: none; padding: 12px; flex: 1; overflow-y: auto; overflow-x: hidden; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: var(--radius-sm);
    cursor: pointer; transition: var(--transition);
    color: var(--text-secondary); margin-bottom: 4px; position: relative;
    white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active {
    background: linear-gradient(135deg, var(--blue-glow), rgba(139,92,246,0.15));
    color: var(--text-primary); font-weight: 500;
}
.nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
    width: 3px; background: var(--blue); border-radius: 0 3px 3px 0;
}
.nav-badge {
    margin-left: auto; background: var(--red); color: white;
    font-size: 0.7rem; font-weight: 600; padding: 2px 7px;
    border-radius: 10px; min-width: 20px; text-align: center;
    flex-shrink: 0;
}
.nav-category {
    padding: 16px 24px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    pointer-events: none;
    white-space: nowrap; overflow: hidden;
    transition: opacity 0.2s ease;
}
.sidebar-footer {
    padding: 16px 20px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; flex-shrink: 0;
    overflow: hidden;
}

/* ---- Collapsed State ---- */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-category,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed #sidebarUserInfo {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}
.sidebar.collapsed .sidebar-toggle-btn .material-icons-round {
    transform: rotate(180deg);
}
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px;
}
.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 20px 0;
}
.sidebar.collapsed .sidebar-toggle-btn {
    margin-left: 0;
    position: absolute;
    right: 4px;
    top: 20px;
}
.sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: 16px 0;
}
/* Tooltip on hover when collapsed */
.sidebar.collapsed .nav-item {
    position: relative;
}
.sidebar.collapsed .nav-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(var(--sidebar-collapsed-width) - 8px);
    top: 50%; transform: translateY(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.8rem; font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0; pointer-events: none;
    z-index: 200;
    transition: opacity 0.15s ease;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.sidebar.collapsed .nav-item:hover::after {
    opacity: 1;
}

/* ===== MOBILE HEADER ===== */
.mobile-header {
    display: none; position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-height); background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 16px; align-items: center; justify-content: space-between;
    z-index: 90;
}
.mobile-title { font-weight: 700; font-size: 1.1rem; }
.sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 95;
}

/* ===== CONTENT ===== */
.content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 32px; 
    position: relative; 
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.content.sidebar-hidden {
    margin-left: var(--sidebar-collapsed-width);
}
.page { 
    display: none; 
    animation: fadeIn 0.3s ease; 
    width: 100%;
    max-width: 1400px;
    align-self: stretch; /* Crucial: prevent page resizing based on centered content */
}
.page.active { display: block; }
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { font-size: 1.8rem; font-weight: 700; }
.page-date { color: var(--text-secondary); font-size: 0.9rem; }

/* ===== CHART CONTAINER ===== */
.chart-container {
    height: 350px;
    position: relative;
    width: 100%;
}
@media (max-width: 768px) {
    .chart-container { height: 220px; }
}

/* ===== CARDS ===== */
.summary-cards {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px; 
    margin-bottom: 24px;
}
.card, .summary-card {
    background: var(--bg-glass); 
    backdrop-filter: blur(12px);
    border: 1px solid var(--border); 
    border-radius: var(--radius);
    padding: 20px; 
    display: flex; 
    align-items: center; 
    gap: 16px;
    transition: var(--transition); 
    cursor: default;
    min-height: 100px;
    position: relative;
    overflow: hidden;
}
.summary-card {
    flex-direction: column;
    align-items: flex-start;
}
.summary-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 4px; height: 100%;
    background: var(--card-color, var(--blue));
}
.card:hover, .summary-card:hover { 
    transform: translateY(-4px); 
    box-shadow: var(--shadow); 
    background: rgba(255, 255, 255, 0.05);
}
.card-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}
.card-icon .material-icons-round { font-size: 24px; }
.card-total-debt .card-icon { background: var(--red-glow); color: var(--red); }
.card-total-fund .card-icon { background: var(--emerald-glow); color: var(--emerald); }
.card-due-soon .card-icon { background: var(--amber-glow); color: var(--amber); }
.card-overdue .card-icon { background: var(--purple-glow); color: var(--purple); }
.card-info {
    flex: 1;
    min-width: 0;
}
.card-label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 2px; }
.card-value { 
    display: block; 
    font-size: 1.4rem; 
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card .stat-desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ===== GLASS PANEL ===== */
.glass-panel {
    background: var(--bg-glass); backdrop-filter: blur(12px);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; margin-bottom: 24px;
}
.panel-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 1.1rem; font-weight: 600; margin-bottom: 16px;
}
.panel-title .material-icons-round { color: var(--blue); font-size: 22px; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border: 1px solid transparent; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.9rem; font-weight: 500;
    cursor: pointer; transition: var(--transition); white-space: nowrap;
    line-height: 1.2;
}
.btn .material-icons-round { font-size: 18px; }
.btn-primary {
    background: linear-gradient(135deg, var(--blue), #2563eb);
    color: white; box-shadow: 0 4px 15px var(--blue-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--blue-glow); }
.btn-secondary {
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); }
.btn-success, .btn-emerald {
    background: linear-gradient(135deg, var(--emerald), #059669);
    color: white; box-shadow: 0 4px 15px var(--emerald-glow);
}
.btn-danger {
    background: linear-gradient(135deg, var(--red), #dc2626);
    color: white; box-shadow: 0 4px 15px var(--red-glow);
}
.btn-warning {
    background: linear-gradient(135deg, var(--amber), #d97706);
    color: white;
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; padding: 14px; font-size: 1rem; }
.btn-icon {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 8px; border-radius: var(--radius-sm);
    transition: var(--transition); display: inline-flex; align-items: center;
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

/* ===== INPUTS ===== */
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.input-icon {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 20px;
}
input, select, textarea {
    width: 100%; padding: 12px 16px; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-family: inherit; font-size: 0.9rem;
    transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--blue-glow);
}
.input-group .input-icon + input { padding-left: 44px; }
select option { background: var(--bg-secondary); color: var(--text-primary); }
textarea { resize: vertical; min-height: 80px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== TABLE ===== */
.table-container { 
    overflow: hidden; 
    position: relative;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
/* Inner scroll wrapper for horizontal overflow on small screens */
.table-container > .table-scroll-wrapper,
.table-container > div[id*="Table"] {
    overflow-x: auto;
}
table {
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0;
    background: transparent;
}
thead th {
    padding: 16px 20px; text-align: left; font-size: 0.75rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-secondary); background: rgba(255,255,255,0.04);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    font-size: 0.95rem; vertical-align: middle;
    color: var(--text-primary);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: all 0.2s ease; position: relative; background: transparent; }
tbody tr:hover { 
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
}
tr.row-overdue td:first-child,
tr.row-due-soon td:first-child,
tbody tr:hover td:first-child { 
    position: relative; 
}

tr.row-overdue td:first-child::before,
tr.row-due-soon td:first-child::before,
tbody tr:hover td:first-child::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 50%;
    border-radius: 4px;
    transition: all 0.3s ease;
    z-index: 1;
}

tr.row-overdue td:first-child::before { 
    background: var(--red);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
tr.row-due-soon td:first-child::before { 
    background: var(--amber); 
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}
tbody tr:hover td:first-child::before {
    background: var(--blue);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

/* Priority for status colors over hover color */
tr.row-overdue:hover td:first-child::before { background: var(--red); }
tr.row-due-soon:hover td:first-child::before { background: var(--amber); }

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

/* ===== STATUS BADGES ===== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge-pending { background: rgba(100,116,139,0.2); color: #94a3b8; }
.badge-partial { background: var(--amber-glow); color: var(--amber); }
.badge-paid { background: var(--emerald-glow); color: var(--emerald); }
.badge-overdue { background: var(--red-glow); color: var(--red); animation: pulse 2s infinite; }
.badge-new {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.4);
    font-size: 0.7rem;
    padding: 2px 8px;
    margin-left: 6px;
    vertical-align: middle;
}

.type-badge {
    display: inline-flex; padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 500;
}
.type-cong_no { background: rgba(59,130,246,0.15); color: #60a5fa; }
.type-ngan_hang { background: rgba(139,92,246,0.15); color: #a78bfa; }
.type-ca_nhan { background: rgba(16,185,129,0.15); color: #34d399; }
.type-nhan_vien { background: rgba(245,158,11,0.15); color: #fbbf24; }
.type-nha_nuoc { background: rgba(239,68,68,0.15); color: #f87171; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    z-index: 500;
}
.modal-overlay.active { display: block; }
.modal {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 95%; max-width: 600px; max-height: 90vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
    z-index: 600; overflow-y: auto;
    animation: modalIn 0.3s ease;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--bg-secondary); z-index: 1;
}
.modal-header h2 { font-size: 1.2rem; font-weight: 600; }
.modal-body { padding: 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

/* Expense Payment Modal: flex shown by JS — force vertical stacking */
#expensePaymentModal {
    flex-direction: column;
}

/* ===== FILTERS BAR PANELS ===== */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    padding: 16px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-wrap: wrap;
    align-items: center;
    box-shadow: var(--shadow);
}

.filter-group {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 200px;
}

.filter-group.fixed-width {
    flex: none;
    min-width: 160px;
}

.filter-group .material-icons-round {
    position: absolute;
    left: 14px;
    font-size: 18px;
    color: var(--text-muted);
    pointer-events: none;
    transition: var(--transition);
}

.filter-group input, 
.filter-group select {
    width: 100%;
    padding: 10px 16px 10px 42px; /* Large left padding for icon */
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition);
}

.filter-group input:focus, 
.filter-group select:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-glow);
}

.filter-group input:focus + .material-icons-round,
.filter-group select:focus + .material-icons-round {
    color: var(--blue);
}

.filter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 8px;
    white-space: nowrap;
}

/* Adjustments for different pages */
.filter-row {
    display: flex;
    gap: 12px;
    width: 100%;
    flex-wrap: wrap;
}

/* ===== DATE RANGE PICKER ===== */
.date-range-picker {
    display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
}
.date-range-picker .input-group { margin-bottom: 0; flex: 1; min-width: 150px; }

/* ===== AI NOTIFICATIONS ===== */
.ai-notifications { display: flex; flex-direction: column; gap: 12px; }
.ai-notification {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    animation: slideInRight 0.4s ease;
}
.ai-notification.urgent {
    background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.3);
}
.ai-notification.warning {
    background: rgba(245,158,11,0.08); border-color: rgba(245,158,11,0.3);
}
.ai-notification.info {
    background: rgba(59,130,246,0.08); border-color: rgba(59,130,246,0.3);
}
.ai-notification.success {
    background: rgba(16,185,129,0.08); border-color: rgba(16,185,129,0.3);
}
.ai-notification .ai-icon { font-size: 22px; flex-shrink: 0; margin-top: 2px; }
.ai-notification.urgent .ai-icon { color: var(--red); }
.ai-notification.warning .ai-icon { color: var(--amber); }
.ai-notification.info .ai-icon { color: var(--blue); }
.ai-notification.success .ai-icon { color: var(--emerald); }
.ai-notification .ai-text { flex: 1; }
.ai-notification .ai-title { font-weight: 600; margin-bottom: 2px; }
.ai-notification .ai-desc { font-size: 0.85rem; color: var(--text-secondary); }

/* ===== AI FULL ANALYSIS ===== */
.ai-full-analysis { display: flex; flex-direction: column; gap: 20px; }
.ai-section {
    background: var(--bg-glass); backdrop-filter: blur(12px);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px;
}
.ai-section h3 {
    display: flex; align-items: center; gap: 8px;
    font-size: 1rem; margin-bottom: 16px;
}
.ai-priority-list { display: flex; flex-direction: column; gap: 10px; }
.ai-priority-item {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 18px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03); border: 1px solid var(--border);
    transition: all 0.2s ease;
}
.ai-priority-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(4px);
    border-color: rgba(59, 130, 246, 0.2);
}
.ai-rank {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
}
.ai-rank.rank-1 { background: var(--red-glow); color: var(--red); }
.ai-rank.rank-2 { background: var(--amber-glow); color: var(--amber); }
.ai-rank.rank-3 { background: var(--blue-glow); color: var(--blue); }
.ai-rank.rank-default { background: rgba(100,116,139,0.2); color: var(--text-secondary); }
.ai-priority-info { 
    flex: 1; 
    min-width: 0;
}
.ai-priority-name { 
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-priority-detail { 
    font-size: 0.8rem; 
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-priority-amount { font-weight: 700; white-space: nowrap; }

/* ===== SUPPLIER CLASSIFICATION GRID ===== */
.supplier-classification-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px; margin-top: 16px;
}
.classification-card {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.classification-header {
    display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1.05rem;
}
.classification-header .material-icons-round { font-size: 20px; }
.count-badge {
    margin-left: auto; text-align: center; font-size: 0.8rem; font-weight: 700;
    padding: 2px 8px; border-radius: 12px;
}

/* Modifier Colors */
.classification-card.critical { border-top: 3px solid var(--red); background: linear-gradient(180deg, rgba(239,68,68,0.05) 0%, transparent 100%); }
.classification-card.critical .classification-header { color: var(--red); }
.classification-card.critical .count-badge { background: var(--red); color: white; }

.classification-card.warning { border-top: 3px solid var(--amber); background: linear-gradient(180deg, rgba(245,158,11,0.05) 0%, transparent 100%); }
.classification-card.warning .classification-header { color: var(--amber); }
.classification-card.warning .count-badge { background: var(--amber); color: white; }

.classification-card.normal { border-top: 3px solid var(--emerald); background: linear-gradient(180deg, rgba(16,185,129,0.05) 0%, transparent 100%); }
.classification-card.normal .classification-header { color: var(--emerald); }
.classification-card.normal .count-badge { background: var(--emerald); color: white; }

.classification-desc { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 4px; line-height: 1.4; }
.classification-list { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.supplier-item {
    background: rgba(255,255,255,0.03); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 12px;
}
.supplier-item .sup-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.supplier-item .sup-stats { display: flex; justify-content: space-between; font-size: 0.8rem; }
.supplier-item .days { color: var(--text-secondary); }
.empty-list { color: var(--text-muted); font-size: 0.85rem; font-style: italic; text-align: center; padding: 16px 0; }

/* ===== CASH NEED RESULT ===== */
#cashNeedResult .cash-summary {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px; margin-top: 16px;
}
#cashNeedResult .cash-item {
    padding: 16px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03); border: 1px solid var(--border);
    text-align: center;
    min-width: 0;
}
#cashNeedResult .cash-item .cash-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 4px; }
#cashNeedResult .cash-item .cash-value { font-size: 1.3rem; font-weight: 700; }
#cashNeedResult .cash-item.negative .cash-value { color: var(--red); }
#cashNeedResult .cash-item.positive .cash-value { color: var(--emerald); }

/* ===== ALERT BANNER ===== */
.alert-banner {
    padding: 14px 20px; border-radius: var(--radius);
    margin-bottom: 20px; display: flex; align-items: center; gap: 10px;
    font-weight: 500; animation: slideInDown 0.4s ease;
}
.alert-banner.alert-danger {
    background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3);
    color: var(--red);
}
.alert-banner.alert-warning {
    background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3);
    color: var(--amber);
}
.alert-banner.alert-success {
    background: rgba(16,185,129,0.12); border: 1px solid rgba(16,185,129,0.3);
    color: var(--emerald);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-state .material-icons-round { font-size: 48px; margin-bottom: 12px; opacity: 0.3; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ===== RECENT LIST ===== */
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.2s ease;
}
.recent-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(4px);
}
.recent-item .recent-icon {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.recent-item .recent-icon.add { background: var(--emerald-glow); color: var(--emerald); }
.recent-item .recent-icon.pay { background: var(--blue-glow); color: var(--blue); }
.recent-item .recent-icon.fund { background: var(--amber-glow); color: var(--amber); }
.recent-item .recent-text { flex: 1; }
.recent-item .recent-title { font-weight: 500; font-size: 0.9rem; }
.recent-item .recent-time { font-size: 0.75rem; color: var(--text-muted); }

/* ===== TOAST ===== */
.toast-container {
    position: fixed; bottom: 24px; right: 24px; z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 20px; border-radius: var(--radius-sm);
    background: var(--bg-secondary); border: 1px solid var(--border);
    box-shadow: var(--shadow); min-width: 280px;
    animation: slideInRight 0.4s ease;
}
.toast.toast-success .toast-icon { color: var(--emerald); }
.toast.toast-error .toast-icon { color: var(--red); }
.toast.toast-warning .toast-icon { color: var(--amber); }
.toast.toast-info .toast-icon { color: var(--blue); }
.toast .toast-icon { font-size: 22px; }
.toast .toast-message { flex: 1; font-size: 0.9rem; }
.toast.removing { animation: slideOutRight 0.3s ease forwards; }

/* ===== PROGRESS BAR ===== */
.progress-bar {
    width: 100%; height: 6px; background: rgba(255,255,255,0.1);
    border-radius: 3px; overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 3px; transition: width 0.5s ease;
}
.progress-fill.low { background: var(--red); }
.progress-fill.medium { background: var(--amber); }
.progress-fill.high { background: var(--emerald); }

/* ===== INSTALLMENTS ===== */
.installments-list { margin-top: 12px; }
.installment-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); margin-bottom: 8px;
    background: rgba(255,255,255,0.02);
}
.installment-item.paid { opacity: 0.6; }
.installment-item .inst-info { 
    flex: 1; 
    min-width: 0;
}
.installment-item .inst-amount { font-weight: 600; }
.installment-item .inst-date { 
    font-size: 0.8rem; 
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== SUPPLIER BANK INFO ===== */
.bank-info {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px; padding: 12px; border-radius: var(--radius-sm);
    background: rgba(59,130,246,0.06); border: 1px solid rgba(59,130,246,0.15);
    margin-top: 8px;
}
.bank-info-item { font-size: 0.85rem; }
.bank-info-item .bank-label { color: var(--text-muted); font-size: 0.75rem; }
.bank-info-item .bank-value { font-weight: 500; }

/* ===== DEBT DETAIL PANEL ===== */
.detail-section { margin-bottom: 20px; }
.detail-section h4 {
    font-size: 0.9rem; font-weight: 600; margin-bottom: 10px;
    color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideOutRight { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100px); } }
@keyframes slideInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ===== RESPONSIVE ===== */
.mobile-hide { display: initial !important; }
td.mobile-hide, th.mobile-hide { display: table-cell !important; }
.mobile-only { display: none !important; }

@media (max-width: 1024px) {
    .summary-cards { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); z-index: 100; }
    .sidebar-overlay.active { display: block; }
    .mobile-header { display: flex; }
    .content { margin-left: 0; padding: 80px 16px 16px; }
    .page-header h1 { font-size: 1.4rem; }
    .summary-cards { grid-template-columns: 1fr 1fr !important; }
    .form-row { grid-template-columns: 1fr; }
    .modal { width: 98%; max-height: 95vh; padding: 12px; }
    .modal-body { padding: 16px; }
    .date-range-picker { flex-direction: column; }
    .filters-bar { flex-direction: column; align-items: stretch; padding: 12px; }
    .filter-group { min-width: 0; width: 100%; }
    .filter-row { flex-direction: column; }
    .toast-container { left: 16px; right: 16px; bottom: 16px; }
    .toast { min-width: auto; }
    .mobile-hide { display: none !important; }
    .mobile-only { display: block !important; }
    
    /* Table optimization */
    .table-container { 
        margin: 0 -16px; 
        width: calc(100% + 32px); 
        padding: 0 16px;
        -webkit-overflow-scrolling: touch;
    }
    table { font-size: 0.85rem; }
    thead th { padding: 12px 10px; }
    tbody td { padding: 12px 10px; }
    
    .btn { padding: 10px 16px; font-size: 0.85rem; }
    .nav-item { padding: 14px 18px; } /* Improved touch target */
    
    .modal { padding: 8px; }
    .modal-body { padding: 12px; }
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr !important; }
    .login-container { padding: 32px 24px; margin: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header .btn { width: 100%; }
    .card-value { font-size: 1.2rem; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ===== ACTIONS BTN GROUP ===== */
.actions-group { 
    display: flex; gap: 8px; 
    justify-content: flex-end; /* Align to right for better visual balance in tables */
}
.actions-group .btn-icon { 
    padding: 8px; 
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
}
.actions-group .btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* ===== AMOUNT DISPLAY ===== */
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.amount.negative { color: var(--red); }
.amount.positive { color: var(--emerald); }

/* Indicators replaced by pseudo-elements for better harmony */
tr.row-overdue td:first-child { box-shadow: none; }
tr.row-due-soon td:first-child { box-shadow: none; }
tr.row-paid { opacity: 0.6; }

/* Summary Modal Enhancements */
.summary-cards {
    margin-bottom: 24px;
}

.summary-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.summary-card.total::before { background: var(--amber); }
.summary-card.paid::before { background: var(--green); }
.summary-card.remaining::before { background: var(--red); }

.summary-card:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
}

.stat-value.amber { color: var(--amber); text-shadow: 0 0 15px rgba(245, 158, 11, 0.2); }
.stat-value.green { color: var(--green); text-shadow: 0 0 15px rgba(16, 185, 129, 0.2); }
.stat-value.red { color: var(--red); text-shadow: 0 0 15px rgba(239, 68, 68, 0.2); }

/* Activity Icons */
.recent-icon.add { color: var(--blue); background: rgba(59, 130, 246, 0.1); }
.recent-icon.pay { color: var(--amber); background: rgba(245, 158, 11, 0.1); }
.recent-icon.fund { color: var(--green); background: rgba(16, 185, 129, 0.1); }

/* Overall Progress Widget */
.overall-progress-container {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

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

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

.summary-table th {
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
}

.summary-table tr:hover {
    background: rgba(255, 255, 255, 0.01);
}
tr.row-due-soon td:first-child { border-left: 4px solid var(--amber); }
tr.row-paid { opacity: 0.6; }

/* ===== ATTACHMENTS ===== */
.paste-area {
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    padding: 24px; text-align: center;
    background: rgba(255,255,255,0.02);
    color: var(--text-secondary);
    transition: var(--transition);
    cursor: pointer; position: relative;
    margin-bottom: 16px;
}
.paste-area:hover, .paste-area:focus {
    border-color: var(--blue);
    background: rgba(59,130,246,0.05);
}
.paste-area input[type="file"] {
    position: absolute; top:0; left:0; width:100%; height:100%;
    opacity: 0; cursor: pointer;
}
.attachments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px; margin-top: 12px;
}
.attachment-item {
    position: relative; border-radius: 8px; overflow: hidden;
    aspect-ratio: 1; background: #000; border: 1px solid var(--border);
}
.attachment-item img {
    width: 100%; height: 100%; object-fit: cover;
    display: block; cursor: zoom-in;
    transition: var(--transition);
}
.attachment-item img:hover { transform: scale(1.05); }
.attachment-item .btn-delete-att {
    position: absolute; top: 4px; right: 4px;
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(0,0,0,0.6); color: white;
    border: none; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    opacity: 0; transition: var(--transition);
}
.attachment-item:hover .btn-delete-att { opacity: 1; }
.attachment-item .remove-btn {
    position: absolute; top: 4px; right: 4px;
    width: 20px; height: 20px; border-radius: 50%;
    background: rgba(220, 38, 38, 0.8); color: white;
    border: none; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    font-size: 14px; transition: var(--transition);
}

/* Quick Add Form Specifics */
.quick-add-form .quick-add-row {
    display: flex;
    gap: 8px;
    margin-bottom: 0; /* Handled by margin-top on rows */
}
.quick-add-form .quick-add-row > * {
    flex: 1;
    min-width: 0;
}
.quick-add-form .quick-add-row label {
    flex: 0 0 100%;
}
.quick-add-form select, .quick-add-form input {
    height: 40px;
}
.attachment-item .btn-delete-att:hover { background: var(--red); }
.attachment-item .btn-delete-att .material-icons-round { font-size: 16px; }

/* Fullscreen Image Preview */
.img-preview-overlay {
    position: fixed; top:0; left:0; width:100vw; height:100vh;
    background: rgba(0,0,0,0.9); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: var(--transition);
}
.img-preview-overlay.active { opacity: 1; pointer-events: all; }
.img-preview-overlay img {
    max-width: 90%; max-height: 90%; object-fit: contain;
    border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.img-preview-overlay .btn-close {
    position: absolute; top: 20px; right: 30px;
    background: none; border: none; color: white;
    font-size: 36px; cursor: pointer; opacity: 0.7;
}
.img-preview-overlay .btn-close:hover { opacity: 1; }

/* ===== SALARY MODULE STYLES ===== */

/* Salary status badges */
.badge-paid {
    background: rgba(16, 185, 129, 0.15);
    color: var(--emerald);
    border: 1px solid rgba(16, 185, 129, 0.3);
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600;
}
.badge-unpaid {
    background: rgba(245, 158, 11, 0.15);
    color: var(--amber);
    border: 1px solid rgba(245, 158, 11, 0.3);
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600;
    animation: pulse 2.5s infinite;
}
.badge-muted {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.2);
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 500;
}

/* Position chip */
.badge-position {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.25);
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 500;
}

/* Salary badge on sidebar (amber color overrides red) */
#salaryBadge {
    background: var(--amber) !important;
    color: #000 !important;
}

/* Salary page card color override for "Đã chi" card */
.card-due-soon[style*="--card-color:var(--green)"] .card-icon {
    background: rgba(16, 185, 129, 0.2);
    color: var(--emerald);
}

/* Batch pay table checkbox */
.batch-emp-check {
    width: 16px; height: 16px;
    cursor: pointer; accent-color: var(--emerald);
}


/* ===== REPAYMENT PLAN PROGRESS ===== */
.plan-progress { width: 100%; }
.plan-progress-label {
    display: flex; justify-content: space-between;
    font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 4px;
}
.plan-progress-bar {
    height: 6px; background: rgba(255,255,255,0.08);
    border-radius: 3px; overflow: hidden;
}
.plan-progress-fill {
    height: 100%; border-radius: 3px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.plan-progress-fill.low   { background: var(--red); }
.plan-progress-fill.mid   { background: var(--amber); }
.plan-progress-fill.high  { background: var(--emerald); }

/* ===== MONTHLY SCHEDULE TABLE ===== */
.monthly-schedule-table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    margin-top: 12px; border-radius: var(--radius-sm); overflow: hidden;
    border: 1px solid var(--border); font-size: 0.85rem;
}
.monthly-schedule-table thead th {
    padding: 12px 16px; background: rgba(59,130,246,0.08);
    color: var(--blue); font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    border-bottom: 1px solid var(--border); text-align: left;
}
.monthly-schedule-table tbody td {
    padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.04);
    vertical-align: middle; font-size: 0.9rem;
}
.monthly-schedule-table tbody tr:last-child td { border-bottom: none; }
.monthly-schedule-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.month-index { color: var(--text-muted); font-size: 0.75rem; font-weight: 600; }
.month-highlight td { background: rgba(245,158,11,0.07) !important; }
.month-highlight .month-label { color: var(--amber); font-weight: 600; }

/* Plans page card colors */
#plansCompletedCount { color: var(--emerald); }
#plansActiveCount { color: var(--blue); }

/* ===== CALENDAR VIEW ===== */
.calendar-container { padding: 12px 16px; background: rgba(255,255,255,0.02); border-radius: var(--radius-sm); }
#repaymentCalendarGrid { 
    display: grid !important; 
    grid-template-columns: repeat(7, 1fr) !important; 
    gap: 1px; 
    background: var(--border); 
    border: 1px solid var(--border); 
    border-radius: var(--radius-sm); 
    overflow: hidden;
    width: 100%;
}
.calendar-day-header { background: rgba(255,255,255,0.05); padding: 10px; text-align: center; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }
.calendar-cell { background: var(--bg-secondary); min-height: 100px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.calendar-cell.other-month { background: rgba(17,29,53,0.3); opacity: 0.5; }
.calendar-cell.today { background: rgba(59,130,246,0.1); }
.calendar-date { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); align-self: flex-end; margin-bottom: 4px; }
.calendar-cell.today .calendar-date { color: var(--blue); background: var(--blue-glow); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--blue); }
.calendar-event { font-size: 0.75rem; padding: 4px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 4px; align-items: center; cursor: pointer; font-weight: 500; }
.calendar-event.overdue { background: rgba(239,68,68,0.15); color: #fca5a5; border-left: 2px solid var(--red); }
.calendar-event.pending { background: rgba(245,158,11,0.15); color: #fcd34d; border-left: 2px solid var(--amber); }
.calendar-event.ai-plan { background: rgba(139,92,246,0.15); color: #c4b5fd; border-left: 2px solid var(--purple); }
.calendar-event.paid { background: rgba(16,185,129,0.15); color: #6ee7b7; border-left: 2px solid var(--emerald); text-decoration: line-through; opacity: 0.7; }
@media (max-width: 768px) { .calendar-cell { min-height: 80px; padding: 4px; } .calendar-event { font-size: 0.65rem; padding: 2px 4px; } }

/* ===== CATEGORY BREAKDOWN GRID ===== */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 10px;
}

.category-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.category-card:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border-color: rgba(59, 130, 246, 0.3);
}

.category-cat-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.category-card .cat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--blue);
}

.category-card:nth-child(2) .cat-icon { color: var(--purple); }
.category-card:nth-child(3) .cat-icon { color: var(--amber); }
.category-card:nth-child(4) .cat-icon { color: var(--emerald); }
.category-card:nth-child(5) .cat-icon { color: var(--red); }

.cat-label {
    font-size: 1.1rem;
    font-weight: 700;
}

.cat-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cat-stat {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.cat-stat .label {
    color: var(--text-secondary);
}

.cat-stat .value {
    font-weight: 600;
}

.cat-stat.highlight {
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    margin-top: 4px;
}

.cat-stat.highlight .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.cat-progress {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cat-progress .progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
}


/* ===== LEDGER DASHBOARD & SUMMARY CARDS ===== */
.summary-card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.summary-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: var(--shadow);
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 4px; height: 100%;
    background: var(--card-color, var(--blue));
}

.summary-card .stat-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.summary-card .stat-label .material-icons-round {
    font-size: 18px;
    color: var(--card-color, var(--blue));
}

.summary-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.summary-card.total .stat-value {
    color: var(--blue);
}

.summary-card .stat-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Entry Badges */
.entry-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.entry-badge-in { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.entry-badge-out { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.entry-badge-transfer { background: rgba(59, 130, 246, 0.15); color: var(--blue); }

.wallet-breakdown-container {
    grid-column: 1 / -1;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.wallet-breakdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--blue);
    margin-bottom: 20px;
}

.wallet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.wallet-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border);
    transition: var(--transition);
    gap: 16px;
}

.wallet-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.wallet-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.wallet-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.wallet-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.wallet-balance-group {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.wallet-sub-balance {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.wallet-main-balance {
    font-weight: 700;
    font-size: 1.1rem;
}

.wallet-main-balance.positive { color: var(--emerald); }
.wallet-main-balance.negative { color: var(--red); }

/* Ledger Header Refinement */
.ledger-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.ledger-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ledger-date-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    transition: var(--transition);
    min-width: 180px;
}

.ledger-date-wrapper:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px var(--blue-glow);
}

.ledger-date-wrapper .material-icons-round {
    color: var(--text-muted);
    font-size: 18px;
    margin-right: 8px;
}

.ledger-date-wrapper input[type="date"] {
    background: none;
    border: none;
    padding: 10px 0;
    width: 100%;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

.ledger-actions-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

@media (max-width: 768px) {
    .ledger-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .ledger-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .ledger-controls input[type="date"] {
        width: 100%;
    }
    .ledger-actions-wrapper {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
    }
    .ledger-actions-wrapper .btn {
        padding: 10px 4px;
        font-size: 0.75rem;
        justify-content: center;
        flex-direction: column;
        gap: 4px;
    }
    .ledger-actions-wrapper .btn .material-icons-round {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .ledger-actions-wrapper {
        grid-template-columns: 1fr 1fr;
    }
    .ledger-actions-wrapper .btn:last-child {
        grid-column: span 2;
        flex-direction: row;
    }
}

/* ===== UNIVERSAL TABS SYSTEM ===== */
.tabs-container, .ledger-tabs, .expense-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 20px;
    background: var(--bg-glass);
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    width: 100% !important;
    box-sizing: border-box;
    align-items: stretch;
    height: 62px; /* Fixed height for the whole tab bar */
    overflow: hidden;
}
.expense-tabs {
    grid-template-columns: 20% 20% 20% 20% 20% !important; /* Extremely rigid */
    /* Adjust for gaps: (100% - 4*8px) / 5 ... grid handles it better with 1fr usually but % is very explicit */
    grid-template-columns: repeat(5, 1fr) !important; 
}
.tab-item, .ledger-tab, .expense-tab {
    padding: 12px 10px;
    text-align: center;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; /* Avoid 'all' to prevent layout jumps */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 48px;
    max-height: 48px;
    box-sizing: border-box;
}
.tab-item:hover, .ledger-tab:hover, .expense-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}
.tab-item.active, .ledger-tab.active, .expense-tab.active {
    background: var(--blue);
    color: white;
    box-shadow: 0 4px 12px var(--blue-glow);
}
.tab-content, .ledger-tab-content, .expense-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}
.tab-content.active, .ledger-tab-content.active, .expense-tab-content.active {
    display: block;
}


/* Compact Summary for Ledger */
.ledger-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.ledger-summary-item {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ledger-summary-item .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.ledger-summary-item .value {
    font-size: 1.1rem;
    font-weight: 700;
}

@media (max-width: 1024px) {
    .ledger-summary-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .ledger-tabs, .expense-tabs {
        top: 60px; /* Below mobile header */
        margin: 0 -16px 16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .ledger-tab, .expense-tab {
        padding: 12px 6px;
        font-size: 0.85rem;
        flex-direction: column;
        gap: 2px;
    }
    .ledger-tab .material-icons-round, .expense-tab .material-icons-round {
        font-size: 18px;
    }
    .ledger-summary-grid { gap: 8px; }
    .ledger-summary-item { padding: 10px; }
    .ledger-summary-item .value { font-size: 1rem; }
}

@media (max-width: 480px) {
    .ledger-summary-grid { grid-template-columns: 1fr; }
}

/* Search Results Dropdown */
.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a1b1e; /* Solid dark background for maximum contrast */
    border: 1px solid var(--blue); /* More distinct border */
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5); /* Stronger shadow */
    z-index: 2000; /* Higher z-index to be above everything in modal */
    max-height: 250px;
    overflow-y: auto;
    margin-top: 4px;
}

.search-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    transition: all 0.2s;
}

.search-item:hover {
    background: var(--blue);
}

.search-item:hover .search-item-name,
.search-item:hover .search-item-phone {
    color: white; /* Flip text color on hover for clarity */
}

.search-item-info {
    display: flex;
    flex-direction: column;
}

.search-item-name {
    font-weight: 600;
    color: #ffffff; /* Bright white for primary text */
    font-size: 0.95rem;
}

.search-item-phone {
    font-size: 0.85rem;
    color: #94a3b8; /* Clearer light gray for secondary text */
}

.search-item.empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    cursor: default;
}

/* ===== OPTIMIZED EXPENSES UI ===== */
.expenses-analytics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.expenses-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.quick-add-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-add-row {
    display: flex;
    gap: 10px;
}

.quick-add-row input, .quick-add-row select {
    flex: 1;
}

@media (max-width: 1024px) {
    .expenses-analytics, .expenses-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .quick-add-row {
        flex-direction: column;
    }
}

/* ===== TAB MINI DASHBOARD ===== */
.tab-mini-dashboard {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 24px;
    border: 1px solid var(--border);
}

.mini-db-stat {
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--border);
    padding-right: 20px;
}

.mini-db-stat .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.mini-db-stat .value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
}

.mini-db-stat .sub-value {
    font-size: 0.8rem;
    margin-top: 4px;
}

.mini-db-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
}

.dist-bar-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dist-bar-label {
    font-size: 0.75rem;
    width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
}

.dist-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.dist-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.dist-bar-pct {
    font-size: 0.7rem;
    font-weight: 700;
    width: 35px;
    text-align: right;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .tab-mini-dashboard {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 12px;
    }
    .mini-db-stat {
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 12px;
        text-align: center;
    }
}

/* ===== PREMIUM EXPENSE PAYMENT MODAL (GLASSMORPHISM) ===== */
#expensePaymentModal .modal-header {
    justify-content: center;
    padding-bottom: 20px;
}

#expensePaymentModalTitle {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, rgba(255,255,255,0.7) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    margin-bottom: 4px;
}

#expensePaymentModal {
    max-width: 500px;
    background: rgba(15, 23, 42, 0.85); /* Slate 900 with transparency */
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.premium-card-wrapper {
    perspective: 1000px;
    margin-bottom: 28px;
}

.financial-glass-card {
    position: relative;
    padding: 24px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(59, 130, 246, 0.1) 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.05);
}

.financial-glass-card::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(255,255,255,0.05) 0%, transparent 70%);
    transform: rotate(30deg);
    pointer-events: none;
}

.card-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 4px;
    font-weight: 500;
}

.card-amount-large {
    font-size: 2rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: 20px;
    text-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.card-stats-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.card-stat-item .val {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--emerald);
}

.card-stat-item .lbl {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
}

/* Premium Form Elements */
.premium-input-group {
    margin-bottom: 20px;
}

.premium-input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.premium-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 14px 16px;
    color: #fff;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.premium-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    outline: none;
}

.premium-amount-input {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--emerald);
    text-align: center;
}

/* Activity Feed (History) */
.transaction-feed {
    margin-top: 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feed-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.feed-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition);
}

.feed-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(4px);
}

.feed-icon {
    width: 42px;
    height: 42px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--emerald);
}

.feed-content {
    flex: 1;
}

.feed-amount {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
}

.feed-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
}

.feed-actions {
    opacity: 0;
    transition: opacity 0.2s;
}

.feed-item:hover .feed-actions {
    opacity: 1;
}

.empty-feed {
    text-align: center;
    padding: 40px 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    color: var(--text-muted);
}
