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

:root {
  --bg-primary: #1e1e1e;
  --bg-secondary: #252526;
  --bg-tertiary: #2d2d30;
  --bg-hover: #3c3c3c;
  --text-primary: #cccccc;
  --text-secondary: #858585;
  --text-muted: #6e6e6e;
  --accent: #0078d4;
  --accent-hover: #1a8cff;
  --border: #3c3c3c;
  --success: #4ec9b0;
  --error: #f14c4c;
  --warning: #cca700;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

#app {
  height: 100%;
  display: flex;
}

/* Loading state */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Auth screen */
#auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  text-align: center;
}

#auth-screen h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

#auth-screen p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

#auth-screen a {
  color: var(--accent);
  text-decoration: none;
}

#auth-screen a:hover {
  text-decoration: underline;
}

/* Layout */
.chat-layout {
  display: flex;
  height: 100%;
  width: 100%;
}

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

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

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.org-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  width: 100%;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.channel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.channel-section-header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.channel-section-header button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.channel-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.channel-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.channel-item.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.channel-item .hash {
  margin-right: 8px;
  font-weight: 500;
}

.channel-item .channel-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-item.has-unread {
  color: var(--text-primary);
  font-weight: 600;
}

.channel-item.has-unread .hash {
  color: var(--accent);
}

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

