/**
 * LNK FAQ Module - front office.
 *
 * Design intent: the module never imposes a look. Every colour and font is
 * inherited from the shop's theme, so the FAQ reads as a native part of any
 * theme it is dropped into. What the module *does* bring is the craft a theme
 * cannot: a considered accordion, precise rhythm, full right-to-left support,
 * keyboard and reduced-motion behaviour.
 *
 * Tune it from the theme with one line, no module edit needed, e.g.:
 *   :root { --lnk-faq-accent: #b8912f; }
 * The LNK base tokens (--lnk-accent, --lnk-border, ...) apply when the module
 * variables are not set, and the 1.x names (--lnkfaq-accent on .lnkfaq) still
 * work. The appearance settings of the module are written inline on the block
 * as the same --lnk-faq-* variables.
 *
 * Everything is scoped under .lnkfaq and uses logical properties, so LTR and
 * RTL are the same code path.
 *
 * @author    LNK
 * @copyright 2026 LNK
 * @license   https://opensource.org/licenses/MIT MIT License
 */

.lnkfaq {
    /* Accent defaults to the theme's own text colour: restrained, never clashes.
       A shop that wants its brand colour sets --lnkfaq-accent and nothing else. */
    --lnkfaq-accent: var(--lnk-faq-accent, var(--lnk-accent, currentColor));

    /* Hairlines and tints are derived from the current text colour, so they are
       correct on a light theme and on a dark one without a second definition.
       Solid fallbacks first, then color-mix() where the browser supports it. */
    --lnkfaq-rule: var(--lnk-faq-border, var(--lnk-border, rgba(128, 128, 128, .28)));
    --lnkfaq-rule-open: var(--lnk-faq-border, var(--lnk-border, rgba(128, 128, 128, .5)));
    --lnkfaq-hover: rgba(128, 128, 128, .08);

    --lnkfaq-measure: 68ch;
    --lnkfaq-ease: cubic-bezier(.4, .01, .2, 1);
    --lnkfaq-dur: .34s;
    --lnkfaq-pad: clamp(.85rem, .55rem + .9vw, 1.25rem);
    --lnkfaq-gap: var(--lnk-faq-gap, clamp(2rem, 1rem + 4vw, 4.5rem));

    /* Secondary text (answers, introductions, search status): the muted colour,
       attenuated IN the colour by the "secondary text strength" setting
       (--lnk-faq-muted-opacity, 0 to 1), never with `opacity`, so the contrast
       measured on the colour is the contrast the visitor gets. 1 by default. */
    --lnkfaq-muted: var(--lnk-faq-muted, var(--lnk-muted, currentColor));

    color: inherit;
}

@supports (color: color-mix(in srgb, currentColor 20%, transparent)) {
    .lnkfaq {
        --lnkfaq-rule: var(--lnk-faq-border, var(--lnk-border, color-mix(in srgb, currentColor 18%, transparent)));
        --lnkfaq-rule-open: var(--lnk-faq-border, var(--lnk-border, color-mix(in srgb, currentColor 34%, transparent)));
        --lnkfaq-hover: color-mix(in srgb, currentColor 5%, transparent);
    }
}

/* ------------------------------------------------------------------ */
/* Shells: editorial two-column, compact single-column                 */
/* ------------------------------------------------------------------ */

.lnkfaq-block {
    margin-block: clamp(2.5rem, 1.5rem + 4vw, 5rem);
}

.lnkfaq-shell {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1.5rem, 1rem + 2vw, 3rem);
}

@media (min-width: 62em) {
    .lnkfaq-shell {
        grid-template-columns: minmax(15rem, 20rem) 1fr;
        gap: var(--lnkfaq-gap);
    }
    /* Grid places the aside on the leading side in both LTR and RTL. */
    .lnkfaq-aside {
        position: sticky;
        top: 2rem;
        align-self: start;
    }
}

.lnkfaq-aside {
    display: flex;
    flex-direction: column;
    gap: .9rem;
    align-items: start;
}

.lnkfaq-eyebrow {
    margin: 0;
    font-size: .72em;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--lnkfaq-accent);
}

