/**
 * Chat Widget CSS - Styl dla asystenta AI
 */

.ai-chat-widget {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    top: auto !important;
    z-index: 9999;
}

/* Chat Button */
.ai-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0066cc 0%, #3385db 100%);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.4);
    transition: all 0.3s ease;
    position: relative;
    animation: chat-button-intro 2s ease-out 1s;
}

/* Animacja przycisku - przywitanie po załadowaniu strony */
@keyframes chat-button-intro {
    0%, 20%, 40%, 60% {
        transform: translateY(0) scale(1);
    }
    10% {
        transform: translateY(-20px) scale(1.1);
    }
    30% {
        transform: translateY(-15px) scale(1.08);
    }
    50% {
        transform: translateY(-10px) scale(1.05);
    }
    100% {
        transform: translateY(0) scale(1);
    }
}

.ai-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.5);
}

.ai-chat-button:active {
    transform: scale(0.95);
}

.chat-notification {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    background: #ff6b35;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Window */
.ai-chat-window {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.ai-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
    background: linear-gradient(135deg, #0066cc 0%, #3385db 100%);
    color: white;
    padding: 16px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible; /* Zmienione z hidden na visible aby kropka była widoczna */
}

.ai-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%; /* Dodane aby obrazek był okrągły */
    animation: mascot-float 3s ease-in-out infinite;
}

/* Animacja powitalna - gdy chat się otwiera */
.ai-chat-window.open .ai-chat-avatar {
    animation: mascot-greeting 1.5s ease-out;
}

@keyframes mascot-greeting {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(10deg);
    }
    70% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Animacja maskotki - delikatne unoszenie */
@keyframes mascot-float {
    0%, 100% { 
        transform: translateY(0px) scale(1); 
    }
    50% { 
        transform: translateY(-3px) scale(1.02); 
    }
}

/* Status indicator - zielona kropka przy avatarze */
.status-indicator-dot {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #00ff88;
    border: 4px solid #0f1419;
    box-shadow: 0 0 20px rgba(0, 255, 136, 1), 0 0 40px rgba(0, 255, 136, 0.6);
    animation: pulse-green 2s infinite;
    z-index: 100;
}

@keyframes pulse-green {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(0, 255, 136, 1), 0 0 40px rgba(0, 255, 136, 0.6);
        transform: scale(1);
        background: #00ff88;
    }
    50% { 
        box-shadow: 0 0 30px rgba(0, 255, 136, 1), 0 0 60px rgba(0, 255, 136, 0.8);
        transform: scale(1.15);
        background: #00ffaa;
    }
}

.ai-chat-info {
    flex: 1;
}

.ai-chat-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f7fa;
}

.ai-message,
.user-message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0066cc 0%, #3385db 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-right: 12px;
    flex-shrink: 0;
    position: relative;
}

/* DEV: Subtelna różnica dla OpenAI vs Regex */
.message-avatar.ai-openai {
    background: linear-gradient(135deg, #d4af37 0%, #f4c430 100%); /* Złoty odcień */
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.3);
}

.message-avatar.ai-regex {
    background: linear-gradient(135deg, #0066cc 0%, #3385db 100%); /* Niebieski - domyślny */
}

/* Animacja dla pierwszej wiadomości (powitanie) */
.ai-message:first-child .message-avatar {
    animation: wave-hello 2s ease-in-out;
}

@keyframes wave-hello {
    0%, 100% { transform: rotate(0deg); }
    10%, 30%, 50%, 70%, 90% { transform: rotate(14deg); }
    20%, 40%, 60%, 80% { transform: rotate(-14deg); }
}

/* Emoji "machanie" w pierwszej wiadomości */
.ai-message:first-child .message-content p::before {
    content: "👋 ";
    display: inline-block;
    animation: wave-hand 1s ease-in-out 0.5s 3;
}

@keyframes wave-hand {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-20deg); }
}

.message-content {
    flex: 1;
}

