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

html { height: 100%; font-size: 15px; }

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

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

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent-light); box-shadow: 0 0 0 1px var(--accent-light); }

ul { list-style: none; }

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

[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.hidden { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 10; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700; font-size: 14px;
  transition: background 0.1s, box-shadow 0.1s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-ghost    { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-full     { width: 100%; justify-content: center; }
.btn-sm       { padding: 4px 10px; font-size: 13px; font-weight: 400; }
.btn-link     { padding: 0; font-size: 13px; color: var(--text-link); }
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
  position: relative;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--text-heading); }
.field input, .field textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.optional { font-weight: 400; color: var(--text-muted); }
.form-error   { color: var(--danger); font-size: 13px; margin-bottom: 12px; padding: 8px; background: rgba(232,81,90,0.1); border-radius: var(--radius-sm); }
.form-success { color: #166534; font-size: 13px; margin-bottom: 12px; padding: 8px; background: #dcfce7; border-radius: var(--radius-sm); }
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.radio-label input[type="radio"] { width: auto; }

/* ── Auth Screen ──────────────────────────────────────────────────────────── */
.auth-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
  overflow-y: auto;
}
.auth-container { width: 100%; max-width: 420px; padding: 24px; }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo .logo-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 26px; font-weight: 900; color: var(--text-heading); }
.auth-logo p { color: var(--text-secondary); margin-top: 4px; }
.auth-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; }
.auth-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 24px; color: var(--text-heading); }
.auth-switch { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-secondary); }
.auth-hint   { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ── Workspace selector ───────────────────────────────────────────────────── */
#workspace-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); overflow-y: auto;
}
.workspace-container { width: 100%; max-width: 480px; padding: 24px; }
.workspace-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; }
.workspace-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--text-heading); }
.workspace-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.workspace-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.workspace-item:hover { border-color: var(--accent-light); background: var(--bg-hover); }
.workspace-item-icon { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 16px; color: white; flex-shrink: 0; }
.workspace-item-info { flex: 1; }
.workspace-item-name { font-weight: 700; font-size: 15px; }
.workspace-item-role { font-size: 12px; color: var(--text-secondary); }
.workspace-actions { margin-top: 4px; }

/* ── App Layout ───────────────────────────────────────────────────────────── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  overflow: hidden;
}

.sidebar-workspace {
  display: flex; align-items: center;
  padding: 0 12px 0 16px;
  height: 49px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.workspace-name-btn {
  flex: 1; display: flex; align-items: center; gap: 6px;
  font-weight: 900; font-size: 15px;
  padding: 4px 6px; border-radius: var(--radius-sm);
  transition: background 0.1s;
  overflow: hidden;
}
.workspace-name-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-name-btn:hover { background: var(--sidebar-hover); }
.workspace-name-btn { color: var(--sidebar-text-active); }

.sidebar-workspace-actions { display: flex; gap: 2px; }
.sidebar-workspace-actions .icon-btn { color: var(--sidebar-text); }
.sidebar-workspace-actions .icon-btn:hover { color: var(--sidebar-text-active); background: var(--sidebar-hover); }

.badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--danger); color: white;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-search { padding: 10px 12px; flex-shrink: 0; }
.search-trigger {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 6px 10px;
  background: var(--sidebar-hover); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--sidebar-text);
  transition: background 0.1s;
}
.search-trigger:hover { background: rgba(255,255,255,0.12); color: var(--sidebar-text-active); }
.search-trigger kbd { margin-left: auto; font-size: 11px; opacity: 0.5; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

.nav-section { margin-bottom: 4px; }
.nav-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; font-size: 13px; font-weight: 700;
  color: var(--sidebar-label);
  cursor: default;
}
.nav-add-btn {
  width: 20px; height: 20px; border-radius: 4px; font-size: 16px;
  color: var(--sidebar-label); line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.nav-add-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }

.nav-list { }
.nav-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 14px 5px 16px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px;
  color: var(--sidebar-text);
  transition: background 0.1s, color 0.1s;
  position: relative;
  user-select: none;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active) !important;
  font-weight: 700;
  border-left-color: var(--sidebar-active-border);
}
.nav-item-icon { font-size: 14px; opacity: 0.7; flex-shrink: 0; }
.nav-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item-badge { background: var(--danger); color: white; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 5px; min-width: 18px; text-align: center; flex-shrink: 0; }
.nav-item-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--bg-sidebar); position: absolute; bottom: 0; right: 0; }
.status-active  { background: var(--success); }
.status-away    { background: var(--warning); }
.status-dnd     { background: var(--danger); }
.status-offline { background: var(--text-muted); }

.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.user-avatar-wrap { position: relative; }
.user-info { flex: 1; overflow: hidden; }
.user-name { display: block; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--sidebar-text-active); }
.user-status-msg { display: block; font-size: 11px; color: var(--sidebar-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Avatar ───────────────────────────────────────────────────────────────── */
.avatar {
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; text-transform: uppercase;
  flex-shrink: 0; overflow: hidden;
  background-size: cover; background-position: center;
}
.avatar-sm  { width: 28px; height: 28px; font-size: 11px; }
.avatar-md  { width: 36px; height: 36px; font-size: 14px; }
.avatar-lg  { width: 48px; height: 48px; font-size: 18px; }

