/* DefenseClaw Spaces: components.
   Flat specificity: single-class selectors (BEM-ish); state is expressed by
   ARIA attributes on the same element. No !important. Requires tokens.css
   and base.css. Classes are listed in design/tokens.md "Components". */

/* ---------- Verdict: the answer panel ---------- */
.verdict {
    display: grid;
    gap: var(--sp-4);
    padding: var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
}

.verdict__label {
    color: var(--muted);
    font-size: var(--fs-small);
    font-weight: 500;
}

.verdict__answer {
    max-width: 32em;
    font-family: var(--font-display);
    font-size: clamp(22px, 1.25rem + 0.6vw, 28px);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

/* 3-tier strip: segments grow by --share (set from data-share by JS), equal without JS */
.verdict__strip {
    display: flex;
    gap: 2px;
    height: 12px;
    border-radius: var(--r-control);
    overflow: hidden;
}

.verdict__seg {
    flex: var(--share, 1) 1 0;
    min-width: 4px;
    background: var(--tier-1);
}

.verdict__seg--2 {
    background: var(--tier-2);
}

.verdict__seg--3 {
    background: var(--tier-3);
}

.verdict__rows {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.verdict__row {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    column-gap: var(--sp-3);
    align-items: baseline;
    padding: var(--sp-3) 0;
    border-top: 1px solid var(--line);
}

.verdict__key {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--tier-1);
    align-self: center;
}

.verdict__key--2 {
    background: var(--tier-2);
}

.verdict__key--3 {
    background: var(--tier-3);
}

.verdict__name {
    font-weight: 600;
    color: var(--ink);
}

.verdict__note {
    grid-column: 2 / -1;
    color: var(--ink-2);
    font-size: var(--fs-small);
}

.verdict__value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

/* ---------- Tiles ---------- */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: var(--sp-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-width: 0;
    padding: var(--sp-4) var(--sp-5) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
}

.tile__label {
    color: var(--ink-2);
    font-size: var(--fs-small);
    font-weight: 500;
    line-height: 1.35;
}

/* Hero/tile figures are proportional (the one exception to tabular-nums) */
.tile__value {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-3);
    font-family: var(--font-display);
    font-size: clamp(40px, 1.5rem + 2.4vw, 64px);
    font-weight: 600;
    font-variant-numeric: proportional-nums lining-nums;
    font-variation-settings: "opsz" 96;
    letter-spacing: -0.02em;
    line-height: 1;
    color: var(--ink);
}

.tile__unit {
    font-size: 0.45em;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--ink-2);
}

.tile__delta {
    color: var(--ink-2);
    font-size: var(--fs-small);
    font-variant-numeric: tabular-nums;
}

.tile__delta--good {
    color: var(--allow-text);
}

.tile__delta--bad {
    color: var(--block-text);
}

/* before -> after variant: two values with a CSS-drawn chevron */
.tile__before {
    color: var(--muted);
}

.tile__after {
    color: var(--ink);
}

.tile__arrow {
    position: relative;
    display: inline-block;
    flex: none;
    width: 0.42em;
    height: 0.42em;
}

.tile__arrow::before {
    content: "";
    position: absolute;
    inset: 0;
    border-top: 3px solid var(--muted);
    border-right: 3px solid var(--muted);
    transform: translateX(-25%) rotate(45deg);
}

/* ---------- Figure card ---------- */
.figure {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    min-width: 0;
    padding: var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: var(--shadow);
}

/* The hero glow: the only glow on the page. The figure must not sit inside
   another stacking context (z-index/transform) or the glow covers the card. */
.figure--hero::before {
    content: "";
    position: absolute;
    inset: -18% 0;
    z-index: -1;
    background:
        radial-gradient(farthest-side at 40% 50%, var(--glow-a), transparent),
        radial-gradient(farthest-side at 65% 55%, var(--glow-b), transparent);
    pointer-events: none;
}

.figure__head {
    display: grid;
    gap: var(--sp-1);
    max-width: var(--measure);
}

.figure__title {
    font-family: var(--font-text);
    font-size: var(--fs-lede);
    font-weight: 600;
    line-height: 1.3;
    color: var(--ink);
}

.figure__subtitle {
    color: var(--ink-2);
    font-size: var(--fs-small);
    line-height: 1.45;
}

.figure__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--sp-3) var(--sp-5);
}

.figure__plot {
    position: relative;
    width: 100%;
    min-height: 120px;
}

.figure__legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-4);
    color: var(--ink-2);
    font-size: var(--fs-caption);
}

/* Static legend keys; the chart kit's legend.js may render its own */
.key {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.key__swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--key, var(--muted));
}

.key__swatch--line {
    height: 2px;
    width: 16px;
    border-radius: 1px;
}

.key--s1 {
    --key: var(--s1);
}

.key--s2 {
    --key: var(--s2);
}

.key--s3 {
    --key: var(--s3);
}

.key--s4 {
    --key: var(--s4);
}

