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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --text: #e0e0e0;
  --text-muted: #8892a4;
  --border: #2a3550;
  --msg-own: #1b3a5c;
  --msg-other: #1e2a3a;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen { width: 100%; height: 100vh; }
.hidden { display: none !important; }

/* ---- AUTH ---- */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.auth-box h1 {
  font-size: 1.6rem;
  color: var(--accent);
  text-align: center;
  margin-bottom: .3rem;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  margin-bottom: 1.5rem;
}

.tab-row {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.2rem;
}

.tab-btn {
  flex: 1;
  padding: .55rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .9rem;
  transition: background .2s, color .2s;
}

.tab-btn.active {
  background: var(--surface2);
  color: var(--text);
}

.auth-form { display: flex; flex-direction: column; gap: .75rem; }

.auth-form input {
  padding: .65rem .9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}

.auth-form input:focus { border-color: var(--accent); }

.auth-form button {
  padding: .7rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity .2s;
}
.auth-form button:hover { opacity: .85; }
.auth-form button:disabled { opacity: .5; cursor: not-allowed; }

.form-error {
  color: #ff6b6b;
  font-size: .82rem;
  min-height: 1rem;
  text-align: center;
}

/* ---- CHAT ---- */
#chat-screen {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
}

#my-username {
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color .2s;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#my-username:hover { border-bottom-color: var(--text-muted); }

.username-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  padding: 1px 5px;
  outline: none;
}

#logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: .2rem .4rem;
  border-radius: 4px;
  transition: color .2s;
}
#logout-btn:hover { color: var(--accent); }

.online-section { padding: .75rem 1rem; flex: 1; overflow-y: auto; }

.section-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .5rem;
}

#online-list { list-style: none; }

#online-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem 0;
  font-size: .88rem;
  color: var(--text);
}

#online-list li::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  flex-shrink: 0;
}

/* ---- CHAT MAIN ---- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: .9rem 1.2rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ---- MESSAGE BUBBLE ---- */
.message {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  position: relative;
}

.message.own  { align-self: flex-end; }
.message.other { align-self: flex-start; }

.message-actions {
  display: none;
  position: absolute;
  top: 4px;
  gap: 2px;
  z-index: 10;
}
.message.own  .message-actions { left: -72px; flex-direction: row; }
.message.other .message-actions { right: -72px; flex-direction: row; }

.message.show-actions .message-actions { display: flex; }

.action-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .8rem;
  padding: 3px 6px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.action-btn:hover { color: var(--text); background: var(--border); }

.bubble {
  padding: .55rem .85rem;
  border-radius: 10px;
  font-size: .93rem;
  line-height: 1.45;
  word-break: break-word;
}

.message.own  .bubble { background: var(--msg-own);   border-bottom-right-radius: 3px; }
.message.other .bubble { background: var(--msg-other); border-bottom-left-radius: 3px; }

.meta {
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: .2rem;
}
.message.own .meta { text-align: right; }

/* ---- REPLY QUOTE inside bubble ---- */
.reply-quote {
  border-left: 3px solid var(--accent);
  padding: .25rem .5rem;
  margin-bottom: .35rem;
  border-radius: 3px;
  background: rgba(255,255,255,.04);
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
}
.reply-quote .rq-name { color: var(--accent); font-weight: 600; margin-bottom: .1rem; }
.reply-quote .rq-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* ---- REACTIONS ---- */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.message.own .reactions { justify-content: flex-end; }

.reaction-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 7px;
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  user-select: none;
}
.reaction-pill:hover { background: var(--border); }
.reaction-pill.mine { border-color: var(--accent); }
.reaction-pill .count { color: var(--text-muted); font-size: .75rem; }

/* ---- REPLY BAR ---- */
.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .45rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: .5rem;
}

.reply-bar-content {
  display: flex;
  flex-direction: column;
  font-size: .82rem;
  overflow: hidden;
}

.reply-bar-label { color: var(--accent); margin-bottom: 2px; }

.reply-bar-text {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reply-bar-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  flex-shrink: 0;
  transition: color .15s;
}
#reply-bar-cancel:hover { color: var(--accent); }

/* ---- INPUT AREA ---- */
.message-form {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .85rem 1.2rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 .2rem;
  line-height: 1;
  opacity: .7;
  transition: opacity .15s;
  flex-shrink: 0;
}
.emoji-btn:hover { opacity: 1; }

#message-input {
  flex: 1;
  padding: .65rem .9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}
#message-input:focus { border-color: var(--accent); }

.message-form > button[type="submit"] {
  padding: .65rem 1.2rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: .95rem;
  cursor: pointer;
  transition: opacity .2s;
}
.message-form > button[type="submit"]:hover { opacity: .85; }

/* ---- EMOJI PICKER ---- */
.emoji-picker {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .6rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 260px;
  max-height: 200px;
  overflow-y: auto;
}

.emoji-picker button {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 6px;
  padding: 3px 5px;
  transition: background .15s;
  line-height: 1;
}
.emoji-picker button:hover { background: var(--surface2); }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 600px) {
  .sidebar { width: 160px; min-width: 160px; }
  .message { max-width: 90%; }
  .message.own  .message-actions { left: -60px; }
  .message.other .message-actions { right: -60px; }
}
