/* ===================================================================
   CHATBOT.CSS - AI Chatbot Widget
   Komplett responsive für Desktop, Tablet & Mobile
   Version 2.0 - Build: 2025-11-27-v2
   =================================================================== */

/* ===== CSS Custom Properties (Chatbot-spezifisch) ===== */
:root {
    --chat-primary: #6366f1;
    --chat-primary-hover: #4f46e5;
    --chat-bg: #0f0f23;
    --chat-bg-light: #1a1a2e;
    --chat-bg-hover: #252542;
    --chat-border: rgba(255, 255, 255, 0.1);
    --chat-text: #ffffff;
    --chat-text-muted: #a1a1aa;
    --chat-success: #10b981;
    --chat-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --chat-radius: 20px;
    --chat-radius-sm: 12px;
}

/* ===== Main Container ===== */
.chatbot-container {
    position: fixed;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Desktop: Bottom-right corner */
@media (min-width: 769px) {
    .chatbot-container {
        bottom: 24px;
        right: 24px;
    }
}

/* Tablet: Bottom-right with less margin */
@media (min-width: 481px) and (max-width: 768px) {
    .chatbot-container {
        bottom: 20px;
        right: 20px;
    }
}

/* Mobile: Bottom-right, will expand to fullscreen when open */
@media (max-width: 480px) {
    .chatbot-container {
        bottom: 16px;
        right: 16px;
    }
    
    .chatbot-container.chat-open {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
    }
}

/* ===== Floating Toggle Button ===== */
.chatbot-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow), 0 0 0 0 rgba(99, 102, 241, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    outline: none;
}

.chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: var(--chat-shadow), 0 0 0 8px rgba(99, 102, 241, 0.15);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chatbot-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: all 0.3s ease;
}

.chatbot-toggle.active svg {
    transform: rotate(180deg);
    opacity: 0;
}

/* Online indicator pulse */
.chatbot-toggle::before {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 14px;
    height: 14px;
    background: var(--chat-success);
    border-radius: 50%;
    border: 3px solid var(--chat-bg);
    animation: pulse-ring 2s ease-out infinite;
    z-index: 1;
}

.chatbot-toggle.active::before {
    display: none;
}

@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Hide button when chat is open on mobile */
@media (max-width: 480px) {
    .chatbot-toggle.active {
        opacity: 0;
        pointer-events: none;
        transform: scale(0);
    }
}

/* Tablet button size */
@media (min-width: 481px) and (max-width: 768px) {
    .chatbot-toggle {
        width: 58px;
        height: 58px;
    }
    
    .chatbot-toggle svg {
        width: 26px;
        height: 26px;
    }
}

/* ===== Chat Window ===== */
.chatbot-window {
    position: absolute;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.9);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Desktop: Floating window */
@media (min-width: 769px) {
    .chatbot-window {
        bottom: 80px;
        right: 0;
        width: 400px;
        height: 550px;
        border-radius: var(--chat-radius);
        box-shadow: var(--chat-shadow);
    }
}

/* Tablet: Slightly smaller window */
@media (min-width: 481px) and (max-width: 768px) {
    .chatbot-window {
        bottom: 74px;
        right: 0;
        width: 360px;
        height: 480px;
        border-radius: var(--chat-radius);
        box-shadow: var(--chat-shadow);
    }
}

/* Mobile: Fullscreen overlay */
@media (max-width: 480px) {
    .chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        transform: translateY(100%);
    }
    
    .chatbot-window.open {
        transform: translateY(0);
    }
}

/* ===== Chat Header ===== */
.chatbot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(180deg, var(--chat-bg-light) 0%, var(--chat-bg) 100%);
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.chatbot-info {
    flex: 1;
    min-width: 0;
}

.chatbot-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: var(--chat-text);
    margin: 0 0 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatbot-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--chat-success);
    font-weight: 500;
}

.chatbot-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--chat-success);
    border-radius: 50%;
    animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-close:hover {
    background: var(--chat-bg-hover);
    color: var(--chat-text);
}

.chatbot-close:active {
    transform: scale(0.9);
}

.chatbot-close svg {
    width: 20px;
    height: 20px;
}

/* Mobile header adjustments */
@media (max-width: 480px) {
    .chatbot-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }
    
    .chatbot-avatar {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .chatbot-info h4 {
        font-size: 14px;
    }
    
    .chatbot-close {
        width: 40px;
        height: 40px;
    }
}

/* ===== Messages Container ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Custom scrollbar - Desktop only */
@media (min-width: 481px) {
    .chatbot-messages::-webkit-scrollbar {
        width: 6px;
    }
    
    .chatbot-messages::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .chatbot-messages::-webkit-scrollbar-thumb {
        background: var(--chat-border);
        border-radius: 3px;
    }
    
    .chatbot-messages::-webkit-scrollbar-thumb:hover {
        background: var(--chat-text-muted);
    }
}

