/* Container und Variablen */
#n8n-chat-wrapper {
    position: fixed;
    bottom: 30px;
    z-index: 9999999; /* Maximaler Z-Index */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    box-sizing: border-box;
}

#n8n-chat-wrapper * {
    box-sizing: border-box;
}

#n8n-chat-wrapper.position-right { right: 30px; }
#n8n-chat-wrapper.position-left { left: 30px; right: auto; }

/* Toggle Button */
#n8n-chat-toggle {
    background-color: var(--chat-primary, #2563eb) !important;
    color: white !important;
    border: none;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    animation: n8n-pulse 4s infinite;
    z-index: 10000000;
}

@keyframes n8n-pulse {
    0% { transform: scale(1); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
    50% { transform: scale(1.05); box-shadow: 0 12px 30px rgba(0,0,0,0.3); }
    100% { transform: scale(1); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
}

#n8n-chat-toggle:hover {
    animation: none;
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}

.n8n-chat-status-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 18px;
    height: 18px;
    background-color: #4ade80 !important;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Chat Fenster */
#n8n-chat-window {
    position: absolute;
    bottom: 90px;
    width: 380px; 
    height: 600px;
    max-height: 80vh;
    background: white !important;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 1px solid rgba(0,0,0,0.05);
    z-index: 9999999;
}

.position-right #n8n-chat-window { right: 0; transform-origin: bottom right; }
.position-left #n8n-chat-window { left: 0; right: auto; transform-origin: bottom left; }

/* Sichtbarkeit Steuerung */
#n8n-chat-window.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.9) translateY(20px) !important;
    display: none !important; /* Hartes Ausblenden */
}

#n8n-chat-window:not(.hidden) {
    display: flex !important; /* Hartes Einblenden als Flexbox */
    opacity: 1 !important;
    pointer-events: all !important;
    transform: scale(1) translateY(0) !important;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary, #2563eb), #1e40af) !important;
    color: white !important;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-info { display: flex; align-items: center; gap: 12px; }

.avatar-container { position: relative; width: 42px; height: 42px; }

.bot-avatar-small, .bot-avatar-placeholder {
    width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
    background: white; border: 2px solid rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    color: var(--chat-primary, #2563eb);
}

.online-indicator-avatar {
    position: absolute; bottom: 0; right: 0; width: 12px; height: 12px;
    background-color: #4ade80; border: 2px solid var(--chat-primary, #2563eb); border-radius: 50%;
}

.header-text { display: flex; flex-direction: column; line-height: 1.2; }
.bot-name { font-weight: 700; font-size: 16px; color: white !important; margin: 0; }
.bot-status { font-size: 12px; opacity: 0.9; color: rgba(255,255,255,0.9) !important; }

#n8n-chat-close {
    background: rgba(255,255,255,0.1); border: none; color: white !important;
    width: 30px; height: 30px; border-radius: 50%; font-size: 20px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
#n8n-chat-close:hover { background: rgba(255,255,255,0.25); }

/* Nachrichten */
#chat-messages {
    flex: 1; padding: 20px; overflow-y: auto; background-color: #f8fafc !important;
    display: flex; flex-direction: column; gap: 12px; width: 100%;
}

#chat-messages p { margin: 0 0 8px 0; padding: 0; line-height: 1.5; }
#chat-messages p:last-child { margin-bottom: 0; }

/* Nachrichten Wrapper */
#n8n-chat-window .message-wrapper {
    display: flex; flex-direction: column; 
    max-width: 85%; width: auto; min-width: 0; margin-bottom: 4px;
}

#n8n-chat-window .message-wrapper.bot { align-self: flex-start; align-items: flex-start; margin-right: auto; }
#n8n-chat-window .message-wrapper.user { align-self: flex-end; align-items: flex-end; margin-left: auto; }

/* Blasen */
#n8n-chat-window .message {
    padding: 12px 16px; border-radius: 14px; font-size: 13px !important;
    line-height: 1.5 !important; overflow-wrap: anywhere; word-break: break-word;
    position: relative; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    width: fit-content; max-width: 100%;
}

#n8n-chat-window .message.bot {
    background-color: var(--chat-bot-bg, #f3f4f6) !important; 
    color: var(--chat-bot-text, #1f2937) !important;
    border-bottom-left-radius: 2px;
}

#n8n-chat-window .message.user {
    background-color: var(--chat-user-bg, #2563eb) !important;
    color: var(--chat-user-text, #ffffff) !important;
    border-bottom-right-radius: 2px;
}

#n8n-chat-window .message-time {
    font-size: 11px !important; color: #94a3b8 !important; margin-top: 4px;
}
#n8n-chat-window .message-wrapper.user .message-time { text-align: right; }

/* Input */
.chat-input-area {
    padding: 20px; background: white !important; border-top: 1px solid #f1f5f9;
    display: flex; gap: 12px; align-items: center; flex-shrink: 0;
}

#chat-input-field {
    flex: 1; border: 1px solid #e2e8f0 !important; background-color: #f8fafc !important;
    color: #333 !important; border-radius: 24px !important; padding: 12px 18px !important;
    outline: none; font-size: 15px !important; margin: 0 !important; height: auto !important; box-shadow: none !important;
}

#chat-input-field:focus {
    border-color: var(--chat-primary, #2563eb) !important; background-color: white !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
}

#chat-send-btn {
    background: var(--chat-primary, #2563eb) !important; color: white !important;
    border: none !important; border-radius: 50% !important; width: 44px !important;
    height: 44px !important; padding: 0 !important; display: flex; align-items: center;
    justify-content: center; cursor: pointer; flex-shrink: 0; box-shadow: none !important;
}
#chat-send-btn svg { width: 20px; height: 20px; stroke: white !important; }

.typing-indicator { font-size: 12px !important; color: #64748b !important; margin-left: 10px; font-style: italic; margin-bottom: 5px; }

/* Mobile */
@media (max-width: 480px) {
    #n8n-chat-wrapper { bottom: 20px !important; right: 20px !important; }
    #n8n-chat-wrapper.position-left { left: 20px !important; right: auto !important; }
    #n8n-chat-window {
        width: calc(100vw - 40px) !important; position: fixed !important; bottom: 90px !important;
        right: 20px !important; left: 20px !important; margin: 0 !important; height: 70vh !important;
    }
}