:root {
  --bg: #08090d;
  --bg-glow: radial-gradient(circle at 50% -10%, rgba(124,92,255,0.16), transparent 60%);
  --panel: #111219;
  --panel-2: #191b25;
  --panel-3: #20232f;
  --border: #262636;
  --border-soft: #1c1e29;
  --text: #eef0f7;
  --muted: #8b8fa3;
  --muted-2: #62667a;
  --accent: #7c5cff;
  --accent-2: #4f8cff;
  --accent-hover: #6a4aef;
  --accent-glow: rgba(124,92,255,0.45);
  --danger: #ff5c7a;
  --danger-hover: #e84a68;
  --online: #37e0a0;
  --warn: #f5b942;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; height: 100vh; background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden; letter-spacing: -0.005em;
}
.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes glowDrift { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* ---------- auth screens ---------- */
.screen {
  display: flex; align-items: center; justify-content: center; height: 100vh; padding: 16px;
  animation: fadeIn 0.2s ease; position: relative; background: var(--bg-glow), var(--bg);
}
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border); border-radius: 18px;
  padding: 30px; width: 100%; max-width: 380px; animation: popIn 0.3s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.02) inset;
  position: relative;
}
.card::before {
  content: ''; position: absolute; inset: -1px; border-radius: 18px; padding: 1px;
  background: linear-gradient(135deg, var(--accent-glow), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}
.card h1 {
  font-size: 1.4rem; margin: 0 0 18px; font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff, var(--muted) 140%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.card label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
.card input {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: #050608; color: var(--text); font-size: 0.95rem; margin-bottom: 4px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,0.15); }
.card button {
  width: 100%; padding: 13px; margin-top: 14px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; font-size: 0.95rem;
  font-weight: 600; cursor: pointer; transition: filter 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 8px 24px -8px var(--accent-glow);
}
.card button:hover { filter: brightness(1.1); box-shadow: 0 10px 30px -6px var(--accent-glow); }
.card button:active { transform: scale(0.98); }
.status { font-size: 0.82rem; color: var(--danger); margin-top: 10px; min-height: 18px; }

/* ---------- app shell ---------- */
.app-layout {
  display: flex; align-items: stretch; justify-content: flex-start; height: 100vh; padding: 0;
  animation: fadeIn 0.25s ease; background: var(--bg);
}
.sidebar {
  width: 250px; min-width: 250px; background: var(--panel);
  border-right: 1px solid var(--border-soft); display: flex; flex-direction: column;
}
.sidebar-header {
  display: flex; align-items: center; gap: 9px; padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border-soft); flex: none;
}
.brand-mark {
  font-size: 1.1rem; color: var(--accent); filter: drop-shadow(0 0 6px var(--accent-glow));
  animation: glowDrift 3s ease-in-out infinite;
}
.brand-name {
  font-weight: 800; font-size: 0.95rem; letter-spacing: 0.02em; color: var(--text);
  font-family: var(--mono);
}
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 14px 10px; min-height: 0; }
.sidebar-section { margin-bottom: 20px; }
.sidebar-title {
  font-size: 0.7rem; text-transform: uppercase; color: var(--muted-2); letter-spacing: 0.08em;
  font-weight: 700; display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 7px; padding: 0 6px;
}
.btn-add {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1;
  border-radius: 5px; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.btn-add:hover { color: var(--text); background: var(--panel-3); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar > .sidebar-scroll > .sidebar-section > ul > li {
  padding: 7px 9px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 0.88rem;
  display: flex; flex-direction: column; transition: background 0.12s ease, color 0.12s ease;
  animation: slideUp 0.2s ease; position: relative;
}
.sidebar > .sidebar-scroll > .sidebar-section > ul > li:hover { background: var(--panel-2); color: var(--text); }
.sidebar > .sidebar-scroll > .sidebar-section > ul > li.active { background: var(--panel-2); color: var(--text); }
.sidebar > .sidebar-scroll > .sidebar-section > ul > li.active::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; border-radius: 0 3px 3px 0; background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
#voice-channel-list > li.active { color: var(--online); }
#voice-channel-list > li.active::before { background: var(--online); box-shadow: 0 0 8px rgba(55,224,160,0.5); }
.sidebar li .voice-members {
  font-size: 0.8rem; color: var(--muted); list-style: none; margin: 6px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.voice-members .voice-empty { padding: 3px 4px; font-size: 0.74rem; font-style: italic; opacity: 0.6; }
.voice-members .voice-member {
  display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 6px;
  transition: background 0.12s ease; animation: slideUp 0.15s ease;
}
.voice-members .voice-member:hover { background: rgba(255,255,255,0.04); }
.voice-members .voice-member .avatar.small { margin-right: 0; }
.voice-members .voice-member.sharing { cursor: pointer; }
.voice-members .voice-member.sharing:hover { background: rgba(55,224,160,0.1); }
.voice-member-name {
  color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
}
.voice-member.sharing .voice-member-name,
.voice-member.sharing-readonly .voice-member-name { color: var(--online); font-weight: 600; }
.you-tag { color: var(--muted-2); font-weight: 400; font-size: 0.73rem; }
.voice-member-status { display: flex; align-items: center; gap: 3px; flex: none; }
.status-icon { font-size: 0.78rem; line-height: 1; opacity: 0.85; }
.status-icon.sharing-icon { opacity: 1; }

@keyframes speakingPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--online); }
  50% { box-shadow: 0 0 0 3px var(--online), 0 0 10px 2px rgba(55,224,160,0.55); }
}
.voice-member .avatar { transition: box-shadow 0.15s ease; border-radius: 50%; }
.voice-member.speaking .avatar { animation: speakingPulse 1s ease-in-out infinite; }
.voice-member.speaking .voice-member-name { color: var(--online); }
.online-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--online);
  margin-right: 6px; flex: none; box-shadow: 0 0 6px rgba(55,224,160,0.6);
}
.online-dot.pulse { animation: pulse 1.6s ease-in-out infinite; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%; font-size: 0.72rem; font-weight: 800;
  color: white; text-transform: uppercase; font-family: var(--mono);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.avatar.small { width: 19px; height: 19px; font-size: 0.58rem; margin-right: 6px; }
#online-list li {
  display: flex; align-items: center; padding: 5px 6px; border-radius: 7px; font-size: 0.84rem;
  color: var(--text); transition: background 0.12s ease;
}
#online-list li:hover { background: var(--panel-2); }

