/* Chatbot Styles */
/* Overlay hinter dem Chatbot zum Schließen per Klick außerhalb */
.chatbot-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 1100; /* über Header (1000) und mobile overlay (999) */
}

.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 16px; /* etwas weicher */
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    z-index: 1101; /* über eigenem Overlay */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Mobile Optimierungen für Chatbot */
@media (max-width: 768px) {
    .chatbot-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: calc(100vh - env(safe-area-inset-top));
        border-radius: 0;
        border: none;
    }

    .chatbot-toggle {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        right: 20px;
        z-index: 1102;
    }
}

/* Kleinere Screens - Chatbot nimmt ganzen Bildschirm ein */
@media (max-width: 480px) {
    .chatbot-container {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height für mobile Browser */
    }
}

.chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: #1a1a1a;
    border-radius: 50%;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: 1102; /* immer über allem */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}

.chatbot-toggle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatbot-toggle:hover {
    background: #000;
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .chatbot-toggle:active {
        transform: scale(0.95);
    }
}

.chatbot-header {
    background: #007bff;
    color: white;
    padding: 15px;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-title {
    font-weight: bold;
    font-size: 16px;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-messages {
    flex: 1;
    padding: 15px;
    padding-bottom: 8px; /* etwas Luft unter den Nachrichten */
    overflow-y: auto;
    max-height: 350px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Mobile: Dynamische Höhe für Chatbot Messages */
@media (max-width: 768px) {
    .chatbot-messages {
        max-height: none;
        flex: 1;
        padding: 15px;
    }
}

.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
}

.message.user {
    flex-direction: row-reverse;
}

.message-content {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.4;
}

.message.bot .message-content {
    background: #f1f1f1;
    color: #333;
    border-bottom-left-radius: 5px;
}

.message.user .message-content {
    background: #007bff;
    color: white;
    border-bottom-right-radius: 5px;
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    margin: 0 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message.bot .message-avatar {
    background: #1a1a1a;
    color: white;
}

.message.user .message-avatar {
    background: #6c757d;
    color: white;
}

.chatbot-input-area {
    padding: 15px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

/* Mobile: Bessere Tastatur-Handhabung */
@media (max-width: 768px) {
    .chatbot-input-area {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
        background: white;
        position: sticky;
        bottom: 0;
    }
}

.chatbot-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    resize: none;
}

/* Mobile: Verhindere iOS Zoom */
@media (max-width: 768px) {
    .chatbot-input {
        font-size: 16px; /* iOS zoomt nicht bei 16px+ */
    }
}

.chatbot-send-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.chatbot-send-btn:hover {
    background: #0056b3;
}

.chatbot-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.suggestions {
    margin-top: 10px;
}

.suggestion-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 15px;
    padding: 5px 10px;
    margin: 3px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
}

.suggestion-btn:hover {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.typing-indicator {
    display: none;
    margin-bottom: 15px;
}

.typing-indicator .message-content {
    background: #f1f1f1;
    color: #666;
    font-style: italic;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
/* Tablets: mehr Rand and geringere Höhe, nicht Fullscreen */
@media (max-width: 1024px) {
    .chatbot-container {
        width: 420px;
        height: min(70vh, 560px);
        bottom: 24px;
        right: 24px;
        left: auto;
    }

    .chatbot-toggle {
        bottom: 24px;
        right: 24px;
    }
}

/* Smartphones: kompakter, mit sicheren Randabständen; Bottom-Sheet-Layout */
@media (max-width: 600px) {
    .chatbot-container {
        width: clamp(280px, 96vw, 480px); /* min von 320 -> 280 reduziert */
        max-width: 96vw;
        left: 0;
        right: 0;
        margin: 0 auto;
        border-radius: 16px 16px 12px 12px;
        height: auto;
        max-height: 75vh;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    }

    .chatbot-messages { max-height: none; }

    .chatbot-toggle {
        right: max(12px, env(safe-area-inset-right, 0px) + 8px);
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
}

/* Nutze dynamische Viewport-Einheiten, wenn verfügbar (iOS/Android modern) */
@supports (height: 100dvh) {
  @media (max-width: 600px) {
    .chatbot-container { max-height: 78dvh; }
  }
  @media (max-width: 1024px) {
    .chatbot-container { height: auto; max-height: 70dvh; }
  }
}

/* Body Scroll-Lock wenn Chatbot offen */
body.chatbot-open { overflow: hidden; }
