/* --- GLOBAL RESET --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden; /* Prevents horizontal scrolling */
    background-color: #f4f6f9; /* Or whatever your background color is */
}

:root {
    --bg-color: #f8f9fa;
    --primary: #4a00e0;
    --text-main: #2d3436;
    --income: #00b894;
    --expense: #d63031;
    --card-bg: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: #e9ecef;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    background-color: var(--bg-color);
}

/* --- TOP BAR ALIGNMENT FIX --- */
.profile-bar {
    display: flex;
    align-items: center; /* The magic rule that perfectly aligns them horizontally */
    padding: 15px 20px;
    background-color: #ffffff;
    gap: 10px; /* Provides uniform spacing between all 3 items */
}

/* Force the dropdown and buttons to ignore global margins and match heights */
.profile-bar select, 
.profile-bar button {
    margin: 0; /* Strips the rogue bottom-margin */
    height: 45px; /* Forces them to be the exact same height */
}

.profile-bar select {
    flex: 1; /* Makes the dropdown take up the remaining space */
    padding: 0 15px; 
    border-radius: 8px;
    border: 1px solid #ced4da;
    background-color: white;
}

.icon-btn {
    width: 45px; /* Matches the 45px height to make a perfect square */
    border-radius: 8px;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1.2rem;
    
    /* This perfectly centers the + and 📥 inside their boxes */
    display: flex; 
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.icon-btn:active {
    transform: scale(0.95); /* Nice little tap animation */
}



/* Touch-Friendly Segmented Toggle Button Group */
.type-toggle-group {
    display: flex;
    margin-bottom: 8px; /* Increased from 15px to give space above 'New Entry' */
    background: #e9ecef;
    padding: 4px;
    border-radius: 10px;
}

.toggle-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-weight: bold;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active[data-type="expense"] {
    background-color: var(--expense);
    color: white;
}

.toggle-btn.active[data-type="income"] {
    background-color: var(--income);
    color: white;
}

.submit-btn {
    width: 100%;
    padding: 16px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer !important; /* Forces the hand icon on hover */
    transition: transform 0.1s ease, opacity 0.2s ease;
}

/* Adds a satisfying 'press' effect when clicked or tapped */
.submit-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
}

input, select {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 10px;
    border: 1px solid #ddd;
    font-size: 1rem;
    background-color: white; /* Ensures dropdowns look clean */
}

/* --- NEW: Action Buttons for Edit/Delete --- */
.transaction-item {
    align-items: center; /* Ensures everything lines up vertically */
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.action-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
    border-radius: 5px;
    margin: 0; /* overrides default button margin */
    width: auto;
    cursor: pointer;
}

.edit-btn {
    background-color: #f1c40f; /* Yellow */
    color: #2c3e50;
}

.delete-btn {
    background-color: #e74c3c; /* Red */
    color: white;
}



/* Ensure the inputs take up exactly 50% of the row each */
.form-row > input, 
.form-row > .category-wrapper {
    flex: 1;
    margin-bottom: 0; /* Overrides the old bottom margin */
    min-width: 0; /* Prevents inputs from stretching past the screen on small phones */
}

/* Styling the category dropdown and button to sit nicely together */
.category-wrapper {
    display: flex;
    gap: 5px;
}

.category-wrapper select {
    flex: 1;
    margin-bottom: 0;
    min-width: 0;
}

#add-category-btn {
    width: 45px; /* Keep the + button small and square */
    padding: 0;
    background-color: #ffffff;
    margin-bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================
   FORM LAYOUT (Custom Widths)
   ========================================== */
.form-row {
    display: flex;
    gap: 10px; /* Small gap between fields */
    margin-bottom: 10px;
    width: 100%;
}

/* Remove the old bottom margins so they align perfectly in a row */
.form-row input, 
.form-row select, 
.form-row button {
    margin-bottom: 0; 
}

/* --- LINE 1 --- 
   Subtracting ~6.66px to account for the two 10px gaps in a 3-item row */
.line1-date, .line1-amount { 
    width: calc(50% - 5px); /* Perfectly splits the row with a 10px gap */}

.line1-btn { 
    width: calc(20% - 6.66px); 
    
    /* Adds the rounded corners (10px matches your input fields) */
    border-radius: 10px; 
    
    /* A very subtle, light grey/purple background so you can see the shape */
    background-color: rgba(74, 0, 224, 0.1); 
    border: none; 
    
    color: var(--primary); 
    font-size: 2rem; 
    font-weight: bold;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    padding: 0;
    cursor: pointer;
    transition: all 0.2s ease; 
}

