:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-modal: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --income: #10b981;
    --expense: #ef4444;
    --transfer: #8b5cf6;
}

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --bg-modal: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

/* Auth Page */
.auth-container {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
}

[data-theme="light"] .auth-container {
    background: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 50%, #e0f2fe 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}

[data-theme="light"] .auth-card {
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.1);
}

.auth-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.25rem;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

/* Form */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrap input,
.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus,
.input-wrap input:focus {
    border-color: var(--accent);
}

.input-wrap .toggle-pw {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.125rem;
    line-height: 1;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.9375rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.2;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    border-radius: 0.5rem;
}

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-income { background: var(--income); color: #fff; }
.btn-expense { background: var(--expense); color: #fff; }
.btn-transfer { background: var(--transfer); color: #fff; }

.btn-icon {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border-radius: 50%;
    font-size: 1.25rem;
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Layout */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--bg-primary);
}

.app-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-content {
    flex: 1;
    padding: 0 1.25rem 6rem;
    overflow-y: auto;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    display: flex;
    justify-content: space-around;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    z-index: 50;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.375rem 0.75rem;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.6875rem;
    font-weight: 500;
    transition: color 0.2s;
    border-radius: 0.5rem;
}

.nav-item.active { color: var(--accent); }
.nav-item svg { width: 1.5rem; height: 1.5rem; }

/* Wallet Cards */
.wallets-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0.25rem 0 1rem;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.wallets-scroll::-webkit-scrollbar { display: none; }

.wallet-card {
    flex: 0 0 260px;
    scroll-snap-align: start;
    border-radius: 1rem;
    padding: 1.25rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.wallet-card:hover { transform: scale(1.02); }

.wallet-card::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -20%;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}

.wallet-card .wc-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.wallet-card .wc-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.wallet-card .wc-category {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    background: rgba(255,255,255,0.15);
    padding: 0.2rem 0.5rem;
    border-radius: 0.375rem;
}

.wallet-card .wc-name {
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.9;
    margin-top: 0.75rem;
}

.wallet-card .wc-balance {
    font-size: 1.375rem;
    font-weight: 700;
    margin-top: 0.25rem;
}

.wallet-add-card {
    flex: 0 0 260px;
    scroll-snap-align: start;
    border-radius: 1rem;
    padding: 1.25rem;
    border: 2px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    min-height: 140px;
    transition: border-color 0.2s;
}

.wallet-add-card:hover { border-color: var(--accent); color: var(--accent); }

/* Salary Calculator */
.salary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

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

.salary-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
}

.salary-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.salary-stat {
    padding: 0.75rem;
    border-radius: 0.75rem;
    background: var(--bg-input);
}

.salary-stat .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.salary-stat .value {
    font-size: 1.0625rem;
    font-weight: 700;
}

.salary-stat .value.income { color: var(--income); }
.salary-stat .value.expense { color: var(--expense); }

.progress-bar {
    height: 0.625rem;
    background: var(--bg-input);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.6s ease, background 0.3s;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.375rem;
}

/* Transaction list */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.trx-list { display: flex; flex-direction: column; gap: 0.5rem; }

.trx-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}

.trx-item:hover { background: var(--bg-input); }

.trx-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    flex-shrink: 0;
}

.trx-icon.income { background: rgba(16,185,129,0.15); color: var(--income); }
.trx-icon.expense { background: rgba(239,68,68,0.15); color: var(--expense); }
.trx-icon.transfer { background: rgba(139,92,246,0.15); color: var(--transfer); }

.trx-info { flex: 1; min-width: 0; }
.trx-info .trx-cat { font-weight: 600; font-size: 0.875rem; }
.trx-info .trx-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trx-right { text-align: right; flex-shrink: 0; }
.trx-right .trx-amount { font-weight: 700; font-size: 0.9375rem; }
.trx-right .trx-amount.income { color: var(--income); }
.trx-right .trx-amount.expense { color: var(--expense); }
.trx-right .trx-amount.transfer { color: var(--transfer); }
.trx-right .trx-date { font-size: 0.6875rem; color: var(--text-muted); }

/* Notes */
.note-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.875rem;
    margin-bottom: 0.5rem;
}

.note-check {
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 0.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: none;
    padding: 0;
}

.note-check.done {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.note-body { flex: 1; min-width: 0; }
.note-body .note-title { font-weight: 600; font-size: 0.9375rem; }
.note-body .note-title.done { text-decoration: line-through; opacity: 0.5; }
.note-body .note-content { font-size: 0.8125rem; color: var(--text-secondary); margin-top: 0.25rem; }
.note-body .note-remind {
    font-size: 0.75rem;
    color: var(--warning);
    margin-top: 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.note-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-modal);
    border-radius: 1.5rem 1.5rem 0 0;
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    max-height: 90dvh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-content h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.modal-actions .btn { flex: 1; }

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

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 0.875rem 0.5rem;
    border-radius: 0.875rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.quick-action:hover { border-color: var(--accent); color: var(--accent); }

.quick-action .qa-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
}

.quick-action .qa-icon.income { background: rgba(16,185,129,0.15); color: var(--income); }
.quick-action .qa-icon.expense { background: rgba(239,68,68,0.15); color: var(--expense); }
.quick-action .qa-icon.transfer { background: rgba(139,92,246,0.15); color: var(--transfer); }

/* Chart */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.chart-card h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
    padding: 0.4375rem 0.875rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

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

/* Theme toggle */
.theme-toggle {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    transition: all 0.2s;
}

.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* Color picker */
.color-options {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.color-opt {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s;
}

.color-opt.active { border-color: var(--accent); }

/* Toast */
.toast {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 200;
    animation: fadeIn 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* Checkbox */
.checkbox-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.checkbox-wrap input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    accent-color: var(--accent);
}

/* iOS Add to Home banner */
.ios-banner {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.ios-banner .dismiss-banner {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.125rem;
    flex-shrink: 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.empty-state p { font-size: 0.875rem; }

/* Utility */
.hidden { display: none !important; }
.text-income { color: var(--income); }
.text-expense { color: var(--expense); }
.text-transfer { color: var(--transfer); }
.mt-1 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

@media (min-width: 480px) {
    .modal-content {
        border-radius: 1.5rem;
        margin-bottom: 2rem;
    }
    .modal-overlay {
        align-items: center;
    }
}
