/* PulseChat Modern Glassmorphism & Slack Dark Theme */
:root {
  --bg-main: #101217;
  --bg-sidebar: #181b22;
  --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
  --bg-sidebar-active: #2d224e;
  --bg-card: #1f232d;
  --bg-chat-input: #1b1e26;
  --bg-hover: #262a36;
  
  --accent-purple: #7c3aed;
  --accent-purple-glow: rgba(124, 58, 237, 0.35);
  --accent-hover: #6d28d9;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --status-online: #10b981;
  --status-away: #f59e0b;
  --status-busy: #ef4444;
  --status-offline: #6b7280;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(124, 58, 237, 0.6);
  
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Auth Container */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #2e1065, #0f172a, var(--bg-main));
  padding: 20px;
}

.auth-box {
  background: rgba(26, 30, 40, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-main);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 36px;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-header .brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--accent-purple), #c084fc);
  border-radius: 14px;
  color: white;
  font-size: 28px;
  margin-bottom: 14px;
  box-shadow: 0 0 20px var(--accent-purple-glow);
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

.auth-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-tab.active {
  background: var(--accent-purple);
  color: white;
  box-shadow: 0 2px 8px var(--accent-purple-glow);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(15, 18, 25, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: white;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-hover));
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px var(--accent-purple-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.auth-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 18px;
  display: none;
}

/* Avatar Presets for Signup */
.avatar-selector {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.avatar-opt {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  object-fit: cover;
  transition: all 0.2s;
}
.avatar-opt.selected {
  border-color: var(--accent-purple);
  transform: scale(1.1);
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

/* Main App Shell Layout */
#app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Workspace Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  user-select: none;
}

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

.workspace-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: white;
}

.workspace-title .ws-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-purple), #a855f7);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.sidebar-section {
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-icon-add {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  transition: all 0.15s;
}

.btn-icon-add:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

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

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: white;
  font-weight: 600;
}

.nav-item .hash {
  color: var(--text-dim);
  font-size: 16px;
}

.nav-item.active .hash {
  color: #c084fc;
}

/* User Status dot */
.user-status-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-online { background-color: var(--status-online); box-shadow: 0 0 6px var(--status-online); }
.status-away   { background-color: var(--status-away); }
.status-busy   { background-color: var(--status-busy); }
.status-offline { background-color: var(--status-offline); }

.user-avatar-wrapper {
  position: relative;
  width: 26px;
  height: 26px;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  color: white;
}

.user-avatar-wrapper .user-status-indicator {
  position: absolute;
  bottom: -1px;
  right: -1px;
  border: 2px solid var(--bg-sidebar);
}

/* User Profile Footer in Sidebar */
.user-profile-footer {
  height: 64px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info-brief {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
  overflow: hidden;
}

.user-info-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info-text .name {
  font-size: 14px;
  font-weight: 600;
  color: white;
  line-height: 1.2;
}

.user-info-text .subtext {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-logout:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  height: 100vh;
  position: relative;
}

/* Chat Header */
.chat-header {
  height: 60px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 18, 23, 0.9);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-info h2 {
  font-size: 17px;
  font-weight: 700;
  color: white;
}

.chat-header-info .desc {
  font-size: 13px;
  color: var(--text-muted);
  border-left: 1px solid var(--border-color);
  padding-left: 12px;
}

.chat-search-bar {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  width: 220px;
}

.chat-search-bar input {
  background: none;
  border: none;
  color: white;
  font-size: 13px;
  outline: none;
  width: 100%;
}

/* Messages Stream */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-row {
  display: flex;
  gap: 14px;
  animation: fadeIn 0.15s ease-out;
  position: relative;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  transition: background 0.15s;
}

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

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  font-size: 16px;
}

.message-body {
  flex: 1;
  overflow: hidden;
}

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

.message-author {
  font-weight: 700;
  font-size: 14px;
  color: white;
}

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

.message-content {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-main);
  word-wrap: break-word;
}

/* Message Formatting */
.message-content code {
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
  color: #f472b6;
}

.message-content pre {
  background: #0d0f14;
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-top: 6px;
  overflow-x: auto;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: #a7f3d0;
}

/* Attachment View */
.message-attachment {
  margin-top: 8px;
  max-width: 380px;
}

.message-attachment img {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-attachment img:hover {
  transform: scale(1.02);
}

.file-attachment-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: white;
  transition: background 0.15s;
}

.file-attachment-card:hover {
  background: var(--bg-hover);
}

/* Reactions Bar */
.reactions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}

.reaction-chip:hover {
  background: rgba(255, 255, 255, 0.1);
}

.reaction-chip.user-reacted {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--accent-purple);
  color: #c084fc;
}

/* Action hover popover for message */
.message-actions-hover {
  position: absolute;
  top: -12px;
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: none;
  padding: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.message-row:hover .message-actions-hover {
  display: flex;
}

.btn-action-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 14px;
}

.btn-action-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* Chat Input Bar */
.chat-input-wrapper {
  padding: 0 20px 20px 20px;
}

.chat-input-box {
  background: var(--bg-chat-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  transition: border-color 0.2s;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.chat-input-box:focus-within {
  border-color: var(--border-focus);
}

.chat-textarea {
  width: 100%;
  background: none;
  border: none;
  color: white;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 140px;
  min-height: 24px;
}

.chat-input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.btn-toolbar {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.btn-toolbar:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.btn-send {
  background: var(--accent-purple);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-send:hover {
  background: var(--accent-hover);
}

/* Attachment Preview Container */
.attachment-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.preview-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
}

.preview-info {
  flex: 1;
  font-size: 13px;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-remove-preview {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}

.btn-remove-preview:hover {
  color: #ef4444;
}

/* Emoji Picker Popup */
.emoji-picker-popup {
  position: absolute;
  bottom: 80px;
  right: 30px;
  width: 320px;
  height: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
  display: flex;
  flex-direction: column;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}

.emoji-header {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
}

.emoji-header input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: white;
  font-size: 13px;
}

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.emoji-item {
  font-size: 20px;
  text-align: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.emoji-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.15);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: var(--shadow-main);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: white;
  margin-bottom: 16px;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Loading Spinner */
.messages-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
  gap: 12px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive Mobile Toggle */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.25s ease;
  }
  .sidebar.open {
    left: 0;
    box-shadow: 10px 0 30px rgba(0,0,0,0.8);
  }
  .mobile-menu-btn {
    display: block !important;
  }
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  margin-right: 10px;
}
