:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #0b0f19;
    --card-bg: rgba(17, 24, 39, 0.6);
    --glass-border: rgba(255, 255, 255, 0.05);
    --glass-highlight: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --positive: #10b981;
    --negative: #ef4444;
    --neutral: #3b82f6;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(circle at top right, #1e1b4b, #0b0f19 50%, #000000);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    width: 100%;
}

header {
    text-align: center;
    animation: fadeInDown 0.8s ease;
    padding: 1rem 0;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a5b4fc 0%, #e879f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

header p {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-weight: 400;
    font-size: 1.1rem;
    letter-spacing: 0.025em;
}

.summary-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    animation: fadeInUp 0.8s ease 0.2s;
    animation-fill-mode: both;
}

@media (max-width: 480px) {
    .summary-section {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

.metrics-section, .earmark-section, .timeline-section, .chart-section, .savings-section {
    margin-bottom: 0rem;
    animation: fadeInUp 0.8s ease 0.3s;
    animation-fill-mode: both;
    width: 100%;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .metrics-grid { 
        grid-template-columns: 1fr 1fr; 
        gap: 1rem;
    }
}

.metric-box {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    border-radius: 16px;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
}

.metric-box:hover {
    background: rgba(255,255,255,0.04);
    transform: translateY(-2px);
}

.metric-box span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.metric-box h4 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 0.75rem;
}

@media (max-width: 480px) {
    .metric-box { padding: 1rem; }
    .metric-box h4 { font-size: 1.25rem; }
}

/* Calendar Styles */
.calendar-container {
    position: relative;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
    padding: 1rem;
    gap: 2rem;
}

.cal-month-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cal-month-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-left: 0.25rem;
}

.cal-grid-month {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.cal-grid-header {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding-bottom: 0.5rem;
}

.cal-grid-cell {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 8px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    padding: 0.25rem;
    gap: 0.25rem;
    overflow: hidden;
}

.cal-grid-cell.empty {
    background: transparent;
    border-color: transparent;
}

.cal-grid-cell.out-of-range {
    opacity: 0.3;
}

.cal-grid-cell.today {
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.05);
}

.cal-cell-date {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: right;
    margin-bottom: 0.25rem;
}

.cal-cell-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}

.cal-badge.income {
    background: linear-gradient(90deg, var(--positive), #059669);
}

.cal-badge.bill {
    background: linear-gradient(90deg, #ef4444, #b91c1c);
}

.earmark-container {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
}

.earmark-entry {
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: all 0.3s ease;
}

.earmark-entry:hover {
    background: rgba(255,255,255,0.04);
}

.earmark-fund { color: var(--positive); font-weight: 700; }
.earmark-bill { color: var(--text-primary); font-weight: 500;}
.earmark-unfunded { color: var(--negative); font-weight: 700; }

.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.5);
    background: rgba(30, 41, 59, 0.7);
}

.card h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.amount {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

@media (max-width: 480px) {
    .card { padding: 1.25rem; }
    .amount { font-size: 1.5rem; }
    .card h3 { font-size: 0.7rem; }
}

.amount.positive { color: var(--positive); text-shadow: 0 0 20px rgba(16, 185, 129, 0.2); }
.amount.negative { color: var(--negative); text-shadow: 0 0 20px rgba(239, 68, 68, 0.2); }
.amount.neutral { color: var(--neutral); text-shadow: 0 0 20px rgba(59, 130, 246, 0.2); }

/* Desktop Grid overrides for Income and Expense */
@media (min-width: 901px) {
    .app-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    header, .summary-section, .metrics-section, .savings-section, .timeline-section, .chart-section, .earmark-section {
        grid-column: 1 / -1;
    }
    .income-section {
        grid-column: 1 / 2;
    }
    .expense-section {
        grid-column: 2 / 3;
    }
}

.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.glass-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

@media (max-width: 600px) {
    .glass-panel {
        padding: 1.25rem;
        border-radius: 16px;
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--glass-highlight);
    padding-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

@media (max-width: 480px) {
    .section-header h2 {
        font-size: 1.25rem;
    }
}

.btn {
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', sans-serif;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    padding: 0.6rem 1.25rem;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, #7174f2, var(--primary));
}

.primary-btn:active {
    transform: translateY(0);
}

.remove-btn {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
}

.remove-btn:hover {
    background: var(--danger);
    color: white;
}

.list-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.list-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 1.5rem;
    animation: fadeIn 0.4s ease;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.list-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
}

@media (max-width: 600px) {
    .list-item {
        padding: 1rem;
    }
}

.item-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .item-header {
        gap: 0.5rem;
    }
    .income-name, .expense-name {
        width: 100%;
        flex: none;
    }
    .amount-input {
        flex: 1;
    }
}

