/*
 * Tool Platform styles. Load order: Bootstrap → tokens.css (generated) → this file.
 *
 *  1. Bootstrap mapping   – Bootstrap's CSS variables point at our design tokens
 *  2. Base                – body, links, focus, headings, niche heading face
 *  3. Layout              – container, page head, main + sidebar grid
 *  4. Header & navigation – header, nav, popovers (<details>), search, language menu
 *  5. Controls            – buttons and form fields on top of Bootstrap
 *  6. Tool panel & result – the focal point of every tool page
 *  7. Content             – prose, tables, FAQ, formula, alerts
 *  8. Cards & lists
 *  9. Ads & footer
 *
 * Rules: no colours, radii or spacing literals where a token exists; cards are
 * flat (hairline border, no shadow); shadow only on the tool panel and popovers.
 * Classes prefixed `tf-` are ours; everything else is Bootstrap.
 */

/* ---------- 1. Bootstrap mapping ---------- */
:root {
    color-scheme: light dark;

    --bs-body-font-family: var(--font-sans);
    --bs-body-font-size: 1rem;
    --bs-body-line-height: 1.625;
    --bs-body-color: var(--ink);
    --bs-body-color-rgb: var(--ink-rgb);
    --bs-body-bg: var(--surface-page);
    --bs-body-bg-rgb: var(--surface-page-rgb);
    --bs-secondary-color: var(--ink-muted);
    --bs-secondary-bg: var(--surface-sunken);
    --bs-tertiary-bg: var(--surface-sunken);
    --bs-emphasis-color: var(--ink);
    --bs-border-color: var(--border);
    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-md);
    --bs-border-radius-xl: var(--radius-lg);
    --bs-link-color: var(--brand-text);
    --bs-link-color-rgb: var(--brand-text-rgb);
    --bs-link-hover-color: var(--brand-text);
    --bs-link-hover-color-rgb: var(--brand-text-rgb);
    --bs-primary: var(--brand);
    --bs-primary-rgb: var(--brand-rgb);
    --bs-focus-ring-color: transparent;
    --bs-heading-color: var(--ink);
    --bs-code-color: var(--ink);

    --font-heading: var(--font-display);
    --heading-weight: 700;
    --heading-tracking: -0.025em;
    --gutter: var(--space-4);
}

@media (min-width: 768px) {
    :root {
        --gutter: var(--space-6);
    }
}

/* Niche identity: the one typographic knob per site (see the design system README). */
[data-site="platform"] { --font-heading: var(--font-display); --heading-weight: 700; --heading-tracking: -0.025em; }
[data-site="symfony"] { --font-heading: var(--font-mono); --heading-weight: 600; --heading-tracking: -0.03em; }
[data-site="running"] { --font-heading: var(--font-display); --heading-weight: 800; --heading-tracking: -0.035em; }
[data-site="beekeeping"] { --font-heading: var(--font-serif); --heading-weight: 600; --heading-tracking: -0.01em; }

/* ---------- 2. Base ---------- */
body {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    text-underline-offset: 3px;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.tf-num {
    font-variant-numeric: tabular-nums;
}

.tf-icon {
    width: 20px;
    height: 20px;
    flex: none;
}

.tf-icon--sm {
    width: 16px;
    height: 16px;
}

.tf-h1,
.tf-h2,
.tf-h3 {
    font-family: var(--font-heading);
    color: var(--ink);
    margin: 0;
}

.tf-h1 { font-size: 1.75rem; line-height: 34px; font-weight: var(--heading-weight); letter-spacing: var(--heading-tracking); }
.tf-h2 { font-size: 1.375rem; line-height: 28px; font-weight: 600; letter-spacing: -0.015em; margin-bottom: var(--space-3); }
.tf-h3 { font-size: 1.125rem; line-height: 24px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: var(--space-2); }
.tf-lead { font-size: 1.0625rem; line-height: 26px; color: var(--ink-muted); margin: var(--space-2) 0 0; max-width: var(--measure); }
.tf-caption { font-size: 0.8125rem; line-height: 18px; color: var(--ink-subtle); }
.tf-eyebrow { font-size: 0.75rem; line-height: 16px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }

@media (min-width: 768px) {
    .tf-h1 { font-size: 2.25rem; line-height: 44px; }
    .tf-h2 { font-size: 1.5rem; line-height: 32px; }
}

/* ---------- 3. Layout ---------- */
.tf-container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.tf-page-head {
    padding: var(--space-4) 0 var(--space-5);
}

.tf-page-head .tf-meta {
    margin-top: var(--space-2);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
}

.tf-layout {
    display: grid;
    gap: var(--space-8);
    grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1024px) {
    .tf-layout--sidebar {
        grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
    }
}

.tf-main {
    min-width: 0;
    max-width: var(--content-max);
}

.tf-main--wide {
    max-width: none;
}

.tf-section {
    margin-top: var(--space-10);
    scroll-margin-top: 80px;
}

@media (min-width: 768px) {
    .tf-section { margin-top: var(--space-12); }
}

.tf-sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .tf-sidebar {
        display: block;
    }

    .tf-sticky {
        position: sticky;
        top: 80px;
        display: grid;
        gap: var(--space-6);
    }
}