.key--s5 {
    --key: var(--s5);
}

.key--s6 {
    --key: var(--s6);
}

.key--s7 {
    --key: var(--s7);
}

.key--s8 {
    --key: var(--s8);
}

.key--tier-1 {
    --key: var(--tier-1);
}

.key--tier-2 {
    --key: var(--tier-2);
}

.key--tier-3 {
    --key: var(--tier-3);
}

.key--allow {
    --key: var(--allow);
}

.key--confirm {
    --key: var(--confirm);
}

.key--block {
    --key: var(--block);
}

.figure__caption {
    max-width: var(--measure);
    color: var(--muted);
    font-size: var(--fs-caption);
    line-height: 1.45;
}

.figure__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--sp-2);
    padding-top: var(--sp-3);
    border-top: 1px solid var(--line);
}

.figure__details > summary {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 28px;
    padding: 0 var(--sp-3);
    border: 1px solid var(--line);
    border-radius: var(--r-control);
    color: var(--ink-2);
    font-size: var(--fs-caption);
    font-weight: 500;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

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

.figure__details > summary::before {
    content: "";
    width: 5px;
    height: 5px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--dur-fast) var(--ease);
}

.figure__details > summary:hover {
    background: var(--raised);
    color: var(--ink);
}

.figure__details[open] {
    flex-basis: 100%;
}

.figure__details[open] > summary {
    color: var(--ink);
}

.figure__details[open] > summary::before {
    transform: rotate(45deg);
}

.figure__panel {
    margin-top: var(--sp-3);
    color: var(--ink-2);
    font-size: var(--fs-small);
}

.figure__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-left: auto;
}

.figure__actions .btn {
    min-height: 28px;
    font-size: var(--fs-caption);
}

@media (max-width: 639.98px) {
    .figure,
    .verdict {
        padding: var(--sp-4);
    }

    .figure__actions {
        margin-left: 0;
    }
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 0 var(--sp-2);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: var(--fs-caption);
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
    vertical-align: 0.08em;
}

.badge--superseded {
    border-color: var(--confirm);
    color: var(--confirm-text);
}

.badge--pilot {
    border-color: transparent;
    background: var(--raised);
    color: var(--muted);
}

.badge--evalonly {
    border-color: var(--block);
    color: var(--block-text);
}

/* ---------- Glossary terms + tooltip bubble ---------- */
dfn[data-term] {
    font-style: normal;
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 1.5px;
    text-decoration-color: var(--muted);
    text-underline-offset: 0.22em;
    border-radius: 2px;
    cursor: help;
}

dfn[data-term]:hover {
    text-decoration-color: currentColor;
}

/* glossary.js positions the bubble (left/top) and sets --arrow-x */
.glossary-tip {
    position: absolute;
    z-index: 30;
    max-width: min(320px, calc(100vw - 16px));
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--axis);
    border-radius: var(--r-control);
    box-shadow: var(--shadow);
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: var(--fs-caption);
    font-style: normal;
    font-weight: 400;
    line-height: 1.45;
    pointer-events: none;
}

.glossary-tip::after {
    content: "";
    position: absolute;
    left: var(--arrow-x, 50%);
    bottom: -5px;
    width: 8px;
    height: 8px;
    margin-left: -4px;
    background: var(--surface);
    border-right: 1px solid var(--axis);
    border-bottom: 1px solid var(--axis);
    transform: rotate(45deg);
}

.glossary-tip--below::after {
    top: -5px;
    bottom: auto;
    transform: rotate(-135deg);
}

.glossary-tip__term {
    display: block;
    color: var(--ink);
    font-weight: 600;
}

/* ---------- Callouts ---------- */
.callout {
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--muted);
    border-radius: 0 var(--r-control) var(--r-control) 0;
    color: var(--ink-2);
}

.callout__title {
    display: block;
    margin-bottom: var(--sp-1);
    color: var(--ink);
    font-weight: 600;
}

.callout--warn {
    border-left-color: var(--confirm);
}

.callout--good {
    border-left-color: var(--allow);
}

.callout--bad {
    border-left-color: var(--block);
}

/* ---------- Control labels and inputs ---------- */
.control {
    display: grid;
    gap: 6px;
}

.control__label {
    color: var(--ink-2);
    font-size: var(--fs-caption);
    font-weight: 500;
}

.input {
    min-height: 32px;
    padding: 0 var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-control);
    color: var(--ink);
    font-size: var(--fs-small);
}

.input::placeholder {
    color: var(--muted);
}

/* ---------- Segmented control ---------- */
.seg {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: var(--r-control);
    background: var(--page);
}

.seg__btn {
    min-height: 28px;
    padding: 0 var(--sp-3);
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--ink-2);
    font-size: var(--fs-small);
    font-weight: 500;
    white-space: nowrap;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.seg__btn:hover {
    color: var(--ink);
}

.seg__btn[aria-pressed="true"] {
    background: var(--raised);
    color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--axis);
}

