/* ─── VARIABLES ─── */
:root {
  --bg-app:        #0e1621;
  --bg-panel:      #17212b;
  --bg-panel2:     #1e2c3a;
  --bg-input:      #253340;
  --bg-msg-out:    #2b5278;
  --bg-msg-in:     #182533;
  --bg-hover:      #1c2f3f;
  --accent:        #5288c1;
  --accent-light:  #6ea3d9;
  --accent-green:  #4dcd7f;
  --danger:        #e05151;
  --warn:          #f0a045;
  --text-primary:  #e8ecef;
  --text-secondary:#7d9ab5;
  --text-hint:     #4a6380;
  --border:        #1a2d3e;
  --online:        #4dcd7f;
  --radius:        10px;
  --panel-w:       260px;
}

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg-app); color: var(--text-primary); overflow: hidden; }

/* ─── MODALS ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}

.modal-box {
  background: var(--bg-panel); border-radius: 14px; padding: 36px 28px;
  width: 100%; max-width: 360px; text-align: center;
  animation: popIn 0.22s ease; box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

@keyframes popIn {
  from { transform: scale(0.93) translateY(-10px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);     opacity: 1; }
}

.modal-icon { font-size: 48px; margin-bottom: 14px; line-height: 1; }
.modal-box h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.modal-box p  { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 20px; line-height: 1.5; }

.modal-box input {
  width: 100%; padding: 12px 14px; background: var(--bg-input);
  border: 1.5px solid var(--border); border-radius: 8px;
  color: var(--text-primary); font-size: 15px; outline: none;
  margin-bottom: 6px; transition: border-color 0.2s;
}
.modal-box input:focus { border-color: var(--accent); }

.error-msg { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-bottom: 8px; text-align: left; padding-left: 2px; }

.modal-box button {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background 0.2s; margin-top: 4px;
}
.modal-box button:hover { background: var(--accent-light); }

.btn-secondary { background: var(--bg-input) !important; color: var(--text-secondary) !important; margin-top: 8px !important; }
.btn-secondary:hover { background: var(--bg-hover) !important; }

.username-rules { color: var(--text-hint); font-size: 12px; margin-top: 10px; }

/* ─── APP LAYOUT ─── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ─── LEFT PANEL ─── */
.left-panel {
  width: var(--panel-w); flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: transform 0.25s ease;
}

.close-panel-btn {
  display: none;
  position: absolute; top: 10px; right: 10px;
  background: var(--bg-input); border: none;
  color: var(--text-secondary); font-size: 16px;
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; z-index: 5;
  align-items: center; justify-content: center;
}

/* Group header in panel */
.group-header {
  padding: 28px 20px 20px;
  display: flex; flex-direction: column; align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel2);
}

.group-avatar-wrap {
  position: relative;
  margin-bottom: 12px;
  cursor: default;
}

.group-avatar-circle {
  width: 80px; height: 80px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #3a6da0);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 800; color: #fff;
  overflow: hidden; position: relative;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.group-avatar-circle img {
  width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0;
}

.avatar-upload-label {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(0,0,0,0.55); display: flex;
  align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer;
  opacity: 0; transition: opacity 0.2s;
  border-radius: 50%;
}

.group-avatar-wrap:hover .avatar-upload-label { opacity: 1; }

.group-title {
  font-size: 17px; font-weight: 700;
  color: var(--text-primary); margin-bottom: 4px;
}

.group-subtitle {
  font-size: 12.5px; color: var(--text-secondary);
}

/* Members section */
.members-section {
  flex: 1; overflow-y: auto; padding: 12px 0;
}

.members-section::-webkit-scrollbar { width: 4px; }
.members-section::-webkit-scrollbar-track { background: transparent; }
.members-section::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.members-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-hint);
  padding: 4px 16px 10px;
}

.members-list { display: flex; flex-direction: column; }

.member-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px; cursor: default;
  transition: background 0.15s;
}
.member-item:hover { background: var(--bg-hover); }

.member-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--online); flex-shrink: 0;
  box-shadow: 0 0 6px var(--online);
}

