:root {
    /* --- DESIGN TOKENS (Light Mode Default) --- */
    --primary: #5e35b1;
    --primary-glow: rgba(94, 53, 177, 0.4);
    --secondary: #64748b;
    --accent: #00d2ff;

    --bg-body: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-sidebar: #ffffff;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-on-primary: #ffffff;

    --border-color: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(255, 255, 255, 0.4);

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Shadows */
    --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Dimensions */
    --sidebar-width: 280px;
    --header-height: 80px;
    --radius-xl: 24px;
    --radius-lg: 16px;
}

[data-theme="dark"] {
    --bg-body: #020617;
    --bg-card: rgba(15, 23, 42, 0.7);
    --bg-sidebar: #0f172a;

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;

    --border-color: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

/* --- RECOVERY STYLE OVERRIDE --- */
body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    background: var(--bg-body);
    background-image:
        radial-gradient(at 0% 0%, rgba(94, 53, 177, 0.15) 0, transparent 50%),
        radial-gradient(at 100% 0%, rgba(0, 210, 255, 0.1) 0, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* --- GLASSMORPHISM BASE --- */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* --- LAYOUT STRUCTURE --- */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.view {
    min-height: 100vh;
}

/* AUTH VIEW */
#auth-view {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, #1e1b4b 0%, #020617 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 440px;
    padding: 40px;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.logo-area {
    text-align: center;
    margin-bottom: 30px;
}

.logo-area i {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 15px;
}

.logo-area h1 {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -1px;
}

/* DASHBOARD LAYOUT */
#dashboard-view {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    overflow: hidden;
}


/* SIDEBAR */
.sidebar {
    background: var(--bg-sidebar);
    background-image: radial-gradient(at 0% 100%, rgba(94, 53, 177, 0.1) 0, transparent 50%);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 30px 20px;
    z-index: 100;
    transition: width 0.3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 40px;
    padding: 0 10px;
}

.brand i {
    color: var(--primary);
}

.nav-links {
    list-style: none;
    padding: 0;
    flex: 1;
}

.nav-links li {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links li:hover {
    background: var(--border-color);
    color: var(--text-main);
    transform: translateX(5px);
}

.nav-links li.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 8px 16px var(--primary-glow);
}

.nav-links li i {
    font-size: 1.2rem;
}

/* USER CARD IN SIDEBAR */
.user-info {
    margin-top: auto;
    background: var(--border-color);
    padding: 15px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: white;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-details #display-username {
    display: block;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
}

#logout-btn {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.2s;
}

#logout-btn:hover {
    color: var(--danger);
}

/* MAIN CONTENT */
.content {
    padding: 40px;
    overflow-y: auto;
    position: relative;
}

