/* === CHAT WIDGET === */

/* Floating Action Button */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #0b3b85;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 999;
    transition: transform 0.15s, background 0.15s;
}
.chat-fab:hover { transform: scale(1.08); background: #0a2f6b; }
.chat-fab.hidden { display: none; }
.chat-fab-icon { font-size: 1.6rem; }
.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53e3e;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.mail-page.theme-nma .chat-fab { background: #ff4757; }
.mail-page.theme-nma .chat-fab:hover { background: #e8414f; }
.mail-page.theme-bom .chat-fab { background: #e53e3e; }
.mail-page.theme-bom .chat-fab:hover { background: #d03030; }

/* Chat Panel */
.chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #0b3b85;
    color: white;
}
.chat-header h3 { margin: 0; font-size: 1rem; flex: 1; }
.chat-header-info { flex: 1; }
.chat-header-name { display: block; font-weight: 600; font-size: 0.95rem; }
.chat-header-role { display: block; font-size: 0.75rem; opacity: 0.8; }
.chat-close, .chat-back {
    background: none;
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.8;
}
.chat-close:hover, .chat-back:hover { opacity: 1; }

.mail-page.theme-nma .chat-header { background: #2d3748; }
.mail-page.theme-bom .chat-header { background: #4a5568; }

/* Search */
.chat-search {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
}
.chat-search input {
    width: 100%;
    padding: 0.4rem 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
    box-sizing: border-box;
}

/* Contact List */
.chat-contacts {
    flex: 1;
    overflow-y: auto;
}
.chat-contact {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f8f8f8;
    transition: background 0.1s;
}
.chat-contact:hover { background: #f5f8ff; }
.chat-contact.unread { background: #f0f4ff; }

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e8f0fe;
    color: #0b3b85;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
    position: relative;
}
.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
}
.online-dot.online { background: #48bb78; }
.online-dot.offline { background: #cbd5e0; }

.contact-info {
    flex: 1;
    min-width: 0;
}
.contact-name {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: #333;
}
.contact-role {
    display: block;
    font-size: 0.7rem;
    color: #999;
}
.contact-last-msg {
    display: block;
    font-size: 0.75rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.contact-badge {
    background: #e53e3e;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.chat-loading, .chat-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: #999;
    font-size: 0.9rem;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    background: #f0f2f5;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.chat-msg {
    display: flex;
    max-width: 85%;
}
.chat-msg.mine {
    align-self: flex-end;
    justify-content: flex-end;
}
.chat-msg.theirs {
    align-self: flex-start;
}

.msg-bubble {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
}
.chat-msg.mine .msg-bubble {
    background: #dcf8c6;
    border-bottom-right-radius: 4px;
}
.chat-msg.theirs .msg-bubble {
    background: white;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.msg-text { display: inline; }
.msg-time {
    display: inline-block;
    font-size: 0.65rem;
    color: #999;
    margin-left: 0.5rem;
    vertical-align: bottom;
}
.msg-read {
    font-size: 0.65rem;
    color: #4fc3f7;
    margin-left: 0.15rem;
}

/* Typing indicator */
.typing-indicator {
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    color: #999;
    font-style: italic;
    background: #f0f2f5;
}

/* Input */
.chat-input {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-top: 1px solid #e0e0e0;
    background: white;
}
.chat-input input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
}
.chat-input input:focus { border-color: #0b3b85; }
.chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #0b3b85;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-send:hover { background: #0a2f6b; }
.chat-send:disabled { background: #cbd5e0; cursor: default; }

.mail-page.theme-nma .chat-send { background: #ff4757; }
.mail-page.theme-bom .chat-send { background: #e53e3e; }

/* Responsive */
@media (max-width: 480px) {
    .chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 8px;
        right: 8px;
        border-radius: 8px;
    }
}
