:root {
    --primary: linear-gradient(20deg, #d6c7a9, #bf9f78 50%, #e0cc99 100%);
    --success: #10B981;
    --error: #DC2626;
    --background: rgba(255,255,255,0.95);
    --text: #1F2937;
    --border: #E5E7EB;
}

/* Base Styles */
.mpf-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none; /* Wird per JS auf "flex" gesetzt, wenn aktiv */
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(10px);
}

.mpf-popup {
    position: relative;
    width: 90%;
    max-width: 440px;
    padding: 2.5rem;
    background: var(--background);
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Aktivierung des Popups */
.mpf-popup.active {
    opacity: 1;
    transform: translateY(0);
}

/* Verschiebung bei geöffneter Tastatur (Mobile) */
.mpf-popup.keyboard-open {
    transform: translateY(-50px);
}

/* Close Button */
.mpf-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: #6B7280;
    transition: all 0.2s ease;
}

.mpf-close svg {
    width: 24px;
    height: 24px;
}

.mpf-close:hover {
    color: var(--text);
    transform: rotate(90deg);
}

/* Form Elements */
.mpf-form-content {
    transition: opacity 0.3s ease;
}

.mpf-info-text {
    color: #6B7280;
    margin: 1rem 0 2rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Formular-Felder */
.mpf-field {
    margin-bottom: 1.5rem;
    position: relative;
    min-height: 70px; /* Reserviert Platz für Fehlermeldungen */
}

.mpf-field input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    font-size: 1rem;
    background: rgba(255,255,255,0.9);
    transition: all 0.2s ease;
}

.mpf-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.mpf-field.error input {
    background: #FFF5F5;
    border-color: #FCA5A5;
    animation: shake 0.4s ease;
}

/* Fehlermeldungen: Platz reservieren */
.mpf-error-message {
    min-height: 1.2em;
    display: block;
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    padding-left: 0.5rem;
    transition: opacity 0.3s ease;
}

/* Allgemeine Fehlermeldung (z. B. bei Submit-Fehlern) */
.mpf-message.error {
    background: #FEF2F2;
    border: 2px solid #FECACA;
    color: var(--error);
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.mpf-message.error::before {
    content: '!';
    width: 24px;
    height: 24px;
    background: var(--error);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* Submit Button */
.mpf-submit-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: background 0.3s ease, transform 0.3s ease;
}

.mpf-submit-btn:hover {
    background: #1c1c1c;
    transform: translateY(-1px);
}

/* Loader im Button */
.mpf-submit-btn .loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: inherit;
    display: none;
    align-items: center;
    justify-content: center;
}

.mpf-submit-btn.loading span {
    visibility: hidden;
}

.mpf-submit-btn.loading .loader {
    display: flex;
}

/* Angepasste Loading-State-Regel: keine Neupositionierung mehr */
.mpf-submit-btn.loading {
    position: relative;
    width: 100%;
    /* Weitere Anpassungen können hier erfolgen, ohne fixed-Positionierung */
}

/* Loader Animation */
.loader::after {
    content: "";
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Success State */
.mpf-success-state {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 2.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
}

.mpf-success-state.active {
    opacity: 1;
    pointer-events: all;
}

.checkmark-animation {
    width: 80px;
    height: 80px;
    margin-bottom: 1.5rem;
}

.checkmark {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: block;
    stroke-width: 3;
    stroke: #10B981;
    stroke-miterlimit: 10;
}

.checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 3;
    stroke-miterlimit: 10;
    stroke: var(--success);
    fill: none;
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.6s forwards;
}

/* Animationen */
@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Mobile Optimization */
@media (max-width: 480px) {
    .mpf-popup {
        /* Zentrierung erfolgt jetzt über das Flex-Overlay, daher keine vh-Margin */
        padding: 1.5rem;
        width: 85%;
        max-width: none;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateZ(0);
        will-change: transform;
    }
    
    .mpf-field input {
        font-size: 16px;
        padding: 1rem;
    }
    
    .mpf-submit-btn {
        padding: 1.2rem;
    }
    
    .mpf-close {
        top: 1rem;
        right: 1rem;
    }
    
    .mpf-info-text {
        font-size: 0.85rem;
    }
}

@supports (-webkit-touch-callout: none) {
    .mpf-popup {
        margin-bottom: env(safe-area-inset-bottom);
    }
}