/**
 * Chat en Vivo - Estilos CSS
 * Diseño tipo WhatsApp para el chat widget
 */

/* Animación de spin */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Panel de Chat */
#widget-panel-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 600px;
}

/* Header del Chat */
#chat-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #ecf0f1;
    padding: 15px 20px;
    display: none;
}

#chat-header strong {
    display: block;
    color: #2c3e50;
    font-size: 14px;
    margin-bottom: 4px;
}

#chat-header small {
    color: #7f8c8d;
    font-size: 12px;
}

/* Estado del Chat */
#chat-status {
    color: #27ae60;
    font-weight: 500;
}

#chat-status.warning {
    color: #e74c3c;
}

/* Timeout Display */
#chat-timeout {
    display: block;
    color: #2c3e50;
    font-size: 16px;
    font-weight: bold;
    text-align: right;
}

/* Estado: Buscando Agente */
#chat-searching {
    padding: 40px 20px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
}

#chat-searching svg {
    animation: spin 2s linear infinite;
    margin-bottom: 15px;
}

#chat-searching p {
    margin: 0;
    color: #2c3e50;
}

#chat-searching p:first-of-type {
    font-weight: 600;
    margin-bottom: 8px;
}

#chat-searching p:last-of-type {
    color: #7f8c8d;
    font-size: 13px;
}

/* Estado: Error */
#chat-error {
    padding: 40px 20px;
    text-align: center;
    flex: 1;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: white;
}

#chat-error svg {
    margin-bottom: 15px;
}

#chat-error p {
    margin: 0;
}

#chat-error-message {
    color: #e74c3c;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

#chat-error + p {
    color: #7f8c8d;
    font-size: 13px;
}

/* Área de Mensajes */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px 20px;
    background: #f8f9fa;
    display: none;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Mensajes Individuales */
.chat-message {
    display: flex;
    animation: fadeIn 0.3s ease-in-out;
    margin-bottom: 5px;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.agent {
    justify-content: flex-start;
}

.chat-message .message-content {
    max-width: 75%;
    padding: 10px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

/* Mensaje del Usuario */
.chat-message.user .message-content {
    background: #3498db;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.user strong {
    display: none;
}

.chat-message.user p {
    margin: 0 0 4px 0;
    font-size: 14px;
}

.chat-message.user small {
    font-size: 11px;
    opacity: 0.8;
    display: block;
}

/* Mensaje del Agente */
.chat-message.agent .message-content {
    background: white;
    color: #2c3e50;
    border: 1px solid #ecf0f1;
    border-bottom-left-radius: 4px;
}

.chat-message.agent strong {
    display: block;
    color: #27ae60;
    font-size: 12px;
    margin-bottom: 4px;
    font-weight: 600;
}

.chat-message.agent p {
    margin: 4px 0;
    font-size: 14px;
}

.chat-message.agent small {
    font-size: 11px;
    color: #95a5a6;
    display: block;
    margin-top: 4px;
}

/* Área de Input */
#chat-input-area {
    padding: 15px 20px;
    border-top: 1px solid #ecf0f1;
    background: white;
    display: none;
}

#chat-input-message {
    width: 100%;
    padding: 10px;
    border: 1px solid #ecf0f1;
    border-radius: 4px;
    min-height: 45px;
    resize: vertical;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

#chat-input-message:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Botones del Chat */
.chat-input-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

#chat-send-message,
#chat-convert-ticket {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
}

#chat-send-message {
    background: #3498db;
    color: white;
}

#chat-send-message:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

#chat-send-message:active {
    transform: translateY(0);
}

#chat-convert-ticket {
    background: #ecf0f1;
    color: #2c3e50;
}

#chat-convert-ticket:hover {
    background: #bdc3c7;
    transform: translateY(-2px);
}

#chat-convert-ticket:active {
    transform: translateY(0);
}

/* Estados deshabilitados */
#chat-send-message:disabled,
#chat-convert-ticket:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Notificación de expiración */
.chat-expired-notification {
    padding: 15px 20px;
    background: #fff3cd;
    border-bottom: 1px solid #ffc107;
    text-align: center;
    animation: slideDown 0.3s ease-in-out;
}

.chat-expired-notification strong {
    color: #856404;
    font-size: 14px;
}

.chat-expired-notification p {
    margin: 5px 0 0 0;
    font-size: 13px;
    color: #856404;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Indicador de escritura (futuro) */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    background: white;
    border: 1px solid #ecf0f1;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #bdc3c7;
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scaleY(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scaleY(1);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .chat-message .message-content {
        max-width: 85%;
        padding: 8px 10px;
        font-size: 13px;
    }

    #chat-input-message {
        min-height: 40px;
        font-size: 16px; /* Previene zoom en iOS */
    }

    #chat-send-message,
    #chat-convert-ticket {
        padding: 8px;
        font-size: 13px;
    }
}

/* Tema oscuro (futuro) */
@media (prefers-color-scheme: dark) {
    #chat-messages {
        background: #1e1e1e;
    }

    .chat-message.agent .message-content {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #3d3d3d;
    }

    #chat-input-area {
        background: #2d2d2d;
        border-color: #3d3d3d;
    }

    #chat-input-message {
        background: #1e1e1e;
        color: #e0e0e0;
        border-color: #3d3d3d;
    }

    #chat-input-message:focus {
        border-color: #3498db;
        box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    }

    #chat-convert-ticket {
        background: #3d3d3d;
        color: #e0e0e0;
    }

    #chat-convert-ticket:hover {
        background: #4d4d4d;
    }
}
