/* --- 1. VARIABLES & THEME --- */
:root {
    /* Light Theme */
    --primary: #6366f1; /* Indigo */
    --primary-dark: #4338ca;
    --secondary: #a855f7; /* Purple */
    --success: #10b981;
    --danger: #f43f5e;
    
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius: 24px;
    --nav-height: 80px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    
    --border: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

/* --- 2. RESET & GLOBAL --- */
html {
    font-size: 16px; /* Fix: Mencegah zoom otomatis pada iOS */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Accessibility: Focus Ring untuk Keyboard Navigation */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
    border-radius: 4px;
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    padding-bottom: calc(var(--nav-height) + 40px);
    min-height: 100vh;
    /* Transisi halus saat ganti tema */
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* --- 3. UTILITIES --- */
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 600; }
.w-full { width: 100%; }

/* --- 4. LAYOUT CONTAINER --- */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 24px 20px;
    position: relative;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* --- 5. COMPONENTS --- */

/* Header */
header { margin-bottom: 24px; }
header h1 { font-size: 1.5rem; letter-spacing: -0.5px; margin-bottom: 4px; }
header p { color: var(--text-muted); font-size: 0.9rem; }

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    transition: transform 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

/* Balance Card */
.balance-card {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.4);
    border: none; /* Balance card doesn't need border */
}
.balance-card::before {
    content: ''; position: absolute; top: -60px; right: -60px;
    width: 180px; height: 180px; background: rgba(255,255,255,0.1); border-radius: 50%;
    backdrop-filter: blur(10px);
}
.balance-label { font-size: 0.9rem; opacity: 0.9; font-weight: 500; }
.balance-amount { font-size: 2.2rem; font-weight: 700; margin: 10px 0 20px 0; letter-spacing: -1px; }

.goal-track {
    background: rgba(255,255,255,0.2); border-radius: 12px; height: 8px; overflow: hidden; margin-top: 8px;
}
.goal-fill { height: 100%; background: #ffffff; width: 0%; transition: width 1s cubic-bezier(0.4, 0, 0.2, 1); }
.goal-text { display: flex; justify-content: space-between; font-size: 0.8rem; margin-top: 8px; opacity: 0.9; }

/* Forms & Inputs */
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }

input, select {
    width: 100%; padding: 16px; background: var(--bg-input);
    border: 2px solid transparent; border-radius: 16px;
    font-size: 1rem; color: var(--text-main); font-weight: 500;
    transition: all 0.2s; appearance: none;
}

/* Custom Dropdown Arrow for Select */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2em;
    padding-right: 3rem; /* Extra padding for the arrow */
}

