/* ============================================================
   /aitemp: Qubibyte AI as a whole (the next /ai). Loaded after
   /css/ai.css and only adds what that page did not need: the models
   table, the "preview" pill, the Built with Llama mark, the version
   history table and the API modes table. Same tokens, same look.
   ============================================================ */

/* A quieter pill for "Preview": outlined instead of filled. */
.pp-pill--line {
    background: transparent;
    color: var(--pp-ink-2);
    box-shadow: inset 0 0 0 1px var(--pp-rule-strong);
}

/* ── Models table ─────────────────────────────────────────────────────── */

.at-models {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
    border-top: 1px solid var(--pp-rule-strong);
}

.at-models th,
.at-models td {
    padding: 22px 16px;
    border-bottom: 1px solid var(--pp-rule);
    text-align: left;
    vertical-align: top;
    color: var(--pp-ink-2);
    line-height: 1.55;
}

.at-models th:first-child,
.at-models td:first-child {
    padding-left: 0;
}

.at-models td:last-child,
.at-models th:last-child {
    padding-right: 0;
}

.at-models thead th {
    padding-top: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--pp-rule-strong);
    font-family: var(--pp-mono);
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--pp-muted);
}

.at-models tbody th {
    width: 28%;
    font-weight: 400;
}

.at-models .pp-model-name {
    display: block;
    white-space: nowrap;
}

.at-models .at-sub {
    display: block;
    margin-top: 6px;
    font-family: var(--pp-mono);
    font-size: 0.74rem;
    color: var(--pp-muted);
}

.at-models .at-date {
    width: 110px;
    font-family: var(--pp-mono);
    font-size: 0.8rem;
    color: var(--pp-muted);
    text-align: right;
    white-space: nowrap;
}

.at-models .at-who {
    width: 150px;
    font-size: 0.86rem;
}

/* ── Built with Llama ─────────────────────────────────────────────────── */

.at-llama {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 30px;
    padding: 9px 16px 9px 12px;
    border: 1px solid var(--pp-ink);
    border-radius: 999px;
    color: var(--pp-ink);
    font-family: var(--pp-mono);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.at-llama::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pp-accent);
}

.at-llama--sm {
    margin: 10px 0 0;
    padding: 3px 9px 3px 7px;
    gap: 6px;
    font-size: 0.64rem;
    border-color: var(--pp-rule-strong);
}

.at-llama--sm::before {
    width: 6px;
    height: 6px;
}

.at-fine {
    margin: 30px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--pp-rule);
    max-width: 46rem;
    font-size: 0.84rem;
    line-height: 1.6;
    color: var(--pp-muted);
}

.at-fine a,
.pp-note a,
.pp-para a {
    text-decoration: underline;
    text-decoration-color: var(--pp-rule-strong);
    text-underline-offset: 3px;
}

.at-fine a:hover,
.pp-note a:hover,
.pp-para a:hover {
    text-decoration-color: var(--pp-ink);
}

/* Fermi's figures: label left, figure right, hairline rows. */
.at-facts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0 0 36px;
    border-top: 1px solid var(--pp-rule-strong);
    border-bottom: 1px solid var(--pp-rule);
}

.at-facts > div {
    padding: 20px 20px 22px 0;
}

.at-facts > div + div {
    padding-left: 22px;
    border-left: 1px solid var(--pp-rule);
}

.at-facts dt {
    margin-bottom: 10px;
    font-family: var(--pp-mono);
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--pp-muted);
}

.at-facts dd {
    margin: 0;
    font-family: var(--pp-serif);
    font-size: 2.2rem;
    line-height: 1;
    color: var(--pp-ink);
}

.at-facts dd small {
    display: block;
    margin-top: 8px;
    font-family: var(--pp-sans);
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--pp-muted);
}

/* ── Spec tables: 2.0 vs 2.1, versions, API modes ─────────────────────── */

.at-spec2 tbody th {
    width: 30%;
}

.at-spec2 td {
    line-height: 1.55;
}

.pp-spec thead th.is-hl,
.pp-spec td.is-hl {
    background: var(--pp-tint);
}

.at-pending {
    font-family: var(--pp-serif);
    font-style: italic;
    color: var(--pp-muted) !important;
}

.at-h3 {
    margin: 48px 0 18px !important;
    font-family: var(--pp-serif) !important;
    font-size: 1.35rem !important;
    font-weight: 400 !important;
}

