/* Chat Widget Container */
#automatiza-ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    height: calc(100vh - 90px);
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    opacity: 1;
    transform: translateY(0);
}

#automatiza-ai-chat-widget.closed {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    visibility: hidden;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #06d6a0 0%, #17b7b1 55%, #0ea5e9 100%);
    color: #ffffff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    box-shadow: 0 3px 12px rgba(6,214,160,0.35);
    text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.chat-close-btn {
    color: #ffffff !important;
}

.chat-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message-row.bot {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    align-self: flex-start;
    max-width: 85%;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #fff;
    padding: 4px;
    border: 1px solid #e1e4e8;
    flex-shrink: 0;
}

.message {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap; /* Respect newlines */
}

.message.bot {
    background-color: #e9ecef;
    color: #333;
    border-bottom-left-radius: 2px;
    /* Removed align-self and max-width as they are handled by row now */
}

.message.user {
    background-color: #06d6a0;
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    max-width: 80%;
}

.message.loading {
    background-color: #e9ecef;
    color: #666;
    font-style: italic;
    align-self: flex-start;
}

/* Chat Input Area */
.chat-input-area {
    padding: 10px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    background-color: #fff;
}

#chat-input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

#chat-input:focus {
    border-color: #06d6a0;
}

#chat-send-btn {
    background-color: #06d6a0;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

#chat-send-btn:hover {
    background-color: #04b083;
}

/* Force hide old WhatsApp button */
.whatsapp-float {
    display: none !important;
}

/* Toggle Button Container */
#automatiza-chat-toggle-container {
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Robot — aparece y desaparece sobre el botón */
.chat-robot-peek {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: robotFadeInOut 7s ease-in-out infinite;
}

@keyframes robotFadeInOut {
    0%, 8%   { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.82); }
    20%, 68% { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1);    }
    82%,100% { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.82); }
}

.chat-robot-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-robot-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 12px rgba(6,214,160,0.5));
    animation: heroRobotWave 2.8s cubic-bezier(0.445,0.05,0.55,0.95) infinite;
    transform-origin: bottom center;
}
.chat-robot-avatar svg {
    display: block;
}

.chat-robot-bubble {
    background: linear-gradient(135deg, #ff6b35 0%, #ff9500 100%);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow:
        0 6px 20px rgba(255,107,53,0.55),
        inset 0 1px 0 rgba(255,255,255,0.2);
    position: relative;
    font-size: 13px;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
    animation: heroBubbleFloat 2.4s ease-in-out infinite;
}

.chat-bubble-tail {
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid #ff6b35;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; transform: translateY(5px); }
    20%, 80% { opacity: 1; transform: translateY(0); }
}

@keyframes heroRobotWave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-12deg); }
    75% { transform: rotate(12deg); }
}

@keyframes heroBubbleFloat {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-4px); }
}

/* Chat Form */
.chat-form {
    background: #fff;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0 10px 40px; /* Indent to align with bot messages */
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid #eee;
    width: 85%;
    box-sizing: border-box;
    animation: fadeInSlide 0.3s ease-out;
}

.chat-form h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #333;
    text-align: center;
}

.chat-form input {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.chat-form input:focus {
    border-color: #06d6a0;
    outline: none;
}

.chat-form button {
    width: 100%;
    padding: 10px;
    background: #06d6a0;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: background 0.2s;
}

.chat-form button:hover {
    background: #04b083;
}

.chat-form button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.chat-form .error-msg {
    color: #dc3545;
    font-size: 12px;
    margin-bottom: 8px;
    display: none;
    text-align: center;
}

/* Toggle Button */
#automatiza-ai-chat-toggle {
    width: auto;
    height: auto;
    padding: 14px 28px;
    background: linear-gradient(135deg, #06d6a0 0%, #17b7b1 55%, #0ea5e9 100%);
    color: #ffffff;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    box-shadow:
        0 4px 18px rgba(6,214,160,0.5),
        0 2px 8px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    position: relative;
    font-family: inherit;
}

.toggle-text {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
}

#automatiza-ai-chat-toggle::after {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border-radius: 50px;
    border: 2px solid rgba(6,214,160,0.6);
    animation: pulseRing 2s ease-out infinite;
    z-index: -1;
}

@keyframes pulseRing {
    0%   { transform: scale(0.95); opacity: 1; }
    100% { transform: scale(1.15); opacity: 0; }
}

#automatiza-ai-chat-toggle:hover {
    transform: scale(1.06) translateY(-1px);
    box-shadow:
        0 8px 28px rgba(6,214,160,0.65),
        0 3px 10px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.3);
    background: linear-gradient(135deg, #10e6ac 0%, #1dd6cc 50%, #38bdf8 100%);
}

/* Demo Modal Styles */
.demo-modal {
    display: none; 
    position: fixed; 
    z-index: 10000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.5); 
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s;
}

.demo-modal-content {
    background-color: #fefefe;
    margin: 5% auto; 
    padding: 0;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    position: relative;
    animation: slideDown 0.3s;
}

.close-demo-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 20px;
    top: 10px;
    cursor: pointer;
    z-index: 1;
}

.close-demo-modal:hover,
.close-demo-modal:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.demo-modal-header {
    padding: 20px 25px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    border-radius: 12px 12px 0 0;
}

.demo-modal-header h3 {
    margin: 0;
    color: #333;
    font-size: 20px;
}

.demo-modal-header p {
    margin: 5px 0 0;
    color: #666;
    font-size: 14px;
}

.demo-modal-body {
    padding: 25px;
}

.demo-modal-body .form-group {
    margin-bottom: 15px;
}

.demo-modal-body input,
.demo-modal-body select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.demo-modal-body input:focus,
.demo-modal-body select:focus {
    border-color: #06d6a0;
    outline: none;
}

.demo-modal-body label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
    color: #555;
}

.submit-demo-modal-btn {
    background-color: #06d6a0;
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    width: 100%;
    margin-top: 10px;
}

.submit-demo-modal-btn:hover {
    background-color: #04b083;
}

.submit-demo-modal-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Hide toggle button when chat is open (not closed) - Global Rule */
#automatiza-ai-chat-widget:not(.closed) ~ #automatiza-chat-toggle-container {
    display: none !important;
}

@media (max-width: 768px) {
    #automatiza-ai-chat-widget {
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    #automatiza-chat-toggle-container {
        bottom: 20px !important;
        right: 20px !important;
    }
}

/* Notebooks — mismo cálculo dinámico */
@media (max-height: 900px) and (min-width: 769px) {
    #automatiza-ai-chat-widget {
        bottom: 20px;
        height: calc(100vh - 90px);
    }
}