.lnkfaq-aside-title {
    margin: 0;
    line-height: 1.12;
    text-wrap: balance;
    color: var(--lnk-faq-title-color, inherit);
}

.lnkfaq-aside-lede {
    margin: 0;
    max-inline-size: 34ch;
    color: var(--lnkfaq-muted);
    line-height: 1.6;
}

.lnkfaq-aside-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin: 0;
    margin-block-start: .25rem;
}

/* Compact placement (product pages): a slim header, then the list. */
.lnkfaq-compact {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.lnkfaq-compact .lnkfaq-eyebrow {
    margin-block-end: -.25rem;
}

/* ------------------------------------------------------------------ */
/* Category groups                                                     */
/* ------------------------------------------------------------------ */

.lnkfaq-groups {
    display: flex;
    flex-direction: column;
    gap: clamp(1.75rem, 1rem + 2vw, 3rem);
    min-inline-size: 0;
}

.lnkfaq-group-title {
    margin: 0 0 .6rem;
    line-height: 1.2;
    color: var(--lnk-faq-title-color, inherit);
}

.lnkfaq-group-intro {
    margin: 0 0 1rem;
    max-inline-size: var(--lnkfaq-measure);
    color: var(--lnkfaq-muted);
}

.lnkfaq-group-intro > *:last-child {
    margin-block-end: 0;
}

/* ------------------------------------------------------------------ */
/* The accordion                                                       */
/* ------------------------------------------------------------------ */

.lnkfaq-list {
    border-block-start: 1px solid var(--lnkfaq-rule);
}

.lnkfaq-item {
    position: relative;
    border-block-end: 1px solid var(--lnkfaq-rule);
}

/* Leading accent bar, revealed when the item opens. On the start side of the line (logical
   property): left in French, right in Arabic, whatever the theme sets (dir or direction). */
.lnkfaq-item::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 2px;
    background: var(--lnkfaq-accent);
    transform: scaleY(0);
    transition: transform var(--lnkfaq-dur) var(--lnkfaq-ease);
    pointer-events: none;
}

.lnkfaq-item[open] {
    border-block-end-color: var(--lnkfaq-rule-open);
}

.lnkfaq-item[open]::before {
    transform: scaleY(1);
}

.lnkfaq-item[hidden] {
    display: none;
}

/* Summary = the clickable question row. */
.lnkfaq-q {
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    padding-block: var(--lnkfaq-pad);
    padding-inline: clamp(.5rem, 1.5vw, 1.25rem) clamp(.5rem, 1.5vw, 1rem);
    cursor: pointer;
    list-style: none;
    font-weight: 600;
    line-height: 1.35;
    color: var(--lnk-faq-title-color, inherit);
    transition: background-color var(--lnkfaq-dur) var(--lnkfaq-ease),
                color var(--lnkfaq-dur) var(--lnkfaq-ease);
}

.lnkfaq-q::-webkit-details-marker { display: none; }
.lnkfaq-q::marker { content: ""; }

.lnkfaq-q:hover {
    background-color: var(--lnkfaq-hover);
}

.lnkfaq-item[open] > .lnkfaq-q {
    color: var(--lnkfaq-accent);
}

.lnkfaq-q:focus-visible {
    outline: 2px solid var(--lnkfaq-accent);
    outline-offset: -2px;
    border-radius: 2px;
}

.lnkfaq-q-text {
    flex: 1 1 auto;
    min-inline-size: 0;
}

/* +/- icon, morphed from two bars. Plus -> minus on open. */
.lnkfaq-ico {
    position: relative;
    flex: 0 0 auto;
    inline-size: .8em;
    block-size: .8em;
    margin-block-start: .28em;
    margin-inline-start: auto;
    color: var(--lnkfaq-accent);
    transition: transform var(--lnkfaq-dur) var(--lnkfaq-ease);
}

.lnkfaq-ico::before,
.lnkfaq-ico::after {
    content: "";
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 0;
    inline-size: 100%;
    block-size: 2px;
    background: currentColor;
    border-radius: 2px;
    transform: translateY(-50%);
    transition: transform var(--lnkfaq-dur) var(--lnkfaq-ease),
                opacity var(--lnkfaq-dur) var(--lnkfaq-ease);
}

