/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--font-family);
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s;
    padding: 0;
    overflow: hidden;
}

.chat-btn-text {
    display: none;
    font-size: 16px;
    margin-left: 8px;
    white-space: nowrap;
    font-weight: bold;
}

.chat-toggle-btn:hover {
    width: auto;
    padding: 0 20px;
    transform: scale(1.05);
}

.chat-toggle-btn:hover .chat-btn-text {
    display: inline-block;
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #eee;
}

.chat-window.active {
    display: flex;
}

.chat-header {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
}

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f9f9f9;
}

.chat-footer {
    padding: 10px;
    border-top: 1px solid #eee;
    background: white;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
}

.chat-send-btn, .chat-upload-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 18px;
}

.message-actions {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 100%;
    margin-right: 5px;
    background: white;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    padding: 2px;
}

.message.user .message-actions {
    right: 100%;
    margin-right: 8px;
}

/* Bridge the gap between message and actions to prevent hover loss */
.message-actions::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 100%;
    width: 20px; /* Wide enough to cover the margin */
    background: transparent;
}

.message:hover .message-actions {
    display: flex;
}

.message-actions button {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 12px;
}

.message-actions button:hover {
    color: var(--primary-color);
    background: #f0f0f0;
    border-radius: 3px;
}

.message.recalled .message-content {
    background: #f0f0f0;
    color: #999;
    font-style: italic;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 4px;
    box-shadow: none;
}

.message.recalled {
    justify-content: center;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    margin-bottom: 0; /* Reset */
    position: relative; /* For message actions positioning */
}

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.agent {
    align-self: flex-start;
    align-items: flex-start;
}

.message.system {
    align-self: center;
    align-items: center;
    max-width: 100%;
    margin: 10px 0;
}

.message-content {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 2px;
}

.message.agent .message-content {
    background: white;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 2px;
}

.message.system .message-content {
    background: #f0f2f5;
    color: #666;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    box-shadow: none;
}

.message-meta {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    margin-left: 2px;
    margin-right: 2px;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}

.message-content a {
    color: inherit;
    text-decoration: underline;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-btn {
    padding: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.category-btn:hover {
    background: #f0f0f0;
    border-color: var(--primary-color);
}

.chat-messages {
    display: flex;
    flex-direction: column;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 30px; /* Move up slightly */
        right: 20px;
        z-index: 2147483647; /* Max z-index */
    }

    .chat-toggle-btn {
        width: auto;
        height: 50px;
        padding: 0 20px;
        border-radius: 25px;
        font-size: 20px;
    }

    .chat-btn-text {
        display: inline-block; /* Always show text on mobile */
        font-size: 15px;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        z-index: 2147483647;
        display: none; /* Hidden by default */
        flex-direction: column;
    }

    .chat-window.active {
        display: flex;
    }

    .chat-body {
        flex: 1;
        height: auto;
    }

    .chat-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

.editing-bar {
    background: #f9f9f9;
    padding: 6px 15px;
    font-size: 12px;
    color: var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
}

.editing-cancel-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0 5px;
    font-size: 14px;
}

.editing-cancel-btn:hover {
    color: #666;
}
