/* === Chat Widget === */

.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #29ABE2;
    border: none;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(41, 171, 226, 0.35);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s;
}

.chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(41, 171, 226, 0.45),
                0 0 20px rgba(41, 171, 226, 0.3);
}

.chat-bubble:focus-visible {
    outline: 2px solid #29ABE2;
    outline-offset: 3px;
}

.chat-bubble-hidden {
    display: none;
}

.chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-bubble-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(41, 171, 226, 0.4);
    animation: chat-pulse 2s ease-out infinite;
}

@keyframes chat-pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.4); opacity: 0; }
}

.chat-greeting {
    position: fixed;
    bottom: 90px;
    right: 24px;
    background: white;
    color: #1a1a2e;
    padding: 10px 16px;
    border-radius: 12px 12px 4px 12px;
    font-size: 14px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 9999;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    max-width: 220px;
}

.chat-greeting.visible {
    opacity: 1;
    transform: translateY(0);
}

.chat-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    border: 1px solid rgba(0,0,0,0.08);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', sans-serif;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.2s ease-out,
                visibility 0s 0.3s;
}

.chat-window.open {
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.2s ease-out,
                visibility 0s 0s;
}

.chat-header {
    background: #29ABE2;
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-title {
    font-size: 15px;
    font-weight: 600;
}

.chat-header-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-close:hover {
    background: rgba(255,255,255,0.15);
}

.chat-header-close:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Header avatar */
.chat-header-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
    object-fit: cover;
    background: #29ABE2;
}

.chat-header-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    border: 2px solid white;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chat-header-subtitle {
    font-size: 12px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.8);
}

.chat-disclaimer {
    background: #f5f5f5;
    padding: 8px 16px;
    font-size: 11px;
    color: #6b7280;
    text-align: center;
    flex-shrink: 0;
}

.chat-disclaimer a {
    color: #29ABE2;
    text-decoration: underline;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    max-width: 80%;
}

.chat-msg-bot {
    align-self: flex-start;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: none;
    max-width: 85%;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #e5e7eb;
    object-fit: cover;
    flex-shrink: 0;
    background: #29ABE2;
}

.chat-msg-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-msg-name {
    font-size: 11px;
    font-weight: 500;
    color: #6b7280;
}

.chat-msg-bot .chat-msg-bubble {
    background: #f5f5f5;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 16px 16px 16px 4px;
    padding: 10px 14px;
    color: #1a1a2e;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-msg-user {
    align-self: flex-end;
}

.chat-msg-user .chat-msg-bubble {
    background: #29ABE2;
    color: white;
    border-radius: 16px 16px 4px 16px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(41, 171, 226, 0.2);
}

/* Message slide-in — only on new messages, not renderHistory() */
.chat-msg-animate {
    animation: chatMsgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

/* Quick reply buttons */
.chat-quick-replies {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 16px 8px;
}

.chat-quick-reply {
    background: #f5f5f5;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: #1a1a2e;
}

.chat-quick-reply:hover {
    border-color: #29ABE2;
    background: rgba(41, 171, 226, 0.05);
}

.chat-quick-reply:focus-visible {
    outline: 2px solid #29ABE2;
    outline-offset: 2px;
}

.chat-quick-reply:active {
    transform: scale(0.97);
}

.chat-msg-system {
    align-self: center;
    background: none;
    color: #6b7280;
    font-size: 13px;
    padding: 4px 0;
}

.chat-msg-typing {
    display: none;
}

.chat-msg-typing.visible {
    display: flex;
}

.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: #f5f5f5;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 16px 16px 16px 4px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6b7280;
    animation: chat-dot 1.4s ease-in-out infinite;
}

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

@keyframes chat-dot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

.chat-input-area {
    display: flex;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    gap: 8px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #29ABE2;
    box-shadow: 0 0 0 3px rgba(41, 171, 226, 0.1);
}

.chat-input::placeholder {
    color: #9ca3af;
}

.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #29ABE2;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send:hover {
    background: #1a94c9;
}

.chat-send:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.chat-send svg {
    width: 18px;
    height: 18px;
    fill: white;
}

@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: 16px 16px 0 0;
    }

    .chat-bubble {
        bottom: 80px;
    }

    .chat-greeting {
        bottom: 146px;
        right: 16px;
    }
}

@media (max-width: 360px) {
    .chat-quick-replies {
        grid-template-columns: 1fr;
    }
}

/* Rozmowa zamknieta (odpowiedz z koniec: true) - pole wpisywania wygaszone,
   pod ostatnia wiadomoscia komunikat .chat-msg-system z tekstem pozegnania. */
.chat-window.chat-ended .chat-input-area {
    opacity: 0.55;
}

.chat-window.chat-ended .chat-input,
.chat-window.chat-ended .chat-send {
    cursor: not-allowed;
}
