/* =============================================
   SLACK CLONE — STYLES
   ============================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --rail-w: 68px;
  --sidebar-w: 260px;
  --purple-dark: #3f0e40;
  --purple-mid: #611f69;
  --purple-light: #4a154b;
  --sidebar-text: #cdb5ce;
  --sidebar-hover: rgba(255,255,255,0.1);
  --sidebar-active: rgba(255,255,255,0.18);
  --white: #ffffff;
  --bg: #f8f8f8;
  --border: #e0e0e0;
  --msg-hover: #f5f5f5;
  --blue: #1264a3;
  --green: #2bac76;
  --yellow: #f5c518;
  --red: #e01e5a;
  --text-primary: #1d1c1d;
  --text-secondary: #616061;
  --input-border: #c6c6c6;
  --badge-bg: #cd2553;
  --font: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); font-size: 15px; color: var(--text-primary); background: var(--bg); }

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

/* ── RAIL ── */
#rail {
  width: var(--rail-w);
  background: var(--purple-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  flex-shrink: 0;
  gap: 4px;
}

.rail-workspace {
  width: 40px; height: 40px;
  background: var(--white);
  color: var(--purple-dark);
  font-weight: 800;
  font-size: 13px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  margin-bottom: 12px;
  flex-shrink: 0;
  user-select: none;
}

.rail-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.rail-btn {
  width: 40px; height: 40px;
  border: none; background: transparent;
  color: var(--sidebar-text);
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--sidebar-hover); color: var(--white); }
.rail-btn.active { background: var(--sidebar-active); color: var(--white); }

.rail-bottom { margin-top: auto; }

.rail-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--purple-mid);
  border: 2px solid var(--sidebar-text);
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: border-color 0.15s;
}
.rail-avatar:hover { border-color: var(--white); }
.rail-avatar .status-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px;
  border: 2px solid var(--purple-dark);
  border-radius: 50%;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--purple-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  color: var(--sidebar-text);
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  flex-shrink: 0;
}

#workspace-btn {
  background: none; border: none;
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
#workspace-btn:hover { background: var(--sidebar-hover); }
#workspace-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

#new-message-btn {
  width: 28px; height: 28px;
  background: var(--sidebar-text);
  color: var(--purple-light);
  border: none; border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
#new-message-btn:hover { background: var(--white); }
#new-message-btn svg { width: 14px; height: 14px; }

#sidebar-search {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 8px;
  background: rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: text;
  flex-shrink: 0;
}
#sidebar-search svg { width: 14px; height: 14px; color: var(--sidebar-text); flex-shrink: 0; }
#sidebar-search input {
  background: none; border: none; outline: none;
  color: var(--white);
  font-size: 13px;
  width: 100%;
}
#sidebar-search input::placeholder { color: var(--sidebar-text); }

#sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 16px;
}
#sidebar-nav::-webkit-scrollbar { width: 4px; }
#sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px;
  cursor: pointer;
  font-size: 15px;
  color: var(--sidebar-text);
  border-radius: 4px;
  margin: 0 8px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--white); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 2px 8px;
  margin-top: 8px;
}
.section-toggle {
  background: none; border: none;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}
.section-toggle:hover { background: var(--sidebar-hover); color: var(--white); }
.section-toggle .chevron { width: 14px; height: 14px; transition: transform 0.2s; }
.section-toggle .chevron.open { transform: rotate(0deg); }
.section-toggle .chevron.closed { transform: rotate(-90deg); }