.at-h3:first-child {
    margin-top: 0 !important;
}

.at-modes td code {
    white-space: nowrap;
}

.at-modes td {
    line-height: 1.9;
}

.pp-code + .pp-note {
    margin-top: 18px;
}

.at-code {
    margin-top: 28px;
}

/* ── Narrow ───────────────────────────────────────────────────────────── */

@media (max-width: 980px) {
    .at-models .at-who {
        width: 120px;
    }
}

@media (max-width: 640px) {
    .at-models,
    .at-models thead,
    .at-models tbody,
    .at-models tr,
    .at-models th,
    .at-models td {
        display: block;
    }
    .at-models thead {
        display: none;
    }
    .at-models tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 12px;
        padding: 20px 0;
        border-bottom: 1px solid var(--pp-rule);
    }
    .at-models th,
    .at-models td {
        padding: 0;
        border: 0;
        width: auto !important;
    }
    .at-models tbody th {
        grid-column: 1;
        grid-row: 1;
    }
    .at-models .at-date {
        grid-column: 2;
        grid-row: 1;
        padding-top: 8px;
    }
    .at-models .at-what {
        grid-column: 1 / -1;
    }
    .at-models .at-who {
        grid-column: 1 / -1;
        font-family: var(--pp-mono);
        font-size: 0.74rem;
        color: var(--pp-muted);
    }
    .at-facts {
        grid-template-columns: 1fr;
    }
    .at-facts > div + div {
        padding-left: 0;
        border-left: 0;
        border-top: 1px solid var(--pp-rule);
    }
    .at-facts dd {
        font-size: 2rem;
    }
    .at-spec2 {
        min-width: 520px !important;
    }
    .pp-code {
        font-size: 0.76rem;
        padding: 18px 16px;
    }
}

/* The API column holds a table; let the grid column shrink so it scrolls in its own box. */
.pp-avail > div {
    min-width: 0;
}

@media (max-width: 640px) {
    .pp-spec.at-modes {
        min-width: 0;
    }
}

/* "Preview" sits on its own line under who can use it. */
.at-models .at-who .pp-pill {
    display: inline-block;
    top: 0;
    margin: 6px 0 0;
}

.at-spec2 td.pp-num {
    white-space: nowrap;
}

@media (max-width: 640px) {
    .at-models .at-who .pp-pill {
        margin: 0 0 0 8px;
    }
}

.at-models thead th.at-date {
    font-size: 0.7rem;
}

/* QubiBench v3: model slots not run yet keep their column, dimmed. */
.pp-bench .at-notrun { color: var(--pp-muted); }
.pp-bench th.at-notrun .pp-bench-model,
.pp-bench th.at-notrun .pp-bench-effort { opacity: 0.6; }
.pp-bench .at-notrun-row td { font-family: var(--pp-mono); font-size: 0.78rem; }
.pp-bench .at-notrun-row td.at-notrun { font-style: italic; }

/* ── Sections: the heading above, the content centered at full width ─── */

.pp-page .pp-sec {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
}

/* ── Models: older models step back ───────────────────────────────────── */

.at-models tr.at-older > * {
    opacity: 0.55;
    transition: opacity 0.15s;
}

.at-models tr.at-older:hover > * {
    opacity: 1;
}

/* Only the newest models until "Older Models" is clicked (aitemp.js). The
   html.ai-js class is set in <head> before the first paint, so the older rows
   are never drawn and then hidden; without scripts they simply show, and the
   button (which could do nothing) stays out. */
.ai-js .at-models:not(.is-older-open) .at-older-body {
    display: none;
}

.at-older-btn {
    display: none;
}

.ai-js .at-older-btn {
    all: unset;
    display: inline-block;
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--pp-ink-2);
    text-decoration: underline;
    text-decoration-color: var(--pp-rule-strong);
    text-underline-offset: 3px;
    cursor: pointer;
}

.ai-js .at-older-btn:hover {
    color: var(--pp-ink);
    text-decoration-color: var(--pp-ink);
}

.ai-js .at-older-btn:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ── Results tables: one header per model family, a faint tint each ──── */

/* Plain table banding: every other family a faint neutral band. */
.pp-bench .at-f-21,
.pp-tasktable .at-f-21,
.pp-bench .at-f-20,
.pp-tasktable .at-f-20 {
    background: color-mix(in oklab, var(--pp-ink) 1.8%, transparent);
}

