/* =============================================
   AI Chatbot Widget — Redesigned v2
   Glassmorphism + gradient + micro-interactions
   Minegens theme override
   ============================================= */

.ai-chatbot-root {
    /* Minegens theme */
    --chatbot-primary:     #5865F2;
    --chatbot-primary-rgb: 88, 101, 242;
    --chatbot-accent:      #3BA55D;
    --chatbot-bg:          rgba(15, 15, 15, 0.92);
    --chatbot-header-bg:   rgba(26, 26, 26, 0.95);
    --chatbot-border:      rgba(255, 88, 45, 0.15);
    --chatbot-bot-bg:      rgba(36, 36, 36, 0.85);
    --chatbot-bot-text:    #e5e7eb;
    --chatbot-user-bg:     var(--chatbot-primary);
    --chatbot-user-text:   #fff;
    --chatbot-input-bg:    rgba(15, 15, 15, 0.7);
    --chatbot-text:        #f8fafc;
    --chatbot-muted:       #94a3b8;
    --chatbot-shadow:      0 24px 80px rgba(0,0,0,0.5);

    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1080;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: bottom 0.76s ease;
}

/* Shifted up when js-go-to button is visible, to avoid overlap */
.ai-chatbot-root--shifted-up {
    bottom: 5.5rem;
}

/* ─── Toggle Button ─── */
.ai-chatbot-toggle {
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--chatbot-primary), color-mix(in srgb, var(--chatbot-primary) 70%, #000));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    position: relative;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease;
}
.ai-chatbot-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}
.ai-chatbot-toggle:active { transform: scale(0.96); }
.ai-chatbot-toggle i { font-size: 1.5rem; position: relative; z-index: 1; }

/* Pulsing ring */
.ai-chatbot-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    opacity: 0;
    animation: chatbotPulse 3s ease-in-out infinite;
    z-index: -1;
}
@keyframes chatbotPulse {
    0%, 100% { opacity: 0; transform: scale(1); }
    50% { opacity: 0.25; transform: scale(1.08); }
}
/* Pulse stops when panel is open */
.ai-chatbot-root.is-open .ai-chatbot-toggle::before { animation: none; opacity: 0; }

.ai-chatbot-root.is-open .ai-chatbot-toggle i::before { content: "\f00d"; }

/* ─── Panel ─── */
.ai-chatbot-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 12px);
    width: min(400px, calc(100vw - 2.5rem));
    height: min(600px, calc(100vh - 8rem));
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--chatbot-border);
    border-radius: 16px;
    background: var(--chatbot-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--chatbot-text);
    box-shadow: var(--chatbot-shadow);
    animation: chatbotPanelIn 0.3s cubic-bezier(.16,1,.3,1);
}
@keyframes chatbotPanelIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-chatbot-root.is-open .ai-chatbot-panel { display: flex; }

/* Gradient border overlay */
.ai-chatbot-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    padding: 1.5px;
    background: linear-gradient(135deg, 
        var(--chatbot-primary) 0%, 
        transparent 40%, 
        transparent 60%, 
        var(--chatbot-accent) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 1;
}

/* ─── Header ─── */
.ai-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    background: var(--chatbot-header-bg);
    border-bottom: 1px solid var(--chatbot-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    flex-shrink: 0;
}
.ai-chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.ai-chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--chatbot-primary), color-mix(in srgb, var(--chatbot-primary) 60%, #000));
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}
.ai-chatbot-info { min-width: 0; }
.ai-chatbot-name {
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.ai-chatbot-status {
    font-size: 0.72rem;
    color: var(--chatbot-accent);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.05rem;
}
.ai-chatbot-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chatbot-accent);
    animation: chatbotStatusPulse 2s ease-in-out infinite;
}
@keyframes chatbotStatusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.ai-chatbot-close {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    color: var(--chatbot-muted);
    background: rgba(255,255,255,0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.ai-chatbot-close:hover {
    background: rgba(255,255,255,0.12);
    color: var(--chatbot-text);
}

/* ─── Messages ─── */
.ai-chatbot-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.1rem;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}
.ai-chatbot-messages::-webkit-scrollbar { width: 4px; }
.ai-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chatbot-messages::-webkit-scrollbar-thumb { 
    background: rgba(255,255,255,0.1); 
    border-radius: 2px;
}
.ai-chatbot-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Message wrapper (avatar + bubble row) */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    max-width: 92%;
    animation: msgIn 0.2s ease-out;
    will-change: transform, opacity;
    backface-visibility: hidden;
}
.msg-row.bot { align-self: flex-start; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }

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

/* Bot avatar in message row */
.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, 
        color-mix(in srgb, var(--chatbot-primary) 60%, transparent), 
        color-mix(in srgb, var(--chatbot-primary) 30%, transparent));
    color: var(--chatbot-primary);
    font-size: 0.75rem;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.08);
}
.msg-row.user .msg-avatar { display: none; }

