/*
 * The design's pieces: those more than one page uses (the title bar,
 * carousel controls, the YouTube frame, .hero-image) and those that live
 * in a partial (the specials popup and its pagination). Some are used on
 * one page today but are pieces all the same: the homepage's panels, and
 * the manufacturer page's card, point sheets and video carousel. PR 17
 * consolidates them.
 */

@layer reset, tokens, base, layout, components, pages, utilities;

@layer components {
    /*
     * Buttons. .btn is the shape and the behaviour; a colour modifier goes
     * with it (never alone). The search buttons (the nav's, the homepage's
     * and the results page's) were three copies of .btn--green.
     */
    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-3) var(--space-5);
        border: 0;
        border-radius: var(--radius-sm);
        font-size: var(--text-base);
        font-weight: bold;
        text-decoration: none;
        cursor: pointer;
        transition: background-color var(--duration-base) ease;
    }

    .btn--green {
        background-color: var(--color-forest-green);
        color: var(--color-white);
    }

    .btn--green:hover {
        background-color: var(--color-secondary);
    }

    /*
     * The nav bar's search (layout.css places the bar; this is its form):
     * the full width of the menu below 1024px, beside the links above.
     * In the menu it comes after the links (the logo hangs over the
     * menu's top left corner), as it does in the DOM, so Tab goes from
     * the toggle to the first link; the bar puts it first (order). Its
     * text is 16px, so a phone does not zoom in on focus.
     */
    .nav-search {
        --nav-search-height: 36px;
        display: flex;
        align-items: center;
        padding: var(--space-3) var(--space-4);
    }

    .nav-search__input {
        height: var(--nav-search-height);
        box-sizing: border-box;
        padding: 0 var(--space-3);
        border: 1px solid transparent;
        border-radius: var(--radius-sm) 0 0 var(--radius-sm);
        background-color: rgba(255, 255, 255, 0.14);
        color: var(--color-white);
        font-size: var(--text-base);
        flex: 1 1 auto;
        min-width: 0;
        transition: width var(--duration-slow) ease, background-color var(--duration-base) ease;
    }

    /* At least 4.79:1 in every state: 5.94 (bar) and 5.62 (menu) at rest,
       5.09 and 4.79 focused, when the field is lighter (0.75 gave 4.08 and
       3.89 there, and 4.48 in the menu at rest). */
    .nav-search__input::placeholder {
        color: rgba(255, 255, 255, 0.9);
    }

    .nav-search__input:focus {
        background-color: rgba(255, 255, 255, 0.2);
        border-color: rgba(255, 255, 255, 0.5);
    }

    /* A .btn .btn--green, as an icon beside the field. */
    .nav-search__button {
        height: var(--nav-search-height);
        box-sizing: border-box;
        padding: 0 0.6rem;
        border: 1px solid transparent;
        border-left: none;
        border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
        display: flex;
        font-size: inherit;
    }

    .nav-search__button svg {
        display: block;
    }

    @media (width >= 1024px) {
        .nav-search {
            order: -1;
            margin-left: auto;
            margin-right: var(--space-4);
            padding: 0;
        }

        .nav-search__input {
            flex: none;
            width: 150px;
            font-size: var(--text-sm);
        }

        .nav-search__input:focus {
            width: 200px;
        }
    }

    .card {
        width: 100%;
        border-radius: var(--radius-lg);
        overflow: hidden;
        min-height: fit-content;
    }

    /* An outlined card: the point sheets, the cross-reference lists and the search results. */
    .card--outlined {
        border: 2px solid var(--color-forest-green);
    }

    .card-title {
        padding: var(--space-2);
        padding-left: var(--space-4);
        font-size: var(--text-md);
    }

    .card-text {
        padding: var(--space-2);
    }

    /* The manufacturer page's "Why buy from" box. */
    .card--callout {
        max-width: 800px;
        border: 2px solid var(--color-accent);
        background-color: var(--navy-50);
    }

    .card-paragraph-block {
        gap: var(--space-1);
        display: flex;
        flex-direction: column;
    }

    .card-paragraph-block a {
        color: inherit;
    }

    .link-list {
        gap: var(--space-1);
    }

    .link-list.line-break {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        flex-direction: column;
    }

    .link-list.three-column {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .link-list a {
        text-decoration: none;
        color: inherit;
    }

    .link-list.line-break a {
        padding-left: var(--space-5);
    }

    .link-section {
        align-self: stretch;
        width: 100%;
        font-size: var(--text-base);
    }

    .hero-image {
        max-height: 250px;
        max-width: 250px;
        /* Maintain aspect ratio */
        width: auto;
        height: auto;
    }

    .h-divider {
        background-color: var(--gray-3);
        height: 1px;
    }

    /* Unified homepage panel system — one navy chassis replaces the old grab-bag of
       inline hex card colors. Variants differ by FUNCTION, not arbitrary color. */
    .panel {
        width: 100%;
        background-color: var(--color-white);
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: var(--shadow-1);
        transition: box-shadow var(--duration-base) ease, transform var(--duration-base) ease;
    }

    .panel:hover {
        box-shadow: var(--shadow-3);
    }

    .panel__bar {
        padding: 0.55rem var(--space-4);
        background-color: var(--color-primary);
        color: var(--color-white);
        line-height: 1.2;
    }

    .panel__eyebrow {
        display: block;
        margin-bottom: 0.05rem;
        font-size: var(--text-2xs);
        font-weight: 600;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        opacity: 0.72;
    }

    .panel__title {
        font-size: var(--text-base);
        font-weight: 700;
    }

    .panel__body {
        padding: var(--space-3) var(--space-4);
        color: var(--navy-900);
    }

    .panel__body p {
        text-align: left;
    }

    /* Product Cross-Reference is the OTHER category system — a green chassis encodes
       that it's a different tool, not another manufacturer grid. */
    .panel--xref .panel__bar {
        background-color: var(--color-forest-green);
    }

    /* Spotlight cards stretch to equal height so the 3-up row's bottoms align,
       regardless of text vs. image vs. video body content. */
    .panel--media {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .panel--media .panel__body {
        flex: 1 1 auto;
    }

    .panel__body .link-section {
        color: var(--color-primary);
        font-weight: 700;
    }

    .panel__body.link-list a {
        transition: color var(--duration-fast) ease;
    }

    .panel__body.link-list a:hover {
        text-decoration: underline;
    }

    .panel__body img,
    .panel__body .youtube-embed-block {
        margin-top: var(--space-2);
        border-radius: var(--radius-md);
    }

    /*
     * Manufacturer link grids: 3 columns crush in a narrow panel, so below
     * 28rem of the panel's own width they drop to 2 (a phone, as before at
     * 480px of viewport, and now a half-width panel on a tablet).
     */
    .panel {
        container: panel / inline-size;
    }

    @container panel (inline-size < 28rem) {
        .panel__body.three-column {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    .point-sheet-stack {
        row-gap: var(--space-2);
        color: var(--color-forest-green);
    }

    /* A .card .card--outlined. */
    .point-sheet {
        padding: var(--space-2);
    }

    .point-sheet a {
        text-decoration: none;
        color: inherit;
    }

    .point-sheet-title {
        font-weight: bold;
    }

    /*
     * The green bar over a page: its <h1>, set as body text (sizes come
     * from classes, not from the heading level).
     */
    .title-bar {
        width: 100%;
        max-width: 600px;
        margin-inline: auto;
        margin-bottom: var(--space-4);
        padding: var(--space-2);
        border-radius: var(--radius-lg);
        background: linear-gradient(0deg, var(--green-800) 0%, var(--green-400) 100%);
        color: var(--color-white);
        font-size: var(--text-base);
        font-weight: normal;
        text-align: center;
        /* As the <p> it was: a heading would balance its lines stably. */
        text-wrap: pretty;
    }

    /*
     * A carousel's previous and next arrows: a glyph on a bare button. On
     * a light background it is the accent with a white outline that keeps
     * it off what it overlaps; on a dark one, white, dimmed until hovered.
     * Each carousel places its own (the banner, the cross-reference).
     */
    .carousel-arrow {
        border: none;
        background: transparent;
        font-size: var(--text-xl);
        cursor: pointer;
        transition: opacity var(--duration-base);
    }

    .carousel-arrow:disabled {
        opacity: 0.35;
        cursor: not-allowed;
    }

    .carousel-arrow--on-light {
        color: var(--color-accent);
        -webkit-text-stroke: 2px var(--color-white);
        paint-order: stroke fill;
    }

    .carousel-arrow--on-dark {
        color: var(--color-white);
        opacity: 0.7;
    }

    .carousel-arrow--on-dark:hover {
        opacity: 1;
    }

    .video-carousel {
        max-width: 500px;
        margin: 0 auto;
    }

    .video-carousel__controls {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-3);
        margin-top: var(--space-2);
    }

    .video-carousel__counter {
        font-size: var(--text-sm);
        color: var(--color-forest-green);
    }

    .video-carousel__title {
        margin-top: var(--space-1);
        font-size: var(--text-sm);
        color: var(--color-forest-green);
        text-align: center;
    }

    .youtube-embed-block {
        width: 100%;
        aspect-ratio: 16/9;
        /* The players' obsolete frameborder="0", as CSS. */
        border: 0;
    }

    .pagination {
        display: flex;
        align-items: center;
        justify-content: space-around;
        gap: var(--space-4);
        margin-top: var(--space-4);
    }

    .pagination > * {
        flex: 1 0;
    }

    .pagination-prev:disabled,
    .pagination-next:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    .pagination-status {
        min-width: 4rem;
        text-align: center;
    }

    /*
     * A dialog: a card fixed in the middle of the viewport, above the page
     * and the logo, scrolling inside itself when taller than 75% of it.
     * Centred by inset and auto margins, which also centre a <dialog>
     * (the SPECIALS popup is one, modal; its ::backdrop is the
     * browser's). Its close control is a bare × (.dialog__close).
     */
    .dialog {
        position: fixed;
        inset: 0;
        z-index: var(--z-dialog);
        width: min(100%, 350px);
        height: fit-content;
        max-height: 75%;
        margin: auto;
        overflow-y: auto;

        padding: var(--space-2);
        border-radius: var(--radius-lg);
        border: 2px solid var(--color-accent);
        box-shadow: var(--shadow-4);

        background-color: var(--color-white);
        color: var(--color-black);
    }

    /* A <dialog> shows only while open, whatever display another class
       (.grid) sets, and as wide as .dialog says: not the browser's
       max-width for a modal one. */
    dialog.dialog:not([open]) {
        display: none;
    }

    dialog.dialog {
        max-width: none;
    }

    /* A <form method="dialog"> around a close button only wraps it, as
       <specials-pager> (scripts/specials.js) wraps the specials: their
       children lay out as the dialog's own. */
    .dialog form[method="dialog"],
    specials-pager {
        display: contents;
    }

    .dialog__close {
        appearance: none;
        margin: 0;
        padding: 0 var(--space-1);
        border: 0;
        background: none;
        /* 4.8:1 on white (#aaa was 2.3:1, under the 3:1 a control needs). */
        color: var(--gray-5);
        font-family: sans-serif;
        font-size: var(--text-2xl);
        font-weight: bold;
        line-height: 1;
        cursor: pointer;
    }

    .dialog__close:hover,
    .dialog__close:focus {
        color: var(--color-black);
    }

    /*
     * A data table: <table class="table">, with a <caption>, <th scope>
     * headers, and .table--numeric for right-aligned figures. Put a wide
     * one in <div class="table-scroll" tabindex="0" role="region"
     * aria-labelledby="…">, naming the <caption> by its id, which scrolls sideways inside itself (and by
     * keyboard, being focusable) instead of making the page scroll; the
     * table keeps display: table, so its semantics survive (display: block
     * on a table drops them in some screen readers). First used by the
     * FAQ and conversions rebuilds (PRs 21, 22).
     */
    .table-scroll {
        max-width: 100%;
        overflow-x: auto;
    }

    .table {
        width: 100%;
        border-collapse: collapse;
        font-size: var(--text-sm);
        color: var(--gray-9);
    }

    .table caption {
        padding-block: var(--space-2);
        font-weight: bold;
        text-align: start;
    }

    .table th,
    .table td {
        padding: var(--space-2) var(--space-3);
        border: 1px solid var(--gray-3);
        text-align: start;
        vertical-align: top;
    }

    .table thead th {
        background-color: var(--gray-1);
    }

    .table tbody tr:nth-child(2n) {
        background-color: var(--gray-0);
    }

    .table--numeric td {
        text-align: end;
        font-variant-numeric: tabular-nums;
    }

    .special-item {
        margin-bottom: var(--space-2);
        padding-bottom: var(--space-2);
    }

    /* A debug run's error detail (errors/error.twig): the trace, left-aligned,
       scrolling sideways inside the centred column. */
    .error-detail {
        text-align: left;
        overflow-x: auto;
    }
}
