/*
 * Distance Between Two Airports.
 *
 * Everything is prefixed .apd- so it cannot collide with the site's Bootstrap
 * or with another tool's styles - this file loads on one page, and a bare
 * .card or .input here would leak into the shared stylesheet's territory.
 *
 * Mobile-first: the base rules are the narrow layout, and the two-column
 * arrangement is added at a breakpoint rather than being undone below one.
 */

.apd-page {
    --apd-ink: #0f2540;
    --apd-muted: #5a6b80;
    --apd-line: #dbe4ee;
    --apd-accent: #0b6bcb;
    --apd-accent-dark: #075299;
    --apd-sky: #eaf3fc;
    --apd-radius: 14px;

    max-width: 940px;
    padding-bottom: 1rem;
}

.apd-title {
    font-size: clamp(1.5rem, 4vw, 2.1rem);
    font-weight: 700;
    color: var(--apd-ink);
    margin-bottom: .35rem;
}

.apd-lede {
    color: var(--apd-muted);
    max-width: 60ch;
    margin-bottom: 1.25rem;
}

/* ---- card ------------------------------------------------------------- */

.apd-card {
    background: #fff;
    border: 1px solid var(--apd-line);
    border-radius: var(--apd-radius);
    /* Restrained: one soft shadow, not a stack of them. */
    box-shadow: 0 1px 2px rgba(15, 37, 64, .04), 0 8px 24px rgba(15, 37, 64, .06);
    padding: 1.25rem;
}

.apd-fields {
    display: grid;
    gap: .75rem;
}

.apd-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 600;
    color: var(--apd-ink);
    margin-bottom: .35rem;
}

.apd-icon {
    width: 20px;
    height: 20px;
    fill: var(--apd-accent);
    flex: 0 0 auto;
}

/* ---- combobox --------------------------------------------------------- */

.apd-combo {
    position: relative;
}

.apd-input {
    width: 100%;
    /* 44px minimum touch target, before padding is considered. */
    min-height: 48px;
    padding: .6rem 2.5rem .6rem .8rem;
    font-size: 1rem;
    color: var(--apd-ink);
    background: #fff;
    border: 1.5px solid var(--apd-line);
    border-radius: 10px;
    /* Colour is never the only signal - the border thickens on focus too. */
    transition: border-color .15s ease, box-shadow .15s ease;
}

.apd-input:hover {
    border-color: #b9c9dc;
}

.apd-input:focus {
    outline: 3px solid transparent; /* keeps a visible ring in forced-colours mode */
    border-color: var(--apd-accent);
    box-shadow: 0 0 0 3px rgba(11, 107, 203, .25);
}