.tf-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}

/* ---------- 4. Header & navigation ---------- */
.tf-mark {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--ink);
    text-decoration: none;
    font-family: var(--font-heading);
    font-weight: var(--heading-weight);
    letter-spacing: calc(var(--heading-tracking) * 0.5);
    font-size: 1.0625rem;
    line-height: 20px;
    white-space: nowrap;
}

.tf-mark__glyph {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--brand);
    color: var(--on-brand);
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0;
}

.tf-header {
    background: var(--surface-glass);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: var(--z-header);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .tf-header { background: var(--surface); }
}

.tf-header__bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 56px;
}

.tf-header__nav {
    display: none;
    align-items: center;
    gap: var(--space-1);
}

.tf-header__search {
    display: none;
    flex: 1;
    max-width: 460px;
    margin-left: auto;
}

.tf-header__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

@media (min-width: 1024px) {
    .tf-header__bar { height: 64px; gap: var(--space-6); }
    .tf-header__nav { display: flex; }
    .tf-header__search { display: block; }
    .tf-header__actions { margin-left: 0; }
    .tf-only-mobile { display: none !important; }
}

.tf-iconbtn {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border: 0;
    background: none;
    color: var(--ink);
    border-radius: var(--radius-pill);
    cursor: pointer;
    list-style: none;
}

.tf-iconbtn:hover { background: var(--surface-sunken); }
.tf-iconbtn::-webkit-details-marker { display: none; }

.tf-navlink {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0 var(--space-3);
    height: 36px;
    border-radius: var(--radius-pill);
    color: var(--ink);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9375rem;
    list-style: none;
    cursor: pointer;
}

.tf-navlink:hover { background: var(--surface-sunken); }
.tf-navlink[aria-current="page"] { color: var(--brand-text); }
.tf-navlink::-webkit-details-marker { display: none; }

/* Popovers are <details>: they work without JavaScript; the `popover` Stimulus controller only adds close-on-outside-click. */
.tf-popover {
    position: relative;
}

.tf-popover > summary { list-style: none; }

.tf-popover__panel {
    position: absolute;
    top: calc(100% + var(--space-2));
    z-index: var(--z-popover);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
    padding: var(--space-2);
}

.tf-popover__panel--end { right: 0; }

.tf-mega {
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    width: min(720px, 90vw);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-6);
}

.tf-mega h3 { margin: 0 0 var(--space-2); font-size: 0.9375rem; line-height: 20px; }
.tf-mega h3 a { color: var(--ink); text-decoration: none; }
.tf-mega ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.tf-mega li a { color: var(--ink-muted); text-decoration: none; font-size: 0.875rem; line-height: 28px; }
.tf-mega li a:hover { color: var(--brand-text); text-decoration: underline; }

/* Mobile menu: a full-width sheet under the header. */
.tf-mobile-menu > .tf-popover__panel {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow-y: auto;
    padding: var(--space-4);
    z-index: var(--z-drawer);
}

.tf-acc { border-top: 1px solid var(--border); }
.tf-acc a { display: block; padding: var(--space-2) 0; color: var(--ink); text-decoration: none; font-weight: 500; min-height: 44px; display: flex; align-items: center; }

