@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --accent-primary: #6366f1;
    --accent-secondary: #06b6d4;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(226, 232, 240, 0.8);
    --bot-bubble: #ffffff;
    --user-bubble: #6366f1;
}

body.dark {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(51, 65, 85, 0.8);
    --bot-bubble: #1e293b;
}

/* Base Layout */
.ai-layout-integrated {
    font-family: 'Inter', sans-serif;
    height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    border: none !important;
    overflow: hidden;
    position: relative;
}

/* Top Bar */
.ai-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.ai-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
}

.ai-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ai-controls {
    display: flex;
    gap: 20px;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-item label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ai-select-sm {
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8rem;
    color: var(--text-main);
    outline: none;
}

/* Chat Viewport */
.ai-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

.chat-viewport::-webkit-scrollbar {
    width: 5px;
}

.chat-viewport::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* Message Wrappers */
.message-wrapper {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out;
}

.message-wrapper.user {
    align-self: flex-end;
    flex-direction: row;
}

.message-wrapper.bot {
    align-self: flex-start;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user .message-content {
    align-items: flex-end;
}

/* Message Bubbles */
.message-bubble {
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.5;
    position: relative;
}

.bot .message-bubble {
    background: var(--bot-bubble);
    color: var(--text-main);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.user .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.message-info {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Avatars */
.ai-avatar {
    width: 32px;
    height: 32px;
    background: #0f172a;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chart-container {
    margin-top: 10px;
    background: #fff;
    border-radius: 8px;
    padding: 10px;
    border: 1px solid var(--glass-border);
    max-width: 100%;
    min-height: 200px;
}

.dark .chart-container {
    background: #1e293b;
}

.user-avatar-mini {
    width: 32px;
    height: 32px;
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Footer & Input */
.ai-footer-controls {
    padding: 16px 24px 24px;
    background: linear-gradient(to top, var(--bg-main) 80%, transparent);
}

.quick-tasks-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    justify-content: center;
}

.quick-task-pill {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 0.8rem;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.quick-task-pill:hover {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

.ai-input-bar {
    max-width: 900px;
    margin: 0 auto;
}

.input-glass-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    transition: border-color 0.2s;
}

.input-glass-wrapper:focus-within {
    border-color: var(--accent-primary);
}

.ai-textarea-flat {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px;
    color: var(--text-main);
    font-size: 0.95rem;
    resize: none;
    max-height: 150px;
    outline: none;
}

.ai-send-btn-modern {
    background: var(--accent-primary);
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.ai-send-btn-modern:hover {
    background: #4f46e5;
    transform: scale(1.05);
}

/* Settings Button */
.ai-settings-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-settings-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.05);
}

/* Settings Overlay */
.ai-settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.ai-settings-card {
    background: var(--bg-card);
    width: 600px;
    border-radius: 20px;
    overflow: hidden;
    animation: fadeIn 0.3s ease-out;
}

.keys-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.ai-settings-textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-main);
    border: 1px solid var(--glass-border);
    padding: 12px;
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 8px;
}

.field-info {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.settings-row-flex {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.flex-1 {
    flex: 1;
}

/* Slider Style */
input[type="range"] {
    width: 100%;
    margin: 10px 0;
    cursor: pointer;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.settings-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.settings-body {
    padding: 24px;
}

.settings-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.key-input-group {
    margin-bottom: 16px;
}

.key-input-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.key-input-group input {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--glass-border);
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-main);
    font-size: 0.9rem;
}

.settings-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--glass-border);
    text-align: right;
}

.save-settings-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.save-settings-btn:hover {
    background: #4f46e5;
}

/* Typing Indicator */
.typing-container {
    padding: 10px 40px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Status Pills */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
}

.status-online {
    color: #22c55e;
}

.status-online span {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .ai-top-bar {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .ai-controls {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 5px;
    }

    .ai-user-meta {
        display: none;
    }
}

/* Cancel Button Style */
.ai-cancel-btn {
    margin-left: 15px;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.ai-cancel-btn:hover {
    background: #ef4444;
    color: white;
}

.dark .ai-cancel-btn {
    background: rgba(239, 68, 68, 0.2);
}

/* Floating AI Bubble */
.ai-floating-bubble {
    position: fixed;
    bottom: 25px;
    right: 95px;
    /* Movido a la izquierda para no interferir con otros chats */
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
    z-index: 10000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ai-floating-bubble:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.6);
}

/* Pulsing effect */
.ai-floating-bubble::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: #6366f1;
    border-radius: 50%;
    z-index: -1;
    animation: nexus-pulse 2s infinite;
}

@keyframes nexus-pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

/* Sidebar Drawer */
.ai-sidebar-drawer {
    position: fixed;
    top: 0;
    right: -450px;
    width: 450px;
    height: 100vh;
    background: #ffffff;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.1);
    z-index: 10001;
    transition: right 0.4s cubic-bezier(0.075, 0.82, 0.165, 1);
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
}

.ai-sidebar-drawer.active {
    right: 0;
}

.ai-sidebar-drawer.active.fullscreen {
    width: 100%;
    right: 0;
}

.ai-sidebar-drawer iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.ai-sidebar-close {
    position: absolute;
    top: 120px;
    /* Bajado para no tapar el menú superior */
    left: -40px;
    width: 40px;
    height: 40px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-right: none;
    border-radius: 10px 0 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
}

.ai-sidebar-drawer.active .ai-sidebar-close {
    opacity: 1;
    visibility: visible;
}

.ai-sidebar-close:hover {
    color: #6366f1;
}

@media (max-width: 500px) {
    .ai-sidebar-drawer {
        width: 100%;
        right: -100%;
    }

    .ai-sidebar-close {
        left: auto;
        right: 15px;
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 10px;
    }
}