.add-btn {
  width: 22px; height: 22px;
  background: none; border: none;
  color: var(--sidebar-text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.add-btn:hover { background: var(--sidebar-hover); color: var(--white); }

.channel-list {
  list-style: none;
  margin: 0;
}
.channel-list.collapsed { display: none; }

.channel-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 16px;
  cursor: pointer;
  font-size: 15px;
  color: var(--sidebar-text);
  border-radius: 4px;
  margin: 0 8px;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.channel-item:hover { background: var(--sidebar-hover); color: var(--white); }
.channel-item.active { background: var(--sidebar-active); color: var(--white); }

.channel-hash {
  color: var(--sidebar-text);
  font-size: 16px;
  flex-shrink: 0;
  opacity: 0.75;
}
.channel-item.active .channel-hash,
.channel-item:hover .channel-hash { opacity: 1; }

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

.badge {
  background: var(--badge-bg);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* DM items */
.dm-item { gap: 8px; }
.dm-avatar {
  width: 20px; height: 20px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Status dots */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--green); }
.status-dot.away { background: var(--yellow); }
.status-dot.offline { background: transparent; border: 2px solid var(--sidebar-text); }

/* ── CHAT MAIN ── */
#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white);
  overflow: hidden;
  min-width: 0;
}

/* Chat header */
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--white);
}

#chat-header-left {
  display: flex; align-items: center; gap: 10px;
  overflow: hidden;
}

#channel-title-btn {
  background: none; border: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 2px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.12s;
  white-space: nowrap;
}
#channel-title-btn:hover { background: var(--msg-hover); }
#chat-channel-indicator { color: var(--text-secondary); font-size: 18px; }

#channel-description {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-header-right {
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}

.header-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  transition: background 0.12s, color 0.12s;
}
.header-btn:hover { background: var(--msg-hover); color: var(--text-primary); }
.header-btn svg { width: 18px; height: 18px; }

/* Messages */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
}
#messages-container::-webkit-scrollbar { width: 6px; }
#messages-container::-webkit-scrollbar-thumb { background: #d1d1d1; border-radius: 6px; }

#messages-inner { display: flex; flex-direction: column; }

/* Day divider */
.day-divider {
  display: flex; align-items: center;
  margin: 16px 20px;
  gap: 12px;
}
.day-divider::before, .day-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.day-divider span {
  font-size: 12px; font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

/* Message group */
.msg-group {
  display: flex;
  padding: 4px 20px;
  gap: 12px;
  transition: background 0.1s;
  position: relative;
}
.msg-group:hover { background: var(--msg-hover); }

.msg-group:hover .msg-actions { display: flex; }

.msg-avatar {
  width: 36px; height: 36px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
}

.msg-body { flex: 1; min-width: 0; }

.msg-meta {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 2px;
}
.msg-author {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  cursor: pointer;
}
.msg-author:hover { text-decoration: underline; }
.msg-time {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.msg-text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-primary);
  word-break: break-word;
}
.msg-text a { color: var(--blue); text-decoration: none; }
.msg-text a:hover { text-decoration: underline; }
.msg-text code {
  background: #f2f2f2;
  border: 1px solid #e0e0e0;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
}

/* Continued messages (no avatar repeat) */
.msg-continued {
  padding-left: calc(20px + 36px + 12px);
}
.msg-continued .msg-avatar-spacer { display: none; }

/* Reactions */
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.reaction-pill {
  display: flex; align-items: center; gap: 4px;
  background: #f0f0f0;
  border: 1px solid #d0d0d0;
  border-radius: 14px;
  padding: 2px 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}
