/* SQL function reference (/sql-functions and /sql-functions/{slug}) - page rules
   ONLY. Shared primitives (tokens, headings, buttons, eyebrows, cards, form
   controls) come from tokens.css / site.css; section shapes (.tools-sec,
   .tools-faq, .tools-cta, .fmt-code, .tools-xref) come from tools.css and are
   only re-shaped here under page-scoped classes. Site brand tokens only. */

/* ---------- Full-width frame ---------- */
/* Both pages break out of the 1140px .wrap; long prose keeps its own measure below. */
.fn-wide { max-width: none; padding: 0 clamp(16px, 2vw, 32px); }
.fn-head .lede { max-width: 60ch; text-wrap: pretty; }
.fn-hub ::selection,
.fn-body ::selection { background: var(--blue-soft); color: var(--heading); }

/* ---------- Side rail (hub filters, detail outline) ---------- */
.fn-label {
    display: block; margin: 0 0 8px;
    font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted);
}
.fn-field { margin: 0 0 22px; }
.fn-search, .fn-engine { width: 100%; }
.fn-search::placeholder { color: var(--muted); opacity: 1; }
.fn-hint { margin: 8px 0 0; font-size: .82rem; line-height: 1.5; color: var(--muted); }
.fn-hint kbd {
    font-family: "JetBrains Mono", monospace; font-size: .76rem;
    padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--card); color: var(--heading);
}

/* Category buttons: a scrolling pill row on narrow screens, a vertical list in the rail. */
.fn-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px; scrollbar-width: thin; }
.fn-chip {
    display: inline-flex; align-items: center; justify-content: space-between; gap: 10px;
    flex: 0 0 auto; min-height: 44px; padding: 8px 16px;
    font-family: inherit; font-size: .92rem; color: var(--ink); text-align: left;
    background: var(--card); border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.fn-chip:hover { border-color: var(--blue-bright); }
.fn-chip.is-active { color: var(--blue-on-soft); background: var(--blue-soft); border-color: var(--blue-bright); font-weight: 600; }
.fn-chip-n { font-size: .8rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.fn-chip.is-active .fn-chip-n { color: inherit; }
.fn-chip.is-empty { opacity: .6; }

.fn-count { margin: 0 0 22px; font-size: .92rem; font-weight: 600; color: var(--heading); font-variant-numeric: tabular-nums; }

/* ---------- Support marks: shape AND colour, never colour alone ---------- */
.fn-dot {
    display: inline-block; flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%;
    vertical-align: middle;
}
.fn-dot-yes { background: var(--green); }
.fn-dot-partial { background: linear-gradient(90deg, var(--amber-dot) 50%, transparent 50%); box-shadow: inset 0 0 0 1.5px var(--amber-dot); }
.fn-dot-no { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }

.fn-legend { padding-top: 18px; border-top: 1px solid var(--line); }
.fn-legend-order { margin: 0 0 10px; font-size: .84rem; line-height: 1.5; color: var(--muted); text-wrap: balance; }
.fn-legend ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: .88rem; color: var(--ink); }
.fn-legend li { display: flex; align-items: center; gap: 10px; }

/* ---------- Hub layout ---------- */
.fn-hub-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; }
.fn-rail { min-width: 0; }

@media (min-width: 1000px) {
    .fn-hub-layout { grid-template-columns: 272px minmax(0, 1fr); gap: clamp(32px, 3vw, 56px); align-items: start; }
    .fn-hub .fn-rail {
        position: sticky; top: 94px; max-height: calc(100vh - 110px); overflow-y: auto;
        overscroll-behavior: contain; padding-right: 4px; scrollbar-width: thin;
    }
    .fn-hub .fn-chips { flex-direction: column; gap: 2px; overflow: visible; padding: 0; margin: 0; }
    .fn-hub .fn-chip { width: 100%; min-height: 38px; padding: 7px 12px; border-color: transparent; background: transparent; }
    .fn-hub .fn-chip:hover { background: var(--blue-soft); border-color: transparent; }
    .fn-hub .fn-chip.is-active { border-color: var(--blue-bright); }
}

