/* =========================================================================
 * MasterTrader AI Assistant — Standalone Stylesheet
 * ========================================================================= */

/* Floating Launcher Container & Trigger Button */
#ai-floating-container {
    position: fixed;
    z-index: 999;
    user-select: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* --- 1. Logged-in Mode (Keep original circular look exactly as before) --- */
#ai-floating-container.is-user-mode {
    bottom: 85px;
    right: 18px;
}

#ai-floating-container.is-user-mode #ai-guest-popup-bubble {
    display: none !important;
}

#ai-floating-trigger {
    overflow: visible !important;
}

#ai-floating-trigger.is-user-circle {
    position: relative;
    overflow: visible !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: transparent;
    border: none;
    box-shadow: rgb(236, 167, 16) 0px 4px 15px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Close / Remove badge for logged-in user (Hides icon for 5 minutes) */
.ai-user-trigger-close {
    display: none;
    position: absolute;
    top: -5px;
    right: -5px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: #000000;
    border: 1.5px solid #ffffff;
    color: #ffffff;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    padding: 0;
    margin: 0;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#ai-floating-trigger.is-user-circle .ai-user-trigger-close {
    display: flex !important;
}

#ai-floating-trigger.is-guest-pill .ai-user-trigger-close {
    display: none !important;
}

.ai-user-trigger-close:hover {
    background: #dc2626;
    border-color: #ffffff;
    color: #ffffff;
    transform: scale(1.18);
    box-shadow: 0 3px 8px rgba(239, 68, 68, 0.6);
}

.ai-user-trigger-close:active {
    transform: scale(0.92);
}

.ai-user-trigger-close svg {
    display: block;
    pointer-events: none;
}

#ai-floating-trigger.is-user-circle:hover {
    transform: scale(1.08);
}

#ai-floating-trigger.is-user-circle .ai-trigger-icon-wrap {
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
}

#ai-floating-trigger.is-user-circle .ai-trigger-icon {
    width: 35px;
    height: 35px;
    display: block;
    border-radius: 50%;
}

#ai-floating-trigger.is-user-circle .ai-trigger-label,
#ai-floating-trigger.is-user-circle .ai-trigger-online-dot {
    display: none !important;
}

/* --- 2. Guest Mode (Login Page: "Let's Talk" Pill Button & AI Popup Bubble) --- */
#ai-floating-container.is-guest-mode {
    bottom: 85px;
    right: 18px;
}

/* "Let's Talk" Pill Button */
#ai-floating-trigger.is-guest-pill {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 6px 7px;
    height: 42px;
    border-radius: 24px;
    background: linear-gradient(135deg, #1d2530 0%, #10151c 100%);
    border: 1.5px solid #eca710;
    box-shadow: 0 4px 18px rgba(236, 167, 16, 0.45), 0 2px 6px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    color: #ffffff;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    text-decoration: none;
}

#ai-floating-trigger.is-guest-pill:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 24px rgba(236, 167, 16, 0.65), 0 2px 8px rgba(0, 0, 0, 0.5);
    border-color: #ffd54f;
}

#ai-floating-trigger.is-guest-pill .ai-trigger-icon-wrap {
    position: relative;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-floating-trigger.is-guest-pill .ai-trigger-icon {
    width: 28px;
    height: 28px;
    display: block;
}

#ai-floating-trigger.is-guest-pill .ai-trigger-online-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00e676;
    border: 1.5px solid #1d2530;
    box-shadow: 0 0 6px #00e676;
    display: block !important;
}

#ai-floating-trigger.is-guest-pill .ai-trigger-label {
    display: inline-block !important;
    color: #ffffff;
    font-size: 13.5px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* AI Guest Popup Bubble (Speech Bubble positioned right above the button) */
#ai-guest-popup-bubble {
    position: relative;
    margin-bottom: 12px;
    min-width: 180px;
    max-width: 225px;
    background: linear-gradient(135deg, rgba(28, 35, 45, 0.96), rgba(16, 22, 29, 0.98));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1.5px solid rgba(236, 167, 16, 0.45);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 16px rgba(236, 167, 16, 0.2);
    padding: 9px 12px;
    color: #ffffff;
    cursor: pointer;
    animation: aiPopupFloat 3.5s ease-in-out infinite;
    transform-origin: bottom right;
}

@keyframes aiPopupFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

.ai-popup-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-popup-badge-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-popup-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #00e676;
}

.ai-pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #00e676;
    box-shadow: 0 0 6px #00e676;
    animation: aiDotPulse 1.5s infinite;
}

@keyframes aiDotPulse {
    0% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.2); }
    100% { opacity: 0.4; transform: scale(0.9); }
}

.ai-popup-close-btn {
    background: transparent;
    border: none;
    color: #8899a6;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    margin: -2px -2px 0 0;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.ai-popup-close-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.ai-popup-body {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 1px;
}

.ai-popup-wave {
    font-size: 16px;
    animation: aiWaveHand 2.2s infinite;
    transform-origin: 70% 70%;
    display: inline-block;
}

