/* ═══════════════════════════════════════
   CODE AI — Selection Tooltip + Panels
   ═══════════════════════════════════════ */

/* ─── Selection Tooltip ─── */
.cai-tooltip {
    position: fixed;
    z-index: 10000;
    display: flex;
    gap: 6px;
    padding: 6px;
    background: rgba(15, 15, 35, 0.92);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 12px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 20px rgba(99, 102, 241, 0.08);
    opacity: 0;
    transform: translateY(8px) scale(0.95);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.cai-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.cai-tooltip-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.cai-tooltip-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.cai-btn-explain {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}
.cai-btn-explain:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.cai-btn-ask {
    background: rgba(99, 102, 241, 0.12);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.2);
}
.cai-btn-ask:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.35);
    transform: translateY(-1px);
}

/* Light mode tooltip */
[data-theme="light"] .cai-tooltip {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(99, 102, 241, 0.15);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(99, 102, 241, 0.05);
}
[data-theme="light"] .cai-btn-ask {
    background: rgba(99, 102, 241, 0.06);
    color: #4338ca;
    border-color: rgba(99, 102, 241, 0.15);
}

/* ─── Overlay ─── */
.cai-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.cai-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
[data-theme="light"] .cai-overlay {
    background: rgba(0, 0, 0, 0.2);
}

/* ─── Side Panel ─── */
.cai-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    max-width: 90vw;
    height: 100vh;
    z-index: 10002;
    display: flex;
    flex-direction: column;
    background: #0a0a1a;
    border-left: 1px solid rgba(99, 102, 241, 0.15);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.4);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.cai-panel.open {
    transform: translateX(0);
}

[data-theme="light"] .cai-panel {
    background: #ffffff;
    border-left-color: rgba(99, 102, 241, 0.1);
    box-shadow: -20px 0 60px rgba(0, 0, 0, 0.08);
}

/* ─── Panel Header ─── */
.cai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.1);
    flex-shrink: 0;
}

