/* Chatnito Frontend Styles */
.chatnito-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: 90vw;
    height: 500px;
    max-height: 70vh;
    background: black;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
}

.chatnito-header {
    background: linear-gradient(135deg, var(--chatnito-primary, #6b46c1), var(--chatnito-secondary, #00b5d8));
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatnito-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatnito-avatar.bot {
    background: var(--chatnito-primary);
}

.chatnito-avatar.user {
    background: var(--chatnito-secondary);
}

.chatnito-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: none;
}

.chatnito-avatar-fallback {
    color: white;
    font-weight: bold;
    font-size: 16px;
    text-transform: uppercase;
}

/* Header Avatar específico */
.chatnito-header .chatnito-avatar {
    width: 45px;
    height: 45px;
}

.chatnito-header .chatnito-avatar-fallback {
    font-size: 18px;
}

/* Message Avatars */
.chatnito-message .chatnito-avatar {
    width: 35px;
    height: 35px;
}

.chatnito-message .chatnito-avatar-fallback {
    font-size: 14px;
}

/* Asegurar que las imágenes se muestren cuando están cargadas */
.chatnito-avatar-img:not([style*="display: none"]) {
    display: block !important;
}

.chatnito-avatar-fallback:not([style*="display: none"]) {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.chatnito-avatar.has-image .chatnito-avatar-img {
    display: block;
}

.chatnito-avatar.has-image .chatnito-avatar-fallback {
    display: none;
}

.chatnito-header-info {
    flex: 1;
}

.chatnito-header-info strong {
    display: block;
    font-size: 16px;
}

.chatnito-status {
    font-size: 12px;
    opacity: 0.8;
}

.chatnito-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.3s;
    padding: 0;
}

.chatnito-close-btn:hover {
    opacity: 1;
}

.chatnito-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--chatnito-dark, #1a202c);
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* Forzar scrollbar siempre visible */
    overflow-y: scroll;
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--chatnito-primary, #6b46c1) #f1f1f1;
}

.chatnito-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
}

.chatnito-message.bot {
    align-self: flex-start;
}

.chatnito-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chatnito-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.4;
}