/* Search */
.tf-search { position: relative; }

.tf-search__field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-2) 0 var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    background: var(--surface-sunken);
    color: var(--ink-muted);
}

.tf-search__field:focus-within {
    background: var(--surface);
    border-color: var(--border-control);
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.tf-search__field input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: none;
    font: inherit;
    font-size: 1rem;
    color: var(--ink);
}

.tf-search__field input::placeholder { color: var(--ink-subtle); }
.tf-search--hero .tf-search__field { height: 52px; font-size: 1.0625rem; padding-left: var(--space-4); background: var(--surface); border-color: var(--border); }

.tf-kbd {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    line-height: 16px;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--ink-subtle);
    background: var(--surface);
}

.tf-suggest {
    position: absolute;
    top: calc(100% + var(--space-2));
    left: 0;
    right: 0;
    z-index: var(--z-popover);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
    padding: var(--space-2);
    max-height: 70vh;
    overflow-y: auto;
}

.tf-suggest[hidden] { display: none; }
.tf-suggest ul { list-style: none; margin: 0; padding: 0; }

.tf-suggest__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    min-height: 44px;
    color: var(--ink);
    text-decoration: none;
    border-radius: var(--radius-sm);
}

.tf-suggest__item[aria-selected="true"],
.tf-suggest__item:hover { background: var(--brand); color: var(--on-brand); }
.tf-suggest__meta { margin-left: auto; font-size: 0.8125rem; color: var(--ink-muted); white-space: nowrap; }
.tf-suggest__item[aria-selected="true"] .tf-suggest__meta,
.tf-suggest__item:hover .tf-suggest__meta { color: inherit; }

/* Language selector */
.tf-lang__menu { width: 280px; }
.tf-lang__menu a { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: var(--space-2) var(--space-3); min-height: 44px; color: var(--ink); text-decoration: none; border-radius: var(--radius-sm); }
.tf-lang__menu a:hover { background: var(--surface-sunken); }
.tf-lang__menu a[aria-current="true"] { font-weight: 600; background: var(--brand-soft); }
.tf-lang__menu small { color: var(--ink-subtle); font-size: 0.8125rem; }
.tf-lang__note { padding: var(--space-2) var(--space-3) 0; border-top: 1px solid var(--border); margin-top: var(--space-2); font-size: 0.8125rem; line-height: 18px; color: var(--ink-subtle); }

/* Breadcrumbs (Bootstrap .breadcrumb) */
.tf-crumbs .breadcrumb {
    --bs-breadcrumb-divider: "/";
    --bs-breadcrumb-divider-color: var(--ink-subtle);
    --bs-breadcrumb-item-active-color: var(--ink-muted);
    --bs-breadcrumb-margin-bottom: 0;
    --bs-breadcrumb-font-size: 0.875rem;
    font-size: 0.875rem;
    line-height: 20px;
}

.tf-crumbs a { color: var(--ink-muted); text-decoration: none; }
.tf-crumbs a:hover { color: var(--brand-text); text-decoration: underline; }
.tf-crumbs__back { display: none; align-items: center; gap: var(--space-1); font-size: 0.875rem; color: var(--ink-muted); text-decoration: none; min-height: 44px; }

@media (max-width: 767.98px) {
    .tf-crumbs--compact .breadcrumb { display: none; }
    .tf-crumbs--compact .tf-crumbs__back { display: inline-flex; }
}

/* ---------- 5. Controls ---------- */
.btn {
    --bs-btn-padding-x: var(--space-5);
    --bs-btn-padding-y: 0;
    --bs-btn-font-weight: 600;
    --bs-btn-font-size: 1rem;
    --bs-btn-border-radius: var(--radius-sm);
    --bs-btn-focus-box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    line-height: 20px;
    transition: background-color 0.15s;
}

.btn-primary {
    --bs-btn-color: var(--on-brand);
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-color: var(--on-brand);
    --bs-btn-hover-bg: var(--brand-hover);
    --bs-btn-hover-border-color: var(--brand-hover);
    --bs-btn-active-color: var(--on-brand);
    --bs-btn-active-bg: var(--brand-hover);
    --bs-btn-active-border-color: var(--brand-hover);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-disabled-color: var(--on-brand);
}