/* ---------- Hub: groups and cards ---------- */
.fn-group { padding: 0; margin: 0 0 clamp(40px, 4vw, 56px); scroll-margin-top: 90px; }
.fn-group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 0 0 4px; }
.fn-group-head h2 { font-size: clamp(1.4rem, 2.4vw, 1.75rem); margin: 0; }
.fn-group-n { font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.fn-group-blurb { color: var(--muted); margin: 0 0 16px; max-width: 72ch; text-wrap: pretty; }
.fn-grid {
    list-style: none; padding: 0; margin: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 10px;
}
.fn-card {
    display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none;
    transition: border-color .15s ease;
}
.fn-card:hover { border-color: var(--blue-bright); text-decoration: none; }
.fn-card:hover h3 code { color: var(--link); }
.fn-card h3 { margin: 0; font-size: 1rem; line-height: 1.35; color: var(--heading); text-wrap: balance; overflow-wrap: anywhere; }
.fn-card h3 code { font-size: .95rem; font-weight: 600; }
.fn-ret { font-family: "JetBrains Mono", monospace; font-size: .76rem; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; }
.fn-dots { display: flex; gap: 5px; margin-top: auto; padding-top: 4px; }

.fn-empty { padding: 28px; border: 1px dashed var(--line); border-radius: 12px; max-width: 72ch; }
.fn-empty p { margin: 0 0 10px; color: var(--muted); }
.fn-empty p:first-child { color: var(--heading); font-weight: 600; font-size: 1.05rem; }
.fn-empty .btn { margin-top: 6px; }

/* ---------- FAQ (both pages): a multi-column grid with a readable measure per card ---------- */
.fn-faq { max-width: none; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); }
.fn-faq .card { padding: 24px; }
.fn-faq .card h3 { text-wrap: balance; }
.fn-faq .card p { max-width: 62ch; text-wrap: pretty; }

/* ---------- Detail page: head ---------- */
.fn-facts { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 22px 0 0; }
.fn-facts div { display: flex; flex-direction: column; gap: 2px; }
.fn-facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fn-facts dd { margin: 0; color: var(--heading); }

