.ap-smart-dialog {
    position: fixed;
    z-index: 999999;
    bottom: 16px;
    font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.ap-smart-dialog--bottom-right { right: 16px; }
.ap-smart-dialog--bottom-left { left: 16px; }
.ap-smart-dialog--bottom-center { left: 50%; transform: translateX(-50%); }

/* "По центру страницы": бабл всё равно якорится справа внизу,
   а раскрытая панель встаёт по центру экрана (см. правило ниже) */
.ap-smart-dialog--page-center { right: 16px; bottom: 16px; left: auto; transform: none; }

/* --- Затемнение фона при открытии --- */
.ap-smart-dialog__overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999998;
    background: #00000078;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

body.smart-dialog__opened .ap-smart-dialog__overlay { display: block; }

/* --- Свёрнутое состояние (плашка-бабл) --- */
.ap-smart-dialog__bubble {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 18px 10px 10px;
    background: #fff;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    max-width: 280px;
}

.ap-smart-dialog.is-minified .ap-smart-dialog__bubble { display: flex; }

.ap-smart-dialog__bubble-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.ap-smart-dialog__bubble-logo--placeholder {
    background: var(--ap-sd-accent, #2AABEE);
}

.ap-smart-dialog__bubble-title {
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ap-smart-dialog__bubble-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    margin-left: auto;
    flex-shrink: 0;
    border-radius: 999px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* --- Развёрнутая панель --- */
.ap-smart-dialog__panel {
    display: none;
    flex-direction: column;
    width: 340px;
    max-width: calc(100vw - 24px);
    height: 520px;
    max-height: calc(100vh - 40px);
    background: var(--ap-sd-panel-bg, linear-gradient(160deg, #d6e975 0%, #a9e08a 100%));
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
}

.ap-smart-dialog.is-open .ap-smart-dialog__panel { display: flex; }

/* Раскрытая панель в режиме "по центру страницы" позиционируется
   независимо от якоря бабла — как модальное окно поверх контента */
.ap-smart-dialog--page-center .ap-smart-dialog__panel {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
}

.ap-smart-dialog__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--ap-sd-header-bg, #ffffff);
    border-bottom: 1px solid var(--ap-sd-header-border, #a1d183);
    flex-shrink: 0;
}

.ap-smart-dialog__header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.ap-smart-dialog__header-title {
    font-weight: 700;
    color: var(--ap-sd-header-title, #1a1a1a);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ap-smart-dialog__close {
    border: none;
    background: none;
    color: var(--ap-sd-close-color, #2c8f2c);
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    font-size: 13px;
}

.ap-smart-dialog__body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-image: var(--ap-sd-body-bg-image, none);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.ap-smart-dialog__message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 95%;
}

.ap-smart-dialog__message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.ap-smart-dialog__message-avatar--placeholder {
    background: var(--ap-sd-author-color, #8544e4);
    opacity: 0.5;
}

.ap-smart-dialog__message {
    background: #fff;
    border-radius: 14px 14px 14px 4px;
    padding: 10px 12px;
    min-width: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    animation: ap-sd-fade-in 0.25s ease;
}

.ap-smart-dialog__message-author {
    display: block;
    font-weight: 700;
    color: var(--ap-sd-author-color, #8544e4);
    margin-bottom: 3px;
    font-size: 13px;
}

.ap-smart-dialog__message-text {
    color: #1a1a1a;
    white-space: pre-wrap;
    word-break: break-word;
}

.ap-smart-dialog__message-time {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: #9a9a9a;
}

.ap-smart-dialog__typing-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 60%;
}

.ap-smart-dialog__typing {
    background: #fff;
    border-radius: 14px 14px 14px 4px;
    padding: 10px 12px;
    color: #6a6a6a;
    font-style: italic;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

@keyframes ap-sd-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Подвал: поле ввода + кнопки мессенджеров в одной обёртке --- */
.ap-smart-dialog__footer {
    background: var(--ap-sd-footer-bg, rgba(255, 255, 255, 0.5));
    border-top: 1px solid #ffffff52;
    flex-shrink: 0;
    padding-top: 10px;
}

.ap-smart-dialog__input-row {
    padding: 0 12px 10px;
}

.ap-smart-dialog__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.ap-smart-dialog__input {
    width: 100%;
    border: none;
    border-radius: 999px;
    padding: 10px 44px 10px 14px;
    font-size: 14px;
    outline: none;
    background: #fff;
    box-sizing: border-box;
}

.ap-smart-dialog__input::placeholder { color: #a0a0a0; }

.ap-smart-dialog__hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.ap-smart-dialog__send {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #b7b7b7;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease;
}

.ap-smart-dialog__send svg { width: 17px; height: 17px; }

.ap-smart-dialog__send.is-filled {
    color: var(--ap-sd-accent, #2AABEE);
}

.ap-smart-dialog__send:disabled {
    opacity: 0.5;
    cursor: default;
}

.ap-smart-dialog__messengers {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 0 14px 12px;
}

.ap-smart-dialog__messengers:empty { display: none; }

.ap-smart-dialog__messenger-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--ap-sd-msngr-color, #1a1a1a);
    transition: color 0.15s ease;
}

.ap-smart-dialog__messenger-btn:hover {
    color: var(--ap-sd-msngr-hover, #3f993d);
    text-decoration: none;
}

.ap-smart-dialog__messenger-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ap-smart-dialog__messenger-icon svg {
    width: 13px;
    height: 13px;
}

.ap-smart-dialog__messenger-icon--telegram { background: linear-gradient(45deg, #0043d9, #00c8e7); }
.ap-smart-dialog__messenger-icon--whatsapp { background: linear-gradient(45deg, #098117, #09c600); }
.ap-smart-dialog__messenger-icon--max { background: linear-gradient(50deg, #009ef2, #f50fff); }
.ap-smart-dialog__messenger-icon--max svg { width: 12px; height: 12px; }

.ap-smart-dialog__lead-status {
    padding: 0 14px 10px;
    font-size: 12px;
    color: #2c6b2c;
}

.ap-smart-dialog__lead-status:empty { display: none; }

@media (max-width: 480px) {
    .ap-smart-dialog { bottom: 10px; }
    .ap-smart-dialog--bottom-left, .ap-smart-dialog--bottom-right, .ap-smart-dialog--page-center { left: 10px; right: 10px; }
    .ap-smart-dialog--bottom-center { left: 10px; right: 10px; transform: none; width: auto; }
    .ap-smart-dialog__bubble { width: fit-content; }
    .ap-smart-dialog__panel { width: 100%; }
    .ap-smart-dialog--page-center .ap-smart-dialog__panel { width: calc(100vw - 20px); }
}