/* Mobile messages padding */
@media (max-width: 480px) {
    .chatbot-messages {
        padding: 16px;
        gap: 14px;
    }
}

/* ===== Chat Messages ===== */
.chat-message {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: message-in 0.3s ease-out;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.bot {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-message.bot .message-avatar {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
}

.chat-message.user .message-avatar {
    background: var(--chat-bg-hover);
    border: 1px solid var(--chat-border);
}

.message-content {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chat-message.bot .message-content {
    background: var(--chat-bg-light);
    color: var(--chat-text);
    border-radius: 18px 18px 18px 6px;
    border: 1px solid var(--chat-border);
}

.chat-message.user .message-content {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    color: white;
    border-radius: 18px 18px 6px 18px;
}

/* Mobile message adjustments */
@media (max-width: 480px) {
    .chat-message {
        max-width: 92%;
        gap: 8px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .message-content {
        padding: 10px 14px;
        font-size: 15px; /* Slightly larger for mobile readability */
    }
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: var(--chat-bg-light);
    border-radius: 18px 18px 18px 6px;
    border: 1px solid var(--chat-border);
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--chat-text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        background: var(--chat-text-muted);
    }
    30% {
        transform: translateY(-8px);
        background: var(--chat-primary);
    }
}

/* ===== Input Container ===== */
.chatbot-input-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    min-width: 0;
    padding: 14px 18px;
    background: var(--chat-bg-light);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    color: var(--chat-text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s ease;
}

.chatbot-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chatbot-input::placeholder {
    color: var(--chat-text-muted);
}

.chatbot-send {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-hover) 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    outline: none;
}

.chatbot-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.chatbot-send:active:not(:disabled) {
    transform: scale(0.95);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send svg {
    width: 20px;
    height: 20px;
    fill: white;
    transform: translateX(1px);
}

/* Mobile input adjustments */
@media (max-width: 480px) {
    .chatbot-input-container {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        gap: 10px;
    }
    
    .chatbot-input {
        padding: 12px 16px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    .chatbot-send {
        width: 44px;
        height: 44px;
    }
    
    .chatbot-send svg {
        width: 18px;
        height: 18px;
    }
}

/* ===== Welcome Screen ===== */
.chatbot-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 24px;
    height: 100%;
}

.chatbot-welcome h5 {
    font-size: 20px;
    font-weight: 600;
    color: var(--chat-text);
    margin: 0 0 8px 0;
}

.chatbot-welcome p {
    font-size: 14px;
    color: var(--chat-text-muted);
    margin: 0 0 28px 0;
    max-width: 260px;
}

.quick-questions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.quick-question {
    padding: 12px 16px;
    background: var(--chat-bg-light);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    color: var(--chat-text-muted);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.quick-question:hover {
    background: var(--chat-bg-hover);
    color: var(--chat-text);
    border-color: var(--chat-primary);
    transform: translateY(-2px);
}

.quick-question:active {
    transform: translateY(0);
}

/* Mobile welcome adjustments */
@media (max-width: 480px) {
    .chatbot-welcome {
        padding: 24px 20px;
    }
    
    .chatbot-welcome h5 {
        font-size: 18px;
    }
    
    .quick-questions {
        max-width: 100%;
    }
    
    .quick-question {
        padding: 14px 18px;
        font-size: 14px;
    }
}

/* ===== Anchor link style used inside bot messages ===== */
.chatbot-anchor {
    color: var(--chat-primary);
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
}

/* Highlight effect applied to target when jumped to */
.chat-scroll-highlight {
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12);
    transition: box-shadow 0.35s ease;
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    .chatbot-toggle,
    .chatbot-window,
    .chat-message,
    .chatbot-send,
    .quick-question {
        transition: none;
        animation: none;
    }
    
    .chatbot-toggle::before,
    .chatbot-status::before,
    .typing-indicator span {
        animation: none;
    }
}

/* Focus visible states */
.chatbot-toggle:focus-visible,
.chatbot-close:focus-visible,
.chatbot-send:focus-visible,
.chatbot-input:focus-visible,
.quick-question:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

/* ===== Dark mode is default, but handle light mode if vars exist ===== */
@media (prefers-color-scheme: light) {
    /* Keep dark theme for chatbot regardless of system preference */
    .chatbot-container {
        --chat-bg: #0f0f23;
        --chat-bg-light: #1a1a2e;
    }
}

/* ===== High Contrast Mode ===== */
@media (prefers-contrast: high) {
    .chatbot-window {
        border-width: 2px;
    }
    
    .message-content {
        border: 1px solid var(--chat-text-muted);
    }
    
    .chatbot-input {
        border-width: 2px;
    }
}
