/* --- IMPORT CZCIONEK --- */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css');

/* --- RESET & BAZA --- */
.chat-widget-button, .chat-widget-container, .confirm-modal {
    box-sizing: border-box;
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.chat-widget-container * { box-sizing: border-box; }

/* --- STYLIZACJA LINKÓW --- */
/* Domyślne linki na stronie */
a:not(.nav-link):not(.btn-primary):not(.btn-secondary):not(.chat-widget-button):not(.logo-link):not(.demo-top-bar a) {
    color: #bfa07a !important;
    font-weight: 700 !important;
    text-decoration: underline !important;
    transition: opacity 0.3s;
}
a:not(.nav-link):not(.btn-primary):not(.btn-secondary):not(.chat-widget-button):hover {
    opacity: 0.8;
}

/* Linki w dymkach użytkownika (tło złote -> białe linki) */
.chat-widget-message.user a {
    color: white !important;
    text-decoration: underline !important;
    font-weight: 700 !important;
}

/* Linki w dymkach bota (tło białe -> złote linki) */
.chat-widget-message.bot a {
    color: #bfa07a !important;
    text-decoration: underline !important;
    font-weight: 700 !important;
    cursor: pointer;
}

/* --- 1. PRZYCISK OTWIERANIA --- */
.chat-widget-button {
    position: fixed; bottom: 30px; right: 30px; width: 70px; height: 70px;
    background: linear-gradient(135deg, #bfa07a 0%, #a88965 100%);
    border: none; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; 
    box-shadow: 0 8px 24px rgba(168, 137, 101, 0.4);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9990;
}
.chat-widget-button:hover { 
    transform: scale(1.15) rotate(10deg); 
    box-shadow: 0 12px 32px rgba(168, 137, 101, 0.6); 
}
.chat-widget-button.active { transform: scale(0); opacity: 0; pointer-events: none; }

.chat-widget-button.has-notification::after {
    content: ''; position: absolute; top: 8px; right: 8px; width: 16px; height: 16px;
    background: #ff4757; border-radius: 50%; border: 3px solid white; animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.2); opacity: 0.8; } }

/* --- 2. KONTENER CHATU --- */
.chat-widget-container {
    position: fixed; bottom: 120px; right: 30px; width: 420px; height: 650px;
    background: #fdfcf8;
    border-radius: 20px; box-shadow: 0 20px 60px rgba(44, 51, 51, 0.2);
    display: none; flex-direction: column; z-index: 9998; overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); /* Płynniejsza animacja */
    border: 1px solid #ebe5dd;
}
.chat-widget-container.active { display: flex; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* --- 3. HEADER --- */
.chat-widget-header {
    background: #2c3333; color: white;
    padding: 20px 25px; display: flex; justify-content: space-between; align-items: center;
    position: relative; flex-shrink: 0; /* Nie zgniataj nagłówka */
}
.chat-header-info { display: flex; align-items: center; gap: 15px; }
.chat-avatar {
    width: 40px; height: 40px; background: rgba(255, 255, 255, 0.1); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; backdrop-filter: blur(10px);
    border: 2px solid #bfa07a;
}
.chat-avatar svg, .chat-avatar i { font-size: 18px; color: #bfa07a; }
.chat-header-text h3 { margin: 0; font-size: 18px; font-weight: 600; font-family: 'Playfair Display', serif; }
.chat-status { font-size: 11px; opacity: 0.8; display: flex; align-items: center; gap: 6px; }
.status-dot { width: 8px; height: 8px; background: #4ade80; border-radius: 50%; animation: pulse 2s infinite; }

.chat-header-actions { display: flex; gap: 8px; }
.chat-widget-close, .chat-clear-btn {
    background: rgba(255, 255, 255, 0.1); border: none; color: #bfa07a; width: 32px; height: 32px;
    border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.3s ease;
}
.chat-widget-close:hover { background: rgba(191, 160, 122, 0.2); color: white; transform: rotate(90deg); }

/* --- 4. WIADOMOŚCI --- */
.chat-widget-messages {
    flex: 1; /* Zajmij całą dostępną przestrzeń */
    overflow-y: auto; 
    overflow-x: hidden;
    padding: 20px;
    background: linear-gradient(to bottom, #fdfcf8, #f7f4ef);
    scroll-behavior: smooth;
    min-height: 0; /* Ważne dla flexboxa w zagnieżdżeniu */
}
.chat-widget-message {
    margin: 10px 0; padding: 12px 16px; border-radius: 16px; max-width: 85%;
    word-wrap: break-word; line-height: 1.5; font-size: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.chat-widget-message.user { 
    background: linear-gradient(135deg, #bfa07a 0%, #a88965 100%); 
    color: white; margin-left: auto; border-bottom-right-radius: 4px; 
}
.chat-widget-message.bot { 
    background: white; color: #2c3333; margin-right: auto; border-bottom-left-radius: 4px; 
    border: 1px solid #ebe5dd; 
}
.chat-widget-message.error { background: #ff6b6b; color: white; margin-right: auto; }
.chat-widget-message img { max-width: 100%; border-radius: 8px; margin-top: 8px; }

/* --- 5. INPUT AREA --- */
.chat-widget-input-area { 
    display: flex; gap: 10px; padding: 15px; 
    border-top: 1px solid #ebe5dd; background: white; 
    flex-shrink: 0; /* Nie zgniataj input area */
}
.chat-widget-input { 
    flex: 1; padding: 12px 16px; border: 2px solid #ebe5dd; border-radius: 12px; 
    font-size: 15px; /* 16px zapobiega zoomowi na iOS */
    outline: none; transition: border 0.3s;
    background: #fdfcf8;
}
.chat-widget-input:focus { border-color: #bfa07a; background: white; }
.chat-widget-send { 
    padding: 0 20px; background: linear-gradient(135deg, #bfa07a 0%, #a88965 100%); 
    color: white; border: none; border-radius: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* --- 6. STOPKA (RODO) --- */
.chat-disclaimer { 
    padding: 10px; background: #f7f4ef; border-top: 1px solid #ebe5dd; 
    font-size: 10px; color: #78716c; text-align: center; 
    flex-shrink: 0;
    transition: all 0.3s ease;
    max-height: 50px;
    opacity: 1;
}
.chat-disclaimer a { color: #bfa07a; font-weight: bold; text-decoration: none; }

/* Klasa ukrywająca stopkę na mobile gdy klawiatura otwarta */
.chat-widget-container.keyboard-open .chat-disclaimer {
    max-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    border: none;
}

/* --- 7. LOADING & MODAL --- */
.typing-indicator { display: flex; gap: 5px; padding: 10px; background: white; border-radius: 16px; width: fit-content; margin: 10px 0; border: 1px solid #ebe5dd; }
.typing-indicator span { width: 6px; height: 6px; background: #bfa07a; border-radius: 50%; animation: typing 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 100% { opacity: 0.4; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }

.confirm-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); display: none; justify-content: center; align-items: center; z-index: 20000;
}
.confirm-modal.active { display: flex; }
.confirm-modal-content { background: white; padding: 25px; border-radius: 16px; max-width: 350px; width: 90%; text-align: center; }
.confirm-modal-header { font-weight: bold; margin-bottom: 10px; font-size: 18px; color: #2c3333; display: flex; align-items: center; justify-content: center;}
.confirm-modal-actions { margin-top: 20px; display: flex; justify-content: center; gap: 10px; }
.confirm-btn { padding: 10px 25px; border-radius: 8px; border: none; cursor: pointer; font-weight: bold; }
.confirm-btn-cancel { background: #eee; color: #555; }
.confirm-btn-confirm { background: #bfa07a; color: white; }

/* --- 8. MOBILE (RWD) --- */
@media (max-width: 600px) {
    .chat-widget-container {
        /* FIXED NA CAŁY EKRAN - NAJPROSTSZE I NAJSTABILNIEJSZE ROZWIĄZANIE */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%; /* Fallback */
        height: 100dvh; /* Dynamic viewport height dla nowoczesnych przeglądarek */
        border-radius: 0;
        border: none;
        margin: 0;
        transform: none !important; /* Reset animacji transform dla stabilności */
        animation: simpleFadeIn 0.3s ease-out;
    }
    
    @keyframes simpleFadeIn { from { opacity: 0; } to { opacity: 1; } }

    .chat-widget-button.active { display: none; }
    
    .chat-widget-header {
        padding: 15px; /* Mniejszy padding na mobile */
    }
    
    /* Ukrywamy przycisk zamykania 'X' na mobile jeśli wolisz, ale tutaj zostawiam */
    /* .chat-widget-close { width: 40px; height: 40px; } Dla łatwiejszego klikania */
}