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

:root {
  --bg-primary:    #1e1f22;
  --bg-secondary:  #2b2d31;
  --bg-tertiary:   #313338;
  --bg-hover:      #35373c;
  --bg-active:     #404249;
  --accent:        #5865f2;
  --accent-hover:  #4752c4;
  --text-primary:  #f2f3f5;
  --text-secondary:#b5bac1;
  --text-muted:    #80848e;
  --border:        #3f4147;
  --success:       #23a55a;
  --danger:        #f23f43;
  --warning:       #f0b232;
  --sidebar-w:     240px;
  --header-h:      48px;
  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 2px 10px rgba(0,0,0,.4);
  --ctrl-h:        36px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; background: var(--bg-primary); color: var(--text-primary); overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }

/* ── Consistent control height ─────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
select {
  height: var(--ctrl-h);
  padding: 0 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus { border-color: var(--accent); }
input[type="file"] { background: none; border: none; color: var(--text-secondary); padding: 0; height: auto; width: auto; }

/* ── Remix Icon sizing by context ──────────────── */
i[class^="ri-"], i[class*=" ri-"] { line-height: 1; vertical-align: middle; }
.icon-btn i    { font-size: 18px; }
.act-btn i     { font-size: 13px; }
.tool-btn i    { font-size: 15px; }
.send-btn i    { font-size: 16px; }
.channel-item i{ font-size: 16px; color: inherit; }
.badge i       { font-size: 11px; }
.back-btn i    { font-size: 18px; }
.ch-icon i     { font-size: 18px; }
.copy-btn i    { font-size: 13px; }
.file-link i   { font-size: 18px; flex-shrink: 0; }
.alert i       { font-size: 16px; flex-shrink: 0; }
.btn i         { font-size: 14px; }
.page-title-row > i { font-size: 22px; }
.sidebar-section-header .icon-btn i { font-size: 14px; }

/* ── Auth Pages ────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-primary); overflow: auto; }
.auth-card { background: var(--bg-secondary); border-radius: 12px; padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo svg { margin-bottom: 12px; }
.auth-logo h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.auth-logo p { color: var(--text-secondary); font-size: 14px; }

/* ── Forms ─────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select { width: 100%; }

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: var(--ctrl-h); padding: 0 16px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; color: var(--text-primary);
  transition: background .15s, transform .1s; white-space: nowrap; flex-shrink: 0;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-full { width: 100%; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-ghost { background: var(--bg-hover); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-active); color: var(--text-primary); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #d33; }
.btn-danger { background: rgba(242,63,67,.12); color: var(--danger); border: 1px solid rgba(242,63,67,.35); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-danger:disabled { opacity: .4; cursor: not-allowed; }

/* icon button */
.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 .15s, color .15s; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* small action buttons in tables */
.act-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; white-space: nowrap;
  transition: background .12s, color .12s;
}
.act-btn-ghost { background: var(--bg-active); color: var(--text-secondary); }
.act-btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.act-btn-warn { background: rgba(240,178,50,.12); color: var(--warning); border: 1px solid rgba(240,178,50,.25); }
.act-btn-warn:hover { background: rgba(240,178,50,.22); }
.act-btn-danger { background: rgba(242,63,67,.12); color: var(--danger); border: 1px solid rgba(242,63,67,.25); }
.act-btn-danger:hover { background: rgba(242,63,67,.22); }
.act-btn-success { background: rgba(35,165,90,.12); color: var(--success); border: 1px solid rgba(35,165,90,.25); }
.act-btn-success:hover { background: rgba(35,165,90,.22); }

/* ── Alerts ────────────────────────────────────── */
.alert { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; }
.alert-error { background: rgba(242,63,67,.12); border: 1px solid rgba(242,63,67,.28); color: #f23f43; }
.alert-success { background: rgba(35,165,90,.12); border: 1px solid rgba(35,165,90,.28); color: var(--success); }

/* ── Toggle Switch ─────────────────────────────── */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--bg-active); border-radius: 22px;
  cursor: pointer; transition: background .2s;
}
.switch-track::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  left: 3px; top: 3px;
  background: var(--text-muted); transition: transform .2s, background .2s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(18px); background: #fff; }
