/* ═══════════════════════════════════
   KR Agro Tech ERP — Slack Style Chat
   ═══════════════════════════════════ */

/* ── Navbar Chat Icon ── */
#navChatBtn {
    position: relative;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.2s;
    color: white;
    font-size: 18px;
}
#navChatBtn:hover { background: rgba(255,255,255,0.15); }

#navChatBadge {
    position: absolute;
    top: 2px;
    right: 4px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid #1A3A5C;
}

/* ── Overlay ── */
#chatOverlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 1040;
    display: none;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Right Drawer ── */
#chatDrawer {
    position: fixed;
    top: 0; right: -380px;
    width: 360px;
    height: 100vh;
    background: white;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
    transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
}
#chatDrawer.open { right: 0; }

/* ── Drawer Header ── */
#chatDrawerHeader {
    background: #1A3A5C;
    color: white;
    padding: 6px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#chatDrawerHeader .title {
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}
#chatDrawerHeader .close-btn {
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 16px;
}
#chatDrawerHeader .close-btn:hover { background: rgba(255,255,255,0.2); }

/* ── Search ── */
#chatDrawerSearch {
    padding: 10px 14px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}
#chatDrawerSearch input {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 13px;
    outline: none;
    background: #f8f9fa;
}
#chatDrawerSearch input:focus {
    border-color: #1A3A5C;
    background: white;
}

/* ── User List ── */
#chatUserListDrawer {
    flex: 1;
    overflow-y: auto;
}
.drawer-user-item {
    display: flex;
    align-items: center;
    padding: 11px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.15s;
}
.drawer-user-item:hover { background: #f0f4ff; }
.drawer-user-item.active { background: #e8f0fe; }

.drawer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1A3A5C;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    margin-right: 11px;
    position: relative;
}
.drawer-avatar .odot {
    position: absolute;
    bottom: 1px; right: 1px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #ccc;
    border: 2px solid white;
}
.drawer-avatar .odot.on { background: #2ecc71; }

.drawer-user-info { flex: 1; min-width: 0; }
.drawer-user-info .dname {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #222;
}
.drawer-user-info .dlast {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.drawer-unread {
    background: #1A3A5C;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Chat Window ── */
#chatWindowDrawer {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
#chatWindowDrawerHeader {
    padding: 11px 14px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    background: #f8f9fa;
    flex-shrink: 0;
}
#chatWindowDrawerHeader .back {
    cursor: pointer;
    color: #1A3A5C;
    font-size: 15px;
    margin-right: 10px;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s;
}
#chatWindowDrawerHeader .back:hover { background: #e0e7ff; }
#chatWindowDrawerHeader .wname {
    font-weight: 700;
    font-size: 14px;
    flex: 1;
    color: #1A3A5C;
}
#chatWindowDrawerHeader .wtyping {
    font-size: 11px;
    color: #27ae60;
    font-style: italic;
    min-width: 80px;
    display: inline-block;
    overflow: visible;
    white-space: nowrap;
}

/* ── Messages ── */
#drawerMessages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.dmsg { display: flex; flex-direction: column; }
.dmsg.mine { align-items: flex-end; }
.dmsg.other { align-items: flex-start; }

.dmsg .sender-name {
    font-size: 10px;
    color: #888;
    margin-bottom: 2px;
    padding: 0 4px;
}
.dmsg .bubble {
    max-width: 260px;
    width: fit-content;
    padding: 8px 13px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 60px;
}
.dmsg.mine .bubble {
    background: #1A3A5C;
    color: white;
    border-bottom-right-radius: 4px;
    word-break: break-word;
    overflow-wrap: break-word;
}
.dmsg.other .bubble {
    background: white;
    border: 1px solid #e8e8e8;
    color: #222;
    border-bottom-left-radius: 4px;
}
.dmsg.other .bubble.emoji-only,
.dmsg.mine .bubble.emoji-only {
    background: none !important;
    border: none !important;
    font-size: 32px !important;
    padding: 2px 4px !important;
    box-shadow: none !important;
}
.dmsg .bubble a {
    color: #f0c040;
    text-decoration: underline;
}
.dmsg.other .bubble a { color: #1A3A5C; }
.dmsg .dtime {
    font-size: 10px;
    color: #aaa;
    margin-top: 2px;
    padding: 0 4px;
}

/* Date separator */
.date-sep {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    margin: 8px 0;
    position: relative;
}
.date-sep::before, .date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: #ddd;
}
.date-sep::before { left: 0; }
.date-sep::after { right: 0; }

/* ── Input ── */
#drawerInput {
    padding: 10px 14px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: center;
    background: white;
    flex-shrink: 0;
}
#drawerInput input,
#drawerInput textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 8px 16px;
    font-size: 13px;
    outline: none;
    transition: border 0.2s;
    font-family: inherit;
    resize: none;
    overflow: hidden;
    min-height: 36px;
    max-height: 120px;
    line-height: 1.5;
    display: block;
    box-sizing: border-box;
}
#drawerInput input:focus,
#drawerInput textarea:focus { border-color: #1A3A5C; }
#drawerInput .send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #1A3A5C;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}
#drawerInput .send-btn:hover {
    background: #2a5a8c;
    transform: scale(1.05);
}

/* Typing indicator dots */
.typing-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}
.typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #27ae60;
    animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Emoji Reaction ── */
.dmsg {
    position: relative;
}
.dmsg:hover .reaction-bar {
    opacity: 1;
    pointer-events: all;
}
.reaction-bar {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    background: white;
    border: 1px solid #eee;
    border-radius: 20px;
    padding: 4px 8px;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 100;
    bottom: -36px;
    left: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.dmsg.mine .reaction-bar {
    left: auto;
    right: 0;
}
.reaction-btn {
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    border-radius: 50%;
    transition: transform 0.15s;
    border: none;
    background: none;
    line-height: 1;
}
.reaction-btn:hover {
    transform: scale(1.3);
    background: #f0f4ff;
}
.reaction-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.reaction-count {
    background: #f0f4ff;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 1px 7px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: background 0.15s;
}
.reaction-count:hover { background: #dce8ff; }
.reaction-count.mine { 
    background: #1A3A5C; 
    color: white;
    border-color: #1A3A5C;
}
