/**
 * 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: #1a1410;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 16px 16px 0 0 !important;
    border-bottom: 2px solid #c62828;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    background: #c62828;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #FFFFFF;
    flex-shrink: 0;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.05rem;
    color: #ffffff;
    font-weight: 600;
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

.chat-status {
    margin: 0;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
}

.chat-header .close-btn {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255,255,255,0.6);
    border: none;
    font-size: 22px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.chat-header .close-btn:hover {
    background: rgba(198, 40, 40, 0.3);
    color: #ffffff;
}

/* ========================================
   CUERPO DEL CHAT
   ======================================== */

.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #faf7f2;
    overflow: hidden;
    min-height: 0;
}

.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: #c62828;
    color: #ffffff;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.chat-message-bot .message-content {
    background-color: #ffffff;
    color: #2c2820;
    border-bottom-left-radius: 4px;
    border: 1px solid #e4ddd3;
}

.message-time {
    font-size: 0.75rem;
    color: #9b9188;
    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: #c62828;
    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: 12px 16px;
    background-color: #ffffff;
    border-top: 1px solid #e4ddd3;
    flex-shrink: 0;
    min-height: 60px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e4ddd3;
    border-radius: 8px;
    background-color: #faf7f2;
    color: #2c2820;
    font-size: 0.93rem;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    max-height: 120px;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: #c62828;
    background-color: #ffffff;
}

.chat-input::placeholder {
    color: #9b9188;
}

.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;
}

/* ========================================
   BOTÓN FLOTANTE DE CHAT — EmilIA
   ======================================== */

#chat-bot-link {
    position: fixed !important;
    bottom: 32px !important;
    right: 32px !important;
    z-index: 9999 !important;
    width: 80px !important;
    height: 80px !important;
    border-radius: 50% !important;
    background: #c62828 !important;
    border: 3px solid #faf7f2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    text-decoration: none !important;
    color: #ffffff !important;
    transition: transform 0.3s ease, box-shadow 0.3s ease !important;
    box-shadow: 0 6px 24px rgba(198, 40, 40, 0.6) !important;
    animation: chatPulse 2.4s ease-in-out infinite !important;
}

#chat-bot-link i {
    font-size: 2.2rem !important;
    color: #ffffff !important;
    line-height: 1 !important;
    display: block !important;
}

#chat-bot-link:hover {
    transform: scale(1.12) !important;
    animation-play-state: paused !important;
    box-shadow: 0 8px 36px rgba(198, 40, 40, 0.85) !important;
    background: #e53935 !important;
}

#chat-bot-link:visited,
#chat-bot-link:focus {
    color: #ffffff !important;
}

@keyframes chatPulse {
    0%   { box-shadow: 0 6px 24px rgba(198,40,40,0.60), 0 0 0 0   rgba(198,40,40,0.35); }
    50%  { box-shadow: 0 6px 32px rgba(198,40,40,0.80), 0 0 0 16px rgba(198,40,40,0.00); }
    100% { box-shadow: 0 6px 24px rgba(198,40,40,0.60), 0 0 0 0   rgba(198,40,40,0.35); }
}

/* Tooltip */
#chat-bot-link::after {
    content: "Chatear con EmilIA";
    position: absolute !important;
    bottom: calc(100% + 12px);
    right: 0;
    background: #1a1410;
    color: #faf7f2;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid #c62828;
    font-size: 0.82rem;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform: translateY(6px);
}

#chat-bot-link:hover::after {
    opacity: 1;
    transform: translateY(0);
}

.chat-logo { display: none !important; }

/* ========================================
   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-bot-link {
        width: 66px !important;
        height: 66px !important;
        bottom: 20px !important;
        right: 20px !important;
    }

    #chat-bot-link i {
        font-size: 1.8rem !important;
    }
}

@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 */
    }
}
