/* Montana Mike Chatbot - Modern Chat Widget (Co-Pilot Inspired) */

/* CSS Custom Properties (populated by JS from Appearance settings) */
:root {
    --mm-header-bg: #1a1a2e;
    --mm-header-text: #ffffff;
    --mm-user-bubble: #4a6cf7;
    --mm-user-text: #ffffff;
    --mm-bot-bubble: #f0f0f5;
    --mm-bot-text: #1d1d1d;
    --mm-bg: #ffffff;
    --mm-input-bg: #f8f9fa;
    --mm-input-border: #e0e0e0;
    --mm-send-btn: #4a6cf7;
    --mm-primary: #4a6cf7;
    --mm-radius: 16px;
    --mm-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Floating Widget Container ───────────────────────── */

.mm-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--mm-font);
    font-size: 14px;
    line-height: 1.5;
}

.mm-chat-widget.mm-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.mm-chat-widget.mm-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* ── Toggle Button ───────────────────────────────────── */

.mm-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(74, 108, 247, 0.4);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    animation: mmPulse 3s infinite;
}

.mm-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
    animation: none;
}

.mm-chat-toggle.mm-hidden {
    display: none;
}

@keyframes mmPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(74, 108, 247, 0.3); }
    50% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(74, 108, 247, 0); }
}

/* ── Chat Window ─────────────────────────────────────── */

.mm-chat-window {
    display: none;
    position: absolute;
    bottom: 70px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 120px);
    border-radius: var(--mm-radius);
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    background: var(--mm-bg);
    flex-direction: column;
    transition: opacity 0.25s, transform 0.25s;
}

.mm-position-bottom-right .mm-chat-window {
    right: 0;
}

.mm-position-bottom-left .mm-chat-window {
    left: 0;
}

.mm-chat-window.mm-open {
    display: flex;
    animation: mmSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* ── Header ──────────────────────────────────────────── */

.mm-chat-header {
    padding: 16px 20px;
    background: var(--mm-header-bg);
    color: var(--mm-header-text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    position: relative;
}

.mm-chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

.mm-chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mm-chat-header-info strong {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.mm-chat-status {
    font-size: 11px;
    opacity: 0.75;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mm-chat-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
}

.mm-chat-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--mm-header-text);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s, background 0.2s;
}

.mm-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* ── Persona Selector (Round Profile Pictures) ─────── */

.mm-persona-selector {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    background: var(--mm-bg);
    border-bottom: 1px solid var(--mm-input-border);
    flex-shrink: 0;
    justify-content: center;
}

.mm-persona-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: #888;
    transition: all 0.25s;
    border-radius: 12px;
    min-width: 72px;
}

.mm-persona-btn:hover {
    background: rgba(74, 108, 247, 0.06);
    color: #555;
}

.mm-persona-btn.mm-active {
    color: var(--mm-primary);
    background: rgba(74, 108, 247, 0.08);
    font-weight: 600;
}

.mm-persona-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
    border: 3px solid transparent;
    transition: border-color 0.25s, transform 0.25s;
}

.mm-persona-btn:hover .mm-persona-avatar {
    transform: scale(1.05);
}

.mm-persona-btn.mm-active .mm-persona-avatar {
    border-color: var(--mm-primary);
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.25);
}

.mm-persona-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mm-persona-name {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

/* ── Messages ────────────────────────────────────────── */

.mm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--mm-bg);
}

.mm-message {
    display: flex;
    max-width: 85%;
    animation: mmMsgIn 0.3s ease-out;
}

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

.mm-message-bot {
    align-self: flex-start;
}

.mm-message-user {
    align-self: flex-end;
}

.mm-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.5;
}

.mm-message-bot .mm-message-content {
    background: var(--mm-bot-bubble);
    color: var(--mm-bot-text);
    border-bottom-left-radius: 4px;
}

.mm-message-user .mm-message-content {
    background: var(--mm-user-bubble);
    color: var(--mm-user-text);
    border-bottom-right-radius: 4px;
}

/* ── Typing Indicator ────────────────────────────────── */

