/* 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%;
    max-width: 80px;
    max-height: 80px;
    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: 20px !important;
    color: #FFF !important;
    font-weight: 700 !important;
}

.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;
}

/* Wrapper para recortar el scrollbar dentro de los bordes redondeados */
.sofia-textarea-wrapper {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid #ccc;
    border-radius: 20px;
    overflow: hidden;              /* recorta el contenido (incluido el scrollbar) */
    background: #fff;
}

/* Realzar el wrapper cuando el textarea tiene foco */
.sofia-textarea-wrapper:focus-within {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

#sofia-chatbot-input {
    width: 100%;
    border: 0;                     /* el borde lo gestiona el wrapper */
    border-radius: 0;              /* redondeado en el wrapper */
    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;
    background: transparent;       /* usar el fondo del wrapper */

    /* Scrollbar settings */
    scrollbar-width: thin;                     /* Firefox */
    scrollbar-color: rgba(0,0,0,0.35) transparent; /* Firefox */
    scrollbar-gutter: stable both-edges;       /* Reservar espacio para scrollbar */
    -webkit-overflow-scrolling: touch;         /* Suavidad en iOS */
}

/* WebKit/Blink custom scrollbar to keep it within rounded border */
#sofia-chatbot-input::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
#sofia-chatbot-input::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 20px;
}
#sofia-chatbot-input::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.35);
    border-radius: 10px;
    border: 2px solid transparent;       /* inner padding so it doesn’t touch the border edge */
    background-clip: padding-box;
}
#sofia-chatbot-input::-webkit-scrollbar-corner {
    background: transparent;
}

#sofia-chatbot-input:focus {
    outline: none; /* border highlight is applied to wrapper via :focus-within */
}

#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;
}

/* Send button (paper plane) */
#sofia-chatbot-form .sofia-send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    padding: 0;
    background-color: #2e18ff; /* same as header */
    position: relative; /* for tooltip positioning */
}

#sofia-chatbot-form .sofia-send-btn svg {
    stroke: #fff;
    transform: translateX(-1px); /* optical centering: move plane slightly left */
}



/* Typing indicator animated dots */
#sofia-typing-indicator .typing-dots {
    display: inline-block;
    margin-left: 6px;
}

#sofia-typing-indicator .typing-dots span {
    display: inline-block;
    width: 4px;
    height: 4px;
    margin: 0 2px;
    background: currentColor;
    border-radius: 50%;
    opacity: 0.25;
    animation: sofia-typing-dots 1s infinite ease-in-out;
    box-shadow: none !important;
    text-shadow: none !important;
    filter: none !important;
}

#sofia-typing-indicator .typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}
#sofia-typing-indicator .typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes sofia-typing-dots {
    0%, 60%, 100% {
        opacity: 0.25;
    }
    30% {
        opacity: 1;
    }
}
#sofia-chatbot-form .sofia-send-btn:hover {
    background-color: #2411d8;
    transform: scale(1.05);
}

#sofia-chatbot-form button:not(.sofia-send-btn):hover {
    background-color: #2512c7;
}

#sofia-typing-indicator {
    display: none;
    font-style: italic;
    color: #888;
    font-size: 0.9em;
    margin-bottom: 5px;
    padding-left: 10px;
    text-shadow: none !important; /* ensure no shadow on text */
}

/* 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;
    }
}

/* Utility classes to replace inline styles applied by JS */
.sofia-fixed-position {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 9999 !important;
}

.sofia-offset-40 {
    bottom: 40px !important;
    right: 40px !important;
}

.sofia-z-top {
    z-index: 2147483647 !important; /* bring to very top if conflicts detected */
}
