/* Modal Styles */
.modal {
    display: none; /* Controlled by JS */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow: auto;
    /* display: flex; /* If using flex for centering */
    /* align-items: center; */ /* If using flex for centering */
    /* justify-content: center; */ /* If using flex for centering */
}

/* .modal.show { */ /* This class is not used by the JS */
    /* display: flex; */
/* } */

.modal-content {
    background-color: white;
    margin: 8% auto; /* Slightly adjusted margin */
    padding: 30px 35px; /* Increased padding */
    border-radius: var(--border-radius);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15); /* Softened shadow */
    width: 90%;
    max-width: 700px; /* Increased max-width */
    position: relative;
    animation: modalOpen 0.3s ease-out;
}

@keyframes modalOpen {
    from {
        opacity: 0;
        transform: translate(0, -20px) scale(0.95); /* Added slide down effect */
    }
    to {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px; /* Increased margin */
    border-bottom: 1px solid var(--border-color); /* Used variable */
    padding-bottom: 15px; /* Increased padding */
}

.modal-header h3 {
    margin: 0;
    color: var(--dark-color);
    font-size: 1.4rem; /* Slightly larger header */
}

.close-modal { /* Styles for the 'x' icon */
    font-size: 1.8rem; /* Slightly larger close icon */
    font-weight: bold;
    cursor: pointer;
    color: var(--gray-color);
    transition: var(--transition);
    line-height: 1;
    background: none; /* Ensure no background */
    border: none; /* Ensure no border */
    padding: 0; /* Ensure no padding */
}

.close-modal:hover {
    color: var(--accent-color);
    transform: scale(1.1); /* Add subtle scale on hover */
}

.modal-body {
    padding-top: 10px; /* Add some space below header border */
}

/* General Form Group Styling */
.form-group {
    margin-bottom: 1.5rem; /* Increase default bottom margin */
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem; /* Space between label and input */
    font-weight: 500; /* Slightly bolder labels */
    color: var(--dark-gray-color); /* Slightly lighter than black */
    font-size: 0.9rem;
}

.form-group small.form-text {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--gray-color);
}

/* Removed redundant .error-message style from here, use the one in styles.css */

/* Responsive adjustments for smaller screens */
@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        margin: 5% auto; /* Adjust margin for smaller screens */
        padding: 20px;
    }
    .modal-header h3 {
        font-size: 1.2rem;
    }
    .close-modal { /* Style for 'x' icon on small screens */
        font-size: 1.5rem;
    }
}

/* Styles for Loan Selection Tiles in Strategy Modal */
#extra-repayment-target-loans-list { /* Renamed ID */
    display: flex;
    flex-direction: column;
    gap: 0.5rem; /* Space between tiles */
    max-height: 200px; /* Limit height and allow scrolling */
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    background-color: #f8f9fa; /* Light background for the list area */
}

/* Apply same styles to the container used in the loan modal */
.tile-select-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem; /* Space between tiles */
    max-height: 200px; /* Limit height and allow scrolling */
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    background-color: #f8f9fa; /* Light background for the list area */
}

.loan-selection-tile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: white;
    cursor: pointer;
    /* transition: var(--transition); */ /* Replaced with specific transitions */
    transition: opacity var(--transition-speed), background-color var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed);
    opacity: 0.7; /* Default greyed-out look */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    border-left: 3px solid transparent; /* Add space for selected border */
}

.loan-selection-tile .tile-icon {
    width: 24px; /* Smaller icon */
    height: 24px;
    flex-shrink: 0;
    opacity: 0.6; /* Dim icon by default */
    transition: opacity var(--transition-speed); /* Smooth transition */
    line-height: 24px; /* Match height for vertical centering */
}

.loan-selection-tile .loan-selection-name {
    flex-grow: 1;
    font-size: 0.9rem;
    color: var(--dark-color);
    line-height: 1.4; /* Explicit line-height for text */
}

.loan-selection-tile:hover {
    border-color: var(--primary-color-light);
    opacity: 0.9;
}

.loan-selection-tile.selected {
    border-color: var(--primary-color); /* Keep right border */
    border-left: 3px solid var(--primary-color); /* Add accent left border */
    background-color: var(--primary-color-lightest); /* Light blue background */
    opacity: 1.0; /* Fully opaque when selected */
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.1);
    padding-left: calc(0.8rem - 3px); /* Adjust padding to account for border */
}

.loan-selection-tile.selected .tile-icon {
    opacity: 1.0; /* Make icon fully visible when selected */
}

.loan-selection-tile.selected .loan-selection-name {
    font-weight: 500; /* Reduced font weight for selected state */
}

/* --- NEW STYLES FOR LOAN MODAL LAYOUT --- */

/* Style for rows containing multiple form groups */
.form-row {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on very small screens if needed */
    gap: 1.5rem; /* Increased space between form groups in the row */
    margin-bottom: 1.5rem; /* Space below the row */
}

