/* ==========================================================================
   ME-Bot Chat Widget
   Floating AI assistant chat panel, theme-aware, responsive.
   Class prefix: .me-bot- to avoid conflicts.
   ========================================================================== */

/* ── Floating Action Button ─────────────────────────────────── */
.me-bot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--brand-primary, #f59e0b);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), 0 0 0 0 var(--brand-primary, #f59e0b);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    line-height: 1;
}
.me-bot-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 0 0 4px rgba(245, 158, 11, 0.2);
}
.me-bot-fab:active {
    transform: scale(0.95);
}
.me-bot-fab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}
.me-bot-fab-icon svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}

/* Pulse animation when panel is closed */
.me-bot-fab.me-bot-has-unread {
    animation: me-bot-pulse 2s ease-in-out infinite;
}
@keyframes me-bot-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), 0 0 0 0 var(--brand-primary, #f59e0b); }
    50% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), 0 0 0 8px rgba(245, 158, 11, 0.15); }
}

/* Hide FAB when panel is open */
.me-bot-fab.me-bot-hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* ── Chat Panel ─────────────────────────────────────────────── */
.me-bot-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 10001;
    width: 380px;
    height: 520px;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius, 12px);
    border: 1px solid var(--border, #2a2a3e);
    background: var(--bg-card, rgba(26, 26, 46, 0.92));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.05);
    overflow: hidden;
    /* Closed state */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.me-bot-panel.me-bot-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Panel Header ───────────────────────────────────────────── */
