:root {
    /* HSL Colors for better manipulation */
    --hue: 250;
    /* Indigo/Violet base */
    --primary: hsl(var(--hue), 80%, 60%);
    --primary-dark: hsl(var(--hue), 80%, 50%);
    --primary-light: hsl(var(--hue), 80%, 90%);
    /* Light bg */

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    --bg-body: #f3f4f6;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --border-glass: rgba(255, 255, 255, 0.5);

    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.05);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;

    --nav-height: 70px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    background-attachment: fixed;
    height: 100vh;
    overflow: hidden;
    /* Prevent pull-to-refresh on mobile if not desired */
    overscroll-behavior: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* App Container */
#app {
    width: 100%;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

.hidden {
    display: none !important;
}

/* Components */
.glass-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-soft);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    width: 100%;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 14px 0 rgba(100, 100, 255, 0.39);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: white;
    color: var(--text-main);
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0.75rem;
    width: 100%;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 0.5rem;
}

.btn-danger {
    background: #fee2e2;
    color: var(--danger);
    border: none;
    padding: 1rem;
    width: 100%;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
}

/* Auth View */
#auth-screen {
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.1) 100%);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    margin: 0;
    color: var(--primary-dark);
    font-size: 1.8rem;
}

.auth-header p {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
}

.input-group {
    position: relative;
    margin-bottom: 1rem;
}

.input-group i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.8);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    margin-left: 0.5rem;
    color: var(--text-muted);
}

.input-group input:focus {
    border-color: var(--primary);
    background: white;
}

.auth-switch {
    text-align: center;
    font-size: 0.9rem;
    margin-top: 1.5rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer {
    margin-top: 2rem;
    text-align: center;
}

.btn-text-small {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 0.8rem;
}

/* Main Screen Structure */
.app-header {
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    z-index: 20;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.greeting {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.user-email {
    font-weight: 600;
    font-size: 0.9rem;
}

.icon-btn-glass {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn-glass:hover {
    background: white;
}

#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    padding-bottom: 100px;
    /* Nav space */
    scroll-behavior: smooth;
}

/* Navigation */
.bottom-nav {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(15px);
    border-radius: var(--radius-lg);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.4rem;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    padding: 0.5rem;
}

.nav-item.active {
    color: var(--primary);
    transform: translateY(-2px);
}

.nav-item.center-fab {
    background: var(--primary);
    color: white;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -30px;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.4);
    font-size: 1.6rem;
}

/* Dashboard Modules */
.balance-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(79, 70, 229, 0.3);
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.balance-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 60%);
    transform: rotate(30deg);
}

.balance-label {
    opacity: 0.8;
    font-size: 0.9rem;
}

.balance-amount {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0.5rem 0 1.5rem;
}

.balance-row {
    display: flex;
    gap: 1rem;
}

.b-item {
    flex: 1;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    backdrop-filter: blur(5px);
}

.b-item i {
    font-size: 0.9rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: white;
}

.b-item.income i {
    color: var(--success);
}

.b-item.expense i {
    color: var(--danger);
}

.b-item span {
    display: block;
    font-size: 0.8rem;
}

.b-item span:last-child {
    font-weight: 600;
    font-size: 1rem;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    margin-top: 1.5rem;
}

.section-title h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
}

/* Transaction List */
.transaction-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.t-item {
    background: rgba(255, 255, 255, 0.6);
    padding: 1rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.1s, box-shadow 0.1s;
    cursor: pointer;
}

.t-item:active {
    transform: scale(0.98);
}

.t-icon {
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.t-info {
    flex: 1;
}

.t-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.2rem;
    font-weight: 600;
}

.t-btm {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.amt-pos {
    color: var(--success);
}

.amt-neg {
    color: var(--text-main);
}

/* Add View */
.view-header {
    text-align: center;
    margin-bottom: 2rem;
}

.type-switch {
    display: flex;
    background: rgba(255, 255, 255, 0.6);
    padding: 0.3rem;
    border-radius: var(--radius-lg);
    position: relative;
    margin-bottom: 2rem;
}

.switch-opt {
    flex: 1;
    text-align: center;
    padding: 0.8rem;
    cursor: pointer;
    z-index: 2;
    font-weight: 500;
    transition: color 0.3s;
}

.switch-opt.income {
    color: var(--text-muted);
}

.switch-opt.expense {
    color: var(--text-muted);
}

input[type="radio"] {
    display: none;
}

input#t-expense:checked~.switch-opt.expense {
    color: white;
}

input#t-income:checked~.switch-opt.income {
    color: white;
}

.slider {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 50%;
    height: calc(100% - 10px);
    background: var(--danger);
    border-radius: var(--radius-md);
    transition: transform 0.3s ease, background 0.3s;
    z-index: 1;
}

input#t-income:checked~.slider {
    transform: translateX(96%);
    background: var(--success);
}

.amount-group {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
}