/* ---------- Detail page: layout ---------- */
.fn-detail-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; }
.fn-main { min-width: 0; }
.fn-toc ol { list-style: none; padding: 0; margin: 0; display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.fn-toc a {
    display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px; white-space: nowrap;
    font-size: .92rem; color: var(--ink); text-decoration: none;
    background: var(--card); border: 1px solid var(--line); border-radius: 999px;
}
.fn-toc a:hover { border-color: var(--blue-bright); }
.fn-toc a.is-current { color: var(--blue-on-soft); background: var(--blue-soft); border-color: var(--blue-bright); font-weight: 600; }
/* The at-a-glance list repeats the support table, so narrow screens skip it. */
.fn-glance { display: none; }

@media (min-width: 1100px) {
    .fn-detail-layout { grid-template-columns: 232px minmax(0, 1fr); gap: clamp(32px, 3vw, 64px); align-items: start; }
    .fn-outline { position: sticky; top: 94px; max-height: calc(100vh - 110px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .fn-toc ol { flex-direction: column; gap: 2px; overflow: visible; padding: 0; }
    .fn-toc a { display: flex; min-height: 36px; padding: 6px 12px; border-color: transparent; background: transparent; white-space: normal; }
    .fn-toc a:hover { background: var(--blue-soft); border-color: transparent; }
    .fn-toc a.is-current { border-color: var(--blue-bright); }
    .fn-glance { display: block; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
    .fn-glance ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
    .fn-glance li { display: grid; grid-template-columns: 11px minmax(0, 1fr); column-gap: 10px; align-items: center; font-size: .88rem; }
    .fn-glance-engine { font-weight: 600; color: var(--heading); }
    .fn-glance-status { grid-column: 2; font-size: .8rem; color: var(--muted); }
}

/* ---------- Detail page: sections ---------- */
.fn-sec { padding: 0; scroll-margin-top: 90px; }
.fn-sec + .fn-sec { margin-top: clamp(48px, 5vw, 72px); }
.fn-sec > h2 { margin: 0 0 16px; }
.fn-note { margin: 10px 0 0; font-size: .9rem; color: var(--muted); max-width: 72ch; text-wrap: pretty; }

/* Copyable code: the script wraps each [data-copy] block and adds the button. */
.fn-code { position: relative; min-width: 0; }
.fn-code .fmt-code { padding-right: 88px; white-space: pre; word-break: normal; overflow-x: auto; }
.fn-copy {
    position: absolute; top: 8px; right: 8px; min-height: 32px; padding: 5px 12px;
    font-family: inherit; font-size: .78rem; font-weight: 600; color: var(--muted);
    background: var(--card); border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}
.fn-copy:hover { color: var(--heading); border-color: var(--blue-bright); }
.fn-copy.is-done { color: var(--green); border-color: var(--green); }
.fn-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.fn-syntax-forms { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; max-width: 120ch; }
.fn-syntax { padding: 14px 18px; margin: 0; font-size: .9rem; }

.fn-table-wrap { overflow-x: auto; max-width: 1100px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.fn-support { width: 100%; min-width: 520px; border-collapse: collapse; }
.fn-support th, .fn-support td { padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.fn-support tbody tr:last-child > * { border-bottom: none; }
.fn-support thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fn-support tbody th { font-weight: 600; color: var(--heading); white-space: nowrap; }
.fn-support td { color: var(--ink); }
.fn-support td:last-child { max-width: 64ch; color: var(--muted); }
.fn-support td .fn-dot { margin: -2px 8px 0 0; }
.fn-support .fn-yes { color: var(--green); font-weight: 600; white-space: nowrap; }
.fn-support .fn-partial { color: var(--amber-ink); font-weight: 600; }
.fn-support .fn-no { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* Per-engine examples sit side by side so the dialects compare at a glance. */
.fn-examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 18px; }
.fn-examples.is-single { grid-template-columns: minmax(0, 1fr); max-width: 120ch; }
.fn-ex { min-width: 0; display: flex; flex-direction: column; }
.fn-ex-label {
    margin: 0 0 8px; font-family: "JetBrains Mono", monospace; font-size: .8rem; font-weight: 600;
    letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.fn-ex .fn-code { flex: 1 1 auto; display: flex; }
.fn-ex .fn-code .fmt-code { flex: 1 1 auto; min-width: 0; }
.fn-example { padding: 14px 18px; margin: 0; }

.fn-points { max-width: 60ch; }
.fn-points li { text-wrap: pretty; }

.fn-links {
    list-style: none; padding: 0; margin: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); column-gap: 32px;
}
.fn-links li { border-bottom: 1px solid var(--line); }
.fn-links a { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; min-height: 44px; text-decoration: none; }
.fn-links a:hover code { color: var(--link); }
.fn-links code { font-weight: 600; color: var(--heading); }
.fn-links span { color: var(--muted); font-size: .94rem; }

.fn-pager { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; margin: clamp(40px, 4vw, 56px) 0 0; max-width: 900px; }
.fn-pager a {
    display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; text-decoration: none;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    transition: border-color .15s ease;
}
.fn-pager a:hover { border-color: var(--blue-bright); }
.fn-pager-next { text-align: right; grid-column: -2 / -1; }
.fn-pager-dir { font-size: .82rem; color: var(--muted); }
.fn-pager code { font-weight: 600; color: var(--heading); overflow-wrap: anywhere; }
.fn-after { margin: 28px 0 0; max-width: 72ch; }

/* "Related on SQLly" (shared partial) widened under this page's wrapper only. */
.fn-xref .wrap { max-width: none; padding: 0 clamp(16px, 2vw, 32px); }
.fn-xref .tools-xref { max-width: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); column-gap: 32px; }
.fn-xref .tools-xref li:last-child { border-bottom: 1px solid var(--line); }
.fn-xref .tools-xref-also { text-wrap: pretty; }

@media (prefers-reduced-motion: reduce) {
    .fn-chip, .fn-card, .fn-copy, .fn-pager a { transition: none; }
}
