@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');

/* =====================================================
   VARIABLES / TOKENS
   ===================================================== */
:root {
    --accent-primary:   #6366f1;
    --accent-secondary: #06b6d4;
    --accent-glow:      rgba(99, 102, 241, 0.30);
    --bg-main:          #f1f5f9;
    --bg-card:          #ffffff;
    --text-main:        #0f172a;
    --text-muted:       #64748b;
    --glass-bg:         rgba(255, 255, 255, 0.88);
    --glass-border:     rgba(226, 232, 240, 0.9);
    --bot-bubble:       #ffffff;
    --user-bubble:      #6366f1;
    --shadow-xs:        0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm:        0 2px 6px rgba(0,0,0,0.06);
    --shadow-md:        0 4px 14px rgba(0,0,0,0.08);
    --shadow-lg:        0 10px 32px rgba(0,0,0,0.11);
    --radius-sm:        8px;
    --radius-md:        12px;
    --radius-lg:        16px;
    --radius-xl:        20px;
    --ease:             0.2s ease;
}

body.dark {
    --bg-main:      #0f172a;
    --bg-card:      #1e293b;
    --text-main:    #f1f5f9;
    --text-muted:   #94a3b8;
    --glass-bg:     rgba(15, 23, 42, 0.90);
    --glass-border: rgba(51, 65, 85, 0.90);
    --bot-bubble:   #1e293b;
    --shadow-sm:    0 2px 6px rgba(0,0,0,0.25);
    --shadow-md:    0 4px 14px rgba(0,0,0,0.35);
    --shadow-lg:    0 10px 32px rgba(0,0,0,0.50);
}

/* =====================================================
   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 gradient beam */
.decorative-beam {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 55%;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--accent-primary) 30%,
        var(--accent-secondary) 70%,
        transparent 100%);
    z-index: 20;
    pointer-events: none;
    border-radius: 0 0 4px 4px;
}

/* =====================================================
   TOP BAR
   ===================================================== */
.ai-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.ai-logo-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px var(--accent-glow);
    flex-shrink: 0;
    transition: box-shadow var(--ease);
}

.ai-logo-icon:hover { box-shadow: 0 6px 18px var(--accent-glow); }

.ai-title-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-title {
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    margin: 0;
    line-height: 1.1;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Status pill */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.status-online { color: #22c55e; }

.pulse-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse-ring 2s infinite;
    flex-shrink: 0;
}

/* Controls */
.ai-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.glass-controls { background: transparent; }

.controls-divider {
    width: 1px;
    height: 22px;
    background: var(--glass-border);
    margin: 0 3px;
    flex-shrink: 0;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-item label {
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    white-space: nowrap;
}

.ai-select-sm {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 5px 10px;
    font-size: 0.78rem;
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    transition: border-color var(--ease);
    max-width: 145px;
}

.ai-select-sm:hover,
.ai-select-sm:focus { border-color: var(--accent-primary); }

.ai-settings-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--ease);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.ai-settings-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.06);
    transform: translateY(-1px);
}

/* =====================================================
   CHAT VIEWPORT
   ===================================================== */
.ai-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
}

.chat-viewport::-webkit-scrollbar       { width: 4px; }
.chat-viewport::-webkit-scrollbar-track { background: transparent; }
.chat-viewport::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}
.chat-viewport::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =====================================================
   MESSAGES
   ===================================================== */
.message-wrapper {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeSlideIn 0.28s ease-out;
}

.message-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-wrapper.bot { align-self: flex-start; }

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.user .message-content { align-items: flex-end; }

.message-bubble {
    padding: 11px 16px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.65;
    position: relative;
    word-break: break-word;
}

.bot .message-bubble {
    background: var(--bot-bubble);
    color: var(--text-main);
    border-top-left-radius: 4px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-xs);
}

