/* ============================================
   Floating Chat Widget - BC.UI
   Accessible from any page
   ============================================ */

/* Floating button */
.chat-widget-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7460ee 0%, #563dea 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(116, 96, 238, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    transition: all 0.3s ease;
}

.chat-widget-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(116, 96, 238, 0.5);
}

/* Unread count badge on the FAB */
.chat-widget-fab .widget-unread {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #dc3545;
    color: white;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 12px;
    min-width: 22px;
    height: 22px;
    line-height: 18px;
    text-align: center;
    border: 2.5px solid white;
    display: none;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.5);
    z-index: 10001;
    animation: badgeBounce 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes badgeBounce {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Persistent animated ring when there are unreads (even without popup cards) */
.chat-widget-fab.has-unreads::after {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 2.5px solid #dc3545;
    animation: unreadRing 2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes unreadRing {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 0; transform: scale(1.3); }
}

/* Panel */
.chat-widget-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 10001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}

.chat-widget-panel.open {
    display: flex;
}

.chat-widget-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #7460ee 0%, #563dea 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-widget-header h6 {
    margin: 0;
    font-weight: 600;
}

.chat-widget-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.8;
}

.chat-widget-close:hover { opacity: 1; }

/* Conversation list in widget */
.chat-widget-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.chat-widget-conv {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-widget-conv:hover {
    background: #f8f9fa;
}

.chat-widget-conv-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #7460ee;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 13px;
    flex-shrink: 0;
}

.chat-widget-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-widget-conv-title {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-widget-conv-preview {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-widget-conv-badge {
    background: #dc3545;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* Chat view inside widget */
.chat-widget-chat {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-widget-chat.active {
    display: flex;
}

.chat-widget-chat-header {
    padding: 10px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chat-widget-back {
    background: none;
    border: none;
    color: #7460ee;
    cursor: pointer;
    padding: 4px;
    font-size: 16px;
}

.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fa;
    min-height: 0;
}

.chat-widget-msg {
    margin-bottom: 8px;
    display: flex;
    align-items: flex-end;
}

.chat-widget-msg.own {
    flex-direction: row-reverse;
}

.chat-widget-msg-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    font-size: 13px;
}

.chat-widget-msg.own .chat-widget-msg-bubble {
    background: #7460ee;
    color: white;
}

.chat-widget-msg-sender {
    font-weight: 600;
    font-size: 11px;
    color: #7460ee;
    margin-bottom: 2px;
}

.chat-widget-msg-time {
    font-size: 9px;
    color: #999;
    text-align: right;
    margin-top: 2px;
}

.chat-widget-msg.own .chat-widget-msg-time {
    color: rgba(255,255,255,0.6);
}

.chat-widget-input {
    padding: 8px 12px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

.chat-widget-input input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    outline: none;
}

.chat-widget-input input:focus {
    border-color: #7460ee;
}

.chat-widget-input button {
    background: #7460ee;
    color: white;
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-widget-input button:hover {
    background: #563dea;
}

.chat-widget-footer {
    padding: 8px 16px;
    text-align: center;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.chat-widget-footer a {
    color: #7460ee;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.chat-widget-footer a:hover {
    text-decoration: underline;
}

/* ============================================
   Popup notification cards (stacking above FAB)
   ============================================ */
.chat-widget-notifications {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 10002;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
    max-height: 60vh;
    overflow: hidden;
}

.chat-notify-card {
    width: 340px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    pointer-events: all;
    animation: notifySlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    transition: opacity 0.3s, transform 0.3s;
    border-left: 4px solid #7460ee;
    position: relative;
    overflow: hidden;
}

.chat-notify-card:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(116, 96, 238, 0.3);
    transform: translateX(-4px);
}

.chat-notify-card.removing {
    opacity: 0;
    transform: translateX(100%);
}

@keyframes notifySlideIn {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.chat-notify-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7460ee, #563dea);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-notify-body {
    flex: 1;
    min-width: 0;
}

.chat-notify-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}

.chat-notify-sender {
    font-weight: 700;
    font-size: 13px;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-notify-time {
    font-size: 11px;
    color: #adb5bd;
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-notify-conv {
    font-size: 11px;
    color: #7460ee;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-notify-preview {
    font-size: 13px;
    color: #495057;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.chat-notify-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #adb5bd;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
    pointer-events: all;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-notify-card:hover .chat-notify-close {
    opacity: 1;
}

.chat-notify-close:hover {
    color: #dc3545;
}

/* Progress bar at bottom of card */
.chat-notify-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #7460ee, #563dea);
    border-radius: 0 0 0 12px;
    animation: notifyCountdown 8s linear forwards;
}

@keyframes notifyCountdown {
    from { width: 100%; }
    to { width: 0%; }
}

/* Pulse effect on FAB when there are notifications */
.chat-widget-fab.has-notifications {
    animation: fabPulse 1.5s ease-in-out infinite;
}

@keyframes fabPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(116, 96, 238, 0.4); }
    50% { box-shadow: 0 4px 24px rgba(116, 96, 238, 0.7), 0 0 0 8px rgba(116, 96, 238, 0.1); }
}

/* Hide on chat page and on very small screens where panel would be too cramped */
body[data-page="chat"] .chat-widget-fab,
body[data-page="chat"] .chat-widget-panel,
body[data-page="chat"] .chat-widget-notifications {
    display: none !important;
}

@media (max-width: 480px) {
    .chat-widget-panel {
        right: 8px;
        left: 8px;
        width: auto;
        bottom: 80px;
        max-height: 70vh;
    }

    .chat-widget-notifications {
        right: 8px;
        left: 8px;
        bottom: 86px;
    }

    .chat-notify-card {
        width: auto;
    }
}
