/* AI Assistant Chat Widget */
#aiAssistantWidget {
    position: fixed;
    bottom: 45px;
    right: 24px;
    z-index: 9999;
    font-family: inherit;
}

.ai-chat-fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background-color: #5e6d9d;
    color: white;
    border: none;
    cursor: grab;
    font-size: 20px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.15s;
    outline: none;
    margin-left: auto;
}

.ai-chat-fab:hover {
    background-color: #4d5c8b;
    transform: scale(1.07);
}

.ai-chat-fab.ai-chat-open {
    background-color: #4d5c8b;
}

.ai-chat-panel {
    display: none;
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 360px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    flex-direction: column;
    animation: aiChatSlideIn 0.2s ease;
}

.ai-chat-panel.open {
    display: flex;
    height: 420px;
}

@keyframes aiChatSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Resize handle — top-left corner of the panel */
.ai-chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    cursor: nw-resize;
    z-index: 10;
}


.ai-chat-header {
    background-color: #5e6d9d;
    color: white;
    padding: 11px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
}

.ai-chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 14px;
    padding: 3px 7px;
    border-radius: 4px;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
    outline: none;
    line-height: 1;
    position: absolute;
    right: 10px;
}

.ai-chat-close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.18);
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
    background: #f4f6f9;
}

.ai-chat-msg {
    max-width: 86%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
}

.ai-chat-msg.user {
    align-self: flex-end;
    background-color: #5e6d9d;
    color: white;
    border-bottom-right-radius: 3px;
}

.ai-chat-msg.assistant {
    align-self: flex-start;
    background-color: #ffffff;
    color: #333;
    border: 1px solid #e0e4eb;
    border-bottom-left-radius: 3px;
}

.ai-chat-msg.error {
    align-self: flex-start;
    background-color: #fef0f0;
    color: #c0392b;
    border: 1px solid #f5c6cb;
    border-bottom-left-radius: 3px;
}

.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e0e4eb;
    border-radius: 10px;
    border-bottom-left-radius: 3px;
    align-self: flex-start;
}

.ai-typing-dot {
    width: 7px;
    height: 7px;
    background-color: #aab4c0;
    border-radius: 50%;
    animation: aiTypingBounce 1.2s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTypingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-6px); }
}

.ai-chat-footer {
    padding: 8px 10px;
    border-top: 1px solid #e9ecef;
    background: white;
    flex-shrink: 0;
}

.ai-chat-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-chat-input-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.ai-chat-validation {
    display: none;
    color: #c0392b;
    font-size: 11px;
    padding-left: 2px;
    line-height: 1.2;
}

.ai-chat-input {
    width: 100%;
    border: 1px solid #ced4da;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 80px;
    overflow-y: auto;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-chat-input:focus {
    border-color: #5e6d9d;
    box-shadow: 0 0 0 2px rgba(94, 109, 157, 0.15);
}

.ai-chat-send-btn {
    background-color: #5e6d9d;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 13px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.15s;
    outline: none;
    flex-shrink: 0;
    line-height: 1;
}

.ai-chat-send-btn:hover:not(:disabled) {
    background-color: #4d5c8b;
}

.ai-chat-send-btn:disabled {
    background-color: #9aabc8;
    cursor: not-allowed;
}

.ai-chat-welcome {
    text-align: center;
    color: #7a8a9a;
    font-size: 12px;
    padding: 20px 16px 8px;
    line-height: 1.5;
}

.ai-chat-disclaimer {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e2e7ed;
    font-size: 11px;
    color: #b8c4cc;
    font-style: italic;
    line-height: 1.4;
}

/* Markdown en mensajes del asistente */
.ai-chat-msg.assistant .ai-md-h {
    font-weight: 700;
    margin: 6px 0 2px;
    display: block;
}
.ai-chat-msg.assistant .ai-md-h1 { font-size: 14px; }
.ai-chat-msg.assistant .ai-md-h2 { font-size: 13px; }
.ai-chat-msg.assistant .ai-md-h3 { font-size: 13px; font-weight: 600; }

.ai-chat-msg.assistant .ai-md-ul,
.ai-chat-msg.assistant .ai-md-ol {
    margin: 3px 0;
    padding-left: 18px;
}
.ai-chat-msg.assistant li {
    margin: 2px 0;
    line-height: 1.45;
}
.ai-chat-msg.assistant .ai-md-ul .ai-md-ul {
    margin: 1px 0;
}

.ai-chat-msg.assistant .ai-md-hr {
    border: none;
    border-top: 1px solid #d5dce6;
    margin: 6px 0;
}

.ai-chat-msg.assistant .ai-md-gap {
    height: 5px;
}

.ai-chat-msg.assistant .ai-md-code {
    background: #f0f2f5;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    font-family: Consolas, monospace;
}
