/* ==============================================================================
   GalaxyChat - Cosmic Space Theme & Design System
   Ultra-High Performance, Minimal Memory, GPU-Accelerated Responsive UI
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-deep: #06080f;
  --bg-surface: #0b0e17;
  --bg-sidebar: #0f1422;
  --bg-channel: #131a2c;
  --bg-card: rgba(19, 26, 44, 0.7);
  --bg-hover: rgba(139, 92, 246, 0.12);
  --bg-active: rgba(139, 92, 246, 0.22);
  --bg-input: #090c14;

  --accent-purple: #5865F2;
  --accent-purple-glow: rgba(88, 101, 242, 0.3);
  --accent-cyan: #4752C4;
  --accent-cyan-glow: rgba(71, 82, 196, 0.3);
  --accent-gradient: #5865F2;
  --accent-gradient-hover: #4752C4;

  --status-online: #10b981;
  --status-idle: #f59e0b;
  --status-dnd: #ef4444;
  --status-offline: #64748b;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(139, 92, 246, 0.35);

  --glass-blur: blur(20px);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 25px rgba(139, 92, 246, 0.25);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea {
  user-select: text;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* Background Cosmic Canvas */
#starfield {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.6;
}

.cosmic-nebula {
  position: absolute;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  background: radial-gradient(circle at 70% 20%, rgba(139, 92, 246, 0.15) 0%, transparent 40%),
              radial-gradient(circle at 20% 80%, rgba(6, 182, 212, 0.12) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
  filter: blur(60px);
}

/* App Master Layout */
#app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* 1. Leftmost Server Rail */
#server-rail {
  width: 72px;
  background: rgba(6, 8, 15, 0.85);
  backdrop-filter: var(--glass-blur);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  scrollbar-width: none;
}

#server-rail::-webkit-scrollbar {
  display: none;
}

.rail-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  color: var(--text-muted);
}

.rail-btn:hover {
  border-radius: var(--radius-lg);
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: var(--shadow-glow);
  transform: scale(1.05);
}

.rail-btn.active {
  border-radius: var(--radius-lg);
  background: var(--accent-purple);
  color: #fff;
  box-shadow: 0 0 15px var(--accent-purple-glow);
}

.rail-btn.active::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 4px;
  height: 36px;
  background: #fff;
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 8px #fff;
}

.rail-btn-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.rail-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--status-dnd);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  border: 2px solid var(--bg-surface);
}

.rail-separator {
  width: 32px;
  height: 2px;
  background: var(--border-subtle);
  margin: 4px 0;
  border-radius: 2px;
}

/* 2. Channel & DM Navigation Sidebar */
#channel-sidebar {
  width: 240px;
  background: rgba(11, 14, 23, 0.85);
  backdrop-filter: var(--glass-blur);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
}

.sidebar-header {
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: background 0.2s;
}

.sidebar-header:hover {
  background: var(--bg-hover);
}

.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.channel-category {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 8px 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.category-add-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
}

.category-add-btn:hover {
  color: var(--text-main);
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}

.channel-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  transform: translateX(2px);
}

.channel-item.active {
  background: var(--bg-active);
  color: #fff;
  border-left: 3px solid var(--accent-purple);
  font-weight: 600;
}

.channel-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  opacity: 0.7;
}

.channel-item.active .channel-icon {
  fill: var(--accent-cyan);
  opacity: 1;
}

/* Voice Channel Live Participant Preview */
.voice-participants-preview {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 28px;
  margin-top: 2px;
}

.voice-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
}

.voice-user-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-card);
}

/* Active Voice Status Bar in Sidebar */
#active-voice-bar {
  display: none;
  background: rgba(16, 185, 129, 0.12);
  border-top: 1px solid rgba(16, 185, 129, 0.3);
  padding: 10px 12px;
  flex-direction: column;
  gap: 6px;
}

.voice-status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--status-online);
}

.voice-controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.voice-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.voice-btn:hover {
  background: var(--bg-hover);
}

.voice-btn.disconnect {
  background: rgba(239, 68, 68, 0.2);
  color: var(--status-dnd);
  border-color: rgba(239, 68, 68, 0.3);
  margin-left: auto;
}

.voice-btn.disconnect:hover {
  background: var(--status-dnd);
  color: #fff;
}