.apd-input[aria-expanded="true"] {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.apd-clear {
    position: absolute;
    top: 50%;
    right: .35rem;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.apd-clear svg {
    width: 18px;
    height: 18px;
    fill: var(--apd-muted);
}

.apd-clear:hover svg { fill: var(--apd-ink); }

.apd-clear:focus-visible {
    outline: 2px solid var(--apd-accent);
    outline-offset: 1px;
}

.apd-list {
    position: absolute;
    z-index: 40;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 19rem;
    overflow-y: auto;
    background: #fff;
    border: 1.5px solid var(--apd-accent);
    border-top: 0;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 12px 24px rgba(15, 37, 64, .12);
}

.apd-option {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .55rem .8rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f4f9;
}

.apd-option:last-child { border-bottom: 0; }

/* Both states styled identically: the highlight must not depend on whether the
   pointer or the keyboard put it there. */
.apd-option[aria-selected="true"],
.apd-option:hover {
    background: var(--apd-sky);
}

.apd-option-code {
    flex: 0 0 auto;
    font-weight: 700;
    font-size: .95rem;
    color: var(--apd-accent-dark);
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}

.apd-option-body { min-width: 0; }

.apd-option-name {
    display: block;
    color: var(--apd-ink);
    /* One line: an airport name can be very long and a wrapped option makes the
       list jump as the visitor types. */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apd-option-place {
    display: block;
    font-size: .82rem;
    color: var(--apd-muted);
}

.apd-empty {
    padding: .7rem .8rem;
    color: var(--apd-muted);
}

.apd-help {
    font-size: .82rem;
    color: var(--apd-muted);
    margin: .3rem 0 0;
}

/* ---- swap ------------------------------------------------------------- */

.apd-swap-wrap {
    display: flex;
    justify-content: center;
}

.apd-swap {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    min-height: 44px;
    padding: .4rem .9rem;
    background: var(--apd-sky);
    color: var(--apd-accent-dark);
    border: 1px solid #cfe2f6;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}

.apd-swap svg { width: 18px; height: 18px; fill: currentColor; }

.apd-swap:hover { background: #ddecfb; }

.apd-swap:focus-visible {
    outline: 2px solid var(--apd-accent);
    outline-offset: 2px;
}

/* ---- actions ---------------------------------------------------------- */

.apd-validation {
    min-height: 1.25rem;
    margin: .85rem 0 0;
    color: #9a3412;
    font-size: .9rem;
}

.apd-validation:empty { margin: 0; min-height: 0; }

.apd-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: .85rem;
}

.apd-calc {
    flex: 1 1 12rem;
    min-height: 48px;
    padding: .7rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(180deg, var(--apd-accent) 0%, var(--apd-accent-dark) 100%);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.apd-calc:hover { filter: brightness(1.06); }

.apd-calc:focus-visible {
    outline: 3px solid var(--apd-accent);
    outline-offset: 2px;
}

.apd-calc[disabled] {
    /* Dimmed AND cursor-blocked: opacity alone is a colour-only signal. */
    opacity: .55;
    cursor: not-allowed;
    filter: none;
}

.apd-reset,
.apd-secondary {
    min-height: 48px;
    padding: .7rem 1.1rem;
    font-weight: 600;
    color: var(--apd-ink);
    background: #fff;
    border: 1.5px solid var(--apd-line);
    border-radius: 10px;
    cursor: pointer;
}

.apd-reset:hover,
.apd-secondary:hover { border-color: #b9c9dc; }

.apd-reset:focus-visible,
.apd-secondary:focus-visible {
    outline: 2px solid var(--apd-accent);
    outline-offset: 2px;
}

/* ---- examples --------------------------------------------------------- */

.apd-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    margin-top: 1rem;
    padding-top: .9rem;
    border-top: 1px solid #f0f4f9;
}

.apd-examples-label {
    font-size: .85rem;
    color: var(--apd-muted);
}

.apd-chip {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: .25rem .7rem;
    font-size: .85rem;
    font-weight: 600;
    color: var(--apd-accent-dark);
    background: var(--apd-sky);
    border-radius: 999px;
    text-decoration: none;
}

.apd-chip:hover {
    background: #ddecfb;
    text-decoration: none;
}

.apd-chip:focus-visible {
    outline: 2px solid var(--apd-accent);
    outline-offset: 2px;
}

/* ---- result ----------------------------------------------------------- */

.apd-result {
    margin-top: 1.25rem;
    padding: 1.25rem;
    background: linear-gradient(180deg, #f7fbff 0%, #fff 60%);
    border: 1px solid var(--apd-line);
    border-radius: var(--apd-radius);
    animation: apd-rise .25s ease-out;
}

@keyframes apd-rise {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.apd-result-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    font-size: 1.35rem;
    color: var(--apd-ink);
    margin: 0 0 .5rem;
}

.apd-code {
    font-weight: 800;
    letter-spacing: .04em;
    color: var(--apd-accent-dark);
}

.apd-route {
    position: relative;
    display: flex;
    align-items: center;
    height: 44px;
    margin: .25rem 0 1rem;
    color: #9db8d6;
}

.apd-path { flex: 1 1 auto; height: 40px; }

.apd-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--apd-accent);
    flex: 0 0 auto;
    align-self: flex-end;
    margin-bottom: 4px;
}

.apd-plane {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.apd-plane svg {
    width: 22px;
    height: 22px;
    fill: var(--apd-accent-dark);
    transform: rotate(90deg);
}

.apd-endpoints {
    display: grid;
    gap: .75rem;
    margin-bottom: 1rem;
}

.apd-endpoint {
    background: #fff;
    border: 1px solid var(--apd-line);
    border-radius: 10px;
    padding: .7rem .85rem;
}

.apd-endpoint p { margin: 0; }

.apd-endpoint-name { font-weight: 600; color: var(--apd-ink); }
.apd-endpoint-place { font-size: .88rem; color: var(--apd-muted); }

.apd-endpoint-coords {
    font-size: .82rem;
    color: var(--apd-muted);
    font-variant-numeric: tabular-nums;
    margin-top: .2rem;
}

.apd-primary {
    text-align: center;
    margin: 0 0 .75rem;
    line-height: 1;
}

.apd-primary-value {
    font-size: clamp(2.4rem, 9vw, 3.6rem);
    font-weight: 800;
    color: var(--apd-ink);
    font-variant-numeric: tabular-nums;
}

.apd-primary-unit {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--apd-muted);
    margin-left: .25rem;
}

.apd-units {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}

.apd-units li {
    background: #fff;
    border: 1px solid var(--apd-line);
    border-radius: 10px;
    padding: .55rem .7rem;
    text-align: center;
}

.apd-units strong {
    display: block;
    font-size: 1.05rem;
    color: var(--apd-ink);
    font-variant-numeric: tabular-nums;
}

.apd-units span {
    font-size: .78rem;
    color: var(--apd-muted);
}

.apd-explain {
    font-size: .9rem;
    color: var(--apd-muted);
    margin-bottom: 1rem;
}

.apd-result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
}

.apd-note {
    margin-top: 1.25rem;
    padding: .8rem 1rem;
    background: #f7fbff;
    border-left: 3px solid var(--apd-accent);
    border-radius: 0 8px 8px 0;
    font-size: .9rem;
    color: var(--apd-muted);
}

/* ---- utilities -------------------------------------------------------- */

.apd-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- desktop ---------------------------------------------------------- */

@media (min-width: 768px) {
    .apd-fields {
        /* Swap sits between the two fields, sized to itself. */
        grid-template-columns: 1fr auto 1fr;
        align-items: start;
        gap: 1rem;
    }

    .apd-swap-wrap {
        /* Nudged down so it lines up with the inputs, not with their labels. */
        padding-top: 2.1rem;
    }

    .apd-endpoints { grid-template-columns: 1fr 1fr; }
    .apd-units { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .apd-actions { flex-wrap: nowrap; }
    .apd-calc { flex: 0 0 auto; }
}

/* ---- reduced motion --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .apd-result { animation: none; }
    .apd-input { transition: none; }
}

/* ---- forced colours --------------------------------------------------- */

@media (forced-colors: active) {
    /* The highlighted option is distinguished by a real border, since the
       background colour is overridden by the system palette. */
    .apd-option[aria-selected="true"] { border: 2px solid Highlight; }
    .apd-input:focus { outline: 2px solid Highlight; }
}