.user .message-bubble {
    background: linear-gradient(135deg, var(--accent-primary) 0%, #4f46e5 100%);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.28);
}

.message-info {
    font-size: 0.64rem;
    color: var(--text-muted);
    padding: 0 2px;
}

/* Avatars */
.ai-avatar {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #1e293b, #334155);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    flex-shrink: 0;
    border: 2px solid var(--glass-border);
}

.user-avatar-mini {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Welcome message */
.welcome-header {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.welcome-features {
    list-style: none;
    padding: 0;
    margin: 10px 0 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.welcome-features li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    color: var(--text-muted);
}

.welcome-features li i {
    color: var(--accent-primary);
    font-size: 0.78rem;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

/* Chart */
.chart-container {
    margin-top: 12px;
    background: var(--bg-main);
    border-radius: var(--radius-md);
    padding: 14px;
    border: 1px solid var(--glass-border);
    max-width: 100%;
    min-height: 220px;
    position: relative;
}

.dark .chart-container { background: #0f172a; }

/* =====================================================
   TYPING INDICATOR
   ===================================================== */
.typing-container {
    display: flex;
    align-items: center;
    padding: 6px 24px;
    gap: 10px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dot {
    width: 7px;
    height: 7px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.16s; }
.dot:nth-child(3) { animation-delay: 0.32s; }

.ai-cancel-btn {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.20);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all var(--ease);
}

.ai-cancel-btn:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

/* =====================================================
   ACTION HUB  (quick tasks)
   ===================================================== */
.ai-action-hub {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: var(--shadow-xs);
}

/* Tab row */
.hub-categories {
    display: flex;
    background: var(--bg-main);
    border-bottom: 1px solid var(--glass-border);
    overflow-x: auto;
    scrollbar-width: none;
}
.hub-categories::-webkit-scrollbar { display: none; }

.hub-tab {
    flex: 1;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 7px 10px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all var(--ease);
    white-space: nowrap;
}

.hub-tab i { font-size: 0.78rem; }

.hub-tab:hover {
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.04);
}

.hub-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.06);
}

/* Pills area */
.hub-content-wrapper { padding: 8px 10px; }

.hub-category-content {
    display: none;
    gap: 6px;
    flex-wrap: wrap;
}

.hub-category-content.active { display: flex; }

.quick-task-pill {
    background: transparent;
    border: 1px solid var(--glass-border);
    padding: 5px 12px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--ease);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.quick-task-pill i { font-size: 0.7rem; }

.quick-task-pill:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.06);
    transform: translateY(-1px);
}

/* =====================================================
   INPUT BAR
   ===================================================== */
.ai-footer-controls {
    padding: 8px 20px 14px;
    background: linear-gradient(to top, var(--bg-main) 72%, transparent);
}

.ai-input-bar {
    max-width: 860px;
    margin: 0 auto;
}

.input-glass-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: flex-end;
    padding: 6px 8px;
    box-shadow: var(--shadow-md);
    transition: border-color var(--ease), box-shadow var(--ease);
}

.input-glass-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.10), var(--shadow-md);
}

.ai-action-btn-left {
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: color var(--ease), background var(--ease);
    flex-shrink: 0;
}

.ai-action-btn-left:hover {
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.06);
}

.ai-textarea-flat {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 10px;
    color: var(--text-main);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    outline: none;
    line-height: 1.5;
}

.ai-textarea-flat::placeholder {
    color: var(--text-muted);
    font-size: 0.87rem;
}

.ai-send-btn-flush,
.ai-send-btn-modern {
    width: 34px;
    height: 34px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.88rem;
    transition: all var(--ease);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.30);
}

.ai-send-btn-flush:hover,
.ai-send-btn-modern:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.45);
}

.ai-send-btn-flush:active,
.ai-send-btn-modern:active { transform: translateY(0); }

/* =====================================================
   SETTINGS OVERLAY
   ===================================================== */
.ai-settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.52);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.ai-settings-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 580px;
    max-height: 86vh;
    border-radius: var(--radius-xl);
    overflow: hidden;
    animation: fadeSlideIn 0.24s ease-out;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

.settings-header {
    padding: 16px 22px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: linear-gradient(135deg,
        rgba(99,102,241,0.04) 0%,
        rgba(6,182,212,0.03) 100%);
}

.settings-header h3 {
    margin: 0;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--text-main);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all var(--ease);
}

.close-btn:hover {
    color: var(--text-main);
    background: var(--bg-main);
}

.settings-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}

.settings-body::-webkit-scrollbar       { width: 4px; }
.settings-body::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

.settings-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 16px;
    line-height: 1.5;
}

.key-input-group { margin-bottom: 14px; }

.key-input-group label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.key-input-group input,
.ai-settings-textarea {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--glass-border);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
    box-sizing: border-box;
}

.key-input-group input:focus,
.ai-settings-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.10);
}

