/* ════════════════════════════════════════════════════════════
   DART CRM — TEAM CHAT  (chat.css)
   Modern full-height chat UI, inspired by Slack/Linear 2026
   ════════════════════════════════════════════════════════════ */

/* ── Hide feedback FAB when chat view is open (it sits over the send button) ─ */
body.chat-open #feedback-fab { display: none !important; }

/* ── View container — fills viewport (which is position:relative) ─ */
#view-chat {
    position: absolute !important;
    inset: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    z-index: 1;
}
#chat-root {
    height: 100%;
    overflow: hidden;
}
.chat-boot-msg {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 100%;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* ── Master layout ──────────────────────────────────────────── */
.chat-wrap {
    display: flex;
    height: 100%;
    overflow: hidden;
    background: #fff;
}

/* ══════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════ */
.chat-sidebar {
    width: 230px;
    min-width: 210px;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,0.04);
}

/* header */
.chat-sidebar-hdr {
    padding: 16px 14px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.chat-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 0.88rem;
    color: #f1f5f9;
    letter-spacing: -0.01em;
}

/* scrollable body */
.chat-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.chat-sidebar-body::-webkit-scrollbar      { width: 4px; }
.chat-sidebar-body::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.12); border-radius: 2px; }

/* section header row */
.chat-section-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 4px;
}
.chat-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #475569;
}
.chat-add-btn {
    width: 20px; height: 20px;
    border: none; background: transparent;
    border-radius: 4px;
    color: #475569;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.1s, color 0.1s;
}
.chat-add-btn:hover { background: rgba(255,255,255,0.08); color: #cbd5e1; }

/* channel item */
.chat-ch-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    margin: 1px 6px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.86rem;
    color: #94a3b8;
    transition: background 0.1s, color 0.1s;
    user-select: none;
}
.chat-ch-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.chat-ch-item.active { background: rgba(72,144,224,0.22); color: #fff; font-weight: 600; }
.chat-ch-item.has-unread { color: #f1f5f9; font-weight: 700; }
.chat-ch-item.has-unread .chat-ch-hash { opacity: 0.85; }
.chat-ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-unread-pill {
    background: #ef4444;
    color: #fff;
    font-size: 0.67rem;
    font-weight: 800;
    border-radius: 12px;
    min-width: 18px; height: 18px;
    line-height: 18px;
    text-align: center;
    padding: 0 5px;
    flex-shrink: 0;
}

/* empty fallback */
.chat-empty-channels {
    padding: 8px 16px;
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.6;
}
.chat-empty-channels a { color: #4890E0; text-decoration: none; }
.chat-empty-channels a:hover { text-decoration: underline; }

/* presence */
.chat-member-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 14px;
    font-size: 0.82rem;
    color: #64748b;
}
.chat-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chat-dot.online   { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.25); }
.chat-dot.offline  { background: #475569; }
.chat-mini-avatar {
    width: 20px; height: 20px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}
.chat-member-name { font-size: 0.82rem; color: #64748b; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-presence-empty { padding: 4px 14px; font-size: 0.78rem; color: #334155; }

/* clickable online-user row → opens DM */
.chat-dm-clickable { cursor: pointer; border-radius: 7px; margin: 1px 4px; transition: background 0.12s; }
.chat-dm-clickable:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }

/* DM suggestion pills inside the New DM modal */
.chat-dm-suggestions {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin: 6px 0 2px;
}
.chat-dm-suggestions button {
    background: rgba(99,102,241,0.15);
    color: #a5b4fc;
    border: 1px solid rgba(99,102,241,0.3);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.1s;
}
.chat-dm-suggestions button:hover { background: rgba(99,102,241,0.3); color: #fff; }

/* ══════════════════════════════════════════════════════════════
   MAIN PANE
   ══════════════════════════════════════════════════════════════ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* header */
.chat-main-hdr {
    padding: 14px 20px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
    background: #fff;
    display: flex;
    align-items: center;
    min-height: 56px;
}
.chat-channel-title {
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-header-hash {
    font-size: 1.15rem;
    color: #94a3b8;
    font-weight: 500;
    line-height: 1;
}
.chat-header-name {
    font-weight: 700;
    font-size: 1rem;
    color: #0f172a;
}
.chat-header-desc {
    font-size: 0.78rem;
    color: #94a3b8;
    padding-left: 12px;
    border-left: 1px solid #e2e8f0;
    margin-left: 6px;
}

/* message pane */
#chat-msg-pane {
    flex: 1;
    overflow-y: auto;
    padding: 8px 20px 4px;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: #e2e8f0 transparent;
}
#chat-msg-pane::-webkit-scrollbar      { width: 5px; }
#chat-msg-pane::-webkit-scrollbar-thumb{ background: #e2e8f0; border-radius: 3px; }

.chat-load-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 0;
}
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #94a3b8;
    font-size: 0.9rem;
    padding: 40px 0;
    text-align: center;
}
.chat-empty-icon { font-size: 3rem; opacity: 0.45; }

/* date divider */
.chat-date-div {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 8px;
    font-size: 0.72rem;
    color: #94a3b8;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.chat-date-div::before,
.chat-date-div::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #f1f5f9;
}

/* ── Message rows ─────────────────────────────────────────────── */
.chat-msg-row {
    display: flex;
    gap: 10px;
    padding: 3px 4px 3px 0;
    border-radius: 8px;
    position: relative;
    margin-bottom: 1px;
    transition: background 0.1s;
}
.chat-msg-row:hover { background: #f8fafc; }
.chat-msg-row:hover .chat-action-bar { opacity: 1; pointer-events: all; }

/* grouped (no avatar) */
.chat-msg-row.grouped { padding-left: 0; }
.chat-avatar-ph {
    width: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 2px;
}
.chat-ts-peek {
    font-size: 0.67rem;
    color: #cbd5e1;
    opacity: 0;
    transition: opacity 0.1s;
    white-space: nowrap;
    padding-top: 4px;
}
.chat-msg-row.grouped:hover .chat-ts-peek { opacity: 1; }

/* avatar */
.chat-avatar {
    width: 36px; height: 36px;
    border-radius: 9px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: #fff;
    align-self: flex-start;
    margin-top: 1px;
}

/* body */
.chat-msg-body { flex: 1; min-width: 0; }

.chat-msg-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.chat-sender {
    font-weight: 700;
    font-size: 0.88rem;
    color: #0f172a;
}
.chat-ts {
    font-size: 0.72rem;
    color: #94a3b8;
}
.chat-msg-text {
    font-size: 0.875rem;
    color: #1e293b;
    line-height: 1.57;
    word-break: break-word;
    white-space: pre-wrap;
}
.chat-edited {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-left: 5px;
}
.chat-msg-text strong { color: #0f172a; }
.chat-msg-text em     { color: #334155; }
.chat-code {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.82em;
    color: #0f172a;
}
.chat-mention {
    background: #eef2ff;
    color: #4f46e5;
    border-radius: 4px;
    padding: 0 3px;
    font-weight: 600;
    font-size: 0.88em;
}

/* reply quote */
.chat-reply-quote {
    background: #f8fafc;
    border-left: 3px solid #4890E0;
    padding: 4px 8px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 4px;
    font-size: 0.78rem;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 500px;
}

/* reactions */
.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}
.chat-rx-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 3px 9px;
    font-size: 0.82rem;
    cursor: pointer;
    color: #475569;
    transition: background 0.1s, border-color 0.1s;
    font-family: inherit;
    line-height: 1.4;
}
.chat-rx-btn:hover { background: #e0e7ff; border-color: #a5b4fc; }
.chat-rx-btn.mine  { background: #eef2ff; border-color: #6366f1; color: #4338ca; font-weight: 600; }
.chat-rx-btn span  { font-size: 0.78rem; }

/* hover action bar */
.chat-action-bar {
    position: absolute;
    right: 4px;
    top: -2px;
    display: flex;
    gap: 1px;
    opacity: 0;
    pointer-events: none;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    padding: 2px 3px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: opacity 0.12s;
    z-index: 10;
}
.chat-act-btn {
    width: 28px; height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.88rem;
    color: #64748b;
    transition: background 0.1s, color 0.1s;
}
.chat-act-btn:hover        { background: #f1f5f9; color: #0f172a; }
.chat-act-btn.danger:hover { background: #fee2e2; color: #ef4444; }

/* ── Typing indicator ─────────────────────────────────────────── */
.chat-typing-row {
    min-height: 24px;
    padding: 3px 20px;
    font-size: 0.78rem;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.chat-typing-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}
.chat-typing-dots span {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: #94a3b8;
    animation: chatTypeDot 1.3s ease-in-out infinite;
    display: inline-block;
}
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chatTypeDot {
    0%, 60%, 100% { opacity: 0.2; transform: scale(0.8); }
    30%            { opacity: 1;   transform: scale(1.3); }
}

/* ── Composer ─────────────────────────────────────────────────── */
.chat-composer {
    border-top: 1px solid #f1f5f9;
    padding: 10px 16px 14px;
    flex-shrink: 0;
    background: #fff;
}
.chat-reply-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px;
    background: #eff6ff;
    border-left: 3px solid #4890E0;
    border-radius: 8px 8px 0 0;
    margin-bottom: 6px;
}
.chat-reply-text {
    flex: 1;
    font-size: 0.78rem;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-reply-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 0.9rem;
    padding: 0 3px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.1s;
}
.chat-reply-close:hover { color: #ef4444; }

.chat-composer-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
#chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 0.88rem;
    font-family: 'Inter', sans-serif;
    resize: none;
    min-height: 42px;
    max-height: 160px;
    overflow-y: hidden;
    outline: none;
    background: #f8fafc;
    color: #0f172a;
    line-height: 1.55;
    margin: 0;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
#chat-input:focus {
    border-color: #4890E0;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(72,144,224,0.12);
}
#chat-input::placeholder { color: #b1bfcc; }

.chat-send-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #002b7a 0%, #4890E0 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    box-shadow: 0 2px 8px rgba(0,43,122,0.28);
}
.chat-send-btn:hover  { transform: scale(1.06); box-shadow: 0 4px 14px rgba(0,43,122,0.4); }
.chat-send-btn:active { transform: scale(0.96); }

/* ── Attach button ────────────────────────────────────────────── */
.chat-attach-btn {
    width: 42px; height: 42px;
    border-radius: 10px;
    background: none;
    border: 1px solid #e2e8f0;
    color: #64748b;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chat-attach-btn:hover { background: #f1f5f9; color: #4890E0; border-color: #cbd5e1; }

/* ── Attachment preview bar (above composer) ──────────────────── */
.chat-attachment-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #f0f9ff;
    border-top: 1px solid #bae6fd;
    font-size: 0.82rem;
    color: #0369a1;
}
.chat-att-thumb {
    height: 48px; width: auto; max-width: 80px;
    border-radius: 6px; object-fit: cover;
    cursor: zoom-in; border: 1px solid #bae6fd;
}
.chat-att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-att-clear {
    background: none; border: none; color: #64748b; cursor: pointer;
    font-size: 1rem; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
.chat-att-clear:hover { color: #ef4444; }
.chat-att-file-icon { font-size: 1.2rem; flex-shrink: 0; }

/* ── Inline attachment in message ─────────────────────────────── */
.chat-att-img-wrap { margin-top: 6px; }
.chat-att-inline {
    max-width: 320px; max-height: 220px;
    border-radius: 10px; border: 1px solid #e2e8f0;
    display: block; cursor: zoom-in; object-fit: contain;
    transition: opacity 0.12s;
}
.chat-att-inline:hover { opacity: 0.9; }
.chat-att-file-chip {
    display: inline-flex; align-items: center; gap: 7px;
    margin-top: 6px;
    padding: 7px 12px;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px;
    font-size: 0.82rem; color: #0f172a; text-decoration: none;
    transition: background 0.12s, border-color 0.12s;
    max-width: 280px;
}
.chat-att-file-chip:hover { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }
.chat-att-file-chip span:last-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Emoji picker (floating) ──────────────────────────────────── */
.chat-emoji-picker {
    position: fixed;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    width: 210px;
    z-index: 9500;
    box-shadow: 0 8px 28px rgba(0,0,0,0.14), 0 1px 4px rgba(0,0,0,0.06);
    animation: chatPickerIn 0.12s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes chatPickerIn {
    from { opacity: 0; transform: scale(0.88) translateY(6px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   }
}
.chat-emoji-picker button {
    width: 34px; height: 34px;
    border: none; background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.15rem;
    transition: background 0.1s, transform 0.1s;
    display: flex; align-items: center; justify-content: center;
}
.chat-emoji-picker button:hover { background: #f1f5f9; transform: scale(1.18); }

/* ── Create channel modal ─────────────────────────────────────── */
.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: chatFadeIn 0.15s ease both;
}
@keyframes chatFadeIn { from { opacity: 0; } to { opacity: 1; } }

.chat-modal {
    background: #fff;
    border-radius: 18px;
    padding: 26px 28px 22px;
    width: 390px;
    max-width: 95vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.03);
    animation: chatModalIn 0.18s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes chatModalIn {
    from { opacity: 0; transform: scale(0.92) translateY(12px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}
.chat-modal-header {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 1rem;
    color: #0f172a;
    margin-bottom: 18px;
}
.chat-modal-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.chat-modal input {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    font-size: 0.88rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    margin-bottom: 14px;
    background: #f8fafc;
    color: #0f172a;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-modal input:focus {
    border-color: #4890E0;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(72,144,224,0.12);
}
.chat-modal-btns {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 6px;
}
.chat-modal-btns button {
    padding: 9px 20px;
    border-radius: 9px;
    border: none;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    transition: background 0.12s, transform 0.1s;
}
.chat-modal-cancel  { background: #f1f5f9; color: #475569; }
.chat-modal-cancel:hover  { background: #e2e8f0; }
.chat-modal-primary { background: linear-gradient(135deg,#002b7a,#4890E0); color: #fff; box-shadow: 0 2px 8px rgba(0,43,122,0.25); }
.chat-modal-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,43,122,0.35); }

/* ── Spinner ──────────────────────────────────────────────────── */
.chat-spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid #e2e8f0;
    border-top-color: #4890E0;
    border-radius: 50%;
    animation: chatSpin 0.7s linear infinite;
}
@keyframes chatSpin { to { transform: rotate(360deg); } }

/* ── Nav badge ────────────────────────────────────────────────── */
#nav-chat { position: relative; }
#chat-nav-badge {
    display: none;
    position: absolute;
    top: 7px; right: 7px;
    width: 10px; height: 10px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #0b1628;
    animation: chatDotPulse 1.8s ease-in-out infinite;
}
@keyframes chatDotPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.55); }
    50%       { box-shadow: 0 0 0 5px rgba(239,68,68,0); }
}

/* ── Chat toast notification (avatar inside call-toast) ─────── */
.chat-notif-avatar {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}
.chat-notif-toast { border-left-color: #6366f1; }
