/* Futuristic Chatbot Styles - Codexy */
:root {
    --chat-primary-color: #6a5af9; /* Vibrant purple */
    --chat-secondary-color: #4f46e5; /* Deeper purple/blue */
    --chat-accent-color: #818cf8; /* Lighter purple/blue for accents */
    --chat-bg-dark: #1f2937; /* Dark grey for main background */
    --chat-bg-medium: #374151; /* Medium grey for elements */
    --chat-bg-light: #4b5563; /* Light grey for hover or less prominent elements */
    --chat-text-light: #e5e7eb; /* Light grey for text on dark backgrounds */
    --chat-text-dark: #111827; /* Dark grey for text on light backgrounds */
    --chat-border-radius: 12px;
    --chat-font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --chat-z-index-toggle: 999990;
    --chat-z-index-chatbox: 999999;
}

#codexy-chatbot-container * {
    box-sizing: border-box;
    font-family: var(--chat-font-family);
}

.contact-button {
    display: inline-block;
    background: linear-gradient(135deg, var(--chat-primary-color), var(--chat-secondary-color));
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    margin: 8px 0;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 2px 8px rgba(106, 90, 249, 0.2);
}

.contact-button:hover {
    background: linear-gradient(135deg, var(--chat-secondary-color), var(--chat-primary-color));
    text-decoration: none;
    color: white;
    box-shadow: 0 4px 12px rgba(106, 90, 249, 0.3);
    transform: translateY(-1px);
}

.message.bot span {
    display: inline-block;
    margin: 4px 0;
}