.member-dot.admin-dot   { background: var(--online); box-shadow: 0 0 6px var(--online); }
.member-dot.offline-dot { background: var(--text-hint); box-shadow: none; opacity: 0.5; }

.member-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-input); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: var(--accent-light);
}

.member-info { flex: 1; min-width: 0; }
.member-name {
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member-role { font-size: 11px; color: var(--text-hint); margin-top: 1px; }

.member-actions { display: flex; gap: 3px; }
.mem-btn {
  padding: 3px 7px; border: none; border-radius: 4px;
  font-size: 10px; font-weight: 700; cursor: pointer;
  transition: opacity 0.2s; white-space: nowrap;
}
.mem-btn:hover { opacity: 0.8; }
.mem-kick   { background: var(--warn);   color: #000; }
.mem-ban    { background: var(--danger); color: #fff; }
.mem-mute   { background: #5b6fd6;       color: #fff; }
.mem-unmute { background: var(--accent-green); color: #000; }

/* ─── CHAT AREA ─── */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Chat header */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  height: 58px; flex-shrink: 0; z-index: 10;
}

.panel-toggle-btn {
  background: none; border: none; color: var(--text-secondary);
  font-size: 20px; cursor: pointer; padding: 6px; border-radius: 6px;
  transition: background 0.2s; display: none; line-height: 1;
}
.panel-toggle-btn:hover { background: var(--bg-input); color: var(--text-primary); }

.chat-header-info { flex: 1; }
.chat-header-name { font-size: 16px; font-weight: 700; }
.chat-header-sub  { font-size: 12px; color: var(--accent-green); margin-top: 1px; }

.header-right { display: flex; align-items: center; gap: 8px; }

.admin-badge {
  background: var(--accent); color: #fff;
  padding: 3px 9px; border-radius: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
}

.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 19px; padding: 6px; border-radius: 50%;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s; line-height: 1;
}
.icon-btn:hover { background: var(--bg-input); color: var(--text-primary); }

/* ─── MESSAGES ─── */
.messages-area {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 3px;
  position: relative;
}

.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Scroll button */
.scroll-btn {
  position: absolute; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel); color: var(--accent);
  border: 1px solid var(--accent); padding: 6px 16px;
  border-radius: 20px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; z-index: 20; box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  white-space: nowrap; transition: background 0.2s;
}
.scroll-btn:hover { background: var(--bg-input); }

/* Message wrappers */
.msg-wrapper { display: flex; flex-direction: column; max-width: 74%; }
.msg-wrapper.out { align-self: flex-end; align-items: flex-end; }
.msg-wrapper.in  { align-self: flex-start; align-items: flex-start; }

.msg-username {
  font-size: 12px; font-weight: 700; margin-bottom: 3px; padding: 0 6px;
  color: var(--accent-light);
}

.msg-bubble {
  padding: 7px 12px 6px; border-radius: 10px;
  max-width: 100%; word-break: break-word; overflow-wrap: anywhere;
  position: relative;
}
.msg-wrapper.out .msg-bubble { background: var(--bg-msg-out); border-top-right-radius: 2px; }
.msg-wrapper.in  .msg-bubble { background: var(--bg-msg-in);  border-top-left-radius: 2px; }
.msg-bubble.admin-hover:hover { outline: 1px solid var(--accent); cursor: context-menu; }

.msg-text { font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; }
.msg-text a { color: var(--accent-light); text-decoration: none; }
.msg-text a:hover { text-decoration: underline; }

.msg-img { display: block; max-width: 280px; max-height: 240px; border-radius: 7px; cursor: zoom-in; object-fit: cover; margin-bottom: 4px; }

.msg-meta { display: flex; align-items: center; gap: 5px; margin-top: 3px; }
.msg-time  { font-size: 11px; color: rgba(255,255,255,0.65); }

/* @mention highlight in messages */
.mention { color: var(--accent-light); font-weight: 600; }

/* Link preview card */
.link-preview {
  margin-top: 8px; background: rgba(0,0,0,0.25);
  border-left: 3px solid var(--accent); border-radius: 6px;
  overflow: hidden; cursor: pointer; transition: background 0.2s;
  max-width: 320px; text-decoration: none; display: block;
}
.link-preview:hover { background: rgba(0,0,0,0.4); }

.lp-thumb { width: 100%; max-height: 140px; object-fit: cover; display: block; }

.lp-body { padding: 8px 10px; }
.lp-site { font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 3px; }
.lp-title { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; line-height: 1.3; }
.lp-desc  { font-size: 12px; color: var(--text-secondary); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* System messages */
.system-msg {
  align-self: center; background: rgba(0,0,0,0.3);
  color: var(--text-secondary); font-size: 12px;
  padding: 4px 14px; border-radius: 12px;
  margin: 6px 0; user-select: none;
}

/* System event messages (kick / ban / mute) */
.system-event {
  background: rgba(82,136,193,0.12) !important;
  border: 1px solid rgba(82,136,193,0.25);
  color: var(--text-secondary) !important;
  font-size: 12.5px !important;
  padding: 5px 16px !important;
}

/* Upload indicator */
.upload-indicator {
  align-self: flex-end; background: var(--bg-msg-out);
  border-radius: 10px; padding: 10px 16px;
  font-size: 13px; color: var(--text-secondary);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

/* ─── INPUT AREA ─── */
.input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px 10px; background: var(--bg-panel);
  border-top: 1px solid var(--border); flex-shrink: 0;
}

.attach-btn {
  font-size: 22px; cursor: pointer; padding: 7px;
  border-radius: 50%; color: var(--text-secondary);
  transition: background 0.2s, color 0.2s; user-select: none; line-height: 1;
}
.attach-btn:hover { background: var(--bg-input); color: var(--text-primary); }

.input-wrapper {
  flex: 1; background: var(--bg-input); border-radius: 22px;
  padding: 10px 16px; min-height: 42px; display: flex; align-items: center;
}
.input-wrapper textarea {
  width: 100%; background: none; border: none; color: var(--text-primary);
  font-size: 14.5px; outline: none; resize: none;
  max-height: 130px; overflow-y: auto; font-family: inherit; line-height: 1.45;
}
.input-wrapper textarea::placeholder { color: var(--text-hint); }

.send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
}
.send-btn:hover  { background: var(--accent-light); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { background: var(--bg-input); cursor: not-allowed; opacity: 0.5; }

/* ─── LIGHTBOX ─── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.96);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
#lightbox-close {
  position: absolute; top: 16px; right: 18px;
  background: rgba(255,255,255,0.1); border: none; color: #fff;
  font-size: 20px; width: 42px; height: 42px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
#lightbox-close:hover { background: rgba(255,255,255,0.2); }
#lightbox-img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: 6px; box-shadow: 0 8px 40px rgba(0,0,0,0.6); }

/* ─── CONTEXT MENU ─── */
.context-menu {
  position: fixed; background: var(--bg-panel2); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; z-index: 3000;
  min-width: 175px; box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  animation: fadeIn 0.12s ease;
}
@keyframes fadeIn { from { opacity:0; transform:scale(.95); } to { opacity:1; transform:scale(1); } }

.ctx-item { padding: 10px 16px; font-size: 13.5px; cursor: pointer; color: var(--text-primary); transition: background 0.15s; user-select: none; }
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 2px 0; }

/* ─── IMAGE SEND PREVIEW ─── */
.img-preview-box {
  background: #0a0f14;
  border-radius: 14px;
  width: 92%;
  max-width: 480px;
  overflow: hidden;
  box-shadow: 0 16px 50px rgba(0,0,0,0.7);
  animation: popIn 0.2s ease;
}

.img-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-panel);
  font-size: 15px;
  font-weight: 600;
}