.ai-settings-textarea {
    min-height: 96px;
    resize: vertical;
    margin-bottom: 4px;
}

.field-info {
    display: block;
    font-size: 0.67rem;
    color: var(--text-muted);
    margin: 4px 0 0;
    line-height: 1.4;
}

.keys-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.settings-row-flex {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.flex-1 { flex: 1; }

/* Slider */
input[type="range"] {
    width: 100%;
    margin: 8px 0 4px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.settings-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.save-settings-btn {
    background: linear-gradient(135deg, var(--accent-primary), #4f46e5);
    color: white;
    border: none;
    padding: 9px 22px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all var(--ease);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.28);
}

.save-settings-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.44);
}

/* =====================================================
   TOAST  (feedback message)
   ===================================================== */
.ai-toast {
    position: absolute;
    bottom: 18px;
    right: 18px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 11px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-lg);
    min-width: 230px;
    max-width: 320px;
    z-index: 200;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.3s cubic-bezier(0.175,0.885,0.32,1.275),
                transform 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    pointer-events: none;
}

.ai-toast.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.toast-indicator {
    width: 3px;
    height: 34px;
    border-radius: 3px;
    background: #22c55e;
    flex-shrink: 0;
}

.ai-toast.error   .toast-indicator { background: #ef4444; }
.ai-toast.success .toast-indicator { background: #22c55e; }

.toast-content {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
}

.toast-content > i {
    font-size: 0.95rem;
    color: #22c55e;
    flex-shrink: 0;
}

.ai-toast.error .toast-content > i { color: #ef4444; }

.toast-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.toast-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.toast-desc {
    font-size: 0.74rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =====================================================
   CONFIRM TOAST
   ===================================================== */
.ai-confirm-toast {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.175,0.885,0.32,1.275),
                transform 0.3s cubic-bezier(0.175,0.885,0.32,1.275);
    pointer-events: none;
    white-space: nowrap;
}

.ai-confirm-toast.active {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.ai-confirm-toast .toast-content {
    font-size: 0.84rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-confirm-toast .toast-icon { color: #f59e0b; }

.toast-actions {
    display: flex;
    gap: 6px;
}

.btn-cancel,
.btn-confirm {
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--ease);
}

.btn-cancel {
    background: var(--bg-main);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
}
.btn-cancel:hover {
    background: var(--glass-border);
    color: var(--text-main);
}

.btn-confirm {
    background: #ef4444;
    color: white;
}
.btn-confirm:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* =====================================================
   FLOATING BUBBLE + SIDEBAR DRAWER
   ===================================================== */
.ai-floating-bubble {
    position: fixed;
    bottom: 90px;
    right: 18px;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(99, 102, 241, 0.44);
    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.22);
}

.ai-floating-bubble:hover {
    transform: scale(1.12) rotate(12deg);
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.60);
}

.ai-floating-bubble::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-primary);
    border-radius: 50%;
    z-index: -1;
    animation: nexus-pulse 2.2s infinite;
}

.ai-sidebar-drawer {
    position: fixed;
    top: 0;
    right: -460px;
    width: 460px;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.12);
    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 var(--glass-border);
}

.ai-sidebar-drawer.active               { right: 0; }
.ai-sidebar-drawer.active.fullscreen    { width: 100%; }
.ai-sidebar-drawer iframe               { width: 100%; height: 100%; border: none; }

.ai-sidebar-close {
    position: absolute;
    top: 115px;
    left: -38px;
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-right: none;
    border-radius: 10px 0 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, color var(--ease);
}

.ai-sidebar-drawer.active .ai-sidebar-close { opacity: 1; visibility: visible; }
.ai-sidebar-close:hover { color: var(--accent-primary); }

/* =====================================================
   DARK MODE EXTRAS
   ===================================================== */
.dark .ai-avatar {
    background: linear-gradient(135deg, #334155, #475569);
    border-color: rgba(51,65,85,0.8);
}

.dark .ai-select-sm { background: var(--bg-card); }

.dark .ai-cancel-btn { background: rgba(239, 68, 68, 0.14); }

.dark .hub-categories { background: rgba(15, 23, 42, 0.50); }

.dark .ai-sidebar-close {
    background: var(--bg-card);
    border-color: var(--glass-border);
}

/* =====================================================
   ANIMATIONS
   ===================================================== */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@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); }
}

@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0   rgba(34,197,94,0.55); }
    70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0   rgba(34,197,94,0); }
}

