/* Global Reset */
* {
    /* Set margin to 0 for all elements */
    margin: 0;
    /* Set padding to 0 for all elements */
    padding: 0;
    /* Ensure padding/border don't increase element width */
    box-sizing: border-box;
}

/* Page body styling */
body {
    /* Default text color (dark gray) */
    color: #555;
    /* Primary font family */
    font-family: Open Sans;
    /* Base font size */
    font-size: 16px;
    /* Allow absolute positioning of children relative to body */
    position: relative;
    /* Minimum height fills the viewport */
    min-height: 100vh;
    /* Use flexbox column to push footer to the bottom */
    display: flex;
    flex-direction: column;
    /* Normal font weight */
    font-weight: 400;
}

/* Animation for sliding up and fading in */
@keyframes fadeInUp {
    /* Initial state */
    from {
        /* Fully transparent */
        opacity: 0;
        /* Positioned 40px lower */
        transform: translateY(40px);
    }
    /* Final state */
    to {
        /* Fully visible */
        opacity: 1;
        /* Original position */
        transform: translateY(0);
    }
}

/* Special animation for centered elements (budget info) */
@keyframes fadeInUpCentered {
    /* Initial state */
    from {
        /* Fully transparent */
        opacity: 0;
        /* Centered horizontally and 40px lower from vertical center */
        transform: translate(-50%, calc(-50% + 40px));
    }
    /* Final state */
    to {
        /* Fully visible */
        opacity: 1;
        /* Centered perfectly both ways */
        transform: translate(-50%, -50%);
    }
}

