﻿/*
 * Login-Modal (PP-373) – modern & schlicht.
 *
 * Helle Karte auf weichgezeichnetem Seitenhintergrund, Markenzeichen + App-Name
 * statt dunklem Kopfblock, Felder ohne Icons. Nutzt ausschließlich Tokens aus
 * theme.css, dadurch gelten Hell/Dunkel und das org-weite Farbschema automatisch.
 */

/* ---------- Hintergrund (Scrim) ---------- */
/* Fast deckend in der Seitenfarbe: Die geschützte Seite tritt ruhig zurück. */
.login-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    backdrop-filter: blur(14px) saturate(120%);
    animation: loginFadeIn 0.2s ease;
}
.login-modal.is-hidden {
    display: none !important;
}

@keyframes loginFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Karte ---------- */
.login-modal-content {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: auto;
    padding: 36px 32px 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    animation: loginRise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes loginRise {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---------- Kopf: Markenzeichen, Titel, Untertitel ---------- */
.login-head {
    margin-bottom: 28px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

/* Rotes Rundquadrat mit Anfangsbuchstaben – gleiche Optik wie das App-Icon */
.login-brand-mark {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    background: var(--brand-grad-btn);
    color: var(--on-brand);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 800;
    line-height: 1;
}

.login-brand-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
}

.login-head h2 {
    margin: 0;
    font-size: 26px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.login-head p {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-muted);
}

/* ---------- Formular ---------- */
.login-form-group {
    margin-bottom: 18px;
}

.login-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.login-input-wrap {
    position: relative;
}

.login-input-wrap input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* 16px verhindert das Auto-Zoomen von iOS */
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-input-wrap.has-toggle input {
    padding-right: 52px;
}

.login-input-wrap input::placeholder {
    color: var(--text-faint);
}

.login-input-wrap input:hover {
    border-color: var(--text-faint);
}

.login-input-wrap input:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}

/* Passwort anzeigen/verbergen */
.login-pw-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: var(--r-xs);
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}
.login-pw-toggle:hover {
    color: var(--text);
    background: var(--surface-3);
}
.login-pw-toggle:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 1px;
}
.login-pw-toggle .login-eye-closed,
.login-pw-toggle.is-visible .login-eye-open {
    display: none;
}
.login-pw-toggle.is-visible .login-eye-closed {
    display: block;
}

/* ---------- Fehlermeldung ---------- */
.login-error {
    margin-bottom: 18px;
    padding: 10px 12px 10px 14px;
    border: 1px solid var(--danger-border);
    border-left: 3px solid var(--danger-text);
    border-radius: var(--r-xs);
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.4;
}

/* ---------- Buttons ---------- */
.login-submit-btn {
    width: 100%;
    height: 48px;
    margin-top: 8px;
    padding: 0 16px;
    border-radius: var(--r-sm);
    font-size: 15.5px;
    font-weight: 600;
}

.login-modal .btn-primary,
.login-modal .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-modal .btn-primary:disabled {
    opacity: 0.75;
    cursor: progress;
}

/* Lade-Spinner im Button (Klasse setzt _setLoginBusy in login.js) */
.login-modal .is-busy::before {
    content: "";
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, currentColor 35%, transparent);
    border-top-color: currentColor;
    animation: loginSpin 0.7s linear infinite;
}

@keyframes loginSpin {
    to { transform: rotate(360deg); }
}

/* ---------- 2FA- und Passwortwechsel-Schritte ---------- */
.login-totp-illu {
    width: 44px;
    height: 44px;
    margin: 0 0 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand-500);
    background: var(--brand-50);
}

.login-totp-hint {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}

.login-totp-input {
    width: 100%;
    height: 60px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.45em;
    text-indent: 0.45em; /* gleicht den Abstand nach der letzten Ziffer aus */
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, 'SF Mono', 'Roboto Mono', Consolas, monospace;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-totp-input::placeholder {
    color: var(--text-faint);
    font-size: 22px;
    letter-spacing: 0.45em;
}

.login-totp-input:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}

.login-totp-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.login-totp-actions .btn-secondary,
.login-totp-actions .btn-primary {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    height: 48px;
    margin: 0;
    padding: 0 12px;
    border-radius: var(--r-sm);
    font-size: 15.5px;
}

.login-totp-qr {
    display: block;
    width: 180px;
    height: 180px;
    margin: 0 auto 10px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: #fff; /* QR-Code braucht hellen Grund, auch im Dunkelmodus */
    box-sizing: border-box;
}

.login-totp-secret {
    margin: 0 0 16px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    text-align: center;
    word-break: break-all;
    color: var(--text-muted);
}

/* ---------- Fußzeile ---------- */
.login-footer {
    margin: 24px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-faint);
    text-align: center;
}

/* ---------- Handy: Vollbild-Fläche statt schwebender Karte ---------- */
@media (max-width: 480px) {
    .login-modal {
        padding: 0;
        align-items: stretch;
        background: var(--surface);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    .login-modal-content {
        max-width: none;
        min-height: 100%;
        margin: 0;
        padding: calc(32px + env(safe-area-inset-top, 0px)) 22px calc(20px + env(safe-area-inset-bottom, 0px));
        border: 0;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }
    .login-modal-body {
        flex: 1 0 auto;
    }
    .login-footer {
        border-top: 0;
    }
}

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
    .login-modal,
    .login-modal-content { animation: none !important; }
    .login-modal .is-busy::before { animation-duration: 1.6s; }
}
