﻿    
/* ======================================== */
/*                 Modal                   */
/* ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    /* Overlay-Höhe = sichtbarer Viewport (--vvh aus visualViewport, TxUiHelper.js).
       Mit `height: 100%` war das Overlay so hoch wie der Layout-Viewport (= inkl.
       Keyboard-Bereich auf iOS). Mit --vvh = sichtbarer Bereich. */
    height: var(--vvh, 100%);
    background-color: rgba(0, 0, 0, 0.2);

    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    /* iOS: Touches auf dem Backdrop dürfen nicht zum darunterliegenden Scroll-Container
       durchgereicht werden. touch-action:none verhindert das komplett, overscroll-behavior:contain
       blockt Scroll-Chaining für den Fall dass iOS doch versucht zu scrollen. */
    touch-action: none;
    overscroll-behavior: contain;
}

    .modal-overlay.active {
        opacity: 1;
        visibility: visible;
    }

/* iOS Keyboard / Scroll-Lock wird jetzt in TxUiHelper.js gehandhabt (MutationObserver
   + body.style.top = -scrollY mit !important + zwangsweise window.scrollTo(0,0)).
   CSS-only mit :has() reichte auf iOS nicht — iOS' input-focus Auto-Scroll umging
   die Sperre teils. JS-Lock ist robuster und merkt sich die Scroll-Position. */
body:has(.modal-overlay.active) .main-content {
    overflow: hidden;
}


.modal {
    overflow: visible;
    position: relative;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
    width: min(100vw, var(--modal-w, 700px));
    /* --vvh wird in TxUiHelper.js aus window.visualViewport.height gesetzt und
       tracked die tatsächliche sichtbare Höhe (Keyboard zieht ab). 100dvh greift
       auf iOS nicht zuverlässig — Footer rutschte hinter die Tastatur. */
    max-height: min(var(--vvh, 100dvh), 90vh);
    min-width: 250px;
    background: var(--body-bg);
    color: var(--text-color);
    /* KEINE height-Transition: Mit resizes-content (Android) verkleinert die Engine den
       Viewport synchron zur Tastatur, --vvh/Höhe folgt frame-genau. Eine Transition legt
       nur eine verzögerte Aufhol-Animation drüber → Modal ragt kurz hinter die Tastatur,
       bevor es "nachanimiert". Direkt tracken ist ruhiger. */
    /* Modal blockt grundsätzlich Touch-Gesten (Scroll/Pan) — sonst reicht iOS
       Wisch-Bewegungen auf Header/Footer durch zur darunterliegenden Page. Taps
       und Clicks sind keine Gesten und funktionieren unabhängig davon weiter,
       Inputs/Buttons reagieren also normal. Nur .modal-body bekommt unten explizit
       wieder pan-y für Content-Scroll. */
    touch-action: none;
}

.modal--sm {
    --modal-w: 420px;
}

.modal--md {
    --modal-w: 600px;
}

.modal--lg {
    --modal-w: 1100px;
    height:820px;
    max-height:95vH;
    
  
}


.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 5px 0px 20px;
    border-radius: 8px 8px 0 0;
    background: var(--primary);
}

.modal-header .hFlex {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.modal-header .hFlex h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.modal-header .help-button {
    background: transparent;
    border: none;
    color: white;
    padding: 4px 8px;
    cursor: pointer;
    opacity: 0.8;
    margin-left: auto;
    flex-shrink: 0;
}

.modal-header .help-button:hover {
    opacity: 1;
}

.modal-header .help-button i {
    font-size: 1.2rem;
}

.modal-body {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS: ermöglicht Momentum-Scroll im Modal */
    overscroll-behavior: contain; /* verhindert Bounce/Scroll-Chain auf den Body */
    /* Modal-weit ist touch-action:none gesetzt — hier vertikalen Scroll für den
       eigentlichen Content wieder erlauben. */
    touch-action: pan-y;
    line-height: normal;
    font-size: var(--font-size);
}

.modal-footer {
    padding: 10px 20px 10px 20px;
    border-top:1px solid var(--gray-300);
    gap: 15px;
    display: flex;
    justify-content: space-between;
}

.modal-footer-left {
    display: flex;
    gap: 10px;
    align-items: center;
}

.modal-footer-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

    .modal-footer-right .btn {
        min-width: 60px;
    }

/* Vollbild für md & lg auf kleinen Screens :) */
@media (max-width: 1000px) {
    .modal:not(.modal--sm) {
        width: 100vw !important;
        /* --vvh aus visualViewport (TxUiHelper.js) statt 100dvh — auf iOS bleibt
           dvh beim Keyboard-Auf/Zu zu groß, dadurch entsteht ein leerer Bereich
           zwischen Modal-Footer und Tastatur. */
        height: var(--vvh, 100dvh) !important;
        max-height: var(--vvh, 100dvh) !important;
        border-radius: 0 !important;

    }

    .modal-footer {
        padding: 10px 5px 10px 5px;
        border-top: 1px solid var(--gray-300);
        gap: 15px;
        display: flex;
    }

    /* kein Vollbild für das kleine Modal ;( */
    .modal--sm {
        width: min(calc(100vw - 32px), var(--modal-w, 420px));
        height: auto;
        max-height: min(var(--vvh, 100dvh), 90dvh);
        border-radius: var(--border-radius);
    }

    .modal-header {
        border-radius: 0;
    }
}

/* Top-Anchoring für große, floatende Modals auf NIEDRIGEN Viewports (z.B. Tablet quer).
   Dort frisst die Tastatur viel vertikalen Platz; ein zentriertes Modal würde beim
   Keyboard-Resize nach oben "wandern" (Re-Center-Sprung). Oben verankert ändert es nur
   die Höhe unten → deutlich ruhiger. margin-bottom:auto schiebt es trotz zentriertem
   Overlay nach oben, sodass .modal--sm (kleine Dialoge) weiter zentriert bleiben.
   Auf hohen Screens (Desktop, > 800px Höhe) greift die Regel nicht → bleibt zentriert.
   min-width:1001px = nur im floating-Regime (darunter sind Modals ohnehin Vollbild). */
@media (max-height: 800px) and (min-width: 1001px) {
    .modal:not(.modal--sm) {
        margin-top: 24px;
        margin-bottom: auto;
        max-height: min(calc(var(--vvh, 100dvh) - 48px), 90vh);
    }
}

@media (max-width: 400px) {
    .modal-body {
        padding:10px 5px;
    }

    .modal-footer {
        padding: 10px 5px 10px 5px;
        border-top: 1px solid var(--gray-300);
        gap: 15px;
        display: flex;
    }
}

    .no-overflow {
        overflow: hidden !important;
        padding: 0;
    }