.btn-secondary {
    --bs-btn-color: var(--ink);
    --bs-btn-bg: var(--surface);
    --bs-btn-border-color: var(--border);
    --bs-btn-hover-color: var(--ink);
    --bs-btn-hover-bg: var(--surface-sunken);
    --bs-btn-hover-border-color: var(--border);
    --bs-btn-active-color: var(--ink);
    --bs-btn-active-bg: var(--surface-sunken);
    --bs-btn-active-border-color: var(--border);
    box-shadow: var(--shadow-control);
}

.btn-link {
    --bs-btn-color: var(--ink-muted);
    --bs-btn-hover-color: var(--ink);
    --bs-btn-padding-x: var(--space-3);
    text-decoration: none;
}

.btn-link:hover { background: var(--surface-sunken); }

.btn-sm {
    --bs-btn-padding-x: var(--space-3);
    --bs-btn-font-size: 0.875rem;
    --bs-btn-border-radius: var(--radius-pill);
    min-height: 36px;
}

/* Form fields: Bootstrap .form-control / .form-select / .input-group restyled by tokens. */
.form-label {
    font-size: 0.9375rem;
    line-height: 20px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: var(--space-2);
}

.form-text {
    font-size: 0.875rem;
    line-height: 20px;
    color: var(--ink-muted);
    margin-top: var(--space-2);
}

.form-control,
.form-select {
    min-height: var(--control-height);
    padding: 0 var(--space-3);
    border: 1px solid var(--border-control);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--ink);
    font-size: 1.125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    box-shadow: none;
}

.form-control::placeholder { color: var(--ink-subtle); font-weight: 400; }

.form-control:focus,
.form-select:focus {
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--focus);
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    box-shadow: none;
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--danger);
    border-width: 2px;
    background-image: none;
    padding-right: var(--space-3);
}

.form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%235e5e63' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    font-size: 1rem;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-mode="light"]) .form-select {
        --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23aeaeb2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    }
}

[data-mode="dark"] .form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23aeaeb2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.invalid-feedback {
    display: flex;
    gap: var(--space-1);
    align-items: flex-start;
    margin-top: var(--space-2);
    font-size: 0.875rem;
    line-height: 20px;
    color: var(--danger);
}

.is-invalid ~ .invalid-feedback,
.tf-field--invalid .invalid-feedback { display: flex; }

.tf-textarea { min-height: 160px; padding: var(--space-3); font-family: var(--font-mono); font-size: 1rem; font-weight: 400; line-height: 24px; resize: vertical; }

.input-group-text {
    padding: 0 var(--space-4);
    border: 1px solid var(--border-control);
    background: var(--surface-sunken);
    color: var(--ink-muted);
    font-size: 0.9375rem;
    font-weight: 500;
}

.input-group > .form-select {
    flex: 0 0 auto;
    width: auto;
    background-color: var(--surface-sunken);
    font-weight: 600;
}

.tf-field { min-width: 0; }

.tf-time {
    display: flex;
    align-items: flex-start;
    gap: var(--space-1);
}

.tf-time__part { display: grid; gap: 2px; justify-items: center; flex: 1; min-width: 0; }
.tf-time__part .form-control { text-align: center; padding-inline: var(--space-1); width: 100%; }
.tf-time__sep { font-size: 1.25rem; font-weight: 600; color: var(--ink-subtle); line-height: var(--control-height); }
.tf-time__unit { font-size: 0.75rem; line-height: 16px; color: var(--ink-subtle); }

