/* Messenger Module Specific Styles */

/* Overriding Main Wrapper for Full-Height Chat */
.chat-layout-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; 
}

.messenger-container {
    flex: 1;
    display: flex;
    margin: 20px 40px;
    margin-bottom: 30px;
    overflow: hidden; /* Contains the sidebars */
}

@media (max-width: 1024px) {
    .messenger-container {
        margin: 10px 20px;
    }
}

/* ---------------- Left Pane (Sidebar) ---------------- */
.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
}

.chat-search {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.chat-search i {
    color: var(--text-secondary);
    position: absolute;
    margin-left: 12px;
}

.chat-search input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 10px 10px 36px;
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
    transition: var(--transition);
}
.chat-search input:focus {
    border-color: var(--accent-blue);
}

.chat-groups {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}
.scroll-area::-webkit-scrollbar {
    width: 6px;
}
.scroll-area::-webkit-scrollbar-track {
    background: transparent;
}
.scroll-area::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

.chat-sec-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    margin-bottom: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-new-dm {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}
.btn-new-dm:hover { color: var(--accent-blue); }

.channel-list, .dm-list {
    list-style: none;
}

.channel-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: var(--transition);
}
.channel-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.channel-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    border-right: 3px solid var(--accent-blue);
    font-weight: 600;
}

.ch-hash {
    color: var(--text-secondary);
    margin-right: 8px;
    font-size: 1.1rem;
    font-weight: 300;
}
.channel-item.active .ch-hash { color: var(--accent-blue); }

.ch-badge {
    margin-left: auto;
    background: var(--accent-red);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

.has-unread {
    font-weight: 700;
}

/* DMs */
.dm-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
}
.dm-item:hover { background: rgba(255, 255, 255, 0.05); }

.dm-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.dm-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.dm-name {
    font-size: 0.9rem;
    margin-bottom: 2px;
}
.has-unread .dm-name { font-weight: 700; }

.dm-status { font-size: 0.75rem; }
.dm-status.online { color: var(--accent-green); }
.dm-status.offline { color: var(--text-secondary); }
.dm-msg {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}
.has-unread .dm-msg { color: var(--text-primary); font-weight: 500; }

/* ---------------- Right Pane (Chat Window) ---------------- */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.1);
}

.chat-header {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.ch-header-info h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.ch-header-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.ch-header-tools {
    display: flex;
    gap: 8px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.chat-date-divider {
    text-align: center;
    position: relative;
    margin: 20px 0;
}
.chat-date-divider::before {
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    border-top: 1px solid var(--border-color);
    z-index: 1;
}
.chat-date-divider span {
    background: var(--bg-surface);
    padding: 4px 12px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 20px;
    position: relative;
    z-index: 2;
    border: 1px solid var(--border-color);
}

.msg-wrapper {
    display: flex;
    gap: 16px;
    max-width: 80%;
}

.msg-wrapper.peer { align-self: flex-start; }
.msg-wrapper.self { align-self: flex-end; flex-direction: row-reverse;}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.msg-content-block {
    display: flex;
    flex-direction: column;
}
.self .msg-content-block { align-items: flex-end; }

.msg-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    gap: 8px;
    align-items: baseline;
}
.msg-meta .m-name {
    font-weight: 600;
    color: var(--text-primary);
}

.msg-bubble {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px 16px;
    border-radius: 2px 14px 14px 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    border: 1px solid var(--border-color);
}

.self .msg-bubble {
    background: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
    border-radius: 14px 2px 14px 14px;
}

/* Broadcast Styling */
.msg-bubble.broadcast {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.1);
}
.msg-bubble.broadcast .b-title {
    display: block;
    color: var(--accent-red);
    font-size: 1.05rem;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(239, 68, 68, 0.2);
    padding-bottom: 6px;
}

/* Input Area */
.chat-input-area {
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--border-color);
}

.chat-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: center;
}

.chat-toolbar button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
}
.chat-toolbar button:hover {
    color: var(--text-primary);
}