.chatnito-message.bot .chatnito-message-content {
    background: var(--chatnito-botbt, #000000);
    border: 1px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    color: var(--chatnito-bott, #ffffff);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chatnito-message.user .chatnito-message-content {
    background: var(--chatnito-primary, #6b46c1);
    color: var(--chatnito-usert, #ffffff);
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 4px rgba(107, 70, 193, 0.3);
}

.chatnito-typing {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #718096;
    font-style: italic;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: none;
    flex-shrink: 0;
}

.chatnito-typing-indicator {
    display: flex;
    gap: 4px;
}

.chatnito-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatnito-primary, #6b46c1);
    animation: chatnito-typing 1.4s ease-in-out infinite both;
}

.chatnito-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.chatnito-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chatnito-typing {
    0%, 80%, 100% { 
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% { 
        transform: scale(1);
        opacity: 1;
    }
}

.chatnito-input-area {
    padding: 15px 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--chatnito-darker, #0f1419);
    flex-shrink: 0;
}

.chatnito-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    background: var(--chatnito-darker, #0f1419);
    color: var(--chatnito-usert, #ffffff);
    transition: border-color 0.3s;
}

.chatnito-input:focus {
    border-color: var(--chatnito-primary, #6b46c1);
}

.chatnito-input::placeholder {
    color: #a0aec0;
}

.chatnito-send-btn {
    background: var(--chatnito-primary, #6b46c1);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.chatnito-send-btn:hover {
    background: var(--chatnito-secondary, #00b5d8);
    transform: scale(1.05);
}

.chatnito-send-btn:active {
    transform: scale(0.95);
}

/* Toggle Button - Base Styles */
.chatnito-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, var(--chatnito-primary, #6b46c1), var(--chatnito-secondary, #00b5d8));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(107, 70, 193, 0.4);
    font-weight: 600;
    transition: all 0.3s;
    z-index: 10000;
    padding: 15px 20px;
    border-radius: 25px;
}

.chatnito-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(107, 70, 193, 0.6);
}

.chatnito-toggle-btn:active {
    transform: translateY(0);
}

.chatnito-toggle-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatnito-toggle-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.chatnito-toggle-text {
    font-size: 14px;
}

.chatnito-custom-bubble-text {
    display: none;
    font-weight: bold;
    font-size: 14px;
    color: white;
}

/* Bubble Button Styles */
.chatnito-toggle-btn.bubble-style {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    padding: 0;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

/* Ajustes para el estilo burbuja */
.chatnito-toggle-btn.bubble-style .chatnito-toggle-icon {
    margin-bottom: 2px;
}

/* Texto más pequeño para el estilo burbuja */
.chatnito-toggle-btn.bubble-style .chatnito-toggle-text {
    font-size: 9px;
    line-height: 1;
    text-align: center;
    margin-top: -2px;
}

/* Bubble Shapes */
.chatnito-toggle-btn.bubble-style[data-shape="circle"] {
    border-radius: 50%;
}

.chatnito-toggle-btn.bubble-style[data-shape="rounded"] {
    border-radius: 12px;
}

.chatnito-toggle-btn.bubble-style[data-shape="square"] {
    border-radius: 4px;
}

/* Bubble Sizes */
.chatnito-toggle-btn.bubble-style[data-size="small"] {
    width: 50px;
    height: 50px;
}

.chatnito-toggle-btn.bubble-style[data-size="medium"] {
    width: 60px;
    height: 60px;
}

.chatnito-toggle-btn.bubble-style[data-size="large"] {
    width: 70px;
    height: 70px;
}

.chatnito-toggle-btn[data-size="small"] svg {
    width: 20px;
    height: 20px;
}

.chatnito-toggle-btn[data-size="large"] svg {
    width: 28px;
    height: 28px;
}

/* Bubble Positions */
.chatnito-toggle-btn[data-position="bottom-right"] {
    bottom: 20px;
    right: 20px;
}

.chatnito-toggle-btn[data-position="bottom-left"] {
    bottom: 20px;
    left: 20px;
}

.chatnito-toggle-btn[data-position="top-right"] {
    top: 20px;
    right: 20px;
}

.chatnito-toggle-btn[data-position="top-left"] {
    top: 20px;
    left: 20px;
}

/* Bubble Icon Styles */
.chatnito-toggle-btn[data-icon="custom"] .chatnito-toggle-icon {
    display: none;
}

.chatnito-toggle-btn[data-icon="custom"] .chatnito-custom-bubble-text {
    display: block;
}

/* Efecto de pulso para el botón burbuja */
@keyframes chatnito-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(107, 70, 193, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(107, 70, 193, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(107, 70, 193, 0);
    }
}

.chatnito-toggle-btn.pulse {
    animation: chatnito-pulse 2s infinite;
}

/* Scrollbar Styling - Mejorado y forzado */
.chatnito-messages::-webkit-scrollbar {
    width: 8px;
    display: block !important;
    -webkit-appearance: none;
}

.chatnito-messages::-webkit-scrollbar:vertical {
    width: 8px;
}

.chatnito-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
    display: block !important;
}

.chatnito-messages::-webkit-scrollbar-thumb {
    background: var(--chatnito-primary, #6b46c1);
    border-radius: 4px;
    display: block !important;
}

.chatnito-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatnito-secondary, #00b5d8);
    display: block !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chatnito-widget {
        width: 95vw;
        height: 70vh;
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .chatnito-toggle-btn {
        bottom: 10px;
        right: 10px;
    }
    
    .chatnito-toggle-btn.bubble-style {
        width: 55px;
        height: 55px;
    }
    
    .chatnito-message-content {
        max-width: 85%;
    }
    
    .chatnito-toggle-btn.bubble-style .chatnito-toggle-text {
        font-size: 8px;
    }
}

/* Dynamic theme variables */
:root {
    --chatnito-primary: #6b46c1;
    --chatnito-secondary: #00b5d8;
    --chatnito-dark: #1a202c;
    --chatnito-darker: #0f1419;
    --chatnito-botbt: #000000;
    --chatnito-bott: #ffffff;
    --chatnito-usert: #ffffff;
}
/* Bubble Button with Text */
.chatnito-toggle-btn:not(.bubble-style) {
    padding: 12px 20px;
    border-radius: 25px;
    background: var(--chatnito-primary);
    color: white;
    gap: 8px;
}

.chatnito-toggle-btn:not(.bubble-style) .chatnito-toggle-text {
    display: block;
    font-weight: 600;
    font-size: 14px;
}

/* Bubble Style without Text */
.chatnito-toggle-btn.bubble-style {
    padding: 0;
}

.chatnito-toggle-btn.bubble-style .chatnito-toggle-text {
    display: none;
}

/* Cuando el texto está oculto en modo no-bubble (por si acaso) */
.chatnito-toggle-btn:not(.bubble-style)[data-show-text="false"] {
    padding: 12px;
}

.chatnito-toggle-btn:not(.bubble-style)[data-show-text="false"] .chatnito-toggle-text {
    display: none;
}

/* Asegurar que el custom text se centre cuando no hay texto */
.chatnito-toggle-btn[data-show-text="false"] .chatnito-custom-bubble-text {
    display: block;
    text-align: center;
    width: 100%;
}
