/**
 * Schaller & Ponce - Chatbot Widget Styles
 * Diseño coherente con la paleta de colores del sitio
 */

/* ========================================
   MODAL DE CHAT
   ======================================== */

.chat-modal .modal-content {
    max-width: 450px;
    height: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    margin: 2% auto;
    border-radius: 12px;
    overflow: hidden;
}

.chat-modal-content {
    padding: 0 !important;
}

/* ========================================
   HEADER DEL CHAT
   ======================================== */

.chat-header {
    background: linear-gradient(135deg, #C62828 0%, #8B1F1F 100%);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0 !important;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 45px;
    height: 45px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #FFFFFF;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: #FFFFFF;
    font-weight: 600;
}

.chat-status {
    margin: 0;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}

.chat-header .close-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #FFFFFF;
    border: none;
    font-size: 28px;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.chat-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   CUERPO DEL CHAT
   ======================================== */

.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #2D3D4F;
    overflow: hidden;
    min-height: 0; /* Importante para flex overflow */
}

.chat-messages {
    flex: 1;
    min-height: 0; /* Permite que flex funcione correctamente con scroll */
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scrollbar personalizada para chat */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(198, 40, 40, 0.6);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(198, 40, 40, 0.8);
}

/* ========================================
   MENSAJES
   ======================================== */

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeInMessage 0.3s ease;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message-user {
    align-self: flex-end;
}

.chat-message-bot {
    align-self: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message-user .message-content {
    background: linear-gradient(135deg, #64B5F6 0%, #90CAF9 100%);
    color: #1E2D3C;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.chat-message-bot .message-content {
    background-color: #3A4F63;
    color: #F0F0F0;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.75rem;
    color: #999999;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message-user .message-time {
    text-align: right;
}

.chat-message-bot .message-time {
    text-align: left;
}

/* ========================================
   INDICADOR DE ESCRITURA
   ======================================== */

.typing-indicator .message-content {
    padding: 16px;
}

.typing-dots {
    display: flex;
    gap: 6px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: #64B5F6;
    border-radius: 50%;
    animation: typingDots 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDots {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========================================
   BOTÓN DE CAL.COM
   ======================================== */

.cal-com-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #C62828 0%, #8B1F1F 100%);
    color: #FFFFFF;
    padding: 12px 24px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(198, 40, 40, 0.3);
    margin-top: 8px;
}

.cal-com-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(198, 40, 40, 0.4);
    background: linear-gradient(135deg, #D32F2F 0%, #9C2424 100%);
}

.cal-com-button i {
    font-size: 1.1rem;
}

/* Enlaces normales en mensajes */
.chat-link {
    color: #90CAF9;
    text-decoration: underline;
    transition: color 0.3s ease;
}

.chat-link:hover {
    color: #64B5F6;
}

/* ========================================
   FORMULARIO DE CHAT
   ======================================== */

.chat-form {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    background-color: #32465A;
    border-top: 1px solid rgba(100, 181, 246, 0.2);
    flex-shrink: 0; /* Nunca permitir que el formulario se encoja */
    min-height: 60px; /* Altura mínima garantizada */
}

.chat-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid rgba(100, 181, 246, 0.3);
    border-radius: 8px;
    background-color: #2D3D4F;
    color: #F0F0F0;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.3s ease, background-color 0.3s ease;
    max-height: 120px;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: #64B5F6;
    background-color: #3A4F63;
}

.chat-input::placeholder {
    color: #999999;
}

.chat-send-btn {
    background: linear-gradient(135deg, #C62828 0%, #8B1F1F 100%);
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    padding: 12px 18px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.chat-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #D32F2F 0%, #9C2424 100%);
    transform: translateY(-1px);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
   LOGO DE CHAT FLOTANTE
   ======================================== */

.chat-logo {
    position: fixed;
    bottom: 180px;
    right: 40px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(198, 40, 40, 0.5);
    transition: all 0.3s ease;
    z-index: 999;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 6px 20px rgba(198, 40, 40, 0.5), 0 0 0 0 rgba(198, 40, 40, 0.7);
    }
    50% {
        box-shadow: 0 6px 20px rgba(198, 40, 40, 0.5), 0 0 0 15px rgba(198, 40, 40, 0);
    }
    100% {
        box-shadow: 0 6px 20px rgba(198, 40, 40, 0.5), 0 0 0 0 rgba(198, 40, 40, 0);
    }
}

.chat-logo:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(198, 40, 40, 0.7);
    animation-play-state: paused;
}

#chat-bot-link {
    position: fixed;
    bottom: 180px;
    right: 40px;
    z-index: 999;
}

/* Tooltip para el ícono de chat */
#chat-bot-link::after {
    content: "Click en este ícono para chatear";
    position: absolute;
    bottom: 150px;
    right: 0;
    background-color: #32465A;
    color: #FFFFFF;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#chat-bot-link:hover::after {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .chat-modal .modal-content {
        max-width: 95%;
        height: 90vh;
        max-height: 90vh;
        margin: 5% auto;
        border-radius: 8px;
    }

    .chat-header {
        padding: 15px;
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .chat-header h2 {
        font-size: 1.1rem;
    }

    .chat-messages {
        padding: 15px;
    }

    .chat-message {
        max-width: 85%;
    }

    .message-content {
        font-size: 0.9rem;
        padding: 10px 14px;
    }

    .chat-form {
        padding: 12px 15px;
    }

    .chat-input {
        font-size: 0.9rem;
        padding: 10px 12px;
    }

    .cal-com-button {
        font-size: 0.9rem;
        padding: 10px 20px;
    }

    .chat-logo {
        width: 100px;
        height: 100px;
        bottom: 120px;
        right: 25px;
    }

    #chat-bot-link {
        bottom: 120px;
        right: 25px;
    }

    #chat-bot-link::after {
        font-size: 0.85rem;
        padding: 10px 14px;
        bottom: 110px;
    }
}

@media (max-width: 480px) {
    .chat-modal .modal-content {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .chat-header {
        border-radius: 0 !important;
    }

    .chat-body {
        min-height: 0;
        max-height: 100%;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
        max-height: calc(100vh - 200px); /* Altura máxima: viewport menos header y form */
        overflow-y: auto;
    }

    .chat-form {
        flex-shrink: 0; /* NUNCA permitir que se encoja */
        position: sticky; /* Mantener siempre visible */
        bottom: 0;
        z-index: 10;
    }

    .chat-input {
        max-height: 80px; /* Limitar altura del textarea en móvil */
    }
}
