/* ── RESET & BASE ────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --sidebar-bg: #1a1d21;
  --sidebar-hover: #27292d;
  --sidebar-active: #1164a3;
  --main-bg: #1d1f23;
  --input-bg: #2b2d31;
  --border: #3f4147;
  --text: #d1d2d3;
  --text-muted: #8b8d91;
  --text-bright: #f2f3f5;
  --accent: #1164a3;
  --accent-hover: #0d4f86;
  --danger: #e03e3e;
  --green: #23a55a;
  --msg-hover: #2b2d31;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
body { font-family: var(--font); background: var(--main-bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ── AUTH SCREEN ─────────────────────────────────── */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: #0f1117;
}
.auth-box {
  background: var(--sidebar-bg); border-radius: 12px; padding: 40px;
  width: 100%; max-width: 420px; border: 1px solid var(--border);
}
.auth-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.auth-box h1 { text-align: center; color: var(--text-bright); font-size: 22px; margin-bottom: 6px; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.auth-tabs { display: flex; margin-bottom: 24px; border-radius: 8px; overflow: hidden; background: var(--input-bg); }
.tab-btn { flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 14px; transition: all .2s; }
.tab-btn.active { background: var(--accent); color: #fff; }
.auth-box input {
  width: 100%; padding: 11px 14px; margin-bottom: 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text-bright);
  font-size: 14px; outline: none; transition: border .2s;
}
.auth-box input:focus { border-color: var(--accent); }
.pwd-wrap { position: relative; margin-bottom: 12px; }
.pwd-wrap input { margin-bottom: 0; padding-right: 40px; }
.btn-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 0; font-size: 15px;
  color: var(--text-muted); line-height: 1; opacity: .7;
}
.btn-eye:hover { opacity: 1; }
.modal .pwd-wrap input { margin-bottom: 0; }
.btn-primary {
  width: 100%; padding: 12px; border: none; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .2s; margin-top: 4px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.auth-error { color: #e05c5c; font-size: 13px; margin-top: 10px; min-height: 18px; }

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

/* ── SIDEBAR ─────────────────────────────────────── */
#sidebar {
  width: 260px; min-width: 200px; background: var(--sidebar-bg);
  display: flex; flex-direction: column; border-right: 1px solid var(--border);
  flex-shrink: 0; height: 100vh; overflow: hidden;
}
.workspace-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--border);
}
.workspace-name { font-weight: 700; font-size: 16px; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
#sidebar-content { flex: 1; min-height: 0; overflow-y: auto; }
#sidebar-content::-webkit-scrollbar { width: 4px; }
#sidebar-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar-section { padding: 16px 0 8px; flex: 0 0 auto; overflow: visible; }
.sidebar-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 6px; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
}
.btn-icon {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 2px; transition: color .2s;
}
.btn-icon:hover { color: var(--text-bright); }
#channels-list, #dm-list { list-style: none; }
#channels-list li, #dm-list li {
  padding: 5px 16px; cursor: pointer; border-radius: 6px; margin: 1px 8px;
  font-size: 15px; color: var(--text-muted); transition: background .15s, color .15s;
  display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#channels-list li:hover, #dm-list li:hover { background: var(--sidebar-hover); color: var(--text); }
#channels-list li.active, #dm-list li.active { background: var(--sidebar-active); color: #fff; }
.channel-hash { color: var(--text-muted); font-size: 16px; }
li.active .channel-hash { color: rgba(255,255,255,.7); }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-bright); margin-left: auto; flex-shrink: 0; }
.unread-badge {
  margin-left: auto; flex-shrink: 0;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
#channels-list li.has-unread,
#dm-users-list li.has-unread { color: var(--text-bright); font-weight: 600; }
li.active .unread-badge { display: none; }

/* ── DM USER LIST ────────────────────────────────── */
#dm-users-list { list-style: none; }
#dm-users-list li {
  padding: 4px 16px; cursor: pointer; border-radius: 6px; margin: 1px 8px;
  font-size: 14px; color: var(--text-muted); transition: background .15s, color .15s;
  display: flex; align-items: center; gap: 8px;
}
#dm-users-list li:hover { background: var(--sidebar-hover); color: var(--text); }
#dm-users-list li.active { background: var(--sidebar-active); color: #fff; }

.dm-avatar-wrap { position: relative; flex-shrink: 0; }
.dm-avatar-wrap .avatar { width: 26px; height: 26px; font-size: 11px; border-radius: 5px; }
.presence-dot {
  position: absolute; bottom: -2px; right: -2px;
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--sidebar-bg);
  background: var(--text-muted); /* offline by default */
}
.presence-dot.online { background: var(--green); }
#dm-users-list li.active .presence-dot { border-color: var(--sidebar-active); }