/* Bubble */
.ai-chatbot-message {
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    font-size: 0.91rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    position: relative;
}
.msg-row.bot .ai-chatbot-message {
    background: var(--chatbot-bot-bg);
    color: var(--chatbot-bot-text);
    border-bottom-left-radius: 4px;
}
.msg-row.user .ai-chatbot-message {
    background: var(--chatbot-user-bg);
    color: var(--chatbot-user-text);
    border-bottom-right-radius: 4px;
}

/* Text formatting */
.ai-chatbot-message b { font-weight: 700; }
.ai-chatbot-message u { text-decoration: underline; text-underline-offset: 2px; }
.ai-chatbot-message i { font-style: italic; }
.ai-chatbot-message a { 
    color: var(--chatbot-accent, #4a9eff); 
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.2s;
}
.ai-chatbot-message a:hover { opacity: 0.8; }

/* Link rendered as button (chatbot-link-btn class) — uniform, clickable,
   styled with the chatbot accent color. Applied to both bare URLs and
   markdown [text](url) links via formatText(). */
.ai-chatbot-message a.chatbot-link-btn {
    display: inline-block;
    padding: 0.35rem 0.8rem;
    margin: 0.15rem 0.1rem;
    border-radius: 8px;
    background: var(--chatbot-accent, #4a9eff);
    color: #fff !important;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.4;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}
.ai-chatbot-message a.chatbot-link-btn:hover {
    opacity: 0.88;
    text-decoration: none;
    transform: translateY(-1px);
}
.ai-chatbot-message a.chatbot-link-btn:active { transform: translateY(0); }

.ai-chatbot-message br + br { margin-top: 0.3rem; display: block; content: ''; }

/* Tables */
.ai-chatbot-message table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.4rem 0;
    font-size: 0.85rem;
}
.ai-chatbot-message th,
.ai-chatbot-message td {
    border: 1px solid var(--chatbot-border, rgba(255,255,255,0.12));
    padding: 0.35rem 0.6rem;
    text-align: left;
}
.ai-chatbot-message th {
    background: rgba(255,255,255,0.06);
    font-weight: 600;
}
.ai-chatbot-message td {
    background: rgba(255,255,255,0.02);
}

/* Timestamp */
.msg-time {
    font-size: 0.65rem;
    color: var(--chatbot-muted);
    padding: 0 0.25rem;
    opacity: 0.6;
    margin-top: 0.15rem;
}
.msg-row.user .msg-time { text-align: right; }

/* Typing indicator */
.msg-row.bot.typing .ai-chatbot-message {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    min-height: 44px;
}
.typing-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chatbot-muted);
    animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input ─── */
.ai-chatbot-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    background: var(--chatbot-header-bg);
    border-top: 1px solid var(--chatbot-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    flex-shrink: 0;
}
.ai-chatbot-input {
    flex: 1;
    min-width: 0;
    height: 44px;
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    padding: 0 0.9rem;
    background: var(--chatbot-input-bg);
    color: var(--chatbot-text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}
.ai-chatbot-input:focus {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(var(--chatbot-primary-rgb, 55, 125, 255), 0.15);
}
.ai-chatbot-input::placeholder { color: var(--chatbot-muted); opacity: 0.5; }
.ai-chatbot-input:disabled { opacity: 0.4; }

.ai-chatbot-send {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--chatbot-primary), color-mix(in srgb, var(--chatbot-primary) 70%, #000));
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), opacity 0.2s;
    flex-shrink: 0;
}
.ai-chatbot-send:hover:not(:disabled) { transform: scale(1.06); }
.ai-chatbot-send:active:not(:disabled) { transform: scale(0.94); }
.ai-chatbot-send:disabled { opacity: 0.35; cursor: default; }
.ai-chatbot-send i { font-size: 1.1rem; }

/* ─── Escalation Button ─── */
.ai-chatbot-escalation {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--chatbot-border);
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    color: var(--chatbot-muted);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    margin-right: 0.5rem;
}
.ai-chatbot-escalation:hover {
    background: rgba(255,255,255,0.1);
    color: var(--chatbot-text);
    border-color: rgba(255,255,255,0.2);
}

/* ─── Refresh/logout button inside chat bubble ─── */
.btn-refresh {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--chatbot-accent, #4a9eff);
    background: transparent;
    color: var(--chatbot-accent, #4a9eff);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    transition: all 0.15s ease;
}
.btn-refresh:hover {
    background: var(--chatbot-accent, #4a9eff);
    color: #fff;
}

/* ─── Mobile ─── */
@media (max-width: 575.98px) {
    .ai-chatbot-root { right: 0.75rem; bottom: 0.75rem; }
    .ai-chatbot-toggle { width: 52px; height: 52px; }
    .ai-chatbot-toggle i { font-size: 1.3rem; }
    .ai-chatbot-panel {
        bottom: calc(100% + 10px);
        width: calc(100vw - 1.5rem);
        height: min(560px, calc(100vh - 6rem));
    }
}
