/* --- GLOBAL VARIABLES --- */
:root {
    --primary: #0f172a;
    --accent: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --bg-light: #f8fafc;
    --white: #ffffff;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --sidebar-width: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    min-height: 100vh;
}

/* --- DESKTOP SIDEBAR --- */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--primary);
    color: var(--white);
    display: flex; flex-direction: column;
    padding: 25px;
    z-index: 2000; /* Higher Z-Index to sit on top of everything */
    transition: transform 0.3s ease-in-out; /* Smooth slide animation */
}

.brand { margin-bottom: 40px; }
.brand h2 { font-size: 1.5rem; margin-bottom: 5px; font-weight: 700; }
.brand span { color: var(--accent); }
.brand p { font-size: 0.8rem; color: #94a3b8; line-height: 1.4; }

.sidebar nav a {
    display: flex; align-items: center; color: #94a3b8; text-decoration: none;
    padding: 14px 10px; margin-bottom: 5px; border-radius: 8px; font-size: 0.95rem; transition: 0.3s;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255, 255, 255, 0.1); color: var(--white); }

.profile { margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.profile p { font-weight: 600; font-size: 0.95rem; }
.profile small { color: #94a3b8; font-size: 0.8rem; }

/* --- MAIN CONTENT --- */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 40px;
    min-height: 100vh;
    display: flex; flex-direction: column;
}

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }

.mobile-header { display: none; } /* Hidden on desktop */

h1 { font-size: 1.8rem; font-weight: 700; color: var(--text-dark); }
.date-display { color: var(--text-light); font-weight: 500; }

/* --- CARDS --- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: var(--white);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid #e2e8f0;
}
.card h3 { font-size: 0.85rem; color: var(--text-light); text-transform: uppercase; font-weight: 600; }
.card p { font-size: 2rem; font-weight: 700; margin-top: 10px; color: var(--text-dark); }
.income-card p { color: var(--success); }
.expense-card p { color: var(--danger); }

/* --- SECTIONS --- */
.content-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 25px; margin-bottom: 35px; }

.section-container {
    background: var(--white);
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid #e2e8f0;
}
.section-container h2 { font-size: 1.2rem; margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #f1f5f9; }

/* --- FORM ELEMENTS --- */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 8px; }
.form-group input, .form-group select {
    width: 100%; padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px;
    font-size: 1rem; background: #f8fafc;
}
.row-group { display: flex; gap: 15px; }
.row-group .form-group { flex: 1; }

.btn-primary {
    width: 100%; background: var(--accent); color: white; padding: 14px;
    border: none; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 1rem;
}

/* --- CHART & TABLE --- */
.chart-wrapper { height: 300px; width: 100%; position: relative; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 15px; color: var(--text-light); font-weight: 600; border-bottom: 2px solid #e2e8f0; font-size: 0.9rem; }
td { padding: 15px; border-bottom: 1px solid #e2e8f0; font-size: 0.95rem; }
.text-right { text-align: right; }
.delete-btn { color: var(--danger); background: #fee2e2; border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 0.8rem; }

.main-footer { margin-top: 50px; padding-top: 20px; border-top: 1px solid #e2e8f0; text-align: center; color: var(--text-light); font-size: 0.9rem; }
.mobile-nav { display: none; }
.menu-btn { display: none; } /* Hidden on desktop */
.overlay { display: none; } /* Hidden on desktop */

/* ==================================================
   MOBILE OVERRIDES
   ================================================== */
@media (max-width: 900px) {
    /* 1. SIDEBAR HIDDEN BY DEFAULT (Off-Screen) */
    .sidebar { 
        transform: translateX(-100%); /* Move left off screen */
        width: 280px; /* Slightly wider for touch */
    }
    
    /* Class to show sidebar when button clicked */
    .sidebar.active {
        transform: translateX(0);
    }

    /* 2. OVERLAY (Dark background when menu is open) */
    .overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.5); z-index: 1500;
        display: none; /* Hidden by default */
    }
    .overlay.active { display: block; }

    /* 3. MOBILE HEADER LAYOUT */
    .mobile-header { 
        display: flex !important; 
        align-items: center; 
        justify-content: space-between;
        margin-bottom: 20px; 
    }
    
    /* Sandwich Button */
    .menu-btn {
        display: block;
        background: none; border: none;
        font-size: 1.8rem; color: var(--primary);
        cursor: pointer; padding: 5px;
    }

    .mobile-header h3 { font-size: 1.2rem; font-weight: 800; color: var(--primary); margin: 0; }
    .desktop-header { display: none !important; } 

    /* 4. MAIN CONTENT ADJUSTMENTS */
    .main-content { 
        margin-left: 0 !important; 
        padding: 20px !important; 
        width: 100% !important;
        padding-bottom: 100px !important; 
    }

    /* 5. STACK GRID */
    .cards-grid { grid-template-columns: 1fr; gap: 15px; }
    .content-grid { grid-template-columns: 1fr; gap: 20px; }
    .row-group { flex-direction: column; gap: 0; }

    /* 6. CARD & FORM */
    .card { padding: 20px; display: flex; justify-content: space-between; align-items: center; }
    .card h3 { margin: 0; font-size: 0.9rem; }
    .card p { margin: 0; font-size: 1.6rem; }
    .section-container { padding: 20px; }
    
    /* 7. BOTTOM NAV */
    .mobile-nav {
        display: flex; position: fixed; bottom: 0; left: 0; width: 100%;
        background: var(--white); border-top: 1px solid #e2e8f0;
        padding: 12px 0 30px 0; 
        justify-content: space-around; z-index: 9999;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
    }
    .nav-item {
        display: flex; flex-direction: column; align-items: center;
        text-decoration: none; color: #94a3b8; font-size: 0.7rem;
    }
    .nav-item .icon { font-size: 1.5rem; margin-bottom: 4px; }
    .nav-item.active { color: var(--accent); }

    /* 8. PREVENT ZOOM */
    input, select, button { font-size: 16px !important; }
    th, td { padding: 12px 5px; font-size: 0.85rem; }
    th:nth-child(2), td:nth-child(2) { max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