.lnkfaq-ico::after {
    transform: translateY(-50%) rotate(90deg);
}

.lnkfaq-item[open] > .lnkfaq-q .lnkfaq-ico {
    transform: rotate(180deg);
}

.lnkfaq-item[open] > .lnkfaq-q .lnkfaq-ico::after {
    transform: translateY(-50%) rotate(90deg) scaleX(0);
    opacity: 0;
}

.lnkfaq-q:hover .lnkfaq-ico {
    transform: scale(1.12);
}

.lnkfaq-item[open] > .lnkfaq-q:hover .lnkfaq-ico {
    transform: rotate(180deg) scale(1.12);
}

/* Answer, revealed on open. Native <details> hides it when closed, so the
   keyframe simply plays each time the item is opened. */
.lnkfaq-a {
    padding-block: 0 calc(var(--lnkfaq-pad) + .1rem);
    padding-inline: clamp(.5rem, 1.5vw, 1.25rem) clamp(.5rem, 1.5vw, 1rem);
    max-inline-size: var(--lnkfaq-measure);
    line-height: 1.7;
    color: var(--lnkfaq-muted);
}

.lnkfaq-a > *:first-child { margin-block-start: 0; }
.lnkfaq-a > *:last-child { margin-block-end: 0; }

.lnkfaq-item[open] > .lnkfaq-a {
    animation: lnkfaq-reveal var(--lnkfaq-dur) var(--lnkfaq-ease) both;
}

@keyframes lnkfaq-reveal {
    from { opacity: 0; transform: translateY(-.4rem); }
    to   { opacity: 1; transform: none; }
}

/* Deep-link arrival highlight (JS adds the class on /faq#lnkfaq-q-N). */
.lnkfaq-flash {
    animation: lnkfaq-flash 1.6s var(--lnkfaq-ease);
}

@keyframes lnkfaq-flash {
    0%, 15% { background-color: var(--lnkfaq-hover); }
    100%    { background-color: transparent; }
}

/* Attenuation in the colour, where color-mix() exists; elsewhere the muted
   colour is used as it is. The eyebrow takes the accent at full strength: a
   merchant's accent is often a light brand colour, and fading it further
   drops it under any readable contrast (measured: #b8912f at 85 % gives 2.45:1
   on white, where lnk_faq printed it at 100 %). */
@supports (color: color-mix(in srgb, currentColor 50%, transparent)) {
    .lnkfaq-aside-lede,
    .lnkfaq-group-intro,
    .lnkfaq-a,
    .lnkfaq-page-lede,
    .lnkfaq-search-status,
    .lnkfaq-search-empty {
        color: color-mix(in srgb, var(--lnkfaq-muted) calc(var(--lnk-faq-muted-opacity, 1) * 100%), transparent);
    }
}

/* Sizes set in the module's appearance settings. A size has no neutral
   fallback (the theme sizes its own headings), so each rule only applies once
   the setting exists: the block then carries the matching class. */
.lnkfaq--title-size .lnkfaq-aside-title,
.lnkfaq--title-size .lnkfaq-group-title { font-size: var(--lnk-faq-title-size); }
.lnkfaq--question-size .lnkfaq-q { font-size: var(--lnk-faq-question-size); }
.lnkfaq--text-size .lnkfaq-a,
.lnkfaq--text-size .lnkfaq-aside-lede { font-size: var(--lnk-faq-text-size); }

/* ------------------------------------------------------------------ */
/* Links (aside actions, "more" row)                                   */
/* ------------------------------------------------------------------ */

.lnkfaq-more {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-block-start: 1.5rem;
}

.lnkfaq-link {
    position: relative;
    text-decoration: none;
    font-weight: 600;
    color: inherit;
    padding-block-end: 2px;
}

.lnkfaq-link::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    inset-block-end: 0;
    block-size: 1px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform var(--lnkfaq-dur) var(--lnkfaq-ease);
}