/* Make form groups within a row take up equal space */
.form-row > .form-group {
    flex: 1; /* Each group takes equal width */
    min-width: 200px; /* Prevent groups from becoming too narrow */
    margin-bottom: 0; /* Remove default bottom margin as row handles spacing */
}

/* Style for the group containing Years/Months inputs */
.term-input-group {
    display: flex;
    gap: 0.75rem; /* Space between Years and Months inputs */
    align-items: center; /* Align items vertically */
    position: relative; /* Needed for absolute positioning of icon */
}

/* Style for disabled input groups (like Loan Term when IO is selected) */
.form-group .disabled-group {
    opacity: 0.6;
    pointer-events: none; /* Prevent interaction with elements inside */
    background-color: #f8f9fa; /* Light grey background */
    border-radius: 4px; /* Match input rounding */
    padding: 5px 10px; /* Add some padding */
    margin-top: 5px; /* Space from label */
}

/* Reduce width of term inputs */
.term-input-group input[type="number"] {
    flex: 0 1 80px; /* Don't grow, allow shrinking, base width 80px */
    min-width: 60px; /* Prevent excessive shrinking */
}

/* Style for the new Years/Months labels */
.term-label {
    font-size: 0.85rem;
    color: var(--gray-color);
    margin-left: -0.25rem; /* Slightly reduce gap before label */
    flex-shrink: 0; /* Prevent label from shrinking */
}

/* Remove the old ::before/::after pseudo-element styles */
.term-input-group::before,
.term-input-group::after {
    display: none; /* Hide old pseudo-elements */
}

/* Conditional display for Offset Balance */
#offset-balance-group {
    /* Keep display: none; managed by JS */
    /* Add smooth transition */
    max-height: 0;
    overflow: hidden;
    margin-bottom: 0; /* Remove margin when hidden */
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out, margin-bottom 0.3s ease-out;
}

#offset-balance-group.visible {
    max-height: 100px; /* Adjust as needed for content height */
    opacity: 1;
    margin-bottom: 1.5rem; /* Restore margin when visible */
}

/* Snowball Target Styling */
#snowball-targets-list {
    margin-top: 0.5rem; /* Space between helper text and list */
}

#snowball-target-placeholder,
.no-loans-message { /* Style for placeholder text */
    color: var(--gray-color);
    font-style: italic;
    font-size: 0.9rem;
    padding: 0.5rem;
    text-align: center;
}

