/* =============================================
   GLOBAL AI CHAT - Floating Assistant
   ============================================= */

/* Floating trigger button */
.global-ai-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4), 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

.global-ai-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(102, 126, 234, 0.5), 0 4px 12px rgba(0,0,0,0.12);
}

.global-ai-fab:active {
    transform: scale(0.95);
}

.global-ai-fab svg {
    width: 24px;
    height: 24px;
}

.global-ai-fab.hidden {
    display: none;
}

/* Panel */
.global-ai-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 420px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,0,0,0.06);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

.global-ai-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
.global-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.06) 0%, rgba(118, 75, 162, 0.06) 100%);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.global-ai-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.global-ai-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.global-ai-header-icon svg {
    width: 18px;
    height: 18px;
}

.global-ai-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #0F172A;
}

.global-ai-header-section {
    font-size: 11px;
    color: #94A3B8;
    font-weight: 500;
    margin-top: 1px;
}

.global-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.global-ai-header-actions button {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #64748B;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.global-ai-header-actions button:hover {
    background: rgba(0,0,0,0.06);
    color: #0F172A;
}

/* Quick prompts */
.global-ai-prompts {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    flex-shrink: 0;
    max-height: 120px;
    overflow-y: auto;
}

.global-ai-prompt-btn {
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid rgba(0,0,0,0.08);
    background: #FAFBFC;
    color: #475569;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.3;
}

.global-ai-prompt-btn:hover {
    border-color: #667eea;
    color: #667eea;
    background: rgba(102, 126, 234, 0.04);
}

/* Chat area */
.global-ai-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.global-ai-chat::-webkit-scrollbar {
    width: 4px;
}

.global-ai-chat::-webkit-scrollbar-track {
    background: transparent;
}

.global-ai-chat::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 2px;
}

/* Welcome state */
.global-ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px;
    text-align: center;
}

.global-ai-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8B5CF6;
    margin-bottom: 12px;
}

.global-ai-welcome-icon svg {
    width: 24px;
    height: 24px;
}

.global-ai-welcome h4 {
    font-size: 16px;
    font-weight: 600;
    color: #0F172A;
    margin: 0 0 6px;
}

.global-ai-welcome p {
    font-size: 13px;
    color: #94A3B8;
    margin: 0;
    line-height: 1.5;
}

/* Messages */
.global-ai-msg {
    display: flex;
    gap: 8px;
    max-width: 92%;
}

.global-ai-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.global-ai-msg.assistant {
    align-self: flex-start;
}

.global-ai-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.global-ai-msg-avatar svg {
    width: 14px;
    height: 14px;
}

.global-ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.global-ai-msg.user .global-ai-msg-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.global-ai-msg.assistant .global-ai-msg-bubble {
    background: #F8FAFC;
    color: #1E293B;
    border: 1px solid rgba(0,0,0,0.04);
    border-bottom-left-radius: 4px;
}

.global-ai-msg-bubble h4, .global-ai-msg-bubble h5 {
    font-size: 13px;
    font-weight: 600;
    margin: 8px 0 4px;
}

.global-ai-msg-bubble h4:first-child, .global-ai-msg-bubble h5:first-child {
    margin-top: 0;
}

.global-ai-msg-bubble ul, .global-ai-msg-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}

.global-ai-msg-bubble li {
    margin: 2px 0;
}

.global-ai-msg-bubble strong {
    font-weight: 600;
}

.global-ai-msg-time {
    font-size: 10px;
    color: #CBD5E1;
    margin-top: 4px;
    text-align: right;
}

.global-ai-msg.assistant .global-ai-msg-time {
    text-align: left;
}

/* Model badge */
.global-ai-model-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: #94A3B8;
    margin-top: 2px;
}

.global-ai-model-badge.opus {
    color: #8B5CF6;
}

/* Loading dots */
.global-ai-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
}

.global-ai-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #F8FAFC;
    border-radius: 14px;
    border: 1px solid rgba(0,0,0,0.04);
}

.global-ai-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94A3B8;
    animation: globalAiTypingDot 1.4s infinite ease-in-out both;
}

.global-ai-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.global-ai-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.global-ai-typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes globalAiTypingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.global-ai-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    background: #FAFBFC;
}

.global-ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.global-ai-input-row textarea {
    flex: 1;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    resize: none;
    outline: none;
    background: #fff;
    color: #0F172A;
    line-height: 1.4;
    max-height: 100px;
    transition: border-color 0.15s;
}

.global-ai-input-row textarea:focus {
    border-color: #667eea;
}

.global-ai-input-row textarea::placeholder {
    color: #CBD5E1;
}

.global-ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: box-shadow 0.15s, transform 0.15s;
}

.global-ai-send-btn:hover:not(:disabled) {
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
}

.global-ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.global-ai-send-btn svg {
    width: 16px;
    height: 16px;
}

/* Deep analysis toggle */
.global-ai-model-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
}

.global-ai-model-toggle label {
    font-size: 11px;
    color: #94A3B8;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    transition: color 0.15s;
}

.global-ai-model-toggle label:hover {
    color: #64748B;
}

.global-ai-model-switch {
    position: relative;
    width: 32px;
    height: 18px;
}

.global-ai-model-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.global-ai-model-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #E2E8F0;
    border-radius: 9px;
    transition: background 0.2s;
}

.global-ai-model-switch .slider:before {
    content: '';
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.global-ai-model-switch input:checked + .slider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.global-ai-model-switch input:checked + .slider:before {
    transform: translateX(14px);
}

.global-ai-deep-label {
    transition: color 0.15s;
}

.global-ai-deep-label.active {
    color: #8B5CF6 !important;
    font-weight: 500;
}

/* Responsive — lift FAB above mobile bottom nav (56px + safe-area) */
@media (max-width: 768px) {
    .global-ai-fab {
        bottom: calc(56px + env(safe-area-inset-bottom, 0) + 16px);
    }
}

@media (max-width: 480px) {
    .global-ai-panel {
        bottom: 0;
        right: 0;
        width: 100vw;
        max-width: 100vw;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        border-radius: 20px 20px 0 0;
    }

    .global-ai-fab {
        bottom: calc(56px + env(safe-area-inset-bottom, 0) + 12px);
        right: 16px;
        width: 48px;
        height: 48px;
    }
}
