
/* Sidebar collapse — deprecated, kept for legacy */
#sidebar.collapsed {
  width: 48px;
  min-width: 48px;
  overflow: hidden;
}

#sidebar.collapsed .sidebar-brand span,
#sidebar.collapsed .sidebar-search,
#sidebar.collapsed #chatList,
#sidebar.collapsed .user-details,
#sidebar.collapsed .sidebar-actions {
  display: none !important;
}

#sidebar.collapsed .sidebar-header {
  padding: 12px 8px;
  justify-content: center;
}

#sidebar.collapsed .sidebar-logo {
  width: 28px;
  height: 28px;
}

#sidebar.collapsed .sidebar-footer {
  padding: 8px 4px;
  justify-content: center;
}

#sidebar.collapsed .user-info {
  justify-content: center;
}

#sidebar.collapsed .user-avatar {
  min-width: 28px;
  min-height: 28px;
  width: 28px;
  height: 28px;
  font-size: 12px;
}


/* Voice recording overlay */
.voice-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(20, 20, 30, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(8px);
}

.voice-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px;
}

.voice-overlay-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(231, 76, 60, 0.15);
  animation: pulse-record 1s infinite;
}

.voice-overlay-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.btn-voice-stop {
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: Poppins, sans-serif;
  transition: background 0.15s;
  letter-spacing: 0.5px;
}

.btn-voice-stop:hover {
  background: #c0392b;
}
.btn-voice-cancel {
  background: transparent;
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: Poppins, sans-serif;
  transition: all 0.15s;
}

.btn-voice-cancel:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.voice-overlay-timer {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: center;
  letter-spacing: 1px;
}

.btn-voice-send {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: Poppins, sans-serif;
  transition: background 0.15s;
  letter-spacing: 0.5px;
}

.btn-voice-send:hover {
  filter: brightness(1.15);
}


/* Transient processing message */
.transient-message {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  opacity: 0.8;
}

.transient-msg-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
  font-style: italic;
}

.transient-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 992px) {
  #sidebar.collapsed {
    width: 100%;
    min-width: 100%;
  }

}
/* ============================================
   AI Chat - Modern Dark Theme
   ============================================ */

/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1e1b2e;
  --bg-secondary: #19191f;
  --bg-tertiary: #22222b;
  --bg-hover: #2a2a35;
  --bg-active: #32324a;

  --text-primary: #e8e8ed;
  --text-secondary: #9b9baf;
  --text-tertiary: #6b6b80;
  --text-inverse: #ffffff;

  --accent: #DD3333;
  --accent-hover: var(--accent);
  --accent-muted: color-mix(in srgb, var(--accent) 15%, transparent);
  --accent-glow: color-mix(in srgb, var(--accent) 50%, transparent);

  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;

  --border: #2a2a35;
  --border-light: #1e1e28;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);

  /* Custom colors from setup — fall back to existing values */
  --custom-accent: var(--accent);
  --custom-ai-bubble: var(--bg-tertiary);
  --custom-font: 'Inter', system-ui, sans-serif;
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(124, 58, 237, 0.3);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 320px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: var(--custom-font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

input, button, textarea, select {
  font-family: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ============================================
   Auth Pages
   ============================================ */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(221, 51, 51, 0.08) 0%, transparent 60%);
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}

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