.amount-group span {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.amount-group input {
    border: none;
    background: transparent;
    font-size: 3rem;
    font-weight: 700;
    width: 240px;
    text-align: center;
    color: var(--text-main);
    outline: none;
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.stat-bar-bg {
    flex: 1;
    height: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 350px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-up {
    animation: slideUp 0.4s ease forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.empty-placeholder {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.empty-placeholder i {
    font-size: 2rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Updated/New Styles */
.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
}

.chart-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.chart-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.3rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.chart-btn.active {
    background: var(--primary);
    color: white;
}

.budget-card {
    background: rgba(255, 255, 255, 0.6);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.8rem;
    cursor: pointer;
    transition: transform 0.1s;
}

.budget-card:active {
    transform: scale(0.98);
}

.budget-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.progress-bar {
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    transition: width 0.3s;
}

.progress-fill.warning {
    background: var(--warning);
}

.progress-fill.danger {
    background: var(--danger);
}

/* Responsive adjustments */
@media (max-height: 700px) {
    .balance-card {
        padding: 1.5rem;
    }

    .balance-amount {
        font-size: 2rem;
    }
}

/* Dark Mode */
/* Dark Mode Refined */
body.dark-mode {
    --text-main: #e2e8f0;
    /* Slate 200 */
    --text-muted: #94a3b8;
    /* Slate 400 */
    --bg-glass: rgba(30, 41, 59, 0.7);
    /* Slate 800 */
    --border-glass: rgba(255, 255, 255, 0.08);
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    /* Slate 900 -> Indigo 950 */
}

body.dark-mode .glass-card,
body.dark-mode .bottom-nav,
body.dark-mode .app-header {
    background: rgba(30, 41, 59, 0.85);
    /* Slightly more opaque slate */
}

body.dark-mode .modal-content {
    background: #1f2937;
    color: white;
}

body.dark-mode .input-group input,
body.dark-mode .input-group select {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Month Input */
.header-month-input {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    padding: 0.4rem;
    font-family: inherit;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    width: 130px;
}

body.dark-mode .header-month-input {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Insights */
.insights-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.4));
    border: 1px solid rgba(255, 255, 255, 0.6);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
}

body.dark-mode .insights-card {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.05);
}

.insight-icon {
    width: 36px;
    height: 36px;
    background: rgba(245, 158, 11, 0.15);
    /* Orange tint */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--warning);
    flex-shrink: 0;
}

.insight-content p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Card Header Row */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

body.dark-mode .t-item {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .t-icon {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

body.dark-mode .budget-card {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .nav-item {
    color: #6b7280;
}

body.dark-mode .nav-item.active {
    color: var(--primary);
}

body.dark-mode .amt-neg {
    color: #e5e7eb;
}

/* Bottom Sheet Menu */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
}

.sheet-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.bottom-sheet.active .sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet.active {
    pointer-events: auto;
}

.sheet-content {
    background: rgba(255, 255, 255, 0.95);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 1.5rem;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 2;
    padding-bottom: 2rem;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.bottom-sheet.active .sheet-content {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sheet-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.close-sheet {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.5rem;
    transition: color 0.2s;
}

.close-sheet:hover {
    color: var(--text-main);
}

/* Menu List */
.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.menu-list li button {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 1rem;
    font-size: 1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.2s, transform 0.1s;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
}

.menu-list li button:active,
.menu-row:active {
    transform: scale(0.98);
    background: rgba(0, 0, 0, 0.05);
}

.menu-list li button:hover,
.menu-row:hover {
    background: rgba(0, 0, 0, 0.03);
}

.menu-list li button i {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
    color: var(--primary);
}

.text-danger {
    color: var(--danger) !important;
}

.text-danger i {
    color: var(--danger) !important;
}

.menu-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    font-size: 1rem;
    color: var(--text-main);
    cursor: pointer;
    border-radius: 12px;
}

.menu-row span {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 500;
}

.menu-row span i {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
    color: var(--primary);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-round {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    transition: .4s;
    border-radius: 34px;
}

.slider-round:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

input:checked+.slider-round {
    background-color: var(--primary);
}

input:checked+.slider-round:before {
    transform: translateX(22px);
}

/* Profile Btn */
.profile-btn {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.profile-btn:active {
    transform: scale(0.9);
}

/* Dark Mode Updates */
body.dark-mode .sheet-content {
    background: #1e293b;
    /* Slate 800 */
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
}

body.dark-mode .sheet-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .menu-list li button,
body.dark-mode .menu-row {
    color: #f3f4f6;
}

body.dark-mode .menu-list li button:hover,
body.dark-mode .menu-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .slider-round {
    background-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode input:checked+.slider-round {
    background-color: var(--primary);
}

body.dark-mode .profile-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
}

/* Animation refinement */
.btn-primary,
.btn-secondary,
.btn-danger,
.icon-btn-glass,
.nav-item {
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s, color 0.2s;
}

.btn-primary:active,
.btn-secondary:active,
.icon-btn-glass:active {
    transform: scale(0.95);
}

@media (min-width: 500px) {
    .bottom-sheet {
        align-items: center;
    }
}