/* =========================================
   1. VARIABLES & RESET
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Color Palette - Modern Light Theme */
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    
    --primary: #10b981;       /* Emerald Green */
    --primary-hover: #059669;
    --secondary: #3b82f6;     /* Royal Blue */
    --danger: #ef4444;        /* Red */
    --warning: #f59e0b;       /* Orange */
    --success: #10b981;       /* Green */
    
    --text-main: #111827;     /* Deep Black/Grey */
    --text-muted: #6b7280;    /* Medium Grey */
    --border: #e5e7eb;        /* Light Border */
    
    /* Spacing & UI */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; outline: none; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0; padding: 0;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; transition: 0.2s; }
ul { list-style: none; padding: 0; margin: 0; }

/* =========================================
   2. LAYOUT ENGINE
   ========================================= */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 1000;
    display: flex; flex-direction: column;
    transition: transform 0.3s ease;
}

.logo-area {
    height: var(--header-height);
    display: flex; align-items: center; padding: 0 24px;
    font-size: 1.25rem; font-weight: 700; color: var(--text-main);
    border-bottom: 1px solid var(--border);
}

.nav-links { padding: 20px 15px; overflow-y: auto; flex: 1; }
.nav-links li { margin-bottom: 5px; }
.nav-links a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    color: var(--text-muted);
    border-radius: 8px;
    font-weight: 500;
}
.nav-links a:hover { background: #f9fafb; color: var(--text-main); }
.nav-links a.active { background: #ecfdf5; color: var(--primary); font-weight: 600; }

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 30px;
    min-height: 100vh;
    transition: margin-left 0.3s ease, width 0.3s ease;
}

/* Header */
.top-bar {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 30px;
    margin: -30px -30px 30px -30px; /* Flush with edges */
    position: sticky; top: 0; z-index: 900;
}
.page-title h1 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.mobile-toggle { display: none; background: none; border: none; font-size: 1.6rem; cursor: pointer; color: var(--text-main); }
.sidebar-overlay { display: none; }

/* =========================================
   3. GLOBAL COMPONENTS (Buttons, Forms, Cards)
   ========================================= */
/* Cards */
.stat-card, .bill-card, .sub-card, .account-card, .sum-card, .modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: relative;
}

/* Grids */
.stats-grid, .accounts-grid, .sub-grid, .forecast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 30px;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 20px;
    background: var(--primary); color: white;
    border: none; border-radius: 8px;
    font-weight: 500; font-size: 0.95rem;
    cursor: pointer; transition: 0.2s;
}
.btn:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; font-size: 0.9rem; }
.form-input {
    width: 100%; padding: 12px;
    border: 1px solid var(--border); border-radius: 8px;
    background: #f9fafb; font-family: inherit; font-size: 1rem;
    transition: 0.2s;
}
.form-input:focus { background: white; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1); }

/* =========================================
   4. MODULE: DASHBOARD
   ========================================= */
.stat-card h3 { margin: 0 0 10px 0; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 1.8rem; font-weight: 700; color: var(--text-main); }

.forecast-section { background: var(--bg-card); padding: 25px; border-radius: var(--radius); border: 1px solid var(--border); }
.forecast-box { background: #f9fafb; padding: 15px; border-radius: 8px; text-align: center; }
.forecast-box small { display: block; color: var(--text-muted); margin-bottom: 5px; }
.forecast-box .amount { font-size: 1.2rem; font-weight: 700; color: var(--text-main); }

/* =========================================
   5. MODULE: ACCOUNTS
   ========================================= */
.account-card { display: flex; flex-direction: column; justify-content: space-between; min-height: 200px; transition: 0.2s; }
.account-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; }
.bank-logo { 
    width: 48px; height: 48px; border-radius: 10px; background: #f3f4f6;
    display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--text-muted);
    font-size: 1.2rem; object-fit: contain;
}

.account-name { font-size: 1.1rem; font-weight: 600; color: var(--text-main); margin-bottom: 5px; }
.account-balance { font-size: 1.6rem; font-weight: 700; color: var(--text-main); letter-spacing: -0.5px; }
.currency-tag { font-size: 0.85rem; color: var(--text-muted); }