.user-panel {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

.user-info {
  flex: 1;
  overflow: hidden;
}

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

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

/* Main chat area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .hash {
  color: var(--text-secondary);
  font-size: 1.25rem;
}

.chat-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.chat-header .description {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

/* Messages */
.messages-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* Scroll to bottom button */
.scroll-to-bottom {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.15s;
  z-index: 10;
}

.scroll-to-bottom:hover {
  background: var(--bg-hover);
}

.scroll-to-bottom .arrow {
  font-size: 1rem;
}

.scroll-to-bottom .new-messages-badge {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.message {
  display: flex;
  gap: 12px;
  padding: 4px 0;
  margin: 4px 0;
}

.message:hover {
  background: var(--bg-secondary);
  margin-left: -16px;
  margin-right: -16px;
  padding-left: 16px;
  padding-right: 16px;
}

/* Grouped messages (same user, consecutive) */
.message.grouped {
  margin-top: 0;
  padding-top: 1px;
  padding-bottom: 1px;
}

.message.grouped .message-gutter {
  width: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-right: 4px;
}

.message.grouped:hover .message-gutter::before {
  content: attr(data-time);
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  margin: 16px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-separator span {
  padding: 0 12px;
  font-weight: 600;
}

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

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

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

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

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

.message-edited {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
}

.message-text {
  line-height: 1.4;
  word-wrap: break-word;
}

.message-text.deleted {
  color: var(--text-muted);
  font-style: italic;
}

.message-attachments {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-attachment {
  max-width: 300px;
  border-radius: 4px;
  overflow: hidden;
}

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

.message-attachment.file {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.reaction:hover {
  border-color: var(--accent);
}

.reaction.active {
  background: rgba(0, 120, 212, 0.2);
  border-color: var(--accent);
}

.reaction .count {
  color: var(--text-secondary);
}

.message-actions {
  position: absolute;
  right: 16px;
  top: -12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: none;
  padding: 4px;
  gap: 2px;
}

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

.message-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.875rem;
}

.message-actions button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.message-actions .quick-react {
  font-size: 1rem;
  padding: 4px 6px;
  opacity: 0.7;
  transition: opacity 0.15s, transform 0.15s;
}

.message-actions .quick-react:hover {
  opacity: 1;
  transform: scale(1.2);
}

.message-wrapper {
  position: relative;
}

/* Thread indicator */
.thread-indicator {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.thread-indicator:hover {
  text-decoration: underline;
}

/* Chat input */
.chat-input-container {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.chat-input-wrapper {
  background: var(--bg-tertiary);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 0.9rem;
  resize: none;
  max-height: 200px;
  font-family: inherit;
}

.chat-input:focus {
  outline: none;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  padding: 8px;
  gap: 4px;
}

.input-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 1rem;
}

.input-actions button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Type selector dropdown */
.input-type-selector {
  position: relative;
  display: flex;
  align-items: center;
  padding: 8px;
  padding-right: 0;
}

.type-selector-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
  font-size: 1rem;
}

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

.type-selector-menu {
  position: absolute;
  bottom: 100%;
  left: 8px;
  margin-bottom: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  min-width: 160px;
  padding: 4px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  z-index: 100;
}

.type-selector-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.type-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.type-option:hover:not([disabled]) {
  background: var(--bg-hover);
}

.type-option.active {
  background: var(--bg-active);
}

.type-option[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.type-option .type-icon {
  font-size: 1rem;
}

.type-option .type-label {
  flex: 1;
}

.type-option .type-badge {
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  font-weight: 500;
}

.typing-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 4px 16px 0;
  min-height: 20px;
}

.typing-indicator strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingPulse 1.4s infinite;
  margin-right: 4px;
}

@keyframes typingPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Thread panel */
.thread-panel {
  width: 400px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.thread-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.thread-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 4px;
}

.thread-close:hover {
  color: var(--text-primary);
}

.thread-parent {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

/* Emoji picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  display: none;
  max-width: 320px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.emoji-picker.visible {
  display: block;
}

.emoji-search {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  color: var(--text-primary);
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.emoji-search:focus {
  outline: none;
  border-color: var(--accent);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
}

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

/* Upload preview */
.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 0;
}

.upload-item {
  position: relative;
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-item img {
  max-width: 60px;
  max-height: 60px;
  border-radius: 4px;
}

.upload-item .remove {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--error);
  border: none;
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 24px;
  min-width: 400px;
  max-width: 90%;
}

.modal h3 {
  margin-bottom: 16px;
}

.modal-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.btn {
  padding: 8px 16px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

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

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

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* Inline Edit */
.edit-textarea {
  width: 100%;
  min-height: 60px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
}

.edit-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88, 101, 242, 0.2);
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.edit-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex: 1;
}

/* Mentions */
.mention {
  background: rgba(88, 101, 242, 0.2);
  color: var(--accent);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 500;
}

/* Mention Autocomplete Dropdown */
.mention-dropdown {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
}

.mention-option {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.mention-option .avatar {
  flex-shrink: 0;
}

.mention-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mention-option:hover,
.mention-option.selected {
  background: var(--bg-hover);
}

.mention-name {
  font-weight: 500;
  color: var(--text-primary);
}

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

/* Mention Tooltip */
.mention-tooltip {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1001;
  min-width: 180px;
}

.mention-tooltip-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mention-tooltip-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mention-tooltip-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.mention-tooltip-handle {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* User hover targets */
.user-hover {
  cursor: pointer;
}

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

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
  padding: 32px;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}

/* Settings button */
.settings-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Settings modal */
.settings-modal {
  min-width: 420px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  margin-bottom: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}

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

.settings-section {
  margin-bottom: 24px;
}

.settings-section h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* Toggle settings */
.toggle-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.toggle-setting:last-of-type {
  border-bottom: none;
}

.toggle-setting span {
  font-size: 0.9rem;
}

.toggle-switch-container {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch-container input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-tertiary);
  border-radius: 12px;
  transition: background 0.2s;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch-container input:checked + .toggle-switch {
  background: var(--accent);
}

.toggle-switch-container input:checked + .toggle-switch::before {
  transform: translateX(20px);
  background: white;
}

/* Permission status */
.permission-status {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
}

.permission-granted {
  color: var(--success);
  font-size: 0.85rem;
}

.permission-denied {
  color: var(--error);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Button small */
.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 0;
  min-width: 180px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 1001;
}

.menu-item {
  padding: 8px 16px;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-primary);
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* Markdown styles in messages */
.message-text p {
  margin: 0 0 0.5em;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
  margin: 0.75em 0 0.25em;
  font-weight: 600;
}

.message-text h1 { font-size: 1.3em; }
.message-text h2 { font-size: 1.2em; }
.message-text h3 { font-size: 1.1em; }
.message-text h4,
.message-text h5,
.message-text h6 { font-size: 1em; }

.message-text code {
  background: var(--bg-tertiary);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85em;
}

.message-text pre {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}

.message-text blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.message-text ul,
.message-text ol {
  margin: 4px 0;
  padding-left: 24px;
}

.message-text li {
  margin: 2px 0;
}

.message-text table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}

.message-text th,
.message-text td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}

.message-text th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

.message-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message-text a {
  color: var(--accent);
  text-decoration: none;
}

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

.message-text img {
  max-width: 100%;
  border-radius: 4px;
}

/* LaTeX styles */
.message-text .katex-display {
  margin: 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.latex-error {
  color: var(--error);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.85em;
  background: rgba(241, 76, 76, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
}

/* === Org Bar (Slack/Discord style) === */
.org-bar {
  width: 56px;
  min-width: 56px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  border-right: 1px solid var(--border);
}

.org-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  transition: border-radius 0.2s, transform 0.1s;
  background: var(--bg-tertiary);
}

.org-icon:hover {
  border-radius: 16px;
  transform: scale(1.05);
}

.org-icon.active {
  border-radius: 16px;
  box-shadow: 0 0 0 2px var(--accent);
}

.org-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.org-initials {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  font-weight: 600;
  font-size: 14px;
  color: white;
}

/* Sidebar header with org name */
.sidebar-header .org-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

/* User handle in user panel */
.user-handle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* User panel clickable */
.user-panel {
  cursor: pointer;
}

.user-panel:hover {
  background: var(--bg-hover);
}

/* === User Menu === */
.user-menu {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1100;
  min-width: 220px;
  overflow: hidden;
}

.user-menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-tertiary);
}

