/* ================================================================
   FLOATING CHAT BUTTON
   ================================================================ */
.floating-chat-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
}

.floating-chat-button {
    width: 60px;
    height: 60px;
    background-color: var(--color_2);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    animation: chatPulse 2.5s infinite;
}

.floating-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    animation: none;
}

.floating-chat-button i {
    color: white;
    font-size: 28px;
    pointer-events: none;
}

/* Unread badge on the floating button */
.chat-notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #ff4757;
    color: white;
    border-radius: 50%;
    min-width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    padding: 0 3px;
    animation: badgePop 0.8s infinite alternate;
}

@keyframes chatPulse {
    0%   { box-shadow: 0 0 0 0 rgba(32,72,140,0.55); }
    70%  { box-shadow: 0 0 0 12px rgba(32,72,140,0); }
    100% { box-shadow: 0 0 0 0 rgba(32,72,140,0); }
}

@keyframes badgePop {
    from { transform: scale(1); }
    to   { transform: scale(1.15); }
}


/* ================================================================
   CHAT POPUP
   ================================================================ */
.chat-popup {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 360px;
    height: 500px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    animation: popupSlideIn 0.28s ease;
}

@keyframes popupSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* Header */
.chat-popup-header {
    background: var(--color_2);
    color: #fff;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-popup-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-popup-avatar-wrap {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
}

.chat-popup-title strong {
    display: block;
    font-size: 14px;
    line-height: 1.3;
}

.chat-popup-title small {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-online-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2ecc71;
    flex-shrink: 0;
}

.chat-popup-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-popup-expand-btn,
.chat-popup-close-btn {
    color: #fff;
    background: rgba(255,255,255,0.18);
    border: none;
    border-radius: 7px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    text-decoration: none;
    transition: background 0.2s;
}

.chat-popup-expand-btn:hover,
.chat-popup-close-btn:hover {
    background: rgba(255,255,255,0.32);
    color: #fff;
}

/* Message area */
.chat-popup-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f7fb;
    scroll-behavior: smooth;
}

.chat-popup-messages::-webkit-scrollbar { width: 4px; }
.chat-popup-messages::-webkit-scrollbar-track { background: transparent; }
.chat-popup-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Loading spinner */
.chat-popup-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.loading-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.loading-dots span {
    width: 9px;
    height: 9px;
    background: var(--color_2);
    border-radius: 50%;
    animation: dotBounce 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0.65); opacity: 0.5; }
    40%           { transform: scale(1);    opacity: 1; }
}

/* No messages placeholder */
.chat-no-messages {
    text-align: center;
    color: #aaa;
    margin: auto;
    padding: 20px;
}

.chat-no-messages i {
    font-size: 40px;
    display: block;
    margin-bottom: 8px;
    opacity: 0.5;
}

.chat-no-messages p {
    font-size: 13px;
    line-height: 1.5;
}

/* Individual messages */
.chat-popup-msg {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    max-width: 88%;
    animation: msgFadeIn 0.2s ease;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-popup-msg--sent     { margin-left: auto; flex-direction: row-reverse; }
.chat-popup-msg--received { margin-right: auto; }

.popup-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.popup-msg-avatar--initials {
    background: var(--color_2);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-msg-bubble {
    background: #fff;
    border-radius: 14px 14px 14px 3px;
    padding: 8px 11px;
    font-size: 13px;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    word-break: break-word;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.chat-popup-msg--sent .popup-msg-bubble {
    background: var(--color_2);
    color: #fff;
    border-radius: 14px 14px 3px 14px;
}

.popup-msg-text { line-height: 1.5; white-space: pre-wrap; }

.popup-msg-time {
    font-size: 10px;
    opacity: 0.55;
    margin-top: 4px;
    align-self: flex-end;
}

.popup-msg-img {
    max-width: 200px;
    border-radius: 8px;
    margin-top: 6px;
    cursor: pointer;
    display: block;
}

.popup-msg-file {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: inherit;
    text-decoration: none;
    margin-top: 5px;
    opacity: 0.85;
}

.popup-msg-file:hover { opacity: 1; }

/* Footer */
.chat-popup-footer {
    padding: 9px 11px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
}

.attachment-preview-popup {
    display: flex;
    align-items: center;
    gap: 7px;
    background: #f0f0f0;
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 12px;
    margin-bottom: 7px;
}

.attach-name-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-preview-popup button {
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.chat-popup-input-row {
    display: flex;
    align-items: center;
    gap: 7px;
}

/* Textarea wrapper — attach icon sits inside the right edge */
.chat-popup-textarea-wrap {
    flex: 1;
    position: relative;
    display: flex;
}

.chat-popup-input-row textarea {
    flex: 1;
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 9px 38px 9px 14px;
    font-size: 13px;
    resize: none;
    height: 40px;
    max-height: 40px;
    overflow: hidden;
    outline: none;
    line-height: 1.45;
    background: #f5f7fb;
    transition: border-color 0.2s;
    font-family: inherit;
    box-sizing: border-box;
    min-height: 40px !important;
}

.chat-popup-input-row textarea:focus {
    border-color: var(--color_2);
    background: #fff;
}

/* Attach icon — floats inside the right edge of the textarea */
.chat-popup-attach-btn {
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #aaa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    padding: 0;
    transition: color 0.2s;
    flex-shrink: 0;
}

.chat-popup-attach-btn:hover { color: var(--color_2); }

.chat-popup-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.chat-popup-send-btn {
    background: var(--color_2);
    color: #fff;
}

.chat-popup-send-btn:hover   { opacity: 0.85; }
.chat-popup-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Dark mode support */
.dark-mode .chat-popup {
    background: #1e1e2e;
    border-color: rgba(255,255,255,0.1);
}

.dark-mode .chat-popup-messages { background: #14141f; }

.dark-mode .popup-msg-bubble {
    background: #2a2a3e;
    color: #ddd;
    box-shadow: none;
}

.dark-mode .chat-popup-footer {
    background: #1e1e2e;
    border-top-color: rgba(255,255,255,0.08);
}

.dark-mode .chat-popup-input-row textarea {
    background: #2a2a3e;
    border-color: rgba(255,255,255,0.12);
    color: #e0e0e0;
}

.dark-mode .chat-popup-input-row textarea:focus {
    border-color: var(--color_2);
    background: #32324a;
}

.dark-mode .chat-popup-attach-btn { background: #2a2a3e; color: #aaa; }
.dark-mode .attachment-preview-popup { background: #2a2a3e; color: #ccc; }

/* Responsive */
@media (max-width: 480px) {
    .chat-popup {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 90px;
        height: 65vh;
        max-height: 500px;
    }

    .floating-chat-container {
        right: 15px;
        bottom: 20px;
    }
}
