:root {
    /* LIGHT THEME (Default) */
    --primary: #2563eb;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --input-bg: #ffffff;
}

/* DARK THEME OVERRIDES */
[data-theme="dark"] {
    --primary: #3b82f6;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --input-bg: #0f172a;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    margin: 0; padding: 0; line-height: 1.5; 
    transition: background 0.3s, color 0.3s;
}

/* [UPDATED] Increased Max-Width to allow more tabs to fit */
.app-container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 20px; 
}

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.header-actions { display: flex; gap: 15px; align-items: center; }
h1, h2, h3 { margin: 0; }

/* Dashboard & Grids */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.card { 
    background: var(--surface); 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); 
    position: relative; 
    transition: background 0.3s, border-color 0.3s;
    border: 1px solid transparent; 
}
[data-theme="dark"] .card { box-shadow: none; border: 1px solid var(--border); }

.card.archived { opacity: 0.6; background: var(--bg); border: 1px dashed var(--border); }
.card.archived::after { content: '(Archived)'; position: absolute; top: 10px; right: 10px; font-size: 0.7rem; color: var(--text-secondary); font-weight: bold; }

.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 5px; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.neutral { color: var(--warning); }

/* [UPDATED] Navigation Tabs with Custom Scrollbar */
.nav-tabs { 
    display: flex; 
    gap: 10px; 
    margin-bottom: 20px; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 10px; 
    overflow-x: auto; 
    
    /* Smooth scrolling */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--border) transparent;
}

/* Chrome/Safari/Edge Scrollbar Styling */
.nav-tabs::-webkit-scrollbar {
    height: 4px; /* Very thin height */
}

.nav-tabs::-webkit-scrollbar-track {
    background: transparent; 
}

.nav-tabs::-webkit-scrollbar-thumb {
    background: var(--border); 
    border-radius: 10px;
}

.nav-tabs::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary); 
}

.tab-btn { background: none; border: none; padding: 10px 20px; cursor: pointer; font-weight: 600; color: var(--text-secondary); border-radius: 6px; white-space: nowrap; transition: color 0.3s; }
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { background: var(--primary); color: white; }

/* Filter Bar */
.filter-bar { 
    display: flex; gap: 10px; align-items: center; 
    background: var(--surface); 
    padding: 10px 15px; border-radius: 8px; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); 
    margin-bottom: 20px; flex-wrap: wrap; 
    border: 1px solid var(--border);
}
.filter-group { display: flex; align-items: center; gap: 8px; }

/* Tables */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 600px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); color: var(--text); }
th { color: var(--text-secondary); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* Buttons & Forms */
.btn { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.btn:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: 5px; margin-left: 5px; color: var(--text-secondary); transition: color 0.2s; }
.btn-icon:hover { color: var(--text); background: var(--border); border-radius: 4px; }

input, select { 
    width: 100%; padding: 10px; 
    border: 1px solid var(--border); 
    background: var(--input-bg);
    color: var(--text);
    border-radius: 6px; font-size: 1rem; box-sizing: border-box; margin-bottom: 10px; 
}

.checkbox-wrapper { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin-bottom: 10px; cursor: pointer; }
.checkbox-wrapper input { width: auto; margin: 0; cursor: pointer; }

/* Split Logic Styles */
.split-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.split-amount.locked { background-color: rgba(37, 99, 235, 0.1); border-color: var(--primary); font-weight: 500; }

/* Modals */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
.modal.open { display: flex; }
.modal-content { background: var(--surface); padding: 30px; border-radius: 12px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; border: 1px solid var(--border); box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); }

/* Utility */
.hidden { display: none !important; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.detail-header { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.back-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); padding: 0; }
.back-btn:hover { color: var(--text); }

.tag-fund { background: rgba(245, 158, 11, 0.15); color: var(--warning); padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; border: 1px solid rgba(245, 158, 11, 0.3); }
.tag-cat { background: rgba(37, 99, 235, 0.1); color: var(--primary); padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; }

/* Credit Card Visuals */
.cc-top-row {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    margin-bottom: 5px;
}

.cc-last4 {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.progress-track {
    background: var(--border);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
    margin-bottom: 4px;
    width: 100%;
}

.progress-fill {
    height: 100%;
    background: var(--warning);
    transition: width 0.3s ease;
}

/* LOGIN SCREEN & OVERLAYS */
.auth-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100vh;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--surface);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    text-align: center;
}

.login-card h2 { margin-bottom: 20px; color: var(--primary); }
.login-card input { margin-bottom: 15px; }

/* ADMIN USER CARDS */
.user-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.role-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}
.role-admin { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.role-user { background: rgba(16, 185, 129, 0.1); color: var(--success); }

/* Header Profile Section */
.profile-section {
    display: flex;
    align-items: center;
    gap: 10px;
}
.profile-name {
    font-weight: 600;
    font-size: 0.9rem;
}

/* PASSWORD FIELD STYLING */
.password-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    margin-bottom: 15px; 
}

.password-wrapper input {
    width: 100%;
    padding-right: 45px; 
    margin-bottom: 0; 
    box-sizing: border-box;
    height: 42px; 
}

.password-toggle-btn {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%; 
    width: 40px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s;
    border-radius: 0 6px 6px 0;
}

.password-toggle-btn:hover {
    color: var(--primary);
    background: rgba(0,0,0,0.02);
}

.password-toggle-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* --- RESPONSIVE HEADER FOR MOBILE --- */
@media (max-width: 600px) {
    /* 1. Stack Logo and Actions vertically */
    header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        margin-bottom: 20px;
    }

    /* 2. Allow actions to wrap nicely */
    .header-actions {
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
    }

    /* 3. Give Profile its own "Card" look */
    .profile-section {
        width: 100%;
        background: var(--surface);
        border: 1px solid var(--border);
        padding: 8px 12px;
        border-radius: 8px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        order: 1; /* Ensure it appears at the top of the actions block */
    }

    /* 4. Theme toggle sits next to the main button or floats */
    #theme-toggle {
        order: 2;
        padding: 10px;
        background: var(--surface);
        border-radius: 8px;
        border: 1px solid var(--border);
        width: 45px; /* Fixed square width */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 5. Make the Main Action Button Big and Tappable */
    .header-actions .btn {
        order: 3;
        flex-grow: 1; /* Fill the rest of the row */
        text-align: center;
        padding: 12px; /* Taller touch target */
    }
}