/* ── 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;
}

/* Light theme overrides */
html[data-theme="light"] {
  --bg-primary:    #ffffff;
  --bg-secondary:  #f3f5f7;
  --bg-tertiary:   #ffffff;
  --bg-hover:      #ebeef1;
  --bg-active:     #e3e7eb;
  --accent:        #4752c4;
  --accent-hover:  #3a44b0;
  --text-primary:  #1a1c1f;
  --text-secondary:#43484f;
  --text-muted:    #6a727b;
  --border:        #d8dce0;
  --shadow:        0 2px 10px rgba(0,0,0,.08);
}
html[data-theme="light"] .message:hover { background: rgba(0,0,0,.03); }
html[data-theme="light"] .messages-container::-webkit-scrollbar-thumb { background: #c3c8ce; }
html[data-theme="light"] .code-block,
html[data-theme="light"] .rich-content pre,
html[data-theme="light"] .rich-content pre.ql-syntax,
html[data-theme="light"] #quill-editor .ql-editor pre.ql-syntax { background: #1e1f22; color: #abb2bf; }
html[data-theme="light"] .message.msg-own .message-content .code-block { background: #1e1f22; }
html[data-theme="light"] .rich-content code { background: rgba(0,0,0,.06); color: #b3580d; }
html[data-theme="light"] .rich-content a { color: #1a73e8; }
html[data-theme="light"] .ql-snow .ql-stroke { stroke: var(--text-secondary); }
html[data-theme="light"] .ql-snow .ql-fill { fill: var(--text-secondary); }
html[data-theme="light"] .avatar-letter { background: var(--accent); color: #fff; }

html, body { height: 100%; height: 100dvh; 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; height: 100dvh; 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; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.rich-content p { margin: 0; }
.rich-content p + p { margin-top: 4px; }
.rich-content ol, .rich-content ul { padding-left: 1.4em; margin: 4px 0; }
.rich-content li { margin: 2px 0; }
.rich-content blockquote { border-left: 3px solid var(--accent); padding: 2px 10px; color: var(--text-secondary); margin: 4px 0; background: rgba(88,101,242,.06); border-radius: 0 4px 4px 0; }
.rich-content a { color: #00aff4; text-decoration: underline; word-break: break-all; }
.rich-content a:hover { text-decoration: none; }
.rich-content code { background: rgba(0,0,0,.35); border-radius: 3px; padding: 1px 5px; font-size: 13px; font-family: 'Fira Code', 'Consolas', monospace; color: #f1c97a; }
.rich-content pre, .rich-content pre.ql-syntax {
  position: relative;
  background: #282c34;
  color: #abb2bf;
  border-radius: 6px;
  padding: 10px 0;
  font-size: 13px;
  font-family: 'Fira Code', 'Consolas', monospace;
  margin: 4px 0;
  overflow-x: auto;
  line-height: 1.6;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  display: flex;
  gap: 0;
  box-sizing: border-box;
}
.rich-content pre .code-line-nums { padding: 0 12px; }
.rich-content pre code {
  background: none;
  padding: 0 14px 0 0;
  color: inherit;
  font-size: inherit;
  display: block;
  white-space: pre;
  flex: 1;
  min-width: 0;
}
.rich-content pre code.hljs { background: transparent; padding: 0; }
.rich-content pre.ql-syntax-with-lang { padding-top: 26px; }
.rich-content pre.ql-syntax-with-lang::before {
  content: attr(data-lang-badge);
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 10px;
  text-transform: lowercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  background: rgba(0,0,0,.25);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: 'Fira Code', 'Consolas', monospace;
}
/* Copy button on Quill code blocks (rich-content). The pre is position: relative already. */
.rich-content pre.ql-syntax .copy-code-btn-quill {
  position: absolute;
  top: 4px;
  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;
  padding: 0;
}
.rich-content pre.ql-syntax .copy-code-btn-quill i { font-size: 14px; }
.rich-content pre.ql-syntax:hover .copy-code-btn-quill,
.rich-content pre.ql-syntax .copy-code-btn-quill:focus { opacity: 1; }
.rich-content pre.ql-syntax .copy-code-btn-quill:hover { color: #abb2bf; }
.rich-content pre.ql-syntax .copy-code-btn-quill.copied { color: #98c379; border-color: #98c379; opacity: 1; }
.rich-content u { text-decoration: underline; }
.rich-content s { text-decoration: line-through; }
/* ── Message actions (edit / delete) ──────────── */
.msg-content-row { display: flex; align-items: flex-start; gap: 4px; min-width: 0; max-width: 100%; }
.msg-content-row > .message-content { min-width: 0; max-width: 100%; flex: 0 1 auto; }
.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: flex-end; 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-quill { background: var(--bg-primary); border: 1px solid var(--accent); border-radius: var(--radius-sm); min-height: 60px; max-height: 240px; overflow-y: auto; }
.msg-edit-quill .ql-editor { color: var(--text-primary); font-size: 14px; line-height: 1.5; padding: 8px 10px; min-height: 50px; }
.msg-edit-quill .ql-editor.ql-blank::before { color: var(--text-muted); font-style: normal; left: 10px; }
.msg-edit-form .ql-toolbar { background: var(--bg-secondary); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; padding: 4px 6px; }
.msg-edit-form .ql-toolbar + .msg-edit-quill { border-radius: 0 0 var(--radius-sm) var(--radius-sm); border-top: none; }
.msg-edit-form .ql-toolbar button { width: 24px; height: 24px; padding: 2px; }
.msg-edit-form .ql-toolbar button svg { width: 14px; height: 14px; }
.msg-edit-form .ql-toolbar .ql-stroke { stroke: var(--text-secondary); }
.msg-edit-form .ql-toolbar .ql-fill { fill: var(--text-secondary); }
.msg-edit-form .ql-toolbar button:hover .ql-stroke,
.msg-edit-form .ql-toolbar button.ql-active .ql-stroke { stroke: var(--accent); }
.msg-edit-form .ql-toolbar button:hover .ql-fill,
.msg-edit-form .ql-toolbar button.ql-active .ql-fill { fill: var(--accent); }
.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; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.media-img {
  display: block;
  max-width: 100%;
  width: auto;
  max-height: 320px;
  min-width: 120px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  cursor: pointer;
  background: var(--bg-primary);
}
.media-img.media-img-broken { display: none; }
.media-wrap .file-link { font-size: 12px; padding: 4px 8px; }
.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; position: relative; }
.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: 10px; display: flex; gap: 12px; flex-wrap: wrap; padding: 12px 14px 4px; border-top: 1px solid var(--border); }
.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; }

  /* Pin chat header so it stays visible even when mobile chrome
     resizes the viewport or content overflows unexpectedly. */
  .main-content { position: relative; }
  .chat-header {
    position: sticky; top: 0; z-index: 50;
    background: var(--bg-tertiary);
  }
  .chat-header-info h2 { font-size: 14px; }
  .member-count { display: none; }
  /* Trim padding so all action buttons stay on one row on narrow screens */
  .chat-header { padding: 0 6px; gap: 4px; }
  .chat-header-actions { gap: 0; }

  /* Hard cap every bubble + its children to the viewport width on mobile,
     overriding the desktop min(...) rules. Use !important to win over the
     more-specific .message.msg-own selectors. */
  .messages-container { overflow-x: hidden; }
  .message { padding: 4px 8px; }
  .message-body, .msg-content-row { max-width: 100%; min-width: 0; overflow: hidden; }
  .message-content,
  .message-content .rich-content,
  .message-content .code-block,
  .message-content .msg-text,
  .message-content .attachments {
    max-width: calc(100vw - 76px) !important;
  }
  .rich-content pre, .rich-content pre.ql-syntax, .code-block pre {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* ── 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: min(560px, calc(100vw - 96px));
  display: inline-block;
}
.message.msg-own .message-content .code-block { background: #1e1f22; padding: 0; }
.message.msg-own .message-content .attachments { background: none; padding: 0; }
/* Right-align all children (attach-label pill, image+filename, file pills) for own messages.
   Force message-content into a flex column so every direct child hugs the right edge regardless of
   block/inline-block behavior. */
.message.msg-own .message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.message.msg-own .message-content > * { max-width: 100%; }
.message.msg-own .media-wrap { align-items: flex-end; }
.message.msg-own .file-link-wrap { justify-content: flex-end; }
.message.msg-own .attachments { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
/* Keep text reading left-to-right inside bubbles */
.message.msg-own .message-content .msg-text:not(.attach-label),
.message.msg-own .message-content .rich-content,
.message.msg-own .message-content .code-block { text-align: left; }
.message.msg-own .message-author { color: var(--accent); }
.message:not(.msg-own) .message-content .msg-text,
.message:not(.msg-own) .message-content .rich-content,
.message:not(.msg-own) .message-content .code-block {
  background: var(--bg-secondary);
  border-radius: 4px 16px 16px 16px;
  padding: 8px 12px;
  max-width: min(560px, calc(100vw - 96px));
  display: inline-block;
}
.message:not(.msg-own) .message-content .code-block { padding: 0; }
.message:not(.msg-own) .message-content .rich-content { padding: 6px 10px; }

/* Outer hard-cap on the content cell — every bubble is also clipped here. */
.message-content { max-width: min(620px, calc(100vw - 96px)); }
.message-content > * { max-width: 100%; }
.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,
.rich-content a,
.msg-caption a,
.reply-text a,
.mini-msg-body a { color: #7da6ff; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; cursor: pointer; }
.msg-text a:hover,
.msg-link:hover,
.rich-content a:hover,
.msg-caption a:hover,
.reply-text a:hover,
.mini-msg-body a:hover { color: #b9cdff; text-decoration: underline; }

/* Light mode — stronger contrast against light bubble. */
html[data-theme="light"] .msg-text a,
html[data-theme="light"] .msg-link,
html[data-theme="light"] .rich-content a,
html[data-theme="light"] .msg-caption a,
html[data-theme="light"] .reply-text a,
html[data-theme="light"] .mini-msg-body a { color: #1a73e8; }
html[data-theme="light"] .msg-text a:hover,
html[data-theme="light"] .msg-link:hover,
html[data-theme="light"] .rich-content a:hover,
html[data-theme="light"] .msg-caption a:hover { color: #0b51b4; }

/* Own-message bubble has --accent (purple) background — links need a
   high-contrast color in both themes. */
.message.msg-own .message-content a,
.message.msg-own .message-content .msg-link { color: #fff; text-decoration: underline; text-underline-offset: 2px; }
.message.msg-own .message-content a:hover,
.message.msg-own .message-content .msg-link:hover { color: #fff; opacity: 0.85; }

/* ── 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; }

/* ── Quill editor ─────────────────────────────── */
.message-input-area { padding: 0 16px 16px; flex-shrink: 0; }
#send-form { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: visible; position: relative; }

/* Toolbar */
#quill-toolbar { background: var(--bg-secondary); border: none; border-bottom: 1px solid var(--border); border-radius: var(--radius-sm) var(--radius-sm) 0 0; padding: 3px 6px; display: flex; align-items: center; flex-wrap: wrap; gap: 0; }
#quill-toolbar .ql-formats { display: inline-flex; align-items: center; gap: 0; margin-right: 6px; }
#quill-toolbar .ql-formats-right { margin-left: auto; margin-right: 0; }
#quill-toolbar button { color: var(--text-secondary); background: none; border: none; border-radius: 4px; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s, color .15s; padding: 2px; }
#quill-toolbar button svg { width: 14px; height: 14px; }
#quill-toolbar button:hover { background: var(--bg-hover); color: var(--text-primary); }
#quill-toolbar button.ql-active { color: var(--accent); background: rgba(88,101,242,.12); }
#quill-toolbar .ql-stroke { stroke: var(--text-secondary); }
#quill-toolbar button:hover .ql-stroke,
#quill-toolbar button.ql-active .ql-stroke { stroke: var(--accent); }
#quill-toolbar .ql-fill { fill: var(--text-secondary); }
#quill-toolbar button:hover .ql-fill,
#quill-toolbar button.ql-active .ql-fill { fill: var(--accent); }
#quill-toolbar .ql-attach { color: var(--text-secondary); border-radius: 4px; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; transition: background .15s, color .15s; }
#quill-toolbar .ql-attach:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Editor area */
#quill-editor { background: var(--bg-secondary); color: var(--text-primary); font-size: 14px; font-family: inherit; min-height: 44px; max-height: 200px; overflow-y: auto; border: none; border-radius: 0; padding-right: 48px; }
#quill-editor .ql-editor { padding: 8px 12px; min-height: 44px; max-height: 200px; line-height: 1.5; }
#quill-editor .ql-editor.ql-blank::before { color: var(--text-muted); font-style: normal; left: 12px; }
#quill-editor .ql-editor p { margin: 0; }
#quill-editor .ql-editor pre.ql-syntax { background: var(--bg-primary); color: #abb2bf; border-radius: 6px; padding: 10px 14px; font-size: 13px; margin: 4px 0; overflow-x: auto; }
#quill-editor .ql-editor code { background: rgba(0,0,0,.25); border-radius: 3px; padding: 1px 4px; font-size: 13px; font-family: 'Fira Code', 'Consolas', monospace; }
#quill-editor .ql-editor blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--text-secondary); margin: 4px 0; }

/* Send button – absolute bottom-right corner of form */
#send-btn { position: absolute; bottom: 8px; right: 8px; 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; flex-shrink: 0; border: none; cursor: pointer; z-index: 1; }
#send-btn:hover { background: var(--accent-hover); }

/* Quill link tooltip – dark */
.ql-tooltip { background: var(--bg-secondary) !important; border: 1px solid var(--border) !important; color: var(--text-primary) !important; box-shadow: 0 4px 16px rgba(0,0,0,.4) !important; border-radius: var(--radius-sm) !important; z-index: 300; }
.ql-tooltip input { background: var(--bg-primary) !important; border: 1px solid var(--border) !important; color: var(--text-primary) !important; border-radius: 4px; padding: 4px 8px; }
.ql-tooltip a.ql-action::after { color: var(--accent) !important; }
.ql-tooltip a.ql-remove::before { color: var(--danger, #f04747) !important; }

/* ── Forward modal ─────────────────────────── */
.forward-modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 500; display: flex; align-items: center; justify-content: center; }
.forward-modal.hidden { display: none; }
.forward-modal-content { width: 440px; max-width: 92vw; max-height: 80vh; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.forward-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.forward-modal-header h3 { margin: 0; font-size: 15px; }
.forward-modal-search { position: relative; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.forward-modal-search i { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.forward-modal-search input { width: 100%; padding: 8px 10px 8px 32px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); outline: none; }
.forward-modal-search input:focus { border-color: var(--accent); }
.forward-modal-results { overflow-y: auto; padding: 6px; flex: 1; }
.forward-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background .12s; }
.forward-item:hover { background: var(--bg-hover, rgba(255,255,255,.05)); }
.forward-item-name { flex: 1; font-size: 14px; color: var(--text-primary); }
.forward-item-type { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.forward-item .ch-icon { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; background: var(--bg-primary); border-radius: 6px; color: var(--text-muted); }

/* ── Notification menu ─────────────────────── */
.notif-wrap { position: relative; display: inline-flex; }
.notif-menu { position: absolute; top: calc(100% + 4px); right: 0; min-width: 180px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 4px; z-index: 200; display: flex; flex-direction: column; }
.notif-menu.hidden { display: none; }
.notif-opt { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13px; color: var(--text-primary); background: none; border: none; border-radius: 4px; text-align: left; cursor: pointer; transition: background .12s; }
.notif-opt:hover { background: var(--bg-hover); }
.notif-opt.active { color: var(--accent); }
.notif-opt.active i { color: var(--accent); }
.notif-opt i { font-size: 14px; color: var(--text-muted); }

.msg-forwarded { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; padding: 2px 8px; background: rgba(88,101,242,.08); border-left: 2px solid var(--accent); border-radius: 3px; font-style: italic; }
.msg-forwarded i { font-size: 12px; }
.msg-forwarded strong { color: var(--text-secondary, var(--text-primary)); font-weight: 600; font-style: normal; }

/* ── Day separators ────────────────────────── */
.day-sep { display: flex; align-items: center; justify-content: center; margin: 16px 0 8px; pointer-events: none; }
.day-floating { position: absolute; top: 8px; left: 0; right: 0; display: flex; justify-content: center; z-index: 10; pointer-events: none; transition: opacity .15s; }
.day-floating.hidden { opacity: 0; }
.day-floating .day-sep-pill { backdrop-filter: blur(8px); background: rgba(30,31,34,.85); }
html[data-theme="light"] .day-floating .day-sep-pill { background: rgba(255,255,255,.9); }
.day-sep-pill { font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; box-shadow: var(--shadow); letter-spacing: 0.3px; text-transform: uppercase; }

/* ── Unread divider ────────────────────────── */
.unread-divider { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; }
.unread-divider::before, .unread-divider::after { content: ""; flex: 1; height: 1px; background: #ef4444; opacity: 0.5; }
.unread-divider-label { font-size: 11px; font-weight: 700; color: #ef4444; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 8px; background: rgba(239,68,68,0.1); border-radius: 999px; }

/* ── Jump to bottom badge ──────────────────── */
.jump-bottom-btn { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% - 4px); display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-primary); font-size: 12px; font-weight: 500; cursor: pointer; box-shadow: var(--shadow); z-index: 20; white-space: nowrap; transition: background .12s, transform .12s; }
.jump-bottom-btn:hover { background: var(--bg-hover); transform: translateX(-50%) translateY(-1px); }
.jump-bottom-btn.hidden { display: none; }
.jump-bottom-btn i { font-size: 14px; }

/* ── Drop zone ─────────────────────────────── */
.messages-container.dropzone-active { outline: 2px dashed var(--accent); outline-offset: -8px; background: rgba(88,101,242,0.04); }

/* ── Pin / Save active states ──────────────── */
.msg-pin-btn.active, .msg-pin-btn.active i { color: var(--accent); }
.msg-save-btn.active, .msg-save-btn.active i { color: #f59e0b; }

/* ── Pinned / Saved panel mini messages ────── */
.mini-msg { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.mini-msg:hover { background: var(--bg-hover); }
.mini-msg-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; flex-wrap: wrap; }
.mini-msg-author { color: var(--text-primary); font-weight: 600; font-size: 12px; }
.mini-msg-time { font-size: 11px; }
.mini-msg-jump { color: var(--accent); text-decoration: none; font-size: 11px; }
.mini-msg-jump:hover { text-decoration: underline; }
.mini-msg-body { font-size: 13px; color: var(--text-secondary, var(--text-primary)); line-height: 1.4; max-height: 4.5em; overflow: hidden; text-overflow: ellipsis; word-break: break-word; }
.mini-msg-body * { max-width: 100%; }
.mini-msg-body img { max-height: 80px; border-radius: 4px; }

/* ── Link preview cards ────────────────────── */
.link-preview-card { display: flex; gap: 10px; margin-top: 8px; padding: 10px; background: var(--bg-secondary); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); text-decoration: none; color: inherit; max-width: min(560px, calc(100vw - 96px)); transition: background .12s; }
.link-preview-card:hover { background: var(--bg-hover); }
.link-preview-card .lp-img { flex: 0 0 88px; width: 88px; height: 88px; border-radius: 4px; overflow: hidden; background: var(--bg-tertiary, var(--bg-primary)); display: flex; align-items: center; justify-content: center; }
.link-preview-card .lp-img img { width: 100%; height: 100%; object-fit: cover; }
.link-preview-card .lp-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.link-preview-card .lp-site { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.link-preview-card .lp-title { font-size: 14px; font-weight: 600; color: var(--text-primary); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.link-preview-card .lp-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

@media (max-width: 640px) {
  .link-preview-card { max-width: calc(100vw - 76px) !important; }
  .link-preview-card .lp-img { flex-basis: 64px; width: 64px; height: 64px; }
}

/* ── Instant tooltips ──────────────────────────
   Native [title] tooltips have a ~700ms browser delay that can't be
   shortened. We swap titles for [data-tooltip] at boot (see app.js) and
   render via CSS so they appear immediately on hover. */
[data-tooltip] { position: relative; }
[data-tooltip]::after,
[data-tooltip]::before {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity .08s ease-out, transform .08s ease-out;
  z-index: 9999;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translate(-50%, 4px);
  background: #111827;
  color: #f9fafb;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  padding: 5px 8px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  letter-spacing: 0.1px;
}
[data-tooltip]::before {
  content: "";
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translate(-50%, 4px);
  border: 5px solid transparent;
  border-top-color: #111827;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before,
[data-tooltip]:focus-visible::after,
[data-tooltip]:focus-visible::before {
  opacity: 1;
  transform: translate(-50%, 0);
}
/* Tooltip below for elements near top of viewport */
[data-tooltip][data-tooltip-pos="bottom"]::after {
  bottom: auto; top: calc(100% + 8px);
}
[data-tooltip][data-tooltip-pos="bottom"]::before {
  bottom: auto; top: calc(100% + 3px);
  border-top-color: transparent;
  border-bottom-color: #111827;
}
/* Tooltip to the left for right-edge buttons */
[data-tooltip][data-tooltip-pos="left"]::after {
  bottom: 50%; left: auto; right: calc(100% + 8px);
  transform: translate(4px, 50%);
}
[data-tooltip][data-tooltip-pos="left"]::before {
  bottom: 50%; left: auto; right: calc(100% + 3px);
  transform: translate(4px, 50%);
  border-top-color: transparent;
  border-left-color: #111827;
}
[data-tooltip][data-tooltip-pos="left"]:hover::after,
[data-tooltip][data-tooltip-pos="left"]:hover::before {
  transform: translate(0, 50%);
}
/* Header buttons sit at top of viewport — tooltips above get clipped by
   `overflow: hidden` on <body>. Force them to render below. */
.chat-header [data-tooltip]::after,
.app-header [data-tooltip]::after {
  bottom: auto; top: calc(100% + 8px);
}
.chat-header [data-tooltip]::before,
.app-header [data-tooltip]::before {
  bottom: auto; top: calc(100% + 3px);
  border-top-color: transparent;
  border-bottom-color: #111827;
}
/* Right-edge buttons in the header — keep tooltip from clipping off-screen */
.chat-header-actions > *:last-child [data-tooltip]::after,
.chat-header-actions > *:last-child[data-tooltip]::after {
  left: auto; right: 0; transform: translate(0, 4px);
}
.chat-header-actions > *:last-child [data-tooltip]:hover::after,
.chat-header-actions > *:last-child[data-tooltip]:hover::after {
  transform: translate(0, 0);
}

/* Suppress on touch devices to avoid sticky tooltips */
@media (hover: none) {
  [data-tooltip]::after, [data-tooltip]::before { display: none; }
}

/* ── Checklist messages ────────────────────── */
.checklist {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px 8px;
  max-width: min(560px, calc(100vw - 96px));
  min-width: 0;
}
.checklist-progress { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.checklist-progress-count { font-size: 11px; font-weight: 600; color: var(--text-muted); flex-shrink: 0; min-width: 36px; }
.checklist-progress-bar { flex: 1; height: 4px; background: var(--bg-primary); border-radius: 2px; overflow: hidden; }
.checklist-progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .25s ease; }
.checklist-items { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.checklist-item { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; }
.checklist-checkbox {
  flex: 0 0 auto;
  background: none; border: none; padding: 0; cursor: pointer;
  width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); position: relative;
  transition: color .12s, transform .12s;
}
.checklist-checkbox:hover { color: var(--accent); transform: scale(1.08); }
.checklist-checkbox i { font-size: 18px; line-height: 1; position: absolute; transition: opacity .12s; }
.checklist-checkbox .on  { opacity: 0; color: var(--accent); }
.checklist-checkbox .off { opacity: 1; }
.checklist-item.checked .checklist-checkbox .on  { opacity: 1; }
.checklist-item.checked .checklist-checkbox .off { opacity: 0; }
.checklist-text { flex: 1; min-width: 0; word-break: break-word; line-height: 1.4; font-size: 14px; color: var(--text-primary); }
.checklist-item.checked .checklist-text { color: var(--text-muted); text-decoration: line-through; }

/* Quill toolbar checklist button — match other ql buttons */
.ql-toolbar .ql-checklist-btn {
  background: none; border: none; padding: 3px 5px; width: 28px; height: 24px;
  cursor: pointer; color: #444; display: inline-flex; align-items: center; justify-content: center;
}
.ql-toolbar .ql-checklist-btn:hover { color: var(--accent); }
.ql-toolbar .ql-checklist-btn i { font-size: 16px; line-height: 1; }

/* ── Checklist composer modal ──────────────── */
.checklist-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.checklist-modal.hidden { display: none; }
.checklist-modal-content { width: 720px; max-width: 100%; max-height: 88vh; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.checklist-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.checklist-modal-header h3 { margin: 0; font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text-primary); }
.checklist-modal-header h3 i { color: var(--accent); }
.checklist-modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; flex: 1; overflow: hidden; }
.checklist-editor, .checklist-preview { padding: 14px; overflow-y: auto; }
.checklist-editor { border-right: 1px solid var(--border); }
.checklist-editor-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.checklist-editor-items { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.cl-edit-row { display: flex; align-items: center; gap: 6px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 6px; }
.cl-edit-row:focus-within { border-color: var(--accent); }
.cl-edit-check { background: none; border: none; cursor: pointer; width: 22px; height: 22px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); position: relative; padding: 0; }
.cl-edit-check:hover { color: var(--accent); }
.cl-edit-check i { font-size: 18px; line-height: 1; position: absolute; transition: opacity .12s; }
.cl-edit-check .on  { opacity: 0; color: var(--accent); }
.cl-edit-check .off { opacity: 1; }
.cl-edit-check.on .on  { opacity: 1; }
.cl-edit-check.on .off { opacity: 0; }
.cl-edit-input { flex: 1; min-width: 0; background: none; border: none; outline: none; font-size: 14px; color: var(--text-primary); padding: 4px 2px; }
.cl-edit-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 6px; }
.cl-edit-remove:hover { color: #ef4444; }
.checklist-add-btn { display: inline-flex; align-items: center; gap: 4px; }
.checklist-editor-hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.checklist-editor-hint kbd { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; font-size: 10px; font-family: monospace; }
.checklist-preview-body { background: var(--bg-tertiary, var(--bg-primary)); border-radius: var(--radius-sm); padding: 10px; min-height: 140px; }
.checklist-modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--bg-tertiary, var(--bg-secondary)); }

@media (max-width: 640px) {
  .checklist-modal-content { max-height: 92vh; }
  .checklist-modal-body { grid-template-columns: 1fr; }
  .checklist-editor { border-right: none; border-bottom: 1px solid var(--border); }
  .checklist { max-width: calc(100vw - 76px) !important; }
}

/* ── Focus Dashboard ───────────────────────── */
.focus-page { background: var(--bg-tertiary); }
.focus-header { gap: 8px; }
.focus-header .focus-heading { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.focus-label-pill { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; background: var(--bg-secondary); border: 1px solid var(--border); font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.focus-save-status { font-size: 11px; color: var(--text-muted); margin-left: 6px; min-width: 56px; text-align: right; }
.focus-save-status.saving { color: var(--text-muted); }
.focus-save-status.saved { color: #16a34a; }
.focus-save-status.error { color: #ef4444; }
.icon-btn.disabled { opacity: 0.4; pointer-events: none; }

.focus-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }

.focus-rail { width: 240px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg-secondary); display: flex; flex-direction: column; overflow: hidden; }
.focus-rail-header { padding: 12px 14px 8px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.focus-rail-header span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.focus-rail-today { font-size: 12px; color: var(--accent); text-decoration: none; font-weight: 600; }
.focus-rail-today:hover { text-decoration: underline; }
.focus-rail-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.focus-rail-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; color: var(--text-primary); text-decoration: none; font-size: 13px; transition: background .12s; cursor: pointer; }
.focus-rail-item:hover { background: var(--bg-hover); }
.focus-rail-item.active { background: var(--bg-hover); border-left: 3px solid var(--accent); padding-left: 11px; font-weight: 600; }
.focus-rail-progress { font-size: 11px; color: var(--text-muted); padding: 1px 7px; border-radius: 999px; background: var(--bg-tertiary, var(--bg-primary)); border: 1px solid var(--border); }
.focus-rail-progress.complete { color: #16a34a; border-color: rgba(22,163,74,0.4); }

.focus-main { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.focus-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md, 10px); overflow: hidden; }
.focus-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.focus-card-header h3 { margin: 0; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; color: var(--text-primary); }
.focus-card-header h3 i { color: var(--accent); }
.focus-notes-hint { font-size: 11px; color: var(--text-muted); }

.focus-progress { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.focus-progress-count { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.focus-progress-bar { flex: 1; height: 6px; background: var(--bg-tertiary, var(--bg-primary)); border-radius: 999px; overflow: hidden; min-width: 80px; }
.focus-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #22c55e); transition: width .25s ease; }

.focus-checklist-card { display: flex; flex-direction: column; max-height: min(560px, 70vh); }
.focus-items { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.focus-checklist-card .focus-add { flex-shrink: 0; background: var(--bg-secondary); position: sticky; bottom: 0; }
.focus-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 18px; min-height: 40px; transition: background .12s; }
.focus-item:hover { background: var(--bg-hover); }
.focus-item.checked .focus-item-text { text-decoration: line-through; color: var(--text-muted); }
.focus-checkbox { background: transparent; border: 0; padding: 4px; margin-top: 1px; cursor: pointer; color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.focus-checkbox i { font-size: 20px; }
.focus-checkbox .on { display: none; }
.focus-item.checked .focus-checkbox { color: #16a34a; }
.focus-item.checked .focus-checkbox .off { display: none; }
.focus-item.checked .focus-checkbox .on { display: inline; }
.focus-item-text { flex: 1; font-size: 14px; line-height: 1.5; outline: none; color: var(--text-primary); padding: 5px 4px; border-radius: 4px; word-break: break-word; min-width: 0; }
.focus-item-text:focus { background: var(--bg-tertiary, var(--bg-primary)); box-shadow: inset 0 0 0 1px var(--accent); }
.focus-item-del { background: transparent; border: 0; color: var(--text-muted); cursor: pointer; padding: 4px; opacity: 0; transition: opacity .12s, color .12s; flex-shrink: 0; }
.focus-item:hover .focus-item-del,
.focus-item-del:focus { opacity: 1; }
.focus-item-del:hover { color: #ef4444; }

.focus-add { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--border); }
.focus-add i { color: var(--text-muted); font-size: 16px; }
.focus-add-input { flex: 1; background: transparent; border: 0; outline: none; color: var(--text-primary); font-size: 14px; padding: 6px 0; }
.focus-add-input::placeholder { color: var(--text-muted); }

.focus-notes-editor { min-height: 240px; }
.focus-notes-editor.ql-container { border: 0; font-size: 14px; }
.focus-notes-card .ql-toolbar { border: 0; border-bottom: 1px solid var(--border); }
.focus-notes-editor .ql-editor { color: var(--text-primary); }
.focus-notes-editor .ql-editor.ql-blank::before { color: var(--text-muted); font-style: normal; opacity: 0.85; }

@media (max-width: 900px) {
  .focus-rail { width: 200px; }
  .focus-main { padding: 16px; }
}

@media (max-width: 720px) {
  .focus-body { flex-direction: column; }
  .focus-rail { width: 100%; max-height: 140px; border-right: 0; border-bottom: 1px solid var(--border); }
  .focus-rail-list { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; overflow-y: hidden; }
  .focus-rail-item { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; }
  .focus-rail-item.active { border-left: 0; padding-left: 12px; background: var(--accent); color: #fff; }
  .focus-rail-item.active .focus-rail-progress { background: rgba(255,255,255,0.18); border-color: transparent; color: #fff; }
  .focus-rail-header { display: none; }
  .focus-main { padding: 12px; gap: 12px; }
  .focus-card-header { padding: 12px 14px; flex-wrap: wrap; }
  .focus-progress { min-width: 0; width: 100%; }
  .focus-item { padding: 10px 14px; }
  .focus-item-text { font-size: 15px; }
  .focus-item-del { opacity: 1; }
  .focus-add { padding: 12px 14px; }
  .focus-add-input { font-size: 16px; }
  .focus-checklist-card { max-height: 60vh; }
  .focus-header .focus-heading { font-size: 14px; }
  .focus-label-pill { display: none; }
}

.focus-nav-item { color: var(--text-primary); }
.focus-nav-item.active { background: var(--bg-hover); }
.focus-nav-item i { color: var(--accent); }
.sidebar-section-focus { padding: 8px 6px 0; }

/* ── Knowledge Base ────────────────────────── */
.kb-page { background: var(--bg-tertiary); }
.kb-header { gap: 8px; }
.kb-header-info { flex: 1; min-width: 0; gap: 8px; }
.kb-title { font-size: 16px; font-weight: 600; margin: 0; outline: none; padding: 2px 6px; border-radius: 4px; min-width: 60px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.kb-title[contenteditable="true"]:hover { background: var(--bg-hover); }
.kb-title[contenteditable="true"]:focus { background: var(--bg-secondary); box-shadow: inset 0 0 0 1px var(--accent); white-space: normal; }
.kb-pinned-indicator { color: var(--accent); font-size: 14px; }
.kb-header-actions { gap: 4px; }
.kb-pin-btn.active i { color: var(--accent); }
.kb-rail-toggle { display: none; }

.kb-presence { display: inline-flex; align-items: center; gap: -4px; margin-right: 4px; }
.kb-presence .avatar { width: 22px; height: 22px; font-size: 10px; border: 2px solid var(--bg-secondary); margin-left: -6px; }
.kb-presence .avatar:first-child { margin-left: 0; }
.kb-presence-more { font-size: 11px; color: var(--text-muted); margin-left: 4px; }

.kb-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }

.kb-rail { width: 280px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg-secondary); display: flex; flex-direction: column; overflow: hidden; }
.kb-rail-header { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.kb-rail-search { flex: 1; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px 10px; font-size: 13px; color: var(--text-primary); outline: none; }
.kb-rail-search:focus { border-color: var(--accent); }
.kb-rail-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.kb-rail-section { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 10px 14px 4px; }
.kb-rail-item { display: block; padding: 8px 14px; color: var(--text-primary); text-decoration: none; border-left: 3px solid transparent; transition: background .12s; }
.kb-rail-item:hover { background: var(--bg-hover); }
.kb-rail-item.active { background: var(--bg-hover); border-left-color: var(--accent); }
.kb-rail-item-row { display: flex; align-items: center; gap: 6px; }
.kb-rail-pin { color: var(--accent); font-size: 11px; flex-shrink: 0; }
.kb-rail-shared { color: var(--text-muted); font-size: 12px; margin-left: auto; flex-shrink: 0; }
.kb-rail-title { font-size: 13px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-rail-snippet { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.kb-main { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-width: 0; padding: 24px 28px; }
.kb-meta-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.kb-meta-sep { opacity: 0.6; }
.kb-meta-row strong { color: var(--text-primary); font-weight: 600; }
.kb-readonly-banner { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.4); border-radius: var(--radius-sm); color: #b45309; font-size: 12px; margin-bottom: 12px; align-self: flex-start; }
[data-theme="dark"] .kb-readonly-banner { color: #fbbf24; }

.kb-body-editor { flex: 1; overflow-y: auto; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md, 10px); }
.kb-body-editor.ql-container { font-size: 15px; border: 1px solid var(--border) !important; border-radius: var(--radius-md, 10px); }
.kb-main .ql-toolbar { background: var(--bg-secondary); border: 1px solid var(--border); border-bottom: none; border-top-left-radius: var(--radius-md, 10px); border-top-right-radius: var(--radius-md, 10px); position: sticky; top: 0; z-index: 5; }
.kb-main .ql-toolbar + .kb-body-editor.ql-container,
.kb-main .ql-toolbar + .ql-container { border-top: 0 !important; border-top-left-radius: 0; border-top-right-radius: 0; }
.kb-body-editor .ql-editor { min-height: 320px; color: var(--text-primary); padding: 18px 22px; }
.kb-body-editor .ql-editor.ql-blank::before { color: var(--text-muted); font-style: normal; opacity: 0.85; }

/* Empty state */
.kb-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.kb-empty-card { text-align: center; max-width: 420px; padding: 36px 24px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md, 10px); }
.kb-empty-card > i { font-size: 40px; color: var(--accent); }
.kb-empty-card h2 { margin: 12px 0 6px; font-size: 18px; }
.kb-empty-card p { color: var(--text-muted); font-size: 14px; margin: 0 0 18px; }
.kb-empty-card .btn { display: inline-flex; align-items: center; gap: 8px; }
.kb-empty-card .btn i { font-size: 16px; }

/* Share modal */
.kb-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.kb-modal.hidden { display: none; }
.kb-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.kb-modal-content { position: relative; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md, 10px); width: min(520px, calc(100vw - 32px)); max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.kb-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.kb-modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.kb-modal-body { padding: 16px 18px; overflow-y: auto; }
.kb-share-public { padding: 10px 12px; background: var(--bg-tertiary, var(--bg-primary)); border-radius: var(--radius-sm); margin-bottom: 14px; }
.kb-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.kb-share-add { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.kb-share-add-row { display: flex; gap: 8px; }
.kb-share-select { flex: 1; min-width: 0; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; color: var(--text-primary); }
.kb-share-select[multiple] { padding: 4px; }
.kb-share-select[multiple] option { padding: 6px 8px; border-radius: 4px; }
.kb-share-hint { font-size: 11px; color: var(--text-muted); }
.kb-share-role { flex: 0 0 110px; }
.kb-share-list { display: flex; flex-direction: column; gap: 6px; }
.kb-share-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg-tertiary, var(--bg-primary)); }
.kb-share-name { flex: 1; font-size: 13px; font-weight: 600; }
.kb-share-role-pill { font-size: 11px; padding: 2px 8px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); text-transform: capitalize; }
.kb-share-remove { color: var(--text-muted); }
.kb-share-remove:hover { color: #ef4444; }

/* "Updated" toast */
.kb-update-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg-secondary); border: 1px solid var(--accent); border-radius: 999px; padding: 8px 16px; font-size: 13px; color: var(--text-primary); box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 10px; z-index: 90; }
.kb-update-toast button { background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }

/* Mobile */
@media (max-width: 900px) {
  .kb-rail { width: 240px; }
  .kb-main { padding: 18px 20px 0; }
}
@media (max-width: 720px) {
  .kb-rail-toggle { display: inline-flex; }
  .kb-rail { position: absolute; top: var(--header-h, 56px); left: 0; bottom: 0; width: min(85vw, 320px); z-index: 50; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 24px rgba(0,0,0,0.3); }
  .kb-rail.open { transform: translateX(0); }
  .kb-body { position: relative; }
  .kb-main { padding: 14px; }
  .kb-meta-row { font-size: 11px; }
  .kb-body-editor .ql-editor { padding: 14px 16px; min-height: 260px; font-size: 16px; }
  .kb-share-add { flex-direction: column; }
  .kb-share-role { flex: 1; }
  .kb-presence .avatar { width: 20px; height: 20px; }
  .kb-title { font-size: 14px; }
  .kb-header-actions .icon-btn { padding: 4px; }
}

/* ── Quill tables ─────────────────────────── */
.ql-table-embed { margin: 8px 0; overflow-x: auto; }
.ql-table-embed table { border-collapse: collapse; width: 100%; font-size: 14px; }
.ql-table-embed th, .ql-table-embed td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  min-width: 48px;
  vertical-align: top;
  color: var(--text-primary);
  background: var(--bg-secondary);
}
.ql-table-embed th { background: var(--bg-tertiary, var(--bg-primary)); font-weight: 600; text-align: left; }
.ql-table-embed td:focus, .ql-table-embed th:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Toolbar button icon centering */
.ql-toolbar button.ql-table svg { vertical-align: middle; }
/* Rendered messages */
.message-body .ql-table-embed { max-width: 100%; }

.msg-action-btn.flash { color: #16a34a; }

/* ── Send / upload overlay ────────────────── */
.send-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  border-radius: inherit;
}
.send-overlay-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 20px; min-width: 240px; max-width: 80%;
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.send-overlay-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  animation: send-spin 0.7s linear infinite;
}
@keyframes send-spin { to { transform: rotate(360deg); } }
.send-overlay-text { font-size: 13px; color: var(--text-primary); text-align: center; }
.send-overlay-bar {
  width: 220px; height: 6px; background: var(--bg-tertiary, var(--border));
  border-radius: 999px; overflow: hidden;
}
.send-overlay-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #22c55e);
  transition: width .15s ease;
}
.send-overlay-pct { font-size: 11px; color: var(--text-muted); }
.send-overlay.is-error .send-overlay-spinner { display: none; }
.send-overlay.is-error .send-overlay-text { color: #ef4444; }
.send-overlay.is-error .send-overlay-bar-fill { background: #ef4444; }

.send-btn.is-busy { opacity: 0.55; pointer-events: none; cursor: not-allowed; }

.msg-caption { margin-bottom: 6px; }
.msg-caption p:last-child { margin-bottom: 0; }

/* ════════════════════════════════════════════════
   UI Enhancement Layer — PHP port polish pass
   Refinements on top of the original theme: softer
   depth, smoother motion, better focus visibility.
   ════════════════════════════════════════════════ */

:root {
  --shadow-sm: 0 1px 4px rgba(0,0,0,.25);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.45);
  --accent-soft: rgba(88,101,242,.14);
}
html[data-theme="light"] {
  --shadow-sm: 0 1px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.14);
  --accent-soft: rgba(71,82,196,.10);
}

/* Smoother global motion */
.channel-item, .icon-btn, .btn, .msg-action-btn, .panel-tab-btn,
.kb-rail-item, .focus-rail-item, .user-chip, .act-btn, .reaction-btn {
  transition: background .14s ease, color .14s ease, border-color .14s ease,
              transform .12s ease, box-shadow .14s ease;
}

/* Visible keyboard focus everywhere */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [contenteditable]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

/* Buttons: subtle lift + press feedback */
.btn { box-shadow: var(--shadow-sm); }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background-image: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,0));
}

/* Sidebar: active channel gets an accent rail */
.channel-item { border-radius: 6px; margin: 1px 6px; position: relative; }
.channel-item.active::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.unread-badge { animation: crew-pop .18s ease; box-shadow: 0 0 0 2px var(--bg-secondary); }
@keyframes crew-pop {
  0% { transform: scale(.6); }
  80% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Messages: gentle entrance + hover affordance */
.message { border-radius: var(--radius); animation: crew-msg-in .16s ease; }
@keyframes crew-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.msg-actions { box-shadow: var(--shadow-sm); border-radius: var(--radius); }
.msg-action-btn:hover { transform: translateY(-1px); }

/* Reactions pill polish */
.reaction-btn { box-shadow: var(--shadow-sm); }
.reaction-btn:hover { transform: translateY(-1px); }
.reaction-btn.mine { background: var(--accent-soft); border-color: var(--accent); }

/* Header: subtle separation from the scroll area */
.chat-header { box-shadow: var(--shadow-sm); z-index: 5; }

/* Cards (focus journal, KB, profile, admin) */
.focus-card, .profile-card, .section, .auth-card {
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s ease;
}
.focus-card:hover, .profile-card:hover { box-shadow: var(--shadow); }

/* Modals: deeper shadow + fade-in */
.forward-modal-content, .checklist-modal-content, .kb-modal-content {
  box-shadow: var(--shadow-lg);
  animation: crew-modal-in .16s ease;
}
@keyframes crew-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* Inputs: soft accent glow when focused */
input[type="text"]:focus, input[type="password"]:focus,
input[type="email"]:focus, select:focus, textarea:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Scrollbars: slimmer, themed */
* { scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
*::-webkit-scrollbar-track { background: transparent; }

/* Progress bars animate width changes */
.checklist-progress-fill, .focus-progress-fill { transition: width .25s ease; }

/* Avatars: ring on hover in member lists */
.member-item .avatar, .kb-share-row .avatar { transition: box-shadow .15s ease; }
.member-item:hover .avatar { box-shadow: 0 0 0 2px var(--accent); }

/* Empty states breathe a little */
.empty-state svg, .kb-empty-card i { animation: crew-float 4s ease-in-out infinite; }
@keyframes crew-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* Admin FCM settings */
.fcm-form textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
}
.fcm-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fcm-form .form-group { margin-bottom: 14px; }

/* Reduced motion: respect user preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
