/* Chat Viewer Styles - WhatsApp-like bubbles */

.chat-container {
    display: flex;
    height: calc(100vh - 200px);
    gap: 16px;
}

/* Chat List */
.chat-list {
    width: 320px;
    background-color: var(--color-bg-card);
    border-radius: 12px;
    border: 1px solid var(--color-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-list-header {
    padding: 16px;
    background-color: var(--color-secondary-light);
    border-bottom: 1px solid var(--color-border);
}

.chat-list-header h3 {
    font-size: 18px;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.chat-list-search {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--color-bg-dark);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    font-size: 14px;
}

.chat-list-items {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.chat-item:hover {
    background-color: var(--color-secondary-light);
    border-color: var(--color-border);
}

.chat-item.active {
    background-color: rgba(255, 215, 0, 0.1);
    border-color: var(--color-primary);
}

.chat-item-id {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
    font-size: 14px;
}

.chat-item-date {
    font-size: 12px;
    color: var(--color-text-secondary);
}

/* Chat Viewer */
.chat-viewer {
    flex: 1;
    background-color: var(--color-bg-card);
    border-radius: 12px;
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-viewer-header {
    padding: 16px 20px;
    background-color: var(--color-secondary-light);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-viewer-header h3 {
    font-size: 18px;
    color: var(--color-primary);
}

.chat-viewer-info {
    font-size: 12px;
    color: var(--color-text-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(to bottom, var(--color-bg-dark) 0%, var(--color-bg-card) 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    position: relative;
}

/* Cuando hay un mensaje vacío, centrar el contenido */
.chat-messages .chat-empty {
    align-self: center;
    margin: auto;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 90%;
    width: auto;
    min-width: auto;
    animation: fadeIn 0.3s ease;
}

/* Mensajes del cliente alineados a la derecha */
.chat-message-cliente {
    align-self: flex-end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
    width: auto;
    max-width: 90%;
    min-width: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Ajustar contenedor según tipo de mensaje */
.chat-message-cliente .mensaje-corto {
    align-self: flex-end;
    max-width: none !important;
}

.chat-message-cliente .mensaje-medio {
    align-self: flex-end;
}

.chat-message-cliente .mensaje-largo {
    align-self: stretch;
    width: 100%;
    max-width: min(90%, 600px) !important;
}

/* Mensajes del bot alineados a la izquierda */
.chat-message-bot {
    align-self: flex-start !important;
    margin-left: 0 !important;
    margin-right: auto !important;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Estilos base para mensajes del cliente */
.mensaje-cliente {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-secondary);
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.2);
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: normal;
    white-space: normal;
    position: relative;
    text-align: left;
    display: inline-block;
    box-sizing: border-box;
    overflow: visible;
}

/* Mensajes cortos: se ajustan completamente al contenido */
.mensaje-cliente.mensaje-corto {
    width: fit-content;
    min-width: auto;
    max-width: none;
}

/* Mensajes medianos: ancho moderado con límite razonable */
.mensaje-cliente.mensaje-medio {
    width: fit-content;
    min-width: auto;
    max-width: min(75%, 500px);
}

/* Mensajes largos: ancho limitado para evitar que ocupen todo el espacio */
.mensaje-cliente.mensaje-largo {
    width: 100%;
    min-width: auto;
    max-width: min(90%, 600px);
}

.mensaje-cliente::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-left-color: var(--color-primary);
    border-bottom: none;
    border-right: none;
}

.mensaje-bot {
    background-color: var(--color-secondary-light);
    color: var(--color-text) !important;
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    word-wrap: break-word;
    position: relative;
    border: 1px solid var(--color-border);
    width: fit-content;
    min-width: fit-content;
    max-width: 100%;
}

.mensaje-bot::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 0;
    height: 0;
    border: 8px solid transparent;
    border-right-color: var(--color-secondary-light);
    border-bottom: none;
    border-left: none;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: normal;
    white-space: normal;
    display: block;
    width: auto;
    max-width: 100%;
}

/* Texto de mensajes del cliente alineado a la izquierda dentro de la burbuja */
.mensaje-cliente .message-text {
    text-align: left;
    padding: 0;
    margin: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: normal;
    white-space: normal;
    hyphens: auto;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: visible;
}

/* Ajustes específicos de texto según tipo de mensaje */
.mensaje-cliente.mensaje-corto .message-text {
    white-space: normal;
    word-break: normal;
    overflow-wrap: normal;
}

.mensaje-cliente.mensaje-medio .message-text {
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
}

.mensaje-cliente.mensaje-largo .message-text {
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
}

/* Texto de mensajes del bot alineado a la izquierda */
.mensaje-bot .message-text {
    text-align: left;
    color: var(--color-text) !important;
}

/* Estilos para enlaces en mensajes del agente */
.mensaje-bot .message-text a {
    color: #2196F3 !important;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.mensaje-bot .message-text a:hover {
    color: #1976D2 !important;
    text-decoration: underline;
}

.mensaje-bot .message-text a:visited {
    color: #7B1FA2 !important;
}

.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.7;
    gap: 8px;
}

/* Meta del cliente alineado a la izquierda dentro de la burbuja */
.mensaje-cliente .message-meta {
    justify-content: flex-start;
    flex-direction: row;
    width: 100%;
}

.message-time {
    font-size: 11px;
    margin-top: 4px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-right: 8px;
}

.message-type {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: 4px;
}

.message-type.cotizacion {
    background-color: rgba(76, 175, 80, 0.2);
    color: var(--color-success);
}

.message-type.transferencia {
    background-color: rgba(255, 152, 0, 0.2);
    color: var(--color-warning);
}

.message-type.generico {
    background-color: rgba(33, 150, 243, 0.2);
    color: var(--color-info);
}

/* Resaltado de palabras clave en el badge tipo_mensaje_bot */
.message-type-highlight {
    font-weight: 700 !important;
    text-shadow: 0 0 8px currentColor;
    border: 1px solid currentColor !important;
}

.message-type-highlight.message-type-transferencia {
    color: #FF6B35 !important;
    background-color: rgba(255, 107, 53, 0.2) !important;
    border-color: #FF6B35 !important;
}

.message-type-highlight.message-type-cotizacion {
    color: #FFD600 !important;
    background-color: rgba(255, 214, 0, 0.2) !important;
    border-color: #FFD600 !important;
}

.message-type-highlight.message-type-saludo {
    color: #2196F3 !important;
    background-color: rgba(33, 150, 243, 0.2) !important;
    border-color: #2196F3 !important;
}

.message-type-highlight.message-type-busqueda {
    color: #9C27B0 !important;
    background-color: rgba(156, 39, 176, 0.2) !important;
    border-color: #9C27B0 !important;
}

.message-type-highlight.message-type-registro {
    color: #18dcf6 !important;
    background-color: rgba(24, 220, 246, 0.2) !important;
    border-color: #18dcf6 !important;
}

.message-type-highlight.message-type-despedida {
    color: #E91E63 !important;
    background-color: rgba(233, 30, 99, 0.2) !important;
    border-color: #E91E63 !important;
}

.message-type-highlight.message-type-respuesta {
    color: #00E676 !important;
    background-color: rgba(0, 230, 118, 0.2) !important;
    border-color: #00E676 !important;
}

.message-type-highlight.message-type-fuera_contexto {
    color: #607D8B !important;
    background-color: rgba(96, 125, 139, 0.2) !important;
    border-color: #607D8B !important;
}

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    color: var(--color-text-secondary);
    text-align: center;
    padding: 40px;
    margin: auto;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.chat-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty-text {
    font-size: 18px;
    margin-bottom: 8px;
}

.chat-empty-subtext {
    font-size: 14px;
}

/* Responsive Chat */
@media (max-width: 1024px) {
    .chat-container {
        flex-direction: column;
        height: auto;
    }
    
    .chat-list {
        width: 100%;
        max-height: 300px;
    }
    
    .chat-viewer {
        min-height: 500px;
    }
}

@media (max-width: 768px) {
    .chat-message {
        max-width: 85%;
        width: fit-content;
    }
    
    .mensaje-cliente,
    .mensaje-bot {
        padding: 10px 14px;
        font-size: 13px;
    }
}