.user-menu-info {
  flex: 1;
  overflow: hidden;
}

.user-menu-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-handle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.1s;
}

.user-menu-item:hover {
  background: var(--bg-hover);
}

.user-menu-item svg {
  color: var(--text-secondary);
}

/* === Avatar styles === */
.avatar {
  border-radius: 50%;
  flex-shrink: 0;
}

.avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: white;
  text-transform: uppercase;
}

/* === Mobile Navigation Drawer === */
@media (max-width: 768px) {
  /* Drawer container */
  .drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 296px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    display: flex;
  }

  .drawer.open {
    transform: translateX(0);
  }

  /* Overlay behind drawer */
  .drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 999;
  }

  .drawer-overlay.visible {
    opacity: 1;
    visibility: visible;
  }

  /* Mobile header with hamburger */
  .mobile-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
  }

  .hamburger-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px;
    margin-right: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .hamburger-btn svg {
    width: 24px;
    height: 24px;
  }

  .mobile-channel-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
  }

  /* Hide org-bar and sidebar from normal flow on mobile */
  .chat-layout > .org-bar,
  .chat-layout > .sidebar {
    display: none;
  }

  /* Chat main takes full width */
  .chat-main {
    width: 100%;
  }

  /* Hide desktop chat header on mobile */
  .chat-header {
    display: none;
  }
}

/* Desktop: hide mobile elements */
@media (min-width: 769px) {
  .drawer,
  .drawer-overlay,
  .mobile-header {
    display: none !important;
  }
}

/* =================================
   Todo System Styles
   ================================= */

/* Todo Bar - shows under chat header */
.todo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.todo-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.todo-pending {
  font-weight: 500;
}

.todo-completed {
}

.todo-separator {
  color: var(--text-muted);
}

.todo-drawer-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: background 0.15s;
}

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

.chat-input-container.todo-mode .chat-input-wrapper {
  border-color: var(--accent);
}