.pp-bench .at-fs,
.pp-tasktable .at-fs {
    border-left: 1px solid var(--pp-rule-strong);
}

.pp-bench thead .at-fam,
.pp-tasktable thead .at-fam {
    text-align: center !important;
    padding-top: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--pp-rule);
}

.pp-tasktable thead .at-fam {
    font-weight: 600;
    color: var(--pp-ink);
}

.pp-bench thead tr.at-efforts th {
    padding-top: 8px;
}

.pp-tasktable thead tr.at-efforts th {
    font-weight: 400;
    color: var(--pp-muted);
}

/* Rows that open: the name is a button with a chevron; its rows start hidden. */
.at-tog {
    all: unset;
    display: block;
    cursor: pointer;
}

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

.at-tog .pp-bench-name::after,
.is-group .at-tog::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 0 3px 10px;
    border-right: 1.5px solid var(--pp-muted);
    border-bottom: 1.5px solid var(--pp-muted);
    transform: rotate(-45deg);
    transition: transform 0.15s;
}

.at-tog[aria-expanded="true"] .pp-bench-name::after,
.is-group .at-tog[aria-expanded="true"]::after {
    transform: rotate(45deg);
}

.at-tog:hover .pp-bench-name {
    text-decoration: underline;
    text-decoration-color: var(--pp-rule-strong);
    text-underline-offset: 3px;
}

/* ── Earlier QubiBench versions: closed until opened ──────────────────── */

.at-old {
    margin-top: 40px;
    padding-top: 18px;
    border-top: 1px solid var(--pp-rule);
}

.at-old > summary {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    list-style: none;
}

.at-old > summary::-webkit-details-marker {
    display: none;
}

.at-old > summary .at-h3 {
    display: inline;
    margin: 0 !important;
}

.at-old > summary::after {
    content: '';
    width: 7px;
    height: 7px;
    margin-bottom: 3px;
    border-right: 1.5px solid var(--pp-muted);
    border-bottom: 1.5px solid var(--pp-muted);
    transform: rotate(-45deg);
    transition: transform 0.15s;
}

.at-old[open] > summary::after {
    transform: rotate(45deg);
}

.at-old[open] > summary {
    margin-bottom: 18px;
}

.at-old > summary:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 4px;
}

/* The first effort heading is not the table's first column. */
.pp-bench thead tr.at-efforts th:first-child {
    padding-left: 16px;
    text-align: right;
}

.pp-tasktable thead .at-fam {
    white-space: nowrap;
}

.pp-tasktable thead tr.at-efforts th {
    text-align: center;
    white-space: nowrap;
}

/* ── "Learn more" / "Close" / "See more": underlined text buttons ────── */

.at-more-btn,
.at-more-close {
    all: unset;
    display: inline-block;
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--pp-ink-2);
    text-decoration: underline;
    text-decoration-color: var(--pp-rule-strong);
    text-underline-offset: 3px;
    cursor: pointer;
}

.at-more-btn:hover,
.at-more-close:hover {
    color: var(--pp-ink);
    text-decoration-color: var(--pp-ink);
}

.at-more-btn:focus-visible,
.at-more-close:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 3px;
    border-radius: 2px;
}

.at-more > .pp-note:first-child {
    margin-top: 18px;
}

/* Author display rules above would otherwise override [hidden]. */
.pp-timeline li[hidden],
.at-more[hidden],
.at-more-btn[hidden] {
    display: none;
}

/* Numbers never break across lines. */
.pp-bench td {
    white-space: nowrap;
}

.pp-bench tr.at-params td small {
    display: block;
    margin-top: 2px;
    font-size: 0.74rem;
    color: var(--pp-muted);
}

/* A value shared by a whole family (Fermi Cloud and Local) sits centred across its columns. */
.pp-bench td.at-merge {
    text-align: center;
}

/* Model names may wrap; numbers elsewhere do not. */
.pp-bench tr.at-main td {
    white-space: normal;
    font-size: 0.82rem;
    line-height: 1.35;
}

/* Effort labels sit centred over their columns. */
.pp-bench thead tr.at-efforts th,
.pp-bench thead tr.at-efforts th:first-child {
    text-align: center;
    padding-left: 10px;
    padding-right: 10px;
}

/* A family heading over both header rows (Pauli 1.0) lines up with the other family names. */
.pp-bench thead th.at-fam[rowspan] {
    vertical-align: top;
    border-bottom: 1px solid var(--pp-rule-strong);
}

