/* ===================================================================
   Zemra Chat Image - Upload-Modal, Anzeige, Schutz
   =================================================================== */

/* ===== Image-Button im Chat-Form ===== */
.chat-input-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-image-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 24px;
    padding: 8px 10px;
    border-radius: 50%;
    transition: background 0.2s;
    line-height: 1;
}

.chat-image-btn:hover {
    background: #f3f4f6;
}

/* ===== Image-Upload Modal ===== */
.zemra-chat-image-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 99998;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.zemra-chat-image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.zemra-chat-image-container {
    position: relative;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: zemraSlideUp 0.3s ease;
}

.zemra-chat-image-close {
    position: absolute;
    top: 12px; right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    width: 32px; height: 32px;
    line-height: 1;
}

.zemra-chat-image-container h3 {
    margin: 0 0 16px !important;
    font-size: 20px;
    color: #1a1a1a !important;
    -webkit-text-fill-color: #1a1a1a !important;
}

/* Dropzone */
.zemra-chat-image-dropzone {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
    margin-bottom: 16px;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}


/* Native File Input: nicht display:none, damit Android/iOS den Bildwähler zuverlässig öffnen. */
.zemra-chat-image-dropzone {
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.zemra-chat-image-native-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.001;
    cursor: pointer;
    z-index: 5;
}
.zemra-chat-image-placeholder,
.zemra-chat-image-preview {
    position: relative;
    z-index: 2;
    pointer-events: none;
}
.zemra-chat .chat-image-btn {
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 3;
}
.zemra-chat-image-modal {
    z-index: 1000002;
}
.zemra-chat-image-container {
    z-index: 1000003;
}

.zemra-chat-image-dropzone:hover,
.zemra-chat-image-dropzone.is-dragover {
    border-color: #ff4458;
    background: #fff5f7;
}

.zemra-chat-image-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.zemra-chat-image-placeholder p {
    color: #6b7280;
    margin: 0;
}

.zemra-chat-image-placeholder small {
    color: #9ca3af;
    font-size: 12px;
}

.zemra-chat-image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
}

/* Mode-Optionen */
.zemra-chat-image-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.zemra-chat-image-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.zemra-chat-image-option:hover {
    background: #f3f4f6;
}

.zemra-chat-image-option:has(input:checked) {
    background: #fff5f7;
    border-color: #ff4458;
}

.zemra-chat-image-option-snap:has(input:checked) {
    background: linear-gradient(135deg, #fef3c7, #fef9c3);
    border-color: #fbbf24;
}

.zemra-chat-image-option input[type="radio"] {
    accent-color: #ff4458;
}

.zemra-chat-image-option select {
    margin-left: 6px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
}

/* Actions */
.zemra-chat-image-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.zemra-chat-image-progress {
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    margin-top: 12px;
    overflow: hidden;
}

.zemra-chat-image-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff4458, #fd267d);
    width: 0;
    transition: width 0.3s ease;
}

.zemra-chat-image-message {
    margin-top: 12px;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
    display: none;
}

.zemra-chat-image-message.success {
    display: block;
    background: #d1fae5;
    color: #065f46;
}

.zemra-chat-image-message.error {
    display: block;
    background: #fee2e2;
    color: #991b1b;
}

/* ===== Chat-Bilder Anzeige ===== */
.chat-message-image {
    margin: 8px 0;
    max-width: 280px;
}

.chat-image {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    cursor: zoom-in;
    /* Schutz-Styles */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: auto;
}

/* Auto-Delete-Bilder: Spezielle Optik */
.chat-image-wrapper-auto {
    position: relative;
    display: inline-block;
}

.chat-image-auto {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    cursor: pointer;
    border: 3px solid #fbbf24;
    /* Schutz-Styles */
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.chat-image-auto-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #fff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
}

.chat-image-auto-hint {
    text-align: center;
    color: #92400e;
    font-size: 12px;
    margin-top: 4px;
    background: #fef3c7;
    padding: 4px 10px;
    border-radius: 6px;
}

/* Vor dem ersten Klick: blurriges Bild */
.chat-image-auto:not(.is-viewed) {
    filter: blur(20px);
    transition: filter 0.3s;
}

.chat-image-auto.is-viewed {
    filter: none;
}

.chat-image-auto-tap-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    pointer-events: none;
}

.chat-image-auto.is-viewed + .chat-image-auto-tap-overlay {
    display: none;
}

/* Countdown */
.zemra-image-countdown {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    animation: zemraCountdownPulse 1s infinite;
}

@keyframes zemraCountdownPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Expired-Bild */
.chat-image-expired {
    background: #f3f4f6;
    padding: 20px;
    text-align: center;
    border-radius: 12px;
    color: #6b7280;
    border: 2px dashed #d1d5db;
}

/* Watermark-Overlay über Bild */
.chat-image-watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    font-size: 18px;
    font-weight: 700;
    color: rgba(255,255,255,0.3);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.4);
    transform: rotate(-30deg);
    user-select: none;
}