/* Bootstrap helper override for specific red color */
.red { color: #FF5049 !important; }
/* Applied border style for focused red inputs */
.redFocus:focus { border: 1px solid #FF5049 !important; }

/* ---- HEADER ---- */
.header {
    /* Header takes 40% of screen height */
    height: 40vh;
    /* Relative positioning for its absolute children */
    position: relative;
    /* Full width container */
    width: 100%;
    /* Top padding for vertical spacing */
    padding-top: 150px;
    /* Bottom padding for vertical spacing */
    padding-bottom: 100px;
    /* Stacked background: texture png over a 紫/红 gradient loop */
    background: url(background.png), linear-gradient(to left, #7b4397, #dc2430, #7b4397);
    /* Image size is automatic, gradient size is 2x for flow */
    background-size: auto, 200% 200%;
    /* 15s smooth repeating gradient slide animation */
    animation: gradientMove 15s ease infinite;
}

/* Logic for moving the background gradient */
@keyframes gradientMove {
    /* Start position */
    0% { background-position: left top, 0% 50%; }
    /* Middle position (slide all the way) */
    50% { background-position: left top, 100% 50%; }
    /* Return to start */
    100% { background-position: left top, 0% 50%; }
}

/* Container for main budget data */
.budget {
    /* Responsive width: fluid on small, capped on larger screens */
    width: 90%;
    max-width: 350px;
    /* Entrance animation for header text */
    animation: fadeInUpCentered 0.6s ease-out both;
}

/* Formatting for budget title text */
.budget_title { font-size: 20px; }

/* Formatting for the main budget number */
.budget_value {
    /* Large font size for visibility */
    font-size: 46px;
    /* Subtle space between numbers */
    letter-spacing: 2px;
}

/* Shared padding for income and expense summary rows */
.budget_income,
.budget_expense {
    /* Inner spacing */
    padding: 12px;
}

/* Background color for income box */
.budget_income { background-color: #28B9B5; }
/* Background color for expense box */
.budget_expense { background-color: #FF5049; }

/* Shared text size for summary labels */
.budget_income--text,
.budget_expense--text {
    /* Small label size */
    font-size: 13px;
    /* Top offset for alignment */
    margin-top: 2px;
}

/* Shared styling for summary numeric values */
.budget_income--value,
.budget_expense--value {
    /* Slight spacing for digits */
    letter-spacing: 1px;
}

/* Shared sizing for percentages in summary */
.budget_income--percentage,
.budget_expense--percentage {
    /* Fixed width for alignment */
    width: 34px;
    /* Smaller font for data density */
    font-size: 11px;
    /* Vertical padding */
    padding: 3px 0;
}

/* Translucent background for expense percentage indicators */
.budget_expense--percentage {
    /* Faded white color */
    background-color: rgba(255, 255, 255, 0.2);
}


/* ---- ADD FORM ---- */
.add {
    /* Inner vertical padding for the form */
    padding: 14px;
    /* Light gray background color */
    background-color: #f7f7f7;
    /* Entrance animation with 0.2s delay for stagger effect */
    animation: fadeInUp 0.6s ease-out 0.2s both;
}

/* Container limits width and centers the form content */
.add_container { max-width: 700px; }

/* Styling for the record type (+/-) dropdown */
.add_type {
    /* Fixed width */
    width: 55px;
    /* Light border color */
    border: 1px solid #e7e7e7;
    /* Matches input height */
    height: 44px;
    /* Larger character size */
    font-size: 18px;
    /* Uses inherited text color */
    color: inherit;
    /* Solid white background */
    background-color: #fff;
    /* Smooth color transition on focus */
    transition: border 0.3s;
    /* Centers text horizontally */
    text-align: center;
    /* Centers the dropdown arrow or select state */
    text-align-last: center;
}

/* Category dropdown in the form, similar look to type but wider */
.add_category {
    /* Enough room for category names */
    width: 130px;
    /* Match input height */
    height: 44px;
    /* Light border color */
    border: 1px solid #e7e7e7;
    /* Soft rounded corners */
    border-radius: 5px;
    /* Readable font size */
    font-size: 14px;
    /* Inherited text color */
    color: inherit;
    /* Solid white background */
    background-color: #fff;
    /* Smooth focus transition */
    transition: border 0.3s;
    /* Inner spacing */
    padding: 0 8px;
}

/* Shared styling for inputs */
.add_description,
.add_value {
    /* Shared border color */
    border: 1px solid #e7e7e7;
    /* Matches white theme */
    background-color: #fff;
    /* Uses theme text color */
    color: inherit;
    /* Uses theme font */
    font-family: inherit;
    /* Readable standard size */
    font-size: 14px;
    /* Inner spacing */
    padding: 12px 15px;
    /* Soft rounded corners */
    border-radius: 5px;
    /* Smooth focus effect */
    transition: border 0.3s;
}

/* Specific widths for balanced form layout */
/* Full width on mobile, constrained on desktop */
.add_description { width: 100%; max-width: 400px; }
.add_value { width: 100%; max-width: 120px; }

/* Main circular add button styling */
.add_btn {
    /* Large icon size */
    font-size: 35px;
    /* No native button background */
    background: none;
    /* No native button border */
    border: none;
    /* Primary brand color (teal) */
    color: #28B9B5;
    /* Show hand icon on hover */
    cursor: pointer;
    /* Flex box to center content exactly */
    display: inline-flex;
    /* Horizontal flex centering */
    justify-content: center;
    /* Vertical flex centering */
    align-items: center;
    /* Vertically aligns button with texts and selects */
    vertical-align: middle;
    /* Fixed square size for perfect circle */
    width: 40px;
    /* Fixed square size for perfect circle */
    height: 40px;
    /* Reset extra browser padding */
    padding: 0;
    /* Tight line spacing */
    line-height: 1.1;
    /* Perfect circular shape */
    border-radius: 50%;
    /* Animation for hover transition */
    transition: color 0.3s, background-color 0.3s;
}

/* Hover state for the add button */
.add_btn:hover {
    /* Background becomes brand teal */
    background-color: #28B9B5;
    /* Icon becomes white */
    color: #fff;
}

/* Visual feedback when button is clicked */
.add_btn:active { transform: translateY(2px); }

/* Focus indicator color for all form controls */
.add_type:focus,
.add_description:focus,
.add_value:focus,
.add_category:focus {
    /* Remove default browser glow */
    outline: none;
    /* Match focus border with theme */
    border: 1px solid #28B9B5;
}

/* Remove default focus outline from the add button */
.add_btn:focus { outline: none; }

/* Hidden by default, handles validation warnings */
#error-msg {
    /* Starts hidden, jquery handles visibility */
    display: none;
    /* Small warning text size */
    font-size: 14px;
}

/* ---- LISTS CONTAINER ---- */
.container {
    /* Vertical spacing from form */
    margin-top: 60px;
    /* Vertical spacing from bottom */
    margin-bottom: 60px;
    /* Bootstrap's container handles centering and max-width responsively */
    animation: fadeInUp 0.6s ease-out 0.4s both;
    /* Let the lists section grow to fill remaining space */
    flex: 1;
}

/* Individual list column sizing */
/* Width, spacing and stacking fully handled by Bootstrap grid (col-12 col-md-6 g-4) */

/* Heading sizes for column titles */
h2 { font-size: 18px; }

/* Branded heading colors */
.income_title { color: #28B9B5; }
.expense_title { color: #FF5049; }


/* ---- LIST ELEMENTS ---- */
.element {
    /* Vertical spacing for rows */
    padding: 13px;
}

/* Decorative top border for the first item in lists */
.element:first-child { border-top: 1px solid #e7e7e7; }
/* Zebra striping for even-numbered records */
.element:nth-child(even) { background-color: #f7f7f7; }

/* Transition for the slide-out effect on hover */
.element_value { transition: transform 0.3s; }

/* Small date label next to the description */
.element_date {
    /* Smaller, subdued text */
    font-size: 11px;
    /* Lighter gray to not compete with the description */
    color: #999;
    /* Small left margin to separate from the name */
    margin-left: 6px;
    /* Italic to visually distinguish from description */
    font-style: italic;
}

/* Category badge shown next to the description */
.element_category {
    /* Small pill-style badge */
    font-size: 10px;
    /* White text on colored background */
    color: #fff;
    /* Default muted teal background */
    background-color: #28B9B5;
    /* Pill shape */
    border-radius: 10px;
    /* Tight padding */
    padding: 2px 8px;
    /* Small left spacing */
    margin-left: 6px;
    /* Uppercase for emphasis */
    text-transform: uppercase;
    /* Bold text */
    font-weight: 600;
    /* Keep inline with text */
    vertical-align: middle;
}

/* Red badge for expense categories */
.expense .element_category {
    background-color: #FF5049;
}

/* Percentage box inside expense rows */
.element_percentage {
    /* Smooth movement transition */
    transition: transform 0.3s;
    /* Smaller font for data label */
    font-size: 11px;
    /* Pinkish background for contrast */
    background-color: #FFDAD9;
    /* Inner padding */
    padding: 3px;
    /* Standardized width */
    width: 45px;
}

/* Text coloring for income data rows */
.income .element_value,
.income .element_delete--btn {
    /* Income brand teal */
    color: #28B9B5;
}

/* Text coloring for expense data rows */
.expense .element_value,
.expense .element_percentage,
.expense .element_delete--btn {
    /* Expense brand red */
    color: #FF5049;
}

/* Actions container: holds edit + delete buttons, hidden until row hover */
.element_actions {
    /* Hidden by default */
    display: none;
    /* Align both buttons side by side */
    align-items: center;
    /* Small gap between buttons */
    gap: 2px;
}

/* Delete button styling for records */
.element_delete--btn {
    /* Icon size */
    font-size: 22px;
    /* Transparent background */
    background: none;
    /* No border */
    border: none;
    /* Pointer cursor */
    cursor: pointer;
    /* Center icon perfectly */
    display: inline-flex;
    /* Align horizontally */
    justify-content: center;
    /* Align vertically */
    align-items: center;
    /* Fixed small width */
    width: 26px;
    /* Fixed small height */
    height: 26px;
    /* Reset padding */
    padding: 0;
    /* Center line height */
    line-height: 1;
    /* Circular shape for color inversion */
    border-radius: 50%;
    /* Smooth hover effect */
    transition: color 0.3s, background-color 0.3s;
}

/* Edit button: same size/shape as delete */
.element_edit--btn {
    font-size: 20px;
    background: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    line-height: 1;
    border-radius: 50%;
    transition: color 0.3s, background-color 0.3s;
}

/* Edit button colors per list type */
.income .element_edit--btn { color: #28B9B5; }
.expense .element_edit--btn { color: #FF5049; }

/* Edit button hover inversion */
.income .element_edit--btn:hover {
    background-color: #28B9B5;
    color: #fff;
}
.expense .element_edit--btn:hover {
    background-color: #FF5049;
    color: #fff;
}

/* Color inversion for income delete button */
.income .element_delete--btn:hover {
    /* Background becomes teal */
    background-color: #28B9B5;
    /* Icon becomes white */
    color: #fff;
}

/* Color inversion for expense delete button */
.expense .element_delete--btn:hover {
    /* Background becomes red */
    background-color: #FF5049;
    /* Icon becomes white */
    color: #fff;
}

/* Reset focus style */
.element_delete--btn:focus,
.element_edit--btn:focus { outline: none; }
/* Clicking feedback animation */
.element_delete--btn:active,
.element_edit--btn:active { transform: translateY(2px); }

/* ---- INLINE EDIT MODE ---- */
/* Wrapper for the two edit inputs */
.element-edit-form {
    /* Align inputs side by side */
    display: flex;
    align-items: center;
    gap: 6px;
    /* Prevent overflowing on small screens */
    flex-wrap: wrap;
}

/* Shared style for inline edit inputs */
.element_edit--desc,
.element_edit--val {
    border: 1px solid #e7e7e7;
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 14px;
    font-family: inherit;
    color: inherit;
    transition: border 0.3s;
}

/* Focus highlight matches brand teal */
.element_edit--desc:focus,
.element_edit--val:focus {
    outline: none;
    border-color: #28B9B5;
}

/* Description input is wider, value input is narrower */
.element_edit--desc { width: 160px; }
.element_edit--val  { width: 80px; }

/* Save button — teal check mark */
.element_save--btn {
    font-size: 22px;
    background: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    color: #28B9B5;
    transition: color 0.3s, background-color 0.3s;
}
.element_save--btn:hover { background-color: #28B9B5; color: #fff; }
.element_save--btn:focus { outline: none; }

/* Cancel button — red close icon */
.element_cancel--btn {
    font-size: 22px;
    background: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    color: #FF5049;
    transition: color 0.3s, background-color 0.3s;
}
.element_cancel--btn:hover { background-color: #FF5049; color: #fff; }
.element_cancel--btn:focus { outline: none; }

/* Show actions container (edit + delete) when hovering over the row */
.element:hover .element_actions { display: flex; }
/* Slide value text left when hovering to make room for two action buttons */
.element:hover .element_value { transform: translateX(-56px); }
/* Slide percentage text left when hovering to make room for two action buttons */
.element:hover .element_percentage { transform: translateX(-56px); }

/* ---- CATEGORY FILTER ---- */
/* Container for the filter dropdown at the top of each list */
.filter-container {
    /* Right-align the dropdown */
    text-align: right;
}

/* Filter dropdown styling */
.filter-select {
    /* Compact size */
    font-size: 12px;
    /* Inner spacing */
    padding: 4px 10px;
    /* Light border */
    border: 1px solid #e7e7e7;
    /* Rounded corners */
    border-radius: 4px;
    /* Theme text color */
    color: #555;
    /* White background */
    background-color: #fff;
    /* Smooth focus transition */
    transition: border 0.3s;
    /* Remove default focus glow */
    outline: none;
}

/* Highlight filter dropdown on focus */
.filter-select:focus {
    border-color: #28B9B5;
}


/* ---- FOOTER ---- */
.app-footer {
    /* Dark gradient footer background */
    background: linear-gradient(to right, #7b4397, #dc2430);
    /* White text for contrast */
    color: #fff;
    /* Border top separator */
    border-top: 1px solid rgba(255,255,255,0.1);
    /* Stays at bottom via body flexbox */
    margin-top: auto;
}

/* Footer brand text styling */
.footer-brand {
    /* Slightly larger, bold */
    font-size: 16px;
    font-weight: 600;
}

/* Footer body text styling */
.footer-text {
    /* Small, semi-transparent */
    font-size: 13px;
    opacity: 0.85;
}


/* ---- RESPONSIVE MEDIA QUERIES ---- */

/* Tablet and smaller (< 768px) */
@media (max-width: 768px) {
    /* Switch header from relative-with-absolute-child to flex centering */
    .header {
        height: auto;
        padding-top: 40px;
        padding-bottom: 40px;
        /* Use flexbox to center content naturally */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Override Bootstrap absolute positioning classes on mobile */
    .budget {
        /* Back to normal document flow */
        position: static !important;
        /* Reset the translate centering trick */
        transform: none !important;
        /* Use standard fade-in instead of the centered variant */
        animation: fadeInUp 0.6s ease-out both;
        /* Full width with breathing room */
        width: 90%;
        max-width: 340px;
    }

    /* Scale down the large budget number */
    .budget_value {
        font-size: 32px;
    }

    /* Prevent form inputs from overflowing on phones */
    .add_description,
    .add_value {
        width: 100%;
        max-width: 100%;
    }
}

/* Mobile (< 576px) */
@media (max-width: 576px) {
    /* Further reduce budget font size */
    .budget_value {
        font-size: 24px;
        letter-spacing: 1px;
    }

    /* Shrink budget title label */
    .budget_title { font-size: 15px; }

    /* Slightly smaller income/expense labels */
    .budget_income--text,
    .budget_expense--text {
        font-size: 11px;
    }

    /* Tighten list element padding */
    .element { padding: 10px 8px; }

    /* Smaller footer text on very small devices */
    .footer-brand,
    .footer-text {
        font-size: 12px;
    }
}