/* Type Indicators (Top Border) */
.type-Bank { border-top: 4px solid #3b82f6; }
.type-Credit { border-top: 4px solid #ef4444; }
.type-Cash { border-top: 4px solid #10b981; }
.type-Investment { border-top: 4px solid #8b5cf6; }

.card-actions-bar {
    margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}
.action-btn { width: 32px; height: 32px; border-radius: 6px; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-edit { background: #eff6ff; color: #3b82f6; }
.btn-delete { background: #fef2f2; color: #ef4444; }
.btn-balance { background: #ecfdf5; color: #10b981; }

/* =========================================
   6. MODULE: TRANSACTIONS & TABLES
   ========================================= */
.table-container {
    background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border);
    overflow: hidden; overflow-x: auto; /* IMPORTANT: Enables scroll on mobile */
}

.custom-table { width: 100%; border-collapse: collapse; min-width: 700px; }
.custom-table th {
    background: #f9fafb; text-align: left; padding: 16px 20px;
    font-weight: 600; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.custom-table td { padding: 16px 20px; border-bottom: 1px solid var(--border); color: var(--text-main); vertical-align: middle; }
.custom-table tr:hover { background: #f9fafb; }
.custom-table tr:last-child td { border-bottom: none; }

/* Cell Content Styles */
.date-cell span { display: block; line-height: 1.3; }
.date-day { font-weight: 600; }
.date-meta { font-size: 0.85rem; color: var(--text-muted); }

.amount-income { color: var(--success); font-weight: 600; }
.amount-expense { color: var(--text-main); font-weight: 600; }

.cat-badge { 
    display: inline-block; padding: 4px 10px; border-radius: 6px; 
    font-size: 0.8rem; background: #f3f4f6; color: var(--text-muted); font-weight: 500;
}
.cat-btn { background: none; border: none; cursor: pointer; padding: 0; font-family: inherit; font-size: inherit; }

/* Tabs */
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border); margin-bottom: 25px; padding-bottom: 10px; overflow-x: auto; }
.tab { text-decoration: none; color: var(--text-muted); font-weight: 600; padding: 8px 12px; border-radius: 6px; white-space: nowrap; }
.tab.active { background: #ecfdf5; color: var(--primary); }

/* Bulk Action Bar */
.bulk-bar {
    background: var(--text-main); color: white; padding: 12px 20px;
    border-radius: 8px; margin-bottom: 20px; display: none;
    align-items: center; justify-content: space-between;
}
.bulk-bar.active { display: flex; }

/* =========================================
   7. MODULE: SUBSCRIPTIONS & FUTURE
   ========================================= */
.sub-card { display: flex; flex-direction: column; min-height: 220px; }
.sub-header { display: flex; justify-content: space-between; margin-bottom: 15px; }
.sub-icon { 
    width: 48px; height: 48px; border-radius: 10px; background: #f8fafc;
    display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--text-muted);
}
.sub-price { text-align: right; }
.sub-amount { font-size: 1.3rem; font-weight: 700; display: block; }
.sub-freq { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; }

/* Progress Bar */
.cycle-info { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }
.progress-bg { width: 100%; height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.5s; }
.progress-fill.danger { background: var(--danger); }
.progress-fill.warning { background: var(--warning); }

.sub-footer { margin-top: auto; padding-top: 15px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }

/* Timeline Items */
.timeline-section { margin-bottom: 30px; }
.timeline-title { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 15px; }

.bill-card { display: flex; justify-content: space-between; align-items: center; padding: 20px; }
.bill-date-box { background: #f1f5f9; padding: 8px 15px; border-radius: 8px; text-align: center; margin-right: 15px; min-width: 65px; }
.bill-day { display: block; font-weight: 700; font-size: 1.25rem; line-height: 1; }
.bill-month { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }

/* =========================================
   8. MODULE: SETTINGS & MODALS
   ========================================= */
.settings-layout { display: flex; gap: 30px; align-items: flex-start; }
.settings-nav { width: 250px; background: var(--bg-card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); flex-shrink: 0; }
.settings-nav a { display: block; padding: 15px 20px; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 500; }
.settings-nav a:hover { background: #f9fafb; color: var(--primary); }
.settings-nav a.active { background: #ecfdf5; color: var(--primary); border-left: 4px solid var(--primary); }

.settings-content { flex: 1; background: var(--bg-card); padding: 30px; border-radius: var(--radius); border: 1px solid var(--border); }

/* Modals */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 2000;
    align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
}
.modal.active { display: flex; }
.modal-content {
    background: var(--bg-card); padding: 30px; width: 90%; max-width: 500px;
    border-radius: var(--radius); box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.csv-dropzone { border: 2px dashed #cbd5e1; padding: 40px; text-align: center; border-radius: 12px; cursor: pointer; background: #f8fafc; }
.csv-dropzone:hover { border-color: var(--primary); background: #ecfdf5; }

/* =========================================
   9. LOGIN PAGE
   ========================================= */
.login-container {
    min-height: 100vh; display: flex; justify-content: center; align-items: center;
    background: #f3f4f6;
}
.login-box {
    background: white; padding: 40px; border-radius: 16px; width: 100%; max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05); text-align: center; border: 1px solid var(--border);
}
.login-header h2 { margin-bottom: 10px; color: var(--text-main); }
.error-msg { background: #fee2e2; color: #b91c1c; padding: 10px; border-radius: 8px; margin-bottom: 15px; font-size: 0.9rem; }

/* =========================================
   10. MOBILE RESPONSIVENESS
   ========================================= */
@media (max-width: 768px) {
    /* 1. Layout Reset */
    .sidebar { transform: translateX(-100%); box-shadow: 5px 0 15px rgba(0,0,0,0.1); }
    .sidebar.active { transform: translateX(0); }
    
    .main-content { margin-left: 0; width: 100%; padding: 15px; }
    
    /* 2. Header adjustments */
    .top-bar { padding: 0 15px; margin: -15px -15px 20px -15px; }
    .mobile-toggle { display: block; margin-right: 15px; }
    
    /* 3. Overlay */
    .sidebar-overlay {
        position: fixed; top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5); z-index: 999;
        display: none;
    }
    .sidebar-overlay.active { display: block; }
    
    /* 4. Grid Stack */
    .stats-grid, .accounts-grid, .sub-grid, .forecast-grid, .rate-grid { grid-template-columns: 1fr; }
    .settings-layout { flex-direction: column; }
    .settings-nav { width: 100%; margin-bottom: 20px; }
    
    /* 5. Summary Bars */
    .summary-bar { grid-template-columns: 1fr; }
    
    /* 6. Typography adjustments */
    .page-title h1 { font-size: 1.2rem; }
    .stat-card .value { font-size: 1.5rem; }
}