/* ── Administration ───────────────────────────────────────────────────────────────────────────────────
   Owned by the Administration workstream. Everything here composes the design system's tokens; there is
   no hex value, no px font size and no off-grid spacing. Loaded per page via <AdminStyles />.
   ------------------------------------------------------------------------------------------------- */

/* ── The access matrix (AUTHORIZATION §3, spec §21) ───────────────────────────────────────────────── */

/* Says which question the grid is answering. A tick means something different for a key than for a
   person, and the difference is not visible in the cells themselves. */
.admin-matrix-channel {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--qp-space-2);
    max-width: min(100%, 54rem);
}

.admin-matrix-channel__text {
    flex: 1 1 20rem;
    min-width: 0;
    font-size: var(--qp-text-xs);
    color: var(--qp-text-muted);
    line-height: var(--qp-leading-snug);
}

.admin-matrix-wrap {
    /* Capped so a three-environment grid does not stretch its cells across an ultra-wide screen; it still
       scrolls horizontally once there are enough environments to need the room. */
    max-width: min(100%, 54rem);
    overflow-x: auto;
    border: 1px solid var(--qp-border-subtle);
    border-radius: var(--qp-radius-lg);
    background: var(--qp-surface);
}

.admin-matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--qp-text-sm);
}

.admin-matrix th,
.admin-matrix td {
    padding: 0;
    text-align: left;
}

.admin-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--qp-space-3) var(--qp-space-4);
    background: var(--qp-surface-sunken);
    border-bottom: 1px solid var(--qp-border-subtle);
    font-size: var(--qp-text-xs);
    font-weight: var(--qp-weight-semibold);
    color: var(--qp-text-muted);
    white-space: nowrap;
}

/* The suite column absorbs the slack, so environment columns stay the width of their content instead of
   stretching a three-column grid across 1400px. */
.admin-matrix thead th:first-child {
    width: 99%;
}

.admin-matrix thead th.admin-matrix__env {
    width: 1%;
    min-width: 9rem;
    text-align: center;
}

.admin-matrix__env-name {
    display: inline-flex;
    align-items: center;
    gap: var(--qp-space-1);
    color: var(--qp-text);
    font-size: var(--qp-text-sm);
}

.admin-matrix__env-note {
    display: block;
    margin-top: var(--qp-space-1);
    font-size: var(--qp-text-2xs);
    font-weight: 400;
    color: var(--qp-text-faint);
    letter-spacing: 0.02em;
    text-transform: none;
}

/* "> *", not "td": the row header is a <th scope="row">, so a td-only rule would leave the separator
   starting half way across the table. */
.admin-matrix tbody tr + tr > * {
    border-top: 1px solid var(--qp-border-subtle);
}

.admin-matrix tbody tr:hover > * {
    background: var(--qp-surface-hover);
}

.admin-matrix__row-head {
    padding: var(--qp-space-3) var(--qp-space-4);
    min-width: 14rem;
    vertical-align: middle;
}

.admin-matrix__suite {
    display: flex;
    align-items: center;
    gap: var(--qp-space-2);
    color: var(--qp-text-strong);
}

.admin-matrix__suite--all {
    font-weight: 600;
}

.admin-matrix__row-note {
    display: block;
    margin-top: 2px;
    font-size: var(--qp-text-xs);
    color: var(--qp-text-faint);
}

.admin-matrix__cell {
    text-align: center;
    vertical-align: middle;
    padding: var(--qp-space-1);
}

/* The cell control. It is a real <button>, so the whole matrix is keyboard-reachable. */
.admin-cell {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    width: 100%;
    min-height: 2.75rem;
    padding: var(--qp-space-2);
    border: 1px solid transparent;
    border-radius: var(--qp-radius-sm);
    background: transparent;
    color: var(--qp-text-faint);
    font: inherit;
    font-size: var(--qp-text-sm);
    cursor: pointer;
    transition: background var(--qp-duration-fast) var(--qp-ease),
                border-color var(--qp-duration-fast) var(--qp-ease);
}

.admin-cell:disabled {
    cursor: default;
}

.admin-cell:not(:disabled):hover {
    border-color: var(--qp-border);
    background: var(--qp-surface-raised);
}

.admin-cell:focus-visible {
    outline: 2px solid var(--qp-accent);
    outline-offset: 2px;
}

.admin-cell__glyph {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: var(--qp-text-md);
    line-height: 1;
}