@keyframes aiWaveHand {
    0% { transform: rotate(0deg); }
    10% { transform: rotate(14deg); }
    20% { transform: rotate(-8deg); }
    30% { transform: rotate(14deg); }
    40% { transform: rotate(-4deg); }
    50% { transform: rotate(10deg); }
    60% { transform: rotate(0deg); }
    100% { transform: rotate(0deg); }
}

.ai-popup-msg {
    font-size: 12px;
    font-weight: 500;
    color: #e1e7ec;
    line-height: 1.35;
}

.ai-popup-msg strong {
    color: #eca710;
    font-weight: 700;
}

/* Downward speech bubble pointer arrow pointing to the button */
.ai-popup-arrow {
    position: absolute;
    bottom: -6px;
    right: 24px;
    width: 10px;
    height: 10px;
    background: #11161d;
    border-right: 1.5px solid rgba(236, 167, 16, 0.45);
    border-bottom: 1.5px solid rgba(236, 167, 16, 0.45);
    transform: rotate(45deg);
}

/* AI Chat Pane Container */
#as-ai-pane {
    position: relative;
    width: 100%;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Header Area */
.ai-header-container {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background: #1e222d;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
    z-index: 100;
}
.ai-header-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-status-badge {
    font-size: 11px;
    background: rgba(0, 230, 118, 0.15);
    color: #00e676;
    padding: 3px 9px;
    border-radius: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Quick Suggestion Chips */
#ai-quick-suggestions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 15px 15px 5px 15px;
    -webkit-overflow-scrolling: touch;
}
#ai-quick-suggestions::-webkit-scrollbar {
    display: none;
}
.ai-chip {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #a0aec0;
    border-radius: 16px;
    padding: 14px 14px;
    font-size: 12px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 0px;
}
.ai-chip:hover {
    background: rgba(0, 230, 118, 0.12);
    border-color: #00e676;
    color: #00e676;
}

/* Chat Messages Thread */
#ai-chat-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    box-sizing: border-box;
}

/* Chat Bubbles */
.chat-bubble {
    max-width: 85%;
    padding: 12px 14px;
    border-radius: 12px;
    word-break: break-word;
    line-height: 1.5;
    font-size: 13.5px;
    animation: fadeInBubble 0.25s ease forwards;
}

@keyframes fadeInBubble {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* User Message Bubble */
.chat-bubble-user {
    align-self: flex-end;
    background: #1565c0;
    color: #ffffff;
    border-bottom-right-radius: 2px;
}
.chat-bubble-user .chat-bubble-meta {
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

/* AI Message Bubble */
.chat-bubble-admin {
    align-self: flex-start;
    background: #252a37;
    color: #e2e8f0;
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.chat-bubble-admin .chat-bubble-meta {
    text-align: left;
    color: #00e676;
    font-weight: 600;
}

.chat-bubble-meta {
    font-size: 11px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.chat-bubble-sender {
    font-weight: 600;
}
.chat-bubble-time {
    font-size: 10px;
    opacity: 0.8;
}

/* Fixed Bottom Chat Input Bar */
#ai-chat-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: #1e222d;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    box-sizing: border-box;
    z-index: 99;
}

/* Attachment Preview Strip above input */
.ai-file-preview-strip {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    overflow-x: auto;
    padding: 2px 0;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}
.ai-file-preview-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #131722;
    border: 1px solid rgba(0, 230, 118, 0.35);
    border-radius: 12px;
    padding: 4px 10px 4px 6px;
    max-width: 260px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}
.ai-preview-media {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    overflow: hidden;
    background: #202634;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ai-preview-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ai-preview-meta {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.ai-preview-name {
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}
.ai-preview-size {
    font-size: 10px;
    color: #8fa0b5;
}
.ai-preview-close {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #ffffff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 4px;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.15s;
}
.ai-preview-close:hover {
    background: #ff5252;
}

.st-ticket-chat-reply-row {
    display: flex;
    gap: 8px;
    align-items: center;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}
.st-ticket-chat-attach-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #8fa0b5;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
}
.st-ticket-chat-attach-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}
.st-ticket-chat-attach-btn.has-file {
    color: #00e676;
    background: rgba(0, 230, 118, 0.15);
    border-color: rgba(0, 230, 118, 0.5);
}
.st-ticket-chat-input {
    flex: 1 1 0%;
    min-width: 0;
    width: 0;
    background: #131722;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    color: #ffffff;
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    box-sizing: border-box;
}
.st-ticket-chat-input:focus {
    border-color: #00e676;
}
.st-ticket-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #00e676;
    color: #121212;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
    box-sizing: border-box;
}
.st-ticket-chat-send-btn:hover {
    background: #00c853;
}
.st-ticket-chat-send-btn:active {
    transform: scale(0.95);
}

/* Clearance Spacer for Bottom Bar */
.st-chat-bottom-spacer {
    height: 75px;
    width: 100%;
}

/* Thinking Indicator Spin Animation */
@keyframes spin {
    100% { transform: rotate(360deg); }
}
.ai-spin {
    animation: spin 1s infinite linear;
    display: inline-block;
    vertical-align: middle;
}