.cai-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #e0e7ff;
}
.cai-panel-title svg {
    width: 18px;
    height: 18px;
    color: #6366f1;
}
[data-theme="light"] .cai-panel-title { color: #1e1b4b; }

.cai-panel-badge {
    padding: 3px 10px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 20px;
    font-size: 0.62rem;
    font-weight: 700;
    color: #a5b4fc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
[data-theme="light"] .cai-panel-badge { color: #4338ca; }

.cai-panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    color: #a5b4fc;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 1.1rem;
}
.cai-panel-close:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}
[data-theme="light"] .cai-panel-close { color: #6b7280; }

/* ─── Code Preview (inside panel) ─── */
.cai-code-preview {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.08);
    flex-shrink: 0;
    max-height: 200px;
    overflow-y: auto;
}

.cai-code-preview-label {
    font-size: 0.62rem;
    font-weight: 700;
    color: rgba(165, 180, 252, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}
[data-theme="light"] .cai-code-preview-label { color: #9ca3af; }

.cai-code-preview pre {
    margin: 0;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(99, 102, 241, 0.1);
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    line-height: 1.6;
    color: #a5b4fc;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
[data-theme="light"] .cai-code-preview pre {
    background: #f3f4f6;
    border-color: rgba(99, 102, 241, 0.08);
    color: #1e1b4b;
}

/* ─── Panel Body (scrollable) ─── */
.cai-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.15) transparent;
}
.cai-panel-body::-webkit-scrollbar { width: 5px; }
.cai-panel-body::-webkit-scrollbar-track { background: transparent; }
.cai-panel-body::-webkit-scrollbar-thumb { background: rgba(99, 102, 241, 0.15); border-radius: 3px; }

/* ─── AI Response ─── */
.cai-response {
    font-size: 0.85rem;
    line-height: 1.8;
    color: rgba(200, 210, 240, 0.8);
}
[data-theme="light"] .cai-response { color: #374151; }

.cai-response h3 {
    font-size: 0.9rem;
    font-weight: 800;
    color: #e0e7ff;
    margin: 20px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}
.cai-response h3:first-child { margin-top: 0; }
[data-theme="light"] .cai-response h3 { color: #1e1b4b; }

.cai-response code {
    padding: 2px 7px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78em;
    color: #a5b4fc;
}
[data-theme="light"] .cai-response code { background: rgba(99, 102, 241, 0.06); color: #4338ca; }

.cai-response pre {
    margin: 10px 0;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.1);
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    color: #a5b4fc;
    overflow-x: auto;
}
[data-theme="light"] .cai-response pre { background: #f3f4f6; color: #1e1b4b; }

.cai-response ul, .cai-response ol {
    padding-left: 20px;
    margin: 8px 0;
}
.cai-response li { margin: 4px 0; }

.cai-response strong { color: #e0e7ff; }
[data-theme="light"] .cai-response strong { color: #1e1b4b; }

/* ─── Chat Messages ─── */
.cai-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cai-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.cai-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    font-weight: 700;
}

.cai-msg-user .cai-msg-avatar {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}
.cai-msg-ai .cai-msg-avatar {
    background: rgba(168, 85, 247, 0.15);
    color: #c4b5fd;
}
[data-theme="light"] .cai-msg-user .cai-msg-avatar { background: rgba(99, 102, 241, 0.08); color: #4338ca; }
[data-theme="light"] .cai-msg-ai .cai-msg-avatar { background: rgba(168, 85, 247, 0.08); color: #6d28d9; }

.cai-msg-body {
    flex: 1;
    min-width: 0;
}

.cai-msg-user .cai-msg-body {
    padding: 10px 14px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.1);
    border-radius: 12px;
    font-size: 0.82rem;
    color: #e0e7ff;
    line-height: 1.6;
}
[data-theme="light"] .cai-msg-user .cai-msg-body { background: rgba(99, 102, 241, 0.04); color: #1e1b4b; }

.cai-msg-ai .cai-msg-body {
    font-size: 0.82rem;
}

/* ─── Loading Indicator ─── */
.cai-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    font-size: 0.78rem;
    color: rgba(165, 180, 252, 0.5);
}
[data-theme="light"] .cai-loading { color: #9ca3af; }

.cai-loading-dots {
    display: flex;
    gap: 4px;
}
.cai-loading-dots span {
    width: 6px;
    height: 6px;
    background: #6366f1;
    border-radius: 50%;
    animation: caiDot 1.4s ease-in-out infinite;
}
.cai-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.cai-loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes caiDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ─── Chat Input ─── */
.cai-input-wrap {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid rgba(99, 102, 241, 0.1);
    flex-shrink: 0;
    background: rgba(10, 10, 26, 0.5);
}
[data-theme="light"] .cai-input-wrap { background: rgba(248, 249, 255, 0.8); }

.cai-input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 10px;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.82rem;
    color: #e0e7ff;
    outline: none;
    transition: border-color 0.2s;
}
.cai-input::placeholder { color: rgba(165, 180, 252, 0.3); }
.cai-input:focus { border-color: rgba(99, 102, 241, 0.4); }
[data-theme="light"] .cai-input { background: #ffffff; border-color: rgba(99, 102, 241, 0.12); color: #1e1b4b; }
[data-theme="light"] .cai-input::placeholder { color: #c0c0d0; }

.cai-send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.cai-send-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); }
.cai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.cai-send-btn svg { width: 16px; height: 16px; }

/* ─── Error State ─── */
.cai-error {
    padding: 12px 16px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 10px;
    font-size: 0.78rem;
    color: #fca5a5;
    line-height: 1.5;
}
[data-theme="light"] .cai-error { color: #dc2626; }

/* ─── Responsive ─── */
@media (max-width: 600px) {
    .cai-panel {
        width: 100vw;
        max-width: 100vw;
    }
    .cai-tooltip {
        flex-direction: column;
    }
}
