/* CSS Variables for Themes */
:root {
    /* Light Mode (Default) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    
    --accent-primary: #6366f1;
    --accent-secondary: #4f46e5;
    --accent-light: #e0e7ff;
    
    --success: #10b981;
    --success-bg: #d1fae5;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

body.dark-mode {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --glass-bg: rgba(30, 41, 59, 0.75);
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
    
    --accent-primary: #818cf8;
    --accent-secondary: #6366f1;
    --accent-light: #312e81;
    
    --success: #34d399;
    --success-bg: #064e3b;
    --danger: #f87171;
    --danger-bg: #7f1d1d;
    --warning: #fbbf24;
    --warning-bg: #78350f;
    
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-primary);
    transition: background-color var(--transition-normal), color var(--transition-normal), background-image var(--transition-normal);
    line-height: 1.5;
    font-size: 1rem;
}

/* Global Utilities */
.hidden { display: none !important; }

/* ========================================================
   1. MOBILE-FIRST BASE LAYOUT (Default: 0px - 767px)
   ======================================================== */

.mobile-only {
    display: flex;
}

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

/* Sidebar (Hidden by default, overlays when open) */
.sidebar {
    width: 250px;
    background-color: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.sidebar.open {
    transform: translateX(0);
}

/* Sidebar Details */
.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-primary);
    margin-bottom: 2.5rem;
    padding: 0 1rem;
}

.logo h2 {
    font-size: 1.5rem;
    font-weight: 700;
}
.logo-icon { font-size: 2rem; }

nav ul { list-style: none; flex: 1; }
nav li { margin-bottom: 0.5rem; }

nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all var(--transition-fast);
    min-height: 44px; /* Touch target minimum */
}

nav a:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

nav li.active a {
    background-color: var(--accent-light);
    color: var(--accent-primary);
}

