/* ============================================================
   CHAT
   (split from style.css, lines 2108-2539)
   ============================================================ */

/* ======================================================
   CHAT — Discord-inspired dark theme
   ====================================================== */

.chat-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: calc(100vh - 120px);
    background: var(--bg-2);
    border: none;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-sunken);
    border-right: 1px solid var(--border);
}
.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 12px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
}
.chat-search {
    margin: 4px 8px 8px;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 10px;
    color: var(--text-1);
    font-size: 0.82rem;
    outline: none;
    width: calc(100% - 16px);
}
.chat-search::placeholder { color: var(--text-3); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    margin-bottom: 1px;
    position: relative;
}
.chat-list-item:hover  { background: var(--bg-3); }
.chat-list-item.active { background: var(--bg-4); }
.chat-list-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem; font-weight: 700; color: #fff;
    flex-shrink: 0; position: relative;
}
.chat-list-info { flex: 1; min-width: 0; }
.chat-list-name {
    font-size: 0.88rem; font-weight: 500; color: var(--text-1);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-list-preview {
    font-size: 0.73rem; color: var(--text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px;
}
.chat-list-item.active .chat-list-name { color: var(--text-1); }
.chat-unread-badge {
    background: var(--danger); color: #fff;
    font-size: 0.65rem; font-weight: 700;
    padding: 2px 5px; border-radius: 99px;
    flex-shrink: 0; min-width: 16px; text-align: center;
}

/* ── Main ────────────────────────────────────────────────────── */
.chat-main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg-2); }
.chat-empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; height: 100%;
    color: var(--text-3); text-align: center; padding: 40px;
}
.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
    flex-shrink: 0;
    box-shadow: none;
}
.chat-search-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}
.chat-search-bar input {
    flex:1; background:var(--bg-sunken); border:1px solid var(--border);
    border-radius:4px; padding:6px 10px;
    color:var(--text-1); font-size:0.82rem; outline:none;
}

/* ── Messages area ───────────────────────────────────────────── */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 8px 0;
    display: flex; flex-direction: column;
    gap: 0;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }

/* ── Date separator ──────────────────────────────────────────── */
.chat-date-sep {
    display: flex; align-items: center; gap: 12px;
    margin: 16px 0 8px;
    color: var(--text-3); font-size: 0.72rem; font-weight: 600;
}
.chat-date-sep::before,
.chat-date-sep::after {
    content: ''; flex: 1;
    height: 1px; background: var(--border);
}

/* ── Individual messages ─────────────────────────────────────── */
.chat-message {
    display: flex;
    gap: 12px;
    padding: 2px 16px;
    border-radius: 0;
    transition: background 0.1s;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}
.chat-message:hover { background: var(--bg-3); }
.chat-message.mine  { flex-direction: row-reverse; }

.chat-msg-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700; color: #fff;
    flex-shrink: 0; align-self: flex-start; margin-top: 2px;
}
.chat-message.mine .chat-msg-avatar { display: none; }

.chat-msg-body {
    display: flex; flex-direction: column;
    max-width: calc(100% - 60px);
    flex: 1;
}
.chat-message.mine .chat-msg-body { align-items: flex-end; }

.chat-message.ctx-active { background: var(--bg-3); }

.chat-msg-name {
    font-size: 0.88rem; font-weight: 600;
    color: var(--text-1); margin-bottom: 2px;
}
.chat-msg-bubble {
    background: transparent;
    padding: 0;
    max-width: 100%;
    word-break: break-word;
    position: relative;
    border: none;
}
.chat-msg-content {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text-1);
    word-break: break-word;
}
.chat-message.mine .chat-msg-content {
    background: var(--accent-strong);
    color: var(--on-accent);
    padding: 8px 12px;
    border-radius: 16px 16px 4px 16px;
    display: inline-block;
    max-width: 520px;
}
.chat-message.theirs .chat-msg-content {
    background: var(--bg-3);
    padding: 8px 12px;
    border-radius: 4px 16px 16px 16px;
    display: inline-block;
    max-width: 520px;
}
.chat-msg-bubble.deleted-msg .chat-msg-content {
    background: transparent !important;
    color: var(--text-3) !important;
    font-style: italic;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* Time and edited — bottom line */
.chat-msg-footer {
    display: flex; align-items: center; gap: 6px;
    margin-top: 2px;
}
.chat-edited {
    font-size: 0.65rem; color: var(--text-3);
    font-style: italic;
}

/* ── Hover timestamp ──────────────────────────────────────────
   .chat-msg-time-hover is a direct child of .chat-message
   (position: relative). It is absolutely positioned so it never
   affects layout.

   For "theirs" — bubble is LEFT-aligned → time on the RIGHT.
   For "mine"   — bubble is RIGHT-aligned → time on the LEFT.
   In both cases the time appears on the OPPOSITE side from the
   bubble, which is always the open/empty side of the row.      */
.chat-msg-time-hover {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.62rem;
    color: var(--text-3);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 2;
}
/* theirs: bubble is left → time appears on the right */
.chat-message.theirs .chat-msg-time-hover {
    right: 16px;
    left: auto;
}
/* mine: bubble is right → time appears on the left */
.chat-message.mine .chat-msg-time-hover {
    left: 16px;
    right: auto;
}
.chat-message:hover .chat-msg-time-hover { opacity: 1; }

/* ── Read receipt — double tick under my last read message ─── */
.chat-read-receipt {
    display: flex;
    align-items: center;
    margin-top: 3px;
    line-height: 1;
}
.chat-receipt-ticks,
.chat-receipt-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    opacity: 0.9;
}
.chat-receipt-count {
    font-size: 0.6rem;
    color: var(--accent);
    font-weight: 600;
}
.chat-input-wrapper {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
}
.chat-typing {
    height: 18px;
    padding: 2px 16px 0;
    font-size: 0.72rem;
    color: var(--text-3);
    font-style: italic;
    line-height: 16px;
    flex-shrink: 0;
}