.dm-user-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── DM AREA ─────────────────────────────────────── */
#dm-area { display: flex; flex-direction: column; height: 100%; }
#dm-area .dm-chat-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#dm-area .dm-chat-header .avatar { width: 32px; height: 32px; font-size: 13px; }
#dm-area .dm-chat-title { font-weight: 700; font-size: 16px; color: var(--text-bright); }
.dm-messages-container { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; }
.dm-messages-container::-webkit-scrollbar { width: 6px; }
.dm-messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#dm-messages-list { flex: 1; padding: 0 20px; }
.dm-input-area { padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-top: 1px solid var(--border); background: var(--sidebar-bg);
  flex-shrink: 0;
}
.avatar {
  width: 32px; height: 32px; border-radius: 6px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0; text-transform: uppercase;
  transition: background .2s;
}
.sidebar-user-info { flex: 1; overflow: hidden; }
.sidebar-user-name { font-size: 14px; font-weight: 600; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--text-muted); }

/* ── MAIN AREA ───────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--text-muted); gap: 12px;
}
.empty-icon { font-size: 64px; }
#empty-state p { font-size: 16px; }

#chat-area { display: flex; flex-direction: column; height: 100%; }
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#chat-name { font-weight: 700; font-size: 16px; color: var(--text-bright); }
#chat-name::before { content: '#'; color: var(--text-muted); margin-right: 2px; }
.chat-desc { font-size: 13px; color: var(--text-muted); margin-left: 10px; }
.members-count { font-size: 13px; color: var(--text-muted); }

/* ── MESSAGES ────────────────────────────────────── */
#messages-container { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; }
#messages-container::-webkit-scrollbar { width: 6px; }
#messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#messages-list { flex: 1; padding: 0 20px; }

.msg {
  display: flex; gap: 12px; padding: 6px 8px; border-radius: 6px;
  margin-bottom: 2px; transition: background .1s;
}
.msg:hover { background: var(--msg-hover); }
.msg.new-sender { margin-top: 14px; }
.msg-avatar { width: 36px; height: 36px; border-radius: 6px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0; text-transform: uppercase; transition: background .2s; }
.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg-author { font-weight: 700; font-size: 15px; color: var(--text-bright); }
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-text { font-size: 15px; color: var(--text); line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.msg-text.deleted { color: var(--text-muted); font-style: italic; }
.msg-compact .msg-avatar { visibility: hidden; }
.msg-compact .msg-header { display: none; }

.msg-file { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 10px 14px; background: var(--input-bg); border-radius: 8px; border: 1px solid var(--border); max-width: 320px; }
.msg-file-icon { display: flex; align-items: center; color: var(--text-muted); flex-shrink: 0; }
.msg-file-info { flex: 1; overflow: hidden; }
.msg-file-name { font-size: 14px; font-weight: 600; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-size { font-size: 12px; color: var(--text-muted); }
.msg-file-dl { padding: 5px 12px; background: var(--accent); color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 13px; }
.msg-file-dl:hover { background: var(--accent-hover); }

.typing-indicator { padding: 4px 20px 8px; font-size: 13px; color: var(--text-muted); min-height: 24px; font-style: italic; }

/* ── REPLY ───────────────────────────────────────── */
.msg-actions {
  display: none; align-items: center; gap: 4px;
  position: absolute; right: 8px; top: 4px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 4px;
}
.msg { position: relative; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 15px; padding: 2px 6px; border-radius: 4px; line-height: 1; }
.msg-actions button:hover { background: var(--sidebar-hover); color: var(--text-bright); }
.btn-delete-action:hover { color: #e74c3c !important; }

.reply-quote {
  display: flex; align-items: baseline; gap: 6px; padding: 4px 10px; margin-bottom: 4px;
  background: var(--sidebar-bg); border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0; font-size: 13px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  cursor: pointer; transition: background .15s;
}
.reply-quote:hover { background: var(--sidebar-hover); }
.reply-quote strong { color: var(--text); flex-shrink: 0; }
.reply-quote em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-style: normal; }

.msg-highlight { animation: highlight-flash 1.8s ease forwards; }
@keyframes highlight-flash {
  0%   { background: rgba(17,100,163,.35); }
  100% { background: transparent; }
}


.reply-preview {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; margin-bottom: 6px;
  background: var(--input-bg); border-radius: 6px; border-left: 3px solid var(--accent);
  font-size: 13px; color: var(--text-muted);
}
.reply-preview > span{
  display: flex; align-items: center; justify-items: center; justify-content: space-between; gap: 4px;
}

.date-divider { display: flex; align-items: center; gap: 12px; margin: 16px 0 8px; padding: 0 8px; }
.date-divider::before, .date-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.date-divider span { font-size: 12px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

.load-more-btn { display: block; margin: 8px auto; padding: 6px 16px; background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 6px; cursor: pointer; font-size: 13px; }
.load-more-btn:hover { background: var(--input-bg); }

/* ── INPUT AREA ──────────────────────────────────── */
#message-input-area {
  padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.upload-preview {
  display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; margin-bottom: 8px;
  background: var(--input-bg); border-radius: 6px; border: 1px solid var(--accent); font-size: 13px;
}
.upload-preview-row { display: flex; align-items: center; gap: 8px; }
#upload-filename, #dm-upload-filename { flex: 1; color: var(--text-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress-bar-wrap {
  width: 100%; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; display: none;
}
.upload-progress-bar {
  height: 100%; width: 0%; background: var(--accent); border-radius: 2px;
  transition: width .1s linear;
}
.input-row {
  display: flex; align-items: center; gap: 6px;
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 8px 6px 12px; transition: border-color .2s;
}
.input-row:focus-within { border-color: var(--accent); }
.btn-attach {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 4px; transition: color .2s; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; border-radius: 4px;
}
.btn-attach:hover { color: var(--text-bright); background: var(--sidebar-hover); }
#msg-input, #dm-input {
  flex: 1; background: none; border: none; outline: none; color: var(--text-bright);
  font-size: 15px; font-family: var(--font); resize: none; max-height: 160px;
  line-height: 1.5; padding: 4px 0; vertical-align: middle;
}
#msg-input::placeholder, #dm-input::placeholder { color: var(--text-muted); }
.btn-send {
  background: var(--accent); border: none; color: #fff; border-radius: 6px;
  padding: 6px 10px; cursor: pointer; transition: background .2s;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); }