/* Adjust arrow color for dark mode */
[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

input:focus, select:focus {
    background: var(--bg-card); border-color: var(--primary);
    outline: none; box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

/* Custom Toggle */
.type-switch {
    display: flex; background: var(--bg-input); padding: 6px;
    border-radius: 20px; margin-bottom: 24px;
}
.switch-opt {
    flex: 1; text-align: center; padding: 12px; border-radius: 16px;
    font-weight: 600; font-size: 0.9rem; cursor: pointer;
    color: var(--text-muted); transition: all 0.3s ease;
    user-select: none; /* Mencegah teks terblok saat diklik */
}
.switch-opt.active {
    background: var(--bg-card); color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.switch-opt.active[data-type="income"] { color: var(--success); }
.switch-opt.active[data-type="expense"] { color: var(--danger); }

.btn-main {
    width: 100%; background: var(--primary); color: white;
    border: none; padding: 18px; border-radius: 16px;
    font-size: 1.05rem; font-weight: 600; cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    transition: transform 0.1s, opacity 0.2s, background-color 0.2s;
}
.btn-main:active { transform: scale(0.98); opacity: 0.9; }
.btn-main:focus { background: var(--primary-dark); }

/* Transaction List */
.trans-group { margin-bottom: 24px; }
.group-header { 
    font-size: 0.8rem; color: var(--text-muted); font-weight: 600; 
    margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.5px; padding-left: 4px;
}

.trans-item {
    display: flex; align-items: center; padding: 16px;
    background: var(--bg-card); margin-bottom: 12px;
    border-radius: 20px; box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.3s ease;
    position: relative;
}

.trans-item:active { transform: scale(0.99); }

.trans-item.income { border-left: 5px solid var(--success); }
.trans-item.expense { border-left: 5px solid var(--danger); }

.trans-icon {
    width: 48px; height: 48px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; margin-right: 16px; flex-shrink: 0;
}
.bg-inc { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.bg-exp { background: rgba(244, 63, 94, 0.1); color: var(--danger); }

.trans-details { flex: 1; min-width: 0; } 
.trans-title { 
    font-size: 1rem; font-weight: 600; color: var(--text-main); 
    margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}
.trans-meta { font-size: 0.75rem; color: var(--text-muted); }
.trans-amount { font-weight: 700; font-size: 1rem; margin-right: 8px; }

/* Delete Button */
.btn-delete {
    background: transparent; border: none; padding: 10px;
    color: var(--text-muted); cursor: pointer; border-radius: 12px;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
    margin-left: 4px; /* Sedikit jarak dari nominal */
}
.btn-delete:active { background: rgba(244, 63, 94, 0.1); color: var(--danger); }
.btn-delete svg { width: 20px; height: 20px; stroke-width: 2; }

/* Filter Chips */
.filter-wrapper {
    display: flex; gap: 10px; overflow-x: auto; 
    padding-bottom: 10px; margin-bottom: 10px; 
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.filter-wrapper::-webkit-scrollbar { display: none; }

.chip {
    padding: 8px 20px; background: var(--bg-card); border-radius: 30px;
    font-size: 0.85rem; font-weight: 500; white-space: nowrap;
    color: var(--text-muted); border: 1px solid var(--border);
    cursor: pointer; transition: all 0.2s; flex-shrink: 0;
    user-select: none;
}
.chip.active { background: var(--text-main); color: var(--bg-body); border-color: var(--text-main); }

/* Chart */
.chart-container {
    position: relative; height: 200px; width: 200px; margin: 0 auto;
}
.chart-center-text {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; pointer-events: none;
}

/* --- 6. NAVIGATION --- */
.bottom-nav {
    position: fixed; bottom: 20px; left: 20px; right: 20px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    height: var(--nav-height); border-radius: 35px;
    display: flex; justify-content: space-around; align-items: center;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    border: 1px solid rgba(255,255,255,0.3);
    transition: background 0.3s ease, border-color 0.3s ease;
}

[data-theme="dark"] .bottom-nav {
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(255,255,255,0.05);
}

.nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); text-decoration: none; font-size: 0.7rem;
    padding: 10px; width: 60px; transition: all 0.2s; cursor: pointer;
    user-select: none;
    border-radius: 12px; /* Area sentuh lebih jelas */
}
.nav-item svg {
    width: 24px; height: 24px; margin-bottom: 4px;
    stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
    transition: stroke 0.2s;
}
.nav-item.active { color: var(--primary); transform: translateY(-4px); }

/* Floating Add Button */
.nav-add {
    width: 56px; height: 56px; background: var(--primary); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: white;
    margin-top: -35px; box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
    border: 4px solid var(--bg-body);
    transition: transform 0.2s, background-color 0.2s;
}
.nav-add:active { transform: scale(0.9); }
.nav-add svg { stroke-width: 2.5; width: 28px; height: 28px; margin: 0; }

/* Settings Items */
.setting-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 0; border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.toggle-switch {
    position: relative; width: 50px; height: 28px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border); transition: .4s; border-radius: 34px;
}
.slider: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.2);
}
input:checked + .slider { background-color: var(--primary); }
input:focus + .slider { box-shadow: 0 0 0 2px var(--bg-body), 0 0 0 4px var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }

/* Toast Notification */
.toast {
    position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card); color: var(--text-main);
    padding: 14px 24px; border-radius: 50px; font-size: 0.9rem; font-weight: 500;
    box-shadow: var(--shadow-lg); z-index: 2000;
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--border);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.3s ease;
    width: max-content; max-width: 90%;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-icon { color: var(--success); }