.admin-cell__label {
    font-size: var(--qp-text-2xs);
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.admin-cell--allowed {
    color: var(--qp-pass);
    background: var(--qp-pass-bg);
}

.admin-cell--inherited {
    color: var(--qp-text-muted);
    background: var(--qp-surface-sunken);
}

.admin-cell--denied {
    color: var(--qp-fail);
    background: var(--qp-fail-bg);
}

.admin-cell--production {
    color: var(--qp-prod);
    background: var(--qp-prod-bg);
}

.admin-cell--none {
    color: var(--qp-text-faint);
}

/* A cell the administrator has changed but not yet applied. */
.admin-cell--pending {
    border-color: var(--qp-accent);
    border-style: dashed;
    box-shadow: inset 0 0 0 1px var(--qp-accent-subtle);
}

.admin-cell__pending-mark {
    position: absolute;
    inset-block-start: 2px;
    inset-inline-end: 4px;
    font-size: var(--qp-text-2xs);
    color: var(--qp-accent-text);
}

.admin-matrix__cell {
    position: relative;
}

/* QpMenu wraps its trigger in a div, so the wrapper must fill the cell for the button to. */
.admin-matrix__cell .qp-menu-root {
    width: 100%;
}

/* ── Legend ───────────────────────────────────────────────────────────────────────────────────────── */

.admin-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--qp-space-2) var(--qp-space-5);
    padding: var(--qp-space-3) var(--qp-space-1);
    font-size: var(--qp-text-xs);
    color: var(--qp-text-muted);
}

.admin-legend__item {
    display: inline-flex;
    align-items: center;
    gap: var(--qp-space-2);
}

.admin-legend__glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.25rem;
    padding: 0 var(--qp-space-1);
    border-radius: var(--qp-radius-xs);
    font-size: var(--qp-text-xs);
}

.admin-legend__footnote {
    width: 100%;
    margin: 0;
    padding-top: var(--qp-space-1);
    font-size: var(--qp-text-xs);
    font-style: italic;
    color: var(--qp-text-faint);
}

/* ── Pending-changes bar ──────────────────────────────────────────────────────────────────────────── */

.admin-pending {
    position: sticky;
    bottom: var(--qp-space-4);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: var(--qp-space-3);
    margin-top: var(--qp-space-4);
    padding: var(--qp-space-3) var(--qp-space-4);
    border: 1px solid var(--qp-accent-border);
    border-radius: var(--qp-radius-lg);
    background: var(--qp-surface-overlay);
    box-shadow: var(--qp-shadow-2);
}

/* The bar is always rendered so its live region exists before the first announcement; with nothing
   pending it takes no space and draws nothing. `display: none` would remove it from the accessibility
   tree too, which is the thing being avoided. */
.admin-pending[data-empty="true"] {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: none;
    height: 0;
    overflow: hidden;
}

.admin-pending__count {
    font-weight: 600;
    color: var(--qp-text-strong);
}

.admin-pending__hint {
    color: var(--qp-text-muted);
    font-size: var(--qp-text-xs);
}

/* ── Functional access ────────────────────────────────────────────────────────────────────────────── */

.admin-perm-group {
    border: 1px solid var(--qp-border-subtle);
    border-radius: var(--qp-radius-lg);
    background: var(--qp-surface);
    overflow: hidden;
}

.admin-perm-group__head {
    display: flex;
    align-items: center;
    gap: var(--qp-space-3);
    width: 100%;
    padding: var(--qp-space-3) var(--qp-space-4);
    border: 0;
    background: var(--qp-surface-sunken);
    color: var(--qp-text-strong);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.admin-perm-group__head:focus-visible {
    outline: 2px solid var(--qp-accent);
    outline-offset: -2px;
}

.admin-perm-group__count {
    font-size: var(--qp-text-xs);
    font-weight: 400;
    color: var(--qp-text-muted);
    font-variant-numeric: tabular-nums;
}

.admin-perm-row {
    display: grid;
    grid-template-columns: 1.5rem minmax(12rem, 1fr) minmax(0, 1.4fr) auto;
    align-items: start;
    gap: var(--qp-space-3);
    padding: var(--qp-space-3) var(--qp-space-4);
}

.admin-perm-row + .admin-perm-row {
    border-top: 1px solid var(--qp-border-subtle);
}

.admin-perm-row__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.25rem;
    font-size: var(--qp-text-md);
    line-height: 1;
}

.admin-perm-row__mark--granted {
    color: var(--qp-pass);
}

.admin-perm-row__mark--denied {
    color: var(--qp-text-faint);
}

.admin-perm-row__mark--override-deny {
    color: var(--qp-fail);
}

.admin-perm-row__label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--qp-space-2);
    color: var(--qp-text-strong);
}

.admin-perm-row__key {
    font-family: var(--qp-font-mono);
    font-size: var(--qp-text-2xs);
    color: var(--qp-text-faint);
}

.admin-perm-row__why {
    font-size: var(--qp-text-xs);
    color: var(--qp-text-muted);
    line-height: 1.5;
}

.admin-perm-row__why--override {
    color: var(--qp-accent-text);
}

.admin-perm-row__actions {
    display: flex;
    align-items: center;
    gap: var(--qp-space-2);
    justify-content: flex-end;
}

/* ── Effective access answer (spec §98) ───────────────────────────────────────────────────────────── */

.admin-verdict {
    display: flex;
    align-items: center;
    gap: var(--qp-space-4);
    padding: var(--qp-space-5);
    border-radius: var(--qp-radius-lg);
    border: 1px solid var(--qp-border-subtle);
    background: var(--qp-surface);
}

.admin-verdict--yes {
    border-color: var(--qp-pass-border);
    background: var(--qp-pass-bg);
}

