/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    font-family: Arial, sans-serif;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 15px 15px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-title {
    font-size: 14px !important;
    font-weight: bold;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
}

.message {
    margin-bottom: 15px;
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
}

.user .bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 5px;
}

.assistant .bubble {
    background: #e9ecef;
    color: #333;
    border-bottom-left-radius: 5px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #e9ecef;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    max-width: 80%;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #764ba2;
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

.chat-input-container {
    position: relative;
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: white;
    border-radius: 0 0 15px 15px;
}

.chat-input {
    width: 100%;
    padding: 12px 50px 12px 15px
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.3s;
}

.chat-input:focus {
    border-color: #667eea;
}

.send-button {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px; /* Statt 50% für rechteckige Form */
    width: 30px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 999;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Markdown Styles */
.markdown-content {
    line-height: 1.6;
}

.markdown-content h1 {
    font-size: 1.4em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.3em;
    margin: 1em 0 0.5em 0;
}

.markdown-content h2 {
    font-size: 1.3em;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.2em;
    margin: 1em 0 0.5em 0;
}

.markdown-content h3 {
    font-size: 1.2em;
    color: #764ba2;
    margin: 0.8em 0 0.4em 0;
}

.markdown-content p {
    margin: 0.8em 0;
}

.markdown-content ul,
.markdown-content ol {
    margin: 0.8em 0;
    padding-left: 1.5em;
}

.markdown-content li {
    margin: 0.3em 0;
}

.markdown-content strong {
    font-weight: 600;
    color: #2c3e50;
}

.markdown-content em {
    font-style: italic;
    color: #555;
}

.markdown-content code {
    background: #f4f4f4;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.markdown-content pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1em 0;
    border-left: 4px solid #667eea;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 1em;
    margin: 1em 0;
    color: #666;
    font-style: italic;
}

/* ✅ ERWEITERTE STYLES FÜR CSS */
.emoji {
    display: inline-block;
    margin: 0 0.2em;
    font-size: 1.1em;
    transition: transform 0.2s ease;
}

.emoji:hover {
    transform: scale(1.2);
}

.language-javascript,
.language-python,
.language-bash {
    color: #e2e8f0;
}

.language-javascript .keyword { color: #ff79c6; }
.language-javascript .string { color: #f1fa8c; }
.language-javascript .number { color: #bd93f9; }

/* Eskalations-Formular Styles */
.escalation-form {
    background: #f8f9fa;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 15px;
    margin: 10px 0;
    max-width: 100%;
    box-sizing: border-box;
}

.escalation-form h4 {
    margin: 0 0 10px 0;
    color: #667eea;
    font-size: 16px;
    font-weight: 600;
}

.escalation-form p {
    margin: 0 0 15px 0;
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.form-group {
    margin-bottom: 12px;
}

.escalation-form input,
.escalation-form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
    transition: border-color 0.3s;
}

.escalation-form input:focus,
.escalation-form textarea:focus {
    border-color: #667eea;
    outline: none;
}

.escalation-form textarea {
    height: 80px;
    resize: vertical;
    min-height: 60px;
}

.escalation-form input[placeholder*="Geburtstermin"] {
    border-left: 3px solid #ff69b4;
}

.escalation-form input[placeholder*="Geburtstermin"]:focus {
    border-color: #ff69b4;
    box-shadow: 0 0 0 2px rgba(255, 105, 180, 0.2);
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.btn-primary {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 5px;
    cursor: pointer;
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 5px;
    cursor: pointer;
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #5a6fd8;
}

.btn-secondary:hover {
    background: #545b62;
}

.form-required {
    color: #e74c3c;
    font-size: 12px;
    margin-top: 5px;
}

/* ✅ Positionierungsklassen */
.chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.chat-widget.top-right {
    top: 20px;
    right: 20px;
}

.chat-widget.top-left {
    top: 20px;
    left: 20px;
}

.chat-toggle.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chat-toggle.bottom-left {
    bottom: 20px;
    left: 20px;
}

.chat-toggle.top-right {
    top: 20px;
    right: 20px;
}

.chat-toggle.top-left {
    top: 20px;
    left: 20px;
}

/* === CHAT TOGGLE ANIMATION STYLES === */
/* ✅ STANDARD ANIMATION FÜR BLAUE WIDGETS */
@keyframes one-time-attention {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    25%, 75% {
        transform: scale(1.2);
        box-shadow: 0 0 30px rgba(102, 126, 234, 0.8);
        background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 40px rgba(118, 75, 162, 1);
        background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    }
}

/* ✅ KORREKTE FAMICORD ANIMATION */
@keyframes famicord-attention-with-movement {
    0%, 100% {
        transform: scale(1) translateY(0);
        box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    }
    20%, 60% {
        transform: scale(1.3) translateY(-35px);
        box-shadow: 0 0 40px rgba(249, 115, 22, 0.9);
        background: linear-gradient(135deg, #ea580c 0%, #f97316 100%);
    }
    40%, 80% {
        transform: scale(1.15) translateY(25px);
        box-shadow: 0 0 60px rgba(249, 115, 22, 1);
        background: linear-gradient(135deg, #dc2626 0%, #ea580c 100%);
    }
}

/* ✅ VEREINFACHTE ANIMATION SELECTORS */
.chat-toggle[data-widget-id*="fami"],
.chat-toggle[data-widget-associated*="fami"] {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%) !important;
    animation: famicord-attention-with-movement 1.5s ease-in-out 2s both !important;
}

/* ✅ FAMICORD WIDGET STYLES */
.chat-widget[data-widget-id*="fami"] .send-button {
    background: #f97316 !important;
    transition: all 0.3s ease;
}

.chat-widget[data-widget-id*="fami"] .send-button:hover {
    background: #ea580c !important;
    transform: scale(1.05) translateY(-50%);
}

.chat-widget[data-widget-id*="fami"] .chat-input:focus {
    border-color: #f97316 !important;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2) !important;
}

.chat-widget[data-widget-id*="fami"] .user .bubble {
    background: linear-gradient(135deg, #1e40af 0%, #1d4ed8 100%) !important;
    color: white;
    border-bottom-right-radius: 5px;
}

.chat-widget[data-widget-id*="fami"] .assistant .bubble {
    background: #f1f5f9 !important;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 5px;
}

.chat-widget[data-widget-id*="fami"] .typing-indicator {
    background: #f1f5f9 !important;
    border: 1px solid #e2e8f0;
}

.chat-widget[data-widget-id*="fami"] .typing-dot {
    background: #1e40af !important;
}

.chat-widget[data-widget-id*="fami"] .chat-header {
    background: linear-gradient(135deg, #1a365d 0%, #2d3748 100%);
}

.chat-widget[data-widget-id*="fami"] .btn-primary {
    background: #1e40af;
}

.chat-widget[data-widget-id*="fami"] .btn-primary:hover {
    background: #1d4ed8;
}

.chat-widget[data-widget-id*="fami"] .escalation-form {
    border-color: #1e40af;
}

.chat-widget[data-widget-id*="fami"] .escalation-form h4 {
    color: #1e40af;
}

/* ✅ ENHANCED BROWSER COMPATIBILITY STYLES - CENTRAL */
/* Reset and normalize for consistent rendering */
.chat-widget * {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}

/* Improved touch targets for mobile */
.chat-toggle {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.chat-close {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 44px; /* Minimum touch target size */
    min-width: 44px;
}

.send-button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Safari-specific fixes */
@supports (-webkit-touch-callout: none) {
    .chat-widget {
        -webkit-overflow-scrolling: touch;
    }

    .chat-messages {
        -webkit-overflow-scrolling: touch;
        overflow-y: scroll;
    }

    .chat-input {
        font-size: 16px; /* Prevents zoom on iOS */
        transform: translateZ(0); /* Hardware acceleration */
    }
}

/* Firefox specific fixes */
@-moz-document url-prefix() {
    .chat-messages {
        scrollbar-width: thin;
        scrollbar-color: #cbd5e0 #f7fafc;
    }
}

/* Internet Explorer/Edge fallbacks */
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    .chat-widget {
        border: 1px solid #e2e8f0; /* Fallback for box-shadow */
    }

    .chat-toggle {
        background: #f97316; /* Fallback for gradient */
    }
}

/* Chrome scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Improved responsive design */
@media (max-width: 480px) {
    /* Prevent text size adjustment on orientation change */
    .chat-widget html {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* Orientation-specific styles */
@media (max-width: 480px) and (orientation: landscape) {
    .chat-widget {
        height: 80vh !important;
        max-height: 80vh !important;
    }
}

/* High-DPI screen optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .chat-toggle {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .chat-toggle {
        animation: none !important;
        transition: none !important;
    }

    .message {
        animation: none !important;
    }

    .typing-dot {
        animation: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .chat-widget {
        background: #1a202c;
        color: #e2e8f0;
    }

    .chat-input {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .chat-messages {
        background: #2d3748;
    }
}

/* Touch active state */
.chat-toggle.touch-active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* ✅ FIX FÜR DARK MODE PROBLEME */
@media (prefers-color-scheme: dark) {
    .chat-widget,
    .chat-messages,
    .assistant .bubble,
    .chat-input,
    .chat-input-container {
        background: #f8f9fa !important;
        color: #333 !important;
    }
    
    .chat-widget {
        border: 1px solid #e0e0e0;
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    }
}