/* ===== SIDEBAR ===== */
.sidebar { width: var(--sidebar-width); background: #fff; border-right: 1px solid #e5e5e5; display: flex; flex-direction: column; flex-shrink: 0; height: 100vh; height: 100dvh; }
.sidebar-header { padding: 16px 20px; background: var(--primary-gradient); color: #fff; flex-shrink: 0; }
.sidebar-header h2 { font-size: 20px; }
.sidebar-header .user-info { font-size: 12px; opacity: 0.85; margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.online-badge { display: inline-block; width: 8px; height: 8px; background: var(--success); border-radius: 50%; }
.icon-btn { background: rgba(255,255,255,0.2); border: none; color: #fff; padding: 2px 8px; border-radius: 8px; font-size: 14px; cursor: pointer; line-height: 1; }
.icon-btn:hover { background: rgba(255,255,255,0.3); }
.logout-btn { background: rgba(255,255,255,0.2); border: none; color: #fff; padding: 3px 10px; border-radius: 8px; font-size: 11px; cursor: pointer; margin-left: auto; }
.logout-btn:hover { background: rgba(255,255,255,0.3); }

.sidebar-tabs { display: flex; border-bottom: 1px solid #eee; flex-shrink: 0; }
.sidebar-tabs button { flex: 1; padding: 12px; border: none; background: #fff; font-size: 13px; cursor: pointer; color: #999; border-bottom: 2px solid transparent; transition: all 0.2s; }
.sidebar-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.room-actions { padding: 10px 16px; border-bottom: 1px solid #eee; flex-shrink: 0; display: flex; gap: 8px; }
.room-actions button { flex: 1; padding: 10px; border: 2px dashed #ccc; border-radius: 12px; background: transparent; cursor: pointer; color: #888; font-size: 13px; transition: all 0.2s; }
.room-actions button:hover { border-color: var(--primary); color: var(--primary); }
.panel-content { flex: 1; overflow-y: auto; min-height: 0; }

.room-item { display: flex; align-items: center; padding: 14px 16px; cursor: pointer; transition: background 0.15s; border-bottom: 1px solid #f5f5f5; position: relative; }
.room-item:hover { background: #f8f8f8; }
.room-item.active { background: #f0e6ff; }
.room-item.joined::after { content: '참여중'; position: absolute; top: 8px; right: 12px; font-size: 10px; color: var(--success); background: #e8fdf0; padding: 2px 8px; border-radius: 8px; }
.room-item.pinned { background: #fffdf0; }
.room-item.pinned::before { content: '📌'; position: absolute; top: 8px; left: 8px; font-size: 10px; }
.room-icon { width: 48px; height: 48px; border-radius: 16px; margin-right: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; font-weight: bold; flex-shrink: 0; }
.room-info { flex: 1; min-width: 0; padding-right: 50px; }
.room-name { font-weight: 600; font-size: 15px; color: #333; display: flex; align-items: center; gap: 6px; }
.room-name .mute-icon { font-size: 12px; color: #bbb; }
.room-preview { font-size: 12px; color: #999; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { position: absolute; right: 12px; bottom: 14px; text-align: right; }
.room-time { font-size: 11px; color: #bbb; }
.room-count { font-size: 11px; color: #999; }
.unread-badge { display: inline-block; background: var(--danger); color: #fff; font-size: 11px; font-weight: bold; padding: 2px 7px; border-radius: 10px; min-width: 20px; text-align: center; margin-top: 2px; }

/* ===== CHAT AREA ===== */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.chat-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; opacity: 0.6; }
.chat-header { padding: 14px 20px; background: #fff; border-bottom: 1px solid #e5e5e5; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.chat-header h3 { font-size: 17px; color: #333; }
.chat-header-actions { display: flex; gap: 8px; align-items: center; }
.chat-header-actions button, .chat-header-actions .member-count { font-size: 12px; padding: 5px 12px; border-radius: 10px; cursor: pointer; border: 1px solid #ddd; background: #fff; color: #666; transition: all 0.2s; }
.chat-header-actions button:hover, .chat-header-actions .member-count:hover { background: #f5f5f5; }
.chat-header-actions .active-toggle { background: var(--primary); color: #fff; border-color: var(--primary); }
.leave-btn { border-color: var(--danger) !important; color: var(--danger) !important; }
.leave-btn:hover { background: var(--danger) !important; color: #fff !important; }

/* Pinned message bar */
.pinned-bar { display: none; padding: 8px 16px; background: #fffde7; border-bottom: 1px solid #f0e68c; flex-shrink: 0; font-size: 13px; cursor: pointer; }
.pinned-bar.show { display: flex; align-items: center; gap: 8px; }
.pinned-bar .pin-icon { font-size: 16px; }
.pinned-bar .pin-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #555; }
.pinned-bar .pin-close { background: none; border: none; cursor: pointer; font-size: 14px; color: #999; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.load-more { text-align: center; padding: 10px; }
.load-more button { padding: 6px 20px; border: 1px solid #aaa; background: rgba(255,255,255,0.7); border-radius: 20px; cursor: pointer; font-size: 12px; color: #666; }
.typing-indicator { padding: 4px 20px; font-size: 12px; color: #666; min-height: 24px; flex-shrink: 0; }
.rate-warning { display: none; padding: 6px 16px; background: #fff3cd; color: #856404; font-size: 12px; text-align: center; flex-shrink: 0; }
.rate-warning.show { display: block; }

/* Date separator */
.date-separator { text-align: center; padding: 12px 0 8px; }
.date-separator span { background: rgba(0,0,0,0.12); color: #fff; padding: 4px 16px; border-radius: 20px; font-size: 12px; }

/* Reply preview (above input) */
.reply-preview { display: none; padding: 8px 16px; background: #f8f8ff; border-top: 1px solid #e0e0e0; border-left: 3px solid var(--primary); flex-shrink: 0; font-size: 13px; }
.reply-preview.show { display: flex; align-items: center; gap: 8px; }
.reply-preview .reply-info { flex: 1; overflow: hidden; }
.reply-preview .reply-nick { font-weight: 600; color: var(--primary); font-size: 12px; }
.reply-preview .reply-text { color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview .reply-cancel { background: none; border: none; cursor: pointer; font-size: 18px; color: #999; padding: 4px; }

/* Input area */
.upload-preview { display: none; padding: 8px 16px; background: #fff; border-top: 1px solid #eee; align-items: center; gap: 10px; flex-shrink: 0; }
.upload-preview.show { display: flex; }
.upload-preview img { height: 60px; border-radius: 8px; }
.cancel-upload { background: none; border: none; font-size: 20px; cursor: pointer; color: #999; }
.input-area { padding: 10px 16px; background: #fff; border-top: 1px solid #e5e5e5; display: flex; align-items: flex-end; gap: 10px; flex-shrink: 0; }
.input-tools { display: flex; gap: 6px; }
.tool-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: #f5f5f5; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.tool-btn:hover { background: #e8e8e8; }
.input-box { flex: 1; position: relative; }
.input-box textarea { width: 100%; padding: 10px 14px; border: 2px solid #e0e0e0; border-radius: 20px; font-size: 14px; outline: none; resize: none; max-height: 100px; line-height: 1.4; font-family: inherit; transition: border-color 0.2s; }
.input-box textarea:focus { border-color: var(--primary); }
.send-btn { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--primary-gradient); color: #fff; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.1s; flex-shrink: 0; }
.send-btn:active { transform: scale(0.9); }

/* Mention dropdown */
.mention-dropdown { display: none; position: absolute; bottom: 100%; left: 0; background: #fff; border: 1px solid #ddd; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); max-height: 200px; overflow-y: auto; z-index: 50; width: 240px; }
.mention-dropdown.show { display: block; }
.mention-item { padding: 8px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.mention-item:hover { background: #f0e6ff; }
.mention-item .m-avatar { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: bold; }

/* Emoji picker */
.emoji-picker { display: none; position: absolute; bottom: 56px; left: 0; background: #fff; border-radius: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); padding: 12px; width: 320px; max-height: 240px; overflow-y: auto; z-index: 100; }
.emoji-picker.show { display: block; }
.emoji-picker span { display: inline-block; font-size: 24px; padding: 4px; cursor: pointer; border-radius: 6px; transition: background 0.15s; }
.emoji-picker span:hover { background: #f0f0f0; }

/* Reaction bar under message */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; border-radius: 12px; font-size: 13px; cursor: pointer; border: 1px solid #e0e0e0; background: #fff; transition: all 0.15s; }
.reaction-chip:hover { background: #f0e6ff; }
.reaction-chip.mine { background: #ede7f6; border-color: var(--primary); }
.reaction-chip .r-count { font-size: 11px; color: #666; }

/* Reaction picker (mini) */
.reaction-picker { display: none; position: absolute; background: #fff; border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 6px 10px; z-index: 150; white-space: nowrap; }
.reaction-picker.show { display: flex; gap: 2px; }
.reaction-picker span { font-size: 22px; cursor: pointer; padding: 2px 4px; border-radius: 8px; transition: transform 0.15s; }
.reaction-picker span:hover { transform: scale(1.3); background: #f0f0f0; }

/* Reply bubble inside message */
.reply-ref { background: rgba(0,0,0,0.06); border-left: 3px solid var(--primary); border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; font-size: 12px; cursor: pointer; }
.reply-ref .reply-ref-nick { font-weight: 600; color: var(--primary); }
.reply-ref .reply-ref-text { color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; display: block; }

/* Message bubbles */
.msg-system { text-align: center; padding: 8px 0; }
.msg-system span { background: rgba(0,0,0,0.15); color: #fff; padding: 4px 14px; border-radius: 20px; font-size: 12px; }
.msg-wrapper { display: flex; align-items: flex-start; margin-bottom: 2px; position: relative; }
.msg-wrapper.mine { flex-direction: row-reverse; }
.msg-avatar { width: 38px; height: 38px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: bold; font-size: 15px; flex-shrink: 0; }
.msg-wrapper.mine .msg-avatar { display: none; }
/* Grouped message (same sender, consecutive) */
.msg-wrapper.grouped .msg-avatar { width: 38px; visibility: hidden; }
.msg-wrapper.grouped .msg-nickname { display: none; }
.msg-wrapper.mine.grouped .msg-avatar { width: 0; }
.msg-body { margin: 0 8px; max-width: 65%; }
.msg-nickname { font-size: 12px; color: #555; margin-bottom: 3px; font-weight: 500; }
.msg-wrapper.mine .msg-nickname { display: none; }
.msg-bubble { padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.msg-wrapper:not(.mine) .msg-bubble { background: #fff; color: #333; border-top-left-radius: 4px; }
.msg-wrapper.mine .msg-bubble { background: #FFEB33; color: #333; border-top-right-radius: 4px; }
.msg-bubble img { max-width: 240px; border-radius: 10px; display: block; cursor: pointer; }
.msg-bubble .emoji-only { font-size: 40px; line-height: 1.2; }
.msg-bubble .mention { color: var(--primary); font-weight: 600; cursor: pointer; }
.msg-deleted { font-style: italic; color: #999; }
.msg-file { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(0,0,0,0.03); border-radius: 10px; cursor: pointer; text-decoration: none; color: inherit; transition: background 0.2s; min-width: 180px; }
.msg-file:hover { background: rgba(0,0,0,0.07); }
.msg-file-icon { font-size: 28px; flex-shrink: 0; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name { font-size: 13px; font-weight: 600; color: #333; word-break: break-all; line-height: 1.3; }
.msg-file-meta { font-size: 11px; color: #999; margin-top: 2px; }
.msg-file-dl { font-size: 18px; color: var(--primary); flex-shrink: 0; }
.upload-file-preview { display: none; padding: 8px 16px; background: #fff; border-top: 1px solid #eee; align-items: center; gap: 10px; flex-shrink: 0; }
.upload-file-preview.show { display: flex; }
.upload-file-preview .file-info { flex: 1; font-size: 13px; color: #555; display: flex; align-items: center; gap: 6px; }
.upload-file-preview .file-info .ficon { font-size: 20px; }
.msg-meta { display: flex; align-items: flex-end; gap: 4px; margin-top: 2px; }
.msg-wrapper.mine .msg-meta { flex-direction: row-reverse; }
.msg-time { font-size: 11px; color: #999; }
.msg-read { font-size: 11px; color: var(--primary); font-weight: 600; }