header {
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

header h2 {
    font-size: 2.2rem;
    font-weight: 800;
    margin: 0;
}

header .subtitle {
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 5px;
    display: block;
}

/* THEME TOGGLE */
.theme-switch {
    background: var(--border-color);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
    margin-left: 15px;
}

.theme-switch:hover {
    background: var(--primary);
    color: white;
    transform: rotate(15deg);
}

/* CARDS GRID */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    padding: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.card h3 {
    margin: 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.card .amount {
    font-size: 1.8rem;
    font-weight: 800;
    margin: 10px 0;
    color: var(--text-main);
}

.card-footer {
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* BUDGET SECTION */
.budget-insight {
    padding: 30px;
    background: linear-gradient(135deg, rgba(94, 53, 177, 0.1), rgba(0, 210, 255, 0.05));
    border-left: 6px solid var(--primary);
    margin-bottom: 30px;
}

.budget-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-item h4 {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-item .val {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
}

/* TABLES */
.table-container {
    overflow-x: auto;
    padding-bottom: 10px;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 12px;
}

th {
    padding: 0 20px 5px;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

tbody tr {
    background: var(--bg-card);
    transition: transform 0.2s, background 0.2s;
}

tbody tr:hover {
    transform: scale(1.01) translateY(-2px);
    background: rgba(var(--primary), 0.05);
}

td {
    padding: 16px 20px;
    border-top: 1px solid var(--glass-border);
    border-bottom: 1px solid var(--glass-border);
}

td:first-child {
    border-left: 1px solid var(--glass-border);
    border-top-left-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-lg);
}

td:last-child {
    border-right: 1px solid var(--glass-border);
    border-top-right-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* UTILS */
.text-success {
    color: var(--success) !important;
}

.text-danger {
    color: var(--danger) !important;
}

.hidden {
    display: none !important;
}

/* BUTTONS */
.btn {
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    border: none;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 20px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 30px var(--primary-glow);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--secondary);
    color: white;
}


/* FORMS & INPUTS */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="month"],
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-body);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px var(--primary-glow);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus {
    background: rgba(255, 255, 255, 0.05);
}

/* Specific Style for Month Filter in Header */
#month-filter {
    width: auto;
    min-width: 160px;
    padding: 10px 15px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    font-size: 0.9rem;
}

.type-selector {
    display: flex;
    gap: 10px;
    background: var(--border-color);
    padding: 6px;
    border-radius: var(--radius-lg);
}

.type-selector label {
    flex: 1;
    margin: 0;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.type-selector input {
    display: none;
}

.type-selector label:has(input:checked) {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .type-selector label:has(input:checked) {
    background: var(--primary);
    color: white;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 30px;
}

/* ANIMATIONS */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* MOBILE NAVIGATION (DOCK) */
.mobile-nav {
    display: none;
}

@media (max-width: 768px) {
    #dashboard-view {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .content {
        padding: 20px 20px 100px;
    }

    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 25px;
        left: 20px;
        right: 20px;
        height: 70px;
        background: var(--bg-sidebar);
        border: 1px solid var(--glass-border);
        border-radius: 24px;
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
        z-index: 1000;
        justify-content: space-around;
        align-items: center;
        padding: 0 15px;
    }

    .nav-item {
        background: none;
        border: none;
        color: var(--text-muted);
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        font-size: 0.7rem;
        font-weight: 700;
        transition: all 0.2s;
    }

    .nav-item.active {
        color: var(--primary);
    }

    .nav-item i {
        font-size: 1.4rem;
    }

    #btn-fab-mobile {
        width: 60px;
        height: 60px;
        background: var(--primary);
        color: white;
        border-radius: 50%;
        margin-top: -45px;
        box-shadow: 0 10px 20px var(--primary-glow);
        border: 5px solid var(--bg-body);
    }

    header h2 {
        font-size: 1.8rem;
    }
}

/* --- RECOVERY STYLES --- */

/* Tabs Logic (Critical for Navigation) */
.tab-content {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-content.active {
    display: block;
}

/* Modals Overlay (Critical for Actions) */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 1000;
    /* Flex centering for modals content */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal Cards */
.modal {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    /* Reset text align */
    text-align: left;
    /* Animation */
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);

    /* Ensure it behaves as a block item inside flex overlay */
    position: relative;
}

/* Special Case for large import modal */
#modal-import {
    max-width: 1100px;
}

/* Ensure hidden overrides display flex */
.hidden {
    display: none !important;
}

/* FAB Responsive Text */
.fab-text {
    display: none;
    font-size: 0.9rem;
    font-weight: 600;
    margin-left: 8px;
    color: white;
}

@media (min-width: 768px) {
    .btn-fab {
        width: auto;
        padding: 0 20px;
        border-radius: 30px;
    }

    .fab-text {
        display: block;
    }
}

/* CUSTOM MONTH PICKER STYLES */
#month-picker-dropdown {
    animation: zoomIn 0.2s ease-out;
}

.btn-picker {
    background: var(--border-color);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-picker:hover {
    background: var(--primary);
    color: white;
}

.month-cell {
    padding: 12px 5px;
    background: var(--border-color);
    border: none;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.month-cell:hover {
    background: var(--primary-glow);
    color: var(--primary);
}

.month-cell.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px var(--primary-glow);
}