/* The site header is sticky, so an in-page jump from a car must clear it */
#calculator {
    scroll-margin-top: 90px;
}

/* Car loan calculator — /loan */

/* align-items:start is what lets the result card stick — do not "tidy" it away */
.dm-loan-calc {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.dm-loan-card {
    background: var(--dm-white);
    border: 1px solid var(--dm-border);
    border-radius: var(--dm-card-radius);
    box-shadow: var(--dm-shadow-sm);
    padding: 24px;
}

.dm-loan-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.dm-loan-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--dm-red);
    color: var(--dm-white);
    font-size: 0.8rem;
    font-weight: 800;
    margin-right: 10px;
    flex-shrink: 0;
}

.dm-loan-card-title {
    display: flex;
    align-items: center;
    font-size: 1rem;
    font-weight: 800;
    margin: 0;
}

.dm-loan-live {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    /* Small red text uses the ink red (5.9:1); the brand red is 4.1:1 */
    color: var(--dm-red-dark);
}

.dm-loan-field {
    margin-bottom: 18px;
}

.dm-loan-field:last-child {
    margin-bottom: 0;
}

.dm-loan-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.dm-loan-caption {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--dm-text-muted);
    text-align: right;
}

.dm-loan-input {
    position: relative;
}

.dm-loan-input .form-control {
    border: 2px solid var(--dm-gray-400);
    border-radius: var(--dm-btn-radius);
    padding: 10px 52px 10px 14px;
    font-weight: 700;
    font-size: 1.05rem;
    transition: var(--dm-transition);
}

.dm-loan-input .form-control:focus {
    border-color: var(--dm-red);
    box-shadow: 0 0 0 0.2rem rgba(var(--dm-red-rgb), 0.15);
}

.dm-loan-input--error .form-control {
    border-color: var(--dm-red-dark);
}

.dm-loan-unit {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    max-width: 44px;
    text-align: right;
    font-weight: 800;
    color: var(--dm-text-muted);
    pointer-events: none;
}

.dm-loan-error {
    margin: 6px 0 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--dm-red-dark);
}

/* The message keeps its element and swaps its text, so an empty one must vanish */
.dm-loan-error:empty {
    display: none;
}

/* Toggle groups: financier, down-payment mode, quick picks */
.dm-loan-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dm-loan-toggle .dm-loan-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 16px;
    /* Same resting affordance as .dm-qsearch-tab / .dm-auth-tab */
    background: var(--dm-gray-100);
    border: 1px solid var(--dm-gray-200);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--dm-text-muted);
    cursor: pointer;
    transition: var(--dm-transition);
}

.dm-loan-toggle .dm-loan-chip:hover {
    border-color: var(--dm-red);
    color: var(--dm-red);
}

.dm-loan-toggle .dm-loan-chip.active {
    background: var(--dm-red);
    border-color: var(--dm-red);
    color: var(--dm-white);
}

.dm-loan-toggle .dm-loan-chip:focus-visible {
    /* Same ring the rest of the site uses — a red ring disappears on an active chip */
    outline: 3px solid var(--dm-gold, #E0B873);
    outline-offset: 2px;
}

.dm-loan-chip-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(var(--dm-red-rgb), 0.18);
    color: var(--dm-red-dark);
    font-size: 0.7rem;
    font-weight: 800;
}

.dm-loan-chip.active .dm-loan-chip-mark {
    background: rgba(255, 255, 255, 0.22);
    color: var(--dm-white);
}

.dm-loan-quick {
    margin-top: 10px;
}

.dm-loan-quick .dm-loan-chip {
    /* 44px is the house minimum touch target — only the type shrinks */
    min-height: 44px;
    padding: 4px 14px;
    font-size: 0.8rem;
}

/* Results */
.dm-loan-result {
    /* The site's dark surfaces are black (navbar, footer, .btn-dm-dark) */
    background: var(--dm-black);
    color: var(--dm-white);
    border-radius: var(--dm-card-radius);
    padding: 24px;
    position: sticky;
    top: 90px;
}

.dm-loan-result .dm-loan-card-title {
    color: var(--dm-white);
}

.dm-loan-provider-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--dm-gray-400);
}

.dm-loan-monthly-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--dm-gray-400);
}

.dm-loan-monthly {
    display: block;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1.15;
    color: var(--dm-red-light);
}

.dm-loan-monthly-caption {
    display: block;
    font-size: 0.8rem;
    color: var(--dm-gray-400);
    margin-bottom: 18px;
}

.dm-loan-principal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--dm-gray-600);
    border-radius: var(--dm-btn-radius);
    margin-bottom: 14px;
}

.dm-loan-principal-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--dm-gray-400);
}

.dm-loan-principal-value {
    font-variant-numeric: tabular-nums;
    font-size: 1.25rem;
    font-weight: 800;
}

.dm-loan-financed {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--dm-red-light);
    white-space: nowrap;
}

.dm-loan-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--dm-gray-200);
    overflow: hidden;
    margin-bottom: 6px;
}

.dm-loan-bar-fill {
    height: 100%;
    width: 0;
    background: var(--dm-red);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.dm-loan-bar-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--dm-gray-400);
    margin-bottom: 16px;
}

.dm-loan-summary {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.dm-loan-summary td {
    padding: 9px 0;
    border-top: 1px solid var(--dm-gray-600);
}

.dm-loan-summary td:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
}

.dm-loan-summary tr.dm-loan-summary-total td {
    font-size: 1rem;
    font-weight: 800;
    color: var(--dm-red-light);
}

.dm-loan-note {
    margin: 16px 0 0;
    padding-top: 14px;
    border-top: 1px solid var(--dm-gray-600);
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--dm-gray-400);
}

.dm-loan-car {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 10px 14px;
    background: rgba(var(--dm-red-rgb), 0.08);
    border: 1px solid rgba(var(--dm-red-rgb), 0.35);
    border-radius: var(--dm-btn-radius);
    font-size: 0.85rem;
    font-weight: 600;
}

@media (max-width: 991.98px) {
    .dm-loan-calc {
        grid-template-columns: 1fr;
    }

    .dm-loan-result {
        position: static;
    }

    .dm-loan-monthly {
        font-size: 2rem;
    }
}

@media (max-width: 575.98px) {
    .dm-loan-card-head,
    .dm-loan-label {
        flex-wrap: wrap;
    }

    .dm-loan-card,
    .dm-loan-result {
        padding: 18px;
    }

    .dm-loan-monthly {
        font-size: 1.6rem;
    }

    .dm-loan-summary {
        font-size: 0.82rem;
    }
}