/* ---------- Range slider ---------- */
.range {
    display: grid;
    gap: 6px;
    min-width: 220px;
}

.range__label {
    color: var(--ink-2);
    font-size: var(--fs-caption);
    font-weight: 500;
}

.range__control {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
}

.range__input {
    width: 100%;
    height: 24px;
    margin: 0;
    background: transparent;
    appearance: none;
    cursor: pointer;
}

.range__input:focus-visible {
    outline: none;
}

.range__input::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right,
            var(--confirm) 0 calc(var(--fill, 0) * 1%),
            var(--raised) calc(var(--fill, 0) * 1%) 100%);
}

.range__input::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    margin-top: -7px;
    border: 0;
    border-radius: 50%;
    background: var(--confirm);
    box-shadow: 0 0 0 2px var(--surface);
    appearance: none;
    transition: transform var(--dur-fast) var(--ease);
}

.range__input:active::-webkit-slider-thumb {
    transform: scale(1.1);
}

.range__input:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}

.range__input::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--raised);
}

.range__input::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--confirm);
}

.range__input::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: 50%;
    background: var(--confirm);
    box-shadow: 0 0 0 2px var(--surface);
}

.range__input:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
}

/* Readout: in flow without JS; floats over the thumb once .range--live is set */
.range__bubble {
    align-self: flex-start;
    padding: 1px var(--sp-2);
    border-radius: var(--r-control);
    background: var(--confirm);
    color: var(--page);
    font-size: var(--fs-caption);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 20px;
    white-space: nowrap;
}

.range--live .range__control {
    padding-top: 30px;
}

.range--live .range__bubble {
    position: absolute;
    top: 0;
    left: calc(var(--fill, 0) * 1% + 9px - var(--fill, 0) * 0.18px);
    transform: translateX(-50%);
}

.range--live .range__bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -4px;
    width: 8px;
    height: 8px;
    margin-left: -4px;
    background: var(--confirm);
    transform: rotate(45deg);
    z-index: -1;
}

.range__scale {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: var(--fs-caption);
    font-variant-numeric: tabular-nums;
}

/* ---------- Tables ---------- */
.table-scroll {
    position: relative;
    max-height: min(70vh, 720px);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    --table-sticky-top: 0px;
}

/* table.js adds this while columns overflow to the right */
.table-scroll--fade {
    mask-image: linear-gradient(to right, #000 calc(100% - 48px), transparent);
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--ink);
    font-size: var(--fs-small);
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}

.table caption {
    padding: var(--sp-3) var(--sp-3) var(--sp-2);
    caption-side: top;
    color: var(--muted);
    font-size: var(--fs-caption);
    text-align: left;
}

.table thead th {
    position: sticky;
    top: var(--table-sticky-top, var(--header-offset));
    z-index: 1;
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
    border-bottom: 1px solid var(--axis);
    color: var(--ink-2);
    font-weight: 600;
    text-align: left;
    vertical-align: bottom;
}

.table td,
.table tbody th {
    padding: var(--sp-2) var(--sp-3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.table tbody th {
    font-weight: 500;
}

.table tbody tr:last-child > * {
    border-bottom: 0;
}

.table tbody tr:hover > * {
    background: var(--raised);
}

.table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* sort button injected into th[data-sort] by table.js */
.table__sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: inherit;
}

.table__sort:hover {
    color: var(--ink);
}

.table__sort::after {
    content: "";
    width: 6px;
    height: 6px;
    margin-top: -3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    opacity: 0.35;
    transform: rotate(45deg);
}

[aria-sort="descending"] > .table__sort::after {
    opacity: 1;
}

[aria-sort="ascending"] > .table__sort::after {
    margin-top: 3px;
    opacity: 1;
    transform: rotate(-135deg);
}

.num > .table__sort {
    flex-direction: row-reverse;
}

.row--pinned > * {
    background: var(--raised);
    font-weight: 500;
}

.row--pinned > :first-child {
    box-shadow: inset 2px 0 0 var(--confirm);
}

.row--control > * {
    color: var(--muted);
}

.row--expand > * {
    padding: var(--sp-3) var(--sp-4);
    background: var(--page);
    color: var(--ink-2);
    font-size: var(--fs-caption);
    line-height: 1.5;
}

.table__expand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin: -2px var(--sp-1) -2px 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    color: var(--ink-2);
    vertical-align: middle;
}

.table__expand::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-left: -2px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--dur-fast) var(--ease);
}

.table__expand[aria-expanded="true"]::before {
    margin: -3px 0 0;
    transform: rotate(45deg);
}

.table__expand:hover {
    background: var(--raised);
    color: var(--ink);
}

.table-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2) var(--sp-4);
    margin-bottom: var(--sp-3);
}

.table-count {
    color: var(--muted);
    font-size: var(--fs-caption);
}

/* ---------- Exact values, keyboard keys ---------- */
.exact {
    white-space: nowrap;
}

.kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 0 5px;
    border: 1px solid var(--axis);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 18px;
    text-align: center;
}