/* ── Sticky column headings (aitemp.js adds .at-fits where a table fits) ── */

.pp-bench,
.pp-tasktable {
    --at-band: color-mix(in oklab, var(--pp-ink) 1.8%, transparent);
}

.pp-scroll.at-fits {
    overflow: visible;
}

/* Opaque, so rows scroll under them; the band is laid over the page colour.
   Collapsed table borders do not travel with a stuck cell, so its lines are drawn as shadows. */
.pp-scroll.at-fits > table > thead th {
    position: sticky;
    top: var(--at-sticky-top, 68px);
    z-index: 3;
    background-color: var(--pp-paper);
    box-shadow: inset 0 -1px 0 var(--pp-rule-strong);
}

.pp-scroll.at-fits > table > thead tr + tr th {
    top: calc(var(--at-sticky-top, 68px) + var(--at-head1, 41px));
}

.pp-scroll.at-fits > table > thead th.at-f-21,
.pp-scroll.at-fits > table > thead th.at-f-20 {
    background-image: linear-gradient(var(--at-band), var(--at-band));
}

.pp-scroll.at-fits > table > thead th.at-fam:not([rowspan]) {
    box-shadow: inset 0 -1px 0 var(--pp-rule);
}

.pp-scroll.at-fits > table > thead th.at-fs {
    box-shadow: inset 1px 0 0 var(--pp-rule-strong), inset 0 -1px 0 var(--pp-rule-strong);
}

.pp-scroll.at-fits > table > thead th.at-fs.at-fam:not([rowspan]) {
    box-shadow: inset 1px 0 0 var(--pp-rule-strong), inset 0 -1px 0 var(--pp-rule);
}

/* The second row overlaps the first by under a pixel (aitemp.js), so the line under the model
   names is drawn along the second row's top. */
.pp-scroll.at-fits > table > thead tr + tr th {
    box-shadow: inset 0 1px 0 var(--pp-rule), inset 0 -1px 0 var(--pp-rule-strong);
}

.pp-scroll.at-fits > table > thead tr + tr th.at-fs {
    box-shadow: inset 1px 0 0 var(--pp-rule-strong), inset 0 1px 0 var(--pp-rule), inset 0 -1px 0 var(--pp-rule-strong);
}

/* While sticky, the shadows above are the lines; the real borders would double them.
   No width at all, not a transparent colour: with collapsed borders, a transparent border's strip
   belongs to no cell's background, so the rows scrolling underneath showed through it. */
.pp-scroll.at-fits > table > thead th {
    border-top-width: 0;
    border-bottom-width: 0;
}

.pp-scroll.at-fits > table > thead th.at-fs {
    border-left-color: transparent;
}

/* Main models: the model behind each effort, one short line each, small enough that a
   three-effort row is no taller than the name and description beside it. */
.at-models td.at-main-models,
.at-models th.at-main-models {
    width: 210px;
    white-space: nowrap;
}

.at-models .at-mm {
    display: block;
    font-family: var(--pp-mono);
    font-size: 0.76rem;
    line-height: 1.55;
    color: var(--pp-ink-2);
}

.at-models .at-mm-e {
    display: inline-block;
    width: 4.6em;
    color: var(--pp-muted);
}

/* Room for the description, so a three-effort row stays as tall as the others. */
.at-models tbody th {
    width: 22%;
}

/* Tighter: the description gets the width it needs for two lines. */
.at-models tbody th {
    width: 17%;
}

.at-models td.at-main-models,
.at-models th.at-main-models {
    width: 200px;
}

.at-models .at-mm-e {
    width: 3.9em;
}

/* Effort and model as two tidy columns with a gap. */
.at-models .at-mm {
    display: grid;
    grid-template-columns: 3.9em auto;
    column-gap: 7px;
}

.at-models .at-mm-e {
    width: auto;
}

.at-models tbody th {
    width: 16%;
}

.at-models td.at-main-models,
.at-models th.at-main-models {
    width: 214px;
}

/* Every data column is at least as wide as its widest value, open or closed, so opening a
   group of rows never re-balances the columns (Fermi Local grew for "12.1 s"). */
.pp-bench thead tr.at-efforts th,
.pp-bench thead th.at-fam[rowspan] {
    min-width: 88px;
}

