/* ========================================
   Chatroom — Industrial Terminal Aesthetic
   ======================================== */

/* --- Palette --- */
:root {
  --bg:             #08080c;
  --surface:        #111118;
  --surface-up:     #1a1a24;
  --surface-hover:  #22222e;
  --border:         #2a2a36;
  --border-focus:   #3a3a4a;

  --accent:         #00d4aa;
  --accent-dim:     rgba(0,212,170,.12);
  --accent-glow:    rgba(0,212,170,.25);

  --danger:         #ff4757;
  --warning:        #ffa726;

  --text:           #e4e2de;
  --text-dim:       #8a8a98;
  --text-muted:     #4a4a58;

  --radius:         8px;
  --radius-lg:      14px;
  --sidebar-w:      260px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'DM Mono', 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, button { font-family: inherit; font-size: inherit; }

/* --- Grain overlay --- */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: .025;
  pointer-events: none;
  z-index: 9999;
}

/* --- Background grid (auth page) --- */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: .18;
}

/* ===========================
   AUTH PAGE
   =========================== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.auth-container {
  position: relative; z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px 36px;
  animation: cardIn .5s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-header { text-align: center; margin-bottom: 28px; }
.auth-header h1 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.8rem;
  letter-spacing: -.02em;
  margin: 8px 0 4px;
}
.brand-icon {
  font-size: 2rem;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}
.brand-icon-sm {
  color: var(--accent);
  font-size: 1.1rem;
}
.auth-subtitle {
  color: var(--text-dim);
  font-size: .85rem;
}

/* Forms */
.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: .75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.field input {
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.field input::placeholder { color: var(--text-muted); }

.auth-switch {
  text-align: center;
  font-size: .82rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Toast */
.toast {
  min-height: 20px;
  text-align: center;
  font-size: .82rem;
  color: var(--danger);
  transition: opacity .3s;
  margin-bottom: 4px;
}
.toast.success { color: var(--accent); }

/* ===========================
   BUTTONS
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .2s, letter-spacing .35s, transform .15s;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover {
  letter-spacing: .06em;
  background: #00eabb;
}

.btn-accent {
  background: var(--accent);
  color: var(--bg);
  border-radius: var(--radius);
}
.btn-accent:hover { background: #00eabb; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-sm { padding: 6px 12px; font-size: .78rem; }

.btn-icon {
  background: none; border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.btn-icon:hover { color: var(--text); }

/* ===========================
   CHAT LAYOUT
   =========================== */
.chat-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform .3s ease, opacity .3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px;
  font-size: .72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.pulse {
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 6px var(--accent-glow);
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(.8); }
}
.online-count {
  margin-left: auto;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 20px;
  font-weight: 500;
}

.user-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.user-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: .88rem;
  animation: fadeLeft .3s ease both;
}
.user-list li:hover { background: var(--surface-up); }
.user-list li.is-me { color: var(--accent); }

@keyframes fadeLeft {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.user-avatar {
  font-size: 1.3rem;
  width: 30px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.my-info {
  flex: 1;
  font-size: .82rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Main Area --- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-header h2 {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 600;
}
.chat-header-info { flex: 1; }

.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .72rem;
  color: var(--text-muted);
}
.conn-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--warning);
  transition: background .3s;
}
.conn-status.connected .conn-dot { background: var(--accent); }
.conn-status.connected { color: var(--accent); }

/* --- Messages --- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.msg-system {
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
  padding: 16px 0;
}

/* Single message */
.msg {
  display: flex;
  align-self: flex-start;
  flex-direction: row;
  gap: 10px;
  padding: 6px 0;
  animation: msgIn .3s ease both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  font-size: 1.4rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-up);
  border-radius: var(--radius);
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-body { flex: 0 1 auto; max-width: 70%; }
.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg-name {
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: .85rem;
  color: var(--accent);
}
.msg-time {
  font-size: .68rem;
  color: var(--text-muted);
}
.msg-text {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  font-size: .9rem;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--surface-up);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.msg.me .msg-text {
  background: var(--accent-dim);
  border-color: rgba(0,212,170,.2);
  text-align: right;
}

.msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.msg.me .msg-body {
  text-align: right;
}



.msg-name { color: var(--text-dim); }
.msg.me .msg-name { color: var(--accent); }

/* --- Composer --- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color .2s;
}
.composer textarea:focus {
  border-color: var(--accent);
}
.composer textarea::placeholder { color: var(--text-muted); }

.send-label { display: inline; }
.send-icon  { display: none; }

/* ===========================
   MOBILE
   =========================== */
.mobile-only { display: none; }

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-only { display: flex; }
  .send-label { display: none; }
  .send-icon  { display: inline; font-size: 1.2rem; }
}

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

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%  { transform: translateX(-4px); }
  75%  { transform: translateX(4px); }
}
.shake { animation: shake .3s ease; }