/* User Account Footer Bar */
.user-footer {
  height: 56px;
  padding: 0 10px;
  background: rgba(6, 8, 15, 0.7);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-wrapper {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.user-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.status-badge {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.status-online { background: var(--status-online); }
.status-idle { background: var(--status-idle); }
.status-dnd { background: var(--status-dnd); }
.status-offline { background: var(--status-offline); }

.user-info-text {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.user-display-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-custom-status {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* 3. Main Center Workspace (Chat / Voice Call / Friends) */
#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(15, 20, 34, 0.7);
  backdrop-filter: var(--glass-blur);
  position: relative;
  overflow: hidden;
}

.panel-header {
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(11, 14, 23, 0.6);
  z-index: 10;
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-topic {
  font-size: 13px;
  color: var(--text-dim);
  border-left: 1px solid var(--border-subtle);
  padding-left: 12px;
  max-width: 400px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-glow);
}

.header-btn.primary {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
}

/* Message Stream Container */
#message-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

.message-card {
  display: flex;
  gap: 14px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.message-card:hover {
  background: rgba(255, 255, 255, 0.02);
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
}

.message-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.message-author {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}

.message-author:hover {
  text-decoration: underline;
}

.message-time {
  font-size: 11px;
  color: var(--text-dim);
}

.message-content {
  font-size: 14px;
  line-height: 1.5;
  color: #e2e8f0;
  word-break: break-word;
}

.message-attachment {
  margin-top: 6px;
  max-width: 400px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

.message-attachment img {
  max-width: 100%;
  display: block;
}

.file-attachment-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  width: fit-content;
  margin-top: 6px;
}

.file-attachment-card a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}

/* Typing Indicator */
#typing-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 20px;
  font-size: 12px;
  color: var(--text-dim);
  height: 24px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--accent-cyan);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* Bottom Message Input Box */
#input-wrapper {
  padding: 0 20px 20px 20px;
}

.input-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
}

.input-box:focus-within {
  border-color: var(--accent-purple);
  box-shadow: 0 0 15px var(--accent-purple-glow);
}

.input-attach-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.2s;
}

.input-attach-btn:hover {
  color: #fff;
  background: var(--bg-hover);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 14px;
  padding: 10px 0;
  resize: none;
  max-height: 120px;
  font-family: inherit;
}

#chat-input::placeholder {
  color: var(--text-dim);
}

.input-send-btn {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.input-send-btn:hover {
  background: var(--accent-gradient-hover);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
  transform: scale(1.02);
}

/* 4. Right Members Sidebar */
#members-sidebar {
  width: 220px;
  background: rgba(11, 14, 23, 0.7);
  border-left: 1px solid var(--border-subtle);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.member-row:hover {
  background: var(--bg-hover);
}

.member-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.member-row:hover .member-name {
  color: #fff;
}

/* 5. Modals & Dialogs */
.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: var(--glass-blur);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-glow);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 440px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: modalScale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScale {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 20px;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-input {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
}

.modal-input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.modal-btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.modal-btn.cancel {
  background: transparent;
  color: var(--text-muted);
}

.modal-btn.cancel:hover {
  color: #fff;
}

.modal-btn.confirm {
  background: var(--accent-gradient);
  color: #fff;
}

.modal-btn.confirm:hover {
  background: var(--accent-gradient-hover);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

/* 6. WebRTC Voice & Video Call Overlay */
#call-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(6, 8, 15, 0.95);
  backdrop-filter: blur(25px);
  z-index: 90;
  flex-direction: column;
}

#call-overlay.active {
  display: flex;
}

.call-header {
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.call-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
  align-content: center;
  justify-items: center;
}

.call-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.call-tile.speaking {
  border-color: var(--status-online);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.35);
}

.call-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.call-tile-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  box-shadow: var(--shadow-lg);
}

.call-tile-name {
  position: absolute;
  bottom: 12px;
  left: 14px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.call-controls-bar {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(11, 14, 23, 0.8);
}

.call-control-circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.call-control-circle:hover {
  background: var(--bg-hover);
  transform: scale(1.1);
}

.call-control-circle.active {
  background: var(--accent-purple);
}

.call-control-circle.danger {
  background: var(--status-dnd);
}

.call-control-circle.danger:hover {
  background: #dc2626;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

/* 7. Mobile (Android) Responsive Overhaul */
@media (max-width: 768px) {
  #server-rail {
    display: none; /* Accessible via mobile drawer */
  }

  #members-sidebar {
    display: none;
  }

  #channel-sidebar {
    position: absolute;
    top: 0;
    left: -100%;
    width: 80%;
    max-width: 300px;
    height: 100%;
    z-index: 50;
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.8);
  }

  #channel-sidebar.open {
    left: 0;
  }

  .mobile-menu-btn {
    display: flex !important;
  }
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
}
