/* Tile-based Layout Styles */

/* Property Tile Styles */
.property-tile {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    min-height: 160px;
    position: relative;
    overflow: hidden;
    display: flex; /* Use flex for alignment */
    align-items: stretch; /* Make children fill height */
}

.property-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%; /* Ensure it takes full width */
    min-height: 150px;
    text-align: center;
    color: var(--gray-color);
}

/* Removed unused .empty-icon and .add-icon */

.property-details {
    display: flex;
    align-items: center;
    gap: 1.5rem; /* Increased gap */
    width: 100%; /* Ensure it takes full width */
}

.property-image {
    width: 100px; /* Slightly smaller */
    height: 100px;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent image from shrinking */
}

.property-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.property-info {
    flex: 1;
    display: flex;
    flex-direction: column; /* Stack content */
}

.property-info h3 {
    margin-bottom: 0.4rem;
    font-size: 1.2rem; /* Adjusted size */
    color: var(--dark-color); /* Darker color */
}
.property-info p {
    margin-bottom: 0.8rem; /* Add space below value */
    font-size: 1rem;
    color: var(--gray-color);
}
.property-info p span { /* Style the value specifically */
    font-weight: 600;
    color: var(--dark-color);
}


.btn-edit {
    background: transparent;
    border: 1px solid transparent; /* Add transparent border for layout consistency */
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 5px 10px;
    margin-top: auto; /* Push button to bottom */
    border-radius: 4px;
    transition: var(--transition);
    align-self: flex-start; /* Align button to left */
}
.btn-edit i { /* Space between icon and text */
    margin-right: 4px;
}

.btn-edit:hover {
    background-color: rgba(38, 166, 154, 0.1);
    color: var(--accent-color);
}

/* Loans Container */
#loans-container { /* Target the ID used in HTML */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Apply same grid to strategies container */
#extra-repayments-container { /* Renamed ID */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1rem; /* Slightly less margin before add tile */
}

/* Add Loan Tile */
.add-loan-tile {
    background-color: #f8fafc;
    border-radius: var(--border-radius);
    padding: 1.2rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.add-loan-tile:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.add-loan-tile p {
    margin-top: 0.5rem; /* Space above text */
}

/* Loan Tile */
.loan-tile {
    background-color: #f8fafc;
    border-radius: var(--border-radius);
    padding: 1.2rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-left 0.2s ease;
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-left: 3px solid transparent;
}

.loan-tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    border-left: 3px solid var(--accent-color);
}

.loan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem; /* Increased margin */
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.8rem; /* Increased padding */
}

.loan-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--dark-color);
    font-weight: 500;
}

.loan-actions { /* Container for buttons */
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0; /* Prevent actions shrinking */
}
/* Style action buttons within loan tile */
.loan-actions .btn-edit {
    margin-top: 0; /* Override margin from property tile */
    padding: 4px 8px; /* Smaller padding */
    font-size: 0.8rem;
    color: var(--gray-color); /* Subtle color */
}
.loan-actions .btn-edit:hover {
    color: var(--primary-color); /* Highlight on hover */
    background: rgba(52, 152, 219, 0.1);
}
.loan-actions .remove-loan { /* Specific style for remove icon */
     color: var(--accent-color);
}
.loan-actions .remove-loan:hover {
     color: #c0392b; /* Darker red on hover */
     background: rgba(231, 76, 60, 0.1);
}

.loan-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1rem; /* row-gap column-gap */
    margin-top: auto; /* Push details down if header content varies */
}

.loan-detail {
    display: flex;
    flex-direction: column;
}

.loan-detail-label {
    font-size: 0.75rem;
    color: var(--gray-color);
    margin-bottom: 0.2rem;
    text-transform: uppercase; /* Uppercase label */
}

.loan-detail-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--dark-color);
}

/* Make interest rate value stand out with accent color */
.loan-tile .loan-detail:nth-child(4) .loan-detail-value {
    color: var(--accent-color);
    font-weight: 600;
}

/* Strategy tile inherits .loan-details grid by default now */

/* Icons for Tiles */
.tile-icon {
    width: 32px;
    height: 32px;
    display: flex; /* Added */
    align-items: center; /* Added */
    justify-content: center; /* Added */
    /* margin-bottom: 0.5rem; */ /* Removed margin, handled by container */
}