.line1-btn:active {
    /* Changes to solid purple when tapped */
    background-color: var(--primary); 
    color: white;
    transform: scale(0.95); 
}

.line1-btn:hover {
    /* Changes to solid purple when tapped */
    background-color: var(--primary); 
    color: rgb(133, 133, 133);
    transform: scale(0.95); 
}

/* --- LINE 2 --- 
   Subtracting 5px to account for the single 10px gap in a 2-item row */
.line2-desc { 
    width: calc(75% - 5px); 
}
.line2-cat { 
    width: calc(25% - 5px); 
    padding: 10px 5px; /* Slight padding tweak to fit long category names in 20% width */
}

/* --- LINE 3 --- */
.line3-container {
    display: flex;
    justify-content: center;
    width: 100%;
}
.line3-submit { 
    width: 95%; 
}

/* ==========================================
   GLOBAL SPACING & PADDING FIX
   ========================================== */

/* 1. Give the whole app breathing room on desktop screens */
body {
    padding: 20px; 
}

/* 2. Make the app container look like a sleek phone screen */
.app-container {
    border-radius: 20px; /* Rounds the outer corners */
    overflow: hidden; /* Stops the top white bar from spilling out of the rounded corners */
    box-shadow: 0 10px 30px rgba(0,0,0,0.1); /* Adds a soft floating shadow */
}

/* 3. Force consistent side padding for the content sections */
.add-transaction, 
.transaction-history {
    padding: 10px 20px; /* 25px top/bottom, 20px left/right */
}

/* ==========================================
   VIEW NAVIGATION & BOTTOM BAR
   ========================================== */

/* The magic classes that handle showing/hiding screens */
.view {
    display: block;
    padding-bottom: 100px; /* Ensures you can scroll past the bottom nav */
    animation: fadeIn 0.3s ease; /* Smooth transition */
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* The Bottom Navigation Dock */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    display: flex;
    justify-content: space-evenly;
    /* Adds extra padding at the bottom for iPhone safe area (the swipe bar) */
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); 
    box-shadow: 0 -2px 15px rgba(0,0,0,0.08);
    z-index: 1000;
}

.nav-btn {
    flex: 1; /* Forces buttons to share width equally */
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    font-size: 0.75rem;
    color: #a4b0be;
    cursor: pointer;
    padding: 5px;
}

.nav-btn.active {
    color: var(--primary);
    font-weight: bold;
}

.nav-btn.active span {
    transform: scale(1.2); /* Icon grows slightly when selected */
}

/* ==========================================
   LOGIN SCREEN
   ========================================== */
.login-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, var(--bg-color), #d1d8e0);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 20px;
}

