/* ── Launcher ── */
.ms-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #c62828);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(192,57,43,0.45);
    transition: transform 0.2s, box-shadow 0.2s;
}

.ms-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(192,57,43,0.55);
}

.ms-chat-btn svg {
    width: 26px;
    height: 26px;
}

.ms-chat-btn__close {
    display: none;
}

.ms-chat-btn--open .ms-chat-btn__open { display: none; }
.ms-chat-btn--open .ms-chat-btn__close { display: block; }

/* ── Widget ── */
.ms-chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 9997;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 540px;
    max-height: calc(100vh - 140px);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    font-family: var(--font-family);
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(.34,1.3,.64,1), opacity 0.2s;
}

.ms-chat-window--open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ── */
.ms-chat-head {
    background: linear-gradient(135deg, var(--primary), #c62828);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.ms-chat-head__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ms-chat-head__info { flex: 1; }

.ms-chat-head__name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.ms-chat-head__status {
    font-size: 12px;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.ms-chat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}

.ms-chat-head__close {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    padding: 0;
}

.ms-chat-head__close:hover { background: rgba(255,255,255,0.28); }

/* ── Messages ── */
.ms-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f7f7f7;
    scroll-behavior: smooth;
}

.ms-chat-body::-webkit-scrollbar { width: 4px; }
.ms-chat-body::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.ms-chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ms-chat-row--user {
    flex-direction: row-reverse;
}

.ms-chat-bot-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #c62828);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ms-chat-bot-icon svg {
    width: 14px;
    height: 14px;
}

.ms-chat-msg {
    max-width: 240px;
    padding: 10px 13px;
    font-size: 13.5px;
    line-height: 1.55;
    border-radius: 12px;
    word-wrap: break-word;
}

.ms-chat-msg--bot {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 12px 12px 12px 2px;
    color: #1a1a1a;
}

.ms-chat-msg--user {
    background: linear-gradient(135deg, var(--primary), #c62828);
    border-radius: 12px 12px 2px 12px;
    color: #fff;
}

.ms-chat-msg strong { font-weight: 600; }

.ms-chat-msg ul {
    margin: 6px 0 0 16px;
    padding: 0;
}

.ms-chat-msg li { margin-bottom: 4px; }

.ms-chat-msg a { color: var(--primary); text-decoration: underline; }

.ms-chat-msg--bot a { color: var(--accent-blue); }

/* ── Products in chat ── */
.ms-chat-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.ms-chat-product {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #f7f7f7;
    border-radius: 10px;
    text-decoration: none;
    color: #1a1a1a;
    transition: background 0.15s;
}

.ms-chat-product:hover { background: #eee; }

.ms-chat-product img {
    width: 44px;
    height: 52px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--bg-light);
}

.ms-chat-p-name {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
}

.ms-chat-p-price {
    font-size: 12px;
    font-weight: 600;
    color: #111;
    white-space: nowrap;
}

/* ── Typing ── */
.ms-chat-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
}

.ms-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: ms-chat-bounce 1.2s infinite ease-in-out;
}

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

@keyframes ms-chat-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ── Suggestions ── */
.ms-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 0 4px 36px;
}

.ms-chat-pill {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--primary);
    background: #fff;
    color: var(--primary);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.ms-chat-pill:hover {
    background: linear-gradient(135deg, var(--primary), #c62828);
    color: #fff;
    border-color: transparent;
}

/* ── Input ── */
.ms-chat-foot {
    padding: 12px;
    border-top: 1px solid #ececec;
    background: #fff;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.ms-chat-foot input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 9px 14px;
    font-size: 13.5px;
    outline: none;
    font-family: inherit;
    background: #f7f7f7;
    color: #1a1a1a;
    transition: border-color 0.15s, background 0.15s;
}

.ms-chat-foot input:focus {
    border-color: var(--primary);
    background: #fff;
}

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

.ms-chat-foot button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #c62828);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.15s;
}

.ms-chat-foot button:hover {
    background: #a93226;
    transform: scale(1.06);
}

.ms-chat-foot button:active { transform: scale(0.95); }

.ms-chat-foot button svg {
    width: 18px;
    height: 18px;
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .ms-chat-window {
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        right: 12px;
        bottom: 80px;
        height: 460px;
        max-height: calc(100vh - 140px);
    }

    .ms-chat-btn {
        right: 12px;
        bottom: 16px;
        width: 52px;
        height: 52px;
    }

    .ms-chat-btn svg {
        width: 24px;
        height: 24px;
    }
}