.reaction-pill:hover { background: #e8e8f8; border-color: var(--blue); }
.reaction-pill.reacted { background: #e8f0fe; border-color: var(--blue); color: var(--blue); }
.reaction-pill .count { font-weight: 700; font-size: 12px; }

/* Message action bar */
.msg-actions {
  display: none;
  position: absolute;
  top: -16px;
  right: 20px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 10;
  overflow: hidden;
}
.msg-action-btn {
  background: none; border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
  display: flex; align-items: center;
}
.msg-action-btn:hover { background: var(--msg-hover); color: var(--text-primary); }
.msg-action-btn svg { width: 16px; height: 16px; }

/* Thread count */
.thread-count {
  font-size: 13px;
  color: var(--blue);
  font-weight: 700;
  cursor: pointer;
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.thread-count:hover { text-decoration: underline; }

/* Typing indicator */
#typing-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 20px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  height: 28px;
}
#typing-indicator.hidden { visibility: hidden; }

.typing-dots {
  display: flex; align-items: center; gap: 3px;
}
.typing-dots span {
  width: 6px; height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ── INPUT AREA ── */
#input-area {
  margin: 0 16px 16px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#input-area:focus-within {
  border-color: #aaa;
  box-shadow: 0 0 0 3px rgba(29,28,29,0.08);
}

#input-toolbar {
  display: flex; align-items: center; gap: 1px;
  padding: 6px 8px 0;
  border-bottom: 1px solid #f0f0f0;
}
.toolbar-btn {
  background: none; border: none;
  padding: 4px 7px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
}
.toolbar-btn:hover { background: var(--msg-hover); color: var(--text-primary); }
.toolbar-btn svg { width: 16px; height: 16px; display: block; }
.toolbar-divider { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

#input-box-wrapper {
  display: flex; align-items: flex-end;
  padding: 8px 8px 8px 12px;
  gap: 8px;
}

#attach-btn {
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
  display: flex;
}
#attach-btn:hover { background: var(--msg-hover); color: var(--text-primary); }
#attach-btn svg { width: 18px; height: 18px; }

#message-input {
  flex: 1;
  min-height: 22px;
  max-height: 200px;
  overflow-y: auto;
  outline: none;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
}
#message-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-secondary);
  pointer-events: none;
}

#input-actions {
  display: flex; align-items: center; gap: 2px;
  flex-shrink: 0;
}
.input-action-btn {
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 700;
  display: flex; align-items: center;
  transition: background 0.12s, color 0.12s;
}
.input-action-btn:hover { background: var(--msg-hover); color: var(--text-primary); }
.input-action-btn svg { width: 18px; height: 18px; }

#send-btn {
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex; align-items: center;
  transition: background 0.12s, color 0.12s;
}
#send-btn:not([disabled]):hover { background: #1264a3; color: #fff; }
#send-btn[disabled] { opacity: 0.4; cursor: default; }
#send-btn svg { width: 18px; height: 18px; }

/* ── RIGHT PANEL ── */
#right-panel {
  width: 360px;
  border-left: 1px solid var(--border);
  background: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.2s;
}
#right-panel.hidden { display: none; }

#right-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#right-panel-title { font-size: 16px; font-weight: 700; }
#close-right-panel {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
#close-right-panel:hover { background: var(--msg-hover); color: var(--text-primary); }

#right-panel-content {
  flex: 1; overflow-y: auto;
  padding: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ── EMOJI PICKER ── */
#emoji-picker {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 320px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 1000;
  padding: 12px;
}
#emoji-picker.hidden { display: none; }

#emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-btn {
  background: none; border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.1s;
  display: flex; align-items: center; justify-content: center;
}
.emoji-btn:hover { background: #f0f0f0; }

/* ── MODAL ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
#modal-overlay.hidden { display: none; }

#modal {
  background: var(--white);
  border-radius: 10px;
  width: 440px;
  max-width: 96vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.24);
  overflow: hidden;
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
#modal-title { font-size: 18px; font-weight: 700; }
#modal-close {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
#modal-close:hover { background: var(--msg-hover); }

#modal-body {
  padding: 20px 24px 24px;
  display: flex; flex-direction: column; gap: 8px;
}
#modal-body label {
  font-size: 13px; font-weight: 700;
  margin-top: 8px;
}
.optional { font-weight: 400; color: var(--text-secondary); }
#modal-body input {
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
#modal-body input:focus { border-color: var(--blue); }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 12px;
}
.btn-secondary {
  background: var(--white);
  border: 1px solid var(--input-border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.12s;
}
.btn-secondary:hover { background: var(--msg-hover); }
.btn-primary {
  background: #007a5a;
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.12s;
}
.btn-primary:hover { background: #006048; }

/* ── UNREAD NEW MESSAGES BADGE ── */
.new-msg-banner {
  position: sticky; top: 0; z-index: 5;
  background: var(--blue);
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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