
/*tool code */
:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #6c757d;
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --border-radius: 8px;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);

    --color-pni: #007bff;
    --color-tax: #28a745;
    --color-insurance: #ffc107;
    --color-pmi: #dc3545;
    --color-hoa: #6f42c1;
    --color-accelerated: #17a2b8;
}

.mortgage-calculator-tool {
    display: flex;
    gap: 2rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.calculator-inputs, .calculator-results {
    flex: 1;
}

.calculator-inputs {
    min-width: 320px;
}

.tool-title {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.input-group, .collapsible-group {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.input-group h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.form-field {
    margin-bottom: 1.25rem;
}
.form-field:last-child {
    margin-bottom: 0;
}

.form-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.input-wrapper {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
}
.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.input-wrapper span {
    padding: 0 0.75rem;
    background: var(--bg-color);
    color: var(--secondary-color);
    font-weight: 500;
}

.input-wrapper input, .form-field select {
    width: 100%;
    border: none;
    padding: 0.75rem;
    font-size: 1rem;
    background: transparent;
    outline: none;
}
.form-field select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 16px 12px;
    padding-right: 2rem;
}
.dual-field {
    display: flex;
    gap: 1rem;
}
.dual-field .field {
    flex: 1;
}

.collapsible-group summary {
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    list-style: none;
    position: relative;
    padding-right: 20px;
}
.collapsible-group summary::-webkit-details-marker { display: none; }
.collapsible-group summary::after {
    content: '▶';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%) rotate(0);
    transition: transform 0.2s;
    font-size: 0.8em;
}
.collapsible-group[open] > summary::after {
    transform: translateY(-50%) rotate(90deg);
}
.collapsible-content {
    padding-top: 1.5rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.tooltip-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: var(--secondary-color);
    color: white;
    border-radius: 50%;
    text-align: center;
    font-size: 12px;
    line-height: 16px;
    cursor: help;
    position: relative;
}
.tooltip-icon:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    width: 250px;
    text-align: left;
    z-index: 10;
    opacity: 1;
    visibility: visible;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.calculate-btn, .reset-btn {
    flex: 1;
    padding: 0.85rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

.calculate-btn {
    background-color: var(--primary-color);
    color: white;
}
.calculate-btn:hover {
    background-color: var(--primary-hover);
}

.reset-btn {
    background-color: var(--secondary-color);
    color: white;
}
.reset-btn:hover {
    background-color: #5a6268;
}

/* Results Panel */
.calculator-results {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.results-summary {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
}
.results-summary p {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: var(--secondary-color);
}
.results-summary h3 {
    margin: 0;
    font-size: 2.75rem;
    color: var(--primary-color);
    font-weight: 700;
}

.results-breakdown {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    width: 150px;
    height: 150px;
    flex-shrink: 0;
}

#payment-pie-chart {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--bg-color);
}

#chart-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

#breakdown-list {
    list-style: none;
    padding: 0;
    margin: 0;
    width: 100%;
}
#breakdown-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    font-size: 0.95rem;
}
#breakdown-list li span:first-child {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.p-and-i, .standard { background-color: var(--color-pni); }
.tax { background-color: var(--color-tax); }
.insurance { background-color: var(--color-insurance); }
.pmi { background-color: var(--color-pmi); }
.hoa { background-color: var(--color-hoa); }
.accelerated { background-color: var(--color-accelerated); }

.insights-box {
    background-color: #e6f2ff;
    border: 1px solid #b3d7ff;
    color: #004085;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin: 1.5rem 0;
    font-size: 0.95rem;
}
.insights-box.hidden { display: none; }
.insights-box h4 { margin: 0 0 0.5rem 0; }
.insights-box p { margin: 0; }

.loan-balance-graph { margin-bottom: 1.5rem; }
.loan-balance-graph h4 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}
#loan-balance-chart-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    background: #fafafa;
}
#loan-balance-chart .grid { stroke: #e0e0e0; stroke-width: 0.5; }
#loan-balance-chart .axis { stroke: #999; stroke-width: 1; }
#loan-balance-chart .labels { font-size: 10px; fill: #666; }
#loan-balance-chart .line-standard { stroke: var(--color-pni); stroke-width: 2.5; fill: none; }
#loan-balance-chart .line-accelerated { stroke: var(--color-accelerated); stroke-width: 2.5; fill: none; stroke-dasharray: 4 4; }

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0.75rem;
    font-size: 0.85rem;
}
.legend-item { display: flex; align-items: center; gap: 0.5rem; }

#amortization-details .collapsible-content { padding: 0; }
.amortization-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: auto; /* Added for horizontal scrolling */
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}
#amortization-table {
    width: 100%;
    border-collapse: collapse;
}
#amortization-table th, #amortization-table td {
    padding: 0.4rem 0.40rem; /* Reduced vertical padding for a more compact look */
    font-size: 0.875rem;     /* Smaller font size for table data */
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;     /* Keep cell content on a single line */
}
#amortization-table th {
    background-color: var(--bg-color);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
/* Left-align the first column (typically the payment number) for better readability */
#amortization-table th:first-child,
#amortization-table td:first-child {
    text-align: left;
}
#amortization-table tbody tr:nth-child(even) {
    background-color: var(--bg-color);
}
#amortization-table tbody tr:hover {
    background-color: #e9ecef;
}

.shimmer {
    color: transparent !important;
    background: linear-gradient(100deg, #eff1f3 40%, #e2e2e2 50%, #eff1f3 60%) var(--bg-color);
    background-size: 200% 100%;
    background-position-x: 180%;
    animation: 1.5s shimmer ease-in-out infinite;
    border-radius: 4px;
}
@keyframes shimmer { to { background-position-x: -20%; } }

/* Mobile Responsive */
@media (max-width: 992px) {
    .mortgage-calculator-tool {
        flex-direction: column;
    }
    .results-breakdown {
        flex-direction: column;
        align-items: stretch;
    }
    .chart-container {
        align-self: center;
    }
}
@media (max-width: 480px) {
    .input-group, .calculator-results {
        padding: 1rem;
    }
    .results-summary h3 {
        font-size: 2rem;
    }
    .dual-field {
        flex-direction: column;
        gap: 0;
    }
    .dual-field .field {
        margin-bottom: 1.25rem;
    }
     .dual-field .field:last-child {
        margin-bottom: 0;
    }
}