/* System-Warnung (Screenshot-Versuch) */
.chat-message-system_warning {
    background: linear-gradient(135deg, #fee2e2, #fef3c7);
    color: #991b1b !important;
    border-left: 4px solid #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    text-align: center;
    font-weight: 600;
}

/* Schutz-Warnung Toast */
.zemra-protection-warning {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(220, 38, 38, 0.95);
    color: #fff;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    z-index: 999999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    animation: zemraSlideUpToast 0.3s ease;
}

@keyframes zemraSlideUpToast {
    from { transform: translate(-50%, 30px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* Mobile */
@media (max-width: 768px) {
    .zemra-chat-image-container {
        padding: 16px;
        max-width: 100%;
    }
    
    .chat-image, .chat-image-auto {
        max-width: 240px;
    }
    
    .zemra-chat-image-dropzone {
        min-height: 140px;
    }
}

/* ===== Spam-Warnung an Sender ===== */
.zemra-chat-warning {
    display: none;
    background: linear-gradient(135deg, #fef3c7, #fee2e2);
    color: #92400e;
    border-left: 4px solid #f59e0b;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    font-size: 14px;
    line-height: 1.4;
    font-weight: 500;
}

/* ===== Bild-Lightbox (Großansicht) ===== */
.zemra-image-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
    animation: zemraLightboxFade 0.15s ease;
}

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

.zemra-lightbox-img {
    max-width: 95%;
    max-height: 95%;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    cursor: default;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.zemra-lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    color: #ff3b3b;
    font-size: 40px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    z-index: 1000000;
    text-shadow: 0 2px 8px rgba(0,0,0,0.6);
    transition: all 0.15s;
}

.zemra-lightbox-close:hover {
    transform: scale(1.25);
    color: #ff1a1a;
}

/* Auto-Delete Bild beim Sender nach Ablauf: dezent grün markiert */
.chat-image-expired-sender {
    background: #f0fdf4 !important;
    border: 1px dashed #86efac !important;
    color: #15803d !important;
}

/* Klarstellung: angesehene Auto-Delete-Bilder sind auch zoombar */
.chat-image-auto.is-viewed {
    cursor: zoom-in;
}


/* v3.13.3 Mobile Upload/Lightbox Fix */
@media (max-width: 768px) {
    .zemra-chat-image-modal {
        align-items: flex-end;
        padding: 10px;
    }
    .zemra-chat-image-container {
        width: 100%;
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
        border-radius: 18px 18px 12px 12px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .zemra-chat-image-dropzone {
        min-height: 190px;
    }
    .zemra-chat-image-actions .zemra-btn,
    #zemraChatImageSend {
        min-height: 46px;
    }
    .chat-message-image,
    .chat-image,
    .chat-image-auto {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

/* v3.13.4 Mobile Bildversand Fix: Vorschau + Sendebutton sicher sichtbar */
@media (max-width: 768px) {
    .zemra-chat-image-container {
        max-height: calc(100dvh - 16px) !important;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }
    .zemra-chat-image-dropzone {
        min-height: 150px !important;
        padding: 14px 12px !important;
        flex: 0 0 auto;
    }
    .zemra-chat-image-preview {
        max-height: 210px !important;
        object-fit: contain !important;
    }
    .zemra-chat-image-options {
        flex: 0 0 auto;
        margin-bottom: 10px !important;
    }
    .zemra-chat-image-option {
        padding: 10px 12px !important;
        font-size: 14px !important;
    }
    .zemra-chat-image-actions {
        position: sticky;
        bottom: 0;
        z-index: 20;
        background: #fff;
        padding-top: 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        border-top: 1px solid #f1f1f1;
    }
    .zemra-chat-image-actions .zemra-btn,
    #zemraChatImageSend {
        min-height: 48px !important;
        font-size: 15px !important;
        font-weight: 700 !important;
    }
}

/* v3.13.5: Mobile Inline-Bildvorschau direkt über der Chat-Eingabe */
@media (max-width: 768px) {
    .zemra-mobile-image-preview-bar {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(72px + env(safe-area-inset-bottom));
        z-index: 1000004;
        display: none;
        align-items: center;
        gap: 10px;
        padding: 9px;
        background: #ffffff;
        border: 1px solid rgba(0,0,0,0.08);
        border-radius: 18px;
        box-shadow: 0 10px 35px rgba(0,0,0,0.22);
    }

    .zemra-chat.has-mobile-image-preview .chat-messages {
        padding-bottom: 155px !important;
    }

    .zemra-mobile-image-preview-close {
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
        border: 0;
        border-radius: 50%;
        background: #111827;
        color: #fff;
        font-size: 22px;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .zemra-mobile-image-preview {
        flex: 0 0 58px;
        width: 58px;
        height: 58px;
        border-radius: 12px;
        object-fit: cover;
        background: #f3f4f6;
    }

    .zemra-mobile-image-preview-info {
        min-width: 0;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        gap: 1px;
        color: #111827;
        font-size: 13px;
        line-height: 1.25;
    }

    .zemra-mobile-image-preview-info strong {
        color: #111827;
        font-size: 14px;
    }

    .zemra-mobile-image-preview-info span {
        color: #4b5563;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .zemra-mobile-image-preview-message {
        font-size: 12px;
        min-height: 15px;
    }

    .zemra-mobile-image-preview-message.error {
        color: #b91c1c;
        font-weight: 700;
    }

    .zemra-mobile-image-preview-message.success {
        color: #047857;
        font-weight: 700;
    }

    .zemra-mobile-image-send {
        flex: 0 0 auto;
        border: 0;
        border-radius: 999px;
        padding: 12px 14px;
        background: #e30613;
        color: #fff;
        font-weight: 800;
        min-width: 74px;
        box-shadow: 0 4px 12px rgba(227,6,19,0.25);
    }

    .zemra-mobile-image-send:disabled {
        opacity: 0.65;
    }
}


/* v3.13.7: mobile direct image-send feedback */
.zemra-chat .message.is-pending .message-bubble {
    opacity: .82;
}
.zemra-chat .message.is-pending .chat-image,
.zemra-chat .message.is-pending .chat-image-auto {
    filter: saturate(.85);
}
.zemra-chat .message.is-failed .message-bubble {
    outline: 2px solid rgba(220, 38, 38, .35);
}
.zemra-image-send-state {
    margin-top: 6px;
    font-size: 12px;
    color: #b91c1c;
    font-weight: 700;
}
.zemra-chat .chat-message-image img.chat-image,
.zemra-chat .chat-message-image img.chat-image-auto {
    display: block !important;
    max-width: min(240px, 66vw) !important;
    max-height: 320px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* ===== Lösch-Button für eigene Nachrichten ===== */
.message-delete-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    opacity: 0.45;
    padding: 2px 4px;
    margin-left: 6px;
    line-height: 1;
    transition: opacity 0.15s, transform 0.15s;
    vertical-align: middle;
}

.message-delete-btn:hover {
    opacity: 1;
    transform: scale(1.15);
}

/* Auf Mobile etwas größer für besseren Touch */
@media (max-width: 768px) {
    .message-delete-btn {
        font-size: 15px;
        opacity: 0.6;
        padding: 4px 6px;
    }
}


/* Zemra 3.16.2: Upload-Senden-Button zuverlässig bedienbar */
#zemraChatImageSend,
#zemraMobileImageSend {
    pointer-events: auto !important;
    position: relative !important;
    z-index: 100003 !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
}
#zemraChatImageSend:not(:disabled),
#zemraMobileImageSend:not(:disabled) {
    opacity: 1 !important;
    visibility: visible !important;
}


/* 3.17.1 – stabile Modal-Aktionsleiste */
.zemra-chat-image-actions {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
    width: 100% !important;
    position: relative !important;
    z-index: 100004 !important;
}
.zemra-chat-image-actions > button {
    position: relative !important;
    inset: auto !important;
    margin: 0 !important;
    min-width: 120px !important;
    pointer-events: auto !important;
}
@media (max-width: 480px) {
    .zemra-chat-image-actions > button { min-width: 0 !important; flex: 1 1 0 !important; }
}


/* 3.18.0 – nur normale Chatbilder */
.zemra-chat-image-info {
    margin: 12px 0; padding: 10px 12px; border-radius: 10px;
    background: #f7f7f7; color: #222; font-size: 14px; line-height: 1.4;
}
.zemra-chat-image-options, .zemra-chat-image-option-snap { display: none !important; }

/* ===================================================================
   v3.20 FINAL: Sauberes Modal-Layout - behebt abgeschnittenen Abbrechen-Button
   Überschreibt alle vorherigen widersprüchlichen Regeln.
   =================================================================== */
.zemra-chat-image-modal {
    display: none;
    position: fixed !important;
    inset: 0 !important;
    z-index: 1000000 !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 16px !important;
    box-sizing: border-box !important;
}
.zemra-chat-image-modal.is-open,
.zemra-chat-image-modal[style*="flex"] { display: flex !important; }

.zemra-chat-image-container {
    position: relative !important;
    background: #fff !important;
    border-radius: 16px !important;
    padding: 20px !important;
    width: 100% !important;
    max-width: 460px !important;
    max-height: calc(100vh - 32px) !important;
    max-height: calc(100dvh - 32px) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch;
}

/* Actions immer unten, immer sichtbar, nie abgeschnitten */
.zemra-chat-image-actions {
    display: flex !important;
    gap: 10px !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100% !important;
    margin-top: 16px !important;
    flex: 0 0 auto !important;
    box-sizing: border-box !important;
}
.zemra-chat-image-actions .zemra-btn {
    flex: 1 1 0 !important;
    min-height: 46px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

/* Auf kleinen Handys: etwas mehr Platz unten für die Safe-Area (iPhone-Leiste) */
@media (max-width: 768px) {
    .zemra-chat-image-container {
        padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
}

/* Alte Auto-Delete-Auswahl in JEDER Form ausblenden (ROT markiert) */
.zemra-chat-image-options,
.zemra-chat-image-option-snap,
.zemra-chat-image-mode,
.zemra-chat-image-expire,
[data-image-mode],
.zemra-snap-options { display: none !important; }
