/* Mobile-spezifische Fixes für Chatbot */

/* WICHTIG: Verhindere Chatbot-Öffnung beim Orientierungswechsel */
@media (max-width: 1024px) and (orientation: landscape) {
    /* Chat Window MUSS im Landscape-Modus GESCHLOSSEN bleiben */
    .chat-window,
    .chat-window.active {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transform: translateY(100%) !important;
    }
}

/* Wichtige Mobile Fixes mit höherer Spezifität */
@media (max-width: 768px) {
    /* Chat Window auf Mobile KOMPLETT AUSBLENDEN - Verwende dedizierte Seite */
    .chat-window {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Chat Toggle Button MUSS SICHTBAR SEIN */
    .chat-toggle {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        position: fixed !important;
        bottom: 20px !important;
        left: 20px !important;
        width: 65px !important;
        height: 65px !important;
        z-index: 999998 !important;
        box-shadow: 0 4px 20px rgba(235, 94, 40, 0.5) !important;
        cursor: pointer !important;
        background: #EB5E28 !important;
        border-radius: 50% !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Close Button hervorheben */
    .chat-close {
        background: #ff4444 !important;
        color: white !important;
        width: 42px !important;
        height: 42px !important;
        font-size: 24px !important;
        border: 2px solid white !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-weight: bold !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    }
    
    .chat-close:active {
        transform: scale(0.9) !important;
        background: #cc0000 !important;
    }
    
    /* Header kleiner auf Mobile */
    .chat-header {
        padding: 8px !important;
        min-height: 54px !important;
        flex-shrink: 0 !important;
    }
    
    .chat-header-text h3 {
        font-size: 0.8rem !important;
    }
    
    .chat-header-text p {
        font-size: 0.55rem !important;
        display: block !important; /* Zeige Datum/Zeit auch auf Mobile */
        line-height: 1.2 !important;
        margin-top: 2px !important;
    }
    
    .chat-avatar {
        width: 32px !important;
        height: 32px !important;
    }
    
    .chat-avatar img {
        width: 28px !important;
        height: 28px !important;
    }
    
    /* Header Actions kompakter */
    .chat-header-actions {
        gap: 4px !important;
    }
    
    .chat-email,
    .chat-print,
    .chat-whatsapp,
    .chat-clear {
        width: 28px !important;
        height: 28px !important;
        padding: 4px !important;
    }
    
    .chat-email svg,
    .chat-print svg,
    .chat-whatsapp svg,
    .chat-clear svg {
        width: 16px !important;
        height: 16px !important;
    }
    
    /* Print-Button auf Mobile verstecken */
    .chat-print {
        display: none !important;
    }
    
    /* Messages Container optimiert - MEHR PLATZ ohne Quick Actions */
    .chat-messages {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 10px !important;
        padding-bottom: 10px !important;
        min-height: 0 !important;
    }
    
    /* Input Container am Bottom fixiert */
    .chat-input-container {
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        padding: 8px !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
        border-top: 1px solid #eee !important;
        flex-shrink: 0 !important;
        margin-top: auto !important;
    }
    
    /* Input Field optimiert für Touch */
    .chat-input {
        font-size: 14px !important;
        padding: 8px 12px !important;
        border: 1.5px solid #ddd !important;
        border-radius: 25px !important;
        -webkit-appearance: none !important;
    }
    
    .chat-input:focus {
        outline: none !important;
        border-color: var(--chat-primary) !important;
    }
    
    /* Send Button größer für Touch */
    .chat-send {
        width: 42px !important;
        height: 42px !important;
        min-width: 42px !important;
    }
    
    /* Quick Actions - KOMPLETT AUSBLENDEN auf Mobile */
    .chat-quick-actions {
        display: none !important;
    }
    
    /* Emergency Buttons - KOMPLETT AUSBLENDEN auf Mobile */
    .chat-emergency {
        display: none !important;
    }
    
    /* Message Bubbles optimiert */
    .message-bubble {
        max-width: 85% !important;
        font-size: 0.75rem !important;
        line-height: 1.35 !important;
    }
    
    /* Dialog/Modal Fixes */
    .email-dialog-overlay {
        padding: 20px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 9999999 !important;
    }
    
    .email-dialog {
        width: auto !important;
        min-width: 280px !important;
        max-width: calc(100vw - 40px) !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        position: relative !important;
        z-index: 10000000 !important;
        margin: 20px !important;
    }
    
    .email-dialog-footer {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .email-dialog-footer button {
        width: 100% !important;
        padding: 12px !important;
    }
}

/* Sehr kleine Geräte (< 380px) */
@media (max-width: 380px) {
    .chat-toggle {
        width: 55px !important;
        height: 55px !important;
        bottom: 15px !important;
        left: 15px !important;
    }
    
    .chat-toggle svg {
        width: 25px !important;
        height: 25px !important;
    }
    
    .chat-header {
        padding: 10px !important;
    }
    
    .chat-header-text h3 {
        font-size: 0.8rem !important;
    }
    
    .chat-header-text p {
        font-size: 0.6rem !important;
    }
    
    .chat-header-actions {
        gap: 3px !important;
    }
    
    .chat-email,
    .chat-print,
    .chat-whatsapp,
    .chat-clear {
        width: 26px !important;
        height: 26px !important;
        padding: 3px !important;
    }
    
    .chat-email svg,
    .chat-print svg,
    .chat-whatsapp svg,
    .chat-clear svg {
        width: 16px !important;
        height: 16px !important;
    }
    
    .chat-close {
        width: 38px !important;
        height: 38px !important;
        font-size: 20px !important;
    }
    
    .message-bubble {
        font-size: 0.7rem !important;
        padding: 6px 8px !important;
        line-height: 1.3 !important;
    }
    
    .quick-action {
        font-size: 0.62rem !important;
        padding: 4px 6px !important;
        min-width: 70px !important;
        line-height: 1.15 !important;
    }
    
    .chat-input {
        font-size: 13px !important;
        padding: 7px 9px !important;
    }
    
    .chat-send {
        width: 40px !important;
        height: 40px !important;
    }
}

/* iOS-spezifische Fixes */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .chat-window {
            /* Safe area für iPhone X und neuer */
            height: 65vh !important;
            max-height: 65vh !important;
            min-height: 65vh !important;
            width: 92% !important;
            max-width: 420px !important;
            top: auto !important;
            bottom: 10px !important;
            left: 50% !important;
            transform: translateX(-50%) !important;
            border-radius: 20px !important;
            padding-bottom: 0 !important;
            display: flex !important;
            flex-direction: column !important;
        }
    }
    
    .chat-input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    }
    
    /* Verhindere Zoom auf iOS bei Focus */
    .chat-input {
        font-size: 16px !important; /* Muss 16px sein um Zoom zu verhindern */
        transform: scale(0.8125); /* Visuell kleiner machen (13px-Äquivalent) */
        transform-origin: left center;
        width: 123%; /* Kompensiere die Skalierung */
    }
    
    /* Fix für iOS Scrolling */
    .chat-messages {
        -webkit-overflow-scrolling: touch !important;
        transform: translateZ(0);
    }
}

/* Landscape Mode - Erweitert auf alle Tablets/iPads */
/* KEINE spezielle Landscape-Regel mehr hier - wird oben gehandhabt */

/* Stelle sicher, dass Dialoge immer im Vordergrund sind */
.email-dialog-overlay,
.chat-notification {
    z-index: 9999999 !important;
}

.email-dialog {
    z-index: 10000000 !important;
}

/* Touch-optimierte Hover-States */
@media (hover: none) and (pointer: coarse) {
    .chat-close:hover {
        background: #ff4444 !important;
        transform: none !important;
    }
    
    .quick-action:hover {
        transform: none !important;
    }
    
    .chat-toggle:hover {
        transform: none !important;
    }
    
    /* Tap-Feedback statt Hover */
    .chat-close:active,
    .quick-action:active,
    .emergency-button:active,
    .directions-button:active,
    .chat-send:active {
        opacity: 0.7 !important;
    }
}