.sidebar-bottom {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.nav-section-title {
    font-size: 0.75rem; 
    color: var(--text-muted); 
    font-weight: 600; 
    padding: 0 1rem; 
    margin-bottom: 0.5rem; 
    letter-spacing: 1px;
}

.role-badge {
    display: flex; 
    align-items: center; 
    gap: 0.5rem; 
    font-size: 0.8rem; 
    color: var(--accent-primary); 
    font-weight: 500;
    padding: 0 1rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: 0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.view-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
}

.view-section.hidden { display: none; }
.view-section.active > * {
    animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.view-section.active > *:nth-child(1) { animation-delay: 0.05s; }
.view-section.active > *:nth-child(2) { animation-delay: 0.15s; }
.view-section.active > *:nth-child(3) { animation-delay: 0.25s; }
.view-section.active > *:nth-child(4) { animation-delay: 0.35s; }
.view-section.active > *:nth-child(5) { animation-delay: 0.45s; }

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.top-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.header-left {
    width: 100%;
    display: flex;
    align-items: center;
}

.header-left h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

/* Interactive Elements Base Forms */
.custom-select, .custom-input {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    font-size: 1rem; /* Minimum 16px to prevent iOS auto-zoom on mobile */
    cursor: pointer;
    transition: border-color var(--transition-fast);
    min-height: 44px;
    width: 100%; /* Full width on mobile */
}

.custom-input { cursor: text; }
.custom-select:focus, .custom-input:focus { border-color: var(--accent-primary); }

.btn-primary, .btn-secondary, .btn-danger {
    min-height: 44px;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all var(--transition-fast);
    font-size: 1rem; /* 16px minimum */
    border: none;
    width: 100%; /* Stretch on mobile */
}

.btn-primary { background-color: var(--accent-primary); color: white; }
.btn-primary:hover {
    background-color: var(--accent-secondary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary { background-color: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--border-color); }

.btn-danger { background-color: var(--danger); color: white; }
.btn-danger:hover { background-color: #dc2626; }

.btn-icon {
    min-height: 44px;
    min-width: 44px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast);
}
.btn-icon:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Base Card & Grid system */
.card {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.25rem; /* Adjusted for mobile */
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.card-header h3 { font-size: 1rem; color: var(--text-secondary); font-weight: 500; }
.card-header span { padding: 0.5rem; border-radius: var(--radius-md); }

.card h2 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.5rem; }
.card-trend { font-size: 0.85rem; display: flex; align-items: center; gap: 0.25rem; }
.card-trend.positive { color: var(--success); }
.card-trend.negative { color: var(--danger); }

/* Layout Grids: Default to 1-column mobile views */
.summary-cards, .charts-section, .wallet-grid, .settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    width: 100%;
}

.chart-container {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    width: 100%;
}
.chart-container h3 { margin-bottom: 1rem; font-size: 1.1rem; color: var(--text-primary); }
.category-chart-wrapper { display: flex; flex-direction: column; width: 100%; flex: 1; }
.canvas-wrapper { position: relative; height: 250px; width: 100%; }

.custom-legend { display: flex; flex-direction: column; gap: 0.5rem; width: auto; margin-top: 1rem; }
.custom-legend-item { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.legend-label-container { display: flex; align-items: center; gap: 0.5rem; }
.legend-color-box { width: 10px; height: 10px; border-radius: 2px; }

/* Transactions Settings */
.transactions-section {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    min-width: 0;
    overflow: hidden;
}

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }

.table-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    width: 100%;
}
.search-box input {
    border: none;
    background: transparent;
    outline: none;
    color: var(--text-primary);
    margin-left: 0.5rem;
    width: 100%;
    min-height: 44px; /* Touch target */
    font-size: 1rem;
}

/* Transaction Table Base */
.table-container {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: normal; /* Mobile default text squish */
    font-size: 0.85rem; /* Smaller font on mobile to fit columns */
}

th, td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td { color: var(--text-primary); }
tr:hover { background-color: var(--bg-tertiary); }
.amount-col { text-align: right; font-weight: 600; font-size: 0.9rem; }
.action-col { text-align: right; }

.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-expense { background-color: var(--danger-bg); color: var(--danger); }
.badge-income { background-color: var(--success-bg); color: var(--success); }

.txn-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.action-btn { min-height: 44px; min-width: 44px; background: transparent; border: none; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.action-btn:hover { color: var(--accent-primary); }
.action-btn.delete:hover { color: var(--danger); }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem; color: var(--text-secondary); }
.empty-icon { font-size: 3rem; color: var(--border-color); margin-bottom: 1rem; }

/* Wallet UI defaults */
.my-cards-section { display: flex; flex-direction: column; gap: 1.5rem; }
.credit-card {
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    color: white;
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: transform 0.4s ease, box-shadow 0.4s ease;
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
}
.primary-card { background: linear-gradient(135deg, rgba(99, 102, 241, 0.9), rgba(79, 70, 229, 0.95)); }
.secondary-card { background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95)); }
body.dark-mode .secondary-card { background: linear-gradient(135deg, rgba(71, 85, 105, 0.9), rgba(30, 41, 59, 0.95)); }
.credit-card::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(255, 255, 255, 0) 40%); pointer-events: none; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.chip { font-size: 3rem; color: #eab308; }
.card-number { font-size: 1.5rem; letter-spacing: 2px; font-weight: 500; }
.card-bottom { display: flex; justify-content: space-between; align-items: flex-end; }
.card-info span { font-size: 0.75rem; text-transform: uppercase; opacity: 0.8; }
.card-info p { font-size: 1.1rem; font-weight: 600; }

.limit-card { margin-bottom: 1rem; }
.limit-info { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 0.9rem; font-weight: 500; color: var(--text-primary); }
.progress-bar { width: 100%; height: 8px; background-color: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background-color: var(--success); border-radius: 4px; }
.progress-fill.warning { background-color: var(--warning); }
.progress-fill.danger { background-color: var(--danger); }

/* Settings Settings UI */
.settings-card { display: flex; flex-direction: column; padding: 1.5rem; }
.divider { border: none; border-top: 1px solid var(--border-color); margin: 1rem 0; }
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text-secondary); }
.form-row { display: grid; grid-template-columns: 1fr; gap: 1rem; }

/* Modal Modals defaults*/
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end; /* Mobile Bottom Sheet alignment default */
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 0 0 1rem 0; /* Add bottom padding */
    opacity: 1;
    transition: opacity var(--transition-normal);
}
.modal.hidden { opacity: 0; pointer-events: none; }
.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: translateY(0);
    transition: transform var(--transition-normal);
    max-height: 90vh;
    overflow-y: auto;
}
.modal.hidden .modal-content { transform: translateY(100%); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-header h3 { font-size: 1.25rem; }
.modal-footer { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; width: 100%; }

/* Utilities */
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 1rem; }
.error-msg { color: var(--danger); font-size: 0.85rem; display: block; margin-top: 0.25rem; font-weight: 500; }
.error-msg.hidden { display: none; }
button:disabled { opacity: 0.6; cursor: not-allowed; }


