/* AI Agent — Floating chat window, minimized icon, popup toasts */

:root {
    --ai-bg: #0e1422;
    --ai-bg-alt: #131a2c;
    --ai-border: #1f2a44;
    --ai-text: #d8e2f5;
    --ai-text-dim: #7a8aa8;
    --ai-accent: #5b8cff;
    --ai-accent-2: #8b5bff;
    --ai-success: #2ecc71;
    --ai-danger: #ff4d6d;
    --ai-warn: #f4b740;
    --ai-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
}

/* ============ MINIMIZED ICON (always-visible launcher) ============ */
.ai-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-2));
    box-shadow: var(--ai-shadow), 0 0 0 0 rgba(91, 140, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9998;
    transition: transform 0.15s ease, box-shadow 0.3s ease;
    user-select: none;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.5px;
}

.ai-launcher:hover {
    transform: scale(1.08);
}

.ai-launcher.pulse {
    animation: ai-pulse 1.6s ease-out infinite;
}

@keyframes ai-pulse {
    0%   { box-shadow: var(--ai-shadow), 0 0 0 0 rgba(91, 140, 255, 0.55); }
    70%  { box-shadow: var(--ai-shadow), 0 0 0 14px rgba(91, 140, 255, 0); }
    100% { box-shadow: var(--ai-shadow), 0 0 0 0 rgba(91, 140, 255, 0); }
}

.ai-launcher .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--ai-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.ai-launcher .badge.visible { display: flex; }

.ai-launcher.disabled {
    background: #2a3148;
    cursor: pointer;
    opacity: 0.7;
}

/* ============ CHAT WINDOW ============ */
.ai-chat-window {
    position: fixed;
    right: 22px;
    bottom: 88px;
    width: 380px;
    height: 520px;
    min-width: 320px;
    min-height: 360px;
    max-width: 90vw;
    max-height: 85vh;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    box-shadow: var(--ai-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    color: var(--ai-text);
    font-family: inherit;
}

.ai-chat-window.visible { display: flex; }

.ai-chat-header {
    background: linear-gradient(135deg, rgba(91,140,255,0.15), rgba(139,91,255,0.1));
    border-bottom: 1px solid var(--ai-border);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: move;
    user-select: none;
}

.ai-chat-header .ai-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
}
.ai-chat-header .title-block { flex: 1; line-height: 1.2; }
.ai-chat-header .title { font-size: 13px; font-weight: 600; color: var(--ai-text); }
.ai-chat-header .subtitle { font-size: 11px; color: var(--ai-text-dim); }

.ai-chat-header .actions { display: flex; gap: 4px; }
.ai-chat-header .actions button {
    background: transparent;
    border: 0;
    color: var(--ai-text-dim);
    cursor: pointer;
    font-size: 16px;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.ai-chat-header .actions button:hover { background: rgba(255,255,255,0.06); color: var(--ai-text); }

.ai-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    vertical-align: middle;
}
.ai-status-dot.on { background: var(--ai-success); }
.ai-status-dot.off { background: var(--ai-text-dim); }

.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #2a3148 transparent;
}
.ai-chat-body::-webkit-scrollbar { width: 6px; }
.ai-chat-body::-webkit-scrollbar-thumb { background: #2a3148; border-radius: 3px; }

.ai-msg {
    max-width: 85%;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.ai-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-2));
    color: #fff;
    border-bottom-right-radius: 3px;
}
.ai-msg.assistant {
    align-self: flex-start;
    background: var(--ai-bg-alt);
    border: 1px solid var(--ai-border);
    border-bottom-left-radius: 3px;
}
.ai-msg.system {
    align-self: center;
    background: rgba(244, 183, 64, 0.1);
    border: 1px solid rgba(244, 183, 64, 0.3);
    color: var(--ai-warn);
    font-size: 12px;
    text-align: center;
    max-width: 95%;
}
.ai-msg.insight {
    align-self: flex-start;
    background: var(--ai-bg-alt);
    border-left: 3px solid var(--ai-accent);
    width: 95%;
    max-width: 95%;
}
.ai-msg.insight .insight-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ai-msg.insight .verdict {
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 11px;
}
.ai-msg.insight .verdict.BULLISH { background: rgba(46,204,113,0.18); color: var(--ai-success); }
.ai-msg.insight .verdict.BEARISH { background: rgba(255,77,109,0.18); color: var(--ai-danger); }
.ai-msg.insight .verdict.NEUTRAL { background: rgba(122,138,168,0.18); color: var(--ai-text-dim); }
.ai-msg.insight .verdict.AVOID   { background: rgba(244,183,64,0.18); color: var(--ai-warn); }
.ai-msg.insight .insight-meta { color: var(--ai-text-dim); font-size: 11px; }
.ai-msg.insight .insight-headline { font-weight: 600; margin: 4px 0 6px; }
.ai-msg.insight .insight-section { margin-top: 6px; font-size: 12px; }
.ai-msg.insight .insight-section strong { color: var(--ai-accent); }