.admin-verdict--no {
    border-color: var(--qp-fail-border);
    background: var(--qp-fail-bg);
}

.admin-verdict__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    flex: none;
    border-radius: var(--qp-radius-full);
    background: var(--qp-surface);
}

.admin-verdict--yes .admin-verdict__mark {
    color: var(--qp-pass);
}

.admin-verdict--no .admin-verdict__mark {
    color: var(--qp-fail);
}

.admin-verdict__answer {
    display: block;
    font-size: var(--qp-text-xl);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--qp-text-strong);
}

.admin-verdict__target {
    display: block;
    margin-top: var(--qp-space-1);
    font-size: var(--qp-text-sm);
    color: var(--qp-text-muted);
}

.admin-reasons {
    display: grid;
    gap: var(--qp-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.admin-reasons li {
    display: flex;
    gap: var(--qp-space-2);
    font-size: var(--qp-text-sm);
    color: var(--qp-text);
    line-height: 1.55;
}

.admin-reasons li::before {
    content: "—";
    color: var(--qp-text-faint);
    flex: none;
}

/* ── Audit detail diff ────────────────────────────────────────────────────────────────────────────── */

.admin-diff {
    display: grid;
    grid-template-columns: minmax(8rem, 1fr) minmax(0, 1.2fr) 1.25rem minmax(0, 1.2fr);
    gap: var(--qp-space-2) var(--qp-space-3);
    align-items: baseline;
    font-size: var(--qp-text-sm);
}

.admin-diff__key {
    color: var(--qp-text-muted);
}

.admin-diff__before {
    color: var(--qp-text-muted);
    text-decoration: line-through;
    text-decoration-color: var(--qp-text-faint);
    word-break: break-word;
}

.admin-diff__arrow {
    color: var(--qp-text-faint);
    text-align: center;
}

.admin-diff__after {
    color: var(--qp-text-strong);
    word-break: break-word;
}

.admin-diff__empty {
    color: var(--qp-text-faint);
    font-style: italic;
}

/* ── Small shared pieces ──────────────────────────────────────────────────────────────────────────── */

/* A six-column trail does not fit a 1024px window beside the sidebar. Scrolling it sideways keeps every
   column readable; dropping one would hide the product, which is the column that matters for isolation. */
.admin-scroll-x {
    overflow-x: auto;
}

/* "9 min ago" on one line: wrapped over three lines it triples the row height for no information. */
.admin-when {
    white-space: nowrap;
}

.admin-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--qp-space-2);
}

.admin-filters > * {
    min-width: 0;
}

.admin-identity {
    display: flex;
    align-items: center;
    gap: var(--qp-space-3);
    min-width: 0;
}

.admin-identity__name {
    display: block;
    color: var(--qp-text-strong);
    font-weight: 500;
}

.admin-identity__email {
    display: block;
    font-size: var(--qp-text-xs);
    color: var(--qp-text-muted);
}

.admin-pill-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--qp-space-2);
}

/* ── Taxonomy ──────────────────────────────────────────────────────────────────────────────────────
   A feature chip on /admin/taxonomy: its name, how many tests sit in it, and the two actions. The
   actions stay visible rather than appearing on hover — this is a keyboard-heavy curation screen, and
   a control you have to find is a control people stop using. */

.admin-taxon {
    display: inline-flex;
    align-items: center;
    gap: var(--qp-space-1);
    padding: var(--qp-space-1) var(--qp-space-1) var(--qp-space-1) var(--qp-space-3);
    border: 1px solid var(--qp-border);
    border-radius: var(--qp-radius-full);
    background: var(--qp-surface);
}

.admin-taxon__name {
    font-size: var(--qp-text-sm);
    color: var(--qp-text);
}

.admin-taxon__count {
    min-width: 1.5rem;
    padding: 0 var(--qp-space-2);
    border-radius: var(--qp-radius-full);
    background: var(--qp-surface-sunken);
    font-size: var(--qp-text-xs);
    color: var(--qp-text-muted);
    text-align: center;
}

/* The tag palette. Swatches are the product's own tag colours, so a tag can never be given a colour
   the rest of the interface has no token for. */

.admin-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: var(--qp-space-2);
}

.admin-swatch {
    inline-size: var(--qp-space-6);
    block-size: var(--qp-space-6);
    padding: 2px;
    border: 2px solid transparent;
    border-radius: var(--qp-radius-full);
    background: var(--swatch);
    background-clip: content-box;
    cursor: pointer;
}

.admin-swatch:hover {
    border-color: var(--qp-border-strong);
}

.admin-swatch[data-selected="true"] {
    border-color: var(--qp-text);
}

.admin-swatch:focus-visible {
    outline: 2px solid var(--qp-accent);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .admin-perm-row {
        grid-template-columns: 1.5rem 1fr;
    }

    .admin-perm-row__why,
    .admin-perm-row__actions {
        grid-column: 2;
        justify-content: flex-start;
    }

    .admin-diff {
        grid-template-columns: 1fr;
    }

    .admin-diff__arrow {
        display: none;
    }
}
