/*
 * Key Generator (/security/key-generator). Builds on devtool-kit.css (dk-*); only what is specific to this tool lives
 * here, prefixed kg-: the settings rows, the key output blocks (title + Copy/Download above a full-width value, so a
 * long key never runs under a button), the randomart, the progress box and the faded state of outputs that cannot be
 * copied (pending generation or an input error).
 */

.kg-copy-cell {
    margin: 0;
}

.kg-quiet {
    color: var(--text-secondary);
    font-weight: 400;
}

.kg-tool code,
.kg-tool .dk-help code {
    padding: 0 3px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.92em;
    white-space: nowrap;           /* "ssh-keygen -lv", "~/.ssh/authorized_keys": never split at a dash or slash */
}

.kg-privacy i {
    margin-right: var(--space-2);
}

/* ------------------------------------------------------------------------------------------------- secrets */

.kg-secrets > .dk-card {
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.kg-secrets .dk-card-head {
    margin-bottom: 0;
}

.kg-len-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
}

.kg-len {
    flex: 0 1 12rem;
}

.kg-len-row .dk-help {
    margin: 0;
}

.kg-alnum {
    align-items: flex-start;
}

.kg-tool .dk-chip {
    min-width: 44px;
    justify-content: center;
}

/* ----------------------------------------------------------------------------------------------- settings */

.kg-settings-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.kg-settings {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4) var(--space-6);
    align-items: flex-end;
}

.kg-settings > .dk-field {
    flex: 0 1 auto;
}

.kg-settings > .kg-comment,
.kg-settings > .kg-alg {
    flex: 1 1 12rem;
}

.kg-settings .dk-input,
.kg-settings .dk-select {
    min-height: 52px;
}

.kg-gen-cell {
    flex: 0 0 auto;
}

.kg-gen {
    min-height: 52px;
}

.kg-tool .dk-tab.kg-unavailable {
    color: var(--text-secondary);
    cursor: not-allowed;
    text-decoration: line-through;
}

/* ------------------------------------------------------------------------------------------------ results */

.kg-result-card {
    min-height: 12rem;
}

.kg-result {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.kg-result-top {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.kg-result-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
}

.kg-badges {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.kg-check-text,
.kg-stale-note {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.kg-stale-note {
    display: flex;
    gap: var(--space-2);
    align-items: baseline;
    color: var(--text-primary);
}

.kg-stale-note i {
    color: var(--error-color);
}

/* outputs that cannot be copied right now: a newer key is being made, or an input has an error */
.kg-stale .dk-value,
.kg-stale .kg-art-pre {
    opacity: 0.45;
    user-select: none;
}

.kg-out {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

.kg-out-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.kg-out-text {
    min-width: 0;
}

.kg-out-title {
    margin: 0;
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
}

.kg-out-sub {
    margin: 2px 0 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.kg-out-actions {
    display: flex;
    flex: 0 0 auto;
    gap: var(--space-2);
}

/* a file name is never cut: the button takes its natural width and the name wraps at its dots and dashes if it must */
.kg-dl {
    white-space: normal;
    text-align: left;
}

.kg-dl-name {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    overflow-wrap: anywhere;
}

/* a key, PEM or JSON block: keeps its line breaks, wraps inside the box (never wider than it), scrolls when tall */
.kg-block {
    margin: 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    font-size: var(--text-sm);
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
    max-height: 22rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* the BEGIN / END lines of a key file never wrap: they shrink to the width of the block (35 characters of about
   0.6 em each fit in 22 em), the Base64 body between them wraps */
.kg-block {
    container-type: inline-size;
}

.kg-armor {
    white-space: nowrap;
    font-size: min(1em, calc(100cqw / 22));
}

.kg-block:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.kg-keygen-line .dk-value {
    font-size: var(--text-sm);
}

/* the randomart sits in its own result row, like the fingerprints it draws */
.kg-art-row {
    align-items: start;
    padding: var(--space-3) 0;
}

.kg-art-pre {
    display: inline-block;
    margin: 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-base);
    line-height: 1.2;
    white-space: pre;
    transition: opacity 200ms ease-out;
}

.kg-more {
    border-top: 1px solid var(--border-color);
    padding-top: var(--space-2);
}

.kg-more > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    list-style: none;
}

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

.kg-more > summary::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: rotate(-45deg);
}

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

.kg-more > summary:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

.kg-more[open] > .kg-out {
    margin-top: var(--space-2);
}

.kg-next {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-color);
}

.kg-pem-grid .dk-group-title {
    margin: 0;
}

/* ------------------------------------------------------------------------------------------------ progress */

.kg-busy {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-4) 0;
}

.kg-bar {
    flex: 1 0 100%;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--bg-tertiary);
}

.kg-bar span {
    display: block;
    width: 30%;
    height: 100%;
    border-radius: 999px;
    background: var(--primary-color);
    animation: kg-slide 1.4s ease-in-out infinite;
}

@keyframes kg-slide {
    from { transform: translateX(-100%); }
    to { transform: translateX(340%); }
}

.kg-busy-text {
    margin: 0;
    flex: 1 1 16rem;
    color: var(--text-primary);
}

.kg-busy-time {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

/* ------------------------------------------------------------------------------------------------ content */

/* a worked example with its Copy button beside it (the example scrolls inside its box, never under the button) */
.kg-pre {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: var(--space-3) 0;
}

.kg-pre > pre {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.kg-pre > .dk-copy {
    flex: 0 0 auto;
}

@media (min-width: 601px) {
    .kg-content .kg-which td:first-child {
        width: 45%;
    }
}

/* stacked on phones: each label sits above its text, so the sentence gets the full width */
@media (max-width: 600px) {
    .kg-content .kg-which td::before {
        float: none;
        display: block;
        width: auto;
        margin-right: 0;
        line-height: 1.5;
    }
}

/* worked examples wrap their long lines inside the box instead of clipping at the right edge */
.kg-pre > pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.kg-content .dk-example .dk-table-wrap {
    margin-bottom: var(--space-4);
}

.kg-content .kg-enc-table th {
    white-space: nowrap;
}

/* ------------------------------------------------------------------------------------------------ narrow */

.kg-content {
    border-top: 1px solid var(--border-color);
    padding-top: var(--space-8);
}

@media (max-width: 720px) {
    .kg-hint-keys {
        display: none;
    }

    /* the three tabs share the full width, so the row never needs to scroll */
    .kg-tool > .dk-toolbar > .dk-tabs {
        flex: 1 1 100%;
    }

    .kg-privacy {
        display: block;
    }

    .kg-gen-cell,
    .kg-gen {
        flex: 1 1 100%;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .kg-out-head {
        flex-wrap: wrap;
    }

    .kg-out-text {
        flex: 1 1 100%;
    }

    .kg-out-actions {
        flex: 1 1 100%;
        min-width: 0;
    }

    .kg-dl {
        max-width: none;
        min-width: 0;
        flex: 0 1 auto;
        white-space: normal;
        text-align: left;
    }

    /* a long file name (rsa-2048-private.jwk.json) wraps at its dots and dashes instead of widening the page */
    .kg-dl-name {
        overflow: visible;
        overflow-wrap: anywhere;
    }

    /* 13 px fits the 35-character BEGIN / END lines of a key file at 390 px, so they never leave a lone "-" */
    .kg-block {
        padding: var(--space-2) var(--space-3);
        font-size: 13px;
    }

    .kg-art-pre {
        padding: var(--space-2) var(--space-3);
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kg-bar {
        display: none;
    }

    .kg-bar span {
        animation: none;
    }
}

@media (max-width: 370px) {
    .kg-block {
        font-size: 12px;
    }
}