.auth-logo {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-group input::placeholder {
  color: var(--text-tertiary);
}

.hint {
  font-size: 12px;
  color: var(--text-tertiary);
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn-primary:hover {
  background: var(--custom-accent-blue, var(--accent-hover));
  filter: brightness(1.2);
  box-shadow: var(--shadow-glow);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

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

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  border-color: var(--text-tertiary);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-danger-ghost {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-full {
  width: 100%;
}



.btn-invite,
.btn-image {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-image:hover,
.btn-invite:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--accent);
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
}

.image-preview.hidden {
  display: none;
}

.image-preview img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}

.image-preview-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.image-preview-info span {
  flex: 1;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-info .btn-icon {
  width: 24px;
  height: 24px;
  font-size: 16px;
  color: var(--text-tertiary);
}

.image-preview-info .btn-icon:hover {
  color: var(--accent);
}

/* Drag & drop overlay */
body.drag-over::after {
  content: 'Drop image or PDF to upload';
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(34, 34, 34, 0.85);
  backdrop-filter: blur(4px);
}

body.drag-over::before {
  content: '';
  position: fixed;
  inset: 12px;
  z-index: 10000;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  pointer-events: none;
}

/* TTS button on Ruby messages */
.btn-tts {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  color: var(--text-muted);
  opacity: 0.6;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  margin-top: 4px;
}
.btn-tts:hover,
.btn-tts.speaking {
  opacity: 1;
  color: var(--accent);
  background: var(--bg-hover);
}

/* Message with image */
.message-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-md);
  margin-top: 4px;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
  background: var(--bg-tertiary);
  min-height: 40px;
}

.message-image:hover {
  opacity: 0.9;
}

/* Message file attachment (PDF) */
.message-file {
  margin-top: 4px;
}

.message-file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.2s;
}

.message-file-link:hover {
  background: rgba(221, 51, 51, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.message-file-link svg {
  flex-shrink: 0;
}

/* ============================================
   Alerts
   ============================================ */

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 20px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* ============================================
   App Layout
   ============================================ */

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
}

/* ============================================
   Sidebar
   ============================================ */

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.admin-logo-img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.auth-logo-img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-avatar-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.profile-avatar-img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
}

.sidebar-search {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-search svg {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.sidebar-search input::placeholder {
  color: var(--text-tertiary);
}

/* Chat list delete button */
.chat-item {
  display: flex;
  align-items: center;
}

.chat-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.chat-item-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.chat-item:hover .chat-item-delete,
.chat-item-delete:focus-visible {
  opacity: 1;
}

.chat-item-delete:hover {
  color: #aaa;
  background: rgba(255,255,255,0.06);
}

/* Chat List */
#chatList {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#chatList::-webkit-scrollbar {
  width: 4px;
}

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

#chatList::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  transition: all 0.15s;
}

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

.chat-item.active {
  background: rgba(227, 62, 51, 0.12);
  border-left: 3px solid var(--accent);
}

.chat-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.chat-item.active .chat-icon {
  background: var(--accent);
  color: white;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-preview {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-item-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.chat-details {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chat-item:hover .chat-item-delete {
  opacity: 0.6;
}

.chat-item-delete:hover {
  opacity: 1 !important;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.chat-item.active .chat-item-delete {
  opacity: 0.6;
}

/* Sidebar Footer */
.sidebar-overlay {
  display: none;
}

.sidebar-overlay:not(.hidden) {
  display: block;
}

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

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  transition: background 0.2s;
}

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

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #aa2222);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

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

.user-actions {
  display: flex;
  gap: 2px;
}

/* ============================================
   Main Area
   ============================================ */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-tertiary);
}

.empty-state-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 100%;
}

.empty-state-logo {
  max-width: 120px;
  width: 100%;
  height: auto;
}

.empty-icon {
  opacity: 0.4;
  margin-bottom: 8px;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
  color: var(--text-tertiary);
  text-align: center;
  max-width: 280px;
}

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

.group-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(221, 51, 51, 0.1);
  border-bottom: 1px solid rgba(221, 51, 51, 0.2);
  font-size: 13px;
  color: var(--text-secondary);
}

.group-notice.hidden {
  display: none;
}

.group-notice svg {
  flex-shrink: 0;
  color: var(--accent);
}

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

.chat-header-info h2 {
  font-size: 16px;
  font-weight: 600;
}

.chat-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

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

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

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

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

.message {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  max-width: 85%;
  animation: messageIn 0.2s ease-out;
}



/* ── Chat.ejs inline CSS replacements ───────────── */

.logout-form {
  display: inline;
}

/* Hidden inputs (file picker, etc) */
.hidden-input {
  display: none !important;
}

/* Margin helper */
.margin-top-12 {
  margin-top: 12px;
}

