/* SQL performance guides (/sql-performance) - page-specific rules ONLY. Shared
   primitives (tokens, headings, buttons, cards, notices) come from tokens.css /
   site.css; tools.css supplies the section, crumb, FAQ and hub-card classes, which
   are overridden here under .perf-page only. Site brand tokens only.

   Layout: every section runs the full viewport width. Guide pages put a sticky
   "On this page" list beside the article; prose keeps a 60ch measure (Inter renders that at ~75-80 characters) while SQL
   blocks may run wider and scroll inside their own box. */

/* ---------- Full-width frame ---------- */
.perf-page .wrap { max-width: none; padding: 0 clamp(16px, 2vw, 32px); }
.perf-page p, .perf-page li { text-wrap: pretty; }
.perf-page h1, .perf-page h2, .perf-page h3 { text-wrap: balance; }
.perf-page :focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ---------- Page head ---------- */
.perf-head .lede { max-width: 60ch; }
.perf-page .tools-intro { max-width: 60ch; }
.perf-covers {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 14px;
    margin: 18px 0 0;
    color: var(--muted);
    font-size: .95rem;
}
.perf-covers > span { font-weight: 600; color: var(--heading); }
.perf-covers a { color: var(--link); font-weight: 600; }
.perf-covers strong { color: var(--ink); font-weight: 600; }

/* Hub: jump links to the two indexes */
.perf-jump { display: flex; flex-wrap: wrap; gap: 10px; margin: 26px 0 0; }
.perf-jump a {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--heading);
    font-weight: 600;
    text-decoration: none;
}
.perf-jump a span { color: var(--muted); font-weight: 400; font-size: .88rem; }
.perf-jump a:hover { border-color: var(--link); text-decoration: none; }

/* ---------- Hub: by engine (columns) ---------- */
.perf-hub-sec { scroll-margin-top: 88px; }
.perf-engines {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 32px clamp(24px, 2.5vw, 40px);
}
.perf-engine { border-top: 1px solid var(--line); padding-top: 18px; min-width: 0; }
.perf-engine h3 { font-size: 1.25rem; margin: 0 0 6px; }
.perf-engine-also { color: var(--muted); font-size: .88rem; margin: 14px 0 8px; }

.perf-index-links { list-style: none; padding: 0; margin: 0; }
.perf-index-links li { padding: 10px 0; border-bottom: 1px solid var(--line); line-height: 1.5; }
.perf-index-links li:last-child { border-bottom: none; }
.perf-index-links a { font-weight: 600; }
.perf-index-links span { display: block; color: var(--muted); font-size: .92rem; margin-top: 4px; max-width: 60ch; }

.perf-chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.perf-chips a {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: .88rem;
    line-height: 1.4;
    color: var(--link);
    background: var(--card);
}
.perf-chips a:hover { border-color: var(--link); text-decoration: none; }

/* ---------- Hub: by symptom (rows) ---------- */
.perf-symptoms { list-style: none; padding: 0; margin: 0; }
.perf-symptom-row {
    display: grid;
    gap: 12px 48px;
    padding: 24px 0;
    border-top: 1px solid var(--line);
}
.perf-symptom-label h3 { font-size: 1.25rem; margin: 0 0 6px; }
.perf-symptom-label p { color: var(--muted); margin: 0; max-width: 52ch; line-height: 1.55; }
.perf-symptom-guides { min-width: 0; }
.perf-symptom-guides .perf-index-links li:first-child { padding-top: 0; }
.perf-symptom-guides .perf-engine-also:first-child { margin-top: 0; }
@media (min-width: 900px) {
    .perf-symptom-row { grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr); }
}

/* ---------- Guide: sidebar + article ---------- */
.perf-layout {
    display: grid;
    gap: 8px;
    padding-top: clamp(28px, 4vw, 48px);
    padding-bottom: clamp(32px, 4vw, 56px);
}
.perf-aside { min-width: 0; }
.perf-article { min-width: 0; }

.perf-toc {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
    padding: 16px 18px;
}
.perf-toc-title {
    margin: 0 0 8px;
    font-weight: 700;
    color: var(--heading);
    font-size: .95rem;
}
.perf-toc ol { list-style: none; padding: 0; margin: 0; }
.perf-toc ol ol { margin: 2px 0 6px 12px; }
.perf-toc a {
    display: block;
    padding: 5px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: .93rem;
    line-height: 1.4;
    text-decoration: none;
}
.perf-toc > ol > li > a { color: var(--ink); font-weight: 600; }
.perf-toc ol ol a { font-size: .87rem; }
.perf-toc a:hover { color: var(--heading); background: var(--blue-soft); }
.perf-toc a[aria-current] { color: var(--heading); }
.perf-toc a[aria-current="location"] { background: var(--blue-soft); color: var(--blue-on-soft); font-weight: 600; }

