.ap-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 999999;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ap-chat-button {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: #111827;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0,0,0,.25);
}


.ap-chat-button,
.ap-chat-window {
    position: relative;
}

.ap-chat-button::after,
.ap-chat-header::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    opacity: 0;
    transform: scale(.6);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
}

.ap-chat-button::after {
    top: 3px;
    right: 3px;
}

.ap-chat-header {
    position: relative;
}

.ap-chat-header::after {
    top: 13px;
    right: 48px;
}

.ap-chat-button.ap-chat-has-unread::after,
.ap-chat-window.ap-chat-has-unread .ap-chat-header::after {
    opacity: 1;
    transform: scale(1);
}

.ap-chat-window {
    width: 340px;
    height: 480px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 45px rgba(0,0,0,.25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ap-chat-header {
    background: #111827;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ap-chat-header div div {
    font-size: 12px;
    opacity: .8;
    margin-top: 2px;
}

.ap-chat-close {
    background: transparent;
    color: #fff;
    border: none;
    font-size: 26px;
    cursor: pointer;
}

.ap-chat-body {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    background: #f5f5f5;
}

.ap-chat-message {
    padding: 10px 12px;
    margin-bottom: 10px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.35;
    max-width: 85%;
    word-break: break-word;
}

.ap-chat-message-system {
    background: #fff;
    color: #111827;
}

.ap-chat-message-guest {
    background: #111827;
    color: #fff;
    margin-left: auto;
}

.ap-chat-footer {
    padding: 10px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.ap-chat-footer textarea {
    width: 100%;
    height: 58px;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px;
    box-sizing: border-box;
    font-size: 14px;
}

.ap-chat-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ap-chat-footer button {
    border: none;
    border-radius: 12px;
    background: #111827;
    color: #fff;
    padding: 10px;
    cursor: pointer;
}

.ap-chat-footer .ap-chat-attach {
    width: 44px;
    flex: 0 0 44px;
    background: #f3f4f6;
    color: #111827;
    font-size: 18px;
}

.ap-chat-footer .ap-chat-send-btn {
    flex: 1;
}

.ap-chat-file-preview {
    margin-top: 8px;
}

.ap-chat-preview-item {
    position: relative;
    width: 82px;
    height: 82px;
    border-radius: 12px;
    overflow: hidden;
    background: #e5e7eb;
    border: 1px solid #e5e7eb;
}

.ap-chat-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ap-chat-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    min-width: 22px;
    padding: 0 !important;
    border-radius: 50% !important;
    background: rgba(17,24,39,.82) !important;
    color: #fff !important;
    line-height: 22px;
    font-size: 16px;
}

.ap-chat-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.ap-chat-image-link {
    display: block;
    width: 150px;
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0,0,0,.06);
}

.ap-chat-image-link img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 220px;
    object-fit: cover;
}

.ap-chat-files {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 6px;
}

.ap-chat-file-link {
    color: inherit;
    text-decoration: underline;
}

.ap-chat-text:empty {
    display: none;
}

.ap-chat-message-guest .ap-chat-image-link {
    background: rgba(0,0,0,.06);
}

@media (max-width: 480px) {
    .ap-chat-widget {
        right: 12px;
        bottom: 12px;
    }

    .ap-chat-window {
        width: calc(100vw - 24px);
        height: 70vh;
    }

    .ap-chat-image-link {
        width: 135px;
    }
}


/* Unread indicator: real DOM dots, not only pseudo-elements. */
.ap-chat-unread-dot {
    position: absolute;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0,0,0,.08);
    opacity: 0;
    transform: scale(.65);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
    z-index: 5;
}

.ap-chat-unread-dot-button {
    top: 3px;
    right: 3px;
}

.ap-chat-unread-dot-header {
    top: 13px;
    right: 48px;
}

.ap-chat-has-unread .ap-chat-unread-dot,
.ap-chat-button.ap-chat-has-unread .ap-chat-unread-dot,
.ap-chat-window.ap-chat-has-unread .ap-chat-unread-dot {
    opacity: 1;
    transform: scale(1);
}

