/* ============================================
   Complex CRM 2.0 - Chat Panel v2
   Nivel 1: Visual Polish
   Nivel 2: Funcionalidad Completa
   Nivel 3: Avanzado
   ============================================ */

/* ===== Panel Lateral ===== */
#chat-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: var(--bs-body-bg, #fff);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.08), -2px 0 8px rgba(0, 0, 0, 0.04);
    z-index: 1050;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(0, 0, 0, 0.06);
}

#chat-panel.open {
    right: 0;
}

/* ===== Overlay ===== */
#chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(2px);
    z-index: 1049;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#chat-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* ===== Header del panel ===== */
.chat-panel-header {
    padding: 14px 20px;
    background: linear-gradient(135deg, #1B84FF 0%, #3699FF 50%, #50b5ff 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(27, 132, 255, 0.25);
    position: relative;
    z-index: 2;
}

.chat-panel-header h5 {
    margin: 0;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.chat-panel-header .btn-close-chat {
    background: rgba(255, 255, 255, 0.35) !important;
    border: 1.5px solid rgba(255, 255, 255, 0.5) !important;
    color: #ffffff !important;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 17px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.chat-panel-header .btn-close-chat i,
.chat-panel-header .btn-close-chat .bi {
    color: #ffffff !important;
}

.chat-panel-header .d-flex > i,
.chat-panel-header .d-flex > .bi,
.chat-panel-header h5 {
    color: #ffffff !important;
}

.chat-panel-header .btn-close-chat:hover {
    background: rgba(255, 255, 255, 0.5) !important;
    border-color: rgba(255, 255, 255, 0.7) !important;
    transform: scale(1.08);
}

/* ===== Search bar ===== */
.chat-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bs-border-color, #eee);
    flex-shrink: 0;
    background: var(--bs-body-bg, #fff);
}

.chat-search input {
    width: 100%;
    border: 1.5px solid var(--bs-border-color, #e4e6ef);
    border-radius: 10px;
    padding: 9px 14px 9px 38px;
    font-size: 13px;
    background: var(--bs-gray-100, #f9fafb);
    outline: none;
    transition: all 0.25s ease;
}

.chat-search input:focus {
    border-color: #3699FF;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.1);
}

.chat-search .search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: #a1a5b7;
    font-size: 14px;
    pointer-events: none;
}

/* ===== Lista de conversaciones ===== */
.chat-conversations-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

/* Scrollbar moderna */
.chat-conversations-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.chat-info-content::-webkit-scrollbar {
    width: 5px;
}

.chat-conversations-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track,
.chat-info-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-conversations-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb,
.chat-info-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
}

.chat-conversations-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-info-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.22);
}

/* ===== Card de conversación ===== */
.chat-conv-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--bs-border-color, #f4f4f8);
    gap: 12px;
    position: relative;
}

.chat-conv-item:hover {
    background: var(--bs-gray-100, #f5f8fa);
    padding-left: 20px;
}

.chat-conv-item.active {
    background: rgba(54, 153, 255, 0.06);
    border-left: 3px solid #3699FF;
    padding-left: 13px;
}

.chat-conv-item.has-unread {
    background: rgba(54, 153, 255, 0.03);
}

/* Avatar con indicador de presencia */
.chat-conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    color: #fff;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.chat-conv-avatar .presence-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2.5px solid var(--bs-body-bg, #fff);
    background: #b5b5c3;
    transition: background 0.3s ease;
}

.chat-conv-avatar .presence-dot.online {
    background: #50CD89;
}

