/**
 * ALTCHA Widget Styles — KW Backend Assistent
 *
 * Custom-CSS für das ALTCHA PoW-Captcha Web Component.
 * ALTCHA v2 rendert im Light DOM (kein Shadow DOM), daher
 * werden alle Styles extern geladen.
 *
 * Invisible-Modus: ALTCHA v2 hat kein display-Attribut —
 * das Verstecken wird per CSS-Attribut-Selektor gelöst
 * ([display="invisible"] auf dem Custom Element).
 *
 * Design: Integriert sich nahtlos in WordPress-Formulare
 * (Login, Registrierung, Kommentare, Passwort-Reset).
 */

/* ── Wrapper (Abstand zum restlichen Formular) ───────────── */

.kwba-gatekeeper-wrap {
    margin: 16px 0 8px;
}

/* ── Invisible-Modus ─────────────────────────────────────── */

.kwba-gatekeeper-wrap altcha-widget[display="invisible"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.kwba-gatekeeper-wrap altcha-widget[display="invisible"] .altcha {
    border: 0;
}

/* ── Haupt-Container ─────────────────────────────────────── */

.altcha {
    background: var(--altcha-color-base, #fff);
    border: 1px solid var(--altcha-color-border, #c3c4c7);
    border-radius: 4px;
    color: var(--altcha-color-text, #3c434a);
    display: flex;
    flex-direction: column;
    max-width: var(--altcha-max-width, 100%);
    position: relative;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
}

.altcha:focus-within {
    border-color: var(--altcha-color-border-focus, #2271b1);
    box-shadow: 0 0 0 1px var(--altcha-color-border-focus, #2271b1);
}

/* ── Main-Layout (Checkbox + Label + Logo) ───────────────── */

.altcha-main {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    position: relative;
}

/* ── Checkbox ────────────────────────────────────────────── */

.altcha-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 24px;
    position: relative;
    width: 24px;
    flex-shrink: 0;
}

.altcha-checkbox .altcha-spinner {
    inset: 0;
    position: absolute;
}

.altcha-checkbox input {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--altcha-color-active, #2271b1);
}

.altcha-checkbox-verifying input {
    appearance: none;
    opacity: 0;
    pointer-events: none;
}

/* ── Switch-Modus (Checkbox als Toggle) ──────────────────── */

altcha-widget[display="switch"] .altcha-checkbox {
    width: 40px;
    height: 22px;
}

altcha-widget[display="switch"] .altcha-checkbox input {
    appearance: none;
    width: 40px;
    height: 22px;
    background: var(--altcha-color-switch-off, #c3c4c7);
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s;
}

altcha-widget[display="switch"] .altcha-checkbox input::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

altcha-widget[display="switch"] .altcha-checkbox input:checked {
    background: var(--altcha-color-active, #2271b1);
}

altcha-widget[display="switch"] .altcha-checkbox input:checked::before {
    transform: translateX(18px);
}

altcha-widget[display="switch"] .altcha-checkbox-verifying input {
    opacity: 0;
}

/* ── Label ───────────────────────────────────────────────── */

.altcha-label {
    cursor: pointer;
    flex-grow: 1;
    font-size: 14px;
    color: var(--altcha-color-text, #3c434a);
    user-select: none;
}

/* ── Logo ────────────────────────────────────────────────── */

.altcha-logo {
    color: var(--altcha-color-text, #3c434a);
    opacity: 0.5;
    flex-shrink: 0;
    display: flex;
    transition: opacity 0.2s;
}

.altcha-logo:hover {
    opacity: 0.8;
}

.altcha-logo svg {
    width: 20px;
    height: 20px;
}

/* ── Footer ──────────────────────────────────────────────── */

.altcha-footer {
    align-items: center;
    display: flex;
    font-size: 0.7rem;
    opacity: 0.5;
    justify-content: end;
    padding: 0 0.75rem 0.4rem;
    transition: opacity 0.2s;
}

.altcha-footer:hover {
    opacity: 0.8;
}

.altcha-footer a {
    color: inherit;
    text-decoration: none;
}

.altcha-footer a:hover {
    text-decoration: underline;
}

/* ── Error-State ─────────────────────────────────────────── */

.altcha-error {
    color: var(--altcha-color-error, #d63638);
    display: flex;
    font-size: 0.85rem;
    gap: 0.3rem;
    padding: 0 0.75rem 0.5rem;
    align-items: flex-start;
}

.altcha-error svg {
    flex-shrink: 0;
    margin-top: 1px;
}

/* ── Spinner Animation ───────────────────────────────────── */

.altcha-spinner {
    animation: altcha-spinner 0.75s infinite linear;
    transform-origin: center;
}

@keyframes altcha-spinner {
    to {
        transform: rotate(360deg);
    }
}

/* ── Verified-State ──────────────────────────────────────── */

.altcha[data-state="verified"] {
    border-color: var(--altcha-color-verified, #00a32a);
}

.altcha[data-state="verified"]:focus-within {
    box-shadow: 0 0 0 1px var(--altcha-color-verified, #00a32a);
}

/* ── Floating-Modus ──────────────────────────────────────── */

.altcha[data-floating] {
    background: var(--altcha-color-base, #fff);
    display: none;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
    left: -100%;
    position: fixed;
    top: -100%;
    width: var(--altcha-max-width, 260px);
    z-index: 999999;
}

.altcha[data-floating]:not([data-state="unverified"]) {
    display: block;
}

.altcha-anchor-arrow {
    border: 6px solid transparent;
    border-bottom-color: var(--altcha-color-border, #c3c4c7);
    content: "";
    height: 0;
    left: 12px;
    position: absolute;
    top: -12px;
    width: 0;
}

/* ── Overlay-Modus ───────────────────────────────────────── */

.altcha-overlay {
    --altcha-color-base: #fff;
    --altcha-color-text: #3c434a;
    animation: altcha-overlay-in 0.3s ease forwards;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    left: 50%;
    width: 280px;
    opacity: 0;
    position: fixed;
    top: 45%;
    transform: translate(-50%, -50%);
}

.altcha-overlay-backdrop {
    background: rgba(0, 0, 0, 0.4);
    display: none;
    inset: 0;
    position: fixed;
    z-index: 99999999;
}

.altcha-overlay-close-button {
    align-self: flex-end;
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: currentColor;
    font-size: 130%;
    line-height: 1;
    opacity: 0.6;
}

.altcha-overlay-close-button:hover {
    opacity: 1;
}

@keyframes altcha-overlay-in {
    to {
        opacity: 1;
        top: 50%;
    }
}

/* ── Code Challenge (Audio-Captcha-Fallback) ─────────────── */

.altcha-code-challenge {
    background: var(--altcha-color-base, #fff);
    border: 1px solid var(--altcha-color-border-focus, #2271b1);
    border-radius: 4px;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
    padding: 0.5rem;
    position: absolute;
    top: 2.5rem;
    z-index: 9999999;
}

.altcha-code-challenge > form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.altcha-code-challenge-input {
    border: 1px solid #c3c4c7;
    border-radius: 3px;
    box-sizing: border-box;
    outline: none;
    font-size: 14px;
    padding: 0.35rem;
    width: 220px;
}

.altcha-code-challenge-input:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

.altcha-code-challenge-image {
    background-color: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 3px;
    box-sizing: border-box;
    object-fit: contain;
    height: 50px;
    width: 220px;
}

.altcha-code-challenge-audio,
.altcha-code-challenge-reload {
    background: #f0f0f1;
    border: 0;
    border-radius: 3px;
    color: #3c434a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
}

.altcha-code-challenge-audio:hover,
.altcha-code-challenge-reload:hover {
    background: #dcdcde;
}

.altcha-code-challenge-audio > *,
.altcha-code-challenge-reload > * {
    height: 20px;
    width: 20px;
}

.altcha-code-challenge-buttons {
    display: flex;
    justify-content: space-between;
}

.altcha-code-challenge-buttons-left {
    display: flex;
    gap: 0.25rem;
}

.altcha-code-challenge-verify {
    align-items: center;
    background: #2271b1;
    border: 0;
    border-radius: 3px;
    color: #fff;
    cursor: pointer;
    display: flex;
    gap: 0.5rem;
    font-size: 100%;
    padding: 0.35rem 1rem;
}

.altcha-code-challenge-verify:hover {
    background: #135e96;
}

.altcha-code-challenge-arrow {
    border: 6px solid transparent;
    border-bottom-color: #2271b1;
    content: "";
    height: 0;
    left: 0.15rem;
    position: absolute;
    top: -12px;
    width: 0;
}

/* ── Reduced Motion ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .altcha-spinner {
        animation-duration: 1.5s;
    }

    .altcha-overlay {
        animation: none;
        opacity: 1;
        top: 50%;
    }
}
