/* ========================================
   Modal System (Generisch für alle Popups)
   ======================================== */

/* Modal Fade-In/Out Animationen */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
}

/* Modal Overlay (Hintergrund) */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

/* Modal wird sichtbar mit Fade-In */
.modal-overlay.active {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

/* Modal wird ausgeblendet mit Fade-Out */
.modal-overlay.closing {
    animation: modalFadeOut 0.3s ease forwards;
}

/* Modal Container (Inhalt) */
.modal-container {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 90%;
    max-height: 95vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
    overscroll-behavior: contain; /* Verhindert, dass Scroll-Events zum Body durchsickern */
}

/* Medium Modal für mässig umfangreiche Formulare */
.modal-container.modal-medium {
    max-width: 600px;
    width: 95%;
}

/* Large Modal für umfangreiche Formulare */
.modal-container.modal-large {
    max-width: 800px;
    width: 95%;
}

/* Extra Large Modal für sehr umfangreiche Inhalte */
.modal-container.modal-xlarge {
    max-width: 1200px;
    width: 95%;
}

/* Small Modal für Bestätigungen */
.modal-container.modal-container-small {
    max-width: 450px;
    width: 90%;
}

/* Container Animation beim Öffnen */
.modal-overlay.active .modal-container {
    animation: modalSlideIn 0.3s ease;
}

/* Container Animation beim Schließen */
.modal-overlay.closing .modal-container {
    animation: modalSlideOut 0.3s ease forwards;
}

/* Force Modal (kann nicht geschlossen werden) */
.modal-overlay.modal-force {
    z-index: 9999;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.modal-overlay.modal-force .modal-container {
    border: 2px solid var(--primary-color);
}

.modal-info {
    margin: 0 0 1.5rem 0;
    padding: 1rem;
    background-color: rgba(220, 40, 20, 0.1);
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.form-help {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg-primary);
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-close .material-symbols-outlined {
    font-size: 24px;
}

.modal-body {
    padding: 1.5rem;
    background: var(--bg-secondary);
}

/* Confirm Modal Styles */
.confirm-message {
    margin: 0 0 1.5rem 0;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    padding: 1.5rem;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
}

.modal-actions button {
    flex: 0 1 auto;
    min-width: 120px;
}

.modal-actions-split {
    justify-content: space-between;
}

.modal-actions-left,
.modal-actions-right {
    display: flex;
    gap: 0.75rem;
}

.modal-actions-left {
    justify-content: flex-start;
}

.modal-actions-right {
    justify-content: flex-end;
}

/* Quill Editor Toolbar Sticky - bleibt unter Modal Header */
.modal-container .ql-toolbar {
    position: sticky;
    /* Modal Header: padding-top (1.5rem) + title line-height (~1.5rem) + padding-bottom (1.5rem) + border (1px) + toolbar-padding (8px) */
    top: calc(4.5rem + 9px);
    z-index: 5;
    background: var(--bg-primary);
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Mobile Optimierung */
@media (max-width: 768px) {
    .modal-container {
        max-height: 85vh;
        width: 95%;
        margin: 1rem;
    }

    .modal-container.modal-large {
        width: 95%;
        max-height: 90vh;
    }

    .modal-container.modal-xlarge {
        width: 95%;
        max-height: 90vh;
    }

    /* Touchscreen-optimiertes Scrolling */
    .modal-body {
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    /* Mehr Padding für bessere Touch-Bedienung */
    .modal-header,
    .modal-body {
        padding: 1rem;
    }

    /* Buttons zentrieren wenn Eingabefelder volle Breite einnehmen */
    .modal-actions {
        justify-content: center;
        padding: 1rem;
    }

    /* Quill Toolbar Position für Mobile anpassen (kleinerer Header) */
    .modal-container .ql-toolbar {
        /* Mobile Modal Header: padding-top (1rem) + title line-height (~1.5rem) + padding-bottom (1rem) + border (1px) + toolbar-padding (8px) */
        top: calc(3.5rem + 9px);
    }
}

/* ========================================
   Modal Error Messages
   ======================================== */
.modal-error {
    display: none;
    margin-bottom: 1.5rem;
}

.modal-error .error-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 8px;
    color: #c00;
    font-size: 0.9rem;
    line-height: 1.5;
}

.modal-error .error-message .material-symbols-outlined {
    flex-shrink: 0;
    font-size: 1.5rem;
    color: #c00;
}

.modal-error .error-message span:last-child {
    flex: 1;
}

/* ========================================
   Modal Info Text (für Hinweise/Warnungen)
   ======================================== */
.modal-info-text {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    margin-top: 1.5rem;
    background-color: rgba(220, 40, 20, 0.08);
    border-radius: 8px;
    line-height: 1.6;
}

.modal-info-text .modal-info-icon {
    flex-shrink: 0;
    font-size: 2rem;
    color: var(--accent-color);
}

.modal-info-text p {
    margin: 0;
    color: var(--text-primary);
}