.ap-chat-button.ap-chat-has-unread::after,
.ap-chat-window.ap-chat-has-unread .ap-chat-header::after {
    display: none;
}

/* ApartPro Chat unread dot fallback: real span element, not only ::after */
.ap-chat-button {
    position: relative !important;
    overflow: visible !important;
}

.ap-chat-header {
    position: relative !important;
}

.ap-chat-unread-dot {
    position: absolute !important;
    width: 13px !important;
    height: 13px !important;
    min-width: 13px !important;
    min-height: 13px !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ef4444 !important;
    border: 2px solid #ffffff !important;
    border-radius: 999px !important;
    box-sizing: border-box !important;
    display: none !important;
    opacity: 1 !important;
    pointer-events: none !important;
    z-index: 2147483647 !important;
    box-shadow: 0 0 0 1px rgba(0,0,0,.08) !important;
}

.ap-chat-unread-dot-button {
    top: 5px !important;
    right: 5px !important;
}

.ap-chat-unread-dot-header {
    top: 22px !important;
    right: 58px !important;
}

.ap-chat-has-unread .ap-chat-unread-dot,
.ap-chat-unread-dot.is-visible {
    display: block !important;
}


/* Attachments: multiple images and documents */
.ap-chat-file-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.ap-chat-preview-item.is-document {
    width: 150px;
    min-height: 82px;
    height: auto;
    padding: 10px 28px 10px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    color: #111827;
}

.ap-chat-preview-file-icon {
    font-size: 20px;
    line-height: 1;
}

.ap-chat-preview-file-name {
    font-size: 12px;
    line-height: 1.25;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ap-chat-preview-file-size {
    font-size: 11px;
    line-height: 1.2;
    color: #6b7280;
}

.ap-chat-file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 10px;
    background: rgba(0,0,0,.06);
    text-decoration: none;
    font-weight: 600;
}

.ap-chat-file-link::before {
    content: "📄";
}

.ap-chat-message-guest .ap-chat-file-link {
    background: rgba(0,0,0,.06);
}

/* ===== ApartPro Light Theme ===== */

.ap-chat-button {
    background: #9ca3af !important;
    color: #374151 !important;
    box-shadow: 0 8px 30px rgba(0,0,0,.16) !important;
}

.ap-chat-header {
    background: #d1d5db !important;
    color: #111827 !important;
}

.ap-chat-header div div {
    color: #6b7280 !important;
    opacity: 1 !important;
}

.ap-chat-close {
    color: #6b7280 !important;
}

.ap-chat-body {
    background: #f7f7f8 !important;
}

.ap-chat-message-guest {
    background: #d1d5db !important;
    color: #111827 !important;
}

.ap-chat-message-system {
    background: #ffffff !important;
    color: #111827 !important;
}

.ap-chat-footer .ap-chat-send-btn {
    background: #9ca3af !important;
    color: #111827 !important;
}

.ap-chat-footer .ap-chat-send-btn:hover {
    background: #c7ccd3 !important;
}

.ap-chat-footer textarea:focus {
    border-color: #d1d5db !important;
    outline: none !important;
}

.ap-chat-unread-dot {
    background: #ef4444 !important;
}

/* Фото не растягиваются на всю ширину сообщения */
.ap-chat-message {
    overflow: hidden;
}

.ap-chat-image-link {
    width: auto !important;
    max-width: 220px !important;
}

.ap-chat-image-link img {
    max-width: 220px !important;
    max-height: 260px !important;
    width: auto !important;
    height: auto !important;
    border-radius: 12px;
}

/* ===== Mobile Fix ===== */

@media (max-width: 480px) {

    .ap-chat-widget {
        right: 12px !important;
        bottom: 95px !important;
    }

    .ap-chat-window {
        width: calc(100vw - 24px) !important;
        height: calc(100vh - 140px) !important;
        max-height: calc(100vh - 140px) !important;
    }

    .ap-chat-body {
        min-height: 220px !important;
    }

    .ap-chat-image-link {
        max-width: 210px !important;
    }

    .ap-chat-image-link img {
        max-width: 210px !important;
        max-height: 260px !important;
    }
}