.img-hdr-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}
.img-hdr-btn:hover { background: var(--bg-input); color: var(--text-primary); }

.img-send {
  background: var(--accent);
  color: #fff !important;
  font-weight: 600;
  border-radius: 20px;
  padding: 6px 16px !important;
}
.img-send:hover { background: var(--accent-light) !important; }

.img-preview-body {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: 58vh;
  overflow: hidden;
}

#img-preview-thumb {
  max-width: 100%;
  max-height: 58vh;
  object-fit: contain;
  display: block;
}

.img-preview-footer {
  padding: 12px 16px;
  background: var(--bg-panel);
}

.img-preview-footer input {
  width: 100%;
  background: var(--bg-input);
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.img-preview-footer input::placeholder { color: var(--text-hint); }

/* ─── PROFILE MODAL ─── */
.profile-box {
  background: var(--bg-panel); border-radius: 16px;
  width: 100%; max-width: 360px;
  padding: 36px 28px 28px; text-align: center;
  animation: popIn 0.22s ease; box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  position: relative;
}

.profile-close-btn {
  position: absolute; top: 12px; right: 12px;
  background: var(--bg-input); border: none; color: var(--text-secondary);
  font-size: 14px; width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.profile-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.profile-avatar-wrap {
  position: relative; width: 90px; height: 90px; margin: 0 auto 16px;
}

.profile-avatar-circle {
  width: 90px; height: 90px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #3a6da0);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 800; color: #fff; overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.profile-avatar-circle img { width: 100%; height: 100%; object-fit: cover; display: block; }

.profile-username { font-size: 20px; font-weight: 700; margin-bottom: 6px; }

.profile-badge {
  font-size: 12px; font-weight: 700; background: var(--accent); color: #fff;
  padding: 3px 12px; border-radius: 20px; display: inline-block; margin-bottom: 14px;
}

.profile-bio-view {
  font-size: 13.5px; color: var(--text-secondary); line-height: 1.55;
  min-height: 20px; margin-bottom: 8px; white-space: pre-wrap; word-break: break-word;
  font-style: italic;
}

.profile-bio-edit {
  width: 100%; background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text-primary);
  font-size: 14px; outline: none; resize: none; height: 80px;
  margin-bottom: 8px; font-family: inherit; line-height: 1.5;
  transition: border-color 0.2s; font-style: normal;
}
.profile-bio-edit:focus { border-color: var(--accent); }

.profile-joined { font-size: 12px; color: var(--text-hint); margin-bottom: 20px; }

.profile-footer { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.profile-footer button {
  padding: 10px 22px; font-size: 14px; font-weight: 600;
  border: none; border-radius: 8px; cursor: pointer; transition: background 0.2s;
}
#profile-edit-btn, #profile-save-btn { background: var(--accent); color: #fff; }
#profile-edit-btn:hover, #profile-save-btn:hover { background: var(--accent-light); }
#profile-cancel-btn { background: var(--bg-input) !important; color: var(--text-secondary) !important; }
#profile-cancel-btn:hover { background: var(--bg-hover) !important; }

/* Profile pic in member list */
.member-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.member-item { cursor: pointer; }

/* ─── MENTION DROPDOWN ─── */
.mention-dropdown {
  background: var(--bg-panel2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 180px;
  overflow-y: auto;
}

.mention-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; cursor: pointer;
  transition: background 0.15s;
}
.mention-item:hover,
.mention-item.selected { background: var(--bg-hover); }

.mention-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--accent-light); flex-shrink: 0;
}

.mention-name { font-size: 14px; font-weight: 500; }

/* ─── EMOJI PICKER ─── */
.emoji-picker {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  height: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel2);
  flex-shrink: 0;
}

.emoji-tab {
  flex: 1; padding: 9px 4px;
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: background 0.15s;
  line-height: 1;
}
.emoji-tab:hover { background: var(--bg-hover); }
.emoji-tab.active { border-bottom-color: var(--accent); background: var(--bg-hover); }

.emoji-grid {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, 40px);
  gap: 1px; padding: 6px;
  align-content: start;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-track { background: transparent; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.emoji-item {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; cursor: pointer;
  border: none; background: none;
  border-radius: 6px;
  transition: background 0.1s; line-height: 1;
}
.emoji-item:hover { background: var(--bg-hover); }

/* ─── UTILITIES ─── */
.hidden { display: none !important; }

/* ─── RESPONSIVE — mobile ─── */
@media (max-width: 700px) {
  .left-panel {
    position: fixed; inset: 0 auto 0 0; z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .left-panel.open { transform: translateX(0); }
  .close-panel-btn { display: flex; }
  .panel-toggle-btn { display: flex; }
  .msg-wrapper { max-width: 90%; }
}
