/*
 * 2FA Code Generator (/security/totp-generator). Builds on devtool-kit.css (dk-*); only what is specific to this tool
 * lives here, prefixed tg-: the secret row, the settings grid, the code with its countdown ring, the QR box and the
 * verify result.
 */

.tg-input-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.tg-secret-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3) var(--space-6);
}

@media (min-width: 900px) {
    .tg-secret-row {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: start;
    }

    .tg-gen {
        padding-top: calc(var(--text-sm) * 1.4 + var(--space-2));
    }
}

.tg-gen {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.tg-gen .dk-btn {
    min-height: 52px;
}

.tg-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}

/* the segmented control is 54px tall: the selects and inputs of the same row match it */
.tg-settings .dk-select,
.tg-settings .dk-input,
.tg-narrow .dk-select,
.tg-b32-controls .dk-select {
    min-height: 52px;
}

.tg-settings > .dk-field:first-child {
    grid-column: 1 / -1;
}

@media (min-width: 900px) {
    .tg-settings {
        grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    }

    .tg-settings > .dk-field:first-child {
        grid-column: auto;
    }
}

.tg-input-card code,
.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;
}

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

.tg-narrow {
    flex: 0 1 180px !important;
}

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

/* results that belong to the last valid input while a field holds an error */
.tg-stale-list {
    opacity: 0.5;
}

/* ----------------------------------------------------------------------------------------- the current code */

.tg-code-card .dk-card-head {
    align-items: center;
}

.tg-at {
    margin-bottom: var(--space-4);
}

.tg-now {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    margin-bottom: var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
}

.tg-ring {
    position: relative;
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
}

.tg-ring svg {
    display: block;
    width: 64px;
    height: 64px;
    transform: rotate(-90deg);
}

.tg-ring circle {
    fill: none;
    stroke-width: 5;
}

.tg-ring-track {
    stroke: var(--border-color);
}

.tg-ring-arc {
    stroke: var(--text-secondary);
    stroke-linecap: round;
    stroke-dasharray: 175.93;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 240ms ease-out, stroke 160ms ease-out;
}

.tg-ring.is-wrap .tg-ring-arc {
    transition: none;
}

.tg-ring.is-ending .tg-ring-arc {
    stroke: var(--warning-color);
}

.tg-ring-num {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.tg-code-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 0;
}

.tg-code {
    font-family: var(--font-mono);
    /* 8 digits plus the group space fit beside the copy button from 320px up (measured in the e2e) */
    font-size: clamp(1.5rem, 7vw, 2.25rem);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.012em;
    line-height: 1.15;
    color: var(--text-primary);
    white-space: nowrap;
    border-radius: var(--border-radius-sm);
    transition: background-color 240ms ease-out;
}

.tg-code.is-changed {
    background: var(--bg-tertiary);
    transition: none;
}

.tg-code.is-stale {
    color: var(--text-secondary);
}

.tg-left {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.tg-code-copy {
    margin-left: auto;
}

.tg-hotp-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.tg-steps .dk-value-note {
    font-family: inherit;
}

/* ------------------------------------------------------------------------------------------------- verify */

.tg-verify-out {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    min-height: 44px;
    margin-top: var(--space-4);
    font-size: var(--text-base);
    color: var(--text-primary);
}

.tg-verify-out:empty {
    display: none;
}

.tg-verify-out > i {
    margin-top: 0.25em;
}

.tg-verify-out .is-yes { color: var(--success-color); }
.tg-verify-out .is-no { color: var(--text-secondary); }
.tg-verify-out .is-bad { color: var(--error-color); }

/* ----------------------------------------------------------------------------------------------- URI + QR */

.tg-uri-card .dk-row {
    margin-bottom: var(--space-4);
}

.tg-uri-card .dk-error {
    margin-bottom: var(--space-3);
}

.tg-qr-box {
    display: flex;
    justify-content: center;
    padding: var(--space-4);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
}

/* the QR stays dark on white in the dark theme too: scanners need the contrast */
.tg-qr {
    display: block;
    width: 240px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: var(--border-radius-sm);
    background: #fff;
    image-rendering: pixelated;
}

.tg-qr.is-stale {
    opacity: 0.25;
}

.tg-qr-empty {
    max-width: 320px;
}

.tg-qr-actions {
    justify-content: center;
    margin: var(--space-3) 0 var(--space-2);
}

/* long values break at the <wbr> points the script inserts (between groups of 4 or 8, after ? & = : / . - _ in a URI);
   overflow-wrap:anywhere is the last resort, so no value can overflow its cell or run under its copy button */
.tg-tool .dk-value {
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------------------------------------- Base32 */

.tg-b32-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-4) var(--space-6);
    margin-bottom: var(--space-4);
}

.tg-b32-controls > .dk-field {
    flex: 0 1 auto;
}

#tgB32In {
    min-height: 120px;
}

.tg-tool .dk-chips {
    margin-top: var(--space-3);
}

.tg-input-card .dk-chips {
    margin-top: 0;
}

/* notes quote values typed by the user (an account such as a long e-mail address): they wrap instead of overflowing */
.tg-tool .dk-notice p {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* the article's code blocks scroll sideways and take keyboard focus (tabindex="0"): show where the focus is */
.tg-content pre:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* a code or hex value in the worked examples never breaks inside the number */
.tg-content td code {
    white-space: nowrap;
}

@media (max-width: 600px) {
    .tg-ex-table tr {
        padding-right: var(--space-3);
    }
}

.tg-uri-restore .dk-chip {
    gap: var(--space-2);
    font-family: inherit;
}

.tg-uri-restore .dk-chip i {
    color: var(--text-secondary);
}

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

.tg-honest {
    align-items: flex-start;
}

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

    .tg-now {
        gap: var(--space-3);
        padding: var(--space-3);
    }

    .tg-ring,
    .tg-ring svg {
        width: 56px;
        height: 56px;
    }

    .tg-privacy {
        display: block;
    }

    .tg-gen .dk-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    /* the ring repeats the "Changes in N s" line: on a phone the code gets its width */
    .tg-ring {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    /* no moving ring: the seconds count beside the code says the same */
    .tg-ring {
        display: none;
    }

    .tg-code,
    .tg-ring-arc {
        transition: none;
    }
}
