/* Icono flotante Sofia - Posicionamiento robusto */
#sofia-chatbot-container {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 9999 !important;
    width: 80px;
    height: 80px;
}

#sofia-chat-icon {
    width: 100px;
    height: 100px;
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 0;
    border: none;
    background: none;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sofia-chat-icon:hover {
    transform: scale(1.1);
}

#sofia-chat-icon:hover img {
    box-shadow: 0 0 15px 5px rgba(0, 123, 255, 0.5);
}

#sofia-chat-icon.hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

#sofia-chat-icon img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    transition: box-shadow 0.2s ease;
}

/* Chat Window */
#sofia-chatbot-window {
    position: fixed !important;
    bottom: 90px !important;
    right: 20px !important;
    width: 350px;
    max-width: 90vw;
    height: 70vh;
    max-height: 500px;
    background-color: #fff;
    border: 1px solid #fff;
    /*border-radius: 15px;*/
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform-origin: bottom right;
    z-index: 9998 !important;
}

#sofia-chatbot-window.hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

/* Header */
.sofia-chatbot-header {
    padding: 15px;
    background-color: #2e18ff;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sofia-chatbot-header h2 {
    margin: 0;
    font-size: 1.2em;
}

.sofia-chatbot-header-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

#sofia-chatbot-close-btn,
#sofia-chatbot-minimize-btn,
#sofia-chatbot-reset-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 30px;
}

#sofia-chatbot-close-btn:hover,
#sofia-chatbot-minimize-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

#sofia-chatbot-reset-btn {
    font-size: 16px;
}

#sofia-chatbot-reset-btn {
    position: relative; 
}

#sofia-chatbot-reset-btn svg {
    transition: all 0.2s ease; 
}

#sofia-chatbot-reset-btn:hover {
    background-color: transparent;
}

#sofia-chatbot-reset-btn:hover svg {
    transform: scale(1.1) rotate(180deg); 
}

#sofia-chatbot-reset-btn:active svg {
    transform: scale(0.95) rotate(180deg);
}


#sofia-chatbot-reset-btn::before {
    content: attr(title);
    position: absolute;
    top: -25px; /* Ajustado de -35px a -20px para que esté 15px más abajo */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 99999; 
}

#sofia-chatbot-reset-btn:hover::before {
    opacity: 1;
}

/* Messages Area */
.sofia-chatbot-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sofia-chatbot-message {
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 0.95em;
}

.sofia-chatbot-message.user {
    background-color: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.sofia-chatbot-message.bot {
    background-color: #f1f1f1;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

/* Input Area */
.sofia-chatbot-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
}

#sofia-chatbot-form {
    display: flex;
    gap: 10px;
}

#sofia-chatbot-input {
    flex-grow: 1;
    width: calc(100% - 90px); 
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 0.95em;
    resize: none;
    min-height: 45px;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
    overflow-y: auto;
    transition: height 0.2s ease;
}

#sofia-chatbot-input:focus {
    outline: none;
    border-color: #007bff;
}

#sofia-chatbot-form button {
    background-color: #2E18F7; 
    border: none;
    border-radius: 8px; 
    width: 80px; 
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: white;
    font-weight: 500;
    font-size: 0.95em;
}

#sofia-chatbot-form button:hover {
    background-color: #2512c7; 
}

#sofia-typing-indicator {
    font-style: italic;
    color: #888;
    font-size: 0.9em;
    margin-bottom: 5px;
    padding-left: 10px;
}

/* Context Toggle Styles */
.sofia-context-toggle-container {
    margin-bottom: 10px;
    padding: 0 5px;
}

.sofia-context-checkbox {
    display: none;
}

.sofia-context-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.85em;
    color: #666;
    user-select: none;
    transition: color 0.2s ease;
}

.sofia-context-label:hover {
    color: #007bff;
}

.sofia-context-label::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-radius: 3px;
    margin-right: 8px;
    display: inline-block;
    position: relative;
    transition: all 0.2s ease;
    background-color: #fff;
    flex-shrink: 0;
}

.sofia-context-checkbox:checked + .sofia-context-label::before {
    background-color: #007bff;
    border-color: #007bff;
}

.sofia-context-checkbox:checked + .sofia-context-label::after {
    content: '✓';
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
}

.sofia-context-checkbox:checked + .sofia-context-label {
    color: #007bff;
}

.sofia-context-label:hover::before {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.sofia-context-text {
    font-weight: 500;
}

/* Anti-interference rules - Override any potential conflicts */
body #sofia-chatbot-container,
html #sofia-chatbot-container {
    font-family: inherit !important;
    line-height: normal !important;
    text-align: left !important;
    direction: ltr !important;
    unicode-bidi: normal !important;
}

/* Ensure no other elements can interfere */
#sofia-chatbot-container * {
    box-sizing: border-box !important;
}

/* Responsive */
@media (max-width: 480px) {
    #sofia-chatbot-window {
        width: 100vw;
        height: 100vh;
        max-height: 100%;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0;
    }

    body #sofia-chatbot-container,
    html body #sofia-chatbot-container,
    #sofia-chatbot-container {
        bottom: 20px !important;
        right: 20px !important;
        position: fixed !important;
        z-index: 999999999 !important;
    }

    /* Header controls responsive adjustments */
    .sofia-chatbot-header-controls {
        gap: 3px;
    }

    #sofia-chatbot-close-btn,
    #sofia-chatbot-minimize-btn,
    #sofia-chatbot-reset-btn {
        font-size: 18px;
        min-width: 28px;
        min-height: 28px;
        padding: 3px;
    }

    #sofia-chatbot-reset-btn {
        font-size: 14px;
    }

    /* Hide tooltip on mobile to avoid layout issues */
    #sofia-chatbot-reset-btn::after {
        display: none;
    }

    /* Toggle responsive adjustments */
    .sofia-context-toggle-container {
        margin-bottom: 8px;
        padding: 0 3px;
    }

    .sofia-context-label {
        font-size: 0.8em;
    }

    .sofia-context-label::before {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    .sofia-context-checkbox:checked + .sofia-context-label::after {
        font-size: 10px;
        left: 2px;
    }
}


@media (max-height: 600px) {
    #sofia-chatbot-window {
        height: calc(100vh - 120px) !important;
        max-height: calc(100vh - 120px) !important;
    }
}


@media (max-width: 400px) {
    #sofia-chatbot-window {
        right: 10px !important;
        width: calc(100vw - 20px) !important;
    }
    
    #sofia-chatbot-container {
        right: 10px !important;
    }
}
