/* Tune page: layout, collapsible sections, and the parameter history chart. */

/* ---------- Layout: a main column, and a side column ---------- */

#content .workload-container.tune-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: start;
}

#content .tune-page > .tune-main {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

#content .tune-page > .tune-side {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

#content .tune-main > .card,
#content .tune-side > .card {
    margin: 0;
}

/* Source order is side first; this puts the story in the right order */
#content .tune-main > #spsa-panel { order: 1; }
#content .tune-main > #results    { order: 2; }
#content .tune-main > #parameters { order: 3; }

@media (max-width: 1000px) {
    #content .workload-container.tune-page { grid-template-columns: minmax(0, 1fr); }
    #content .tune-page > .tune-main { grid-column: 1; grid-row: 1; }
    #content .tune-page > .tune-side { grid-column: 1; grid-row: 2; }
}

/* ---------- Spacing inside the cards ---------- */

/* .card has no padding of its own: only its header is padded, so whatever
   follows has to keep clear of the border by itself. */
#content .spsa-panel { padding-bottom: 16px; }

#content .spsa-panel > :not(.card-head) {
    margin-left: 16px;
    margin-right: 16px;
}

#content .spsa-panel > .card-head + * { margin-top: 14px; }

/* The Modify button ends the Actions card and used to sit 4px from its edge */
#content .workload-container #actions { padding-bottom: 16px; }
#content .workload-container #actions .llr-history-panel { margin-bottom: 0; }

/* ---------- The parameter list scrolls inside the panel ---------- */

/* With dozens of parameters the list ran the page down to the results table.
   It now keeps to a bounded height; the filter and sort bar above it stays in
   view. The left padding keeps focus rings from being clipped. */
#content .spsa-panel .spsa-rows {
    max-height: min(60vh, 540px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    margin-left: 12px;
    padding-left: 4px;
    padding-right: 8px;
}

/* ---------- Collapsible sections ---------- */

#content details.config-fold {
    padding: 0;
}

.config-fold > summary {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 18px;
    cursor: pointer;
    list-style: none;
    border-radius: inherit;
}

.config-fold > summary::-webkit-details-marker { display: none; }

.config-fold > summary .card-title { margin: 0; }

.config-fold > summary:focus-visible {
    outline: 2px solid var(--accent, #4c8dff);
    outline-offset: -2px;
}

.config-hint {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    color: var(--muted, var(--color-font3, #8b95a7));
}

.config-fold > summary::after {
    content: '';
    flex: none;
    align-self: center;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    opacity: .6;
    transform: rotate(45deg) translateY(-2px);
    transition: transform .15s ease;
}

.config-fold[open] > summary::after {
    transform: rotate(-135deg) translateY(-2px);
}

.config-fold[open] > summary {
    border-bottom: 1px solid var(--line, #2a303a);
}

.config-fold > :not(summary) {
    padding-left: 18px;
    padding-right: 18px;
}

.config-fold > table { margin-top: 8px; margin-bottom: 12px; width: calc(100% - 36px); }

/* ---------- Parameter names double as "show on chart" buttons ---------- */

button.spsa-name {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    text-align: left;
    cursor: pointer;
    color: var(--spsa-ink);
    background: none;
    border: 0;
    font-family: var(--spsa-mono);
    font-size: 13.5px;
}

button.spsa-name::before {
    content: '';
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--row-color, transparent);
    opacity: 0;
}

.spsa-row.is-shown button.spsa-name::before { opacity: 1; }
.spsa-row.is-pinned button.spsa-name { text-decoration: underline; text-underline-offset: 3px; }

button.spsa-name:focus-visible {
    outline: 2px solid var(--spsa-fill);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ---------- History chart ---------- */

.spsa-history {
    padding: 4px 0 18px;
}

.spsa-history-head h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--spsa-ink);
}

.spsa-history-head p {
    margin: 2px 0 10px;
    font-size: 13px;
    color: var(--spsa-muted);
}

.spsa-chart { position: relative; width: 100%; }

.sch-plot {
    position: relative;
    cursor: crosshair;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.sch-plot:focus-visible {
    outline: 2px solid var(--spsa-fill);
    outline-offset: 4px;
}

.sch-svg { display: block; width: 100%; height: auto; overflow: visible; }

.sch-bg { fill: transparent; }

.sch-grid { stroke: rgba(197, 204, 217, .09); stroke-width: 1; shape-rendering: crispEdges; }
.sch-zero { stroke: var(--spsa-muted); stroke-width: 1; opacity: .65; shape-rendering: crispEdges; }

.sch-tick {
    fill: var(--spsa-muted);
    font: 500 10px var(--spsa-mono);
}

.sch-line {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sch-line.is-quiet { stroke: var(--spsa-muted); stroke-width: 1; opacity: .24; }
.sch-line.is-on { stroke-width: 2; }

.sch-label { font: 600 11px var(--spsa-mono); }

.sch-hover-line {
    stroke: var(--spsa-ink);
    stroke-width: 1;
    stroke-dasharray: 2 2;
    opacity: 0;
}

.sch-hover-line.is-active { opacity: .7; }

.sch-dot { stroke: var(--color2, #1a1d22); stroke-width: 1.5; }

.c0 { stroke: #5fa0ff; fill: #5fa0ff; }
.c1 { stroke: #6ee7b7; fill: #6ee7b7; }
.c2 { stroke: #f2c94c; fill: #f2c94c; }
.c3 { stroke: #c4a1ff; fill: #c4a1ff; }
.c4 { stroke: #ff8f84; fill: #ff8f84; }

.sch-line.c0, .sch-line.c1, .sch-line.c2, .sch-line.c3, .sch-line.c4 { fill: none; }
.sch-label.c0, .sch-label.c1, .sch-label.c2, .sch-label.c3, .sch-label.c4 { stroke: none; }

.sch-tip {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
    min-width: 150px;
    padding: 8px 10px;
    background: rgba(14, 16, 20, .96);
    border: 1px solid var(--line-strong, #3a3f48);
    border-radius: 4px;
    color: var(--spsa-ink);
    font: 500 12px var(--spsa-mono);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s ease;
}

.sch-tip.is-active { opacity: 1; }

.sch-tip .t-games { margin-bottom: 4px; color: var(--spsa-muted); }

.sch-tip .t-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.sch-tip .t-swatch { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.sch-tip .t-name { margin-right: auto; padding-right: 12px; }
.sch-tip .t-delta { color: var(--spsa-muted); }

.spsa-note {
    margin: 8px 0 0;
    font-size: 12.5px;
    color: var(--spsa-muted);
}

@media (prefers-reduced-motion: reduce) {
    .sch-tip, .config-fold > summary::after { transition: none; }
}