/* ── Consecutive messages (no avatar repeat) ─────────────────── */
.chat-message.consecutive { margin-top: -6px; }
.chat-message.consecutive .chat-msg-avatar { visibility: hidden; }
.chat-message.consecutive .chat-msg-name   { display: none; }
.chat-message.consecutive .chat-msg-bubble { border-radius: 4px 16px 16px 4px; }
.chat-message.mine.consecutive .chat-msg-bubble { border-radius: 16px 4px 4px 16px; }
.chat-msg-avatar.invisible { visibility: hidden; }

/* ── Reply quote ─────────────────────────────────────────────── */
.chat-reply-quote {
    background: var(--accent-dim);
    border-left: 3px solid var(--accent);
    border-radius: 0 4px 4px 0;
    padding: 4px 8px;
    margin-bottom: 4px;
    font-size: 0.78rem;
    max-width: 400px;
}
.chat-reply-sender { color: var(--accent); font-weight: 600; margin-bottom: 1px; }
.chat-reply-content { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px; border-top: 1px solid var(--border);
    background: var(--bg-2); flex-shrink: 0;
    font-size: 0.82rem; color: var(--text-2);
}

/* ── Reactions ───────────────────────────────────────────────── */
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-reaction {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 8px; padding: 2px 8px;
    font-size: 0.82rem; cursor: pointer;
    transition: all 0.12s; color: var(--text-1);
    display: flex; align-items: center; gap: 4px;
}
.chat-reaction.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}
.chat-reaction:hover { background: var(--bg-3); border-color: var(--accent); }

/* ── Hover action buttons ────────────────────────────────────── */
.chat-msg-actions {
    display: none;
    position: absolute; top: -16px; left: 0;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    gap: 1px;
    box-shadow: var(--shadow-md);
    z-index: 10;
}
.chat-message:hover .chat-msg-actions { display: flex; }
.chat-message.mine .chat-msg-actions  { left: auto; right: 0; }
.chat-action-btn {
    background: transparent; border: none;
    border-radius: 4px; padding: 4px 8px;
    font-size: 0.82rem; cursor: pointer; color: var(--text-2);
    transition: all 0.1s;
}
.chat-action-btn:hover { background: var(--bg-4); color: var(--text-1); }

/* ── Attachments ─────────────────────────────────────────────── */
.chat-attachment {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-3); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px;
    margin-top: 4px; max-width: 360px;
}
.chat-attachment.expired { opacity: 0.4; }
.chat-att-info { flex: 1; min-width: 0; }
.chat-att-name { font-size: 0.85rem; font-weight: 500; color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-att-meta { font-size: 0.7rem; color: var(--text-3); margin-top: 2px; }
.chat-img { max-width: 300px; max-height: 240px; border-radius: 8px; display: block; margin-top: 4px; cursor: pointer; }

/* ── Input ───────────────────────────────────────────────────── */
.chat-input-bar {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 0 16px 16px;
    background: var(--bg-2); flex-shrink: 0;
}
.chat-input {
    flex: 1;
    background: var(--bg-sunken);
    border: none; border-radius: 8px;
    padding: 11px 14px;
    color: var(--text-1);
    font-size: 0.9rem; font-family: var(--font-body);
    outline: none; resize: none; max-height: 140px;
    line-height: 1.4;
}
.chat-input::placeholder { color: var(--text-3); }
.chat-typing {
    height: 18px;
    padding: 0 16px;
    font-size: 0.72rem;
    color: var(--text-3);
    font-style: italic;
    flex-shrink: 0;
    line-height: 18px;
}

/* ── Online indicator ────────────────────────────────────────── */
.online-dot {
    width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid var(--bg-2);
    position: absolute; bottom: 0; right: 0;
    background: var(--success);
}
.online-dot.offline { background: var(--text-3); }

/* ── Modal ───────────────────────────────────────────────────── */
.chat-modal-overlay {
    position: fixed; inset: 0;
    background: var(--overlay);
    z-index: 400;
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.chat-modal {
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 24px;
    width: 100%; max-width: 440px;
    max-height: 80vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.15s ease both;
}
.chat-modal .modal-header h2 { color: var(--text-1); font-size: 1rem; }

/* ── Nav badge ───────────────────────────────────────────────── */
.nav-chat-badge {
    background: var(--danger); color: #fff;
    font-size: 0.62rem; font-weight: 700;
    padding: 1px 5px; border-radius: 99px;
    margin-left: auto;
}

/* ── Consecutive message grouping ────────────────────────────── */
.chat-message + .chat-message.consecutive { margin-top: -2px; }

@media (max-width: 768px) {
    .chat-shell { grid-template-columns: 1fr; }
    .chat-sidebar { display: none; }
    .chat-message { max-width: 90%; }
}

