/* Debt Calculation Tool - Custom Styles */

/* General Styles */
body {
    background-color: #f8f9fa;
    color: #333;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Card Styles */
.card {
    transition: all 0.3s ease;
    border-radius: 8px;
}

.card:hover {
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
}

.card-header {
    border-top-left-radius: 10px !important;
    border-top-right-radius: 10px !important;
}

/* Form Controls */
.form-control:focus, .form-select:focus {
    box-shadow: 0 0 0 0.25rem rgba(1, 39, 64, 0.25);
    border-color: rgb(1, 39, 64);
}

/* Button Styles */
.btn-primary {
    background-color: rgb(1, 39, 64);
    border-color: rgb(1, 39, 64);
}

.btn-primary:hover {
    background-color: rgba(1, 39, 64, 0.85);
    border-color: rgb(1, 39, 64);
}

/* Export Button Styles */
#exportCsvBtn {
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#exportCsvBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#exportCsvBtn:active {
    transform: translateY(0);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

.btn-outline-primary {
    color: rgb(1, 39, 64);
    border-color: rgb(1, 39, 64);
}

.btn-outline-primary:hover {
    background-color: rgb(1, 39, 64);
    color: white;
}

/* This is a duplicate rule that was already updated above */

/* Table Styles */
.table th {
    font-weight: 600;
    color: #4b5563;
    vertical-align: top; /* Make header text top-aligned */
}

.table td {
    vertical-align: middle;
}

/* Specifically target the existing debt table headers */
#existingDebtTable th {
    vertical-align: top;
}

/* Left-align Maturity and Yield headers in the yield curve table */
#yieldCurveTable th {
    text-align: left !important; /* Use !important to override the text-center class */
}

/* More specific selector to override the text-center class */
#yieldCurveTable th.text-center {
    text-align: left !important;
}

/* Existing Debt Table Column Widths */
#existingDebtTable tr th:nth-child(1),
#existingDebtTable tr td:nth-child(1) {
    min-width: 140px; /* Type column */
    width: 140px;
}

#existingDebtTable tr th:nth-child(4),
#existingDebtTable tr td:nth-child(4) {
    min-width: 220px; /* Repayment column */
    width: 220px;
}

/* Fix for dropdown caret overlap */
#existingDebtTable .form-select {
    padding-right: 2rem; /* Increase padding on the right side for the caret */
    text-overflow: ellipsis; /* Add ellipsis for text overflow */
}

/* Section Styles */
.section-title {
    display: flex;
    align-items: center;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #2d3748;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.section-title i {
    margin-right: 0.5rem;
    color: rgb(1, 39, 64);
}

/* Results Section */
.results-section {
    background-color: #f0f4f8;
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.results-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Row styles */
.results-row {
    display: flex;
    gap: 1rem;
}

/* First row with metrics */
.metrics-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Second row with charts */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* When yield curve is not shown */
.charts-row.no-yield-curve #debtServiceChartCard {
    grid-column: 1 / -1; /* Span all columns */
    width: 100%;
}

/* Metrics Column (Left Side) */
.metrics-column {
    display: flex;
    flex-direction: column;
}

/* Charts Column (Right Side) */
.charts-column {
    display: flex;
    flex-direction: column;
}

#resultsContainer {
    opacity: 0;
    transition: opacity 0.5s ease;
}

#resultsContainer.fade-in {
    opacity: 1;
}

/* Calculate Button Container */
.calculate-button-container {
    text-align: center;
    margin: 1.5rem 0;
    position: relative;
}

.calculate-button-container:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background-color: #e2e8f0;
    z-index: 1;
}

.calculate-button-container button {
    position: relative;
    z-index: 2;
    padding: 0.75rem 2rem;
    font-size: 1.1rem;
    border-radius: 50px;
    box-shadow: 0 4px 6px rgba(1, 39, 64, 0.25);
}

/* Inputs Section */
.inputs-section {
    background-color: #fff;
    border-radius: 10px;
    padding: 0.75rem 0;
}

