/* ========================================
   AI CHATBOT WIDGET - OLIWIER1PL
   ======================================== */

/* ====== FLOATING BUTTON ====== */
.chatbot-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient, linear-gradient(135deg, #4f46e5, #06b6d4));
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(79, 70, 229, 0.4);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    animation: chatbot-pulse 2s infinite;
}

.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(79, 70, 229, 0.5);
}

.chatbot-trigger i {
    font-size: 1.6rem;
    color: white;
    transition: transform 0.3s ease;
}

.chatbot-trigger.active i {
    transform: rotate(180deg);
}

@keyframes chatbot-pulse {

    0%,
    100% {
        box-shadow: 0 8px 32px rgba(79, 70, 229, 0.4);
    }

    50% {
        box-shadow: 0 8px 32px rgba(79, 70, 229, 0.6), 0 0 0 10px rgba(79, 70, 229, 0.1);
    }
}

/* ====== WELCOME BUBBLE ====== */
.chatbot-bubble {
    position: fixed;
    bottom: 95px;
    right: 24px;
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9997;
    max-width: 220px;
    font-size: 0.9rem;
    color: #1e293b;
    display: none;
    /* Ukryty domyślnie - zapobiega FOUC */
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.chatbot-bubble.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.chatbot-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

.chatbot-bubble-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 480px) {
    .chatbot-bubble {
        bottom: 80px;
        right: 16px;
        max-width: 200px;
        font-size: 0.85rem;
    }
}

/* ====== CHAT MODAL ====== */
.chatbot-modal {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: none;
    /* Ukryty domyślnie - zapobiega FOUC */
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.chatbot-modal.open {
    display: flex;
    /* Pokaż tylko gdy otwarty */
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ====== CHAT HEADER ====== */
.chatbot-header {
    background: var(--gradient, linear-gradient(135deg, #4f46e5, #06b6d4));
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
}

.chatbot-avatar {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.chatbot-info {
    flex: 1;
}

.chatbot-info h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.chatbot-info span {
    font-size: 0.8rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chatbot-info span::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    transition: background 0.2s ease;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Clear chat button */
.chatbot-clear {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    transition: background 0.2s ease;
    margin-right: 4px;
}

.chatbot-clear:hover {
    background: rgba(239, 68, 68, 0.6);
}

/* ====== CHAT MESSAGES ====== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
    overscroll-behavior: contain;
    /* Blokuje propagację scrolla na stronę */
}

.chatbot-message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: message-slide-in 0.3s ease;
}

@keyframes message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.bot {
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.chatbot-message.user {
    background: var(--gradient, linear-gradient(135deg, #4f46e5, #06b6d4));
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

/* Typing indicator */
.chatbot-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 70px;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing-dot 1.4s infinite ease-in-out;
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-dot {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ====== CHAT INPUT ====== */
.chatbot-input-container {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
}

.chatbot-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 0.9rem;
    background: #f8fafc;
    outline: none;
    transition: all 0.2s ease;
}

.chatbot-input:focus {
    border-color: #4f46e5;
    background: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chatbot-input::placeholder {
    color: #94a3b8;
}

.chatbot-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--gradient, linear-gradient(135deg, #4f46e5, #06b6d4));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ====== MOBILE STYLES ====== */
@media (max-width: 480px) {

    /* Trigger - większy i lepiej widoczny */
    .chatbot-trigger {
        width: 56px;
        height: 56px;
        bottom: 20px;
        right: 16px;
        box-shadow: 0 6px 24px rgba(79, 70, 229, 0.5);
    }

    .chatbot-trigger i {
        font-size: 1.5rem;
    }

    /* Welcome bubble - węższy, z prawej */
    .chatbot-bubble {
        bottom: 85px;
        right: 16px;
        left: auto;
        max-width: 220px;
        font-size: 0.85rem;
        text-align: left;
        padding: 12px 16px;
    }

    .chatbot-bubble::after {
        right: 24px;
    }

    /* Modal - pływające okno na dole */
    .chatbot-modal {
        position: fixed;
        bottom: 90px;
        top: auto;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: calc(100% - 24px);
        height: 70vh;
        max-height: 520px;
        border-radius: 20px;
        overflow: hidden;
    }

    .chatbot-modal.open {
        transform: translateY(0);
    }

    /* Header - z safe area dla notcha */
    .chatbot-header {
        padding: 1rem 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        gap: 10px;
    }

    .chatbot-avatar {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }

    .chatbot-info h4 {
        font-size: 0.95rem;
    }

    .chatbot-info span {
        font-size: 0.75rem;
    }

    .chatbot-close,
    .chatbot-clear {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    /* Messages area - więcej miejsca */
    .chatbot-messages {
        padding: 1rem 0.75rem;
        gap: 10px;
    }

    .chatbot-message {
        max-width: 90%;
        padding: 0.7rem 0.9rem;
        font-size: 0.9rem;
        border-radius: 14px;
    }

    .chatbot-message.bot {
        border-bottom-left-radius: 4px;
    }

    .chatbot-message.user {
        border-bottom-right-radius: 4px;
    }

    /* Input area - sticky na dole z safe area */
    .chatbot-input-container {
        padding: 0.75rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
        gap: 8px;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e2e8f0;
    }

    .chatbot-input {
        padding: 0.8rem 1rem;
        font-size: 16px;
        /* Dokładnie 16px zapobiega zoom na iOS */
        border-radius: 20px;
        -webkit-appearance: none;
        appearance: none;
        /* Fix dla iOS */
    }

    .chatbot-send {
        width: 46px;
        height: 46px;
        font-size: 1.1rem;
        flex-shrink: 0;
    }

    /* Typing indicator */
    .chatbot-typing {
        padding: 0.6rem 0.8rem;
        max-width: 60px;
    }

    .chatbot-typing span {
        width: 7px;
        height: 7px;
    }
}

/* ====== SCROLLBAR ====== */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

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

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}