/* Direct Messages — floating widget (desktop) + fullscreen overlay (mobile).
   Use the existing dashboard CSS-variables (--bg, --accent, --text, --border). */

#directChatWidget {
    position: fixed;
    z-index: 950;
    bottom: 24px;
    right: 24px;
    /* По умолчанию контейнер прозрачен для кликов; кнопка-bubble сама их собирает. */
    pointer-events: none;
}

#directChatWidget .dc-bubble,
#directChatWidget .dc-panel {
    pointer-events: auto;
}

/* ─── Bubble (closed state) ──────────────────────────────────────── */
.dc-bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 140ms ease, box-shadow 140ms ease;
    position: relative;
}
.dc-bubble:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(0,0,0,0.5); }
.dc-bubble svg { width: 24px; height: 24px; }

.dc-bubble-badge {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 20px; height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--rose, #f43f5e);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg, #0f1118);
    display: none;
}
#directChatWidget.dc-has-unread .dc-bubble-badge { display: block; }

/* ─── Panel (open states) ────────────────────────────────────────── */
.dc-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 360px;
    height: 500px;
    max-height: calc(100vh - 96px);
    background: rgba(20, 22, 35, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 14px;
    box-shadow: 0 24px 60px -12px rgba(0,0,0,0.7), 0 8px 24px rgba(0,0,0,0.4);
    color: var(--text);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

/* Visibility per state */
#directChatWidget.dc-state-collapsed   .dc-panel { display: none; }
#directChatWidget.dc-state-open-list   .dc-panel--list { display: flex; }
#directChatWidget.dc-state-open-chat   .dc-panel--chat { display: flex; }

/* ─── Panel header ───────────────────────────────────────────────── */
.dc-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.dc-panel-title {
    flex: 1;
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dc-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted, #c0c0d0);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 1.1rem;
    line-height: 1;
}
.dc-icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* ─── Conversations list ─────────────────────────────────────────── */
.dc-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.dc-conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 120ms ease;
}
.dc-conv-item:hover { background: rgba(255,255,255,0.05); }
.dc-conv-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(99,102,241,0.2);
    color: var(--accent);
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.dc-conv-body { flex: 1; min-width: 0; }
.dc-conv-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
}
.dc-conv-name {
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dc-conv-time {
    font-size: 0.7rem;
    color: var(--text-dim, #8888a0);
    flex-shrink: 0;
}
.dc-conv-preview {
    font-size: 0.8rem;
    color: var(--text-muted, #c0c0d0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.dc-conv-badge {
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ─── Chat panel ─────────────────────────────────────────────────── */
.dc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.dc-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 14px;
    word-wrap: break-word;
    word-break: break-word;
}
.dc-msg--me {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.dc-msg--them {
    align-self: flex-start;
    background: rgba(255,255,255,0.08);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.dc-msg-text { font-size: 0.88rem; line-height: 1.35; white-space: pre-wrap; }
.dc-msg-meta {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}
.dc-msg--them .dc-msg-meta { text-align: left; }

.dc-msg-files {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.15);
}
.dc-msg-file img {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    display: block;
}
.dc-msg-file--link {
    color: inherit;
    text-decoration: underline;
    font-size: 0.8rem;
}

/* ─── Edit/Delete для своих сообщений ────────────────────────── */
.dc-msg { position: relative; }
.dc-msg-actions {
    position: absolute;
    top: -10px;
    right: 6px;
    display: none;
    gap: 2px;
    background: rgba(20, 22, 35, 0.95);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 6px;
    padding: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.dc-msg--me:hover .dc-msg-actions { display: flex; }
.dc-msg-act {
    background: transparent;
    border: none;
    color: var(--text-muted, #c0c0d0);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}
.dc-msg-act:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.dc-msg-act--danger { color: var(--rose, #f43f5e); }
.dc-msg-act--primary {
    background: var(--accent);
    color: #fff;
    padding: 4px 10px;
    font-weight: 600;
}
.dc-msg-act--primary:hover { filter: brightness(1.1); background: var(--accent); color: #fff; }

.dc-msg-edit { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.dc-msg-edit-input {
    width: 100%;
    background: rgba(0,0,0,0.25);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 0.88rem;
    resize: vertical;
    min-height: 60px;
    outline: none;
}
.dc-msg-edit-input:focus { border-color: var(--accent); }
.dc-msg-edit-row { display: flex; gap: 6px; justify-content: flex-end; }

.dc-msg-edited {
    font-style: italic;
    opacity: 0.7;
    font-size: 0.65rem;
}

/* Touch-устройства: hover не сработает, всегда показываем actions компактно */
@media (hover: none) {
    .dc-msg-actions { display: flex; opacity: 0.6; }
    .dc-msg-actions:active { opacity: 1; }
}

/* ─── Composer ───────────────────────────────────────────────────── */
.dc-composer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 8px 10px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.2);
}
.dc-file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}
.dc-file-chips:empty { display: none; }
.dc-file-chip {
    background: rgba(99,102,241,0.18);
    border: 1px solid rgba(99,102,241,0.4);
    border-radius: 12px;
    padding: 3px 8px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
}
.dc-file-chip__x {
    cursor: pointer;
    color: var(--rose, #f43f5e);
    font-weight: 700;
}
.dc-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}
.dc-composer textarea {
    flex: 1;
    resize: none;
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 10px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.3;
    min-height: 36px;
    max-height: 120px;
    outline: none;
}
.dc-composer textarea:focus { border-color: var(--accent); }
.dc-send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}
.dc-send-btn:hover { filter: brightness(1.1); }

/* ─── Drag-over hint ─────────────────────────────────────────────── */
.dc-panel.dc-dragover { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* ─── Empty states ───────────────────────────────────────────────── */
.dc-empty {
    text-align: center;
    color: var(--text-dim, #8888a0);
    padding: 24px 16px;
    font-size: 0.85rem;
}
.dc-empty--small { padding: 16px 12px; }

/* ─── Mobile overlay (fullscreen) ────────────────────────────────── */
@media (max-width: 767px) {
    #directChatWidget {
        bottom: 16px;
        right: 16px;
    }
    .dc-bubble { width: 52px; height: 52px; }

    #directChatWidget.dc-state-open-list .dc-panel--list,
    #directChatWidget.dc-state-open-chat .dc-panel--chat {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
        bottom: 0;
        right: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    /* На мобильнике bubble прячем когда панель открыта, чтобы не перекрывала composer */
    #directChatWidget.dc-state-open-list .dc-bubble,
    #directChatWidget.dc-state-open-chat .dc-bubble {
        display: none;
    }
}