/* ── Chat area ────────────────────────────────────────────────────────────── */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-primary); }

.chat-welcome {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-secondary);
}
.welcome-content { text-align: center; }
.welcome-icon { font-size: 64px; display: block; margin-bottom: 16px; }
.welcome-content h2 { font-size: 22px; font-weight: 900; color: var(--text-heading); margin-bottom: 8px; }

.chat-view { display: flex; flex-direction: column; height: 100%; }

/* ── Chat header ──────────────────────────────────────────────────────────── */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  height: 49px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-primary);
}
.chat-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.channel-icon { font-size: 18px; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.channel-info { min-width: 0; }
.channel-name { font-weight: 900; font-size: 15px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-topic { font-size: 12px; color: var(--text-secondary); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--warning);
  background: color-mix(in srgb, var(--warning) 16%, transparent);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.connection-status.offline {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
}
.connection-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  animation: reconnectPulse 1.2s ease-in-out infinite;
}
.connection-status.offline .connection-status-dot {
  background: var(--danger);
}
.chat-header-right { display: flex; align-items: center; gap: 4px; }
.header-btn { color: var(--text-secondary); }
.member-count { font-size: 13px; color: var(--text-secondary); padding-left: 4px; }
.mobile-back-btn { display: none; }

@keyframes reconnectPulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.25); opacity: 1; }
}

/* ── Chat body ────────────────────────────────────────────────────────────── */
.chat-body { display: flex; flex: 1; overflow: hidden; }

/* ── Side panel (pins, members) ───────────────────────────────────────────── */
.side-panel {
  width: 280px; flex-shrink: 0; min-width: 200px; max-width: 600px;
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}
.files-panel-resize-handle {
  position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  cursor: col-resize; z-index: 10;
  background: transparent;
  transition: background 0.15s;
}
.files-panel-resize-handle:hover,
.files-panel-resize-handle.dragging {
  background: var(--accent);
}
.side-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 14px;
}
.pins-list { flex: 1; overflow-y: auto; padding: 8px; }
.pin-item {
  position: relative; padding: 10px 12px; border-radius: 6px;
  cursor: pointer; margin-bottom: 4px; border: 1px solid var(--border);
  background: var(--bg-secondary);
}
.pin-item:hover { background: var(--bg-hover); }
.pin-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; flex-wrap: wrap; }
.pin-author { font-weight: 700; color: var(--text-primary); }
.pin-content { font-size: 13px; color: var(--text-primary); line-height: 1.4; word-break: break-word; padding-right: 20px; }
.pin-unpin-btn {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 12px; padding: 2px 4px; border-radius: 4px;
}
.pin-unpin-btn:hover { background: var(--bg-hover); color: var(--danger); }
.pins-empty { padding: 24px 16px; text-align: center; font-size: 13px; color: var(--text-muted); line-height: 1.6; }