.sidebar-user {
  flex: none; display: flex; align-items: center; gap: 9px; padding: 12px 14px;
  border-top: 1px solid var(--border-soft); background: var(--panel-2);
}
.sidebar-user-name { font-size: 0.85rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--bg); }
.chat-header {
  padding: 15px 22px; border-bottom: 1px solid var(--border-soft); font-weight: 700; font-size: 0.95rem;
  display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em;
}
.reconnect-banner {
  background: var(--warn); color: #1a1300; font-size: 0.8rem; text-align: center;
  padding: 6px; animation: fadeIn 0.2s ease; font-weight: 600;
}
.reconnect-banner .spinner {
  display: inline-block; width: 10px; height: 10px; border: 2px solid #1a1300;
  border-top-color: transparent; border-radius: 50%; margin-right: 6px; vertical-align: -1px;
  animation: spin 0.7s linear infinite;
}
.messages { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 2px; }
.message { max-width: 680px; display: flex; gap: 12px; padding: 3px 8px; border-radius: 8px; animation: slideUp 0.15s ease; }
.message:hover { background: rgba(255,255,255,0.025); }
.message .avatar { margin-top: 2px; }
.message .avatar-spacer { width: 28px; flex: none; }
.message .body { min-width: 0; flex: 1; }
.message.grouped { margin-top: -2px; }
.message .author { font-size: 0.86rem; color: var(--text); font-weight: 700; margin-right: 8px; }
.message .time { font-size: 0.7rem; color: var(--muted-2); font-family: var(--mono); }
.message .content { margin-top: 2px; word-wrap: break-word; white-space: pre-wrap; line-height: 1.5; color: #dcdfec; }
.message img.attachment { max-width: 320px; border-radius: 10px; margin-top: 8px; display: block; cursor: pointer; transition: opacity 0.15s ease; border: 1px solid var(--border-soft); }
.message img.attachment:hover { opacity: 0.9; }
.message a.attachment { color: var(--accent-2); display: block; margin-top: 6px; }
.load-more {
  text-align: center; font-size: 0.78rem; color: var(--muted); padding: 8px; cursor: pointer;
  border-radius: 8px; transition: background 0.15s ease; font-weight: 500;
}
.load-more:hover { background: var(--panel-2); color: var(--text); }

.composer { display: flex; gap: 9px; padding: 15px 22px; border-top: 1px solid var(--border-soft); }
.composer input[type=text] {
  flex: 1; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 0.9rem; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer input[type=text]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,0.15); }