/* Toggle Button */
.chat-toggle-button {
    position: fixed;
    bottom: 20px; /* Ajustado */
    right: 20px; /* Ajustado */
    width: 54px; /* Reducido */
    height: 54px; /* Reducido */
    background: linear-gradient(145deg, var(--chat-primary-color), var(--chat-secondary-color));
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(var(--chat-primary-color), 0.35);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: var(--chat-z-index-toggle);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.chat-toggle-button svg {
    width: 24px; /* Reducido */
    height: 24px; /* Reducido */
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.chat-toggle-button .chat-icon-close {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
    position: absolute;
}

.chat-toggle-button.active .chat-icon-open {
    transform: scale(0) rotate(45deg);
    opacity: 0;
}

.chat-toggle-button.active .chat-icon-close {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

.chat-toggle-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(var(--chat-primary-color), 0.5);
}

/* Chatbox */
.chatbox {
    position: fixed;
    bottom: 100px; /* Above toggle button */
    right: 25px;
    width: 380px;
    height: clamp(400px, 70vh, 650px); /* Responsive height */
    background-color: var(--chat-bg-dark);
    border-radius: var(--chat-border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255,255,255,0.05) inset;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--chat-z-index-chatbox);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.35s;
}

.chatbox.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* Chatbox Header */
.chatbox-header {
    padding: 15px 20px;
    background-color: var(--chat-bg-medium);
    /* background: linear-gradient(145deg, var(--chat-secondary-color), var(--chat-primary-color)); */
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--chat-text-light);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.chatbox-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.chatbox-close-button {
    background: none;
    border: none;
    color: var(--chat-text-light);
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.chatbox-close-button svg {
    width: 20px;
    height: 20px;
    display: block;
}

.chatbox-close-button:hover {
    background-color: var(--chat-bg-light);
}

/* Messages Area */
.chatbox-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Flexbox scroll fix */
    scrollbar-width: thin;
    scrollbar-color: var(--chat-accent-color) transparent;
}

.chatbox-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbox-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbox-messages::-webkit-scrollbar-thumb {
    background-color: var(--chat-accent-color);
    border-radius: 3px;
}

/* Individual Messages */
.message {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: var(--chat-border-radius);
    line-height: 1.5;
    font-size: 0.95rem;
    word-wrap: break-word;
    opacity: 0;
    transform: translateY(10px);
    animation: messageAppear 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

.message.user {
    background: linear-gradient(135deg, var(--chat-primary-color), var(--chat-secondary-color));
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px; /* Bubble tail */
}

.message.bot {
    background-color: var(--chat-bg-medium);
    color: var(--chat-text-light);
    align-self: flex-start;
    border-bottom-left-radius: 4px; /* Bubble tail */
}

@keyframes messageAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Input Area */
.chatbox-input-area {
    display: flex;
    align-items: flex-end; /* Align items to bottom for textarea */
    padding: 12px 15px;
    background-color: var(--chat-bg-medium);
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.chatbox-input {
    flex-grow: 1;
    border: 1px solid var(--chat-bg-light);
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background-color: var(--chat-bg-dark);
    color: var(--chat-text-light);
    resize: none; /* Prevent manual resize */
    min-height: 42px; /* Min height for single line */
    max-height: 100px; /* Max height before scroll */
    overflow-y: auto; /* Scroll for long input */
    line-height: 1.4;
}

.chatbox-input:focus {
    border-color: var(--chat-primary-color);
    box-shadow: 0 0 0 3px rgba(var(--chat-primary-color), 0.3);
}

.chatbox-send-button {
    background: var(--chat-primary-color);
    border: none;
    border-radius: 50%;
    color: white;
    width: 42px;
    height: 42px;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.chatbox-send-button svg {
    width: 20px;
    height: 20px;
}

.chatbox-send-button:hover {
    background-color: var(--chat-secondary-color);
}

/* Typing Indicator */
.typing-indicator {
    display: none; /* Hidden by default, shown by JS */
    align-items: center;
    padding: 0px 15px 8px 15px; /* Positioned above input area */
    position: absolute; /* Position relative to chatbox-input-area's parent if needed */
    bottom: 65px; /* Adjust based on input area height */
    left: 15px;
}

.typing-indicator.active {
    display: flex;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background-color: var(--chat-accent-color);
    border-radius: 50%;
    margin: 0 2px;
    animation: typingAnimation 1.2s infinite ease-in-out;
}

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

@keyframes typingAnimation {
    0%, 60%, 100% { transform: scale(0.8); opacity: 0.5; }
    30% { transform: scale(1.2); opacity: 1; }
}

/* Chat Notification */
#codexy-chat-notification {
    position: fixed;
    bottom: 26px; /* Ajustado para alinearse con el nuevo botón */
    right: 88px;  /* Ajustado para estar cerca del nuevo botón (20px del botón + 54px ancho botón + 14px espacio) */
    background-color: var(--chat-bg-medium);
    color: var(--chat-text-light);
    padding: 8px 14px; /* Reducido */
    border-radius: 10px; /* Ligeramente más pequeño */
    box-shadow: 0 3px 12px rgba(0,0,0,0.18);
    cursor: pointer;
    z-index: calc(var(--chat-z-index-toggle) - 1);
    font-size: 0.78rem; /* Reducido */
    font-weight: 500;
    display: flex;
    align-items: center;
    opacity: 0;
    transform: translateX(15px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

#codexy-chat-notification.hidden {
    opacity: 0 !important;
    transform: translateX(15px) scale(0.95) !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

#codexy-chat-notification:not(.hidden) {
    opacity: 1;
    transform: translateX(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

#codexy-chat-notification span {
    font-weight: 700;
    color: var(--chat-accent-color);
    margin-right: 5px; /* Ligeramente reducido */
}

/* Flecha para la notificación */
#codexy-chat-notification::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%; 
    margin-top: -6px; /* Reducido */
    border-width: 6px; /* Reducido */
    border-style: solid;
    border-color: transparent transparent transparent var(--chat-bg-medium);
    transition: border-color 0.3s ease;
}

#codexy-chat-notification:hover {
    background-color: var(--chat-bg-light);
}

#codexy-chat-notification:hover::after {
    border-color: transparent transparent transparent var(--chat-bg-light);
}

@media (min-width: 375px) and (max-width: 425px){
  .chatbox {
    position: fixed;
    bottom: 100px;
    right: 6px;
    width: 362px;
    height: clamp(400px, 70vh, 650px);
    background-color: var(--chat-bg-dark);
    border-radius: var(--chat-border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--chat-z-index-chatbox);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.35s;
}
}