.login-box {
    background: white;
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h2 { color: var(--text-main); margin-bottom: 10px; }
.login-box p { color: #888; margin-bottom: 30px; font-size: 0.9rem; }

.sso-btn {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
}


.google-btn { background: #4285F4; color: white; }
.biometric-btn { background: #2d3436; color: white; }
.sso-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.2); }

/* --- EMAIL/PASSWORD AUTHENTICATION STYLES --- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-input {
    width: 100%;
    padding: 14px 15px;
    border-radius: 10px;
    border: 1px solid #ddd;
    font-size: 1rem;
    background-color: #f9f9f9;
    transition: border-color 0.2s ease;
}

.auth-input:focus {
    border-color: var(--primary);
    outline: none;
    background-color: white;
}

.auth-submit {
    margin-top: 5px;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 25px 0;
    color: #a4b0be;
    font-size: 0.85rem;
    font-weight: bold;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #dfe4ea;
}

.divider span {
    padding: 0 15px;
}

.auth-toggle {
    margin-top: 15px;
    font-size: 0.9rem;
    color: #57606f;
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: bold;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
    margin-left: 5px;
}

.text-btn:hover {
    text-decoration: underline;
}


/* ==========================================
   NEW METRICS GRID DASHBOARD
   ========================================== */
.dashboard-metrics {
    padding: 20px;
    background-color: #ded6d6; /* Matches app background now */
}

/* --- UPDATED: 2x2 Metric Tiles Grid --- */
.metrics-grid {
    display: grid;
    /* This creates exactly 2 columns, forcing the 4 tiles into a 2x2 square */
    grid-template-columns: repeat(2, 1fr); 
    gap: 12px; 
    margin-bottom: 0;
    width: 100%;
}

.metric-tile {
    background: white;
    padding: 3px 5px; /* Increased padding since we have more room */
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    text-align: center;
    min-width: 0; 
}

.metric-tile span {
    font-size: 0.75rem; /* Slightly larger text for readability */
    color: #888;
    display: block;
    margin-bottom: 4px;
}


.metric-tile h3 {
    font-size: 1.1rem; /* Bumping up the font size for the amounts */
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
}

/* --- EYE ICON FOR PRIVACY --- */
.eye-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: inherit; /* Will inherit white on the main tile, gray on the income tile */
    opacity: 0.6;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.eye-btn:hover {
    opacity: 1;
}

/* Updated Balance Card to fit nicely in the 2x2 layout */
.tile-main {
    background: linear-gradient(135deg, var(--primary), #8e2de2);
    color: white;
    /* Removed the grid-column: 1 / -1; rule so it only takes up 1 box */
}

.tile-main h2 { 
    font-size: 1.2rem; /* Slightly larger than the others to stand out */
    margin: 0; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tile-main span {
    color: rgba(255, 255, 255, 0.85); /* Make the "Balance" label readable on purple */
}
.tile-income h3 { color: var(--income); font-size: 1.4rem; }
.tile-expense h3 { color: var(--expense); font-size: 1.4rem; }
.tile-count h3 { color: #636e72; font-size: 1.4rem; }

/* --- MODERN HISTORY CARDS --- */
#transaction-list {
    list-style: none;
    padding: 20px;
}

.transaction-item {
    background: white;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); /* Soft, modern shadow */
    transition: transform 0.2s ease;
}

.transaction-item:active {
    transform: scale(0.98);
}

/* Color coding amounts */
.amount-expense { color: var(--expense); font-weight: bold; }
.amount-income { color: var(--income); font-weight: bold; }

/* Action Buttons Styling */
.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.action-btn {
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    cursor: pointer;
}

/* --- MODERN ACTION BUTTONS --- */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    background: #f1f2f6; /* Soft neutral background */
    color: #57606f;      /* Soft grey icon color */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover effects */
.btn-icon:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Contextual colors on hover */
.btn-icon.danger:hover { background: #ffeaa7; color: #d63031; }
.btn-icon.success:hover { background: #b8e994; color: #00b894; }

/* Click effect */
.btn-icon:active {
    transform: scale(0.9);
}
/* --- CATEGORY MANAGEMENT --- */
.category-item {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #eee;
}

.category-badge {
    background: #a4b0be;
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
}

/* --- ANALYTICS DASHBOARD --- */
.report-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}

.report-card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: var(--text-main);
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.table-responsive {
    overflow-x: auto; /* Allows table to scroll horizontally if needed on iPhone */
    margin-bottom: 10px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    background: #f8f9fa;
    padding: 8px;
    color: #57606f;
    font-weight: bold;
}

.data-table td {
    padding: 8px;
    border-bottom: 1px solid #eee;
    color: #2d3436;
}

.chart-box {
    position: relative;
    height: 200px;
    width: 100%;
}

/* --- PRIVACY BLUR EFFECT --- */
.blurred-text {
    filter: blur(6px);
    opacity: 0.4;
    user-select: none; /* Prevents highlighting/copying the hidden text */
    pointer-events: none; /* Stops interaction with the hidden text */
}

/* Ensure the text animates smoothly when the class is added/removed */
.metric-tile h2, .metric-tile h3 {
    transition: filter 0.3s ease, opacity 0.3s ease;
}

/* --- MODERN CATEGORY TILES --- */
.category-tiles-container {
    display: flex;
    flex-wrap: wrap; /* Allows tiles to wrap to the next line naturally */
    gap: 8px;
}

.category-tile {
    background: #f1f2f6;
    color: #57606f;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    user-select: none; /* Prevents text highlighting when tapping quickly */
}

/* Push down animation when tapped */
.category-tile:active {
    transform: scale(0.95);
}

/* Styling for the actively selected tile */
.category-tile.selected {
    background:#8198af;
    color: white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* --- MODERN SETTINGS UI --- */
.settings-group {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
    margin-bottom: 25px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.setting-row:active {
    background: #f8f9fa;
}

.setting-divider {
    height: 1px;
    background: #f1f2f6;
    margin: 0 16px;
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 15px;
}

.setting-title {
    font-size: 1rem;
    color: #2d3436;
    font-weight: 500;
}

.setting-desc {
    font-size: 0.75rem;
    color: #888;
    line-height: 1.3;
}

/* Custom Animated Radio Button */
.custom-radio {
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border: 2px solid #ddd;
    border-radius: 50%;
    outline: none;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.custom-radio:checked {
    border-color: var(--primary);
}

.custom-radio:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
}   