:root {
  --primary: #5865f2;
  --primary-dark: #4752c4;
  --secondary: #57f287;
  --danger: #ed4245;
  --warning: #fee75c;
  --bg-primary: #ffffff;
  --bg-secondary: #f2f3f5;
  --bg-tertiary: #e3e5e8;
  --text-primary: #2e3338;
  --text-secondary: #4e5058;
  --text-muted: #80848e;
  --border: #e3e5e8;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.15);
  --border-radius: 8px;
  --border-radius-lg: 16px;
  --transition: all 0.2s ease;
  --sidebar-width: 280px;
  --header-height: 60px;
}

[data-theme="dark"] {
  --primary: #5865f2;
  --primary-dark: #4752c4;
  --secondary: #57f287;
  --danger: #ed4245;
  --warning: #fee75c;
  --bg-primary: #36393f;
  --bg-secondary: #2f3136;
  --bg-tertiary: #202225;
  --text-primary: #ffffff;
  --text-secondary: #dcddde;
  --text-muted: #72767d;
  --border: #40444b;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.chat-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.chat-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  box-shadow: var(--shadow);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--primary);
}

.logo i {
  font-size: 1.5rem;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  transition: var(--transition);
}

.status-indicator.connected {
  background: var(--secondary);
  box-shadow: 0 0 8px rgba(87, 242, 135, 0.5);
}

.status-indicator.connecting {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

/* Main Layout */
.chat-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.user-profile {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.username {
  font-weight: 600;
  font-size: 0.95rem;
}

.user-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  letter-spacing: 0.5px;
}

.channel-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.channel {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.channel:hover {
  background: var(--bg-tertiary);
}

.channel.active {
  background: var(--primary);
  color: white;
}

.channel i {
  font-size: 0.9rem;
  opacity: 0.7;
}

.unread-count {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.9rem;
}

.user-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--secondary);
}

.feature-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.feature-item i {
  color: var(--primary);
  font-size: 0.8rem;
  width: 12px;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header-info {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-primary);
}

.channel-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.channel-info i {
  color: var(--text-muted);
}

.channel-description {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 1.5rem;
}

.chat-actions {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--border-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: var(--transition);
}

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

.action-btn.small {
  width: auto;
  height: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  gap: 0.5rem;
}

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

.welcome-message {
  display: flex;
  justify-content: center;
  padding: 2rem;
}

.welcome-content {
  text-align: center;
  max-width: 400px;
}

.welcome-content i {
  font-size: 3rem;
  color: var(--primary);
  margin-bottom: 1rem;
}

.welcome-content h3 {
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
}

.welcome-content p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.demo-badges {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.message {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.message:hover {
  background: var(--bg-secondary);
}

.message.own {
  flex-direction: row-reverse;
}

.message.own .message-content {
  align-items: flex-end;
}

.message.own .message-bubble {
  background: var(--primary);
  color: white;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.message-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.message-author {
  font-weight: 600;
  font-size: 0.95rem;
}

.message-timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.message-bubble {
  background: var(--bg-secondary);
  padding: 0.75rem;
  border-radius: var(--border-radius);
  max-width: fit-content;
  word-wrap: break-word;
}

.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.5rem;
}

/* Fixed Typing Indicator Styles */
.typing-indicator {
  padding: 0.75rem 1rem;
  margin: 0.5rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  display: none;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  animation: fadeInUp 0.3s ease;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.typing-indicator.show {
  display: flex;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 24px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingBounce 1.4s infinite ease-in-out both;
  opacity: 0.6;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0s;
}

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

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.typing-text {
  font-style: italic;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
  flex: 1;
}

/* Better positioning in chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  min-height: 0;
}

/* Ensure typing indicator appears above input */
.message-input-container {
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  position: relative;
  z-index: 10;
}

/* Input wrapper styling */
.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: all 0.2s ease;
  position: relative;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Message input styling */
#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  min-height: 20px;
  line-height: 1.4;
  font-family: inherit;
}

#messageInput::placeholder {
  color: var(--text-muted);
}

/* Emoji button styling */
.emoji-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1.1rem;
}

.emoji-btn:hover {
  background: var(--bg-tertiary);
  color: var(--primary);
  transform: scale(1.05);
}

/* Send button styling */
.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.send-btn:active {
  transform: scale(0.95);
}

/* Input actions styling */
.input-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.action-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.action-btn.small {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
}

.action-btn i {
  font-size: 0.8em;
}

/* Dark mode fixes */
[data-theme="dark"] .typing-indicator {
  background: var(--bg-tertiary);
  border-color: var(--border);
  color: var(--text-secondary);
}

[data-theme="dark"] .typing-dots span {
  background: var(--secondary);
}