/* Todo Drawer */
.todo-drawer {
  width: 400px;
  min-width: 400px;
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Hide overlay on desktop - drawer displaces content */
.todo-drawer-overlay {
  display: none;
}

/* Make chat-main shrink when drawer is open */
.chat-layout:has(.todo-drawer) .chat-main {
  min-width: 0;
}

.todo-drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.todo-drawer-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  flex: 1;
}

.todo-drawer-counts {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.todo-count-pending {
}

.todo-count-completed {
}

.todo-count-separator {
  margin: 0 4px;
  color: var(--text-muted);
}

.todo-drawer-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
}

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

/* Todo Drawer Filters */
.todo-drawer-filters {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.todo-filter {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: all 0.15s;
}

.todo-filter:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.todo-filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Todo Drawer List */
.todo-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

/* Todo Item in Drawer */
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  transition: background 0.15s;
}

.todo-item:hover {
  background: var(--bg-hover);
}

.todo-item.completed {
  opacity: 0.7;
}

.todo-item.completed .todo-item-text {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.todo-item-checkbox {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  min-width: 24px;
  min-height: 24px;
}

.todo-item-checkbox:hover {
  color: var(--accent);
}

.todo-item.completed .todo-item-checkbox {
}

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

.todo-item-text {
  font-size: 0.9375rem;
  line-height: 1.4;
  word-wrap: break-word;
}

.todo-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.todo-item-completed-by {
}

/* Todo Message in Chat */
.message-wrapper.todo-message .message-text {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.todo-checkbox {
  background: none;
  border: none;
  font-size: 1.375rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  min-width: 22px;
  min-height: 22px;
}

.todo-checkbox:hover {
  color: var(--accent);
}

.message-wrapper.todo-message.completed .todo-checkbox {
}

.message-wrapper.todo-message.completed .todo-text {
}

.todo-completed-by {
}

/* Mobile Todo Drawer - Fixed overlay */
@media (max-width: 768px) {
  .todo-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    z-index: 1000;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.15);
  }

  .todo-drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
  }

  .todo-bar {
    padding: 8px 12px;
  }

  .todo-drawer-header {
    padding: 12px;
  }

  .todo-drawer-filters {
    padding: 8px 12px;
    flex-wrap: wrap;
  }

  .todo-item {
    padding: 10px 12px;
  }
}

/* ===========================================
   TTS (Text-to-Speech) Styles
   =========================================== */

/* Channel header TTS toggle button */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tts-toggle-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  opacity: 0.6;
  transition: opacity 0.2s, background 0.2s;
}

.tts-toggle-btn:hover {
  opacity: 1;
  background: var(--bg-secondary);
}

.tts-toggle-btn.active {
  opacity: 1;
  background: var(--accent);
  color: white;
}

.tts-toggle-btn .tts-icon {
  display: inline-block;
}

/* Sidebar TTS indicator */
.channel-item .tts-indicator {
  font-size: 0.75rem;
  margin-left: 4px;
  opacity: 0.7;
}

/* TTS Player Bar */
.tts-player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.tts-player-bar.visible {
  transform: translateY(0);
}

.tts-player-progress-track {
  height: 3px;
  background: var(--bg-tertiary);
  width: 100%;
}

.tts-player-progress {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s linear;
}

.tts-player-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 16px;
}

.tts-player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.tts-player-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.tts-player-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tts-player-queue {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.tts-player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tts-player-controls button {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--text-primary);
  transition: background 0.2s;
}

.tts-player-controls button:hover {
  background: var(--bg-tertiary);
}

/* Message TTS button */
.message-actions button[data-action="tts"] {
  opacity: 0.7;
}

.message-actions button[data-action="tts"]:hover {
  opacity: 1;
}

/* Mobile adjustments for TTS player */
@media (max-width: 768px) {
  .tts-player-content {
    padding: 6px 12px;
  }

  .tts-player-title {
    font-size: 0.8rem;
  }

  .tts-player-controls button {
    padding: 4px 8px;
    font-size: 1.1rem;
  }

  .tts-toggle-btn {
    font-size: 1.1rem;
    padding: 4px 6px;
  }
}