.tf-presets { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

.tf-chip {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow-control);
    color: var(--ink);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.tf-chip:hover { border-color: var(--ink-muted); }
.tf-chip[aria-pressed="true"] { border-color: var(--brand); color: var(--on-brand); background: var(--brand); box-shadow: none; }

/* Slider (Bootstrap .form-range) */
.tf-slider__row { display: flex; align-items: center; gap: var(--space-3); }
.tf-slider__value { width: 96px; flex: none; }
.form-range { accent-color: var(--brand); }
.form-range:focus { box-shadow: none; }
.form-range:focus::-webkit-slider-thumb { box-shadow: none; outline: 2px solid var(--focus); outline-offset: 2px; }
.form-range::-webkit-slider-thumb { background-color: var(--brand); }
.form-range::-moz-range-thumb { background-color: var(--brand); }
.tf-slider__scale { display: flex; justify-content: space-between; font-size: 0.8125rem; color: var(--ink-subtle); }

/* Checkbox & radio (Bootstrap .form-check) */
.form-check { display: flex; gap: var(--space-3); align-items: flex-start; min-height: 44px; padding-left: 0; margin: 0; }
.form-check-input { float: none; margin: 2px 0 0; width: 22px; height: 22px; flex: none; border: 1px solid var(--border-control); background-color: var(--surface); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { box-shadow: none; outline: 2px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
.form-check-label { font-size: 1rem; line-height: 24px; }
.form-check-label small { display: block; color: var(--ink-muted); font-size: 0.875rem; line-height: 20px; }
.tf-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.tf-fieldset legend { padding: 0; margin-bottom: var(--space-2); float: none; width: auto; font-size: 0.9375rem; font-weight: 600; }

/* Segmented control: Bootstrap .btn-check radios, restyled as a macOS segmented control. */
.tf-seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
    max-width: 100%;
    overflow-x: auto;
}

.tf-seg--block { display: flex; }
.tf-seg--block .tf-seg__opt { flex: 1; }
.tf-seg__opt { position: relative; display: flex; }
.tf-seg__opt .btn-check { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }

.tf-seg__label {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 var(--space-4);
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--ink-muted);
    white-space: nowrap;
    transition: background-color 0.15s;
}

.btn-check:checked + .tf-seg__label {
    background: var(--surface);
    color: var(--ink);
    font-weight: 600;
    box-shadow: var(--shadow-control);
}

.btn-check:focus-visible + .tf-seg__label { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- 6. Tool panel & result ---------- */
.tf-tool {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-panel);
    overflow: hidden;
    scroll-margin-top: 80px;
}

.tf-tool__mode { padding: var(--space-3) var(--space-4) 0; }
.tf-tool__body { display: grid; grid-template-columns: minmax(0, 1fr); }
.tf-tool__inputs { padding: var(--space-4); display: grid; gap: var(--space-5); align-content: start; }
.tf-tool__grid { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); }
.tf-tool__output { padding: 0 var(--space-3) var(--space-3); }
.tf-tool__summary { margin: 0; }

@media (min-width: 560px) {
    .tf-tool__grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
    .tf-tool__inputs { padding: var(--space-6); }
    .tf-tool__output { padding: 0 var(--space-4) var(--space-4); }
    .tf-tool__mode { padding: var(--space-4) var(--space-6) 0; }
}

@media (min-width: 900px) {
    .tf-tool--split .tf-tool__body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .tf-tool--split .tf-tool__output { padding: var(--space-4) var(--space-4) var(--space-4) 0; }
    .tf-tool--split .tf-result { height: 100%; align-content: start; }
}

@media (max-width: 559.98px) {
    .tf-tool__actions .btn-primary { flex: 1; }
}

.tf-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* Mode-dependent fields: pure CSS, so the form works without JavaScript.
   A field group lists the modes it belongs to in data-modes. The mode switch is a
   Form:Segmented named "mode" (pace calculator) or "strategy" (split calculator); add
   a line here when a new tool names its switch differently. */
.tf-tool:has(input[name="mode"][value="pace"]:checked) [data-modes]:not([data-modes~="pace"]),
.tf-tool:has(input[name="mode"][value="time"]:checked) [data-modes]:not([data-modes~="time"]),
.tf-tool:has(input[name="mode"][value="distance"]:checked) [data-modes]:not([data-modes~="distance"]),
.tf-tool:has(input[name="mode"][value="speed"]:checked) [data-modes]:not([data-modes~="speed"]),
.tf-tool:has(input[name="model"][value="max"]:checked) [data-modes]:not([data-modes~="max"]),
.tf-tool:has(input[name="model"][value="reserve"]:checked) [data-modes]:not([data-modes~="reserve"]),
.tf-tool:has(input[name="strategy"][value="even"]:checked) [data-modes]:not([data-modes~="even"]),
.tf-tool:has(input[name="strategy"][value="negative"]:checked) [data-modes]:not([data-modes~="negative"]) {
    display: none;
}

