/* Kinma 6-digit OTP / PIN input (login 2FA, settings activation, …) */
.kinma-otp,
.modal-2fa-otp {
    position: relative;
}

.kinma-otp {
    display: block;
    margin: 0 auto;
    max-width: 100%;
}

/* Password-manager anchor: real input sits as sibling of visual cells, not inside decorative wrap. */
.kinma-otp-pm-anchor {
    position: relative;
    display: block;
    width: max-content;
    max-width: 100%;
    margin-inline: auto;
    isolation: isolate;
}

/* Grid stack: decorative layer below, real field on top (Bitwarden visibility / hit-test). */
.kinma-otp-pm-anchor--grid {
    display: inline-grid;
    grid-template-columns: minmax(0, max-content);
    grid-template-rows: minmax(64px, auto);
    vertical-align: top;
}

.kinma-otp-pm-anchor--grid > .kinma-otp,
.kinma-otp-pm-anchor--grid > .kinma-otp-autofill {
    grid-column: 1;
    grid-row: 1;
}

.kinma-otp-pm-anchor--grid > .kinma-otp {
    z-index: 1;
    pointer-events: none;
}

.kinma-otp-pm-anchor--grid > .kinma-otp-autofill {
    position: relative;
    z-index: 2;
    pointer-events: auto;
    align-self: stretch;
    justify-self: stretch;
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 64px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    opacity: 1;
    background: transparent;
    color: #1a1a1a;
    caret-color: #1a1a1a;
    font-size: 16px;
    line-height: 1;
    cursor: text;
    outline: none;
    box-shadow: none;
    appearance: none;
    -webkit-appearance: none;
    -webkit-text-fill-color: #1a1a1a;
}

.kinma-otp-pm-anchor--grid:has(.kinma-otp--login) > .kinma-otp-autofill {
    font-size: 2.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    letter-spacing: 2.05rem;
    line-height: 64px;
    min-height: 64px;
    height: 64px;
    width: calc((64px * 6) + (8px * 5));
    color: #1a1a1a;
    -webkit-text-fill-color: #1a1a1a;
    caret-color: #1a1a1a;
}

.kinma-otp-pm-anchor--grid > .kinma-otp-autofill:focus {
    outline: none;
    box-shadow: none;
}

.kinma-otp-pm-anchor:has(.kinma-otp-autofill) {
    cursor: text;
    pointer-events: auto;
}

.kinma-otp:has(.kinma-otp-autofill),
.kinma-otp-pm-anchor:has(.kinma-otp-autofill) .kinma-otp {
    display: block;
    width: max-content;
    max-width: 100%;
    margin-inline: auto;
    isolation: isolate;
}

.kinma-otp-cells {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0 auto;
    max-width: 100%;
}

/* inline-flex = shrink-wrap to digits only (no dead flex space on the left/right). */
.kinma-otp:has(.kinma-otp-autofill) .kinma-otp-cells,
.kinma-otp-pm-anchor:has(.kinma-otp-autofill) .kinma-otp-cells,
.modal-2fa-otp:has(.kinma-otp-autofill) .kinma-otp-cells {
    display: inline-flex;
    width: auto;
    max-width: 100%;
    justify-content: flex-start;
    margin: 0;
    padding: 0;
    position: relative;
    z-index: 1;
    vertical-align: top;
}

