/* AI Chat Widget - NAPRAWIONY CSS z pełnym systemem kolorów */

:root {
    /* === KOLORY WIDGETU === */
    --ai-chat-widget-bg: var(--widget-bg-color, #007cba);
    --ai-chat-widget-text: var(--widget-text-color, #ffffff);
    --ai-chat-widget-hover: color-mix(in srgb, var(--ai-chat-widget-bg) 80%, black);
    
    /* === KOLORY OKNA CZATU === */
    --ai-chat-window-bg: var(--window-bg-color, #ffffff);
    --ai-chat-header-bg: var(--header-bg-color, #007cba);
    --ai-chat-header-text: var(--header-text-color, #ffffff);
    --ai-chat-messages-bg: var(--messages-bg-color, #f8f9fa);
    
    /* === KOLORY DYMKÓW === */
    --ai-chat-user-bubble-bg: var(--user-bubble-bg-color, #007cba);
    --ai-chat-user-bubble-text: var(--user-bubble-text-color, #ffffff);
    --ai-chat-ai-bubble-bg: var(--ai-bubble-bg-color, #f1f3f4);
    --ai-chat-ai-bubble-text: var(--ai-bubble-text-color, #333333);
    
    /* === KOLORY PRZYCISKÓW === */
    --ai-chat-send-btn-bg: var(--send-btn-bg-color, #007cba);
    --ai-chat-send-btn-text: var(--send-btn-text-color, #ffffff);
    --ai-chat-send-btn-hover: color-mix(in srgb, var(--ai-chat-send-btn-bg) 80%, black);
    
    /* === AVATARY === */
    --ai-chat-user-avatar-bg: var(--user-avatar-bg-color, #4caf50);
    --ai-chat-ai-avatar-bg: var(--ai-avatar-bg-color, #e0e0e0);
    --ai-chat-user-avatar-icon: var(--user-avatar-icon, '👤');
    --ai-chat-ai-avatar-icon: var(--ai-avatar-icon, '🤖');
    --ai-chat-widget-icon: var(--widget-icon, '💬');
    
    /* === CUSTOM OBRAZKI === */
    --ai-chat-widget-image: var(--widget-custom-image, none);
    --ai-chat-user-avatar-image: var(--user-avatar-custom-image, none);
    --ai-chat-ai-avatar-image: var(--ai-avatar-custom-image, none);
    
    /* === PODSTAWOWE KOLORY === */
    --ai-chat-border: #e0e0e0;
    --ai-chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --ai-chat-shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.15);
    --ai-chat-error-bg: #ffebee;
    --ai-chat-error-text: #d32f2f;
    --ai-chat-z-index: 999999;
    
    /* === RESPONSYWNOŚĆ === */
    --ai-chat-widget-size: 60px;
    --ai-chat-window-width: 350px;
    --ai-chat-window-height: 500px;
}

/* Reset dla widgetu */
.ai-chat-floating *,
.ai-chat-shortcode-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ===================
   PŁYWAJĄCY WIDGET
   =================== */

.ai-chat-floating {
    position: fixed;
    z-index: var(--ai-chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* === POZYCJONOWANIE NAPRAWIONE === */
.ai-chat-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.ai-chat-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.ai-chat-position-top-right {
    top: 20px;
    right: 20px;
}

.ai-chat-position-top-left {
    top: 20px;
    left: 20px;
}

/* === PRZYCISK TOGGLE Z CUSTOM IKONAMI === */
.ai-chat-toggle {
    width: var(--ai-chat-widget-size);
    height: var(--ai-chat-widget-size);
    background: var(--ai-chat-widget-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--ai-chat-shadow);
    transition: all 0.3s ease;
    position: relative;
    color: var(--ai-chat-widget-text);
    font-size: 24px;
    border: none;
    outline: none;
    
    /* Custom image support */
    background-image: var(--ai-chat-widget-image);
    background-size: 70%;
    background-repeat: no-repeat;
    background-position: center;
}

.ai-chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: var(--ai-chat-shadow-hover);
    background-color: var(--ai-chat-widget-hover);
}

/* Ikony w przycisku toggle */
.ai-chat-toggle .ai-chat-icon::before {
    content: var(--ai-chat-widget-icon);
}

.ai-chat-toggle .ai-chat-close-icon {
    display: none;
    position: absolute;
    font-size: 20px;
}

/* Ukryj ikonę gdy jest custom obrazek */
.ai-chat-toggle[style*="background-image"] .ai-chat-icon,
.ai-chat-toggle[style*="background-image"] .ai-chat-close-icon {
    display: none;
}

.ai-chat-floating.ai-chat-open .ai-chat-toggle .ai-chat-icon {
    display: none;
}

.ai-chat-floating.ai-chat-open .ai-chat-toggle .ai-chat-close-icon {
    display: block;
}

/* === OKNO CZATU Z NAPRAWIONYM POZYCJONOWANIEM === */
.ai-chat-window {
    width: var(--ai-chat-window-width);
    height: var(--ai-chat-window-height);
    background: var(--ai-chat-window-bg);
    border-radius: 12px;
    box-shadow: var(--ai-chat-shadow-hover);
    position: absolute;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
}

/* NAPRAWIONE POZYCJONOWANIE - okno pokazuje się po właściwej stronie */
.ai-chat-position-bottom-right .ai-chat-window {
    bottom: calc(var(--ai-chat-widget-size) + 20px);
    right: 0;
}

.ai-chat-position-bottom-left .ai-chat-window {
    bottom: calc(var(--ai-chat-widget-size) + 20px);
    left: 0;
}

.ai-chat-position-top-right .ai-chat-window {
    top: calc(var(--ai-chat-widget-size) + 20px);
    right: 0;
}

.ai-chat-position-top-left .ai-chat-window {
    top: calc(var(--ai-chat-widget-size) + 20px);
    left: 0;
}

.ai-chat-floating.ai-chat-open .ai-chat-window {
    display: flex;
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* === HEADER Z CUSTOM KOLORAMI === */
.ai-chat-header {
    background: var(--ai-chat-header-bg);
    color: var(--ai-chat-header-text);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--ai-chat-header-text);
}

.ai-chat-minimize,
.ai-chat-close {
    background: none;
    border: none;
    color: var(--ai-chat-header-text);
    cursor: pointer;
    padding: 5px;
    margin-left: 10px;
    border-radius: 4px;
    font-size: 16px;
    opacity: 0.8;
    transition: all 0.2s ease;
}

.ai-chat-minimize:hover,
.ai-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* === OBSZAR WIADOMOŚCI === */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: var(--ai-chat-messages-bg);
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* === WIADOMOŚCI Z CUSTOM AVATARAMI === */
.ai-chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: slideInUp 0.3s ease;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* === AVATARY Z CUSTOM OBRAZKAMI === */
.ai-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    margin: 0 10px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Avatar użytkownika */
.ai-chat-message-user .ai-chat-avatar {
    background-color: var(--ai-chat-user-avatar-bg);
    color: var(--ai-chat-widget-text);
    background-image: var(--ai-chat-user-avatar-image);
}

.ai-chat-message-user .ai-chat-avatar::before {
    content: var(--ai-chat-user-avatar-icon);
}

/* Avatar AI */
.ai-chat-message-assistant .ai-chat-avatar {
    background-color: var(--ai-chat-ai-avatar-bg);
    background-image: var(--ai-chat-ai-avatar-image);
}

.ai-chat-message-assistant .ai-chat-avatar::before {
    content: var(--ai-chat-ai-avatar-icon);
}

/* Ukryj tekst ikony gdy jest custom obrazek */
.ai-chat-avatar[style*="background-image"]::before {
    content: '';
}

/* === DYMKI Z CUSTOM KOLORAMI === */
.ai-chat-content {
    flex: 1;
    max-width: calc(100% - 52px);
}

.ai-chat-text {
    background: var(--ai-chat-ai-bubble-bg);
    color: var(--ai-chat-ai-bubble-text);
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
    position: relative;
}

/* Dymek użytkownika */
.ai-chat-message-user .ai-chat-text {
    background: var(--ai-chat-user-bubble-bg);
    color: var(--ai-chat-user-bubble-text);
    margin-left: auto;
}

/* Dymek systemowy/błędu */
.ai-chat-message-system .ai-chat-text {
    background: var(--ai-chat-error-bg);
    color: var(--ai-chat-error-text);
    border: 1px solid #ffcdd2;
}

.ai-chat-timestamp {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 4px;
    text-align: right;
}

.ai-chat-message-user .ai-chat-timestamp {
    text-align: left;
    color: rgba(0, 0, 0, 0.5);
}

/* === WIADOMOŚĆ POWITALNA === */
.ai-chat-welcome .ai-chat-text {
    background: linear-gradient(135deg, var(--ai-chat-header-bg), var(--ai-chat-widget-hover));
    color: var(--ai-chat-header-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* === LOADING INDICATOR === */
.ai-chat-loading .ai-chat-text {
    padding: 16px;
    background: var(--ai-chat-ai-bubble-bg);
}

.ai-chat-typing-indicator {
    display: flex;
    gap: 4px;
}

.ai-chat-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-chat-ai-bubble-text);
    opacity: 0.4;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-chat-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-chat-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* === OBSZAR INPUT === */
.ai-chat-input-container {
    padding: 15px 20px;
    border-top: 1px solid var(--ai-chat-border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--ai-chat-window-bg);
}

.ai-chat-input-container textarea {
    flex: 1;
    border: 1px solid var(--ai-chat-border);
    border-radius: 20px;
    padding: 10px 15px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 100px;
    transition: border-color 0.2s ease;
    background: var(--ai-chat-window-bg);
    color: var(--ai-chat-ai-bubble-text);
}

.ai-chat-input-container textarea:focus {
    border-color: var(--ai-chat-send-btn-bg);
    box-shadow: 0 0 0 2px rgba(0, 123, 186, 0.1);
}

.ai-chat-input-container textarea::placeholder {
    color: rgba(0, 0, 0, 0.5);
}

/* === PRZYCISK SEND === */
.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--ai-chat-send-btn-bg);
    color: var(--ai-chat-send-btn-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 16px;
}

.ai-chat-send-btn:hover:not(:disabled) {
    background: var(--ai-chat-send-btn-hover);
    transform: scale(1.05);
}

.ai-chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send-btn .ai-chat-loading-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* === STATUS I LIMITY === */
.ai-chat-status {
    padding: 8px 20px;
    text-align: center;
    font-size: 12px;
    border-top: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-messages-bg);
}

.ai-chat-limit-info {
    margin-top: 8px;
    text-align: center;
    color: #ff9800;
    font-size: 12px;
}

.ai-chat-contact-button {
    margin-top: 12px;
    text-align: center;
}

.ai-chat-contact-link {
    display: inline-block;
    background: var(--ai-chat-send-btn-bg);
    color: var(--ai-chat-send-btn-text);
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 12px;
    transition: background 0.2s ease;
}

.ai-chat-contact-link:hover {
    background: var(--ai-chat-send-btn-hover);
    color: var(--ai-chat-send-btn-text);
}

/* ===================
   SHORTCODE WIDGET
   =================== */

.ai-chat-shortcode-widget {
    border: 1px solid var(--ai-chat-border);
    border-radius: 12px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    background: var(--ai-chat-window-bg);
}

.ai-chat-embedded {
    max-width: 600px;
    height: 500px;
    display: flex;
    flex-direction: column;
}

.ai-chat-inline {
    max-width: 100%;
    height: 400px;
    display: flex;
    flex-direction: column;
}

.ai-chat-shortcode-widget .ai-chat-messages {
    height: 300px;
}

.ai-chat-embedded .ai-chat-messages {
    height: 380px;
}

/* ===================
   RESPONSYWNOŚĆ
   =================== */

@media (max-width: 480px) {
    :root {
        --ai-chat-window-width: calc(100vw - 20px);
        --ai-chat-window-height: calc(100vh - 100px);
        --ai-chat-widget-size: 55px;
    }
    
    .ai-chat-floating {
        bottom: 10px;
        right: 10px;
    }
    
    .ai-chat-position-bottom-left {
        left: 10px;
    }
    
    /* Wszystkie okna na mobile pokazują się po prawej */
    .ai-chat-position-bottom-left .ai-chat-window,
    .ai-chat-position-top-left .ai-chat-window,
    .ai-chat-position-top-right .ai-chat-window,
    .ai-chat-position-bottom-right .ai-chat-window {
        right: 0;
        left: auto;
    }
    
    .ai-chat-shortcode-widget {
        height: 350px;
    }
    
    .ai-chat-shortcode-widget .ai-chat-messages {
        height: 250px;
    }
    
    .ai-chat-header {
        padding: 12px 15px;
    }
    
    .ai-chat-messages {
        padding: 15px;
    }
    
    .ai-chat-input-container {
        padding: 12px 15px;
    }
}

/* ===================
   STANY WIDGETU
   =================== */

.ai-chat-widget-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.ai-chat-widget-connecting .ai-chat-toggle {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 123, 186, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(0, 123, 186, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 123, 186, 0);
    }
}

.ai-chat-connection-status {
    padding: 5px 0;
}

.ai-chat-status-connected {
    color: #4caf50;
}

.ai-chat-status-disconnected {
    color: #f44336;
}

.ai-chat-status-limited {
    color: #ff9800;
}

/* ===================
   ANIMACJE
   =================== */

.ai-chat-message-enter {
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-window-enter {
    animation: windowSlideIn 0.3s ease;
}

@keyframes windowSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===================
   DARK MODE SUPPORT
   =================== */

@media (prefers-color-scheme: dark) {
    :root {
        --ai-chat-window-bg: var(--window-bg-color, #1e1e1e);
        --ai-chat-messages-bg: var(--messages-bg-color, #2a2a2a);
        --ai-chat-ai-bubble-bg: var(--ai-bubble-bg-color, #333333);
        --ai-chat-ai-bubble-text: var(--ai-bubble-text-color, #e0e0e0);
        --ai-chat-border: #444444;
        --ai-chat-error-bg: #2d1b1b;
    }
    
    .ai-chat-messages::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
    }
    
    .ai-chat-messages::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
    }
    
    .ai-chat-input-container textarea {
        color: #e0e0e0;
    }
    
    .ai-chat-input-container textarea::placeholder {
        color: rgba(255, 255, 255, 0.5);
    }
    
    .ai-chat-timestamp {
        color: rgba(255, 255, 255, 0.5);
    }
}

/* ===================
   ACCESSIBILITY
   =================== */

.ai-chat-toggle:focus,
.ai-chat-send-btn:focus,
.ai-chat-input-container textarea:focus,
.ai-chat-minimize:focus,
.ai-chat-close:focus {
    outline: 2px solid var(--ai-chat-send-btn-bg);
    outline-offset: 2px;
}

/* Dla użytkowników preferujących mniej animacji */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .ai-chat-toggle:hover {
        transform: none;
    }
    
    .ai-chat-send-btn:hover:not(:disabled) {
        transform: none;
    }
}

/* ===================
   WYSOKOŚĆ NA MOBILE
   =================== */

@media (max-width: 480px) and (max-height: 600px) {
    :root {
        --ai-chat-window-height: calc(100vh - 80px);
    }
    
    .ai-chat-messages {
        flex: 1;
        min-height: 150px;
    }
}

/* ===================
   UTILITIES
   =================== */

/* Klasa pomocnicza do ukrywania elementów */
.ai-chat-hidden {
    display: none !important;
}

/* Klasa pomocnicza do wyłączania interakcji */
.ai-chat-no-interaction {
    pointer-events: none;
}

/* Klasa pomocnicza do pełnej przezroczystości */
.ai-chat-transparent {
    opacity: 0;
}

/* Klasa pomocnicza do centrowania */
.ai-chat-center {
    text-align: center;
}

/* ===================
   LOADING STATES
   =================== */

.ai-chat-widget-loading .ai-chat-toggle {
    animation: pulse 2s infinite;
    cursor: wait;
}

.ai-chat-message-sending {
    opacity: 0.7;
}

.ai-chat-message-error {
    border-left: 3px solid var(--ai-chat-error-text);
}

/* ===================
   PRINT STYLES
   =================== */

@media print {
    .ai-chat-floating,
    .ai-chat-shortcode-widget {
        display: none !important;
    }
}