/* ============================================================
   КРОК — Чат v4  (компактный, Telegram-стиль)
   ============================================================ */

.chat-sidebar {
    position: sticky;
    top: 62px;
}

.chat-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 86px);
    overflow: hidden;
    box-shadow: var(--shadow);
}

/* ── Шапка ────────────────────────────────────────────────── */
.chat-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--bg-elevated);
    min-height: 40px;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 7px;
}
.chat-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}
.chat-online {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    color: var(--success);
    font-weight: 500;
}
.chat-online::before {
    content: '';
    width: 5px;
    height: 5px;
    background: var(--success);
    border-radius: 50%;
    flex-shrink: 0;
    animation: chatPulse 2s infinite;
}
@keyframes chatPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--success); }
    50%       { opacity: 0.6; }
}
.chat-online--away { color: var(--warning); }
.chat-online--away::before {
    background: var(--warning);
    animation: none;
}

/* ── Область сообщений ────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 8px 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── Разделитель дат ──────────────────────────────────────── */
.chat-date-sep {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0 4px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.chat-date-sep::before,
.chat-date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Строка сообщения ─────────────────────────────────────── */
.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    padding: 1px 2px;
    position: relative;
}
.chat-row--mine   { flex-direction: row-reverse; }
.chat-row--theirs { flex-direction: row; }

/* При group — аватар скрыт, но место сохранено */
.chat-row--grouped { margin-top: 1px; }
.chat-row--grouped .chat-row__avatar { visibility: hidden; }

/* Кнопка ответа — появляется при hover */
.chat-row__reply-btn {
    opacity: 0;
    pointer-events: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    align-self: center;
    transition: opacity 0.15s, background 0.15s;
    margin-bottom: 2px;
}
.chat-row:hover .chat-row__reply-btn {
    opacity: 1;
    pointer-events: auto;
}
.chat-row__reply-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

/* ── Аватар ───────────────────────────────────────────────── */
.chat-row__avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border);
    margin-bottom: 1px;
}

/* ── Пузырь ───────────────────────────────────────────────── */
.chat-bubble {
    max-width: 82%;
    padding: 5px 10px 4px;
    border-radius: 14px;
    word-break: break-word;
    line-height: 1.4;
    position: relative;
    animation: bubbleIn 0.12s ease-out;
}
@keyframes bubbleIn {
    from { opacity: 0; transform: scale(0.96) translateY(3px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.chat-bubble--theirs {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-bottom-left-radius: 3px;
    color: var(--text-primary);
}
.chat-bubble--mine {
    background: #2c3e50;
    border-bottom-right-radius: 3px;
    color: #ecf0f1;
}

/* Медиа без фона у пузыря */
.chat-bubble--media {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 2px 0 !important;
}

/* Имя автора */
.chat-bubble__author {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1px;
    letter-spacing: 0.1px;
    line-height: 1.2;
}
.chat-bubble--mine .chat-bubble__author { display: none; }

/* Текст */
.chat-bubble__text {
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.45;
}
.chat-bubble--mine .chat-bubble__text { color: #fff; }

/* Время */
.chat-bubble__time {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
    line-height: 1;
    opacity: 0.65;
}
.chat-bubble--mine .chat-bubble__time { color: rgba(255,255,255,0.6); }

/* Медиа внутри пузыря */
.chat-bubble__media-img {
    max-width: 230px;
    max-height: 200px;
    width: 100%;
    object-fit: cover;
    border-radius: 10px;
    display: block;
    cursor: zoom-in;
}
.chat-bubble__media-video {
    max-width: 230px;
    max-height: 160px;
    border-radius: 10px;
    display: block;
}
.chat-bubble__media-audio {
    max-width: 230px;
    height: 32px;
    accent-color: var(--accent);
}
.chat-bubble__media-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--accent);
    text-decoration: underline;
    word-break: break-all;
}
.chat-bubble--mine .chat-bubble__media-link { color: rgba(255,255,255,0.85); }

/* Цитата (ответ) */
.chat-bubble__reply {
    display: flex;
    flex-direction: column;
    border-left: 2px solid var(--accent);
    padding: 2px 7px;
    margin-bottom: 5px;
    border-radius: 0 3px 3px 0;
    background: rgba(0,0,0,0.12);
    cursor: pointer;
    transition: background 0.15s;
    max-width: 100%;
    overflow: hidden;
}
.chat-bubble__reply:hover { background: rgba(0,0,0,0.2); }
.chat-bubble--mine .chat-bubble__reply {
    border-left-color: rgba(255,255,255,0.5);
    background: rgba(0,0,0,0.18);
}
.chat-bubble__reply-author {
    font-size: 0.64rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.3;
}
.chat-bubble--mine .chat-bubble__reply-author { color: rgba(255,255,255,0.85); }
.chat-bubble__reply-text {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-bubble--mine .chat-bubble__reply-text { color: rgba(255,255,255,0.6); }

/* ── Бар ответа ───────────────────────────────────────────── */
.chat-reply-bar {
    padding: 5px 10px;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    display: none;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    gap: 6px;
    flex-shrink: 0;
}
.chat-reply-bar.visible { display: flex; }
.chat-reply-bar__name { color: var(--accent); font-weight: 600; }

/* ── Индикатор набора ─────────────────────────────────────── */
.chat-typing {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
    height: 22px;
}
.chat-typing.visible { display: flex; }
.chat-typing__dots {
    display: flex;
    gap: 3px;
    align-items: center;
}
.chat-typing__dots span {
    width: 4px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingDot 1.2s infinite;
}
.chat-typing__dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing__dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-4px); opacity: 1; }
}

/* ── Футер ────────────────────────────────────────────────── */
.chat-footer {
    padding: 6px 8px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
    background: var(--bg-surface);
}

.chat-input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 6px 12px;
    color: var(--text-primary);
    font-size: 0.84rem;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 80px;
    overflow-y: auto;
}
.chat-input:focus {
    border-color: var(--accent);
    background: var(--bg-base);
}
.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
    font-size: 0.85rem;
}
.chat-send-btn:hover { background: var(--accent-hover); transform: scale(1.06); }
.chat-send-btn:active { transform: scale(0.94); }

/* Кнопка скрепки (если добавлена через JS) */
.chat-clip-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    font-size: 0.85rem;
}
.chat-clip-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Не залогинен */
.chat-guest {
    flex: 1;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 6px;
}
.chat-guest a { color: var(--accent); }