.lnkfaq-link:hover::after,
.lnkfaq-link:focus-visible::after {
    transform: scaleX(1);
}

.lnkfaq-link--accent { color: var(--lnkfaq-accent); }

.lnkfaq-link:focus-visible {
    outline: 2px solid var(--lnkfaq-accent);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ------------------------------------------------------------------ */
/* /faq page                                                           */
/* ------------------------------------------------------------------ */

.lnkfaq-page-lede {
    max-inline-size: 60ch;
    margin-block: 0 clamp(1.5rem, 1rem + 2vw, 2.5rem);
    color: var(--lnkfaq-muted);
    line-height: 1.6;
}

/* Search */
.lnkfaq-search {
    margin-block-end: clamp(1.75rem, 1rem + 2vw, 2.75rem);
    max-inline-size: 34rem;
}

.lnkfaq-search-field {
    position: relative;
    display: flex;
    align-items: center;
}

.lnkfaq-search-icon {
    position: absolute;
    inset-inline-start: .9rem;
    inline-size: 1.1em;
    block-size: 1.1em;
    opacity: .5;
    pointer-events: none;
}

.lnkfaq-search-input {
    inline-size: 100%;
    padding-block: .8rem;
    padding-inline: 2.7rem 2.6rem;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid var(--lnkfaq-rule-open);
    border-radius: .5rem;
    transition: border-color var(--lnkfaq-dur) var(--lnkfaq-ease),
                box-shadow var(--lnkfaq-dur) var(--lnkfaq-ease);
}

.lnkfaq-search-input::-webkit-search-decoration,
.lnkfaq-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.lnkfaq-search-input:focus {
    outline: none;
    border-color: var(--lnkfaq-accent);
    box-shadow: 0 0 0 3px var(--lnkfaq-hover);
}

.lnkfaq-search-input::placeholder { opacity: .55; }

.lnkfaq-search-clear {
    position: absolute;
    inset-inline-end: .6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 1.7rem;
    block-size: 1.7rem;
    padding: 0;
    font: inherit;
    line-height: 1;
    color: inherit;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    opacity: .6;
    transition: opacity var(--lnkfaq-dur), background-color var(--lnkfaq-dur);
}

.lnkfaq-search-clear:hover { opacity: 1; background-color: var(--lnkfaq-hover); }
.lnkfaq-search-clear:focus-visible { outline: 2px solid var(--lnkfaq-accent); outline-offset: 2px; }
.lnkfaq-search-clear[hidden] { display: none; }

.lnkfaq-search-status {
    margin-block: .7rem 0;
    font-size: .82em;
    letter-spacing: .04em;
    color: var(--lnkfaq-muted);
    font-variant-numeric: tabular-nums;
}

.lnkfaq-search-status[hidden] { display: none; }

.lnkfaq-search-empty {
    margin-block: 1rem 0;
    color: var(--lnkfaq-muted);
}

.lnkfaq-search-empty[hidden] { display: none; }

/* Matched term: a tint of the accent (or the browser highlight) under text that keeps its own
   colour, readable on any theme. currentColor would resolve on the mark itself. */
.lnkfaq-mark {
    background: Mark;
    color: MarkText;
    border-radius: 2px;
    padding-inline: .12em;
}

@supports (color: color-mix(in srgb, red 30%, transparent)) {
    .lnkfaq-mark {
        background: color-mix(in srgb, var(--lnk-faq-accent, var(--lnk-accent, Mark)) 30%, transparent);
        color: inherit;
    }
}

.lnkfaq-category[hidden] { display: none; }

/* ------------------------------------------------------------------ */
/* Footer links block                                                  */
/* ------------------------------------------------------------------ */

.lnkfaq-footer .lnkfaq-footer-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

.lnkfaq-footer .lnkfaq-footer-list a {
    text-decoration: none;
}

/* ------------------------------------------------------------------ */
/* Motion preferences                                                  */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    .lnkfaq *,
    .lnkfaq *::before,
    .lnkfaq *::after {
        transition-duration: .001ms !important;
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
    }
}