@media (min-width: 1024px) {
    .perf-layout {
        grid-template-columns: minmax(220px, 270px) minmax(0, 1fr);
        gap: clamp(32px, 4vw, 72px);
        align-items: start;
    }
    .perf-aside { position: sticky; top: 92px; } /* below the 71px sticky site header */
    .perf-toc {
        max-height: calc(100vh - 112px);
        overflow-y: auto;
        overscroll-behavior: contain;
        border: none;
        background: none;
        padding: 0;
    }
    .perf-toc-title { padding: 0 10px; }
    .perf-article { max-width: 1180px; }
}

/* ---------- Guide sections ---------- */
.perf-sec { padding: clamp(32px, 4vw, 48px) 0; border-top: 1px solid var(--line); scroll-margin-top: 88px; }
.perf-sec:first-child { padding-top: 0; border-top: none; }
.perf-sec h2 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 0 0 16px; }
.perf-sec h3 { font-size: 1.2rem; margin: 36px 0 12px; scroll-margin-top: 88px; max-width: 60ch; }
.perf-sec h2 + h3 { margin-top: 8px; }
.perf-sec p, .perf-sec ul, .perf-sec ol { max-width: 60ch; line-height: 1.65; }
.perf-sec p { margin: 0 0 14px; }
.perf-sec a { color: var(--link); }
.perf-article code { font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace; font-size: .88em; }

/* The symptom callout: a tinted panel, hairline all round */
.perf-symptom {
    background: var(--amber-soft);
    color: var(--amber-ink);
    border: 1px solid var(--amber-line);
    border-radius: 14px;
    padding: 18px 22px;
    max-width: calc(60ch + 44px);
}
.perf-symptom p { margin: 0 0 10px; color: inherit; }
.perf-symptom p:last-child { margin-bottom: 0; }
.perf-symptom code { color: inherit; }

/* ---------- SQL blocks ---------- */
.perf-code-wrap { position: relative; margin: 0 0 18px; max-width: 980px; }
.perf-code {
    margin: 0 0 18px;
    max-width: 980px;
    padding: 16px 18px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
    font-size: .85rem;
    line-height: 1.6;
    color: var(--ink);
    font-variant-ligatures: none;
    tab-size: 4;
    white-space: pre;
    overflow-x: auto;
    scrollbar-color: var(--line) transparent;
}
.perf-code-wrap .perf-code { margin: 0; max-width: none; padding-top: 46px; }
.perf-code code { font-family: inherit; font-size: inherit; }
.perf-code:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
@media (min-width: 720px) {
    .perf-code-wrap .perf-code { padding-top: 16px; padding-right: 96px; }
}

.perf-copy {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    font: 600 .8rem/1.3 Inter, system-ui, sans-serif;
    cursor: pointer;
}
.perf-copy:hover { color: var(--heading); border-color: var(--link); }
.perf-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- The ordered checklist ---------- */
.perf-sec .perf-checklist { list-style: none; counter-reset: perf-check; padding: 0; margin: 0; max-width: calc(60ch + 48px); }
.perf-checklist li {
    counter-increment: perf-check;
    position: relative;
    padding: 12px 0 12px 48px;
    border-bottom: 1px solid var(--line);
    line-height: 1.6;
}
.perf-checklist li:last-child { border-bottom: none; }
.perf-checklist li::before {
    content: counter(perf-check);
    position: absolute;
    left: 0;
    top: 13px;
    min-width: 28px;
    text-align: center;
    font-family: "JetBrains Mono", monospace;
    font-size: .8rem;
    font-variant-numeric: tabular-nums;
    color: var(--amber-ink);
    background: var(--amber-soft);
    border: 1px solid var(--amber-line);
    border-radius: 999px;
    padding: 1px 6px;
}

/* ---------- FAQ: two columns once the article is wide enough ---------- */
.perf-faq { max-width: none; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); align-items: start; }
.perf-faq .card p { max-width: 60ch; }

/* ---------- Keep reading + Related on SQLly ---------- */
.perf-more-sec .tools-hub-card h3 { font-size: 1.3rem; margin: 0; }
.perf-page .tools-xref {
    max-width: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    column-gap: 32px;
}
.perf-page .tools-xref li:last-child { border-bottom: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) {
    .perf-page .tools-hub-card, .perf-page .tools-hub-card:hover { transition: none; transform: none; }
}