/* Search result highlight */
mark { background: #fef08a; color: inherit; border-radius: 2px; padding: 0 1px; }

/* ── Messages panel ───────────────────────────────────────────────────────── */
.messages-panel { display: flex; flex-direction: column; flex: 1; min-width: 0; }

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

.load-more-container { text-align: center; padding: 8px; }

/* ── Message bubble ───────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 10px;
  padding: 4px 20px;
  position: relative;
  background: var(--bg-message);
  transition: background 0.1s, box-shadow 0.15s;
}
.message:hover { background: var(--bg-message-hover); }
.message.reaction-target {
  background: color-mix(in srgb, var(--accent-light) 14%, var(--bg-message));
  box-shadow: inset 3px 0 0 var(--accent-light);
}

.message-compact { padding-left: 68px; }
.message-compact .message-avatar { display: none; }

.message-avatar { flex-shrink: 0; padding-top: 2px; }

.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message-author { font-weight: 700; font-size: 14px; cursor: pointer; }
.message-author:hover { text-decoration: underline; }
.message-time { font-size: 11px; color: var(--text-muted); }
.message-edited { font-size: 11px; color: var(--text-muted); font-style: italic; }

.message-content { font-size: 14px; line-height: 1.6; word-break: break-word; white-space: pre-wrap; }
.message-content code { background: var(--bg-tertiary); padding: 2px 5px; border-radius: 3px; font-size: 13px; font-family: 'Fira Code', 'Menlo', monospace; }
.message-content pre { background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; margin: 4px 0; }
.message-content pre code { background: none; padding: 0; }
.message-content .mention { background: var(--mention-bg); color: var(--mention-color); border-radius: 3px; padding: 0 4px; font-weight: 600; cursor: pointer; }

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

.message-image { max-width: 360px; max-height: 280px; border-radius: var(--radius-sm); margin-top: 4px; cursor: zoom-in; object-fit: cover; }

.message-file-attachment {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); max-width: 320px;
  background: var(--bg-secondary);
}
.file-attach-icon { font-size: 24px; flex-shrink: 0; }
.file-attach-info { flex: 1; min-width: 0; }
.file-attach-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-attach-meta { font-size: 11px; color: var(--text-secondary); }
.file-attach-download { padding: 4px 10px; font-size: 12px; }

.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 13px; cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.reaction-chip:hover { border-color: var(--accent-light); background: var(--bg-hover); }
.reaction-chip.reacted { border-color: var(--accent); background: rgba(17,100,163,0.15); color: var(--accent-light); }
.reaction-chip .reaction-count { font-size: 12px; font-weight: 700; }

.message-thread-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 4px; font-size: 12px; color: var(--text-link);
  background: none; border: none; cursor: pointer;
  padding: 2px 0;
}
.message-thread-btn:hover { text-decoration: underline; }

/* Message actions (hover toolbar) */
.message-actions {
  position: absolute; top: -16px; right: 16px;
  display: none;
  background: var(--bg-dropdown); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 10;
}
.message:hover .message-actions { display: flex; }
.msg-action-btn {
  width: 28px; height: 28px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Date divider */
.date-divider {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  color: var(--text-muted); font-size: 12px; font-weight: 700;
}
.date-divider::before, .date-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* System message */
.message-system {
  padding: 6px 20px;
  font-size: 13px; color: var(--text-secondary);
  font-style: italic;
  display: flex; align-items: center; gap: 8px;
}
.message-system::before { content: 'ℹ'; font-style: normal; }

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 20px; font-size: 13px; color: var(--text-secondary);
  height: 28px;
}
.typing-dots { display: flex; gap: 3px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,80%,100% { transform: scale(1); opacity:0.4; } 40% { transform: scale(1.2); opacity:1; } }

/* ── Message input ────────────────────────────────────────────────────────── */
.message-input-area {
  padding: 8px 20px 16px;
  border-top: 1px solid var(--border);
  position: relative;
}
.message-input-toolbar { display: flex; gap: 2px; margin-bottom: 4px; }
.toolbar-btn {
  width: 32px; height: 32px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-secondary);
  transition: background 0.1s;
}
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.message-input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 8px 4px 12px;
  transition: border-color 0.15s;
}
.message-input-wrap:focus-within { border-color: var(--border-light); }

.message-input {
  flex: 1; padding: 7px 0;
  min-height: 36px; max-height: 200px;
  overflow-y: auto; outline: none;
  font-size: 14px; line-height: 1.5;
  word-break: break-word;
}

.send-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--accent); color: white;
  transition: background 0.1s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-muted); }

/* File preview bar */
.file-preview {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 8px;
}
.file-preview-item {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 12px;
  background: var(--bg-secondary);
}
.file-preview-item button { font-size: 14px; color: var(--text-muted); padding: 0 2px; }
.file-preview-item button:hover { color: var(--danger); }

/* ── Thread panel ─────────────────────────────────────────────────────────── */
.thread-panel {
  width: var(--thread-width);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-primary);
}
.thread-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 49px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.thread-header h3 { font-size: 15px; font-weight: 900; }
.thread-messages { flex: 1; overflow-y: auto; padding: 16px 0; }
.thread-input-area { padding: 8px 16px 16px; border-top: 1px solid var(--border); }
.thread-input-area .message-input-wrap { flex-direction: column; align-items: stretch; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--shadow-modal);
  display: flex; align-items: center; justify-content: center;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 32px var(--shadow);
  padding: 24px;
  position: relative;
  z-index: 1001;
}
.modal-wide { max-width: 640px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; font-weight: 900; }
.modal-close { font-size: 18px; color: var(--text-muted); padding: 4px 8px; border-radius: 4px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Dropdowns */
.dropdown {
  position: fixed;
  background: var(--bg-dropdown);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px var(--shadow);
  min-width: 220px;
  z-index: 1002;
  padding: 6px 0;
  max-height: 80vh; overflow-y: auto;
}
.dropdown-wide { min-width: 320px; }
.dropdown-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 8px;
  font-size: 14px; font-weight: 700;
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.dropdown-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 14px; font-size: 14px;
  transition: background 0.1s;
  border-radius: 0;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item-danger { color: var(--danger); }
.dropdown-user-header { padding: 12px 14px; }
.dropdown-user-header strong { display: block; font-weight: 700; }
.dropdown-user-header span { font-size: 12px; color: var(--text-secondary); }
.dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* Context menu */
.context-menu {
  position: fixed; z-index: 1003;
  background: var(--bg-dropdown);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px var(--shadow);
  min-width: 160px;
  padding: 4px 0;
}
.context-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 14px; font-size: 13px;
  transition: background 0.1s;
}
.context-item:hover { background: var(--bg-hover); }
.ctx-danger { color: var(--danger); }