@keyframes nexus-pulse {
    0%   { transform: scale(1);   opacity: 0.5; }
    100% { transform: scale(1.9); opacity: 0; }
}

/* =====================================================
   MARKDOWN EN BURBUJAS DE BOT
   ===================================================== */
.message-bubble p         { margin: 0 0 .6em; line-height: 1.65; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4        { margin: .8em 0 .4em; font-weight: 600; line-height: 1.3; }
.message-bubble h1        { font-size: 1.15rem; }
.message-bubble h2        { font-size: 1.05rem; }
.message-bubble h3        { font-size: .97rem;  }
.message-bubble ul,
.message-bubble ol        { margin: .4em 0 .6em 1.4em; padding: 0; line-height: 1.7; }
.message-bubble li        { margin-bottom: .25em; }
.message-bubble hr        { border: none; border-top: 1px solid var(--glass-border); margin: .75em 0; }
.message-bubble blockquote{
    border-left: 3px solid var(--accent-primary);
    margin: .5em 0;
    padding: .35em .8em;
    color: var(--text-muted);
    background: rgba(99,102,241,.06);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.message-bubble code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: .85em;
    background: rgba(99,102,241,.12);
    border: 1px solid rgba(99,102,241,.18);
    border-radius: 4px;
    padding: .1em .45em;
}
.message-bubble pre {
    background: #0f172a;
    border-radius: var(--radius-md);
    padding: 1em 1.1em;
    overflow-x: auto;
    margin: .6em 0;
    box-shadow: var(--shadow-sm);
}
.message-bubble pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: .82em;
    color: #e2e8f0;
}
/* Tablas */
.message-bubble table {
    border-collapse: collapse;
    width: 100%;
    font-size: .85rem;
    margin: .6em 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}
.message-bubble thead th {
    background: var(--accent-primary);
    color: #fff;
    font-weight: 600;
    padding: .55em .8em;
    text-align: left;
}
.message-bubble tbody tr:nth-child(even) { background: rgba(99,102,241,.06); }
.message-bubble tbody td {
    padding: .45em .8em;
    border-bottom: 1px solid var(--glass-border);
    color: var(--text-main);
}
/* Links */
.message-bubble a {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* =====================================================
   ACCIONES DE MENSAJE (COPIAR / DESCARGAR)
   ===================================================== */
.msg-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity var(--ease);
}
.message-wrapper.bot:hover .msg-actions { opacity: 1; }

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: var(--glass-bg);
    color: var(--text-muted);
    cursor: pointer;
    font-size: .78rem;
    transition: background var(--ease), color var(--ease), transform var(--ease);
    backdrop-filter: blur(6px);
}
.msg-action-btn:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
    transform: scale(1.1);
}

.msg-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    text-decoration: none;
    transition: opacity var(--ease), transform var(--ease);
}
.msg-download-btn:hover { opacity: .85; transform: scale(1.03); color: #fff; text-decoration: none; }

/* =====================================================
   BOTÓN DE VOZ
   ===================================================== */
.voice-active {
    background: rgba(239, 68, 68, .15) !important;
    color: #ef4444 !important;
    border-color: #ef4444 !important;
    animation: voice-pulse 1.2s ease-in-out infinite;
}

@keyframes voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .4); }
    50%       { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .ai-top-bar        { padding: 10px 14px; gap: 8px; }
    .ai-footer-controls{ padding: 6px 12px 12px; }
    .chat-viewport     { padding: 14px 14px; gap: 14px; }

    .ai-controls {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .controls-divider          { display: none; }
    .hub-tab span              { display: none; }
    .hub-tab                   { padding: 8px; min-width: 44px; }
    .message-wrapper           { max-width: 92%; }
    .keys-grid                 { grid-template-columns: 1fr; }
    .ai-settings-card          { max-height: 94vh; }
    .ai-confirm-toast          { white-space: normal; max-width: calc(100vw - 36px); }
    .ai-sidebar-drawer         { width: 100%; right: -100%; }
    .ai-sidebar-close          {
        left: auto; right: 12px;
        border: 1px solid var(--glass-border);
        border-radius: 10px;
    }
}

@media (max-width: 420px) {
    .quick-task-pill { font-size: 0.7rem; padding: 4px 10px; }
    .hub-categories  { overflow-x: auto; scrollbar-width: none; }
}