/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 9999;
}
.toast {
    min-width: 250px;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 4px solid var(--accent-primary);
    animation: slideIn 0.3s ease forwards;
    transform: translateY(10px);
    opacity: 0;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent-primary); }
.toast.fade-out { animation: slideOut 0.3s ease forwards; }

@keyframes slideIn { to { transform: translateY(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateY(10px); opacity: 0; } }

/* API Loading Overlay */
.loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-primary); display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 9999; opacity: 1; transition: opacity 0.5s ease, visibility 0.5s ease;
}
.loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-overlay p { margin-top: 1.5rem; color: var(--text-secondary); font-size: 1.1rem; font-weight: 500; }
.spinner {
    width: 60px; height: 60px; border: 4px solid var(--border-color); border-top: 4px solid var(--accent-primary); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Custom Progress Bars */
.progress-container { margin-bottom: 0.8rem; }
.progress-label-row { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 0.2rem; }
.progress-bar-bg { width: 100%; height: 6px; background-color: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 3px; }

/* ========================================================
   2. TABLET BREAKPOINT (min-width: 768px)
   ======================================================== */
@media (min-width: 768px) {
    /* Header Re-orientation */
    .top-header {
        flex-direction: row;
        align-items: center;
        gap: 1.5rem;
    }
    
    .header-left { width: auto; }
    .header-right { width: auto; justify-content: flex-end; }
    
    /* Input layout recovery */
    .custom-select, .custom-input, .btn-primary, .btn-secondary, .btn-danger, .search-box input {
        width: auto;
    }

    /* Grids Upgrade to 2 Columns */
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    
    /* Table layout upgrades */
    .table-actions {
        flex-direction: row;
        align-items: center;
        margin-bottom: 2rem;
    }
    table { font-size: 0.95rem; }
    th { font-size: 0.875rem; }

    .form-row { grid-template-columns: 1fr 1fr; }
    
    /* Modal alignment adjustment */
    .modal {
        align-items: center; /* Center horizontally/vertically */
        padding: 0;
    }
    .modal-content {
        padding: 2rem;
    }
    .modal.hidden .modal-content { transform: translateY(20px); }
    .modal-footer {
        justify-content: flex-end;
    }
}

/* ========================================================
   3. DESKTOP BREAKPOINT (min-width: 1024px)
   ======================================================== */
@media (min-width: 1024px) {
    .dashboard-container {
        flex-direction: row;
    }

    .mobile-only {
        display: none !important;
    }

    /* Sidebar fully visible natively */
    .sidebar {
        transform: translateX(0);
        box-shadow: none;
        z-index: 10;
        width: 250px;
    }

    /* Main Content gets margin for sidebar */
    .main-content {
        margin-left: 250px;
        padding: 2rem 3rem;
    }

    /* Grids scaling up fully */
    .summary-cards {
        grid-template-columns: repeat(4, 1fr);
    }
    .summary-cards.three-cols {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .charts-section {
        grid-template-columns: 2fr 1fr;
    }
    
    .wallet-grid {
        grid-template-columns: 2fr 1fr;
    }
    
    .settings-grid {
        grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    }
    
    .chart-container > div {
        display: flex;
        align-items: center;
    }
    .category-chart-wrapper {
        flex-direction: row;
        align-items: center;
    }
    .custom-legend {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 40%;
    }
    .custom-legend.relative-legend {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: auto;
    }

    /* Table adjustments */
    table {
        font-size: 1rem;
        white-space: nowrap; /* Desktop width handles nowrap cleanly */
    }
    th, td { padding: 1rem; }
    
    .credit-card { padding: 2rem; }
    .card-number { letter-spacing: 4px; font-size: 1.8rem; }
    
    /* Toast moved securely below */
    .toast-container {
        bottom: 2rem;
        right: 2rem;
        left: auto;
        transform: translateY(0);
    }
}

/* ========================================================
   4. LARGE DESKTOP (min-width: 1440px)
   ======================================================== */
@media (min-width: 1440px) {
    .main-content {
        padding: 3rem 4rem;
        max-width: 1600px;
        margin-left: 250px; /* Plus keeping centered ideally */
    }
}