.ai-typing {
    display: inline-flex;
    gap: 3px;
    padding: 9px 12px;
    background: var(--ai-bg-alt);
    border: 1px solid var(--ai-border);
    border-radius: 10px;
    align-self: flex-start;
}
.ai-typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--ai-text-dim);
    animation: ai-typing 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.ai-chat-footer {
    border-top: 1px solid var(--ai-border);
    padding: 10px;
    display: flex;
    gap: 8px;
}
.ai-chat-footer textarea {
    flex: 1;
    background: var(--ai-bg-alt);
    border: 1px solid var(--ai-border);
    color: var(--ai-text);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    resize: none;
    height: 38px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.ai-chat-footer textarea:focus { border-color: var(--ai-accent); }
.ai-chat-footer button {
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-2));
    border: 0;
    color: #fff;
    width: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.1s, opacity 0.15s;
}
.ai-chat-footer button:hover { transform: scale(1.04); }
.ai-chat-footer button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.ai-chat-resizer {
    position: absolute;
    width: 14px; height: 14px;
    left: 0; bottom: 0;
    cursor: nwse-resize;
    background:
        linear-gradient(135deg, transparent 50%, var(--ai-text-dim) 50%);
    opacity: 0.5;
    border-bottom-left-radius: 12px;
}

/* ============ TOAST POPUPS ============ */
.ai-toast-stack {
    position: fixed;
    top: 64px;
    right: 22px;
    width: 340px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.ai-toast {
    pointer-events: auto;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-left: 4px solid var(--ai-accent);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: var(--ai-shadow);
    color: var(--ai-text);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    cursor: pointer;
}
.ai-toast.in { transform: translateX(0); opacity: 1; }
.ai-toast.BULLISH { border-left-color: var(--ai-success); }
.ai-toast.BEARISH { border-left-color: var(--ai-danger); }
.ai-toast.AVOID   { border-left-color: var(--ai-warn); }

.ai-toast .toast-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--ai-text-dim);
    margin-bottom: 4px;
}
.ai-toast .toast-head .v {
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(91,140,255,0.18);
    color: var(--ai-accent);
}
.ai-toast.BULLISH .toast-head .v { background: rgba(46,204,113,0.18); color: var(--ai-success); }
.ai-toast.BEARISH .toast-head .v { background: rgba(255,77,109,0.18); color: var(--ai-danger); }
.ai-toast.AVOID   .toast-head .v { background: rgba(244,183,64,0.18); color: var(--ai-warn); }

.ai-toast .toast-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}
.ai-toast .toast-body {
    font-size: 12px;
    color: var(--ai-text-dim);
    line-height: 1.4;
    margin-bottom: 6px;
}
.ai-toast .toast-cta {
    font-size: 11px;
    color: var(--ai-accent);
    font-weight: 600;
}

@media (max-width: 600px) {
    .ai-chat-window { right: 12px; left: 12px; width: auto; bottom: 80px; }
    .ai-toast-stack { right: 12px; left: 12px; width: auto; }
    .ai-launcher { right: 14px; bottom: 14px; }
}