/* Search modal */
.search-modal-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  margin: -24px -24px 16px;
}
.search-modal-header input { flex: 1; border: none; background: none; font-size: 16px; padding: 4px 0; }
.search-results-list { display: flex; flex-direction: column; gap: 2px; }
.search-result-item {
  display: flex; gap: 10px; padding: 10px 14px;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-meta { font-size: 12px; color: var(--text-secondary); }
.search-result-content { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
mark { background: var(--warning); color: #1d1c1d; border-radius: 2px; padding: 0 2px; }

/* Selected user chips */
.selected-users-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 6px;
  background: var(--accent); color: white;
  border-radius: 14px; font-size: 13px;
}
.user-chip button { color: rgba(255,255,255,0.7); font-size: 14px; }
.user-chip button:hover { color: white; }

/* Emoji picker */
.emoji-picker {
  position: fixed; z-index: 1004;
  background: var(--bg-dropdown);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px var(--shadow);
  width: 320px; padding: 10px;
}
.emoji-search-wrap { margin-bottom: 8px; }
.emoji-search-wrap input { width: 100%; padding: 6px 10px; font-size: 13px; }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 2px; max-height: 240px; overflow-y: auto; }
.emoji-btn { width: 34px; height: 34px; font-size: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.emoji-btn:hover { background: var(--bg-hover); }

/* ── Notification panel ───────────────────────────────────────────────────── */
.notif-list { max-height: 400px; overflow-y: auto; }
.notif-item {
  display: flex; gap: 10px; padding: 10px 14px;
  transition: background 0.1s; cursor: pointer;
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { border-left: 3px solid var(--accent-light); }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 13px; font-weight: 700; }
.notif-preview { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-time { font-size: 11px; color: var(--text-muted); }
.notif-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px var(--shadow);
  font-size: 14px; max-width: 380px;
  animation: toastIn 0.2s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent-light); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Members panel sidebar ────────────────────────────────────────────────── */
.members-panel-overlay {
  position: fixed; inset: 0; z-index: 900;
}
.members-sidebar {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 280px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 901;
  display: flex; flex-direction: column;
  padding: 16px;
  box-shadow: -4px 0 16px var(--shadow);
}
.members-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.members-sidebar h3 { font-size: 15px; font-weight: 900; }
.members-invite-toggle { padding: 2px 10px; }
.members-invite-form {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
}
.members-invite-form label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}
.members-invite-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
}
.members-invite-row input,
.members-invite-row select {
  width: 100%;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
}
.members-invite-error {
  margin-top: 8px;
  font-size: 12px;
  color: var(--danger);
}
.members-sidebar-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.member-item { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: var(--radius-sm); }
.member-item:hover { background: var(--bg-hover); }
.member-item-info { flex: 1; min-width: 0; }
.member-item-name { font-size: 13px; font-weight: 600; }
.member-item-role { font-size: 11px; color: var(--text-secondary); }

/* ── Inline edit ──────────────────────────────────────────────────────────── */
.message-edit-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--accent-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 14px; line-height: 1.5;
  resize: none;
  font-family: inherit;
}
.message-edit-actions { display: flex; gap: 6px; margin-top: 6px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-width: 100vw; --thread-width: 100vw; }
  .app-layout { position: relative; }
  .sidebar { position: absolute; z-index: 100; transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: none; }
  .chat-main { width: 100%; }
  .connection-status { margin-left: 4px; padding: 2px 8px; font-size: 11px; }
  .connection-status-text { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
  .thread-panel { position: absolute; inset: 0; z-index: 50; }
  .mobile-back-btn { display: flex !important; }
  .message-actions { top: -14px; right: 8px; }
}

/* ── Settings page ────────────────────────────────────────────────────────── */
.settings-screen {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg-primary);
  display: flex; flex-direction: column;
}
.settings-screen.hidden { display: none; }
.settings-layout { display: flex; height: 100%; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.settings-sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 24px 12px;
  gap: 4px;
  overflow-y: auto;
}
.settings-sidebar-header { padding: 0 8px 20px; }
.settings-sidebar-header h2 { font-size: 18px; font-weight: 900; margin-top: 12px; }
.settings-back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  padding: 4px 0; background: none; border: none; cursor: pointer;
}
.settings-back-btn:hover { color: var(--text-primary); }

.settings-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.settings-nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px; border-radius: 6px;
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
  background: none; border: none; cursor: pointer; text-align: left;
  white-space: nowrap;
}
.settings-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-nav-item.active { background: var(--accent-muted, rgba(83,120,209,.15)); color: var(--accent); }

/* ── Main content — fills all remaining space ───────────────────────────── */
.settings-main {
  flex: 1; min-width: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 40px 48px;
}

.settings-section-title { font-size: 22px; font-weight: 900; margin-bottom: 24px; }
.settings-section.hidden { display: none; }

