﻿/* =========================================================================
 * Chat interno SGC — burbuja flotante abajo a la derecha + panel expandible.
 * Diseno mobile-first; en desktop el panel queda como una ventana fija.
 * ========================================================================= */

#sgcChatBubble {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: 0;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform .15s ease;
}
#sgcChatBubble:hover { transform: scale(1.07); }
#sgcChatBubble[hidden] { display: none !important; }

#sgcChatBubbleBadge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px #fff;
}

#sgcChatPanel {
    position: fixed;
    right: 18px;
    bottom: 86px;
    width: 360px;
    max-width: calc(100vw - 24px);
    height: 540px;
    max-height: calc(100vh - 110px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
    z-index: 9991;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
}
#sgcChatPanel[hidden] { display: none !important; }

@media (max-width: 480px) {
    #sgcChatPanel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    #sgcChatBubble { right: 14px; bottom: 14px; }
}

.chat-header {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}
.chat-header .chat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header .chat-back,
.chat-header .chat-close,
.chat-header .chat-mute {
    background: transparent;
    border: 0;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 6px;
}
.chat-header .chat-back:hover,
.chat-header .chat-close:hover,
.chat-header .chat-mute:hover { background: rgba(255,255,255,.15); }
.chat-header .chat-mute { font-size: 16px; }

.chat-body {
    flex: 1;
    overflow-y: auto;
    background: #f3f4f6;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    border: 1px solid #e5e7eb;
    transition: background .12s;
}
.chat-list-item:hover { background: #f9fafb; }
.chat-list-item .chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #6366f1;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    position: relative;
}
.chat-list-item .chat-avatar.group { background: #10b981; }
.chat-list-item .chat-avatar .dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #9ca3af;
    border: 2px solid #fff;
}
.chat-list-item .chat-avatar .dot.online { background: #22c55e; }
.chat-list-item .chat-info { flex: 1; min-width: 0; }
.chat-list-item .chat-info .name { font-weight: 600; color: #111827; font-size: 14px; }
.chat-list-item .chat-info .preview { color: #6b7280; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item .chat-unread {
    background: #ef4444;
    color: #fff;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.chat-msg {
    max-width: 78%;
    padding: 8px 11px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.35;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chat-msg.mine {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.theirs {
    align-self: flex-start;
    background: #fff;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}
.chat-msg .author {
    font-size: 11px;
    font-weight: 700;
    color: #1d4ed8;
    margin-bottom: 2px;
}
.chat-msg.mine .author { color: #dbeafe; }
.chat-msg .time {
    font-size: 10px;
    color: #6b7280;
    margin-top: 3px;
    text-align: right;
}
.chat-msg.mine .time { color: #c7d2fe; }

.chat-err {
    background: #fee2e2;
    color: #991b1b;
    padding: 8px 12px;
    font-size: 13px;
    border-top: 1px solid #fecaca;
    border-bottom: 1px solid #fecaca;
}
.chat-err[hidden] { display: none !important; }

.chat-footer {
    display: flex;
    gap: 8px;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
}
.chat-footer textarea {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 18px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    max-height: 90px;
    min-height: 36px;
    outline: none;
}
.chat-footer textarea:focus { border-color: #2563eb; }
.chat-footer button {
    background: #2563eb;
    color: #fff;
    border: 0;
    border-radius: 999px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
}
.chat-footer button:disabled { background: #93c5fd; cursor: not-allowed; }

.chat-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    padding: 24px 12px;
}

/* Modal de mensajes pendientes al ingresar */
#sgcChatLoginModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 9995;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
#sgcChatLoginModal[hidden] { display: none !important; }
#sgcChatLoginModal .chat-login-box {
    background: #fff;
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
#sgcChatLoginModal .chat-login-head {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    color: #fff;
    padding: 16px 18px;
    font-weight: 700;
    font-size: 16px;
}
#sgcChatLoginModal .chat-login-body {
    padding: 14px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#sgcChatLoginModal .chat-login-msg {
    border-left: 3px solid #2563eb;
    padding: 6px 10px;
    background: #f3f4f6;
    border-radius: 4px;
}
#sgcChatLoginModal .chat-login-msg .from { font-weight: 700; color: #1d4ed8; font-size: 13px; }
#sgcChatLoginModal .chat-login-msg .body { white-space: pre-wrap; font-size: 14px; color: #111827; margin-top: 2px; }
#sgcChatLoginModal .chat-login-msg .time { font-size: 11px; color: #6b7280; margin-top: 2px; }
#sgcChatLoginModal .chat-login-foot {
    padding: 12px 18px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
#sgcChatLoginModal .chat-login-foot button {
    padding: 9px 18px;
    border-radius: 6px;
    border: 0;
    cursor: pointer;
    font-weight: 600;
}
#sgcChatLoginModal .chat-login-foot .btn-secondary {
    background: #e5e7eb;
    color: #111827;
}
#sgcChatLoginModal .chat-login-foot .btn-primary {
    background: #2563eb;
    color: #fff;
}