.broadcast-toggle {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.broadcast-toggle label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-red);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-input-wrapper {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.chat-input-wrapper textarea {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 14px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    outline: none;
    max-height: 150px;
    transition: var(--transition);
}
.chat-input-wrapper textarea:focus {
    border-color: var(--accent-blue);
}

.btn-send {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--accent-blue);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.btn-send:hover {
    background: #2563EB;
}

/* ── DM Active State ── */
.dm-item.dm-active {
    background: rgba(59,130,246,0.12) !important;
    border-right: 3px solid var(--accent-blue);
}

/* ── Status Dot in DM ── */
.dm-avatar {
    position: relative;
    flex-shrink: 0;
}
.dm-avatar .status-dot {
    position: absolute;
    bottom: 0; right: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-surface);
}
.dm-avatar .status-dot.online { background: #10B981; }
.dm-avatar .status-dot.offline { background: #64748B; }

/* ── DM Unread Badge ── */
.dm-badge {
    background: #EF4444;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    flex-shrink: 0;
}

/* ── Chat Empty State ── */
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    gap: 12px;
}
.chat-empty-state i {
    font-size: 3rem;
    opacity: 0.3;
}
.chat-empty-state p {
    font-size: 1.05rem;
    font-weight: 600;
}
.chat-empty-state span {
    font-size: 0.85rem;
    opacity: 0.6;
}

/* ── Header Status Dot ── */
.ch-member-count .status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
}
.ch-member-count .status-dot.online { background: #10B981; }
.ch-member-count .status-dot.offline { background: #64748B; }

/* ── Toast ── */
@keyframes msgToastSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
#msgToast {
    position: fixed; bottom: 30px; left: 50%;
    transform: translateX(-50%);
    background: rgba(59,130,246,0.92); color: white;
    padding: 14px 28px; border-radius: 12px;
    font-weight: 600; font-size: 0.9rem;
    z-index: 99999; display: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-width: 500px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#msgToast.show {
    display: block !important;
    animation: msgToastSlideUp 0.3s ease;
}

/* ── Group Create Modal ── */
.msg-modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; opacity: 0; visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.msg-modal-overlay.show { opacity: 1; visibility: visible; }
.msg-modal-content {
    background: rgba(15,23,42,0.95); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px; width: 420px; max-width: 95vw;
    overflow-y: auto; display: flex; flex-direction: column;
    transform: translateY(20px); transition: transform 0.3s;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}
.msg-modal-overlay.show .msg-modal-content { transform: translateY(0); }
.msg-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex; justify-content: space-between; align-items: center;
}
.msg-modal-header h2 { font-size: 1.1rem; font-weight: 700; color: #F8FAFC; }
.msg-modal-body { padding: 24px; }
.msg-modal-footer {
    padding: 14px 24px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex; justify-content: flex-end; gap: 10px;
}
.msg-form-group { margin-bottom: 16px; }
.msg-form-group label {
    font-size: 0.85rem; color: var(--text-secondary);
    margin-bottom: 8px; display: block; font-weight: 600;
}
.msg-form-group input {
    width: 100%; padding: 12px;
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    outline: none; font-family: inherit;
    font-size: 0.9rem;
    box-sizing: border-box;
}
.msg-form-group input:focus { border-color: var(--accent-blue); }

.msg-btn-primary {
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    color: white; border: none;
    padding: 10px 22px; border-radius: 10px;
    font-weight: 600; cursor: pointer; font-family: inherit;
    font-size: 0.88rem;
}
.msg-btn-secondary {
    background: rgba(255,255,255,0.07);
    color: #94A3B8;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 10px 22px; border-radius: 10px;
    font-weight: 600; cursor: pointer; font-family: inherit;
}

/* ══════════════════════════════════════════════
   v5 New Features Styles
   ══════════════════════════════════════════════ */

/* ── 대화 검색 바 ── */
.chat-search-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid var(--border-color);
    animation: slideDown 0.2s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-search-bar input {
    flex: 1; background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-color); color: var(--text-primary);
    padding: 8px 14px; border-radius: 8px; font-family: inherit; font-size: 0.88rem;
    outline: none;
}
.chat-search-bar input:focus { border-color: var(--accent-blue); }
.chat-search-bar span { color: var(--text-secondary); font-size: 0.78rem; white-space: nowrap; min-width: 50px; text-align: center; }
.chat-search-bar button {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; font-size: 0.9rem; padding: 4px 6px; border-radius: 4px;
    transition: var(--transition);
}
.chat-search-bar button:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }

/* ── 이모티콘 선택기 ── */
.emoji-picker {
    position: absolute; bottom: 100%; left: 0; right: 0;
    background: rgba(15,23,42,0.97); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    z-index: 100; max-height: 280px;
    animation: emojiSlideUp 0.25s ease;
}
@keyframes emojiSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.emoji-tabs {
    display: flex; gap: 2px; padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.emoji-tab {
    background: none; border: none; font-size: 1.3rem; cursor: pointer;
    padding: 6px 10px; border-radius: 8px; transition: var(--transition);
    opacity: 0.5;
}
.emoji-tab:hover { opacity: 0.8; background: rgba(255,255,255,0.06); }
.emoji-tab.active { opacity: 1; background: rgba(59,130,246,0.2); }
.emoji-grid {
    display: grid; grid-template-columns: repeat(10, 1fr);
    gap: 2px; padding: 10px 12px; max-height: 200px; overflow-y: auto;
}
.emoji-grid span {
    font-size: 1.5rem; text-align: center; cursor: pointer;
    padding: 4px; border-radius: 6px; transition: var(--transition);
    line-height: 1.4;
}
.emoji-grid span:hover { background: rgba(255,255,255,0.1); transform: scale(1.2); }

/* ── 읽음 확인 표시 ── */
.msg-read-status {
    font-size: 0.7rem; color: var(--text-secondary);
    display: flex; align-items: center; gap: 3px; margin-top: 2px;
}
.msg-read-status.read { color: #3B82F6; }
.msg-read-status i { font-size: 0.65rem; }

/* ── 메시지 삭제 버튼 ── */
.msg-wrapper:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn {
    opacity: 0; background: none; border: none;
    color: var(--text-secondary); cursor: pointer;
    font-size: 0.75rem; padding: 2px 5px; border-radius: 4px;
    transition: var(--transition); margin-left: 4px;
}
.msg-delete-btn:hover { color: #EF4444; background: rgba(239,68,68,0.15); }

/* ── 채널 고정 표시 ── */
.channel-item.pinned {
    background: rgba(234,179,8,0.08);
}
.channel-item.pinned .pin-icon {
    color: #EAB308; font-size: 0.7rem; margin-left: 4px;
}
#btnPinChannel.pinned i { color: #EAB308; }

/* ── 타이핑 인디케이터 ── */
.typing-indicator {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px; font-size: 0.82rem; color: var(--text-secondary);
    font-style: italic;
}
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary);
    animation: typingBounce 1.4s ease-in-out 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); }
    30% { transform: translateY(-5px); }
}

/* ── 검색 하이라이트 ── */
.msg-bubble mark {
    background: rgba(234,179,8,0.4); color: inherit;
    padding: 1px 2px; border-radius: 2px;
}
.msg-bubble mark.current { background: rgba(59,130,246,0.6); }

/* ── chat-input-area position relative for emoji picker ── */
.chat-input-area { position: relative; }