/* Divider Styling */
hr.form-section-divider {
    border: 0;
    height: 1px;
    background-color: var(--border-color, #e0e0e0); /* Use variable or default */
    margin: 2rem 0; /* Adjust vertical spacing */
}

/* Responsive adjustments */
@media (max-width: 767px) { /* Adjust breakpoint as needed */
    .form-row {
        flex-direction: column; /* Stack items vertically */
        gap: 0; /* Remove gap when stacked */
    }

    .form-row > .form-group {
        margin-bottom: 1rem; /* Add back bottom margin when stacked */
        min-width: 100%; /* Allow groups to take full width */
    }

    /* Ensure last form group in a stacked row doesn't have extra margin */
    .form-row > .form-group:last-child {
        margin-bottom: 0;
    }
}

/* --- NEW: Save/Load Modal Specific Styles --- */

.modal-footer {
    display: flex;
    justify-content: flex-end; /* Align buttons to the right by default */
    align-items: center; /* Vertically align items */
    gap: 0.75rem; /* Space between buttons */
    margin-top: 2rem; /* Space above the footer */
    padding-top: 1rem; /* Space below the body content */
    border-top: 1px solid var(--border-color); /* Separator line */
}

/* Override .close-modal styles specifically for buttons in the footer */
.modal-footer .close-modal {
    /* Inherit button styles or define secondary button style */
    font-size: var(--button-font-size, 0.9rem); /* Use button font size */
    font-weight: var(--button-font-weight, 500);
    color: var(--secondary-color, #6c757d); /* Secondary text color */
    background-color: var(--secondary-bg-color, #f8f9fa); /* Secondary background */
    border: 1px solid var(--secondary-border-color, #ced4da); /* Secondary border */
    padding: var(--button-padding, 0.5rem 1rem); /* Use standard button padding */
    border-radius: var(--border-radius);
    line-height: normal; /* Reset line-height */
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease; /* Standard button transition */
}

.modal-footer .close-modal:hover {
    color: var(--secondary-hover-color, #495057);
    background-color: var(--secondary-hover-bg-color, #e2e6ea);
    border-color: var(--secondary-hover-border-color, #dae0e5);
    transform: none; /* Remove the scale transform */
}

/* --- NEW: IO Term Quick Select Button Styles --- */
.io-term-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.io-term-buttons .btn {
    padding: 0.5rem 0.8rem; /* Slightly larger padding */
    font-size: 0.9rem; /* Slightly larger font */
    flex: 1; /* Make buttons grow to fill space */
    min-width: 80px; /* Minimum width */
    border: 1px solid var(--border-color);
    background-color: #f8f9fa; /* Light background for unselected state */
    color: var(--dark-color);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

/* Hover state for buttons */
.io-term-buttons .btn:hover {
    background-color: #e9ecef; /* Slightly darker on hover */
    border-color: var(--gray-color);
}

/* Style for the 'active' (selected) button */
.io-term-buttons .btn.active {
    background-color: var(--accent-color); /* Change to accent color for more pop */
    color: white;
    border-color: var(--accent-color);
    font-weight: 600;
    transform: translateY(-2px); /* Slight lift effect */
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15); /* More pronounced shadow */
}

/* Add indicator to selected button */
.io-term-buttons .btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: rgba(255, 255, 255, 0.3); /* Subtle underline */
}

/* Style for the custom button icon */
/* Media query for desktop - make buttons even more prominent */
@media (min-width: 768px) {
    .io-term-buttons {
        justify-content: space-between; /* Spread buttons evenly */
    }
    
    .io-term-buttons .btn {
        padding: 0.6rem 1rem; /* Larger padding on desktop */
    }
}

/* Style for the date input */
#interest-only-custom-date {
    width: 150px;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    margin-left: 0.5rem;
}

/* --- END IO Term Styles --- */

/* Specific alignment for Load modal delete button */
#load-modal .modal-footer #load-modal-delete-btn {
    margin-right: auto; /* Push delete button to the left */
    /* Style as a danger button */
    background-color: var(--danger-bg-light, #f8d7da); /* Light red background */
    border-color: var(--danger-border-light, #f5c6cb); /* Light red border */
    color: var(--danger-text-dark, #721c24); /* Dark red text */
}

#load-modal .modal-footer #load-modal-delete-btn:hover {
    background-color: var(--danger-bg-hover, #f1b0b7); /* Slightly darker red background */
    border-color: var(--danger-border-hover, #eea4ac);
    color: var(--danger-text-dark, #721c24);
}

/* Ensure select dropdown takes full width */
#load-filename-select {
    width: 100%;
    padding: 0.6rem; /* Match input padding */
}

/* --- NEW: Global Message Container Styles --- */
/* These apply to both #error-container and #success-container */
.message-container {
    position: fixed;
    top: 20px; /* Position near the top */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 1100; /* Above modals */
    display: none; /* Controlled by JS */
    opacity: 0;
    transition: opacity 0.3s ease-out, top 0.3s ease-out;
    text-align: center;
}

.message-container.show { /* Add this class via JS to show */
    display: block;
    opacity: 1;
    top: 30px; /* Slide down slightly */
}

.message-container h3 { /* Style for error heading */
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
}

.message-container p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Specific styles for error messages */
.error-message {
    background-color: var(--error-bg-color, #f8d7da);
    color: var(--error-text-color, #721c24);
    border: 1px solid var(--error-border-color, #f5c6cb);
}
.error-message h3 {
    color: var(--error-text-color, #721c24);
}

/* Specific styles for success messages */
.success-message {
    background-color: var(--success-bg-color, #d4edda);
    color: var(--success-text-color, #155724);
    border: 1px solid var(--success-border-color, #c3e6cb);
}

/* --- NEW: Auto-population Styles --- */
input.auto-populated,
select.auto-populated { /* Apply to select if needed in future */
    color: var(--gray-color, #6c757d); /* Grey text */
    font-style: italic;
}

/* Style for the warning icon span */
.input-warning-icon {
    display: none; /* Hidden by default */
    color: var(--warning-color, #ffc107); /* Yellow/Orange color */
    margin-left: 0.5rem; /* Space between input and icon */
    font-size: 1rem; /* Adjust size as needed */
    cursor: help; /* Indicate it's informative */
    vertical-align: middle; /* Align with text */
}

/* Position warning icon within term group */
.term-input-group .input-warning-icon {
    /* Position relative to the group */
}

/* Position warning icon within input-with-symbol */
.input-with-symbol .input-warning-icon {
    /* Position relative to the container */
    /* Adjust if needed based on symbol position */
    margin-left: 0.25rem;
}

/* --- NEW: Disabled Input Style --- */
input.disabled-input,
select.disabled-input,
textarea.disabled-input {
    background-color: var(--disabled-bg-color, #e9ecef); /* Light gray background */
    color: var(--disabled-text-color, #6c757d); /* Muted text color */
    cursor: not-allowed; /* Indicate non-interactive state */
    opacity: 0.7; /* Slightly faded appearance */
    border-color: var(--disabled-border-color, #ced4da); /* Match border color */
}
/* --- END Disabled Input Style --- */