.kinma-otp-cell-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.kinma-otp-cell-line {
    position: absolute;
    left: 50%;
    bottom: 22%;
    width: 40%;
    min-width: 18px;
    max-width: 28px;
    height: 2px;
    transform: translateX(-50%);
    background: #1a1a1a;
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

.kinma-otp-cell-line.is-visible {
    opacity: 1;
    animation: kinmaOtpLineBlink 1.1s step-end infinite;
}

.modal-2fa-otp {
    display: block;
    margin: 0 auto;
    max-width: 100%;
}

.modal-2fa-otp:has(.kinma-otp-autofill) {
    display: block;
    width: max-content;
    max-width: 100%;
    margin-inline: auto;
    isolation: isolate;
}

.modal-2fa-otp .kinma-otp-cells {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 8px;
}

/* Real input for password managers — full opacity + transparent text (PMs ignore opacity≈0 fields). */
.kinma-otp-field .kinma-otp-autofill:not(.kinma-otp-autofill--grid),
.wizard-form-group.kinma-otp-field .kinma-otp-autofill:not(.kinma-otp-autofill--grid),
.kinma-otp-pm-anchor:not(.kinma-otp-pm-anchor--grid) .kinma-otp-autofill,
.kinma-otp .kinma-otp-autofill,
.modal-2fa-otp .kinma-otp-autofill {
    all: unset;
    box-sizing: border-box;
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    opacity: 1;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    pointer-events: auto;
    z-index: 2;
    font-size: 16px;
    line-height: 1;
    cursor: text;
    -webkit-text-fill-color: transparent;
    outline: none;
    box-shadow: none;
    min-height: 0;
    max-height: none;
    appearance: none;
    -webkit-appearance: none;
}

.visually-hidden,
.kinma-otp-autofill-label.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.kinma-otp-field .kinma-otp-autofill:not(.kinma-otp-autofill--grid):focus,
.wizard-form-group.kinma-otp-field .kinma-otp-autofill:not(.kinma-otp-autofill--grid):focus,
.kinma-otp-pm-anchor:not(.kinma-otp-pm-anchor--grid) .kinma-otp-autofill:focus,
.kinma-otp .kinma-otp-autofill:focus,
.modal-2fa-otp .kinma-otp-autofill:focus {
    outline: none;
    border: 0;
    box-shadow: none;
    border-bottom: 0;
}

.kinma-otp:has(.kinma-otp-autofill),
.kinma-otp-pm-anchor:has(.kinma-otp-autofill),
.modal-2fa-otp:has(.kinma-otp-autofill) {
    cursor: text;
    pointer-events: auto;
}

.kinma-otp:has(.kinma-otp-autofill) .kinma-otp-cells,
.kinma-otp-pm-anchor:has(.kinma-otp-autofill) .kinma-otp-cells,
.kinma-otp:has(.kinma-otp-autofill) .kinma-otp-cell-wrap,
.kinma-otp-pm-anchor:has(.kinma-otp-autofill) .kinma-otp-cell-wrap,
.kinma-otp:has(.kinma-otp-autofill) .kinma-otp-cell,
.kinma-otp-pm-anchor:has(.kinma-otp-autofill) .kinma-otp-cell,
.modal-2fa-otp:has(.kinma-otp-autofill) .kinma-otp-cells,
.modal-2fa-otp:has(.kinma-otp-autofill) .kinma-otp-cell-wrap,
.modal-2fa-otp:has(.kinma-otp-autofill) .modal-2fa-otp-cell {
    pointer-events: none;
    user-select: none;
    cursor: text;
}

@keyframes kinmaOtpAutofillStart {
    from {
        opacity: 0.99;
    }
    to {
        opacity: 0.99;
    }
}

.kinma-otp-autofill:-webkit-autofill {
    animation-name: kinmaOtpAutofillStart;
    animation-duration: 0.01s;
}

.kinma-otp-cell {
    width: 44px;
    height: 52px;
    padding: 0;
    box-sizing: border-box;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    font-size: 1.35rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    color: #1a1a1a;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.kinma-otp-cell:focus,
.kinma-otp.is-focused .kinma-otp-cell,
.kinma-otp.has-input .kinma-otp-cell,
.modal-2fa-otp.is-focused .modal-2fa-otp-cell,
.modal-2fa-otp.has-input .modal-2fa-otp-cell {
    outline: none;
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

.kinma-otp.is-focused .kinma-otp-cell.is-active-cell,
.modal-2fa-otp.is-focused .modal-2fa-otp-cell.is-active-cell {
    position: relative;
}

@keyframes kinmaOtpLineBlink {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}

body.dark-mode .kinma-otp-cell-line {
    background: #f4f4f5;
}

body.dark-mode .kinma-otp.is-focused .kinma-otp-cell,
body.dark-mode .kinma-otp.has-input .kinma-otp-cell,
body.dark-mode .modal-2fa-otp.is-focused .modal-2fa-otp-cell,
body.dark-mode .modal-2fa-otp.has-input .modal-2fa-otp-cell {
    border-color: #f4f4f5;
    box-shadow: 0 0 0 3px rgba(244, 244, 245, 0.15);
}

.kinma-otp-cell.filled {
    border-color: #cbd5e1;
    background: #fafbfc;
}

.kinma-otp.is-focused .kinma-otp-cell.filled,
.kinma-otp.has-input .kinma-otp-cell.filled,
.modal-2fa-otp.is-focused .modal-2fa-otp-cell.filled,
.modal-2fa-otp.has-input .modal-2fa-otp-cell.filled {
    border-color: #1a1a1a;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}

body.dark-mode .kinma-otp.is-focused .kinma-otp-cell.filled,
body.dark-mode .kinma-otp.has-input .kinma-otp-cell.filled,
body.dark-mode .modal-2fa-otp.is-focused .modal-2fa-otp-cell.filled,
body.dark-mode .modal-2fa-otp.has-input .modal-2fa-otp-cell.filled {
    border-color: #f4f4f5;
    background: var(--kinma-st-surface-elevated, #252525);
    box-shadow: 0 0 0 3px rgba(244, 244, 245, 0.15);
}

.kinma-otp-cell:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Login 2FA: große Kreise, gut lesbare Ziffern */
.kinma-otp--login .kinma-otp-cells {
    gap: 14px;
}

.kinma-otp--login .kinma-otp-cell {
    width: 64px;
    height: 64px;
    font-size: 2.5rem;
    font-weight: 700;
    border-radius: 50%;
    padding: 0;
}

.kinma-otp--login .kinma-otp-cell-line {
    bottom: 24%;
    width: 42%;
    min-width: 22px;
    max-width: 30px;
    height: 2.5px;
}

.kinma-otp.is-disabled .kinma-otp-cell,
.kinma-otp.is-disabled .modal-2fa-otp-cell {
    opacity: 0.5;
    cursor: not-allowed;
}

.kinma-otp.is-error .kinma-otp-cell,
.kinma-otp-cell.is-error {
    border-color: #dc2626;
    background: #fef2f2;
    color: #991b1b;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
    transform: none;
}

.kinma-otp.is-error .kinma-otp-cell:focus,
.kinma-otp-cell.is-error:focus,
.kinma-otp.is-error.is-focused .kinma-otp-cell,
.kinma-otp.is-error.has-input .kinma-otp-cell {
    border-color: #b91c1c;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
    transform: none;
}

body.dark-mode .kinma-otp.is-error .kinma-otp-cell,
body.dark-mode .kinma-otp-cell.is-error {
    background: rgba(220, 38, 38, 0.12);
    color: #fecaca;
    border-color: #f87171;
}

.kinma-otp.is-success .kinma-otp-cell,
.kinma-otp-cell.is-success {
    border: 2px solid #15803d;
    background: #f0fdf4;
    color: #166534;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.22);
    transform: none;
    opacity: 1;
    cursor: default;
}

.kinma-otp.is-success .kinma-otp-cell:focus,
.kinma-otp-cell.is-success:focus {
    border-color: #14532d;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.28);
}

body.dark-mode .kinma-otp.is-success .kinma-otp-cell,
body.dark-mode .kinma-otp-cell.is-success {
    background: rgba(22, 163, 74, 0.18);
    color: #bbf7d0;
    border-color: #22c55e;
    box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.24);
}

/* Settings 2FA modal (legacy class names) */
.modal-2fa-otp {
    position: relative;
}

.modal-2fa-otp-cells {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 0 auto;
    max-width: 100%;
}

.modal-2fa-otp-cell {
    width: 44px;
    height: 52px;
    padding: 0;
    box-sizing: border-box;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    font-size: 1.35rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    color: #1a1a1a;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
    position: relative;
}

.modal-2fa-otp-cell:focus {
    outline: none;
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
    transform: translateY(-1px);
}

.modal-2fa-otp-cell.filled {
    border-color: #cbd5e1;
    background: #fafbfc;
}

body.dark-mode .kinma-otp-cell,
body.dark-mode #settings-menu .modal-2fa-otp-cell {
    background: var(--kinma-st-surface-elevated, #252525);
    border-color: var(--kinma-st-border, rgba(148, 163, 184, 0.25));
    color: var(--kinma-st-text, #f1f5f9);
}

body.dark-mode .kinma-otp-cell:focus,
body.dark-mode #settings-menu .modal-2fa-otp-cell:focus {
    border-color: #f4f4f5;
    box-shadow: 0 0 0 3px rgba(244, 244, 245, 0.15);
}

@media (max-width: 480px) {
    .kinma-otp-cells,
    .modal-2fa-otp-cells {
        gap: 6px;
    }
    .kinma-otp-cell,
    .modal-2fa-otp-cell {
        width: 40px;
        height: 48px;
        font-size: 1.2rem;
        border-radius: 10px;
    }
    .kinma-otp--login .kinma-otp-cell {
        width: 56px;
        height: 56px;
        font-size: 2.15rem;
        border-radius: 50%;
    }

    .kinma-otp--login .kinma-otp-cells {
        gap: 10px;
    }
}
