/* ============================================================
 *  /chats/ page
 * ============================================================ */
.chats-layout {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 16px;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    height: calc(100vh - 200px);
    min-height: 540px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.chats-sidebar {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}
.chats-sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.chats-sidebar-header h1 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.chats-list { overflow-y: auto; flex: 1; }
.chats-list-empty { padding: 30px 20px; color: var(--text-secondary); text-align: center; font-size: .9rem; }
.chats-list-item {
    display: flex; gap: 12px; align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    text-decoration: none; color: inherit;
    transition: background .12s;
}
.chats-list-item:hover { background: var(--bg-card); }
.chats-list-item.is-active { background: var(--bg-card); border-left: 3px solid var(--primary); padding-left: 13px; }
.chats-list-avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.chats-list-meta { flex: 1; min-width: 0; }
.chats-list-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chats-list-name { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats-list-time { font-size: .75rem; color: var(--text-secondary); flex-shrink: 0; margin-left: 6px; }
.chats-list-preview { font-size: .82rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.chats-list-unread { background: var(--primary); color: #fff; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 10px; min-width: 18px; text-align: center; margin-left: auto; }
.chats-online-dot { width: 8px; height: 8px; background: #22c55e; border-radius: 50%; display: inline-block; margin-right: 6px; }

.chats-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-card); }
.chats-empty { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; color: var(--text-secondary); gap: 12px; }
.chats-empty p { margin: 0; font-size: .95rem; }
.chats-thread { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.chats-thread-header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}
.chats-back {
    display: none; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 8px;
    color: var(--text-primary); text-decoration: none;
    transition: background .12s;
}
.chats-back:hover { background: var(--bg); }
.chats-peer-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.chats-peer-meta { flex: 1; min-width: 0; }
.chats-peer-name { display: block; font-weight: 700; font-size: 1rem; text-decoration: none; color: inherit; }
.chats-peer-name:hover { color: var(--primary); }
.chats-peer-status { font-size: .8rem; color: var(--text-secondary); }

.chats-messages {
    flex: 1; overflow-y: auto;
    padding: 16px 20px;
    background: var(--bg);
    display: flex; flex-direction: column; gap: 6px;
}
.chats-thread-empty { text-align: center; color: var(--text-secondary); margin: auto; font-size: .9rem; }
.chats-msg { display: flex; flex-direction: column; max-width: 70%; }
.chats-msg.mine  { align-self: flex-end; align-items: flex-end; }
.chats-msg.other { align-self: flex-start; align-items: flex-start; }
.chats-bubble {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 12px;
    font-size: .92rem; line-height: 1.4;
    word-wrap: break-word; overflow-wrap: anywhere;
    max-width: 100%;
}
.chats-msg.mine .chats-bubble {
    background: var(--primary); color: #fff; border-color: var(--primary);
    border-bottom-right-radius: 4px;
}
.chats-msg.other .chats-bubble { border-bottom-left-radius: 4px; }
.chats-bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; }
.chats-bubble-text { white-space: pre-wrap; margin-top: 4px; }
.chats-bubble > a + .chats-bubble-text { margin-top: 6px; }
.chats-msg-time { font-size: .7rem; color: var(--text-secondary); margin: 2px 8px 0; }

.chats-file {
    display: flex; gap: 8px; align-items: center;
    padding: 6px 10px; background: rgba(0,0,0,.04); border-radius: 8px;
    color: inherit; text-decoration: none;
}
.chats-msg.mine .chats-file { background: rgba(255,255,255,.18); color: #fff; }
.chats-file-name { font-weight: 600; font-size: .88rem; }
.chats-file-size { font-size: .75rem; opacity: .75; margin-left: auto; }

.chats-composer {
    display: flex; gap: 8px; align-items: flex-end;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}
.chats-composer textarea {
    flex: 1; resize: none;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
    font: inherit; font-size: .92rem;
    line-height: 1.4;
    min-height: 40px; max-height: 120px;
    background: var(--bg);
    color: inherit;
}
.chats-composer textarea:focus { outline: none; border-color: var(--primary); }
.chats-attach-btn, .chats-send-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; cursor: pointer;
    border-radius: 10px; color: var(--text-secondary);
    transition: background .12s, color .12s;
}
.chats-attach-btn:hover { background: var(--bg); color: var(--text-primary); }
.chats-send-btn { background: var(--primary); color: #fff; }
.chats-send-btn:hover { background: var(--primary-hover, var(--primary)); opacity: .9; }

@media (max-width: 720px) {
    .chats-layout {
        grid-template-columns: 1fr;
        height: calc(100vh - 100px);
        margin: 0;
        border-radius: 0;
        border-left: 0; border-right: 0;
        padding: 0;
    }
    .chats-sidebar { display: none; }
    .chats-main { display: flex; }
    .chats-back { display: flex; }
    body.has-thread-active .chats-sidebar { display: none; }
    body.no-thread-active .chats-sidebar { display: flex; }
    body.no-thread-active .chats-main { display: none; }
}

/* ============================================================
 *  Floating widget (bottom-right)
 * ============================================================ */
.mkt-dm-widget {
    position: fixed; right: 20px; bottom: 20px;
    z-index: 9000;
    font-family: inherit;
}
.mkt-dm-widget.is-hidden { display: none; }

.mkt-dm-widget-bar {
    display: none;
    align-items: center; gap: 8px;
    background: var(--primary); color: #fff;
    padding: 10px 16px;
    border-radius: 24px;
    box-shadow: 0 6px 20px rgba(0,0,0,.18);
    cursor: pointer;
    font-weight: 600; font-size: .9rem;
    user-select: none;
    transition: transform .12s;
}
.mkt-dm-widget-bar:hover { transform: translateY(-2px); }
.mkt-dm-widget[data-state="min"] .mkt-dm-widget-bar { display: inline-flex; }
.mkt-dm-widget-bar-badge {
    background: #fff; color: var(--primary);
    font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 10px;
    min-width: 18px; text-align: center;
}

.mkt-dm-widget-panel {
    display: none;
    width: 360px; height: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0,0,0,.22);
    overflow: hidden;
    flex-direction: column;
}
.mkt-dm-widget-panel.is-open { display: flex; }

.mkt-dm-widget-header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
.mkt-dm-widget-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.mkt-dm-widget-peer { flex: 1; min-width: 0; }
.mkt-dm-widget-name { font-weight: 700; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mkt-dm-widget-status { font-size: .76rem; color: var(--text-secondary); }
.mkt-dm-widget-action {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; cursor: pointer;
    border-radius: 6px; color: var(--text-secondary);
}
.mkt-dm-widget-action:hover { background: var(--bg); color: var(--text-primary); }

.mkt-dm-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--bg);
    display: flex; flex-direction: column; gap: 4px;
}
.mkt-dm-empty { text-align: center; color: var(--text-secondary); margin: auto; font-size: .85rem; }

.mkt-dm-msg { display: flex; flex-direction: column; max-width: 80%; }
.mkt-dm-msg.mine  { align-self: flex-end; align-items: flex-end; }
.mkt-dm-msg.other { align-self: flex-start; align-items: flex-start; }
.mkt-dm-bubble {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 6px 10px;
    font-size: .88rem; line-height: 1.35;
    word-wrap: break-word; overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.mkt-dm-msg.mine .mkt-dm-bubble {
    background: var(--primary); color: #fff; border-color: var(--primary);
    border-bottom-right-radius: 4px;
}
.mkt-dm-msg.other .mkt-dm-bubble { border-bottom-left-radius: 4px; }
.mkt-dm-msg-time { font-size: .68rem; color: var(--text-secondary); margin: 2px 6px 0; }

.mkt-dm-widget-attach { flex-shrink: 0; }
.mkt-dm-bubble img { display: block; max-width: 100%; max-height: 200px; border-radius: 8px; }
.mkt-dm-widget-form {
    display: flex; gap: 6px; align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}
.mkt-dm-widget-form textarea {
    flex: 1; resize: none;
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
    font: inherit; font-size: .88rem; line-height: 1.35;
    min-height: 36px; max-height: 80px;
    background: var(--bg); color: inherit;
}
.mkt-dm-widget-form textarea:focus { outline: none; border-color: var(--primary); }
.mkt-dm-widget-send {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary); color: #fff;
    border: none; border-radius: 10px; cursor: pointer;
}
.mkt-dm-widget-send:hover { opacity: .92; }

@media (max-width: 720px) {
    .mkt-dm-widget { right: 12px; bottom: 12px; left: 12px; }
    .mkt-dm-widget-panel { width: auto; height: 70vh; }
}

/* ── Кнопка «Написать продавцу» / «Написать» ──────────── */
.btn-write-dm {
    display: flex; align-items: center; justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 12px;
    padding: 10px 16px;
    background: var(--primary); color: #fff;
    border: none; border-radius: 10px;
    font: inherit; font-size: .92rem; font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .12s;
}
.btn-write-dm:hover { opacity: .9; color: #fff; }
.btn-write-dm svg { flex-shrink: 0; }