.message-content p {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    margin: 0 0 8px 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content p {
    background: #0066cc;
    color: white;
    text-align: right;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.quick-action-btn {
    background: white;
    border: 2px solid #0066cc;
    color: #0066cc;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.quick-action-btn:hover {
    background: #0066cc;
    color: white;
}

/* Suggestions */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.suggestion-btn {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    color: #1976d2;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: #1976d2;
    color: white;
    border-color: #1976d2;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 16px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f5f7fa;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
.ai-chat-input-area {
    border-top: 1px solid #e0e0e0;
    background: white;
    border-radius: 0 0 16px 16px;
}

#aiChatForm {
    display: flex;
    padding: 12px;
    gap: 8px;
}

#aiChatInput {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

#aiChatInput:focus {
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #0066cc;
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover {
    background: #004999;
    transform: scale(1.05);
}

.send-button:active {
    transform: scale(0.95);
}

.input-hint {
    padding: 0 16px 12px;
    font-size: 11px;
    color: #999;
    text-align: center;
}

/* Scrollbar */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f5f7fa;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

/* ============================================
   DARK MODE FOR CHAT WIDGET
   ============================================ */

body.dark-mode .ai-chat-button {
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5);
}

body.dark-mode .ai-chat-button:hover {
    box-shadow: 0 6px 25px rgba(59, 130, 246, 0.7);
}

body.dark-mode .ai-chat-window {
    background: #1a1f2e;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .ai-chat-header {
    background: linear-gradient(135deg, #2d3548 0%, #242b3d 100%);
}

body.dark-mode .ai-chat-info h3 {
    color: #e8eaed;
}

body.dark-mode .ai-chat-close {
    background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .ai-chat-messages {
    background: #0f1419;
}

body.dark-mode .message-content p {
    background: #242b3d;
    color: #e8eaed;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode .user-message .message-content p {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

body.dark-mode .quick-action-btn {
    background: #242b3d;
    border-color: #3b82f6;
    color: #60a5fa;
}

body.dark-mode .quick-action-btn:hover {
    background: #3b82f6;
    color: white;
}

body.dark-mode .suggestions {
    margin-top: 8px;
}

body.dark-mode .suggestion-btn {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

body.dark-mode .suggestion-btn:hover {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

body.dark-mode .typing-indicator {
    background: #0f1419;
}

body.dark-mode .typing-dot {
    background: #8a8f98;
}

body.dark-mode .ai-chat-input-area {
    background: #1a1f2e;
    border-top-color: #2d3548;
}

body.dark-mode #aiChatInput {
    background: #242b3d;
    border-color: #2d3548;
    color: #e8eaed;
}

body.dark-mode #aiChatInput::placeholder {
    color: #8a8f98;
}

body.dark-mode #aiChatInput:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    background: #2d3548;
}

body.dark-mode .send-button {
    background: #3b82f6;
}

body.dark-mode .send-button:hover {
    background: #2563eb;
}

body.dark-mode .input-hint {
    color: #8a8f98;
}

body.dark-mode .ai-chat-messages::-webkit-scrollbar-track {
    background: #0f1419;
}

body.dark-mode .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #2d3548;
}

body.dark-mode .ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #3b82f6;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-window {
        bottom: 90px;
        right: 10px;
        left: 10px;
        width: auto;
        height: 500px;
    }
    
    .ai-chat-button {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }
}

@media (max-width: 480px) {
    .ai-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        max-height: 100dvh; /* Dynamic viewport height - uwzględnia pasek przeglądarki */
        max-height: 100vh; /* Fallback dla starszych przeglądarek */
        height: 100%;
        height: 100dvh;
    }
    
    .ai-chat-header {
        border-radius: 0;
    }
    
    /* Dodatkowy padding na dole dla paska nawigacji przeglądarki */
    .ai-chat-input-area {
        padding-bottom: env(safe-area-inset-bottom, 16px);
        border-radius: 0;
    }
    
    #aiChatForm {
        padding-bottom: 8px;
    }
}

/* Przyciski logowania w nagłówku czatu */
.ai-chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.chat-login-btn,
.chat-logout-btn {
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 18px;
}

/* CZERWONE tło - chatLoginButton (wylogowany) */
.chat-login-btn {
    background: rgba(244, 67, 54, 0.85) !important;
    box-shadow: 0 0 20px rgba(244, 67, 54, 0.5) !important;
}

.chat-login-btn:hover {
    background: rgba(244, 67, 54, 1) !important;
    box-shadow: 0 0 30px rgba(244, 67, 54, 0.8) !important;
    transform: scale(1.15);
}

/* ZIELONE tło - chatLogoutButton (zalogowany) */
.chat-logout-btn {
    background: rgba(0, 204, 136, 0.85) !important;
    box-shadow: 0 0 20px rgba(0, 204, 136, 0.5) !important;
}

.chat-logout-btn:hover {
    background: rgba(0, 204, 136, 1) !important;
    box-shadow: 0 0 30px rgba(0, 204, 136, 0.8) !important;
    transform: scale(1.15);
}

/* Przycisk "Nowa rozmowa" */
.chat-new-btn {
    background: rgba(102, 126, 234, 0.85) !important;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.4) !important;
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chat-new-btn:hover {
    background: rgba(102, 126, 234, 1) !important;
    box-shadow: 0 0 25px rgba(102, 126, 234, 0.7) !important;
    transform: scale(1.15) rotate(90deg);
}

/* Wiadomość systemowa (np. "Nowa rozmowa") */
.system-message {
    display: flex;
    justify-content: center;
    margin: 15px 0;
}

.system-message-content {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15), rgba(118, 75, 162, 0.1));
    border: 1px solid rgba(102, 126, 234, 0.3);
    color: #667eea;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.system-message-content i {
    font-size: 14px;
}

/* Ciemny motyw - wiadomość systemowa */
body.dark-mode .system-message-content {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.15));
    border-color: rgba(102, 126, 234, 0.4);
}

/* Obsługa klawiatury ekranowej na urządzeniach mobilnych */
@supports (height: 100dvh) {
    @media (max-width: 480px) {
        .ai-chat-window {
            height: 100dvh;
            max-height: 100dvh;
        }
    }
}

/* Dodatkowe zabezpieczenie dla iOS Safari */
@media (max-width: 480px) {
    .ai-chat-window.open {
        position: fixed;
        overflow: hidden;
    }
    
    .ai-chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 20px;
    }
}
    color: #a5b4fc;
}

#chatCustomerInfo {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 500;
}