/* v2 and v1 have four wide data columns; fixed equal shares keep them steady as rows open. */
.at-old:not(.at-old--wide) .pp-bench thead tr.at-efforts th,
.at-old:not(.at-old--wide) .pp-bench thead th.at-fam[rowspan] {
    width: 17%;
}

/* QubiBench v4: Pauli 2.1, Fermi 1.1, Fermi 1.0. The bands alternate, so Fermi 1.0 is banded here. */
.pp-bench.at-v4 .at-f-fe,
.pp-tasktable.at-v4 .at-f-fe {
    background: color-mix(in oklab, var(--pp-ink) 1.8%, transparent);
}

/* The band above is see-through; a stuck header cell must stay opaque (the page colour under the band). */
.pp-scroll.at-fits > table.at-v4 > thead th.at-f-fe {
    background-color: var(--pp-paper);
    background-image: linear-gradient(var(--at-band), var(--at-band));
}

/* ── Distribution graphs (bench-dist.js) ─────────────────────────────── */

/* A row that opens and has a graph: its toggle holds the name, and its ::before covers the
   whole heading cell so the description still opens the row; the graph button sits above it. */
.pp-bench th.at-has-dist {
    position: relative;
}

.pp-bench th.at-has-dist > .at-tog::before {
    content: '';
    position: absolute;
    inset: 0;
}

/* The description's last word and the graph button stay on one line. */
.at-nobr {
    white-space: nowrap;
}

.at-dist {
    all: unset;
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin: -3px 0 -3px -1px;
    vertical-align: -4px;
    border-radius: 4px;
    color: var(--pp-muted);
    cursor: pointer;
}

.at-dist svg {
    display: block;
    width: 13px;
    height: 13px;
}

.at-dist:hover {
    color: var(--pp-ink);
    background: color-mix(in oklab, var(--pp-ink) 7%, transparent);
}

.at-dist[aria-expanded="true"] {
    color: var(--pp-accent);
    background: var(--pp-tint);
}

.at-dist:focus-visible {
    outline: 2px solid var(--pp-accent);
    outline-offset: 1px;
}

/* An open graph row: each value cell shows its chart instead of its value. The value (and the
   best value's dot) stays in the cell, hidden, so nothing in the table moves: the chart is laid
   over the cell's content box (the cells' 14px 16px padding, css/ai.css), up to 56px tall. */
.pp-bench tr .at-chart {
    display: none;
}

.pp-bench tr.at-dist-on td {
    position: relative;
}

.pp-bench tr.at-dist-on .at-val,
.pp-bench tr.at-dist-on td.is-best::before {
    visibility: hidden;
}

.pp-bench tr.at-dist-on .at-chart {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 16px;
    display: block;
    height: min(calc(100% - 28px), 56px);
    border-bottom: 1px solid var(--pp-rule-strong);
    cursor: crosshair;
    touch-action: pan-y;
}

.at-chart:focus {
    outline: none;
}

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

.at-chart svg {
    display: block;
    width: 100%;
    height: 100%;
}

.at-chart-bars {
    fill: color-mix(in oklab, var(--pp-ink) 45%, transparent);
}

.at-chart-hi {
    fill: var(--pp-accent);
}

.at-dist-tip {
    position: absolute;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-width: 280px;
    padding: 7px 10px;
    border: 1px solid var(--pp-rule-strong);
    border-radius: 6px;
    background: var(--pp-paper-2);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    font-family: var(--pp-sans);
    font-size: 0.76rem;
    line-height: 1.4;
    color: var(--pp-ink-2);
    white-space: nowrap;
    pointer-events: none;
}

.at-dist-tip[hidden] {
    display: none;
}

.at-dist-tip b {
    font-family: var(--pp-mono);
    font-weight: 500;
    color: var(--pp-ink);
}

.at-dist-tip span {
    font-family: var(--pp-mono);
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (forced-colors: active) {
    .at-chart-bars {
        fill: CanvasText;
    }
    .at-chart-hi {
        fill: Highlight;
    }
}

/* ── Companion app ───────────────────────────────────────────────────── */

/* Lands below the fixed nav when reached from a link (#app). */
#app {
    scroll-margin-top: 76px;
}

.at-app-ctas {
    margin-top: 26px;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 18px;
}

.at-app-meta {
    font-family: var(--pp-mono);
    font-size: 0.78rem;
    color: var(--pp-muted);
}