/* ── MODAL ───────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: flex-start; justify-content: center; z-index: 100;
  overflow-y: auto; padding: 24px 16px;
}
.modal {
  background: var(--sidebar-bg); border-radius: 10px; padding: 28px;
  width: 100%; max-width: 400px; border: 1px solid var(--border);
  flex-shrink: 0; margin: auto;
}
.modal h3 { color: var(--text-bright); font-size: 18px; margin-bottom: 18px; }
.modal input, .modal textarea {
  width: 100%; padding: 10px 12px; margin-bottom: 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text-bright);
  font-size: 14px; font-family: var(--font); outline: none; resize: vertical;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 16px; cursor: pointer; }
.checkbox-label input { width: auto; margin-bottom: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-secondary {
  padding: 9px 18px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text); cursor: pointer; font-size: 14px;
}
.btn-secondary:hover { background: var(--input-bg); }

/* ── ADMIN ───────────────────────────────────────── */
.admin-menu { list-style: none; }
.admin-menu li { padding: 6px 16px; cursor: pointer; border-radius: 6px; margin: 1px 8px; font-size: 14px; color: var(--text-muted); transition: background .15s, color .15s; }
.admin-menu li:hover { background: var(--sidebar-hover); color: var(--text-bright); }

.admin-panel { padding: 32px; max-width: 640px; }
.admin-panel h2 { color: var(--text-bright); font-size: 20px; margin-bottom: 24px; }
.admin-form { background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: 10px; padding: 24px; margin-bottom: 24px; }
.admin-form label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; margin-top: 14px; }
.admin-form label:first-child { margin-top: 0; }
.admin-form select { width: 100%; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-bright); font-size: 14px; outline: none; }
.admin-form select:focus { border-color: var(--accent); }
.admin-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.btn-danger { padding: 9px 18px; border: 1px solid var(--danger); border-radius: 6px; background: transparent; color: var(--danger); cursor: pointer; font-size: 14px; transition: background .2s; }
.btn-danger:hover { background: rgba(224,62,62,.15); }

.members-table { background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: none; }
.member-row .avatar { width: 32px; height: 32px; font-size: 13px; }
.member-row-info { flex: 1; }
.member-row-name { font-size: 14px; color: var(--text-bright); font-weight: 600; }
.member-row-email { font-size: 12px; color: var(--text-muted); }
.member-row-role { font-size: 12px; color: var(--text-muted); padding: 2px 8px; border: 1px solid var(--border); border-radius: 4px; flex-shrink: 0; }
.member-row-channels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.channel-tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text-muted); }
.channel-tag.empty { font-style: italic; }

.modal select { width: 100%; padding: 10px 12px; margin-bottom: 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-bright); font-size: 14px; outline: none; }
.modal select:focus { border-color: var(--accent); }
.modal-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; margin-top: 2px; }
.modal-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.modal h4 { color: var(--text-bright); font-size: 15px; margin-bottom: 14px; }

/* ── TOAST ───────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 18px;
  border-radius: 8px; background: #2b2d31; border: 1px solid var(--border);
  color: var(--text-bright); font-size: 14px; z-index: 200;
  animation: slideIn .2s ease; max-width: 320px;
}
.toast.error { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
