/* NEXUS AI Trading Agent — Sticky Bottom Chat Bar
   Dark theme, blue accents (NO purple), bottom-docked layout.
   z-index: 9990 (below modals at 10000, above regular content) */

/* ========== Container & Collapsed Bar ========== */

#nexus-chat-widget {
    position: fixed;
    bottom: 52px; /* sit above footer-bar */
    left: 0;
    right: 0;
    z-index: 9990;
    font-family: 'JetBrains Mono', 'Roboto', monospace;
    pointer-events: none;
}

#nexus-chat-widget * {
    box-sizing: border-box;
}

#nexus-chat-widget .nexus-bar {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(10, 14, 20, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(59, 130, 246, 0.2);
    transition: border-color 0.2s ease;
}

#nexus-chat-widget .nexus-bar:hover {
    border-top-color: rgba(59, 130, 246, 0.4);
}

/* NEXUS icon/badge */
#nexus-chat-widget .nexus-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(6, 182, 212, 0.2));
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.5px;
    cursor: pointer;
    user-select: none;
}

/* Input field in collapsed bar */
#nexus-chat-widget .nexus-input-wrap {
    flex: 1;
    position: relative;
}

#nexus-chat-widget .nexus-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #e2e8f0;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
}

#nexus-chat-widget .nexus-input::placeholder {
    color: rgba(148, 163, 184, 0.6);
}

#nexus-chat-widget .nexus-input:focus {
    border-color: rgba(59, 130, 246, 0.5);
    background: rgba(255, 255, 255, 0.08);
}

/* Buttons */
#nexus-chat-widget .nexus-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 0;
}

#nexus-chat-widget .nexus-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

#nexus-chat-widget .nexus-btn-send {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

#nexus-chat-widget .nexus-btn-send:hover {
    background: rgba(59, 130, 246, 0.35);
    color: #93c5fd;
}

#nexus-chat-widget .nexus-btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ========== Expanded Panel ========== */

#nexus-chat-widget .nexus-panel {
    pointer-events: auto;
    display: none;
    flex-direction: column;
    height: 400px;
    background: rgba(10, 14, 20, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(59, 130, 246, 0.2);
}

#nexus-chat-widget.nexus-expanded .nexus-panel {
    display: flex;
}

/* Panel header */
#nexus-chat-widget .nexus-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

#nexus-chat-widget .nexus-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #60a5fa;
    letter-spacing: 0.5px;
}

#nexus-chat-widget .nexus-panel-title .nexus-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22d3ee;
    box-shadow: 0 0 6px rgba(34, 211, 238, 0.5);
}

#nexus-chat-widget .nexus-panel-actions {
    display: flex;
    gap: 4px;
}

/* Messages area */
#nexus-chat-widget .nexus-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#nexus-chat-widget .nexus-messages::-webkit-scrollbar {
    width: 4px;
}

#nexus-chat-widget .nexus-messages::-webkit-scrollbar-track {
    background: transparent;
}

#nexus-chat-widget .nexus-messages::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.3);
    border-radius: 2px;
}

/* Message bubbles */
#nexus-chat-widget .nexus-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#nexus-chat-widget .nexus-msg-user {
    align-self: flex-end;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.15);
    color: #e2e8f0;
}

#nexus-chat-widget .nexus-msg-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
}

/* Streaming indicator */
#nexus-chat-widget .nexus-msg-assistant .nexus-cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: #60a5fa;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: nexusBlink 0.8s step-end infinite;
}

@keyframes nexusBlink {
    50% { opacity: 0; }
}

/* Typing indicator */
#nexus-chat-widget .nexus-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}

#nexus-chat-widget .nexus-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.5);
    animation: nexusTyping 1.2s infinite;
}

#nexus-chat-widget .nexus-typing-dot:nth-child(2) { animation-delay: 0.2s; }
#nexus-chat-widget .nexus-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes nexusTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* Welcome message */
#nexus-chat-widget .nexus-welcome {
    text-align: center;
    padding: 32px 20px;
    color: #64748b;
    font-size: 13px;
    line-height: 1.6;
}

#nexus-chat-widget .nexus-welcome strong {
    color: #60a5fa;
    font-weight: 600;
}

/* Markdown support inside messages */
#nexus-chat-widget .nexus-msg-assistant strong {
    color: #93c5fd;
    font-weight: 600;
}

#nexus-chat-widget .nexus-msg-assistant code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
}

#nexus-chat-widget .nexus-msg-assistant pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
}

#nexus-chat-widget .nexus-msg-assistant pre code {
    background: none;
    padding: 0;
}

#nexus-chat-widget .nexus-msg-assistant ul,
#nexus-chat-widget .nexus-msg-assistant ol {
    padding-left: 20px;
    margin: 6px 0;
}

#nexus-chat-widget .nexus-msg-assistant h3,
#nexus-chat-widget .nexus-msg-assistant h4 {
    color: #93c5fd;
    margin: 8px 0 4px;
    font-size: 13px;
}

#nexus-chat-widget .nexus-msg-assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    width: 100%;
}

#nexus-chat-widget .nexus-msg-assistant th,
#nexus-chat-widget .nexus-msg-assistant td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    text-align: left;
}

#nexus-chat-widget .nexus-msg-assistant th {
    background: rgba(59, 130, 246, 0.1);
    color: #93c5fd;
}

/* ========== Mobile Responsive ========== */

@media (max-width: 768px) {
    #nexus-chat-widget .nexus-panel {
        height: 60vh;
    }

    #nexus-chat-widget .nexus-msg {
        max-width: 92%;
    }

    #nexus-chat-widget .nexus-bar {
        padding: 6px 10px;
    }

    #nexus-chat-widget .nexus-input {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

/* Hide on /chat page (full chat already there) */
body.page-chat #nexus-chat-widget {
    display: none !important;
}

/* Extra bottom padding so scrollable content clears both footer + nexus bar */
body.nexus-active {
    padding-bottom: 104px; /* 52px footer + 52px nexus bar */
}

body.nexus-active.nexus-panel-open {
    padding-bottom: 504px; /* 52px footer + 400px panel + 52px bar */
}

@media (max-width: 768px) {
    body.nexus-active.nexus-panel-open {
        padding-bottom: calc(60vh + 104px);
    }
}
