/* ────────────────────────────────────────────────────────────────────
   Marketur Chat — AI Bot frontend styles
   ────────────────────────────────────────────────────────────────── */

:root {
    --mc-ai-accent:  #6c47ff;
    --mc-ai-accent2: #8b5cf6;
    --mc-ai-bg:      #ffffff;
    --mc-ai-bg-alt:  #f5f5f7;
    --mc-ai-text:    #1c1c1e;
    --mc-ai-muted:   #8e8e93;
    --mc-ai-bbl-me:  linear-gradient(135deg, #6c47ff, #8b5cf6);
    --mc-ai-bbl-bot: #f0f0f5;
    --mc-ai-radius:  18px;
    --mc-ai-shadow:  0 14px 60px rgba(20, 14, 60, .25), 0 4px 14px rgba(0,0,0,.08);
    --mc-ai-font:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

/* ────────────── Guest pill button ────────────── */
#mc-ai-pill {
    position: fixed;
    bottom: 22px;
    right: 22px;
    z-index: 999990;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--mc-ai-bbl-me);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 12px 22px 12px 14px;
    font-family: var(--mc-ai-font);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(108, 71, 255, .45), 0 2px 8px rgba(0,0,0,.15);
    transition: transform .15s ease, box-shadow .15s ease;
    /* Stay above the iOS safe area on PWA */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px) * 0.4);
}
#mc-ai-pill:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(108, 71, 255, .55), 0 4px 12px rgba(0,0,0,.18);
}
#mc-ai-pill:active { transform: translateY(0); }

.mc-ai-pill-icon {
    width: 28px; height: 28px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.mc-ai-pill-icon img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.mc-ai-pill-text { white-space: nowrap; }

/* ────────────── Chat panel container ────────────── */
#mc-ai-pwrap {
    position: fixed;
    inset: 0;
    z-index: 999991;
    display: none;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0;
    pointer-events: none; /* let through to children only */
    background: rgba(0,0,0,0); /* clean backdrop on desktop */
}
@media (max-width: 680px) {
    #mc-ai-pwrap { background: rgba(0,0,0,.45); }
}

/* ────────────── Chat panel ────────────── */
.mc-ai-panel {
    pointer-events: auto;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 580px;
    max-height: calc(100vh - 40px);
    background: var(--mc-ai-bg);
    border-radius: 20px;
    box-shadow: var(--mc-ai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0 22px 22px 22px;
    font-family: var(--mc-ai-font);
    color: var(--mc-ai-text);
    animation: mc-ai-slide-up .25s cubic-bezier(.22,.61,.36,1);
}

@keyframes mc-ai-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* Mobile fullscreen */
@media (max-width: 680px) {
    .mc-ai-panel {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
        /* iOS PWA safe areas */
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-sizing: border-box;
    }
    #mc-ai-pwrap { align-items: stretch; justify-content: stretch; }
}

/* ────────────── Header ────────────── */
.mc-ai-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--mc-ai-bbl-me);
    color: #fff;
    flex-shrink: 0;
}
.mc-ai-head-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.mc-ai-head-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mc-ai-bot-emoji { font-size: 20px; }
.mc-ai-head-info { flex: 1; min-width: 0; }
.mc-ai-head-name { font-size: 15px; font-weight: 700; line-height: 1.2; }
.mc-ai-head-status {
    font-size: 12px;
    opacity: .85;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.mc-ai-dot {
    width: 7px; height: 7px;
    background: #34c759;
    border-radius: 50%;
    display: inline-block;
}
.mc-ai-head-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.85);
    font-size: 26px;
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
    flex-shrink: 0;
}
.mc-ai-head-close:hover { color: #fff; }

/* ────────────── Messages area ────────────── */
.mc-ai-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 10px;
    background: var(--mc-ai-bg-alt);
    -webkit-overflow-scrolling: touch;
}

.mc-ai-msg {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: flex-end;
}
.mc-ai-msg-user { justify-content: flex-end; }

.mc-ai-msg-av {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--mc-ai-bbl-me);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    font-size: 14px;
    color: #fff;
}
.mc-ai-msg-av img  { width: 100%; height: 100%; object-fit: cover; }
.mc-ai-msg-av .mc-ai-bot-emoji { font-size: 14px; }