.mm-typing {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--mm-bot-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: mmMsgIn 0.3s ease-out;
}

.mm-typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: mmTyping 1.4s infinite;
}

.mm-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.mm-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes mmTyping {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ── Input Area ──────────────────────────────────────── */

.mm-chat-input-area {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--mm-input-border);
    background: var(--mm-bg);
    flex-shrink: 0;
    align-items: flex-end;
}

.mm-chat-input {
    flex: 1;
    border: 1.5px solid var(--mm-input-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    line-height: 1.4;
    background: var(--mm-input-bg);
    color: #1d1d1d;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.mm-chat-input:focus {
    border-color: var(--mm-primary);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.12);
}

.mm-chat-input::placeholder {
    color: #aaa;
}

.mm-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--mm-send-btn);
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

.mm-chat-send:hover {
    transform: scale(1.05);
}

.mm-chat-send:active {
    transform: scale(0.95);
}

.mm-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ── Mobile Responsive ───────────────────────────────── */

@media (max-width: 480px) {
    .mm-chat-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        bottom: 70px;
        border-radius: 16px;
    }

    .mm-chat-widget.mm-position-bottom-right,
    .mm-chat-widget.mm-position-bottom-left {
        bottom: 10px;
        right: 8px;
        left: auto;
    }

    .mm-position-bottom-left .mm-chat-window,
    .mm-position-bottom-right .mm-chat-window {
        right: -8px;
    }

    .mm-persona-selector {
        gap: 8px;
        padding: 12px 10px;
    }

    .mm-persona-avatar {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }

    .mm-persona-btn {
        min-width: 60px;
        padding: 6px 8px;
    }
}

/* ── Inline Mode (Shortcode / Preview) ───────────────── */

.mm-chat-inline {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid var(--mm-input-border);
    border-radius: var(--mm-radius);
    overflow: hidden;
    background: var(--mm-bg);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    font-family: var(--mm-font);
    font-size: 14px;
    line-height: 1.5;
}

.mm-chat-inline .mm-chat-messages {
    flex: 1;
    overflow-y: auto;
}

/* ── Scrollbar ───────────────────────────────────────── */

.mm-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.mm-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mm-chat-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 10px;
}

.mm-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ── TTS Controls ───────────────────────────────────── */

.mm-tts-toggle-wrap {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.mm-tts-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 1.5px solid var(--mm-input-border);
    border-radius: 20px;
    background: var(--mm-input-bg);
    color: #888;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1;
}

.mm-tts-toggle:hover {
    border-color: var(--mm-primary);
    color: var(--mm-primary);
}

.mm-tts-toggle.mm-tts-on {
    background: var(--mm-primary);
    border-color: var(--mm-primary);
    color: #fff;
}

.mm-tts-toggle.mm-tts-on:hover {
    opacity: 0.9;
    color: #fff;
}

.mm-tts-toggle.mm-tts-off {
    color: #888;
}

.mm-tts-toggle.mm-tts-unavailable {
    opacity: 0.5;
    cursor: not-allowed;
    color: #aaa;
}

.mm-tts-toggle.mm-tts-unavailable:hover {
    border-color: var(--mm-input-border);
    color: #aaa;
}

.mm-tts-toggle svg {
    flex-shrink: 0;
}

.mm-tts-toggle span {
    font-size: 11px;
}

/* Play button on bot messages */
.mm-tts-play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #999;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
    margin-left: 4px;
    flex-shrink: 0;
    vertical-align: middle;
    padding: 0;
}

.mm-tts-play-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--mm-primary);
}

.mm-tts-play-btn.mm-playing {
    color: var(--mm-primary);
    animation: mmPulse 1.5s infinite;
}

.mm-tts-play-btn.mm-tts-error {
    color: #dc3545;
}

/* Adjust message layout when play button present */
.mm-message-bot {
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

/* ── Admin Preview Wrapper ───────────────────────────── */

.mm-admin-preview-wrapper {
    max-width: 440px;
    margin: 0 auto;
}

.mm-admin-preview-wrapper .mm-chat-inline {
    border-radius: var(--mm-radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1);
}
