/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

.app {
  display: flex;
  height: 100vh;
  background: #fff;
}

/* Mobile menu button */
.mobile-menu-button {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  background: #0088cc;
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Sidebar */
.sidebar {
  width: 300px;
  background: #f8f9fa;
  border-right: 1px solid #e9ecef;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}

.sidebar-header h3 {
  color: #333;
  font-size: 1.2rem;
  font-weight: 600;
}

.close-sidebar {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
}

/* User Profile */
.user-profile {
  padding: 1rem;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #0088cc;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.user-info {
  flex: 1;
}

.name-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.name-display:hover {
  background: #f0f0f0;
}

.name {
  font-weight: 600;
  color: #333;
}

.anon-badge {
  background: #ff6b6b;
  color: white;
  padding: 0.125rem 0.375rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.edit-icon {
  opacity: 0.6;
  font-size: 0.875rem;
}

.name-edit {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.name-edit input {
  flex: 1;
  padding: 0.25rem 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.875rem;
}

.name-edit button {
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
}

.name-edit button:first-of-type {
  background: #28a745;
  color: white;
}

.name-edit button:last-of-type {
  background: #dc3545;
  color: white;
}

/* Sidebar Sections */
.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid #e9ecef;
}

.sidebar-section h4 {
  color: #666;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}

/* Channels List */
.channels-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.channel-item:hover {
  background: #e9ecef;
}

.channel-item.active {
  background: #0088cc;
  color: white;
}

.channel-name {
  font-weight: 500;
  font-size: 0.875rem;
}

.member-count {
  background: rgba(0, 0, 0, 0.1);
  color: inherit;
  padding: 0.125rem 0.375rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.channel-item.active .member-count {
  background: rgba(255, 255, 255, 0.2);
}

/* Users List */
.users-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 6px;
  transition: background-color 0.2s;
}

.user-item:hover {
  background: #e9ecef;
}

.user-item.active {
  background: #0088cc;
  color: white;
}

.user-item.active .user-name {
  color: white;
}

.empty-contacts {
  text-align: center;
  padding: 1rem;
  color: #666;
  font-style: italic;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #6c757d;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  position: relative;
}

.online-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #28a745;
  border: 2px solid #fff;
  border-radius: 50%;
}

.online-indicator.online {
  background: #28a745;
}

.online-indicator.offline {
  background: #6c757d;
}

.user-item.online .user-name {
  color: #333;
}

.user-item.offline .user-name {
  color: #6c757d;
}

.user-name {
  flex: 1;
  font-size: 0.875rem;
  color: #333;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

/* Chat Header */
.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.channel-info h2 {
  color: #333;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.channel-info p {
  color: #666;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}

.leave-channel {
  background: #dc3545;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.2s;
}

.leave-channel:hover {
  background: #c82333;
}

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

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 70%;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #0088cc;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.message.own .message-avatar {
  background: #28a745;
}

.message-content {
  flex: 1;
  min-width: 0;
}

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

.message-user {
  font-weight: 600;
  font-size: 0.875rem;
  color: #333;
}

.message-time {
  font-size: 0.75rem;
  color: #666;
}

.message-text {
  background: #f1f3f4;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.message.own .message-text {
  background: #dcf8c6;
}

/* Input Container */
.input-container {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e9ecef;
  background: #fff;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-container textarea {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 0.75rem 1rem;
  padding-bottom: 2rem;
  font-size: 0.875rem;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  box-sizing: border-box;
}

.input-container textarea:focus {
  outline: none;
  border-color: #0088cc;
}

.char-counter {
  position: absolute;
  bottom: 0.5rem;
  right: 1rem;
  font-size: 0.75rem;
  color: #666;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.125rem 0.25rem;
  border-radius: 4px;
}

.input-container button {
  background: #0088cc;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
}

.input-container button:hover:not(:disabled) {
  background: #006699;
}

.input-container button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Empty States */
.empty-state {
  text-align: center;
  color: #666;
  padding: 2rem;
}

.empty-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
}

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

.empty-content h2 {
  color: #333;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.empty-content p {
  color: #666;
  margin-bottom: 2rem;
}

.empty-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.join-public-btn {
  background: #0088cc;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
}

.join-public-btn:hover {
  background: #006699;
}

/* Name Prompt Modal */
.name-prompt-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.name-prompt-modal {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  width: 90%;
}

.name-prompt-modal h2 {
  color: #333;
  margin-bottom: 0.5rem;
  text-align: center;
}

.name-prompt-modal p {
  color: #666;
  margin-bottom: 1.5rem;
  text-align: center;
}

.name-prompt-modal input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.name-prompt-modal input:focus {
  outline: none;
  border-color: #0088cc;
}

.name-prompt-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.name-prompt-buttons button {
  padding: 0.75rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
}

.name-prompt-buttons button:first-child {
  background: #0088cc;
  color: white;
}

.name-prompt-buttons button:first-child:hover {
  background: #006699;
}

.anon-button {
  background: #6c757d !important;
  color: white !important;
}

.anon-button:hover {
  background: #5a6268 !important;
}

.notification-permission {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e9ecef;
  text-align: center;
}

.notification-permission p {
  margin-bottom: 0.5rem;
  color: #666;
  font-size: 0.875rem;
}

.notification-btn {
  background: #17a2b8;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background-color 0.2s;
}

.notification-btn:hover {
  background: #138496;
}

/* Notification Settings */
.notification-settings {
  padding: 0.75rem;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.notification-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.notification-icon {
  font-size: 1.125rem;
}

.notification-text {
  font-size: 0.875rem;
  color: #495057;
  font-weight: 500;
}

.notification-help {
  margin-top: 0.5rem;
  color: #6c757d;
  font-size: 0.75rem;
  line-height: 1.3;
}

.notification-settings .notification-btn {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    height: 100vh;
    z-index: 1001;
    transition: left 0.3s ease;
    width: 280px;
  }

  .sidebar.open {
    left: 0;
  }

  .mobile-menu-button {
    display: block !important;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1002;
  }

  .close-sidebar {
    display: block;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
  }

  .chat-container {
    margin-left: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .message {
    max-width: 85%;
  }

  .chat-header {
    padding: 1rem;
  }

  .input-container {
    padding: 1rem;
  }

  .name-prompt-modal {
    margin: 1rem;
    padding: 1.5rem;
  }

  .empty-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  text-align: center;
  padding: 2rem;
}

.loading-state h2 {
  color: #333;
  margin-bottom: 1rem;
}

.loading-state p {
  color: #666;
  font-size: 1rem;
}

/* iOS keyboard send button support */
@media screen and (max-width: 768px) {
  .input-container textarea {
    -webkit-appearance: none;
    border-radius: 20px;
  }
  
  .input-container button {
    -webkit-appearance: none;
    border-radius: 20px;
  }
}

/* Cleanup Button */
.cleanup-button {
  width: 100%;
  background: #dc3545;
  color: white;
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.cleanup-button:hover {
  background: #c82333;
}

/* Unread Badge */
.unread-badge {
  background: #dc3545;
  color: white;
  border-radius: 50%;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 4px;
}

/* Private Chats List */
.private-chats-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.private-chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
  position: relative;
}

.private-chat-item:hover {
  background: #e9ecef;
}

.private-chat-item.active {
  background: #0088cc;
  color: white;
}

.private-chat-item.active .chat-name {
  color: white;
}

.private-chat-item.active .last-message {
  color: rgba(255, 255, 255, 0.8);
}

.private-chat-item.active .last-time {
  color: rgba(255, 255, 255, 0.7);
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #0088cc;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.chat-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: #333;
}

.last-message {
  font-size: 0.75rem;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
}

.last-time {
  font-size: 0.75rem;
  color: #666;
}

/* Channel Meta */
.channel-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.channel-item .unread-badge {
  margin-left: auto;
}

/* Slim Notification Bar */
.notification-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid #e9ecef;
  background: #f8f9fa;
  margin-top: auto;
  flex-shrink: 0;
}

.notification-toggle,
.push-toggle {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e9ecef;
  color: #6c757d;
}

.notification-toggle:hover,
.push-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.notification-toggle.enabled,
.push-toggle.enabled {
  background: #28a745;
  color: white;
}

.notification-toggle.disabled,
.push-toggle.disabled {
  background: #e9ecef;
  color: #6c757d;
}

.notification-toggle:active,
.push-toggle:active {
  transform: scale(0.95);
}

/* Mobile responsive for notification bar */
@media (max-width: 768px) {
  .notification-bar {
    padding: 0.5rem;
    gap: 0.25rem;
  }
  
  .notification-toggle,
  .push-toggle {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
}