.house-icon {
    background: url('../assets/icons/house.svg') no-repeat center center;
    background-size: contain;
}

.money-icon {
    background: url('../assets/icons/money.svg') no-repeat center center;
    background-size: contain;
}

.calendar-icon {
    background: url('../assets/icons/calendar.svg') no-repeat center center;
    background-size: contain;
}

.chart-icon {
    background: url('../assets/icons/chart.svg') no-repeat center center;
    background-size: contain;
}

.graph-icon { /* Keep if used, otherwise remove */
    background: url('../assets/icons/graph.svg') no-repeat center center;
    background-size: contain;
}

/* Tile Icon Container */
.tile-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background-color: rgba(52, 152, 219, 0.1);
    margin-bottom: 0.8rem; /* Space below icon container */
}

/* Metrics Section */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem; /* Increased gap */
    margin-bottom: 1.5rem;
}

.metric-tile {
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 1.25rem;
    text-align: center;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.metric-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.metric-tile h4 {
    color: var(--gray-color);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    margin-top: 0; /* Reset margin from icon */
}

.metric-tile p {
    font-size: 1.6rem; /* Increased size */
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

/* Repayment Schedule Section */

/* Tabs for Yearly/Monthly VIEW */
.schedule-view-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem; /* Space below view tabs */
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

/* Tabs for selecting WHICH loan schedule to view (All / Loan 1 / Loan 2 etc.) */
/* Using #schedule-tabs ID from HTML */
#schedule-tabs.loan-selection-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem; /* Spacing between loan tabs */
    margin-bottom: 1.5rem; /* Space below loan tabs */
    padding-bottom: 0; /* No bottom padding needed here */
    border-bottom: none; /* No border needed here */
}

/* General Schedule Tab Styling (Applies to both view and loan tabs) */
.schedule-tab {
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.6rem 1.2rem; /* Increased padding */
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.6rem; /* Increased gap */
    font-size: 0.95rem;
    color: var(--gray-color);
}

.schedule-tab.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: 600;
}
.schedule-tab:not(.active):hover {
     background-color: #f8f9fa; /* Subtle background on hover for inactive tabs */
     border-color: #adb5bd;
}


.schedule-tab-icon {
    width: 20px;
    height: 20px;
    display: flex; /* Ensure icon alignment */
    align-items: center;
}
.schedule-tab-icon img,
.schedule-tab-icon i { /* Style both img and font-awesome icons */
    width: 100%;
    height: auto;
    fill: currentColor; /* For SVG */
}

/* Removed redundant #loan-tabs selector */

.schedule-content {
    /* background-color: white; */ /* Let panes handle background */
    /* border-radius: var(--border-radius); */
    /* box-shadow: var(--box-shadow); */
    margin-bottom: 2rem;
}

.schedule-pane {
    display: none; /* Hide inactive panes */
    padding: 0; /* Remove padding, let table container handle it */
    animation: fadeIn 0.3s ease-out;
}

.schedule-pane.active {
    display: block;
}

/* Amortization Table Styling (Master Style) */
.amortization-table {
    width: 100%;
    border-collapse: collapse;
    box-shadow: var(--box-shadow);
    border-radius: var(--border-radius);
    overflow: hidden; /* Clip shadow */
    font-size: 0.9rem; /* Base size */
}

.amortization-table thead {
    background-color: var(--primary-color);
    color: white;
}

.amortization-table th,
.amortization-table td {
    padding: 0.8rem 1rem; /* Padding */
    text-align: right; /* Align numbers right */
    border-bottom: 1px solid var(--border-color);
}
.amortization-table th:first-child, /* Align year/month left */
.amortization-table td:first-child {
    text-align: left;
}
.amortization-table th:last-child, /* Last column for button */
.amortization-table td:last-child {
    text-align: center;
    width: 50px; /* Fixed width for button column */
    padding-right: 0.5rem;
    padding-left: 0.5rem;
}


.amortization-table th {
    font-weight: 600;
    white-space: nowrap; /* Prevent header wrapping */
}

.amortization-table tbody tr {
    background-color: white;
    transition: background-color 0.2s;
}