/* Calculation Settings */
.calculation-settings {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* Key Metrics */
.list-group-item {
    padding: 0.75rem;
}

/* Savings and ATM Cards */
.savings-card-body, .atm-card-body {
    background-color: #e8f5e9; /* Light green background */
}

.savings-card-body table, .atm-card-body table {
    margin-bottom: 0;
}

.savings-card-body td, .atm-card-body td {
    padding: 0.25rem 0.75rem;
    border: none;
}

/* Compact Table Styles */
.compact-table tr {
    line-height: 1.2;
}

.compact-table td {
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
}

/* Chart Containers */
canvas {
    max-width: 100%;
    width: 100% !important;
    height: auto !important;
}

/* Chart container height limits */
.card-body canvas {
    max-height: 400px !important;
}

/* Fixed height for chart containers when both charts are showing */
.card-body.dual-chart-mode {
    height: 400px !important;
    overflow: hidden;
}

/* Ensure charts fit within their containers */
.card-body.dual-chart-mode canvas {
    max-height: 100% !important;
}

/* Debt Service Chart */
#debtServiceChart {
    width: 100% !important;
    cursor: pointer !important;
}

/* Yield Curve Chart */
#yieldCurveChart {
    width: 100% !important;
    cursor: pointer !important;
}

/* Change cursor to pointer when hovering over chart elements */
.card-body canvas {
    cursor: pointer !important;
}

/* Make input fields in Existing Debt table more visibly editable */
#existingDebtTable input.form-control:not([disabled]),
#existingDebtTable select.form-select:not([disabled]) {
    border-bottom: 1px solid #e2e8f0 !important;
    background-color: #f8fafc !important;
    transition: all 0.2s ease;
    min-width: 100px;
}

/* Add a slightly enhanced hover effect */
#existingDebtTable input.form-control:not([disabled]):hover,
#existingDebtTable select.form-select:not([disabled]):hover {
    background-color: #f1f5f9 !important;
    border-bottom-color: #cbd5e1 !important;
}

/* Hide disabled fields completely */
#existingDebtTable input.form-control[disabled],
#existingDebtTable select.form-select[disabled] {
    display: none;
}

/* Style for cells with disabled inputs */
#existingDebtTable td:has(input.form-control[disabled]),
#existingDebtTable td:has(select.form-select[disabled]) {
    background-color: #f1f1f1;
    position: relative;
}

/* Add placeholder dash to cells with disabled inputs */
#existingDebtTable td:has(input.form-control[disabled])::after,
#existingDebtTable td:has(select.form-select[disabled])::after {
    content: "—";
    color: #9ca3af;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* Responsive Adjustments */
@media (max-width: 992px) {
    .results-grid,
    .results-grid.no-yield-curve,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .card-body {
        padding: 1rem;
    }

    .row > [class*="col-"] {
        margin-bottom: 1rem;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    /* Make Savings and ATM boxes stack vertically */
    .metrics-row {
        grid-template-columns: 1fr;
    }

    /* Add some spacing between the stacked boxes */
    .metrics-row > .card:first-child {
        margin-bottom: 1.5rem;
    }
}

/* Yield Curve Bond Cards */
.yield-curve-bond {
    border-radius: 8px;
    transition: all 0.3s ease;
}

.yield-curve-bond:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

/* Debt Instrument Styles */
.debt-instrument {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    background-color: white;
}

.debt-instrument-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.debt-instrument-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: rgb(1, 39, 64);
}

.remove-instrument-btn {
    cursor: pointer;
    color: #ef4444;
    font-size: 1.2rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.remove-instrument-btn:hover {
    background-color: #fee2e2;
}

/* New Debt Grid */
.new-debt-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

@media (max-width: 992px) {
    .new-debt-grid {
        grid-template-columns: 1fr;
    }
}

/* Style for read-only Principal Amount field */
#newDebtAmount {
    background-color: #e9ecef !important;
    border-left: 3px solid #6c757d !important;
    color: #495057;
    cursor: not-allowed;
    padding-right: 30px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%236c757d" viewBox="0 0 16 16"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

/* Make the auto-calculated text more prominent */
#newDebtAmount + small.text-muted {
    font-weight: 500;
    color: #6c757d !important;
    display: flex;
    align-items: center;
}

#newDebtAmount + small.text-muted::before {
    content: "🔄";
    margin-right: 4px;
}

/* Grace field validation styles */
.grace-error {
    font-size: 0.8rem;
    color: #dc3545;
}

.is-invalid {
    border-color: #dc3545 !important;
    background-color: #fff8f8 !important;
}

/* Negative value styling for results dashboard */
.negative-value {
    color: #dc3545 !important; /* Bootstrap danger red */
    font-weight: bold !important;
}