/* Print: only the title, the result and the table (a printable pace band). */
@media print {
    .tf-header,
    .tf-footer,
    .tf-sidebar,
    .tf-crumbs,
    .tf-ad,
    .tf-lead,
    .tf-tool__mode,
    .tf-tool__inputs,
    .tf-result__tools,
    .tf-result .btn,
    .tf-section,
    .visually-hidden-focusable {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .tf-tool {
        border: 0;
        box-shadow: none;
    }

    .tf-tool__body { display: block; }
    .tf-tool__output { padding: 0; }
    .tf-result { background: none; padding: 0; }
    .tf-table-wrap { overflow: visible; border-color: #999; }
    .tf-table th, .tf-table td { padding: 2px var(--space-3); }
    .tf-table tbody tr { break-inside: avoid; }
}

.tf-result {
    background: var(--brand-soft);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    display: grid;
    gap: var(--space-4);
    scroll-margin-top: 80px;
}

.tf-result:focus { outline: none; }
.tf-result__eyebrow { color: var(--brand-text); }
.tf-result__main { display: grid; gap: var(--space-1); }

.tf-result__value {
    font-family: var(--font-display);
    font-size: 2.75rem;
    line-height: 48px;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    overflow-wrap: anywhere;
    margin: 0;
}

.tf-result__value small { font-size: 1.25rem; font-weight: 500; color: var(--ink-muted); letter-spacing: 0; margin-left: 2px; }
.tf-result__sub { font-size: 0.9375rem; line-height: 22px; color: var(--ink-muted); margin: 0; }
.tf-result__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); margin: 0; }
.tf-result__grid > div { background: var(--surface); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); min-width: 0; }
.tf-result__grid dt { font-size: 0.8125rem; line-height: 18px; color: var(--ink-muted); font-weight: 400; }
.tf-result__grid dd { margin: 2px 0 0; font-size: 1.25rem; line-height: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tf-result__tools { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.tf-result--empty { background: var(--surface-sunken); color: var(--ink-muted); }
.tf-result--empty .tf-result__value { color: var(--ink-subtle); }
.tf-toast { display: inline-flex; align-items: center; gap: var(--space-1); font-size: 0.875rem; color: var(--success); font-weight: 600; background: var(--success-soft); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill); }
.tf-toast[hidden] { display: none; }

@media (max-width: 389.98px) {
    .tf-result__value { font-size: 2.5rem; line-height: 44px; }
}

/* ---------- 7. Content ---------- */
.tf-prose { max-width: var(--measure); }
.tf-prose p, .tf-prose ul, .tf-prose ol { margin: 0 0 var(--space-4); }
.tf-prose li { margin-bottom: var(--space-1); }
.tf-prose h3 { font-family: var(--font-heading); font-size: 1.125rem; line-height: 24px; margin: var(--space-6) 0 var(--space-2); }
.tf-prose code { font-family: var(--font-mono); font-size: 0.875rem; background: var(--surface-sunken); padding: 1px 6px; border-radius: var(--radius-xs); }
.tf-prose pre { background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-4); overflow-x: auto; }
.tf-prose pre code { background: none; padding: 0; }
.tf-prose .tf-scroll { overflow-x: auto; max-width: 100%; width: max-content; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); margin-bottom: var(--space-4); }
.tf-prose table { border-collapse: collapse; font-size: 0.9375rem; line-height: 22px; font-variant-numeric: tabular-nums; margin: 0; }
.tf-prose th, .tf-prose td { padding: var(--space-2) var(--space-4); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tf-prose thead th { background: var(--surface-sunken); font-size: 0.8125rem; line-height: 18px; color: var(--ink-muted); font-weight: 600; }
.tf-prose tr:last-child td { border-bottom: 0; }

.tf-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.tf-table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--border); margin: 0; font-size: 0.9375rem; line-height: 22px; font-variant-numeric: tabular-nums; }
.tf-table caption { text-align: left; padding: var(--space-3) var(--space-4); font-weight: 600; color: var(--ink); border-bottom: 1px solid var(--border); caption-side: top; }
.tf-table th, .tf-table td { padding: var(--space-2) var(--space-4); white-space: nowrap; }
.tf-table thead th { background: var(--surface-sunken); font-size: 0.8125rem; line-height: 18px; color: var(--ink-muted); font-weight: 600; }
.tf-table .tf-r { text-align: right; }
.tf-table tbody tr:last-child > * { border-bottom: 0; }