.amortization-table tbody tr:hover {
    background-color: #f5f8fa;
}

.amortization-table tbody tr.monthly-row td { /* Special row for nested table */
     padding: 0;
     background-color: #f8f9fa; /* Background for nested area */
     border-bottom: 1px solid var(--border-color); /* Ensure border continues */
}


.btn-toggle-months {
    background: transparent;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-toggle-months:hover {
    background-color: rgba(52, 152, 219, 0.1);
}
.btn-toggle-months i { /* Ensure icon scales */
     font-size: 0.9em;
}


/* Nested Monthly Breakdown Table Styles */
.monthly-details-container { /* TD element containing the nested table */
    padding: 0 !important; /* Override default TD padding */
}

.monthly-breakdown {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background-color: #fdfdfe; /* Slightly off-white background */
    font-size: 0.85rem; /* Smaller font for nested table */
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05); /* Subtle inset shadow */
}

.monthly-breakdown thead {
    background-color: rgba(84, 110, 122, 0.1);
    color: var(--dark-color);
    font-weight: 500; /* Lighter font weight */
}
.monthly-breakdown th {
     color: var(--primary-color);
     font-weight: 500;
}


.monthly-breakdown th,
.monthly-breakdown td {
    padding: 0.6rem 1rem; /* Reduced padding */
    border-bottom: 1px solid #eef2f7; /* Lighter border */
}
.monthly-breakdown th:last-child, /* Last column empty */
.monthly-breakdown td:last-child {
     width: 50px;
}


.monthly-breakdown tbody tr:last-child td {
    border-bottom: none; /* No border on last row */
}

/* Responsive styles */
@media (max-width: 768px) {
    .property-details {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .property-image {
        width: 100%;
        height: 140px; /* Adjust height for mobile */
        margin-bottom: 1rem;
    }
    .property-info {
        width: 100%; /* Ensure info takes full width */
    }
    .btn-edit {
        margin-top: 0.5rem; /* Adjust button margin */
    }

    .metrics-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }

    #loans-container { /* Target ID */
        grid-template-columns: 1fr; /* Stack loans on mobile */
    }

     /* Adjust table padding/font on mobile */
    .amortization-table th,
    .amortization-table td {
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }
     .amortization-table th:last-child,
    .amortization-table td:last-child {
        width: 40px; /* Smaller button column */
    }

    .monthly-breakdown th,
    .monthly-breakdown td {
         padding: 0.5rem;
         font-size: 0.8rem;
    }
     .monthly-breakdown th:last-child,
    .monthly-breakdown td:last-child {
         width: 40px;
    }


    .schedule-tab {
        padding: 0.5rem 0.8rem;
        font-size: 0.9rem;
    }
}

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

.loan-tile, .property-tile, .metric-tile, .add-loan-tile {
    /* Apply fade-in animation */
    animation: fadeIn 0.4s ease-out;
}

/* Loan Tiles */
.loans-container, .extra-repayments-container { /* Renamed selector */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.2rem;
    margin-top: 0.5rem;
}

.loan-tile, .add-loan-tile {
    background-color: #f8fafc;
    border-radius: var(--border-radius);
    padding: 1.2rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.loan-tile:hover, .add-loan-tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.loan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.loan-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--dark-color);
    font-weight: 500;
}

.loan-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-edit {
    background: none;
    border: none;
    color: var(--gray-color);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.btn-edit:hover {
    background-color: rgba(38, 166, 154, 0.1);
    color: var(--accent-color);
}

.loan-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1rem;
    flex-grow: 1;
}

.loan-detail {
    display: flex;
    flex-direction: column;
}

.loan-detail-label {
    font-size: 0.7rem;
    color: var(--gray-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.loan-detail-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--dark-color);
}

/* Empty state / Add tile */
.add-loan-tile {
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--gray-color);
    border: 1px dashed rgba(0, 0, 0, 0.1);
    background-color: rgba(246, 249, 252, 0.7);
}

.add-loan-tile:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.add-loan-tile .tile-icon-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.8rem;
}

.add-loan-tile p {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
}

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

.add-loan-tile.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    /* pointer-events: none; */ /* Removed this line */
}

.add-loan-tile.disabled:hover {
    transform: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--gray-color);
}