.mc-ai-msg-bbl {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}
.mc-ai-msg-assistant .mc-ai-msg-bbl {
    background: #fff;
    color: var(--mc-ai-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.mc-ai-msg-user .mc-ai-msg-bbl {
    background: var(--mc-ai-bbl-me);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.mc-ai-msg-bbl a { color: inherit; text-decoration: underline; }
.mc-ai-msg-user .mc-ai-msg-bbl a { color: #fff; }

/* Markdown elements inside bot replies — keep them visually compact for chat */
.mc-ai-msg-assistant .mc-ai-msg-bbl strong { font-weight: 600; }
.mc-ai-msg-assistant .mc-ai-msg-bbl em { font-style: italic; }
.mc-ai-msg-assistant .mc-ai-msg-bbl ul,
.mc-ai-msg-assistant .mc-ai-msg-bbl ol {
    margin: 6px 0;
    padding-left: 22px;
}
.mc-ai-msg-assistant .mc-ai-msg-bbl li {
    margin: 2px 0;
}
.mc-ai-msg-assistant .mc-ai-msg-bbl li::marker { color: var(--mc-ai-accent); }
.mc-ai-msg-assistant .mc-ai-msg-bbl code {
    background: rgba(108, 71, 255, .08);
    color: #4c1d95;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
}
.mc-ai-msg-assistant .mc-ai-msg-bbl pre {
    background: #1e1e2e;
    color: #f5f5f7;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12.5px;
    line-height: 1.45;
}
.mc-ai-msg-assistant .mc-ai-msg-bbl pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: inherit;
}
/* Tighten spacing of stacked block elements at bubble edges */
.mc-ai-msg-assistant .mc-ai-msg-bbl > ul:first-child,
.mc-ai-msg-assistant .mc-ai-msg-bbl > ol:first-child,
.mc-ai-msg-assistant .mc-ai-msg-bbl > pre:first-child { margin-top: 0; }
.mc-ai-msg-assistant .mc-ai-msg-bbl > ul:last-child,
.mc-ai-msg-assistant .mc-ai-msg-bbl > ol:last-child,
.mc-ai-msg-assistant .mc-ai-msg-bbl > pre:last-child { margin-bottom: 0; }

/* Typing indicator */
.mc-ai-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    height: 18px;
}
.mc-ai-dots i {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--mc-ai-muted);
    animation: mc-ai-bounce 1.2s infinite;
}
.mc-ai-dots i:nth-child(2) { animation-delay: .2s; }
.mc-ai-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes mc-ai-bounce {
    0%,80%,100% { transform: translateY(0);   opacity: .4; }
    40%         { transform: translateY(-3px); opacity: 1; }
}

/* ────────────── Input form ────────────── */
.mc-ai-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e5e5ea;
    background: var(--mc-ai-bg);
    flex-shrink: 0;
}
.mc-ai-input {
    flex: 1;
    border: 1px solid #e5e5ea;
    background: var(--mc-ai-bg-alt);
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 15px; /* >=16px would prevent iOS zoom but 15 is fine since input lives inside fixed modal */
    font-family: var(--mc-ai-font);
    color: var(--mc-ai-text);
    outline: none;
    transition: border-color .15s, background .15s;
}
.mc-ai-input:focus {
    border-color: var(--mc-ai-accent);
    background: #fff;
}
@media (max-width: 680px) {
    .mc-ai-input { font-size: 16px; } /* prevent iOS auto-zoom on focus */
}
.mc-ai-input:disabled { opacity: .6; }

.mc-ai-send {
    width: 38px; height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--mc-ai-bbl-me);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform .1s ease, opacity .15s ease;
}
.mc-ai-send:hover  { transform: scale(1.05); }
.mc-ai-send:active { transform: scale(.95); }
.mc-ai-send:disabled { opacity: .5; cursor: not-allowed; }

/* ────────────── Member thread row (in chat list) ────────────── */
.mc-ai-thread-row {
    background: linear-gradient(90deg, rgba(108,71,255,.06), transparent 60%) !important;
    border-left: 3px solid var(--mc-ai-accent) !important;
}
.mc-ai-thread-row:hover {
    background: linear-gradient(90deg, rgba(108,71,255,.1), transparent 60%) !important;
}

.mc-ai-bot-default-av {
    background: var(--mc-ai-bbl-me) !important;
    color: #fff !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.mc-ai-badge-pin {
    display: inline-block;
    margin-left: 4px;
    font-size: 11px;
}

/* Hide normal chat launcher pill for guests so we don't end up with two pills.
   The PWA plugin can also hide #bmc-pill / #bmc-mobile-btn separately, but this
   is belt-and-suspenders for sites without the PWA plugin. */
body.mc-ai-guest-mode #bmc-pill,
body.mc-ai-guest-mode #bmc-mobile-btn,
body.mc-ai-guest-mode #bmc-widget {
    display: none !important;
}