.tf-toc { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 2px; }
.tf-toc--vertical { flex-direction: column; gap: 2px; }
.tf-toc--vertical a { padding: var(--space-1) var(--space-3); font-size: 0.875rem; color: var(--ink-muted); text-decoration: none; border-radius: var(--radius-sm); }
.tf-toc--vertical a:hover { background: var(--surface-sunken); }

.tf-faq { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0 var(--space-4); }
.tf-faq details + details { border-top: 1px solid var(--border); }
.tf-faq summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-3) 0; font-weight: 600; line-height: 22px; cursor: pointer; }
.tf-faq summary::-webkit-details-marker { display: none; }
.tf-faq summary .tf-icon { transition: transform 0.15s; color: var(--ink-muted); }
.tf-faq details[open] summary .tf-icon { transform: rotate(180deg); }
.tf-faq details p { margin: 0 0 var(--space-4); max-width: var(--measure); }

.tf-trust { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); font-size: 0.875rem; line-height: 20px; color: var(--ink-muted); padding: var(--space-3) var(--space-4); background: var(--surface-sunken); border-radius: var(--radius-md); }
.tf-trust span { display: inline-flex; align-items: center; gap: var(--space-1); }

.tf-formula { background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-4); display: grid; gap: var(--space-3); margin-bottom: var(--space-4); }
.tf-formula__expr { font-family: var(--font-mono); font-size: 1rem; line-height: 26px; overflow-x: auto; white-space: nowrap; margin: 0; }
.tf-formula__expr var { font-style: normal; color: var(--brand-text); font-weight: 600; }
.tf-formula dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-3); font-size: 0.875rem; line-height: 20px; }
.tf-formula dt { font-family: var(--font-mono); color: var(--brand-text); font-weight: 400; }
.tf-formula dd { margin: 0; color: var(--ink-muted); }

/* Alerts (Bootstrap .alert) */
.alert {
    --bs-alert-padding-x: var(--space-4);
    --bs-alert-padding-y: var(--space-4);
    --bs-alert-border-radius: var(--radius-md);
    --bs-alert-margin-bottom: 0;
    display: flex;
    gap: var(--space-3);
    font-size: 0.9375rem;
    line-height: 22px;
    color: var(--ink);
}

.alert p, .alert ul { margin: 0; }
.alert ul { padding-left: var(--space-5); }
.alert strong { display: block; }
.min-w-0 { min-width: 0; }
.alert-info { --bs-alert-bg: var(--info-soft); --bs-alert-border-color: var(--info); --bs-alert-color: var(--ink); }
.alert-info .tf-icon, .alert-info strong { color: var(--info); }
.alert-warning { --bs-alert-bg: var(--warning-soft); --bs-alert-border-color: var(--warning); --bs-alert-color: var(--ink); }
.alert-warning .tf-icon, .alert-warning strong { color: var(--warning); }
.alert-success { --bs-alert-bg: var(--success-soft); --bs-alert-border-color: var(--success); --bs-alert-color: var(--ink); }
.alert-success .tf-icon, .alert-success strong { color: var(--success); }
.alert-danger { --bs-alert-bg: var(--danger-soft); --bs-alert-border-color: var(--danger); --bs-alert-color: var(--ink); }
.alert-danger .tf-icon, .alert-danger strong { color: var(--danger); }

/* ---------- 8. Cards & lists (flat: hairline border, no shadow) ---------- */
.tf-grid-cards { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }

@media (min-width: 640px) {
    .tf-grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
    .tf-grid-cards--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.tf-card {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--ink);
    text-decoration: none;
    min-width: 0;
    transition: border-color 0.15s;
}

.tf-card:hover { border-color: var(--ink-muted); }
.tf-card:hover .tf-card__title { color: var(--brand-text); }

.tf-card__icon {
    width: 40px;
    height: 40px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
}

.tf-card__title { font-weight: 600; line-height: 22px; display: block; }
.tf-card__desc { font-size: 0.875rem; line-height: 20px; color: var(--ink-muted); margin: 2px 0 0; display: block; }
.tf-tag { display: inline-block; font-size: 0.75rem; line-height: 16px; font-weight: 600; padding: 2px var(--space-2); border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand-text); margin-left: var(--space-1); vertical-align: 1px; }

.tf-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.tf-list li { position: relative; }
.tf-list li + li::before { content: ""; position: absolute; top: 0; right: 0; left: 68px; border-top: 1px solid var(--border); }
.tf-list a { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); color: var(--ink); text-decoration: none; min-height: 56px; }
.tf-list a:hover { background: var(--surface-sunken); }
.tf-list .tf-chev { margin-left: auto; color: var(--ink-subtle); }
.tf-links { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.tf-links a { display: block; padding: var(--space-1) 0; font-size: 0.9375rem; line-height: 22px; }

.tf-cat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); display: grid; gap: var(--space-3); align-content: start; }
.tf-cat__head { display: flex; gap: var(--space-3); align-items: center; }
.tf-cat__head a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 1.0625rem; }
.tf-cat__count { margin-left: auto; font-size: 0.8125rem; color: var(--ink-subtle); white-space: nowrap; }
.tf-cat ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.tf-cat li a { font-size: 0.9375rem; line-height: 26px; color: var(--ink-muted); text-decoration: none; }
.tf-cat li a:hover { color: var(--brand-text); text-decoration: underline; }

/* Range bars (Chart:ZoneBars): decoration only, every row states its range in text. */
.tf-zonebars { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.tf-zonebars__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--space-3); align-items: baseline; }
.tf-zonebars__name { font-weight: 600; line-height: 22px; }
.tf-zonebars__range { grid-column: 2; grid-row: 1; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tf-zonebars__desc { grid-column: 1 / -1; font-size: 0.875rem; line-height: 20px; color: var(--ink-muted); }
.tf-zonebars__track { grid-column: 1 / -1; position: relative; height: 12px; margin-top: var(--space-1); border-radius: var(--radius-pill); background: var(--surface-sunken); overflow: hidden; }
.tf-zonebars__fill { position: absolute; top: 0; bottom: 0; border-radius: var(--radius-pill); background: var(--brand); }

/* ---------- 9. Ads & footer ---------- */
.tf-ad {
    background: var(--ad-surface);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    color: var(--ink-subtle);
    font-size: 0.8125rem;
}

.tf-ad::before {
    content: attr(data-label);
    position: absolute;
    top: 8px;
    left: 12px;
    font-size: 0.6875rem;
    line-height: 14px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-subtle);
}

.tf-ad--leader { min-height: 90px; }
.tf-ad--rect { min-height: 250px; }
.tf-ad--sky { min-height: 600px; }
.tf-ad--incontent { min-height: 280px; margin-block: var(--space-8); }
.tf-ad--anchor { position: fixed; inset: auto 0 0; min-height: 60px; border-radius: 0; z-index: var(--z-header); }

.tf-footer {
    margin-top: var(--space-16);
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: var(--space-10) 0 var(--space-6);
    font-size: 0.9375rem;
}

.tf-footer__grid { display: grid; gap: var(--space-6); grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (min-width: 1024px) {
    .tf-footer__grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
}

.tf-footer h2 { font-size: 0.875rem; line-height: 20px; margin: 0 0 var(--space-2); }
.tf-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.tf-footer a { color: var(--ink-muted); text-decoration: none; }
.tf-footer a:hover { color: var(--brand-text); text-decoration: underline; }
.tf-footer__base { margin-top: var(--space-8); padding-top: var(--space-4); border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); justify-content: space-between; color: var(--ink-subtle); font-size: 0.8125rem; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