#forwardConfirmBtn.margin-top-12 {
  margin-top: 12px;
}

/* Narrow modal */
.modal-narrow {
  max-width: 400px;
}

/* Send button overrides */
.btn-send {
  background: var(--custom-accent-blue, var(--custom-accent)) !important;
  opacity: 0.6;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 0.2s;
  padding: 0;
}
.btn-send:hover {
  opacity: 1 !important;
}
.btn-send svg {
  width: 20px;
  height: 20px;
}

/* Mobile media query overrides */


@media (max-width: 992px) {
  .input-area {
    padding: 8px 12px !important;
  }
  .message-form {
    gap: 8px !important;
    overflow: visible !important;
    flex-wrap: nowrap !important;
  }
  .chat-view {
    overflow-y: auto !important;
  }
  #messagesContainer {
    min-height: 100px !important;
  }
  .chat-item-delete {
    opacity: 0.6;
  }
  .chat-header {
    display: none;
  }
}

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

.message.ai {
  align-self: flex-start;
}

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


/* ── Avatar classes (moved from chat.js inline) ───── */
.avatar-ai {
  background: #E33E33 !important;
  color: #fff !important;
}

.avatar-user {
  background: #6366f1 !important;
  color: #fff !important;
}

/* Thinking bubble — pulse-dot animation */
.thinking-bubble {
  background: transparent !important;
  border: none !important;
}

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.thinking-indicator .thinking-label {
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.dot-pulse {
  display: flex;
  align-items: center;
  gap: 3px;
}

.dot-pulse span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.2s infinite ease-in-out;
}

.dot-pulse span:nth-child(2) { animation-delay: 0.15s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1.1); opacity: 1; }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  margin-top: 4px;
  overflow: hidden;
}

