:root {
    --chat-primary-color: #0073e6;
    --chat-secondary-color: #0056b3;
    --chat-background-color: #ffffff;
    --chat-header-bg: #f7f9fa;
    --chat-text-light: #ffffff;
    --chat-text-dark: #2c3e50;
    --chat-text-secondary: #7f8c8d;
    --user-message-bg: #0073e6;
    --admin-message-bg: #e5e5ea;
    --chat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --chat-error-color: #ef4444; /* Колір для індикатора */
}

#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

#chat-bubble {
    width: 60px;
    height: 60px;
    background: var(--chat-primary-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}
#chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

/* ✅ Нові стилі для анімації іконок */
#chat-bubble svg {
    position: absolute;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}
#chat-bubble svg.hidden {
    transform: rotate(-90deg) scale(0.5);
    opacity: 0;
}

/* ✅ Нові стилі для лічильника */
#chat-unread-indicator {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: var(--chat-error-color);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid white;
    transform: scale(0);
    transition: transform 0.2s ease-out;
}
#chat-unread-indicator:not(.hidden) {
    transform: scale(1);
}

#chat-window {
    width: 370px;
    height: 650px;
    max-height: calc(100vh - 100px);
    background-color: var(--chat-background-color);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: 85px;
    right: 0;
    font-family: var(--chat-font);
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform-origin: bottom right;
}
#chat-window.hidden {
    transform: scale(0.95);
    opacity: 0;
    pointer-events: none;
}

#chat-header {
    background-color: var(--chat-header-bg);
    padding: 15px 20px;
    border-bottom: 1px solid #e7e7e7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.header-info { display: flex; align-items: center; gap: 12px; }
.chat-logo { width: 45px; height: 45px; border-radius: 50%; object-fit: cover; }
.chat-title { font-weight: 600; font-size: 16px; color: var(--chat-text-dark); }
.chat-status { font-size: 13px; color: var(--chat-text-secondary); }

#chat-messages {
    flex-grow: 1; padding: 20px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 4px;
    background-color: #f0f2f5;
}
.message {
    padding: 10px 15px; border-radius: 20px; max-width: 80%;
    line-height: 1.5; word-wrap: break-word; font-size: 15px;
    display: flex; flex-direction: column; animation: fadeIn 0.3s ease;
}
.message.user {
    background-color: var(--user-message-bg); color: var(--chat-text-light);
    align-self: flex-end; border-bottom-right-radius: 5px;
}
.message.admin {
    background-color: var(--admin-message-bg); color: var(--chat-text-dark);
    align-self: flex-start; border-bottom-left-radius: 5px;
}
.message-footer {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 5px; margin-top: 5px;
}
.message .timestamp { font-size: 11px; color: rgba(255, 255, 255, 0.7); }
.message.admin .timestamp { color: var(--chat-text-secondary); align-self: flex-start; }
.message .read-status { font-size: 16px; color: rgba(255, 255, 255, 0.7); }
.message .read-status.read { color: #4fc3f7; }

.message-image { max-width: 100%; border-radius: 15px; cursor: pointer; margin-top: 5px; }

#chat-input-container {
    display: flex; align-items: center; padding: 10px 15px;
    border-top: 1px solid #e7e7e7; background-color: var(--chat-header-bg);
}
#chat-input {
    flex-grow: 1; border: none; background-color: #fff;
    border-radius: 20px; padding: 12px 18px; font-size: 15px;
    outline: none; font-family: var(--chat-font);
    border: 1px solid #ddd; margin: 0 10px;
}
.chat-action-btn {
    background: none; border: none; color: var(--chat-primary-color);
    border-radius: 50%; width: 44px; height: 44px; cursor: pointer;
    flex-shrink: 0; display: flex; justify-content: center; align-items: center;
    transition: background-color 0.2s;
}
.chat-action-btn:hover { background-color: #f0f0f0; }
#send-btn svg { fill: var(--chat-primary-color); }

#chat-image-modal {
    position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%;
    overflow: auto; background-color: rgba(0,0,0,0.85);
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
}
.chat-modal-content {
    margin: auto; display: block; max-width: 90%; max-height: 90%;
    border-radius: 5px;
}
.chat-modal-close {
    position: absolute; top: 15px; right: 35px; color: #f1f1f1;
    font-size: 40px; font-weight: bold; transition: 0.3s; cursor: pointer;
}
.hidden { display: none !important; }

.message.pending {
    opacity: 0.6;
}
.message.error .message-footer::before {
    content: "Failed to send.";
    color: var(--chat-error-color);
    font-size: 10px;
    margin-right: 5px;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }