:root {
    --income-color: #28a745;
    --expense-color: #dc3545;
    --savings-color: #0d6efd;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --text-color: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --nav-bg: #ffffff;
    --nav-active: #0d6efd;
    --fab-bg: #0d6efd;
    --fab-color: #ffffff;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 16px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-color: #1a1a2e;
    --card-bg: #16213e;
    --text-color: #e0e0e0;
    --text-secondary: #9e9e9e;
    --border-color: #2a2a4a;
    --nav-bg: #16213e;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    padding-bottom: 80px;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition), color var(--transition);
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    transition: background var(--transition);
}

.fab {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--fab-bg);
    color: var(--fab-color);
    border: none;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform var(--transition), box-shadow var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.fab:active { transform: scale(0.95); }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 200;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 12px;
    transition: color var(--transition), background var(--transition);
    min-width: 56px;
}

.nav-item i, .nav-item svg, .nav-item .nav-icon {
    font-size: 22px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item.active { color: var(--nav-active); }
.nav-item:active { background: rgba(13, 110, 253, 0.1); }

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 10px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.summary-card .label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-card .amount {
    font-size: 16px;
    font-weight: 700;
}

.summary-card.income .amount { color: var(--income-color); }
.summary-card.expense .amount { color: var(--expense-color); }
.summary-card.savings .amount { color: var(--savings-color); }

.txn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.txn-item:last-child { border-bottom: none; }

.txn-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.txn-info { flex: 1; min-width: 0; }

.txn-info .txn-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.txn-info .txn-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.txn-amount {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
}

.txn-amount.income { color: var(--income-color); }
.txn-amount.expense { color: var(--expense-color); }

.page-header {
    padding: 16px 16px 8px;
    position: sticky;
    top: 0;
    background: var(--bg-color);
    z-index: 50;
    transition: background var(--transition);
}

.page-header h1 {
    font-size: 20px;
    font-weight: 700;
}

.content-wrapper {
    padding: 0 16px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-sheet {
    background: var(--card-bg);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    background: var(--bg-color);
    color: var(--text-color);
    transition: border-color var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--nav-active);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236c757d' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--nav-active); color: #fff; }
.btn-primary:active { background: #0b5ed7; }
.btn-success { background: var(--income-color); color: #fff; }
.btn-danger { background: var(--expense-color); color: #fff; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-color);
}

.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 17px; }
.btn-block { width: 100%; }

.btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.type-toggle {
    display: flex;
    gap: 0;
}

.type-toggle .btn {
    flex: 1;
    border-radius: 0;
}

.type-toggle .btn:first-child { border-radius: 12px 0 0 12px; }
.type-toggle .btn:last-child { border-radius: 0 12px 12px 0; }

.progress {
    background: var(--bg-color);
    border-radius: 10px;
    height: 10px;
    overflow: hidden;
    margin-top: 6px;
}

.progress-bar {
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

.chart-container {
    position: relative;
    width: 100%;
    max-height: 300px;
    margin: 0 auto;
}

.chart-container canvas { max-height: 260px; }

.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.filter-chip {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    border: 1.5px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition);
}

.filter-chip.active {
    background: var(--nav-active);
    color: #fff;
    border-color: var(--nav-active);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; margin-top: 8px; }

.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-color);
}

.auth-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.auth-card .app-logo {
    text-align: center;
    margin-bottom: 24px;
}

.auth-card .app-logo .logo-text {
    font-size: 28px;
    font-weight: 800;
    color: var(--nav-active);
}

.auth-card .app-logo .logo-sub {
    font-size: 13px;
    color: var(--text-secondary);
}

.alert {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.alert-info { background: #cff4fc; color: #055160; border: 1px solid #b6effb; }
.alert-success { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
.alert-danger { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
.alert-warning { background: #fff3cd; color: #664d03; border: 1px solid #ffecb5; }

[data-theme="dark"] .alert-info { background: #0a3640; color: #99edff; border-color: #0e5a6b; }
[data-theme="dark"] .alert-success { background: #0e2e1c; color: #8effb8; border-color: #1c5234; }
[data-theme="dark"] .alert-danger { background: #341214; color: #ffb4be; border-color: #6b1e22; }
[data-theme="dark"] .alert-warning { background: #332b00; color: #ffec99; border-color: #6b5a00; }

.txn-amount.savings { color: var(--savings-color); }

.pin-input {
    -webkit-text-security: disc;
    letter-spacing: 12px;
}
.pin-input::-webkit-outer-spin-button,
.pin-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.alert .btn-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0 4px;
}

.month-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 16px;
}

.month-selector button {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    font-size: 16px;
}

.settings-section { margin-bottom: 24px; }
.settings-section h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}

.settings-item:last-child { border-bottom: none; }

.settings-item .si-label { font-size: 15px; font-weight: 500; }

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    transition: var(--transition);
    border-radius: 28px;
}

.slider:before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: var(--transition);
    border-radius: 50%;
}

input:checked + .slider { background: var(--nav-active); }
input:checked + .slider:before { transform: translateX(22px); }

.savings-goal-card {
    border-left: 4px solid var(--nav-active);
}

.savings-goal-card .goal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.savings-goal-card .goal-name {
    font-weight: 600;
    font-size: 15px;
}

.swipe-action {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    transition: transform 0.1s;
}

.swipe-delete { right: 0; background: var(--expense-color); }
.swipe-edit { right: 0; background: var(--nav-active); }

@media (min-width: 768px) {
    body {
        display: flex;
        justify-content: center;
    }

    .app-container {
        max-width: 500px;
        width: 100%;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        min-height: 100vh;
        position: relative;
    }
}

@media (min-width: 1024px) {
    .summary-cards { gap: 16px; }
    .summary-card { padding: 20px 14px; }
    .summary-card .amount { font-size: 20px; }
}