[data-theme="dark"] .typing-text {
  color: var(--text-secondary);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .typing-indicator {
    margin: 0.25rem 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .typing-dots span {
    width: 5px;
    height: 5px;
  }

  .typing-text {
    font-size: 0.8rem;
  }
}

/* Fix scrollbar styling for typing indicator area */
.messages-container::-webkit-scrollbar {
  width: 4px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Ensure proper spacing between last message and typing indicator */
.messages-container .message:last-of-type {
  margin-bottom: 0;
}

/* Typing indicator pulse effect when shown */
.typing-indicator[style*="flex"] {
  animation: fadeInUp 0.3s ease, typingPulse 2s ease-in-out infinite 0.5s;
}

@keyframes typingPulse {
  0%,
  100% {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  50% {
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.1);
  }
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--border-radius-lg);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.close-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
}

.info-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
}

.info-item label {
  font-weight: 500;
  color: var(--text-secondary);
}

.tech-info h4 {
  margin-bottom: 1rem;
  color: var(--primary);
}

.tech-info ul {
  list-style: none;
  padding: 0;
}

.tech-info li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.tech-info li:last-child {
  border-bottom: none;
}

/* Animations */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  animation: slideIn 0.3s ease;
}

/* Pinned Message Styles */
.pinned-message {
  background: linear-gradient(135deg, #fef3c7, #fbbf24);
  border: 2px solid #f59e0b;
  border-radius: var(--border-radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.pinned-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(245, 158, 11, 0.9);
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
}

.pinned-header i {
  font-size: 0.8rem;
}

.pinned-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.pinned-content {
  padding: 1rem;
}

.moderation-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.moderation-notice i {
  font-size: 1.5rem;
  color: #d97706;
  margin-top: 0.25rem;
  flex-shrink: 0;
}

.notice-text {
  flex: 1;
}

.notice-text strong {
  color: #92400e;
  font-size: 1rem;
  display: block;
  margin-bottom: 0.5rem;
}

.notice-text p {
  color: #92400e;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
}

/* Dark mode styling for pinned message */
[data-theme="dark"] .pinned-message {
  background: linear-gradient(135deg, #374151, #1f2937);
  border-color: #f59e0b;
}

[data-theme="dark"] .pinned-header {
  background: rgba(245, 158, 11, 0.8);
}

[data-theme="dark"] .notice-text strong {
  color: #fbbf24;
}

[data-theme="dark"] .notice-text p {
  color: #d1d5db;
}

[data-theme="dark"] .moderation-notice i {
  color: #fbbf24;
}

/* Ensure pinned message stays at top */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  position: relative;
}

/* Message expiration indicator */
.message.expiring {
  opacity: 0.6;
  border-left: 3px solid var(--warning);
  background: rgba(245, 158, 11, 0.05);
}

.message.expired {
  opacity: 0.3;
  text-decoration: line-through;
}

/* Error Notification Styles */
.error-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  border: 1px solid #fecaca;
  border-left: 4px solid var(--danger);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
  z-index: 2000;
  min-width: 300px;
  max-width: 400px;
  animation: slideInRight 0.3s ease;
}

.error-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(239, 68, 68, 0.1);
  border-bottom: 1px solid #fecaca;
  font-weight: 600;
  color: var(--danger);
}

.error-header button {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  font-size: 1.2rem;
}

.error-header button:hover {
  background: rgba(239, 68, 68, 0.1);
}

.error-message {
  padding: 0.75rem 1rem;
  color: #991b1b;
  font-size: 0.9rem;
  line-height: 1.4;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Message expiration indicators */
.expiry-timer {
  font-size: 0.7rem;
  color: var(--warning);
  margin-left: 0.5rem;
  opacity: 0.7;
}

.message.expiring .expiry-timer {
  animation: pulse 2s infinite;
  color: var(--danger);
}

.message.expired .expiry-timer {
  color: var(--text-muted);
}

/* Disabled input styling */
#messageInput:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

#sendButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--text-muted);
}

/* Dark mode for error notifications */
[data-theme="dark"] .error-notification {
  background: linear-gradient(135deg, #1f1f1f, #2d1b1b);
  border-color: #dc2626;
}

[data-theme="dark"] .error-header {
  background: rgba(239, 68, 68, 0.2);
  border-bottom-color: #dc2626;
}

[data-theme="dark"] .error-message {
  color: #f87171;
}

/* Mobile responsiveness for error notifications */
@media (max-width: 768px) {
  .error-notification {
    top: 10px;
    right: 10px;
    left: 10px;
    min-width: auto;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .chat-main {
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-section {
    padding: 0.75rem;
  }

  .input-actions {
    flex-direction: column;
  }

  .emoji-picker {
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
  }
}