.composer button {
  padding: 11px 18px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; font-weight: 600;
  cursor: pointer; transition: filter 0.15s ease, transform 0.1s ease;
}
.composer button:hover { filter: brightness(1.1); }
.composer button:active { transform: scale(0.97); }
#btn-attach { background: var(--panel); border: 1px solid var(--border); color: var(--text); }
#btn-attach:hover { background: var(--panel-2); }
.attachment-preview {
  display: none; align-items: center; gap: 8px; padding: 0 22px 9px; font-size: 0.8rem; color: var(--muted);
}
.attachment-preview.visible { display: flex; }
.attachment-preview button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.85rem; }

/* ---------- call bar ---------- */
.call-bar {
  display: flex; align-items: center; gap: 10px; padding: 11px 22px;
  border-top: 1px solid var(--border-soft); background: var(--panel); animation: slideUp 0.2s ease;
}
.call-bar button {
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 8px 13px; cursor: pointer; font-size: 1rem;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.call-bar button:hover { border-color: var(--accent); }
.call-bar button:active { transform: scale(0.94); }
.call-bar button.active { background: var(--danger); border-color: var(--danger); }
.call-bar button.on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 16px -4px var(--accent-glow); }
.call-bar button.danger { background: var(--danger); border-color: var(--danger); margin-left: auto; }
.call-bar button.danger:hover { background: var(--danger-hover); }
#call-channel-name { font-size: 0.85rem; color: var(--muted); margin-right: 6px; display: flex; align-items: center; gap: 6px; font-weight: 600; }
#call-channel-name::before { content: '🔊'; font-size: 0.9rem; }

.mic-settings-panel {
  display: flex; flex-direction: column; gap: 11px; padding: 15px 22px;
  border-top: 1px solid var(--border-soft); background: var(--panel); animation: slideUp 0.15s ease;
}
.mic-settings-panel label { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.mic-settings-panel select {
  padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: #050608; color: var(--text); font-size: 0.85rem;
}
.mic-check { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text) !important; }
.mic-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

#screen-share-wrap { position: relative; animation: popIn 0.2s ease; background: black; }
#screen-share-video { width: 100%; max-height: 40vh; background: black; display: block; }
#screen-share-wrap:fullscreen { display: flex; align-items: center; justify-content: center; }
#screen-share-wrap:fullscreen #screen-share-video { max-height: 100vh; height: 100vh; }
#btn-fullscreen {
  position: absolute; bottom: 10px; right: 10px; background: rgba(0,0,0,0.6);
  border: 1px solid var(--border); color: var(--text); border-radius: 7px;
  padding: 6px 10px; cursor: pointer; font-size: 1.1rem; line-height: 1;
  transition: background 0.15s ease, opacity 0.15s ease; opacity: 0.7;
}
#screen-share-wrap:hover #btn-fullscreen { opacity: 1; }
#btn-fullscreen:hover { background: rgba(0,0,0,0.85); }

/* ---------- modal / toast ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(4,4,8,0.65); backdrop-filter: blur(4px); display: flex;
  align-items: center; justify-content: center; z-index: 100; animation: fadeIn 0.15s ease;
}
.modal {
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; width: 100%; max-width: 350px; animation: popIn 0.18s ease;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.6);
}
.modal h2 { font-size: 1.05rem; margin: 0 0 15px; font-weight: 700; }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .modal-actions button {
  flex: 1; padding: 11px; border: none; border-radius: 9px; cursor: pointer; font-size: 0.88rem; font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease;
}
.modal .modal-actions button:active { transform: scale(0.97); }
.modal .btn-cancel { background: var(--panel-3); color: var(--text); }
.modal .btn-cancel:hover { background: var(--border); }
.modal .btn-confirm { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.modal .btn-confirm:hover { filter: brightness(1.1); }
.modal .type-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.modal .type-toggle button {
  flex: 1; padding: 9px; border-radius: 9px; border: 1px solid var(--border); background: #050608;
  color: var(--muted); cursor: pointer; font-size: 0.84rem; transition: all 0.15s ease;
}
.modal .type-toggle button.selected { border-color: var(--accent); color: var(--text); background: var(--panel-3); box-shadow: 0 0 0 1px var(--accent) inset; }

.toast-container {
  position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--danger);
  border-radius: 9px; padding: 11px 15px; font-size: 0.85rem; max-width: 300px; animation: slideUp 0.2s ease;
  box-shadow: 0 10px 30px -6px rgba(0,0,0,0.5);
}

@media (max-width: 700px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border-soft); }
}