.switch input:disabled + .switch-track { opacity: .45; cursor: not-allowed; }

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

/* ── Sidebar ───────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-secondary);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  transition: transform .2s;
}
.sidebar-header { padding: 0 14px; height: var(--header-h); display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.workspace-name { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.sidebar-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar-section { margin-bottom: 4px; }
.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px 3px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted);
}
.sidebar-section-header .icon-btn { width: 20px; height: 20px; border-radius: 3px; }
.channel-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 14px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; margin: 1px 6px;
  transition: background .1s, color .1s; white-space: nowrap; overflow: hidden;
}
.channel-item:hover { background: var(--bg-hover); color: var(--text-secondary); }
.channel-item.active { background: var(--bg-active); color: var(--text-primary); }
.ch-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ch-unread { font-weight: 600; color: var(--text-primary); }
.unread-badge {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  line-height: 1;
}
.sidebar-footer {
  padding: 8px 12px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; min-height: 52px;
}
.user-info { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.username { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.user-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ── Main Content ──────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-tertiary); }

/* ── Chat Header ───────────────────────────────── */
.chat-header {
  height: var(--header-h); padding: 0 12px 0 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border); background: var(--bg-tertiary); flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.ch-icon { color: var(--text-muted); display: flex; align-items: center; }
.chat-header-info h2 { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-count { font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.chat-header-actions { display: flex; align-items: center; gap: 2px; }
.sidebar-toggle { display: none; }

/* ── Chat Body ─────────────────────────────────── */
.chat-body { flex: 1; display: flex; overflow: hidden; }
.messages-container { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; }
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Message ───────────────────────────────────── */
.message { display: flex; gap: 12px; padding: 4px 16px; transition: background .1s; }
.message:hover { background: rgba(0,0,0,.08); }
.message-avatar { flex-shrink: 0; padding-top: 2px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-sm { width: 28px; height: 28px; }
.avatar-xs { width: 22px; height: 22px; }
.avatar-letter {
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px;
}
.avatar-sm.avatar-letter { font-size: 11px; }
.avatar-xs.avatar-letter { font-size: 9px; }
.avatar-bot { background: var(--warning); }
.message-body { flex: 1; min-width: 0; position: relative; }
.message-meta { display: flex; align-items: baseline; gap: 6px; margin-bottom: 1px; }
.message-author { font-weight: 600; font-size: 13px; }
.bot-name { color: var(--warning); }
.message-time { font-size: 10px; color: var(--text-muted); }
.message-content .msg-text { line-height: 1.55; color: var(--text-primary); word-break: break-word; }
.code-block { position: relative; margin-top: 6px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid #3e4451; }
/* language badge */
.code-lang { display: block; background: #21252b; color: #abb2bf; font-size: 11px; font-family: 'JetBrains Mono','Fira Code',monospace; padding: 4px 60px 4px 12px; border-bottom: 1px solid #3e4451; text-transform: lowercase; letter-spacing: .4px; }
/* pre scroll container */
.code-block pre { background: #282c34; margin: 0; padding: 10px 44px 12px 0; overflow: auto; max-height: 400px; display: flex; gap: 0; }
/* line numbers */
.code-line-nums { user-select: none; text-align: right; color: #636d83; font-size: 12px; font-family: 'JetBrains Mono','Fira Code',monospace; line-height: 1.6; padding: 0 12px; border-right: 1px solid #3e4451; margin-right: 14px; flex-shrink: 0; white-space: pre; position: sticky; left: 0; background: #282c34; z-index: 1; }
.code-block pre code { background: none !important; padding: 0 !important; font-family: 'JetBrains Mono','Fira Code',monospace; font-size: 13px; line-height: 1.6; flex: 1; min-width: 0; white-space: pre; }
/* copy + expand buttons — always in top-right corner of the block */
.copy-code-btn, .expand-code-btn { position: absolute; right: 6px; background: #21252b; border: 1px solid #3e4451; border-radius: var(--radius-sm); color: #636d83; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; cursor: pointer; opacity: 0; transition: opacity .15s, color .15s; z-index: 10; }
/* with lang badge: badge is ~26px tall, so position below it */
.code-block.has-lang .copy-code-btn  { top: 4px; right: 36px; }
.code-block.has-lang .expand-code-btn { top: 4px; right: 6px; }
/* without lang badge: float inside the pre area */
.copy-code-btn  { top: 6px; right: 36px; }
.expand-code-btn { top: 6px; right: 6px; }
.copy-code-btn i, .expand-code-btn i { font-size: 14px; }
.code-block:hover .copy-code-btn,
.code-block:hover .expand-code-btn { opacity: 1; }
.copy-code-btn:hover, .expand-code-btn:hover { color: #abb2bf; }
.copy-code-btn.copied { color: #98c379; border-color: #98c379; opacity: 1; }
/* expanded state removes max-height */
.code-block.expanded pre { max-height: none; }
.message-content code { font-family: 'JetBrains Mono','Fira Code',monospace; font-size: 13px; color: #e3b341; }
.message-content pre code { color: var(--text-primary); }
/* ── Toast ─────────────────────────────────────── */
#crew-toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(12px); background: #1e1f22; color: #fff; font-size: 13px; padding: 8px 18px; border-radius: 20px; border: 1px solid #3e4451; box-shadow: 0 4px 16px rgba(0,0,0,.4); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 9999; white-space: nowrap; }
#crew-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.rich-content { line-height: 1.6; }
/* ── Message actions (edit / delete) ──────────── */
.msg-content-row { display: flex; align-items: flex-start; gap: 4px; }
.msg-actions { visibility: hidden; display: flex; flex-direction: row; gap: 2px; padding: 2px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 2px 8px rgba(0,0,0,.3); flex-shrink: 0; align-self: center; position: relative; }
.message:hover .msg-actions { visibility: visible; }
.message.msg-own .msg-content-row { flex-direction: row-reverse; }
.msg-action-btn { background: none; border: none; color: var(--text-muted); width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); cursor: pointer; transition: background .1s, color .1s; font-size: 15px; }
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.msg-delete-btn:hover { color: #ed4245; }
.message:not(.msg-own) .msg-edit-btn,
.message:not(.msg-own) .msg-delete-btn { display: none !important; }
.message.msg-own .react-add-btn { display: none !important; }
.message-edited { font-size: 11px; color: var(--text-muted); font-style: italic; }
.msg-deleted .msg-deleted, p.msg-deleted { color: var(--text-muted); font-style: italic; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.msg-deleted .message-content p.msg-deleted { color: var(--text-muted); }
/* Inline edit form */
.msg-edit-form { margin-top: 6px; }
.msg-edit-form.hidden { display: none; }
.msg-edit-input { width: 100%; min-height: 60px; max-height: 200px; background: var(--bg-primary); border: 1px solid var(--accent); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 14px; line-height: 1.5; padding: 8px 10px; resize: vertical; outline: none; font-family: inherit; box-sizing: border-box; }
.msg-edit-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.msg-edit-hint { font-size: 11px; color: var(--text-muted); }
.btn-sm { padding: 4px 12px; font-size: 13px; }
/* ── Profile page ──────────────────────────────── */
.profile-page { max-width: 560px; margin: 0 auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }
.profile-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.profile-avatar-wrap { margin-bottom: 14px; }
.profile-avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; }
.profile-avatar-letter { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 28px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.profile-identity { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.profile-identity h2 { font-size: 18px; font-weight: 700; margin: 0; }
.profile-card-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin: 0 0 14px; display: flex; align-items: center; gap: 6px; }
.profile-form { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; gap: 8px; align-items: center; }
.form-row .form-input { flex: 1; }
.username-link { color: var(--text-primary); text-decoration: none; font-weight: 600; font-size: 13px; }
.username-link:hover { color: var(--accent); text-decoration: underline; }
.alert { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 4px; }
.alert-success { background: rgba(59,165,92,.15); color: #3ba55c; border: 1px solid rgba(59,165,92,.3); }
.alert-error { background: rgba(237,66,69,.12); color: #ed4245; border: 1px solid rgba(237,66,69,.25); }
.media-wrap { margin-top: 4px; }
.media-img { max-width: 400px; max-height: 300px; border-radius: var(--radius-sm); object-fit: contain; cursor: pointer; }
.hidden-fallback { display: none; }
.file-link-wrap { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; }
.file-link { display: inline-flex; align-items: center; gap: 8px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; color: var(--accent); transition: background .15s; }
.file-link:hover { background: var(--bg-hover); }
.file-link-name { font-weight: 500; }
.file-link-size { font-size: 11px; color: var(--text-muted); margin-left: 2px; }
.file-preview-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--radius-sm); background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; transition: background .15s, color .15s; flex-shrink: 0; }
.file-preview-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
/* File preview modal */
.file-preview-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 2000; flex-direction: column; }
.file-preview-modal.open { display: flex; }
.file-preview-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.file-preview-title { font-weight: 600; font-size: 14px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.file-preview-actions { display: flex; align-items: center; gap: 8px; }
.file-preview-body { flex: 1; overflow: hidden; position: relative; }
.file-preview-body iframe { width: 100%; height: 100%; border: none; background: #fff; }
.file-preview-unsupported { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 16px; color: var(--text-muted); }
.file-preview-unsupported i { font-size: 48px; }

/* ── Right Panel (Members / Files / Search) ─────── */
.right-panel { width: 0; overflow: hidden; background: var(--bg-secondary); border-left: 1px solid var(--border); transition: width .2s; display: flex; flex-direction: column; flex-shrink: 0; }
.right-panel.open { width: 300px; overflow: visible; }
.panel-tab { display: flex; flex-direction: column; width: 300px; height: 100%; overflow: hidden; }
.panel-tab.hidden { display: none; }
.panel-header { padding: 14px 14px 8px; flex-shrink: 0; }
.panel-header h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); margin-bottom: 8px; }
.panel-body { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.panel-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 24px 0; }
.panel-tab-btn.active { color: var(--accent); background: var(--bg-active); }
.member-item { display: flex; align-items: center; gap: 8px; padding: 5px 4px; font-size: 13px; color: var(--text-secondary); }
.member-item .member-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.member-badges { display: flex; gap: 4px; flex-wrap: wrap; }
/* Files panel */
.files-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 10px; }
.files-grid-item { aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; cursor: pointer; }
.files-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.files-doc-list { display: flex; flex-direction: column; gap: 2px; }
.files-doc-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; text-decoration: none; background: var(--bg-primary); transition: background .1s; }
.files-doc-item:hover { background: var(--bg-hover); }
.files-doc-item i { font-size: 18px; color: var(--accent); flex-shrink: 0; }
.files-doc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.files-doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; color: var(--text-primary); }
.files-doc-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 6px; }
.files-doc-size { font-weight: 600; }
.files-load-more { display: block; width: 100%; margin-top: 8px; padding: 7px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--accent); font-size: 13px; cursor: pointer; text-align: center; transition: background .1s; }
.files-load-more:hover { background: var(--bg-hover); }
/* Search panel */
.search-input-wrap { display: flex; align-items: center; gap: 6px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px 10px; }
.search-input-wrap i { color: var(--text-muted); font-size: 14px; flex-shrink: 0; }
.search-input-wrap input { background: none; border: none; outline: none; color: var(--text-primary); font-size: 13px; width: 100%; }
.search-result-item { display: block; padding: 8px; border-radius: var(--radius-sm); text-decoration: none; color: inherit; cursor: pointer; transition: background .1s; margin-bottom: 2px; }
.search-result-item:hover { background: var(--bg-hover); }
.search-result-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-size: 12px; color: var(--text-muted); }
.search-result-meta span:first-of-type { color: var(--text-secondary); font-weight: 600; }
.search-result-time { margin-left: auto; }
.search-result-text { font-size: 13px; color: var(--text-secondary); margin: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* Highlight matched message */
@keyframes msgHighlight { 0%,100% { background: transparent; } 30%,70% { background: rgba(88,101,242,.18); } }
.msg-highlight { animation: msgHighlight 1.5s ease; border-radius: var(--radius-sm); }
/* DM avatar-xs in sidebar */
.avatar-xs { width: 22px; height: 22px; font-size: 10px; flex-shrink: 0; }

/* ── Message Input ─────────────────────────────── */
.message-input-area { padding: 0 16px 16px; flex-shrink: 0; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; background: var(--bg-secondary); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tool-btn { padding: 4px 7px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 13px; font-weight: 600; transition: background .1s, color .1s; display: flex; align-items: center; }
.tool-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tool-btn.active { background: var(--bg-active); color: var(--text-primary); }
.toolbar-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }
.input-row { display: flex; align-items: flex-end; background: var(--bg-secondary); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 4px 8px 6px; gap: 6px; min-width: 0; }
.input-wrap { flex: 1; min-width: 0; overflow: visible; position: relative; }
.msg-input { min-height: 38px; max-height: 200px; overflow-y: auto; overflow-x: auto; padding: 8px 4px; outline: none; line-height: 1.5; color: var(--text-primary); word-break: break-word; white-space: pre-wrap; }
.msg-input[style*="monospace"] { white-space: pre; word-break: normal; overflow-x: auto; }
.msg-input:empty::before { content: attr(data-placeholder); color: var(--text-muted); pointer-events: none; }
.input-actions { display: flex; align-items: center; gap: 2px; padding-bottom: 1px; }
.hidden-file { display: none; }
.send-btn { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; transition: background .15s, transform .1s; flex-shrink: 0; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(.95); }
.file-preview { margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; padding-top: 6px; }
.file-preview.hidden { display: none; }

/* base thumb */
.file-thumb { position: relative; flex-shrink: 0; }

/* image thumb */
.file-thumb-img img {
  display: block;
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* document / file thumb */
.file-thumb-doc {
  display: flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 10px 0 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-width: 180px;
}
.file-thumb-doc i {
  font-size: 16px; color: var(--accent); flex-shrink: 0;
}
.file-thumb-doc span {
  font-size: 12px; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 120px;
}

/* remove button — sits outside the thumb box in the top-right corner */
.file-thumb-remove {
  position: absolute;
  top: -7px; right: -7px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid var(--bg-tertiary);
  padding: 0;
  z-index: 1;
}

/* ── Empty State ───────────────────────────────── */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--text-muted); text-align: center; padding: 40px; }
.empty-state h2 { color: var(--text-primary); font-size: 22px; }
.empty-state p { max-width: 360px; line-height: 1.6; }

/* ── Page Content (admin / settings pages) ─────── */
.main-content > .page-content { flex: 1; overflow-y: auto; min-height: 0; }
.page-content { padding: 28px 32px; max-width: 860px; }
.page-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.page-title { font-size: 20px; font-weight: 700; }
.back-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  color: var(--text-secondary); transition: background .15s, color .15s; flex-shrink: 0;
}
.back-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Section ───────────────────────────────────── */
.section { margin-bottom: 36px; }
.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ── Inline form row ───────────────────────────── */
.form-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form-row input, .form-row select { flex: 1; min-width: 100px; max-width: 280px; width: auto; }
.form-row .lbl { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }

/* ── Data table ────────────────────────────────── */
.data-table {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  width: 100%;
}
.data-table-header {
  display: grid;
  padding: 0 16px;
  min-height: 36px;
  align-items: center;
  gap: 12px;
  background: var(--bg-hover);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted);
}
.data-table-row {
  display: grid;
  padding: 0 16px;
  min-height: 48px;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.data-table-row:hover { background: rgba(0,0,0,.06); }

/* Users table: avatar+name | role | status | actions */
.users-table .data-table-header,
.users-table .data-table-row { grid-template-columns: minmax(140px,1fr) 110px 70px minmax(180px,auto); }

/* Channels table: name | type | webhook | add-member */
.channels-table .data-table-header,
.channels-table .data-table-row { grid-template-columns: minmax(120px,1fr) 80px minmax(160px,1fr) 220px; }

/* Members table (edit-channel): name | role | actions */
.members-table .data-table-header,
.members-table .data-table-row { grid-template-columns: 1fr 120px auto; }

.cell-user { display: flex; align-items: center; gap: 9px; min-width: 0; overflow: hidden; }
.cell-user > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cell-webhook { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }

/* ── Inline expand forms ───────────────────────── */
.expand-form { display: none; border-top: 1px solid var(--border); background: var(--bg-tertiary); }
.expand-form.open { display: block; }
.expand-form-inner {
  padding: 14px 16px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
}
.expand-form-inner .field { display: flex; flex-direction: column; gap: 5px; }
.expand-form-inner .field label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted);
}
.expand-form-inner input[type="text"],
.expand-form-inner input[type="password"] { width: 220px; }

/* ── User Picker ───────────────────────────────── */
.user-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; }
.user-chip { display: flex; align-items: center; gap: 6px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px 4px 6px; font-size: 13px; cursor: pointer; transition: background .1s, border-color .1s; }
.user-chip:hover { background: var(--bg-hover); border-color: var(--accent); }
.user-chip input { display: none; }
.user-chip:has(input:checked) { background: rgba(88,101,242,.18); border-color: var(--accent); }

/* ── Tabs ──────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 16px; font-size: 14px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Badges ────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--bg-active); color: var(--text-muted); white-space: nowrap; }
.badge-admin { background: rgba(88,101,242,.2); color: var(--accent); }
.badge-ch-admin { background: rgba(240,178,50,.15); color: var(--warning); }
.badge-owner { background: rgba(88,101,242,.12); color: #a5b4fc; }
.badge-inactive { background: rgba(242,63,67,.12); color: var(--danger); }

/* ── Webhook display ───────────────────────────── */
.webhook-url {
  font-family: monospace; font-size: 12px;
  background: var(--bg-tertiary); padding: 2px 7px;
  border-radius: var(--radius-sm); color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 200px; display: block; border: 1px solid var(--border);
}
.webhook-url-lg {
  font-family: monospace; font-size: 13px;
  background: var(--bg-secondary); padding: 9px 13px;
  border-radius: var(--radius-sm); color: var(--text-secondary);
  border: 1px solid var(--border); word-break: break-all; flex: 1;
}
.webhook-display { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px; font-size: 12px;
  background: var(--bg-active); border-radius: var(--radius-sm);
  color: var(--text-secondary); white-space: nowrap;
  transition: background .12s, color .12s;
}
.copy-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Text utils ────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.hidden { display: none !important; }

/* ── Lightbox ──────────────────────────────────── */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 1000; align-items: center; justify-content: center; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius); box-shadow: var(--shadow); }
.lightbox-close { position: absolute; top: 16px; right: 20px; font-size: 32px; color: #fff; cursor: pointer; line-height: 1; }

/* ── Spinner ───────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ─────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.5); }
  .sidebar-toggle { display: flex !important; }
  .media-img { max-width: 100%; }
  .page-content { padding: 12px; }

  /* ── Mobile card layout for all data tables ── */
  .data-table-header { display: none !important; }

  .data-table-row {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    padding: 12px !important;
    min-height: unset !important;
  }

  /* Top row: avatar+name on left, badge on right */
  .data-table-row .cell-user { font-size: 14px; font-weight: 600; }

  /* Action buttons and toggles: shown as a flex row */
  .data-table-row .cell-actions {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Active toggle cell: show inline with a label */
  .users-table .data-table-row > span:nth-child(3) { display: flex !important; align-items: center; gap: 8px; }
  .users-table .data-table-row > span:nth-child(3)::before { content: "Active"; font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }

  /* Webhook cell wrap */
  .cell-webhook { flex-wrap: wrap; }

  /* Channels table: hide the add-member column on mobile, too complex */
  .channels-table .data-table-row > span:last-child { display: none !important; }

  /* Form rows on mobile: stack vertically */
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row input, .form-row select { max-width: 100%; }
  .form-row .btn, .form-row button { width: 100%; justify-content: center; }

  /* Expand forms: full width inputs */
  .expand-form-inner { flex-direction: column; }
  .expand-form-inner input[type="text"],
  .expand-form-inner input[type="password"] { width: 100%; }

  .btn-full { width: 100%; }
}

/* ── Tunnel card ──────────────────────────────── */
.tunnel-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.tunnel-status-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.tunnel-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.tunnel-dot-on  { background: #3ba55c; box-shadow: 0 0 6px #3ba55c88; animation: pulse-green 2s infinite; }
.tunnel-dot-off { background: var(--text-muted); }
@keyframes pulse-green { 0%,100% { box-shadow: 0 0 4px #3ba55c88; } 50% { box-shadow: 0 0 10px #3ba55ccc; } }
.tunnel-url-wrap { display: flex; align-items: center; gap: 8px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; }
.tunnel-url-link { font-size: 13px; color: var(--accent); word-break: break-all; flex: 1; }
.tunnel-url-link:hover { text-decoration: underline; }
.tunnel-download-wrap { display: flex; flex-direction: column; gap: 8px; }
.tunnel-log { background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 11px; color: var(--text-muted); font-family: monospace; max-height: 120px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.tunnel-actions { display: flex; gap: 8px; }
.tunnel-dns-hint { font-size: 11px; color: var(--text-muted); margin: 4px 0 0; display: flex; align-items: center; gap: 4px; }

/* ── Chat direction (own=right, other=left) ───── */
.message.msg-own { flex-direction: row-reverse; }
.message.msg-own .message-body { align-items: flex-end; display: flex; flex-direction: column; }
.message.msg-own .message-meta { flex-direction: row-reverse; }
.message.msg-own .message-content .msg-text,
.message.msg-own .message-content .attachments,
.message.msg-own .message-content .code-block,
.message.msg-own .message-content .rich-content {
  background: var(--accent);
  color: #fff;
  border-radius: 16px 4px 16px 16px;
  padding: 8px 12px;
  max-width: 480px;
  display: inline-block;
}
.message.msg-own .message-content .code-block { background: #1e1f22; padding: 0; }
.message.msg-own .message-content .attachments { background: none; padding: 0; }
.message.msg-own .message-author { color: var(--accent); }
.message:not(.msg-own) .message-content .msg-text {
  background: var(--bg-secondary);
  border-radius: 4px 16px 16px 16px;
  padding: 8px 12px;
  max-width: 480px;
  display: inline-block;
}
.message.msg-own .msg-edit-form { width: 100%; }
.message.msg-own .msg-actions { right: auto; left: 8px; }

/* ── @mention highlight ───────────────────────── */
.mention { color: var(--accent); font-weight: 600; background: rgba(88,101,242,.15); border-radius: 3px; padding: 0 2px; }
.mention-self { background: rgba(250,168,26,.18); color: #fab91a; }

/* ── Mention autocomplete ─────────────────────── */
.mention-popup { position: absolute; bottom: 100%; left: 0; min-width: 200px; max-width: 320px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 200; max-height: 240px; overflow-y: auto; margin-bottom: 6px; }
.mention-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; transition: background .1s; }
.mention-item:hover, .mention-item.active { background: var(--bg-hover); }
.mention-item .username { font-size: 14px; font-weight: 600; }

/* ── Reactions ────────────────────────────────── */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-btn { display: flex; align-items: center; gap: 4px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 13px; cursor: pointer; transition: background .1s, border-color .1s; color: var(--text-primary); }
.reaction-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.reaction-btn.reacted { background: rgba(88,101,242,.15); border-color: var(--accent); color: var(--accent); }
.reaction-count { font-size: 12px; font-weight: 600; }
.react-add-btn { background: none; border: 1px solid transparent; border-radius: 12px; padding: 2px 6px; cursor: pointer; color: var(--text-muted); font-size: 15px; opacity: 0; transition: opacity .15s, border-color .1s; }
.message:hover .react-add-btn { opacity: 1; }
.react-add-btn:hover { border-color: var(--border); color: var(--text-primary); }
.emoji-picker { position: absolute; bottom: calc(100% + 4px); left: 0; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 20px rgba(0,0,0,.4); padding: 8px; z-index: 200; display: flex; flex-wrap: wrap; gap: 2px; width: 220px; }
.message.msg-own .emoji-picker { left: auto; right: 0; }
.emoji-picker button { background: none; border: none; font-size: 20px; cursor: pointer; width: 32px; height: 32px; border-radius: 4px; transition: background .1s; }
.emoji-picker button:hover { background: var(--bg-hover); }

/* ── Sidebar search ───────────────────────────── */
.sidebar-search { padding: 6px 10px; }
.sidebar-search-input { width: 100%; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 13px; padding: 5px 10px; outline: none; box-sizing: border-box; }
.sidebar-search-input:focus { border-color: var(--accent); }
.channel-item.pinned-item { order: -1; }
.pin-btn { opacity: 0; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0 2px; font-size: 13px; margin-left: auto; flex-shrink: 0; }
.channel-item:hover .pin-btn { opacity: 1; }
.pin-btn.pinned { opacity: 1; color: var(--accent); }
.channel-item { display: flex; order: 0; }

/* ── Clickable links in messages ──────────────── */
.msg-text a, .msg-link { color: #7289da; text-decoration: underline; word-break: break-all; }
.msg-text a:hover { color: #a0b0ff; }

/* ── Seen-by receipts ─────────────────────────── */
.msg-seen { font-size: 10px; color: var(--text-muted); display: flex; align-items: center; gap: 3px; margin-top: 2px; }
.msg-seen i { color: #3ba55d; font-size: 12px; }

/* ── Reply quote ──────────────────────────────── */
.msg-reply-quote { border-left: 3px solid var(--accent); padding: 4px 8px; background: var(--bg-primary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; cursor: pointer; margin-bottom: 4px; max-width: 400px; }
.reply-author { font-size: 12px; font-weight: 700; color: var(--accent); display: block; }
.reply-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 380px; }

/* ── Reply bar ────────────────────────────────── */
.reply-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--bg-secondary); border-top: 1px solid var(--border); border-radius: var(--radius-sm) var(--radius-sm) 0 0; font-size: 13px; }
.reply-bar-inner { display: flex; align-items: center; gap: 6px; color: var(--text-muted); overflow: hidden; }
.reply-cancel-btn { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; flex-shrink: 0; line-height: 1; }
.reply-cancel-btn:hover { color: var(--text-primary); }

/* ── Message highlight ────────────────────────── */
.msg-highlight { animation: highlight-flash 1.5s ease; }
@keyframes highlight-flash { 0%,100% { background: transparent; } 30% { background: rgba(88,101,242,.18); } }

/* ── Numbered list in messages ────────────────── */
.msg-text ol { padding-left: 1.4em; margin: 0; }
.msg-text ol li { margin-bottom: 2px; }
