/* Apex Equity AI Chat Widget */
.apex-chat-bubble {
    position: fixed;
    bottom: 14px;
    right: 14px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0b1a3f 0%, #2c5aa0 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(11, 26, 63, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.apex-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(11, 26, 63, 0.45);
}

.apex-chat-bubble svg {
    width: 20px;
    height: 20px;
    transition: opacity 0.2s ease;
}

.apex-chat-bubble .chat-close-icon {
    display: none;
}

.apex-chat-bubble.open .chat-open-icon {
    display: none;
}

.apex-chat-bubble.open .chat-close-icon {
    display: block;
}

/* Unread badge */
.apex-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}

.apex-chat-badge.show {
    display: block;
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Chat Window — always a popup, never full-screen */
.apex-chat-window {
    position: fixed;
    bottom: 66px;
    right: 14px;
    width: min(320px, calc(100vw - 28px));
    max-height: min(400px, calc(100vh - 80px));
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 8px 40px rgba(11, 26, 63, 0.2);
    display: none;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    animation: chatSlideUp 0.3s ease;
}

.apex-chat-window.open {
    display: flex;
}

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

/* Header */
.apex-chat-header {
    background: linear-gradient(135deg, #0b1a3f 0%, #1e3a6f 100%);
    color: #fff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.apex-chat-avatar {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.apex-chat-avatar svg {
    width: 14px;
    height: 14px;
}

.apex-chat-header-info h4 {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'Playfair Display', serif;
}

.apex-chat-header-info p {
    margin: 1px 0 0;
    font-size: 0.65rem;
    opacity: 0.8;
}

/* Messages Area */
.apex-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 80px;
    background: #f8fafc;
}

.apex-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.apex-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(11, 26, 63, 0.15);
    border-radius: 10px;
}

/* Message Bubbles */
.apex-chat-msg {
    max-width: 85%;
    padding: 7px 10px;
    border-radius: 10px;
    font-size: 0.78rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.apex-chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #0b1a3f 0%, #2c5aa0 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.apex-chat-msg.assistant {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Typing indicator */
.apex-chat-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    border-bottom-left-radius: 4px;
    display: none;
}

.apex-chat-typing.show {
    display: flex;
    gap: 4px;
    align-items: center;
}

.apex-chat-typing span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.apex-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.apex-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* Input Area */
.apex-chat-input-area {
    padding: 8px 10px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 6px;
    align-items: flex-end;
    background: #fff;
    flex-shrink: 0;
}

.apex-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 16px; /* Prevents iOS zoom */
    font-family: 'Inter', sans-serif;
    resize: none;
    outline: none;
    max-height: 60px;
    min-height: 34px;
    line-height: 1.4;
    transition: border-color 0.2s ease;
}

.apex-chat-input:focus {
    border-color: #4a90e2;
}

.apex-chat-input::placeholder {
    color: #94a3b8;
}

.apex-chat-send {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #0b1a3f 0%, #2c5aa0 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s ease;
}

.apex-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.apex-chat-send:not(:disabled):hover {
    opacity: 0.9;
}

.apex-chat-send svg {
    width: 16px;
    height: 16px;
}

/* Welcome message */
.apex-chat-welcome {
    text-align: center;
    padding: 14px 12px;
    color: #64748b;
    font-size: 0.78rem;
    line-height: 1.5;
}

.apex-chat-welcome strong {
    color: #0b1a3f;
    display: block;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

/* Powered by */
.apex-chat-powered {
    text-align: center;
    padding: 4px;
    font-size: 0.6rem;
    color: #94a3b8;
    background: #fff;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
}