.msg-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message.ai .message-avatar {
  background: linear-gradient(135deg, var(--accent), #aa2222);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.message-bubble {
  padding: 6px 12px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.2;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  position: relative;
}

.message.ai .message-bubble {
  background: var(--custom-ai-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text-primary);
}

.message.user .message-bubble {
  background: var(--custom-accent);
  border-top-right-radius: 4px;
  color: white;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-align: right;
}

.message.user .message-time {
  color: rgba(255,255,255,0.6);
}

/* Code blocks */
.code-block-wrapper {
  background: #1a1a2e;
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  margin: 8px 0;
  overflow: hidden;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #222240;
  border-bottom: 1px solid #2a2a3e;
  font-size: 12px;
}

.code-lang {
  color: #888;
  text-transform: uppercase;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.copy-code-btn {
  background: none;
  border: 1px solid #3a3a5e;
  color: #aaa;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-code-btn:hover {
  background: #3a3a5e;
  color: #fff;
}

.copy-code-btn.copied {
  background: #2a7a3e;
  border-color: #2a7a3e;
  color: #fff;
}

.code-block-wrapper pre {
  margin: 0;
  padding: 12px 16px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  background: transparent;
}

.code-block-wrapper code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e0e0f0;
  background: none;
  padding: 0;
}

/* Syntax highlighting colors */
.hl-comment { color: #6a9955; font-style: italic; }
.hl-string { color: #ce9178; }
.hl-number { color: #b5cea8; }
.hl-keyword { color: #569cd6; }
.hl-builtin { color: #4ec9b0; }
.hl-operator { color: #d4d4d4; }
.hl-tag { color: #569cd6; }
.hl-attr { color: #9cdcfe; }
.hl-selector { color: #d7ba7d; }
.hl-hex { color: #b5cea8; }
.hl-flag { color: #c586c0; }
.hl-json-key { color: #9cdcfe; }
.hl-prop { color: #ce9178; }

.message-bubble code:not(.code-block-wrapper code) {
  background: #2a2a3e;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

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

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

.message-bubble p {
  margin: 8px 0;
}

.message-bubble p:first-child {
  margin-top: 0;
}

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

.message-bubble .message-image {
  clear: both;
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

.message-bubble .message-image img,
.message-bubble img.message-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  cursor: pointer;
  margin: 8px 0;
  object-fit: contain;
}

/* Typing / Loading indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-top-left-radius: 4px;
  align-self: flex-start;
  margin-top: 4px;
}

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

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

/* Thinking dots for inline messages */
.thinking-dots { font-style: italic; opacity: 0.7; }
.thinking-dots .dot {
  animation: thinkBlink 1.4s infinite;
  opacity: 0;
}
.thinking-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0.4s; }
.thinking-dots .dot:nth-child(4) { animation-delay: 0.6s; }

@keyframes thinkBlink {
  0%, 60%, 100% { opacity: 0; }
  30% { opacity: 1; }
}

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.input-area {
  position: relative;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.message-form {
  display: flex;
  align-items: center;
  gap: 12px;
}

.message-form input,
.message-form textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  resize: none;
  overflow: hidden;
  min-height: 20px;
  max-height: 120px;
  font-family: inherit;
  transition: all 0.2s;
}

.message-form input:focus,
.message-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.message-form input::placeholder {
  color: var(--text-tertiary);
}

/* ============================================
   Modal
   ============================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  z-index: 1000;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease-out;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2,
.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.modal-body {
  padding: 20px 24px 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  width: 32px;
  height: 32px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

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

.modal-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 24px 24px;
}

.modal-footer .btn {
  flex: 1;
  max-width: 200px;
}

/* Toggle Switch */
.toggle-group {
  margin-bottom: 8px;
}

.toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.toggle-label span {
  font-size: 14px;
  font-weight: 500;
}

.toggle-row {
  display: flex;
  align-items: center;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 0;
}

.toggle-row-label {
  font-size: 14px;
  font-weight: 500;
  display: block;
  margin-bottom: 2px;
}

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

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: 0.3s;
}

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

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

/* Invite */
.invite-link-container {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.invite-link-container input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.add-user-row {
  display: flex;
  gap: 8px;
}

.add-user-row input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

/* Members List */
.members-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

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

.member-info {
  flex: 1;
}

.member-name {
  font-size: 14px;
  font-weight: 500;
}

.member-email {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ============================================
   Admin Panel
   ============================================ */

.admin-layout {
  display: flex;
  min-height: 100dvh;
}

.admin-body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
}

.admin-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow-y: auto;
}

.admin-nav {
  padding: 12px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  transition: all 0.2s;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link.active {
  background: var(--surface-hover);
  color: var(--text-primary);
  font-weight: 600;
}

.admin-main,
.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  height: 100dvh;
}

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

.admin-header h1 {
  font-size: 26px;
  font-weight: 700;
}

.admin-header p.hint {
  font-size: 14px;
  color: var(--text-tertiary);
  margin: 0;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 24px;
  width: 100%;
  box-sizing: border-box;
}

.card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.checkbox-group {
  display: flex;
  align-items: flex-end;
  padding-bottom: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.checkbox-label input:checked + .checkbox-custom {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: '✓';
  color: white;
  font-size: 14px;
  font-weight: 700;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
}

.users-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.users-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}

.users-table tr:last-child td {
  border-bottom: none;
}

.users-table tr:hover td {
  background: var(--bg-hover);
}

.actions-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.badge-admin {
  background: var(--accent-muted);
  color: var(--accent);
}

.badge-user {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* ============================================
   Utilities
   ============================================ */

.hidden {
  display: none !important;
}

/* ============================================
   Responsive
   ============================================ */

.btn-mobile-only {
  display: none;
}

.btn-desktop-only {
  display: flex;
}

@media (max-width: 992px) {
  .btn-desktop-only {
    display: none;
  }
}

.mobile-top-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

.mobile-top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mobile-top-actions .btn-icon {
  width: 34px;
  height: 34px;
  color: var(--text-tertiary);
}

.mobile-top-actions .btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.mobile-top-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-breadcrumb {
  font-size: 14px;
  color: var(--text-muted);
  display: none;
  align-items: center;
  gap: 4px;
}

.mobile-breadcrumb::before {
  content: '›';
  font-size: 18px;
  color: var(--text-muted);
  margin-right: 2px;
}

.mobile-breadcrumb.visible {
  display: inline-flex;
}

@media (max-width: 992px) {
  .btn-mobile-only {
    display: flex;
  }

  #main {
    position: relative;
    flex: 1;
    height: 100dvh;
    min-height: 100dvh;
  }

  #app {
    position: relative;
    overflow: hidden;
  }

  #sidebar {
    width: 100%;
    min-width: 100%;
    position: absolute;
    z-index: 30;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
  }

  #sidebar.hidden-mobile {
    transform: translateX(-100%);
    display: flex;
    flex-direction: column;
  }

  #sidebarOverlay {
    display: none;
    position: fixed;
    z-index: 20;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: rgba(0,0,0,0.5);
  }

  #sidebarOverlay:not(.hidden) {
    display: block;
  }



  #main {
    width: 100%;
  }

  .message {
    max-width: 85%;
    padding: 2px 0;
    gap: 3px;
  }
  .message-bubble {
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.35;
  }
  .message-avatar {
    width: 26px;
    height: 26px;
    font-size: 11px;
    margin-top: 2px;
  }
  .message-sender {
    display: none;
  }
  .message-time {
    font-size: 9px;
    margin-top: 0;
  }
  .chat-header {
    display: none;
  }
  .chat-item-delete {
    opacity: 0.6;
  }
  .message-text {
    line-height: 1.3;
    margin: 0;
    padding: 0;
  }

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

  .mobile-top-bar {
    display: flex;
  }

  .chat-header {
    padding: 10px 12px;
    gap: 8px;
  }

  .chat-header-left {
    flex: 1;
    min-width: 0;
  }

  .chat-header-info h2 {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-header-actions {
    gap: 4px;
  }

  .chat-header-actions .btn-sm {
    padding: 6px 8px;
    font-size: 12px;
  }

  .chat-header-actions .btn-sm span {
    display: none;
  }

  .chat-header-actions #deleteChatBtn span {
    display: none;
  }

  .messages-container {
    padding: 12px;
  }

  .empty-state {
    height: 100%;
    min-height: calc(100dvh - 70px);
  }

  .empty-state-content {
    padding-top: 64px;
  }



  .empty-state h2 {
    font-size: 16px;
  }

  .empty-state p {
    font-size: 13px;
  }

  .admin-layout {
    flex-direction: column;
    overflow: hidden;
    height: 100dvh;
  }

  .admin-sidebar {
    width: 100%;
    min-width: 100%;
    flex-direction: row;
    align-items: center;
    height: auto;
    min-height: 50px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: relative;
  }

  .admin-sidebar .sidebar-header {
    display: none;
  }

  .admin-nav {
    display: flex;
    flex-direction: row;
    gap: 6px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
    width: 100%;
    white-space: nowrap;
    /* gradient fade edges for scroll affordance */
    mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
  }

  .admin-nav::-webkit-scrollbar {
    display: none;
  }

  .admin-nav .nav-link {
    flex-shrink: 0;
    scroll-snap-align: center;
    padding: 8px 16px;
    font-size: 13px;
    white-space: nowrap;
    gap: 6px;
  }

  .admin-nav .nav-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .admin-main,
  .admin-content {
    padding: 20px;
    overflow-y: auto;
    height: calc(100dvh - 50px);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

/* Context Menu */
.context-menu-container {
  position: relative;
  display: inline-block;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.context-menu {
  position: fixed;
  z-index: 1000;
  background: #1a1a2e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 200px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  font-family: inherit;
  text-align: left;
}

.context-menu-item svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

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

.context-menu-item.delete-user-btn:hover {
  color: var(--danger);
}

.context-menu-item.delete-user-btn:hover svg {
  color: var(--danger);
}

.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

.context-menu.hidden {
  display: none;
}

/* Email Settings */
.settings-form {
  width: 100%;
  max-width: 100%;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.help-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.help-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.help-table tr:last-child td {
  border-bottom: none;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--surface-hover);
  transition: 0.2s;
  border-radius: 24px;
}

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

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

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

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.form-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.form-section h3 {
  font-size: 15px;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.form-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.form-hint code {
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.feature-list,
.help-list {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.form-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* =============================================
 * Message Actions Row (reactions, forward, edit, delete)
 * ============================================= */
.msg-actions-row {
  display: flex;
  gap: 2px;
  align-items: center;
  margin-top: 2px;
  padding-left: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.message-content:hover .msg-actions-row {
  opacity: 1;
}

.msg-action-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 13px;
  width: 24px;
  height: 22px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.msg-action-btn:hover {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.08);
}

/* =============================================
 * Reaction Pills (shown inline)
 * ============================================= */
.msg-reactions {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 5px;
  border-radius: 10px;
  font-size: 12px;
  background: rgba(221, 51, 51, 0.1);
  border: 1px solid rgba(221, 51, 51, 0.15);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  height: 20px;
}

.reaction-pill:hover {
  background: rgba(221, 51, 51, 0.2);
  border-color: rgba(221, 51, 51, 0.3);
}

.reaction-pill.reacted {
  background: rgba(221, 51, 51, 0.25);
  border-color: var(--accent);
}

.reaction-add-pill {
  font-size: 14px;
  padding: 1px 4px;
  height: 20px;
  background: none;
  border-color: transparent;
  color: rgba(255, 255, 255, 0.25);
}

.reaction-add-pill:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.5);
}

.message-bubble .edit-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 6px;
}

.edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.edit-actions .btn {
  padding: 4px 12px;
  font-size: 12px;
}

.edited-badge {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-left: 6px;
  font-style: italic;
}

.message.deleted .message-bubble {
  opacity: 0.4;
  font-style: italic;
  font-size: 12px;
  color: var(--text-tertiary);
}

/*
 * (removed — consolidated into msg-reactions above)
 */

/*
 * (removed — emoji picker moved below)
 */

/* =============================================
 * Emoji Picker
 * ============================================= */
emoji-picker {
  --background: var(--bg-secondary);
  --border-color: var(--border);
  --category-emoji-size: 1.2rem;
  --emoji-size: 1.5rem;
  --indicator-color: var(--accent);
  --input-background: var(--bg-primary);
  --input-border-color: var(--border);
  --input-font-color: var(--text-primary);
  --input-placeholder-color: var(--text-tertiary);
  --num-columns: 8;
  --outline-color: var(--accent);
  height: 360px;
  width: 340px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* =============================================
 * Input Emoji/GIF Picker
 * ============================================= */
.input-picker-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  overflow: hidden;
  width: 350px;
}

.input-picker-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.picker-tab {
  flex: 1;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.picker-tab.active {
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent);
  background: var(--bg-secondary);
}

.picker-tab:hover:not(.active) {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}

.picker-panel.hidden {
  display: none;
}

.picker-panel emoji-picker {
  border-radius: 0 0 12px 12px;
}

.gif-search-wrap {
  padding: 8px;
}

.gif-search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  box-sizing: border-box;
}

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

.gif-results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.gif-result {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  transition: transform 0.1s;
}

.gif-result:hover {
  transform: scale(1.03);
}

.gif-result img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.gif-hint,
.gif-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px 0;
  color: var(--text-tertiary);
  font-size: 13px;
}

.gif-results::-webkit-scrollbar {
  width: 5px;
}

.gif-results::-webkit-scrollbar-track {
  background: transparent;
}

.gif-results::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

/* =============================================
 * Read Receipts
 * ============================================= */
.read-receipts {
  display: flex;
  gap: 0;
  justify-content: flex-end;
  margin-top: 2px;
  padding-right: 4px;
}

.read-receipt-avatar {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
  margin-left: -4px;
  object-fit: cover;
}

.read-receipt-avatar:first-child {
  margin-left: 0;
}

.read-receipt-avatar-text {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
  margin-left: -4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 700;
  background: var(--accent);
  color: white;
}

/* =============================================
 * Forward Modal
 * ============================================= */
.forward-chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.forward-chat-item:hover {
  background: var(--surface-hover);
}

.forward-chat-item.selected {
  background: rgba(221, 51, 51, 0.15);
  border: 1px solid var(--accent);
}

.forward-chat-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.forward-chat-title {
  font-size: 14px;
  font-weight: 500;
}

/* =============================================
 * Scroll-to-bottom button
 * ============================================= */
.scroll-bottom-btn {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(221, 51, 51, 0.4);
  transition: all 0.2s;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
}

.scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: all;
}

.scroll-bottom-btn:hover {
  transform: translateX(-50%) scale(1.1);
}

.messages-container {
  position: relative;
}

.message-text {
  line-height: 1.35;
  margin: 0;
  padding: 0;
}

/* =============================================
 * Slash Command Popup
 * ============================================= */
.slash-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 6px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
}

.slash-popup.hidden {
  display: none;
}

.slash-command {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.slash-command:hover,
.slash-command.active {
  background: var(--surface-hover);
}

.slash-cmd-name {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  min-width: 80px;
}

.slash-cmd-desc {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* =============================================
 * Notification permission banner
 * ============================================= */
.notif-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

.notif-banner button {
  white-space: nowrap;
}

.notif-banner.hidden {
  display: none;
}

/* Timestamp tooltip */
.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-align: right;
  cursor: default;
}

.message-time:hover {
  color: var(--text-secondary);
}

/* Voice message */
.btn-voice {
  transition: all 0.2s;
  color: var(--text-tertiary);
}

.btn-voice:hover {
  color: var(--accent);
}

.btn-voice.recording {
  color: var(--accent);
  animation: pulse-record 1s infinite;
}

.btn-voice.recording svg {
  filter: drop-shadow(0 0 4px var(--accent));
}

@keyframes pulse-record {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.voice-player {
  margin-bottom: 2px;
}

.voice-player audio {
  border-radius: 20px;
  background: var(--bg-secondary);
  height: 36px;
}

.voice-caption {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
  padding-left: 2px;
}

.message.user .voice-player audio {
  filter: invert(0) brightness(1.2);
}

.audio-message audio {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.message.user .audio-message audio {
  filter: invert(0) brightness(1.2);
}

/* ============================================
   Emoji & GIF Picker
   ============================================ */

.emoji-picker-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.15s ease-out;
}

.emoji-picker-overlay.hidden {
  display: none;
}

.emoji-picker-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 420px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
  animation: slideUp 0.2s ease-out;
}

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

.emoji-picker-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
  font-weight: 500;
}

.emoji-picker-tab:hover {
  background: var(--bg-tertiary);
}

.emoji-picker-tab.active {
  background: var(--accent);
  color: white;
}

.emoji-picker-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

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

.emoji-picker-content {
  flex: 1;
  overflow-y: auto;
  min-height: 250px;
}

.emoji-picker-panel {
  display: none;
}

.emoji-picker-panel.active {
  display: block;
}

/* Emoji picker custom element */
emoji-picker {
  --background: var(--bg-secondary);
  --border-color: var(--border);
  --input-border-color: var(--border);
  --input-background: var(--bg-tertiary);
  --input-color: var(--text-primary);
  --outline-color: var(--accent);
  --hover: var(--bg-tertiary);
  --indicator-color: var(--accent);
  width: 100%;
  height: 300px;
  --num-columns: 8;
  font-size: 14px;
}

/* GIF search */
.gif-search-bar {
  padding: 12px;
}

.gif-search-bar input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}

.gif-search-bar input:focus {
  border-color: var(--accent);
}

.gif-results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 0 12px 12px;
}

.gif-results img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s;
}

.gif-results img:hover {
  transform: scale(1.03);
}

@media (max-width: 992px) {
  .emoji-picker-container {
    max-width: 100%;
    border-radius: 0;
    max-height: 50vh;
  }
}