.settings-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 16px;
}
.settings-card-title {
  font-size: 15px; font-weight: 700;
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 10px;
}
.settings-card-body { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.settings-card-body .field,
.settings-card-body .field-row,
.settings-card-body .settings-radio-group,
.settings-card-body .form-error,
.settings-card-body .form-success,
.settings-card-body .settings-hint,
.settings-card-body .dnd-hours-row,
.settings-card-body .settings-actions,
.settings-card-body .totp-qr-wrap,
.settings-card-body .totp-secret-row,
.settings-card-body #st-totp-setup,
.settings-card-body #st-totp-disable,
.settings-card-body #st-totp-actions,
.settings-card-body #st-invite-error,
.settings-card-body #st-invite-success,
.settings-card-body #st-wh-error,
.settings-card-body #st-dnd-error,
.settings-card-body #st-pw-error,
.settings-card-body .webhook-url-display,
.settings-card-body .admin-members-list,
.settings-card-body #st-members-list,
.settings-card-body #st-webhooks-list,
.settings-card-body #st-activity-list,
.settings-card-body .billing-plans-grid { width: 100%; }
.settings-input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-primary); color: var(--text-primary);
  font-size: 14px;
}
.settings-input:focus { outline: none; border-color: var(--accent); }
.settings-hint { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.settings-radio-group { display: flex; flex-direction: column; gap: 10px; }
.settings-radio { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.settings-radio input { accent-color: var(--accent); }
.settings-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }

/* TOTP */
.totp-badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.totp-badge-off  { background: var(--bg-hover); color: var(--text-muted); }
.totp-badge-on   { background: #dcfce7; color: #166534; }
.totp-qr-wrap { display: flex; justify-content: center; padding: 16px 0; }
.totp-qr { width: 180px; height: 180px; border-radius: 8px; border: 1px solid var(--border); }
.totp-secret-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.totp-secret-code {
  font-family: monospace; font-size: 13px; letter-spacing: 0.05em;
  background: var(--bg-hover); padding: 4px 10px; border-radius: 4px;
  user-select: all;
}
.totp-code-input {
  letter-spacing: 0.25em; font-size: 20px; font-weight: 700;
  text-align: center; max-width: 180px;
}

.btn-danger {
  background: var(--danger, #e53e3e); color: #fff; border: none;
  padding: 8px 16px; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-danger:hover { background: #c53030; }

.settings-nav-footer {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.settings-nav-danger { color: var(--danger, #e53e3e) !important; }
.settings-nav-danger:hover { background: #fff1f2 !important; }

/* ── Tablet: narrow sidebar ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .settings-sidebar { width: 200px; padding: 20px 8px; }
  .settings-main { padding: 32px 28px; }
}

/* ── Mobile: top tab-strip replaces sidebar ─────────────────────────────── */
@media (max-width: 640px) {
  .settings-layout { flex-direction: column; overflow: visible; height: 100%; }

  .settings-sidebar {
    width: 100%; height: auto; flex-shrink: 0;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 12px 12px 0;
    overflow-x: auto; overflow-y: hidden;
    flex-direction: column;
  }

  .settings-sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 4px 10px; flex-direction: row;
  }
  .settings-sidebar-header h2 { margin-top: 0; font-size: 16px; }

  /* Nav items become a horizontal scrollable pill row */
  .settings-nav {
    flex-direction: row; gap: 4px;
    overflow-x: auto; padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .settings-nav::-webkit-scrollbar { display: none; }

  .settings-nav-item {
    flex-shrink: 0; width: auto; padding: 7px 14px;
    border-radius: 20px; font-size: 13px; white-space: nowrap;
    border: 1px solid var(--border);
  }
  .settings-nav-item svg { display: none; }
  .settings-nav-item.active {
    border-color: var(--accent);
    background: var(--accent-muted, rgba(83,120,209,.15));
  }

  .settings-nav-divider { display: none; }

  .settings-nav-footer {
    flex-direction: row; margin-top: 0; padding-top: 0;
    border-top: none; gap: 4px;
  }
  .settings-nav-footer .settings-nav-item { border: 1px solid var(--border); }

  .settings-main { padding: 20px 16px; overflow-y: auto; flex: 1; }
}

/* ── Poll messages ──────────────────────────────────────────────────────────── */
.poll-wrap { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; max-width: 420px; margin-top: 4px; }
.poll-question { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.poll-option { position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; margin-bottom: 6px; cursor: pointer; border: 1px solid var(--border); background: var(--bg-secondary); overflow: hidden; transition: border-color .15s; }
.poll-option:hover { border-color: var(--accent); }
.poll-option-voted { border-color: var(--accent); background: var(--accent-bg, rgba(79,70,229,.08)); }
.poll-bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-bg, rgba(79,70,229,.12)); pointer-events: none; transition: width .3s ease; }
.poll-option-label { flex: 1; font-size: 13px; position: relative; z-index: 1; }
.poll-option-count { font-size: 11px; color: var(--text-muted); position: relative; z-index: 1; white-space: nowrap; }
.poll-total { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Link previews ──────────────────────────────────────────────────────────── */
.link-preview { display: flex; gap: 10px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: 10px 12px; margin-top: 8px; max-width: 460px; background: var(--bg-secondary); }
.link-preview-img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.link-preview-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.link-preview-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-preview-desc { font-size: 12px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-preview-url { font-size: 11px; color: var(--accent); text-decoration: none; }
.link-preview-url:hover { text-decoration: underline; }

/* ── DM read receipts ───────────────────────────────────────────────────────── */
.read-receipt { font-size: 11px; color: var(--accent); margin-top: 2px; text-align: right; }

/* ── Slash command popup ────────────────────────────────────────────────────── */
.slash-popup { position: absolute; bottom: calc(100% + 4px); left: 0; right: 0; background: var(--bg-modal); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.15)); z-index: 300; overflow: hidden; max-height: 240px; overflow-y: auto; }
.slash-item { display: flex; align-items: baseline; gap: 10px; padding: 9px 14px; cursor: pointer; transition: background .1s; }
.slash-item:hover { background: var(--bg-hover); }
.slash-name { font-weight: 600; font-size: 13px; color: var(--accent); white-space: nowrap; }
.slash-desc { font-size: 12px; color: var(--text-muted); }

/* ── DND settings ───────────────────────────────────────────────────────────── */
.dnd-hours-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.settings-checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.settings-checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; }

/* ── search result mark highlight ──────────────────────────────────────────── */
mark { background: rgba(255,210,0,.4); color: inherit; border-radius: 2px; padding: 0 1px; }

/* ── Sidebar footer (Documentation link) ───────────────────────────────────── */
.sidebar-footer {
  padding: 4px 8px 6px;
  border-top: 1px solid var(--border);
}
.sidebar-footer-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 10px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--sidebar-text);
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .12s, color .12s;
}
.sidebar-footer-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.sidebar-footer-btn svg { flex-shrink: 0; opacity: .8; }

/* ── Documentation modal ────────────────────────────────────────────────────── */
.docs-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.docs-overlay.hidden { display: none; }

.docs-container {
  display: flex; width: 100%; max-width: 920px; height: 82vh; max-height: 700px;
  background: var(--bg-modal); border-radius: 12px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,.35);
  border: 1px solid var(--border);
}

/* Left nav panel */
.docs-sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--bg-tertiary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.docs-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 13px; border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}
.docs-logo { font-size: 14px; font-weight: 700; color: var(--text-primary); }

.docs-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.docs-nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 11px; border-radius: 6px;
  font-size: 13px; color: var(--text-secondary);
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .12s, color .12s; margin-bottom: 2px;
  line-height: 1.3;
}
.docs-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.docs-nav-item.active {
  background: var(--accent-bg); color: var(--accent); font-weight: 600;
  border-left: 3px solid var(--accent); padding-left: 8px;
}

/* Right content area */
.docs-body {
  flex: 1; overflow-y: auto; padding: 32px 36px;
  background: var(--bg-modal);
  font-size: 14px; line-height: 1.7; color: var(--text-primary);
}
.docs-body h3 {
  font-size: 20px; font-weight: 700; margin: 0 0 16px;
  color: var(--text-heading); padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.docs-body h4 {
  font-size: 14px; font-weight: 600; margin: 22px 0 8px;
  color: var(--text-primary); text-transform: uppercase;
  letter-spacing: 0.04em; font-size: 12px;
}
.docs-body p { margin: 0 0 12px; color: var(--text-secondary); }
.docs-body ul, .docs-body ol {
  margin: 0 0 14px; padding-left: 22px; color: var(--text-secondary);
}
.docs-body li { margin-bottom: 5px; }
.docs-body pre {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 7px; padding: 12px 16px; font-family: monospace; font-size: 12px;
  overflow-x: auto; margin: 10px 0 14px; color: var(--text-primary);
  line-height: 1.6;
}
.docs-body code {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px;
  font-family: monospace; font-size: 12px; color: var(--accent);
}
.docs-body pre code { background: none; border: none; padding: 0; color: var(--text-primary); }
.docs-body kbd {
  display: inline-block; padding: 2px 7px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 11px; font-family: monospace;
  background: var(--bg-tertiary); color: var(--text-primary);
  box-shadow: 0 1px 0 var(--border-light); white-space: nowrap;
}
.docs-body table {
  width: 100%; border-collapse: collapse; margin: 10px 0 18px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden;
}
.docs-body th {
  text-align: left; padding: 9px 12px;
  background: var(--bg-tertiary); border-bottom: 2px solid var(--border);
  font-weight: 600; color: var(--text-primary); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.docs-body td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.docs-body tr:last-child td { border-bottom: none; }
.docs-body tr:nth-child(even) td { background: var(--bg-tertiary); }
.docs-body em { color: var(--text-muted); font-style: italic; }
.docs-body strong { color: var(--text-primary); font-weight: 600; }
.docs-body ol li::marker { color: var(--accent); font-weight: 600; }

@media (max-width: 640px) {
  .docs-container { flex-direction: column; height: 92vh; max-height: none; }
  .docs-sidebar { width: 100%; height: auto; flex-shrink: 0; }
  .docs-nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; }
  .docs-nav-item { width: auto; padding: 6px 10px; }
  .docs-nav-item.active { border-left: none; border-bottom: 2px solid var(--accent); }
  .docs-body { padding: 20px 18px; }
}

/* ── Settings admin sections ────────────────────────────────────────────────── */
.settings-nav-divider {
  padding: 14px 12px 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
}

.admin-loading, .admin-empty {
  padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px;
}

.admin-members-list { display: flex; flex-direction: column; }

.admin-member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.admin-member-row:last-child { border-bottom: none; }
.admin-member-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.admin-member-name { font-size: 13px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-member-email { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.admin-role-badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
  white-space: nowrap; text-transform: capitalize;
}
.role-owner   { background: #fef3c7; color: #92400e; }
.role-admin   { background: #dbeafe; color: #1e40af; }
.role-member  { background: #f0fdf4; color: #166534; }
.role-guest   { background: var(--bg-tertiary); color: var(--text-muted); }

.admin-role-select {
  font-size: 12px; padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-primary); cursor: pointer;
}
.admin-remove-btn { flex-shrink: 0; color: var(--danger) !important; border-color: var(--danger) !important; }
.admin-remove-btn:hover { background: var(--danger-light) !important; }

.webhook-id-badge {
  font-size: 11px; background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 7px; color: var(--text-muted); white-space: nowrap;
  cursor: help; font-family: monospace;
}

.webhook-url-display {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 6px; padding: 9px 13px; margin: 6px 0;
}
.webhook-url-display code { background: none; border: none; padding: 0; font-size: 13px; color: var(--text-primary); }

.admin-log-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 12px;
}
.admin-log-row:last-child { border-bottom: none; }
.admin-log-time   { color: var(--text-muted); white-space: nowrap; min-width: 80px; }
.admin-log-action { font-weight: 600; color: var(--text-primary); text-transform: capitalize; flex: 1; }
.admin-log-who    { color: var(--accent); white-space: nowrap; }
.admin-log-detail { color: var(--text-muted); font-style: italic; white-space: nowrap; }

/* ── Search filters ───────────────────────────────────────────────────────── */
.search-filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px 0; border-top: 1px solid var(--border);
}
.search-filter-input {
  font-size: 12px; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-primary); flex: 1; min-width: 110px; max-width: 160px;
}
.search-filter-input:focus { outline: none; border-color: var(--accent); }
.btn-xs { font-size: 11px; padding: 3px 10px; border-radius: 5px; }

/* ── Unread jump bar ──────────────────────────────────────────────────────── */
.unread-jump-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 500;
}
.unread-jump-bar .icon-btn { color: #fff; opacity: 0.8; }
.unread-jump-bar .icon-btn:hover { opacity: 1; }
.unread-jump-bar .btn-primary { background: rgba(255,255,255,0.25); border: none; color: #fff; font-size: 12px; padding: 3px 10px; }
.unread-jump-bar .btn-primary:hover { background: rgba(255,255,255,0.4); }

/* ── Readonly notice ──────────────────────────────────────────────────────── */
.readonly-notice {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--bg-tertiary);
  border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px;
}

/* ── File browser panel ───────────────────────────────────────────────────── */
.files-list {
  display: flex; flex-direction: column; overflow-y: auto; flex: 1;
}
.file-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.file-row:last-child { border-bottom: none; }
.file-row-icon { font-size: 20px; flex-shrink: 0; }
.file-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-row-name { font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row-meta { font-size: 11px; color: var(--text-muted); }
.file-row-dl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--radius-sm); flex-shrink: 0;
  color: var(--text-secondary); text-decoration: none; transition: background 0.1s, color 0.1s;
}
.file-row-dl:hover { background: var(--bg-hover); color: var(--accent); text-decoration: none; }

/* ── Highlight flash for unread jump ─────────────────────────────────────── */
@keyframes highlight-flash {
  0%   { background: color-mix(in srgb, var(--accent) 20%, transparent); }
  100% { background: transparent; }
}
.highlight-flash { animation: highlight-flash 1.5s ease-out forwards; }

/* ── Webhook event table ──────────────────────────────────────────────────── */
.wh-events-table {
  width: 100%; border-collapse: collapse; margin-top: 6px;
  font-size: 13px; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden;
}
.wh-events-table thead tr {
  background: var(--bg-tertiary);
}
.wh-events-table th {
  padding: 7px 12px; text-align: left; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.wh-events-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle; color: var(--text-primary);
}
.wh-events-table tbody tr:last-child td { border-bottom: none; }
.wh-events-table tbody tr:hover { background: var(--bg-secondary); }
.wh-events-table td:first-child { width: 36px; text-align: center; }
.wh-events-table td:nth-child(2) { width: 180px; white-space: nowrap; }
.wh-events-table td input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }
.wh-events-table code { font-size: 12px; font-weight: 600; color: var(--accent); background: none; border: none; padding: 0; }
.wh-events-table td:last-child { color: var(--text-muted); font-size: 12px; }

/* ── Webhook event tags on existing webhooks ──────────────────────────────── */
.wh-event-tags { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; margin-top: 4px; }
.wh-event-tag {
  font-size: 10px; font-family: monospace; font-weight: 600;
  padding: 2px 7px; border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ── Incoming webhook URL row ─────────────────────────────────────────────── */
.wh-incoming-url-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px;
}
.wh-incoming-url {
  flex: 1; font-size: 12px; color: var(--text-primary);
  font-family: monospace; word-break: break-all;
  background: none; border: none; padding: 0;
}

/* ── Billing ──────────────────────────────────────────────────────────────── */

/* Current plan status */
.billing-current-plan {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.billing-plan-badge-wrap { display: flex; align-items: center; gap: 8px; }
.billing-plan-badge {
  font-size: 13px; font-weight: 700; padding: 4px 14px; border-radius: 20px;
  text-transform: capitalize;
}
.billing-plan-badge-free    { background: var(--bg-tertiary); color: var(--text-muted); }
.billing-plan-badge-starter { background: #dbeafe; color: #1e40af; }
.billing-plan-badge-growth  { background: #d1fae5; color: #065f46; }
.billing-plan-badge-scale   { background: #fef3c7; color: #92400e; }
.billing-plan-badge-custom  { background: #f3e8ff; color: #6b21a8; }

.billing-sub-status {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
  text-transform: capitalize;
}
.billing-sub-status-active    { background: #d1fae5; color: #065f46; }
.billing-sub-status-past_due  { background: #fee2e2; color: #991b1b; }
.billing-sub-status-canceled  { background: var(--bg-tertiary); color: var(--text-muted); }
.billing-sub-status-incomplete{ background: #fef3c7; color: #92400e; }
.billing-sub-status-trialing  { background: #dbeafe; color: #1e40af; }

.billing-plan-meta { font-size: 13px; color: var(--text-muted); }

/* Access expiry */
.billing-expiry-text {
  font-size: 14px; color: var(--text-primary); font-weight: 500;
}
.billing-expiry-warn {
  margin-top: 8px; font-size: 13px; color: #92400e;
  padding: 8px 12px; background: #fef3c7; border-radius: var(--radius-sm);
  border-left: 3px solid #f59e0b;
}

/* Plan cards grid */
.billing-plans-grid {
  display: grid;
  /* 4 equal columns — each shrinks to 0 rather than enforcing a min-width */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
}

.billing-plan-card {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0; /* allow cards to shrink inside grid */
}
.billing-plan-card:hover { border-color: var(--accent-light); }
.billing-plan-card .btn { width: 100%; justify-content: center; }

.billing-plan-card-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

.billing-plan-card-featured {
  border-color: var(--accent);
}

.billing-plan-card-custom {
  border-style: dashed;
}

.billing-plan-card-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--accent); color: var(--text-on-accent);
  padding: 2px 10px; border-radius: 20px; white-space: nowrap;
}

.billing-plan-card-header {
  display: flex; justify-content: space-between; align-items: baseline;
}
.billing-plan-card-name {
  font-size: 15px; font-weight: 700; color: var(--text-heading);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.billing-plan-card-price {
  font-size: 18px; font-weight: 900; color: var(--accent);
  white-space: nowrap;
}
.billing-plan-card-price span {
  font-size: 11px; font-weight: 400; color: var(--text-muted);
}

.billing-plan-features {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px;
  flex: 1;
}
.billing-plan-features li {
  font-size: 13px; color: var(--text-secondary);
  padding-left: 18px; position: relative;
}
.billing-plan-features li::before {
  content: '✓'; position: absolute; left: 0;
  color: var(--accent); font-weight: 700; font-size: 12px;
}

/* Payment history */
.billing-history-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.billing-history-row:last-child { border-bottom: none; }
.billing-history-amount { font-weight: 700; color: var(--text-primary); min-width: 60px; }
.billing-history-date   { flex: 1; color: var(--text-muted); font-size: 12px; }

.billing-history-status {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
  text-transform: capitalize; white-space: nowrap;
}
.billing-history-status-paid         { background: #d1fae5; color: #065f46; }
.billing-history-status-open         { background: #fef3c7; color: #92400e; }
.billing-history-status-void         { background: var(--bg-tertiary); color: var(--text-muted); }
.billing-history-status-uncollectible{ background: #fee2e2; color: #991b1b; }

/* Payment modal overlay */
.billing-modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}

.billing-modal {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}

.billing-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.billing-modal-header h3 { font-size: 16px; font-weight: 700; }

.billing-modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.billing-modal-summary {
  font-size: 14px; color: var(--text-secondary);
  padding: 10px 14px; background: var(--bg-secondary);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

.billing-modal-footer {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px;
}

/* Stripe Payment Element container */
#billing-payment-element {
  min-height: 80px;
}

/*
 * Billing grid breakpoints — keyed to content area width, not viewport.
 * Desktop sidebar ≈ 240px + ~96px padding = ~336px overhead.
 * Tablet sidebar  ≈ 200px + ~56px padding = ~256px overhead.
 * Mobile (≤640px): full width with ~32px padding, no sidebar.
 *
 * At ≤1050px viewport the content area is too narrow for 4 comfortable columns → 2×2.
 * At ≤640px mobile layout kicks in → full width, keep 2 columns.
 * At ≤460px cards are too narrow even at 2 columns → single column.
 */
@media (max-width: 1050px) {
  .billing-plans-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 460px) {
  .billing-plans-grid { grid-template-columns: 1fr; }
}
