/* ================================================================
   HAMRO WORKPLACE — CHAT v2  (chat.css)
   Dark sidebar · Bubble messages · Slide-in panels · Animations
   ================================================================ */

/* ── Reset conflicting app.css chat rules ── */
.message-stream .bubble { background: none !important; border-radius: 0 !important; padding: 0 !important; font-size: inherit !important; line-height: inherit !important; }
.message-stream .mine .bubble,.message-stream article.mine .bubble { background: none !important; color: inherit !important; }
.message-stream article { max-width: none !important; margin: 0 !important; }
.message-stream article.mine { margin-left: 0 !important; }
.message-composer { flex-direction: column !important; align-items: stretch !important; gap: 0 !important; }
.chat-sidebar { border-right: none !important; background: #131320 !important; }

/* ── Override app.css light-mode sidebar rules (app.css has specificity up to 0,2,2) ── */
/* Active item: app.css forces #f0edff (near-white) background; text becomes invisible */
.chat-shell .chat-sidebar nav .chat-room-row.active { background: rgba(109,93,252,.25) !important; color: rgba(255,255,255,.95) !important; }
.chat-shell .chat-sidebar nav .chat-room-row { color: rgba(255,255,255,.65) !important; }
.chat-shell .chat-sidebar nav .chat-room-row:hover { color: rgba(255,255,255,.9) !important; background: rgba(255,255,255,.07) !important; }
/* Preview text and timestamps stay readable on dark sidebar regardless of --muted variable */
.chat-shell .chat-sidebar small { color: rgba(255,255,255,.38) !important; }
.chat-shell .chat-sidebar .room-row-time { color: rgba(255,255,255,.3) !important; }
/* Channel icons: app.css sets light #eef1f6 bg / #657187 text; keep dark sidebar variants */
.chat-shell .chat-sidebar .channel-icon { background: rgba(255,255,255,.08) !important; color: rgba(255,255,255,.5) !important; }
.chat-shell .chat-sidebar .channel-icon-group { background: rgba(109,93,252,.22) !important; color: #a78bfa !important; }
.chat-shell .chat-sidebar .channel-icon-dm { background: rgba(14,165,233,.2) !important; color: #7dd3fc !important; }
/* Active item channel icon gets a brighter tint */
.chat-shell .chat-sidebar nav .chat-room-row.active .channel-icon-group { background: rgba(109,93,252,.38) !important; color: #c4b5fd !important; }
.chat-shell .chat-sidebar nav .chat-room-row.active .channel-icon-dm { background: rgba(14,165,233,.3) !important; color: #bae6fd !important; }

/* ── Shell ── */
.chat-shell { border-radius: 18px; overflow: hidden; box-shadow: 0 1px 3px rgba(15,23,42,.08),0 8px 32px rgba(15,23,42,.04); }

/* ════════════════════════════════════════════════
   SIDEBAR
   ════════════════════════════════════════════════ */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #131320;
  border-right: none;
}

/* Sidebar header */
.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 10px;
  flex: none;
}
.chat-sidebar-header .eyebrow {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .12em;
  color: rgba(255,255,255,.3);
}
.chat-sidebar-header h1 {
  font-size: 16px;
  font-weight: 800;
  margin: 3px 0 0;
  line-height: 1.15;
  color: #fff;
}
.chat-sidebar-header .icon-btn {
  color: rgba(255,255,255,.5);
  background: rgba(255,255,255,.07);
  border-radius: 10px;
}
.chat-sidebar-header .icon-btn:hover { background: rgba(255,255,255,.13); color: #fff; }

/* Search */
.chat-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: rgba(255,255,255,.06);
  border: 1.5px solid transparent;
  border-radius: 11px;
  margin: 0 12px 6px;
  flex: none;
  transition: background .15s, border-color .15s;
}
.chat-search:focus-within { background: rgba(255,255,255,.09); border-color: rgba(109,93,252,.55); }
.chat-search svg { width: 12px; height: 12px; color: rgba(255,255,255,.3); flex: none; }
.chat-search input { flex: 1; background: none; border: none; outline: none; font-size: 12px; color: rgba(255,255,255,.8); padding: 8px 0; font-family: inherit; }
.chat-search input::placeholder { color: rgba(255,255,255,.28); }
.chat-search.wide { background: rgba(0,0,0,.04); border-color: var(--line); margin: 8px 16px; }
.chat-search.wide svg { color: var(--muted); }
.chat-search.wide input { color: var(--ink); }
.chat-search.wide input::placeholder { color: var(--muted); }

/* Section label */
.chat-section-label {
  padding: 14px 16px 4px;
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: .1em;
  color: rgba(255,255,255,.28);
  text-transform: uppercase;
}

/* Room nav */
nav[data-chat-room-list] { overflow-y: auto; flex: 1; padding: 2px 8px 20px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.1) transparent; }
nav[data-chat-room-list]::-webkit-scrollbar { width: 3px; }
nav[data-chat-room-list]::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

/* Room rows */
.chat-room-row {
  display: grid;
  grid-template-columns: 36px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 11px;
  text-decoration: none;
  color: rgba(255,255,255,.6);
  transition: background .12s, color .12s;
  margin-bottom: 1px;
  position: relative;
}
.chat-room-row:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.88); }
.chat-room-row:focus-visible { outline: 2px solid rgba(109,93,252,.8); outline-offset: -2px; border-radius: 10px; }
.chat-room-row.active { background: rgba(109,93,252,.22); color: #c4b5fd; }
.chat-room-row.active:hover { background: rgba(109,93,252,.27); }
.room-row-body { min-width: 0; }
.room-row-body strong { display: block; font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: inherit; }
.room-row-body small { display: block; font-size: 10px; color: rgba(255,255,255,.32); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.chat-room-row.active .room-row-body small { color: rgba(196,181,253,.52); }
.room-row-time { font-size: 9.5px; color: rgba(255,255,255,.28); flex: none; white-space: nowrap; }
.room-unread-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--purple); color: #fff;
  font-size: 9px; font-weight: 900; display: grid; place-items: center; flex: none;
  box-shadow: 0 2px 8px rgba(109,93,252,.45);
  animation: badge-pop .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes badge-pop { from { transform: scale(0) } to { transform: scale(1) } }

/* Channel icons (dark sidebar variant) */
.channel-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.channel-icon svg { width: 15px; height: 15px; }
.channel-icon-group { background: rgba(109,93,252,.2); color: #a78bfa; }
.channel-icon-dm { background: rgba(14,165,233,.18); color: #7dd3fc; }
.chat-room-row.active .channel-icon-group { background: rgba(109,93,252,.35); color: #c4b5fd; }
.chat-room-row.active .channel-icon-dm { background: rgba(14,165,233,.3); color: #bae6fd; }

/* Empty mini */
.empty-mini { display: flex; align-items: center; gap: 8px; padding: 16px 10px; font-size: 11px; color: rgba(255,255,255,.3); }
.empty-mini svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ════════════════════════════════════════════════
   MAIN HEADER
   ════════════════════════════════════════════════ */
.chat-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
  min-height: 62px;
  z-index: 5;
}
.chat-room-identity { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.chat-room-identity .channel-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: #edeaff; color: #6d5dfc; flex: none;
}
.chat-room-identity .channel-icon-dm { background: #e0f2fe; color: #0284c7; }
.chat-room-identity > div { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.chat-room-identity h2 { font-size: 15px; font-weight: 800; margin: 0; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.chat-room-identity p { font-size: 10.5px; color: var(--muted); margin: 2px 0 0; white-space: nowrap; }
.chat-main-header .header-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.header-actions .icon-btn.panel-active { background: rgba(109,93,252,.12); color: var(--purple); }

/* ════════════════════════════════════════════════
   DATE SEPARATOR
   ════════════════════════════════════════════════ */
.date-sep { position: relative; display: flex; align-items: center; margin: 22px 18px 14px; }
.date-sep::before,.date-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.date-sep span {
  padding: 3px 14px; font-size: 10px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px;
}

/* ════════════════════════════════════════════════
   MESSAGES
   ════════════════════════════════════════════════ */
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message-stream { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.message-stream::-webkit-scrollbar { width: 5px; }
.message-stream::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.message-stream::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

.message-stream article {
  display: flex;
  gap: 10px;
  padding: 4px 16px;
  position: relative;
  border-radius: 10px;
  transition: background .1s;
  animation: msg-in .18s ease both;
}
.message-stream article:hover { background: rgba(0,0,0,.022); }
.message-stream article:hover .msg-actions { opacity: 1; pointer-events: auto; }
.message-stream article.is-pinned { background: rgba(245,158,11,.05); border-left: 2px solid #f59e0b; }
.message-stream article.is-deleted .bubble-card { opacity: .6; }

/* Mine → right side */
.message-stream article.mine { flex-direction: row-reverse; }
.message-stream article.mine .msg-content { align-items: flex-end; }
.message-stream article.mine header { flex-direction: row-reverse; }

/* Grouping */
.message-stream article.grouped { padding-top: 2px; }
.message-stream article.grouped > .avatar { visibility: hidden; }
.message-stream article.grouped header { display: none; }
.message-stream article.grouped .bubble-card { border-radius: 8px 16px 16px 16px; }
.message-stream article.grouped.mine .bubble-card { border-radius: 16px 8px 16px 16px; }

/* Content column */
.msg-content { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; max-width: calc(100% - 50px); }
.message-stream article.mine .msg-content { align-items: flex-end; }

/* Message header */
.message-stream header { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; margin-bottom: 4px; }
.message-stream header strong { font-size: 12px; font-weight: 700; color: var(--ink); }
.message-stream header time { font-size: 10px; color: var(--muted); cursor: default; }
.pin-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 9px; font-weight: 700; color: #c77a06; background: #fff3dc; padding: 2px 7px 2px 5px; border-radius: 999px; white-space: nowrap; }
.pin-badge svg { width: 10px; height: 10px; }
.msg-edited-label { font-size: 9px; color: var(--muted); font-style: italic; }

/* Bubble wrapper — just a flex column */
.bubble { display: flex; flex-direction: column; gap: 6px; max-width: 480px; position: relative; }
.message-stream article.mine .bubble { align-items: flex-end; }

/* THEIRS bubble card */
.bubble-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(15,23,42,.06);
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 100%;
}

/* MINE bubble card */
.message-stream article.mine .bubble-card {
  background: linear-gradient(135deg, #6d5dfc 0%, #8b5cf6 100%);
  border-color: transparent;
  border-radius: 16px 4px 16px 16px;
  box-shadow: 0 4px 16px rgba(109,93,252,.28);
}

/* Message body text */
.chat-message-body { font-size: 13px; line-height: 1.6; word-break: break-word; color: var(--ink); }
.chat-message-body a { color: var(--purple); text-decoration: underline; text-underline-offset: 2px; }
.message-stream article.mine .chat-message-body { color: #fff; }
.message-stream article.mine .chat-message-body a { color: rgba(255,255,255,.82); }

/* Reply quote inside bubble-card */
.reply-quote {
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 10px;
  border-left: 3px solid var(--purple); border-radius: 0 8px 8px 0;
  background: rgba(109,93,252,.07); cursor: pointer; max-width: 440px;
}
.reply-quote strong { font-size: 10px; font-weight: 800; color: var(--purple); }
.reply-quote span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-quote:hover { background: rgba(109,93,252,.13); }
.message-stream article.mine .reply-quote { border-left: none; border-right: 3px solid rgba(255,255,255,.45); border-radius: 8px 0 0 8px; background: rgba(255,255,255,.15); }
.message-stream article.mine .reply-quote strong { color: rgba(255,255,255,.9); }
.message-stream article.mine .reply-quote span { color: rgba(255,255,255,.6); }

/* Deleted placeholder */
.deleted-placeholder { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); font-style: italic; padding: 9px 14px; border-radius: 12px; border: 1px dashed var(--line); background: var(--bg); }
.deleted-placeholder svg { width: 13px; color: var(--muted); }

/* Attachment */
.chat-attachment { display: inline-flex; align-items: center; gap: 9px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,.03); font-size: 12px; color: var(--ink); text-decoration: none; max-width: 260px; transition: border-color .15s, transform .12s; }
.chat-attachment:hover { border-color: var(--purple); transform: translateY(-1px); }
.chat-attachment svg { width: 16px; flex: none; color: var(--purple); }
.chat-attachment span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-attachment.is-image { flex-direction: column; align-items: flex-start; padding: 0; border: none; background: none; }
.chat-attachment.is-image img { border-radius: 12px; max-width: 300px; max-height: 230px; display: block; cursor: zoom-in; box-shadow: 0 4px 16px rgba(15,23,42,.12); }
.chat-attachment.is-image span { padding: 5px 2px 0; font-size: 10px; color: var(--muted); }
.message-stream article.mine .chat-attachment { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }
.message-stream article.mine .chat-attachment svg { color: rgba(255,255,255,.8); }
.message-stream article.mine .chat-attachment:hover { border-color: rgba(255,255,255,.5); }

/* Reactions */
.reaction-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.reaction-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px 3px 7px; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--line); font-size: 14px; cursor: pointer; transition: all .12s; line-height: 1; box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.reaction-pill span { font-size: 11px; font-weight: 700; color: var(--ink); }
.reaction-pill:hover { background: #edeaff; border-color: var(--purple); transform: scale(1.05); }
.reaction-pill.reacted { background: #edeaff; border-color: var(--purple); }
.reaction-pill.reacted span { color: var(--purple); }

/* Hover action bar */
.msg-actions {
  position: absolute; top: -14px; right: 0;
  display: flex; gap: 2px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px;
  box-shadow: 0 8px 24px rgba(15,23,42,.12);
  opacity: 0; pointer-events: none;
  transition: opacity .12s, transform .12s;
  transform: translateY(4px);
  z-index: 10;
}
.message-stream article:hover .msg-actions { opacity: 1; pointer-events: auto; transform: translateY(0); }
.message-stream article.mine .msg-actions { right: auto; left: 0; }
.msg-action-btn { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; background: none; border: none; cursor: pointer; color: var(--muted); transition: all .1s; }
.msg-action-btn:hover { background: #edeaff; color: var(--purple); }
.msg-action-btn:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.msg-action-btn svg { width: 13px; height: 13px; }
.msg-action-danger:hover { background: #fff0f0; color: #ef4444; }

/* ════════════════════════════════════════════════
   TYPING INDICATOR
   ════════════════════════════════════════════════ */
.chat-typing-bar { padding: 4px 22px 4px; font-size: 11px; color: var(--muted); font-style: italic; flex: none; min-height: 26px; display: flex; align-items: center; gap: 8px; }
.chat-typing-dots { display: flex; gap: 4px; align-items: center; }
.chat-typing-dots span { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: typing-bounce .9s ease-in-out infinite; }
.chat-typing-dots span:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce { 0%,80%,100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-5px); opacity: 1; } }

/* ════════════════════════════════════════════════
   REPLY PREVIEW STRIP
   ════════════════════════════════════════════════ */
.chat-reply-preview { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 18px; border-top: 1px solid var(--line); background: rgba(109,93,252,.04); flex: none; }
.reply-preview-inner { display: flex; align-items: center; gap: 9px; min-width: 0; }
.reply-preview-inner > svg { width: 14px; color: var(--purple); flex: none; }
.reply-preview-inner > div { min-width: 0; display: flex; flex-direction: column; }
.reply-preview-inner strong { font-size: 11px; font-weight: 700; color: var(--purple); }
.reply-preview-inner span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ════════════════════════════════════════════════
   EMOJI PICKER
   ════════════════════════════════════════════════ */
.emoji-picker {
  position: fixed; z-index: 9999;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 20px 56px rgba(15,23,42,.18);
  padding: 12px; width: 310px;
  animation: ep-in .15s cubic-bezier(.34,1.56,.64,1);
}
@keyframes ep-in { from { opacity:0; transform:scale(.92) translateY(6px) } to { opacity:1; transform:scale(1) translateY(0) } }
.emoji-picker-search {
  width: 100%; box-sizing: border-box;
  padding: 7px 12px; border: 1.5px solid var(--line);
  border-radius: 10px; font-size: 12px; color: var(--ink);
  background: var(--bg); outline: none;
  margin-bottom: 8px; font-family: inherit;
  transition: border-color .15s;
}
.emoji-picker-search:focus { border-color: var(--purple); }
.emoji-picker-cats { display: flex; gap: 2px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.emoji-picker-cats::-webkit-scrollbar { display: none; }
.emoji-cat-btn { padding: 4px 10px; border-radius: 8px; border: none; background: none; font-size: 16px; cursor: pointer; transition: background .1s; flex: none; }
.emoji-cat-btn:hover,.emoji-cat-btn.active { background: #edeaff; }
.emoji-cat-btn:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.emoji-picker-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 200px; overflow-y: auto; scrollbar-width: thin; }
.emoji-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; border: none; background: none; font-size: 18px; cursor: pointer; transition: background .1s, transform .1s; line-height: 1; }
.emoji-btn:hover { background: #edeaff; transform: scale(1.1); }
.emoji-btn:focus-visible { outline: 2px solid var(--purple); outline-offset: 1px; }
.emoji-btn[hidden] { display: none; }

/* ════════════════════════════════════════════════
   COMPOSER
   ════════════════════════════════════════════════ */
.message-composer { flex: none; display: flex !important; flex-direction: column !important; align-items: stretch !important; gap: 0; padding: 10px 16px 14px; background: var(--surface); }
.composer-errors { padding: 8px 12px; border-radius: 10px; background: #fff5f5; color: #c53030; font-size: 11.5px; border-left: 3px solid #ef4444; margin-bottom: 8px; }
.composer-body { display: flex; flex-direction: column; gap: 0; }
.composer-outer {
  border: 1.5px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color .18s, box-shadow .18s;
}
.composer-outer:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,93,252,.1); }
.attachment-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: rgba(109,93,252,.04);
}
.attachment-preview img { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex: none; }
.attachment-preview > span { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.attachment-preview strong { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.attachment-preview small { font-size: 10px; color: var(--muted); margin-top: 1px; }
.attachment-preview .icon-btn { flex: none; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px 8px 14px; }
.composer-attach { flex: none; width: 30px; height: 30px; margin-bottom: 2px; position: relative; color: var(--muted); transition: color .12s; }
.composer-attach:hover { color: var(--purple); }
.composer-attach input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.composer-emoji-btn { flex: none; width: 30px; height: 30px; margin-bottom: 2px; color: var(--muted); transition: color .12s; }
.composer-emoji-btn:hover { color: var(--purple); }
.composer-emoji-btn:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; border-radius: 6px; }
.composer-emoji-btn svg { width: 16px; height: 16px; }
.message-composer textarea,.composer-row textarea {
  flex: 1; border: none !important; outline: none !important; box-shadow: none !important;
  background: transparent; resize: none;
  font-size: 13.5px; color: var(--ink); padding: 4px 0;
  min-height: 38px; max-height: 160px;
  font-family: inherit; line-height: 1.55; overflow-y: hidden;
}
.message-composer textarea::placeholder { color: var(--muted); }
.composer-send {
  flex: none; width: 36px; height: 36px; padding: 0;
  display: grid; place-items: center; border-radius: 12px;
  margin-bottom: 1px;
  background: linear-gradient(135deg, #6d5dfc, #8b5cf6) !important;
  color: #fff !important;
  border: none;
  box-shadow: 0 4px 14px rgba(109,93,252,.32);
  transition: transform .15s, box-shadow .15s;
}
.composer-send:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(109,93,252,.42); }
.composer-send:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.composer-send:active { transform: scale(.94); }
.composer-send svg { width: 15px; height: 15px; color: #fff !important; }
.composer-send[disabled] { opacity: .55; pointer-events: none; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; padding: 5px 4px 0; }
.composer-hint { font-size: 9.5px; color: var(--muted); line-height: 1.4; }
.composer-hint kbd { display: inline-block; padding: 1px 5px; border-radius: 4px; background: var(--bg); color: #475569; border: 1px solid var(--line); font-family: inherit; font-size: 9px; }

/* ════════════════════════════════════════════════
   DRAG-AND-DROP ZONE
   ════════════════════════════════════════════════ */
.chat-drop-zone {
  position: absolute; inset: 62px 0 0;
  z-index: 50; background: rgba(109,93,252,.08);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  border: 2.5px dashed var(--purple);
  border-radius: 0 0 16px 16px;
  pointer-events: none;
  opacity: 0; transition: opacity .2s;
}
.chat-drop-zone.active { opacity: 1; pointer-events: all; }
.chat-drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 40px; background: var(--surface); border-radius: 20px; box-shadow: 0 16px 48px rgba(15,23,42,.14); text-align: center; }
.chat-drop-inner svg { width: 44px; height: 44px; color: var(--purple); }
.chat-drop-inner > span { font-size: 16px; font-weight: 800; color: var(--ink); }
.chat-drop-inner > small { font-size: 11px; color: var(--muted); }

/* ════════════════════════════════════════════════
   TOOLS PANEL (message search)
   ════════════════════════════════════════════════ */
.chat-tools-panel {
  display: block !important;
  overflow: hidden;
  max-height: 0;
  transition: max-height .2s ease, padding .2s;
  padding: 0 16px; border-bottom: 0;
  background: var(--bg);
  flex: none;
}
.chat-tools-panel:not([hidden]) { max-height: 60px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
/* This panel collapses via max-height rather than display, so it must stay
   laid out while hidden. Opts out of the global [hidden] guard in
   responsive.css; safe because max-height:0 + overflow:hidden give it zero
   height and no hit area. */
.chat-tools-panel[hidden] { display: block !important; }

/* ════════════════════════════════════════════════
   MEMBER PANEL (slide-in from right)
   ════════════════════════════════════════════════ */
[data-chat-member-panel] {
  display: flex !important;
  flex-direction: column;
  position: absolute;
  top: 62px; right: 0; bottom: 0;
  width: 268px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 20;
  transform: translateX(105%);
  transition: transform .25s cubic-bezier(.34,1.56,.64,1);
  overflow: hidden;
}
[data-chat-member-panel]:not([hidden]) { transform: translateX(0); }
.chat-member-list { flex: 1; overflow-y: auto; padding: 8px 12px 12px; scrollbar-width: thin; }
.chat-member-list .eyebrow { display: block; font-size: 9.5px; font-weight: 900; letter-spacing: .09em; color: var(--muted); text-transform: uppercase; padding: 8px 4px 10px; }
.chat-member-list article { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; transition: background .1s; }
.chat-member-list article:hover { background: rgba(109,93,252,.05); }
.chat-member-list article > span.member-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-member-list article strong { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.chat-member-list article small { font-size: 10px; color: var(--muted); }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; flex: none; border: 2px solid var(--surface); box-shadow: 0 0 0 1px rgba(34,197,94,.3); }
.online-dot.offline { background: #cbd5e1; box-shadow: none; }
.chat-member-add { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; flex: none; }
.chat-member-add-label { font-size: 10px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chat-member-select { width: 100%; box-sizing: border-box; border: 1.5px solid var(--line); border-radius: 10px; padding: 6px; font-size: 11px; min-height: 88px; background: var(--surface); color: var(--ink); outline: none; transition: border-color .15s; }
.chat-member-select:focus { border-color: var(--purple); }
.chat-member-note { font-size: 11px; color: var(--muted); padding: 14px; line-height: 1.55; text-align: center; flex: 1; display: flex; align-items: center; justify-content: center; }
.icon-btn-danger:hover { color: #ef4444 !important; }

/* ════════════════════════════════════════════════
   IMAGE LIGHTBOX
   ════════════════════════════════════════════════ */
.img-lightbox-overlay { position: fixed; inset: 0; z-index: 10000; background: rgba(0,0,0,.88); display: grid; place-items: center; cursor: zoom-out; animation: lb-in .15s ease; }
.img-lightbox-overlay img { max-width: min(90vw,1200px); max-height: 90vh; border-radius: 10px; box-shadow: 0 24px 60px rgba(0,0,0,.5); object-fit: contain; }
@keyframes lb-in { from { opacity:0; transform:scale(.94) } to { opacity:1; transform:scale(1) } }

/* ════════════════════════════════════════════════
   EMPTY STATES
   ════════════════════════════════════════════════ */
.chat-empty,.chat-start-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 40px 24px; }
.chat-empty svg,.chat-start-state svg { width: 56px; height: 56px; color: var(--purple); opacity: .2; }
.chat-empty h3,.chat-start-state h3 { font-size: 17px; font-weight: 800; color: var(--ink); margin: 0; }
.chat-empty p,.chat-start-state p { font-size: 12px; color: var(--muted); max-width: 280px; margin: 0; line-height: 1.65; }
.chat-start-state .btn { margin-top: 6px; }

/* ════════════════════════════════════════════════
   SCROLL-TO-BOTTOM PILL
   ════════════════════════════════════════════════ */
.chat-new-message-pill {
  position: absolute; left: 50%; bottom: 80px; z-index: 6;
  transform: translateX(-50%);
  min-height: 34px; padding: 0 16px;
  border: 0; border-radius: 999px;
  background: linear-gradient(135deg, #6d5dfc, #3b82f6);
  color: #fff;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 9px; font-weight: 900;
  box-shadow: 0 8px 24px rgba(59,130,246,.3);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  animation: pill-in .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pill-in { from { opacity:0; transform:translateX(-50%) translateY(10px) } to { opacity:1; transform:translateX(-50%) translateY(0) } }
.chat-new-message-pill[hidden] { display: none; }
.chat-new-message-pill svg { width: 13px; }
.chat-new-message-pill:hover { transform: translateX(-50%) translateY(-2px); box-shadow: 0 12px 30px rgba(59,130,246,.38); }

/* ════════════════════════════════════════════════
   DARK MODE
   ════════════════════════════════════════════════ */
html[data-theme-mode="dark"] .chat-sidebar { background: #0d0d1a; }
html[data-theme-mode="dark"] .chat-room-row:hover { background: rgba(255,255,255,.05); }
html[data-theme-mode="dark"] .chat-room-row.active { background: rgba(109,93,252,.2); }
html[data-theme-mode="dark"] .channel-icon-group { background: rgba(109,93,252,.22); color: #a78bfa; }
html[data-theme-mode="dark"] .channel-icon-dm { background: rgba(14,165,233,.18); color: #7dd3fc; }
html[data-theme-mode="dark"] .chat-room-identity .channel-icon-group { background: #252058; color: #c4b5fd; }
html[data-theme-mode="dark"] .chat-room-identity .channel-icon-dm { background: #082f49; color: #7dd3fc; }
html[data-theme-mode="dark"] .message-stream article:hover { background: rgba(255,255,255,.03); }
html[data-theme-mode="dark"] .bubble-card { background: #1e293b; border-color: #263145; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
html[data-theme-mode="dark"] .message-stream article.mine .bubble-card { background: linear-gradient(135deg,#6d5dfc,#7c3aed); border-color: transparent; }
html[data-theme-mode="dark"] .pin-badge { background: #422006; color: #fbbf24; }
html[data-theme-mode="dark"] .reply-quote { background: rgba(109,93,252,.12); }
html[data-theme-mode="dark"] .date-sep span { background: #111827; border-color: #263145; }
html[data-theme-mode="dark"] .chat-attachment { background: rgba(255,255,255,.06); border-color: #334155; }
html[data-theme-mode="dark"] .deleted-placeholder { background: #0f172a; border-color: #334155; }
html[data-theme-mode="dark"] .reaction-pill { background: #1e293b; border-color: #334155; }
html[data-theme-mode="dark"] .reaction-pill span { color: #e2e8f0; }
html[data-theme-mode="dark"] .reaction-pill:hover { background: #252058; border-color: var(--purple); }
html[data-theme-mode="dark"] .reaction-pill.reacted { background: #252058; border-color: var(--purple); }
html[data-theme-mode="dark"] .reaction-pill.reacted span { color: #c4b5fd; }
html[data-theme-mode="dark"] .msg-actions { background: #1e293b; border-color: #334155; }
html[data-theme-mode="dark"] .msg-action-btn:hover { background: #252058; color: #c4b5fd; }
html[data-theme-mode="dark"] .emoji-picker { background: #1e293b; border-color: #334155; }
html[data-theme-mode="dark"] .emoji-picker-search { background: #0f172a; border-color: #334155; color: #e5e7eb; }
html[data-theme-mode="dark"] .emoji-btn:hover { background: #252058; }
html[data-theme-mode="dark"] .emoji-cat-btn:hover,
html[data-theme-mode="dark"] .emoji-cat-btn.active { background: #252058; }
html[data-theme-mode="dark"] .composer-outer { background: #0f172a; border-color: #263145; }
html[data-theme-mode="dark"] .attachment-preview { background: rgba(109,93,252,.08); border-color: #263145; }
html[data-theme-mode="dark"] .composer-errors { background: #3f1d1d; color: #fca5a5; border-color: #dc2626; }
html[data-theme-mode="dark"] .composer-hint kbd { background: #1e293b; color: #94a3b8; border-color: #334155; }
html[data-theme-mode="dark"] .chat-reply-preview { background: rgba(109,93,252,.08); }
html[data-theme-mode="dark"] .chat-member-select { background: #0f172a; border-color: #263145; color: #e5e7eb; }
html[data-theme-mode="dark"] .online-dot { border-color: #1e293b; }
html[data-theme-mode="dark"] .chat-drop-zone { background: rgba(109,93,252,.14); }
html[data-theme-mode="dark"] .chat-drop-inner { background: #1e293b; }
html[data-theme-mode="dark"] .chat-tools-panel { background: #0f172a; }

/* ════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════ */

/* Back-to-rooms button: hidden by default, shown only on mobile */
.chat-back-to-rooms { display: none; flex: none; color: var(--muted); }

/* ── Narrow tablet (769–1024px): tighten sidebar so chat area breathes ── */
@media (max-width: 1024px) and (min-width: 769px) {
  .chat-shell { grid-template-columns: 200px 1fr; }
}

/* ── Compact (≤ 900px): drop timestamps to save horizontal space ── */
@media (max-width: 900px) {
  .room-row-time { display: none; }
}

/* ── Mobile (≤ 768px): single-panel layout ─────────────────────────────
   The shell switches between showing EITHER the room list (sidebar) OR the
   chat area (main), driven by the `has-room` class on .chat-shell.
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Shell: switch from grid to flex column, fill the viewport below the topbar */
  .chat-shell {
    display: flex !important;
    flex-direction: column;
    height: calc(100vh - 105px); /* 65px topbar + 40px content-area padding */
    min-height: 360px;
    overflow: hidden;
    border-radius: 12px;
  }

  /* ── No room selected: show sidebar (room list) full-screen ── */
  .chat-shell:not(.has-room) .chat-sidebar {
    flex: 1;
    height: auto;
    min-height: 0;
    border-bottom: none;
    overflow: hidden;
  }
  .chat-shell:not(.has-room) .chat-main { display: none; }

  /* ── Room open: hide sidebar, main fills screen ── */
  .chat-shell.has-room .chat-sidebar { display: none; }
  .chat-shell.has-room .chat-main {
    flex: 1 !important;
    height: auto !important;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Message stream is the only scrolling region inside the flex column */
  .message-stream {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  /* Composer: fixed at bottom, no scrolling */
  .message-composer { padding: 6px 10px 10px; flex: none; }
  .composer-hint { display: none; }

  /* Header: compact */
  .chat-main-header { padding: 8px 12px; min-height: 52px; }
  .chat-room-identity .channel-icon { width: 32px; height: 32px; border-radius: 9px; }

  /* Messages: narrow padding on phone */
  .message-stream article { padding: 4px 10px; }
  .msg-actions { right: 6px; }
  .bubble { max-width: calc(100vw - 80px); }

  /* Panels that sit inside chat-main */
  [data-chat-member-panel] { width: 100%; top: 52px; }
  .chat-drop-zone { inset: 52px 0 0; }

  /* Back button: visible on mobile */
  .chat-back-to-rooms { display: flex !important; }
}

/* ── Poll composer panel ───────────────────────────────────────────────── */
.poll-composer-panel {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.poll-composer-inner { display: flex; flex-direction: column; gap: 10px; }
.poll-composer-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 800; color: var(--ink);
}
.poll-composer-head span { display: flex; align-items: center; gap: 6px; }
.poll-composer-head svg { width: 14px; height: 14px; color: var(--purple); }
.poll-question-input,
.poll-option-input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 12px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
.poll-question-input { font-weight: 700; }
.poll-question-input:focus,
.poll-option-input:focus { border-color: var(--purple); }
.poll-options-list { display: flex; flex-direction: column; gap: 6px; }
.poll-add-option-btn { align-self: flex-start; font-size: 11px; padding: 5px 12px; min-height: 30px; }
.poll-send-btn { align-self: flex-end; }
.poll-composer-error { font-size: 11px; color: #dc2626; font-weight: 700; padding: 4px 0; }

/* ── Poll card in message stream ───────────────────────────────────────── */
.chat-poll-card {
  min-width: 260px; max-width: 360px;
  background: linear-gradient(135deg, #faf5ff, #ede9fe);
  border: 1px solid rgba(109,93,252,.18);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.poll-type-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 9px; font-weight: 900; letter-spacing: .08em;
  text-transform: uppercase; color: var(--purple);
}
.poll-type-label svg { width: 11px; height: 11px; }
.poll-question {
  font-size: 13px; font-weight: 800; color: var(--ink); line-height: 1.4;
}
.poll-options { display: flex; flex-direction: column; gap: 6px; }
.poll-option {
  position: relative; display: flex; align-items: center;
  gap: 8px; padding: 8px 12px;
  border: 1px solid rgba(109,93,252,.2); border-radius: 10px;
  background: rgba(255,255,255,.7); cursor: pointer;
  text-align: left; font-size: 11px; font-weight: 700; color: var(--ink);
  transition: border-color .15s, background .15s, transform .1s;
  overflow: hidden;
}
.poll-option:hover:not(.closed) { border-color: var(--purple); background: rgba(109,93,252,.06); transform: translateX(2px); }
.poll-option.my-vote { border-color: var(--purple); background: rgba(109,93,252,.1); }
.poll-option.closed { cursor: default; }
.poll-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--pct, 0%); background: rgba(109,93,252,.12);
  border-radius: 9px 0 0 9px; pointer-events: none;
  transition: width .4s ease;
}
.poll-option.my-vote .poll-bar { background: rgba(109,93,252,.22); }
.poll-opt-text { position: relative; flex: 1; }
.poll-opt-tally { position: relative; font-size: 10px; font-weight: 900; color: var(--purple); white-space: nowrap; }
.poll-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; font-weight: 700; color: var(--muted);
}
.poll-closed-pill {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  background: rgba(100,116,139,.1); color: #64748b;
  font-size: 9px; font-weight: 900;
}

/* dark mode */
html[data-theme-mode="dark"] .chat-poll-card { background: rgba(109,93,252,.1); border-color: rgba(109,93,252,.25); }
html[data-theme-mode="dark"] .poll-option { background: rgba(255,255,255,.05); border-color: rgba(109,93,252,.2); }
html[data-theme-mode="dark"] .poll-option.my-vote { background: rgba(109,93,252,.2); }