.me-bot-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary, rgba(20, 20, 40, 0.95));
    border-bottom: 1px solid var(--border, #2a2a3e);
    flex-shrink: 0;
}
.me-bot-header-icon {
    font-size: 1.25rem;
    line-height: 1;
    display: flex;
    align-items: center;
}
.me-bot-header-text {
    flex: 1;
    min-width: 0;
}
.me-bot-header-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary, #e0e0f0);
    line-height: 1.2;
}
.me-bot-header-subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary, #a0a0b0);
    line-height: 1.2;
}
.me-bot-close {
    background: none;
    border: none;
    color: var(--text-secondary, #a0a0b0);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm, 6px);
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.me-bot-close:hover {
    color: var(--text-primary, #e0e0f0);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Message Area ───────────────────────────────────────────── */
.me-bot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--border, #2a2a3e) transparent;
}
.me-bot-messages::-webkit-scrollbar {
    width: 5px;
}
.me-bot-messages::-webkit-scrollbar-track {
    background: transparent;
}
.me-bot-messages::-webkit-scrollbar-thumb {
    background: var(--border, #2a2a3e);
    border-radius: 4px;
}

/* ── Messages ───────────────────────────────────────────────── */
.me-bot-msg {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.me-bot-msg-user {
    align-self: flex-end;
}
.me-bot-msg-bot {
    align-self: flex-start;
}

.me-bot-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius, 12px);
    font-size: 0.85rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.me-bot-msg-user .me-bot-msg-bubble {
    background: var(--brand-primary, #f59e0b);
    color: #000;
    border-bottom-right-radius: var(--radius-sm, 4px);
}
.me-bot-msg-bot .me-bot-msg-bubble {
    background: var(--bg-card, rgba(26, 26, 46, 0.8));
    border: 1px solid var(--border, #2a2a3e);
    color: var(--text-primary, #e0e0f0);
    border-bottom-left-radius: var(--radius-sm, 4px);
}

/* Inline markdown styles */
.me-bot-msg-bubble strong {
    font-weight: 700;
    color: var(--text-primary, #e0e0f0);
}
.me-bot-msg-bubble code {
    background: rgba(0, 0, 0, 0.25);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8em;
}
.me-bot-msg-bubble a {
    color: var(--brand-primary, #f59e0b);
    text-decoration: underline;
}
.me-bot-msg-bubble ul {
    margin: 6px 0 2px 0;
    padding-left: 18px;
}
.me-bot-msg-bubble li {
    margin-bottom: 2px;
}

/* ── Source Links ────────────────────────────────────────────── */
.me-bot-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 0 2px;
}
.me-bot-source-link {
    font-size: 0.7rem;
    color: var(--brand-primary, #f59e0b);
    text-decoration: none;
    opacity: 0.85;
    transition: opacity 0.15s;
}
.me-bot-source-link:hover {
    opacity: 1;
    text-decoration: underline;
}
.me-bot-source-link::before {
    content: '📄 ';
    font-size: 0.65rem;
}

/* ── Feedback Buttons ───────────────────────────────────────── */
.me-bot-feedback {
    display: flex;
    gap: 4px;
    padding: 0 2px;
}
.me-bot-feedback-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--text-secondary, #a0a0b0);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm, 6px);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    line-height: 1;
}
.me-bot-feedback-btn:hover {
    color: var(--text-primary, #e0e0f0);
    border-color: var(--border, #2a2a3e);
    background: rgba(255, 255, 255, 0.04);
}
.me-bot-feedback-btn.me-bot-feedback-active {
    color: var(--brand-primary, #f59e0b);
    border-color: var(--brand-primary, #f59e0b);
    background: rgba(245, 158, 11, 0.1);
}

/* ── Sticky Suggestions Bar ─────────────────────────────────── */
.me-bot-suggestions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    border-top: 1px solid var(--border, #2a2a3e);
    background: var(--bg-card, rgba(26, 26, 46, 0.9));
    flex-shrink: 0;
}
.me-bot-suggestions-bar:empty {
    display: none;
}
.me-bot-suggestions-bar .me-bot-suggestion {
    font-size: 0.72rem;
    padding: 5px 10px;
}

/* ── Suggested Questions ────────────────────────────────────── */
.me-bot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}
.me-bot-suggestion {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border, #2a2a3e);
    color: var(--text-primary, #e0e0f0);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    line-height: 1.3;
}
.me-bot-suggestion:hover {
    background: rgba(245, 158, 11, 0.12);
    border-color: var(--brand-primary, #f59e0b);
    transform: translateY(-1px);
}
.me-bot-suggestion:active {
    transform: translateY(0);
}

/* ── Typing Indicator ───────────────────────────────────────── */
.me-bot-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: var(--bg-card, rgba(26, 26, 46, 0.8));
    border: 1px solid var(--border, #2a2a3e);
    border-radius: var(--radius, 12px);
    border-bottom-left-radius: var(--radius-sm, 4px);
}
.me-bot-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary, #a0a0b0);
    animation: me-bot-typing-bounce 1.4s ease-in-out infinite;
}
.me-bot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}
.me-bot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}
@keyframes me-bot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Welcome Message ────────────────────────────────────────── */
.me-bot-welcome {
    text-align: center;
    padding: 16px 8px 8px;
    color: var(--text-secondary, #a0a0b0);
    font-size: 0.82rem;
    line-height: 1.5;
}
.me-bot-welcome-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 8px;
}

/* ── Login Prompt ───────────────────────────────────────────── */
.me-bot-login-prompt {
    text-align: center;
    padding: 32px 24px;
    color: var(--text-secondary, #a0a0b0);
    font-size: 0.85rem;
    line-height: 1.5;
}
.me-bot-login-prompt a {
    color: var(--brand-primary, #f59e0b);
    font-weight: 600;
    text-decoration: underline;
}

/* ── Input Area ─────────────────────────────────────────────── */
.me-bot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border, #2a2a3e);
    background: var(--bg-secondary, rgba(20, 20, 40, 0.95));
    flex-shrink: 0;
}
.me-bot-input {
    flex: 1;
    min-height: 38px;
    max-height: 100px;
    padding: 8px 12px;
    border: 1px solid var(--border, #2a2a3e);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-input, rgba(0, 0, 0, 0.2));
    color: var(--text-primary, #e0e0f0);
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
    overflow-y: auto;
}
.me-bot-input::placeholder {
    color: var(--text-secondary, #a0a0b0);
    opacity: 0.6;
}
.me-bot-input:focus {
    border-color: var(--brand-primary, #f59e0b);
}
.me-bot-send {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm, 6px);
    border: none;
    background: var(--brand-primary, #f59e0b);
    color: #000;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}
.me-bot-send:hover {
    opacity: 0.9;
}
.me-bot-send:active {
    transform: scale(0.93);
}
.me-bot-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Error State ────────────────────────────────────────────── */
.me-bot-error {
    padding: 8px 14px;
    background: rgba(255, 60, 60, 0.1);
    border: 1px solid rgba(255, 60, 60, 0.25);
    border-radius: var(--radius-sm, 6px);
    color: #ff6b6b;
    font-size: 0.78rem;
    align-self: center;
    text-align: center;
}

/* ── Mobile Responsive ──────────────────────────────────────── */
@media (max-width: 767px) {
    .me-bot-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        border: none;
        transform: translateY(100%);
        opacity: 1;
    }
    .me-bot-panel.me-bot-open {
        transform: translateY(0);
    }
    .me-bot-fab {
        bottom: 16px;
        right: 16px;
    }
}