.chat-conv-avatar .group-icon {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #7239EA;
    border: 2px solid var(--bs-body-bg, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #fff;
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--bs-gray-900, #181c32);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-preview {
    font-size: 12.5px;
    color: var(--bs-gray-500, #a1a5b7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
    line-height: 1.3;
}

.chat-conv-preview .sender-name {
    color: var(--bs-gray-700, #5e6278);
    font-weight: 500;
}

.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

.chat-conv-time {
    font-size: 11px;
    color: var(--bs-gray-500, #a1a5b7);
    font-weight: 500;
}

.chat-conv-badge {
    background: #3699FF;
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Muted icon */
.chat-conv-muted {
    color: var(--bs-gray-400, #b5b5c3);
    font-size: 12px;
}

/* ===== Vista de conversación ===== */
.chat-conv-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--bs-border-color, #eee);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    background: var(--bs-body-bg, #fff);
}

.chat-conv-header .btn-back {
    background: none;
    border: none;
    color: var(--bs-gray-600);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-conv-header .btn-back:hover {
    background: var(--bs-gray-100, #f5f8fa);
    color: #3699FF;
}

.chat-conv-header-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-header-info .conv-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--bs-gray-900, #181c32);
}

.chat-conv-header-info .conv-status {
    font-size: 11.5px;
    color: var(--bs-gray-500, #a1a5b7);
    margin-top: 1px;
}

.chat-conv-header-info .conv-status.online {
    color: #50CD89;
}

/* Conv header action buttons */
.chat-conv-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-conv-action {
    background: none;
    border: none;
    color: var(--bs-gray-500, #a1a5b7);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 15px;
}

.btn-conv-action:hover {
    background: var(--bs-gray-100, #f5f8fa);
    color: #3699FF;
}

/* ===== Mensajes ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bs-gray-100, #f9fafb);
}

/* Drag & drop zone */
.chat-messages.drag-over {
    background: rgba(54, 153, 255, 0.06);
    outline: 2px dashed #3699FF;
    outline-offset: -8px;
}

/* Separador de fecha */
.chat-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    gap: 12px;
}

.chat-date-separator span {
    background: var(--bs-body-bg, #fff);
    color: var(--bs-gray-600, #78829d);
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 14px;
    border-radius: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    letter-spacing: 0.2px;
}

/* Burbuja de mensaje */
.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 82%;
    animation: msgFadeIn 0.25s ease-out;
    position: relative;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-content {
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-msg .sender-label {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    padding-left: 4px;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* Burbuja de otros */
.chat-msg:not(.own) .chat-msg-bubble {
    background: var(--bs-body-bg, #fff);
    color: var(--bs-gray-900, #181c32);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--bs-border-color, #f0f0f5);
}

/* Burbuja propia */
.chat-msg.own .chat-msg-bubble {
    background: linear-gradient(135deg, #3699FF 0%, #1B84FF 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    border: none;
}

/* Links en burbujas */
.chat-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.9;
}

.chat-msg-bubble a:hover {
    opacity: 1;
}

.chat-msg-time {
    font-size: 10px;
    color: var(--bs-gray-400, #b5b5c3);
    margin-top: 3px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-msg.own .chat-msg-time {
    justify-content: flex-end;
    color: var(--bs-gray-400, #b5b5c3);
}

/* Mensaje del sistema */
.chat-msg-system {
    text-align: center;
    font-size: 12px;
    color: var(--bs-gray-500);
    padding: 8px 0;
    font-style: italic;
}

/* Mensaje highlight (scroll-to animation) */
.chat-msg.highlight .chat-msg-bubble {
    animation: msgHighlight 1.5s ease;
}

@keyframes msgHighlight {
    0%, 100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); }
    25%, 75% { box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.3), 0 0 12px rgba(54, 153, 255, 0.15); }
}

/* Mensaje pinneado */
.chat-msg.pinned .chat-msg-bubble {
    border-left: 3px solid #FFC700;
}

.chat-msg.own.pinned .chat-msg-bubble {
    border-right: 3px solid #FFC700;
    border-left: none;
}

/* ===== Reply-to reference (dentro del mensaje) ===== */
.msg-reply-ref {
    background: rgba(0, 0, 0, 0.06);
    border-left: 3px solid #3699FF;
    border-radius: 0 8px 8px 0;
    padding: 5px 10px;
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 1px;
    transition: background 0.2s;
}

.msg-reply-ref:hover {
    background: rgba(0, 0, 0, 0.1);
}

.chat-msg.own .msg-reply-ref {
    background: rgba(255, 255, 255, 0.15);
    border-left-color: rgba(255, 255, 255, 0.5);
}

.chat-msg.own .msg-reply-ref:hover {
    background: rgba(255, 255, 255, 0.22);
}

.reply-ref-name {
    font-size: 11px;
    font-weight: 600;
    color: #3699FF;
}

.chat-msg.own .reply-ref-name {
    color: rgba(255, 255, 255, 0.85);
}

.reply-ref-text {
    font-size: 12px;
    color: var(--bs-gray-600, #78829d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.chat-msg.own .reply-ref-text {
    color: rgba(255, 255, 255, 0.7);
}

/* ===== Pinned badge on message ===== */
.msg-pinned-badge {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    color: #FFC700;
    gap: 3px;
    padding: 1px 0;
}

/* ===== Image messages ===== */
.chat-msg-bubble.msg-image {
    padding: 4px;
    background: transparent !important;
    box-shadow: none;
    border: none !important;
}

.chat-msg-bubble.msg-image img {
    max-width: 240px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    object-fit: cover;
    transition: transform 0.2s;
    display: block;
}

.chat-msg-bubble.msg-image img:hover {
    transform: scale(1.02);
}

/* ===== File messages ===== */
.chat-msg-bubble.msg-file {
    padding: 10px 14px;
}

.chat-msg-bubble.msg-file a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 13px;
}

.chat-msg-bubble.msg-file a:hover {
    text-decoration: underline;
}

.chat-msg-bubble.msg-file i {
    font-size: 18px;
    opacity: 0.7;
}

/* ===== Reactions on messages ===== */
.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
    padding: 0 2px;
}

.msg-reaction {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 13px;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #e4e6ef);
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1.4;
}

.msg-reaction:hover {
    background: rgba(54, 153, 255, 0.08);
    border-color: #3699FF;
}

.msg-reaction.me {
    background: rgba(54, 153, 255, 0.1);
    border-color: #3699FF;
    color: #3699FF;
    font-weight: 600;
}

/* ===== Reaction hover button ===== */
.msg-react-btn {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #e4e6ef);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    color: var(--bs-gray-500);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    transition: all 0.2s;
    z-index: 5;
}

.chat-msg:hover .msg-react-btn {
    display: flex;
}

.msg-react-btn:hover {
    background: #3699FF;
    color: #fff;
    border-color: #3699FF;
    transform: scale(1.1);
}

.chat-msg.own .msg-react-btn {
    right: auto;
    left: -4px;
}

/* ===== Reaction picker (floating) ===== */
.reaction-picker {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--bs-body-bg, #fff);
    border-radius: 20px;
    padding: 6px 8px;
    display: flex;
    gap: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
    z-index: 20;
    animation: reactionPickerIn 0.2s ease;
    border: 1px solid var(--bs-border-color, #e4e6ef);
}

@keyframes reactionPickerIn {
    from { opacity: 0; transform: translateY(6px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg.own .reaction-picker {
    left: auto;
    right: 0;
}

.reaction-picker span {
    font-size: 20px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 8px;
    transition: all 0.15s;
    line-height: 1;
}

.reaction-picker span:hover {
    background: var(--bs-gray-100, #f5f8fa);
    transform: scale(1.25);
}

/* ===== Read receipts ===== */
.read-check {
    font-size: 11px;
    color: var(--bs-gray-400, #b5b5c3);
    letter-spacing: -2px;
    font-weight: 600;
}

.read-check.read {
    color: #3699FF;
}

/* ===== Typing indicator ===== */
.chat-typing {
    font-size: 12px;
    color: var(--bs-gray-500);
    padding: 0;
    min-height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 0 2px;
}

.typing-dots span {
    width: 5px;
    height: 5px;
    background: #3699FF;
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== Reply preview (above input) ===== */
.chat-reply-preview {
    padding: 8px 16px;
    border-top: 1px solid var(--bs-border-color, #eee);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    background: rgba(54, 153, 255, 0.04);
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-reply-preview .reply-info {
    flex: 1;
    min-width: 0;
    border-left: 3px solid #3699FF;
    padding-left: 10px;
}

.chat-reply-preview .reply-to-name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #3699FF;
}

.chat-reply-preview .reply-to-text {
    display: block;
    font-size: 12px;
    color: var(--bs-gray-600, #78829d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-reply-preview .reply-close {
    background: none;
    border: none;
    color: var(--bs-gray-500);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chat-reply-preview .reply-close:hover {
    background: var(--bs-gray-200);
    color: var(--bs-gray-700);
}

/* ===== Input de mensaje ===== */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--bs-border-color, #eee);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: var(--bs-body-bg, #fff);
}

.chat-input-area textarea {
    flex: 1;
    border: 1.5px solid var(--bs-border-color, #e4e6ef);
    border-radius: 14px;
    padding: 10px 16px;
    font-size: 13.5px;
    resize: none;
    max-height: 100px;
    outline: none;
    background: var(--bs-gray-100, #f9fafb);
    transition: all 0.25s ease;
    line-height: 1.4;
}

.chat-input-area textarea:focus {
    border-color: #3699FF;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(54, 153, 255, 0.08);
}

.chat-input-area textarea::placeholder {
    color: var(--bs-gray-400, #b5b5c3);
}

/* Emoji & Attach buttons */
.chat-input-area .btn-emoji,
.chat-input-area .btn-attach {
    background: none;
    border: none;
    color: var(--bs-gray-400, #b5b5c3);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
}

.chat-input-area .btn-emoji:hover,
.chat-input-area .btn-attach:hover {
    background: var(--bs-gray-100, #f5f8fa);
    color: #3699FF;
}

.chat-input-area .btn-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bs-gray-300, #dbdfe9);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
    flex-shrink: 0;
}

.chat-input-area .btn-send.active {
    background: linear-gradient(135deg, #3699FF, #1B84FF);
    box-shadow: 0 2px 8px rgba(54, 153, 255, 0.3);
}

.chat-input-area .btn-send.active:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(54, 153, 255, 0.4);
}

.chat-input-area .btn-send:disabled {
    background: var(--bs-gray-300);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* ===== Emoji Picker ===== */
.chat-emoji-picker {
    padding: 10px 12px;
    border-top: 1px solid var(--bs-border-color, #eee);
    background: var(--bs-body-bg, #fff);
    flex-shrink: 0;
    animation: slideDown 0.2s ease;
    max-height: 180px;
    overflow-y: auto;
}

.emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.emoji-item {
    font-size: 22px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    transition: all 0.15s;
    line-height: 1;
    text-align: center;
}

.emoji-item:hover {
    background: var(--bs-gray-100, #f5f8fa);
    transform: scale(1.2);
}

/* ===== Search in messages bar ===== */
.chat-msg-search {
    padding: 8px 12px;
    border-bottom: 1px solid var(--bs-border-color, #eee);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: var(--bs-body-bg, #fff);
    animation: slideDown 0.2s ease;
}

.chat-msg-search input {
    flex: 1;
    border: 1.5px solid var(--bs-border-color, #e4e6ef);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    outline: none;
    background: var(--bs-gray-100, #f9fafb);
    transition: border-color 0.2s;
}

.chat-msg-search input:focus {
    border-color: #3699FF;
}

.chat-msg-search .search-count {
    font-size: 11px;
    color: var(--bs-gray-500);
    white-space: nowrap;
    min-width: 60px;
    text-align: center;
}

.btn-search-nav,
.btn-search-close {
    background: none;
    border: none;
    color: var(--bs-gray-500);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 14px;
}

.btn-search-nav:hover,
.btn-search-close:hover {
    background: var(--bs-gray-100, #f5f8fa);
    color: #3699FF;
}

/* Search highlight on bubbles */
.chat-msg-bubble.search-highlight {
    box-shadow: 0 0 0 2px rgba(255, 199, 0, 0.5), 0 0 8px rgba(255, 199, 0, 0.2) !important;
}

/* ===== Pinned messages bar ===== */
.chat-pinned-bar {
    padding: 8px 14px;
    border-bottom: 1px solid var(--bs-border-color, #eee);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: rgba(255, 199, 0, 0.06);
    color: var(--bs-gray-700, #5e6278);
    font-size: 12.5px;
    animation: slideDown 0.2s ease;
}

.chat-pinned-bar i {
    color: #FFC700;
    font-size: 14px;
}

.chat-pinned-bar span {
    flex: 1;
    font-weight: 500;
}

.btn-pinned-close {
    background: none;
    border: none;
    color: var(--bs-gray-500);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-pinned-close:hover {
    color: var(--bs-gray-700);
}

/* ===== Context Menu ===== */
.chat-context-menu {
    position: absolute;
    background: var(--bs-body-bg, #fff);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--bs-border-color, #e4e6ef);
    z-index: 100;
    min-width: 150px;
    padding: 6px 0;
    animation: ctxMenuIn 0.15s ease;
}

@keyframes ctxMenuIn {
    from { opacity: 0; transform: scale(0.95) translateY(-4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.ctx-item {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--bs-gray-700, #5e6278);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.15s;
}

.ctx-item:hover {
    background: var(--bs-gray-100, #f5f8fa);
    color: #3699FF;
}

.ctx-item i {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.ctx-item[data-action="delete"] {
    color: #F1416C;
}

.ctx-item[data-action="delete"]:hover {
    background: rgba(241, 65, 108, 0.06);
    color: #F1416C;
}

/* ===== Group Info View ===== */
.chat-info-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
}

.info-header {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--bs-border-color, #eee);
    margin-bottom: 16px;
}

.info-header h6 {
    font-weight: 700;
    font-size: 16px;
    color: var(--bs-gray-900, #181c32);
    margin-bottom: 4px;
}

.info-section {
    margin-bottom: 16px;
}

.info-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--bs-gray-500, #a1a5b7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.info-member {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--bs-border-color, #f4f4f8);
}

.info-member:last-child {
    border-bottom: none;
}

/* ===== Empty state ===== */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-empty .empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(54, 153, 255, 0.08), rgba(54, 153, 255, 0.15));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.chat-empty .empty-icon i {
    font-size: 32px;
    color: #3699FF;
}

.chat-empty i:not(.empty-icon i) {
    font-size: 48px;
    color: var(--bs-gray-300);
    margin-bottom: 16px;
}

.chat-empty h6 {
    color: var(--bs-gray-700);
    margin-bottom: 6px;
    font-weight: 600;
}

.chat-empty p {
    color: var(--bs-gray-500);
    font-size: 13px;
    line-height: 1.4;
}

/* ===== New conversation ===== */
.chat-user-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    gap: 12px;
}

.chat-user-item:hover {
    background: var(--bs-gray-100, #f5f8fa);
    padding-left: 20px;
}

.chat-user-online {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #50cd89;
    border: 2px solid #fff;
    position: absolute;
    bottom: 0;
    right: 0;
}

/* ===== Tabs nueva conversacion ===== */
.chat-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--bs-gray-500, #a1a5b7);
    cursor: pointer;
    transition: all 0.25s ease;
    border-bottom: 2.5px solid transparent;
    position: relative;
}

.chat-tab:hover {
    color: var(--bs-gray-700, #5e6278);
}

.chat-tab.active {
    color: #3699FF;
    border-bottom-color: #3699FF;
}

/* ===== Group badges ===== */
.chat-group-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 14px;
    background: rgba(54, 153, 255, 0.08);
    color: #3699FF;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.chat-group-badge:hover {
    background: rgba(54, 153, 255, 0.14);
}

.chat-group-badge .remove-member {
    cursor: pointer;
    opacity: 0.6;
    font-size: 14px;
    line-height: 1;
    transition: opacity 0.15s;
}

.chat-group-badge .remove-member:hover {
    opacity: 1;
}

/* ===== Attach Menu ===== */
.chat-attach-wrapper {
    position: relative;
}
.chat-attach-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: #1e1e2d;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 6px 0;
    flex-direction: column;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 20;
}
.attach-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #B5B5C3;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}
.attach-menu-item:hover {
    background: rgba(54, 153, 255, 0.1);
    color: #fff;
}
.attach-menu-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

/* ===== Drive Picker ===== */
.chat-drive-picker {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1B1B29;
    display: flex;
    flex-direction: column;
    z-index: 30;
}
.drive-picker-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.drive-picker-title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
    color: #fff;
}
.drive-picker-breadcrumb {
    padding: 8px 16px;
    font-size: 12px;
    color: #7E8299;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.drive-picker-breadcrumb .breadcrumb-item {
    cursor: pointer;
    transition: color 0.15s;
}
.drive-picker-breadcrumb .breadcrumb-item:hover {
    color: #3699FF;
}
.drive-picker-breadcrumb .breadcrumb-item.active {
    color: #B5B5C3;
    font-weight: 500;
}
.drive-picker-search {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: #7E8299;
}
.drive-picker-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: 13px;
}
.drive-picker-search input::placeholder { color: #565674; }
.drive-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.drive-picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
}
.drive-picker-item:hover {
    background: rgba(54, 153, 255, 0.08);
}
.drive-item-info {
    flex: 1;
    min-width: 0;
}
.drive-item-name {
    font-size: 13px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.drive-item-meta {
    font-size: 11px;
    color: #7E8299;
    margin-top: 1px;
}

/* ===== Responsive ===== */
@media (max-width: 576px) {
    #chat-panel {
        width: 100%;
        right: -100%;
    }
}
