/*
 * The calculator family (TOOLS-PLAN 3.2, site/pages/free-tools/calculator.php, assets/js/ft/calc.js), after
 * ft-base.css. Tokens only.
 *
 *   .ft-calc > .ft-calc__inputs (.ft-calc__head, .ft-calc__actions, .ft-calc__example, .ft-field > .ft-input(--pre|--post)
 *              > .input + .ft-input__unit, .ft-field__err, .ft-field__opt)
 *            + .ft-calc__result (.ft-calc__status, .ft-out > .ft-out__row(--main), .ft-work, .ft-calc__share)
 *   .ft-bar > .ft-bar__btn   the phone's bottom bar with the main number (hidden from 960 px, where the result is sticky)
 * Desktop (960 px and wider): inputs 7/12, the result 5/12, sticky under the 64 px header. Phone: the result follows the
 * inputs. Every target is 44 px or more; fields are 16 px so a phone does not zoom in.
 */
.ft-calc {
    display: grid;
    gap: var(--sp-5);
    align-items: start;
}

@media (min-width: 960px) {
    .ft-calc {
        grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
        gap: var(--sp-8);
    }

    .ft-calc__result {
        position: sticky;
        top: 96px;
        /* never past a short laptop screen: a long result's math scrolls inside the card */
        max-height: calc(100vh - 112px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

.ft-calc__inputs,
.ft-calc__result {
    display: grid;
    gap: var(--sp-4);
    padding: var(--sp-4);
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
}

@media (min-width: 640px) {
    .ft-calc__inputs,
    .ft-calc__result { padding: var(--sp-6); }
}

.ft-calc__inputs {
    background: var(--c-surface);
}

.ft-calc__result {
    gap: 0;
    background: var(--c-surface-2);
}

.ft-calc__result:focus {
    outline: none;
}

.ft-calc__result:focus-visible {
    box-shadow: var(--focus-ring);
}

.ft-calc__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2) var(--sp-4);
}

.ft-calc__title {
    margin: 0;
    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    color: var(--c-ink);
}

.ft-calc__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
}

.ft-calc .btn {
    min-height: 44px;
}

.ft-calc__example {
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--c-text-2);
}

/* ---- fields */
.ft-field .field__label {
    font-size: var(--fs-sm);
}

.ft-field__opt {
    font-weight: var(--fw-regular);
    color: var(--c-muted);
}

.ft-field .input,
.ft-field .select {
    min-height: 44px;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

/* the unit sits inside the box: "$" before the number, "%", "min", "ft" after it */
.ft-input {
    position: relative;
    display: block;
}

.ft-input__unit {
    position: absolute;
    top: 50%;
    font-size: 1rem;
    font-weight: var(--fw-medium);
    color: var(--c-muted);
    pointer-events: none;
    transform: translateY(-50%);
}

.ft-input--pre .ft-input__unit:first-child {
    left: 12px;
}

.ft-input--post .ft-input__unit:last-child {
    right: 12px;
}

.ft-input--pre .input {
    padding-left: 28px;
}

.ft-input--post .input {
    padding-right: 3.5em;
}

.ft-field__err {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--c-danger-ink);
}

.ft-field__err:empty {
    display: none;
}

.ft-field .input[aria-invalid="true"],
.ft-field .select[aria-invalid="true"] {
    border-color: var(--c-danger);
}

/* ---- the result */
.ft-calc__status {
    margin: var(--sp-2) 0 0;
    min-height: 1.5em;
    color: var(--c-text-2);
}

.ft-out {
    display: grid;
    margin: var(--sp-2) 0 0;
}

.ft-out__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--c-line);
}

.ft-out__row dt {
    min-width: 0;
    font-size: var(--fs-sm);
    color: var(--c-text-2);
}

.ft-out__row dd {
    margin: 0;
    font-weight: var(--fw-semibold);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--c-ink);
}

.ft-out__row--main dt {
    font-weight: var(--fw-semibold);
    color: var(--c-ink);
}

.ft-out__row--main dd {
    font-size: var(--fs-2xl);
    font-weight: var(--fw-bold);
}

.ft-work {
    display: grid;
    gap: var(--sp-1);
    margin: var(--sp-4) 0 0;
    padding: 0;
    font-size: var(--fs-sm);
    font-variant-numeric: tabular-nums;
    color: var(--c-text-2);
    list-style: none;
    overflow-wrap: anywhere;
}

.ft-calc__share {
    margin-top: var(--sp-4);
}

/* ---- the phone's bottom bar */
.ft-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-sticky);
    padding: var(--sp-1) var(--sp-4) calc(var(--sp-1) + env(safe-area-inset-bottom, 0px));
    background: var(--c-surface);
    border-top: 1px solid var(--c-line-strong);
    box-shadow: var(--sh-md);
}

.ft-bar__btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    width: 100%;
    min-height: 48px;
    padding: 0;
    font: inherit;
    color: var(--c-text-2);
    text-align: left;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.ft-bar__btn strong {
    font-size: var(--fs-lg);
    font-variant-numeric: tabular-nums;
    color: var(--c-ink);
    white-space: nowrap;
}

.ft-bar__btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@media (min-width: 960px) {
    .ft-bar { display: none !important; }
}

@media print {
    .ft-calc__actions,
    .ft-calc__share,
    .ft-bar {
        display: none !important;
    }

    .ft-calc {
        grid-template-columns: 1fr;
    }

    .ft-calc__result {
        position: static;
    }
}