.input-field {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s;
    width: 100%;
}

.input-field:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.amount-input {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding-left: 1rem;
    transition: all 0.3s;
}

.amount-input:focus-within {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.amount-input span {
    color: var(--text-secondary);
    font-weight: 600;
}

.amount-input input {
    background: transparent;
    border: none;
    width: 120px;
    color: var(--text-primary);
    padding: 0.75rem;
    outline: none;
    font-size: 0.95rem;
    font-weight: 600;
}

@media (max-width: 600px) {
    .amount-input input {
        width: 100%;
    }
}

.item-details {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    align-items: center;
}

@media (max-width: 600px) {
    .item-details {
        flex-direction: column;
        align-items: stretch;
    }
}

.select-field {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s;
    cursor: pointer;
    width: 100%;
    max-width: 250px;
}

@media (max-width: 600px) {
    .select-field { max-width: 100%; }
}

.select-field:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
}

.select-field option {
    background: #1e293b;
    color: white;
}

.date-field {
    color-scheme: dark;
    max-width: 180px;
}

@media (max-width: 600px) {
    .date-field { max-width: 100%; }
}

.toggle-lbl {
    font-size: 0.9rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    padding: 0.5rem;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.toggle-lbl:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.1);
}

.slider-container {
    padding-top: 1.25rem;
    border-top: 1px dashed var(--glass-highlight);
}

.slider-container label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-weight: 500;
}

.allocation-val {
    color: var(--neutral);
    font-weight: 700;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 10px 0;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid var(--primary);
    cursor: pointer;
    margin-top: -10px;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.6);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:active {
    transform: scale(1.1);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Mobile Full-Screen Snap Overrides --- */
@media (max-width: 768px) {
    html, body {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        overflow: hidden;
    }
    .app-container {
        height: 100%;
        width: 100%;
        overflow-y: scroll;
        overflow-x: hidden;
        scroll-snap-type: y mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        padding: 0;
        display: block;
    }
    header, .summary-section, .metrics-section, .savings-section, .timeline-section, .chart-section, .earmark-section, .income-section, .expense-section {
        scroll-snap-align: start;
        scroll-snap-stop: always;
        height: 100vh;
        height: 100dvh;
        width: 100%;
        padding: 1.5rem;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
        justify-content: center;
        box-sizing: border-box;
    }
    
    /* Adjust glass panels to look like floating full-screen cards */
    .glass-panel {
        max-height: calc(100dvh - 3rem); /* 1.5rem padding top/bottom */
        height: 100%;
        border-radius: 24px;
        padding: 1.5rem;
    }

    /* Make internal areas scrollable if they overflow the card */
    .earmark-container, .list-container, .calendar-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding-right: 0.5rem;
    }
    
    /* Ensure charts don't break height constraints */
    .chart-section > div {
        flex: 1;
        min-height: 0;
        height: auto !important;
    }
}

html {
    scroll-behavior: smooth;
}

.sidebar-nav {
    position: fixed;
    top: 50%;
    left: 1rem;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem 0.75rem;
    border-radius: 30px;
    z-index: 1000;
}

.sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    transition: var(--transition);
}

.sidebar-nav a .dot {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transition: var(--transition);
    margin: 0 auto;
}

.sidebar-nav a:hover .dot {
    background: var(--primary);
    transform: scale(1.5);
    box-shadow: 0 0 10px var(--primary);
}

.sidebar-nav a .nav-label {
    position: absolute;
    left: 20px;
    background: rgba(15, 23, 42, 0.9);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
    transition: all 0.3s ease;
}

.sidebar-nav a:hover .nav-label {
    opacity: 1;
    transform: translateX(0);
}

@media (max-width: 1024px) {
    .app-container {
        padding-left: 4rem; /* Make room for the sidebar */
    }
}

@media (max-width: 768px) {
    .sidebar-nav {
        top: auto;
        bottom: 1rem;
        left: 50%;
        transform: translateX(-50%);
        flex-direction: row;
        padding: 0.75rem 1.5rem;
    }
    .sidebar-nav a .nav-label {
        display: none;
    }
    .app-container {
        padding-left: 1rem; /* Reset padding for mobile */
        padding-bottom: 5rem; /* Make room at bottom */
    }
}
