
/* ---------- THEME TOKENS ---------- */
:root,
[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --bg-soft: #f0f2f7;
  --bg-hover: #eaeef5;
  --border: #e3e7ee;
  --border-strong: #d1d6df;
  --text: #1a1f2e;
  --text-muted: #6b7280;
  --text-soft: #4b5563;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.06);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);
  --bubble-mine-bg: #4f46e5;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #ffffff;
  --bubble-other-fg: #1a1f2e;
  --bubble-other-border: #e3e7ee;
}
[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elev: #1a1d24;
  --bg-soft: #15181f;
  --bg-hover: #232733;
  --border: #2a2f3a;
  --border-strong: #3a4150;
  --text: #e6e8ee;
  --text-muted: #8b93a6;
  --text-soft: #b6bdcd;
  --primary: #818cf8;
  --primary-hover: #a5afff;
  --primary-soft: #1e2236;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
  --bubble-mine-bg: #4f46e5;
  --bubble-mine-fg: #ffffff;
  --bubble-other-bg: #232733;
  --bubble-other-fg: #e6e8ee;
  --bubble-other-border: #2a2f3a;
}

/* ---------- BASE ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.block { display: block; width: 100%; }
.block-label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; color: var(--text-soft); }

/* ---------- FLASH ---------- */
.flash {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 8px; z-index: 9999;
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500;
  animation: flashIn .2s ease-out, flashOut .3s ease-in 4s forwards;
}
.flash-success { background: var(--success); color: #fff; }
.flash-error   { background: var(--danger);  color: #fff; }
@keyframes flashIn { from { opacity:0; transform: translate(-50%, -8px); } to { opacity:1; transform: translate(-50%, 0);} }
@keyframes flashOut { to { opacity:0; } }

/* ---------- AUTH ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg); position: relative;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--bg-elev);
  border-radius: 16px; padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white; font-weight: 800; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-form label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.auth-form input {
  display: block; width: 100%; margin-top: 6px; padding: 11px 14px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg-soft); color: var(--text); font-size: 15px;
}
.auth-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.auth-form input:disabled { color: var(--text-muted); }
.auth-foot { text-align: center; margin: 20px 0 0; font-size: 13px; }
.alert-inline { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-inline.error { background: rgba(220,38,38,.1); color: var(--danger); border: 1px solid rgba(220,38,38,.25); }
.theme-toggle-floating {
  position: absolute; top: 20px; right: 20px;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 18px;
}

/* ---------- BUTTONS ---------- */
.btn-primary {
  padding: 11px 18px; border-radius: 10px; border: none;
  background: var(--primary); color: white; font-weight: 600; font-size: 15px;
  cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary.block { width: 100%; }
.btn-secondary {
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-weight: 500; font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-secondary.block { width: 100%; margin-bottom: 6px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 14px; padding: 0; }
.btn-link.danger { color: var(--danger); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: transparent; color: var(--text); cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); }

/* ---------- APP SHELL ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 320px; min-width: 320px; height: 100%;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-muted); margin-top: -2px; }
.head-actions { display: flex; gap: 4px; position: relative; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 240px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 6px;
  display: none; z-index: 100;
}
.dropdown-menu.open { display: block; }
.dropdown-head { display: flex; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-item {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 6px;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  font-size: 14px; text-decoration: none;
}
.dropdown-item:hover { background: var(--bg-hover); text-decoration: none; }

.sidebar-actions { padding: 12px 12px 6px; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-item {
  display: flex; gap: 10px; padding: 9px 10px; border-radius: 9px;
  cursor: pointer; transition: background .12s;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--primary-soft); }
.conv-avatar {
  width: 38px; height: 38px; border-radius: 9px;
  color: white; font-weight: 700; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.conv-meta { flex: 1; min-width: 0; }
.conv-title-row { display: flex; justify-content: space-between; align-items: baseline; }
.conv-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-badge {
  background: var(--primary); color: white; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 10px; min-width: 20px; text-align: center;
}
.empty-hint { text-align: center; color: var(--text-muted); font-size: 13px; padding: 30px 12px; line-height: 1.6; }

/* ---------- CHAT PANE ---------- */
.chat-pane {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg); min-width: 0; height: 100%;
}
.chat-head {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev); display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.chat-head-title { font-weight: 700; font-size: 16px; }
.chat-head-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg-row { display: flex; gap: 10px; max-width: 80%; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 9px;
  color: white; font-weight: 700; flex-shrink: 0; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.msg-bubble {
  background: var(--bubble-other-bg); color: var(--bubble-other-fg);
  border: 1px solid var(--bubble-other-border);
  padding: 9px 13px; border-radius: 14px; max-width: 100%;
  box-shadow: 0 1px 1px rgba(0,0,0,.03);
}
.msg-row.mine .msg-bubble {
  background: var(--bubble-mine-bg); color: var(--bubble-mine-fg);
  border-color: transparent;
}
.msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.msg-row.mine .msg-meta { text-align: right; }
.msg-body { font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg-body .mention { background: rgba(99,102,241,.18); color: var(--primary); padding: 1px 5px; border-radius: 4px; font-weight: 600; }
.msg-row.mine .msg-body .mention { background: rgba(255,255,255,.22); color: white; }
.msg-edited { font-size: 11px; opacity: .7; margin-left: 4px; }

.msg-attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.attach-image { max-width: 320px; max-height: 240px; border-radius: 8px; cursor: pointer; display: block; }
.attach-file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  background: rgba(0,0,0,.06); color: inherit; text-decoration: none;
  font-size: 13px;
}
.msg-row.mine .attach-file { background: rgba(255,255,255,.15); color: white; }
.attach-file:hover { text-decoration: none; opacity: .9; }
.attach-icon {
  width: 32px; height: 32px; border-radius: 6px;
  background: rgba(0,0,0,.1); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
}
.msg-row.mine .attach-icon { background: rgba(255,255,255,.2); }
.attach-meta { font-size: 11px; opacity: .75; }

.chat-composer {
  border-top: 1px solid var(--border); background: var(--bg-elev);
  padding: 12px 16px; flex-shrink: 0;
}
.composer-attachments {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.composer-attachments:empty { display: none; }
.composer-attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 10px; border-radius: 6px;
  background: var(--bg-hover); font-size: 12px;
}
.composer-attach-chip .x {
  cursor: pointer; padding: 0 4px; border-radius: 4px;
}
.composer-attach-chip .x:hover { background: rgba(0,0,0,.1); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 200px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--bg-soft); color: var(--text); font: inherit; font-size: 14.5px;
}
.composer-row textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px; text-align: center;
}
.empty-logo {
  width: 80px; height: 80px; border-radius: 20px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white; font-weight: 800; font-size: 28px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}

.avatar {
  width: 28px; height: 28px; border-radius: 7px; color: white;
  font-weight: 700; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- MEMBERS PANEL ---------- */
.members-bar {
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-soft); font-size: 12px; color: var(--text-muted);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.member-chip { display: inline-flex; align-items: center; gap: 6px; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.presence-dot.online { background: #22c55e; }

/* ---------- MODAL ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 24px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 480px; max-height: 80vh; display: flex; flex-direction: column;
  background: var(--bg-elev); border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body input[type="search"], .modal-body input[type="text"] {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg-soft); color: var(--text);
  font-size: 14px; margin-bottom: 12px;
}
.user-list { max-height: 320px; overflow-y: auto; }
.user-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.user-item:hover { background: var(--bg-hover); }
.user-item-check { cursor: default; }
.user-item-check input { margin-right: 4px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }

/* ---------- ADMIN ---------- */
.admin-shell { max-width: 1100px; margin: 0 auto; padding: 24px; }
.admin-head { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.admin-head h1 { margin: 0; font-size: 22px; }
.back-link { color: var(--text-muted); font-size: 14px; }
.admin-section { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.admin-section h2 { font-size: 15px; margin: 0 0 12px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.admin-inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin-inline-form input[type="text"], .admin-inline-form input[type="email"] {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--bg-soft); color: var(--text); font-size: 14px;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(22,163,74,.15); color: var(--success); }
.badge.muted { background: var(--bg-hover); color: var(--text-muted); }

/* ---------- SCROLLBAR ---------- */
.conv-list::-webkit-scrollbar, .chat-messages::-webkit-scrollbar, .user-list::-webkit-scrollbar { width: 8px; }
.conv-list::-webkit-scrollbar-thumb, .chat-messages::-webkit-scrollbar-thumb, .user-list::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 4px;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .sidebar { width: 100%; min-width: 0; position: absolute; z-index: 50; }
  .app-shell.show-chat .sidebar { display: none; }
  .app-shell.show-chat .chat-pane { display: flex; }
}


/* ---------- RICH COMPOSER (contenteditable) ---------- */
.composer-row .composer-input {
  flex: 1;
  min-height: 42px;
  max-height: 200px;
  overflow-y: auto;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  outline: none;
  word-break: break-word;
}
.composer-row .composer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.composer-row .composer-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  display: block;
}
.composer-row .composer-input p { margin: 0 0 4px; }
.composer-row .composer-input p:last-child { margin-bottom: 0; }
.composer-row .composer-input ul,
.composer-row .composer-input ol { margin: 4px 0 4px 20px; padding: 0; }
.composer-row .composer-input a { color: var(--primary); }
.composer-row .composer-input img { max-width: 100%; border-radius: 6px; }

/* ---------- RICH MESSAGE BODY ---------- */
.msg-body > :first-child { margin-top: 0 !important; }
.msg-body > :last-child  { margin-bottom: 0 !important; }
.msg-body p { margin: 0 0 6px; }
.msg-body h1, .msg-body h2, .msg-body h3,
.msg-body h4, .msg-body h5, .msg-body h6 {
  margin: 6px 0 4px;
  font-weight: 700;
  line-height: 1.25;
}
.msg-body h1 { font-size: 1.25em; }
.msg-body h2 { font-size: 1.18em; }
.msg-body h3 { font-size: 1.10em; }
.msg-body h4,
.msg-body h5,
.msg-body h6 { font-size: 1em; }
.msg-body ul, .msg-body ol { margin: 4px 0 4px 20px; padding: 0; }
.msg-body li { margin: 2px 0; }
.msg-body code {
  background: rgba(0,0,0,.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.msg-body pre {
  background: rgba(0,0,0,.08);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: pre;
}
.msg-body pre code { background: transparent; padding: 0; }
.msg-body blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 2px 12px;
  margin: 6px 0;
  color: var(--text-muted);
}
.msg-body a { color: var(--primary); text-decoration: underline; }
.msg-row.mine .msg-body a { color: #fff; text-decoration: underline; }
.msg-row.mine .msg-body code,
.msg-row.mine .msg-body pre { background: rgba(255,255,255,.18); }
.msg-row.mine .msg-body blockquote { border-left-color: rgba(255,255,255,.45); color: rgba(255,255,255,.85); }

/* ---------- SIDEBAR UNREAD ---------- */
.conv-title-row { gap: 6px; }
.conv-item .conv-title { display: inline-flex; align-items: center; gap: 6px; }
.conv-item .conv-title .conv-badge {
  background: var(--primary); color: white; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px; min-width: 20px; text-align: center;
  line-height: 1.4;
}
.conv-item.has-unread .conv-title { font-weight: 700; }
.conv-item.has-unread .conv-preview { color: var(--text); font-weight: 500; }

/* ---------- SIDEBAR USER SEARCH ---------- */
.user-search-wrap { position: relative; }
.user-search-wrap input[type="search"] {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
}
.user-search-wrap input[type="search"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.user-search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  max-height: 360px; overflow-y: auto;
  z-index: 80;
  padding: 4px;
}
.user-search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.user-search-item:hover { background: var(--bg-hover); }
.user-search-empty { padding: 14px; color: var(--text-muted); font-size: 13px; text-align: center; }

/* ---------- NAVRAIL ---------- */
.app-shell { /* sidebar layout stays the same; navrail prepends */ }
.navrail {
  width: 60px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}
.navrail-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.navrail-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  text-decoration: none;
  transition: background .12s ease, color .12s ease;
}
.navrail-btn:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.navrail-btn.active { color: var(--text); background: var(--primary-soft); }
.navrail-btn svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.navrail-badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  line-height: 1.3;
}
@media (max-width: 900px) {
  .navrail { width: 52px; }
  .navrail-btn { width: 36px; height: 36px; }
}


/* ---------- MESSAGE ACTION BUTTONS ---------- */
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg-bubble-wrap { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg-row.mine .msg-bubble-wrap { flex-direction: row-reverse; }
.msg-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity .12s, transform .12s;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  box-shadow: var(--shadow);
  align-self: center;
}
.msg-bubble-wrap:hover .msg-actions { opacity: 1; transform: translateY(0); }
.msg-action {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 999px;
  color: var(--text-soft); cursor: pointer;
}
.msg-action:hover { background: var(--bg-hover); color: var(--text); }
.msg-action.danger:hover { color: var(--danger); }

/* ---------- REPLY QUOTE (inside bubble) ---------- */
.msg-quote {
  background: rgba(0,0,0,.05);
  border-left: 3px solid var(--primary);
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 6px;
  cursor: pointer;
  max-width: 100%;
}
.msg-row.mine .msg-quote {
  background: rgba(255,255,255,.18);
  border-left-color: rgba(255,255,255,.6);
}
.msg-quote:hover { filter: brightness(0.95); }
.msg-quote-name { font-weight: 700; font-size: 12px; color: var(--primary); margin-bottom: 2px; }
.msg-row.mine .msg-quote-name { color: white; }
.msg-quote-body { font-size: 13px; opacity: 0.85; max-height: 3.4em; overflow: hidden; word-break: break-word; }

/* Highlight when jumping to a referenced message */
.msg-flash .msg-bubble { animation: msgFlash 1.4s ease; }
@keyframes msgFlash {
  0%   { box-shadow: 0 0 0 0 var(--primary); }
  20%  { box-shadow: 0 0 0 4px var(--primary-soft); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- REPLY PREVIEW (above composer) ---------- */
.reply-preview {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 8px 16px;
}
.reply-preview-inner {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 6px 10px;
}
.reply-preview-meta { font-size: 12px; color: var(--text-soft); display: flex; align-items: center; gap: 4px; }
.reply-preview-body { flex: 1; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview-x {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-muted); font-size: 18px; line-height: 1;
  width: 24px; height: 24px; border-radius: 6px;
}
.reply-preview-x:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- FORWARD MODAL ---------- */
.forward-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.forward-item:hover { background: var(--bg-hover); }
.forward-item input { margin: 0; }
.forward-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- NOTES VIEW ---------- */
.notes-shell { display: flex; flex-direction: column; height: 100%; }
.notes-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev); flex-shrink: 0;
}
.notes-body { flex: 1; display: flex; min-height: 0; }
.notes-list {
  width: 280px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
}
.note-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background .12s;
}
.note-item:hover { background: var(--bg-hover); }
.note-item.active { background: var(--primary-soft); }
.note-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; word-break: break-word; }
.note-preview { line-height: 1.4; max-height: 2.8em; overflow: hidden; word-break: break-word; }
.note-time { margin-top: 4px; font-size: 11px; }

.notes-editor {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 16px 20px;
  background: var(--bg);
  overflow-y: auto;
  min-height: 0;
}
.note-editor-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
#noteTitle {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  outline: none;
}
#noteTitle:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.note-body {
  flex: 1;
  min-height: 250px;
  margin-bottom: 12px;
  background: var(--bg-elev) !important;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  padding: 14px 16px;
  overflow-y: auto;
}
.note-body:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.note-actions {
  display: flex; gap: 8px; align-items: center;
  padding-top: 8px;
}
.btn-secondary.danger {
  border-color: rgba(220,38,38,.3); color: var(--danger);
}
.btn-secondary.danger:hover { background: rgba(220,38,38,.08); }

/* ---------- BRAND IMAGE (theme-swap) ---------- */
.brand-image { display: inline-flex; align-items: center; }
.brand-image img { height: 32px; width: auto; max-width: 100%; display: block; }
.brand-image-lg img { height: 56px; }
.brand-image .brand-light, .brand-image .brand-dark { display: none; }
[data-theme="light"] .brand-image .brand-light { display: block; }
[data-theme="dark"]  .brand-image .brand-dark  { display: block; }
.auth-brand .brand-image { justify-content: center; margin-bottom: 12px; display: flex; }
.empty-state .brand-image { margin-bottom: 14px; }

/* ---------- MODAL POLISH (blur + center + close) ---------- */
.modal-backdrop {
  background: rgba(15, 23, 42, 0.45) !important;
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  animation: modalFadeIn 0.18s ease-out;
}
[data-theme="dark"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.55) !important;
}
.modal-backdrop .modal {
  animation: modalPopIn 0.22s cubic-bezier(.2,.9,.3,1.1);
  border: 1px solid var(--border);
}
@keyframes modalFadeIn {
  from { opacity: 0; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }
  to   { opacity: 1; }
}
@keyframes modalPopIn {
  from { transform: translateY(8px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1);      opacity: 1; }
}
/* Make the X close button look like a clickable button regardless of context */
.modal-head .icon-btn { font-size: 22px; line-height: 1; cursor: pointer; }
.modal-head .icon-btn:hover { background: var(--bg-hover); }


/* ---------- MSG AVATAR (img variant for profile pictures) ---------- */
img.msg-avatar {
  object-fit: cover;
  background: var(--bg-soft);
}

/* ---------- PROFILE VIEW ---------- */
.profile-shell { display: flex; flex-direction: column; height: 100%; }
.profile-body {
  flex: 1; overflow-y: auto;
  padding: 24px 32px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.profile-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
}
.profile-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.profile-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 12px;
}
.profile-section input[type="text"],
.profile-section input[type="email"],
.profile-section input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.profile-section input[type="text"]:focus,
.profile-section input[type="email"]:focus,
.profile-section input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.profile-section input[type="color"] {
  width: 60px; height: 36px;
  margin-top: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  cursor: pointer;
}
.profile-pic-row { display: flex; align-items: center; gap: 18px; }
.profile-pic-preview {
  width: 96px; height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-soft);
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.profile-pic-preview img { width: 100%; height: 100%; object-fit: cover; }
.profile-pic-preview .avatar-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 36px;
  font-weight: 700;
}
.profile-pic-actions p.muted { margin: 8px 0 0; }

.profile-actions { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.profile-msg { font-size: 13px; }
.profile-msg.ok  { color: var(--success); }
.profile-msg.err { color: var(--danger); }

/* ---------- REMINDERS VIEW ---------- */
.reminders-shell { display: flex; flex-direction: column; height: 100%; }
.reminders-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.reminders-form {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reminders-form input[type="text"],
.reminders-form input[type="datetime-local"],
.reminders-form textarea {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.reminders-form input:focus,
.reminders-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.reminders-form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.reminder-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: background .12s;
}
.reminder-item:hover { background: var(--bg-hover); }
.reminder-item.completed { opacity: 0.55; }
.reminder-item.completed .reminder-title { text-decoration: line-through; }
.reminder-item.overdue { border-color: var(--danger); }
.reminder-check {
  margin-top: 3px;
  width: 18px; height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}
.reminder-meta { flex: 1; min-width: 0; }
.reminder-title { font-weight: 600; font-size: 14px; word-break: break-word; }
.reminder-body { margin-top: 3px; }
.reminder-time { margin-top: 6px; color: var(--text-muted); }
.overdue-tag {
  display: inline-block;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-right: 4px;
}
.reminder-del {
  width: 28px; height: 28px;
  color: var(--text-muted);
}
.reminder-del:hover { color: var(--danger); }

/* ---------- REMINDER TOAST ---------- */
.reminder-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 14px 18px 14px 16px;
  min-width: 260px;
  max-width: 360px;
  animation: toastIn 0.3s ease-out;
  position: relative;
}
.reminder-toast.out { animation: toastOut 0.3s ease-in forwards; }
.reminder-toast-head {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}
.reminder-toast-title { font-weight: 700; font-size: 15px; padding-right: 18px; }
.reminder-toast-body { margin-top: 4px; color: var(--text-soft); }
.reminder-toast-x {
  position: absolute;
  top: 6px; right: 8px;
  border: none; background: transparent;
  color: var(--text-muted);
  font-size: 18px; cursor: pointer;
  width: 22px; height: 22px;
  border-radius: 6px;
}
.reminder-toast-x:hover { background: var(--bg-hover); color: var(--text); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toastOut {
  to { transform: translateX(20px); opacity: 0; }
}


/* ---------- GROUP SETTINGS MODAL ---------- */
.modal-wide { max-width: 560px; }
#groupSettingsBody h4 {
  font-size: 13px;
  margin: 0 0 10px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
}
#groupSettingsBody h4 + .members-list { margin-bottom: 18px; }

.members-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  transition: background .12s;
}
.member-row:hover { background: var(--bg-hover); }
.member-info { flex: 1; min-width: 0; }
.member-info .strong { word-break: break-word; }

.avatar.avatar-md {
  width: 36px; height: 36px;
  font-size: 14px;
  border-radius: 9px;
}
img.avatar { object-fit: cover; }

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .05em;
  vertical-align: middle;
  margin-left: 4px;
}
.badge.admin {
  background: rgba(99,102,241,.18);
  color: var(--primary);
}
.badge.muted {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.group-add-section { margin-top: 6px; }
.group-add-section input[type="search"] {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 8px;
  -webkit-appearance: none;
}
.group-add-section input[type="search"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
#groupAddResults { max-height: 220px; overflow-y: auto; }
#groupAddResults .user-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
#groupAddResults .user-item:hover { background: var(--bg-hover); }

.group-actions-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.btn-link.danger { color: var(--danger); padding: 4px 8px; border-radius: 6px; }
.btn-link.danger:hover { background: rgba(220,38,38,.08); }


/* ---------- CONVERSATION 3-DOT MENU ---------- */
.conv-item {
  position: relative;
  align-items: center;
}
.conv-menu-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity .15s, background .12s, color .12s;
}
.conv-item:hover .conv-menu-btn,
.conv-item.active .conv-menu-btn {
  opacity: 1;
}
.conv-menu-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.conv-menu-btn:focus { opacity: 1; outline: none; }

.conv-item.pinned {
  background: linear-gradient(to right, var(--primary-soft), transparent 60%);
}
.conv-item.pinned.active {
  background: var(--primary-soft);
}
.pin-icon {
  font-size: 11px;
  margin-right: 2px;
  opacity: .75;
}

.conv-menu {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 180px;
  z-index: 1000;
  animation: convMenuIn .12s ease-out;
}
.conv-menu .dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
}
.conv-menu .dropdown-item:hover { background: var(--bg-hover); }
.conv-menu .dropdown-item.danger { color: var(--danger); }
.conv-menu .dropdown-item.danger:hover { background: rgba(220,38,38,.08); }

@keyframes convMenuIn {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ---------- REPORTS VIEW ---------- */
.reports-shell { display: flex; flex-direction: column; height: 100%; }
.reports-body { flex: 1; display: flex; min-height: 0; }

.reports-list {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
}
.report-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background .12s;
}
.report-item:hover { background: var(--bg-hover); }
.report-item.active { background: var(--primary-soft); }
.report-item-title { font-weight: 600; font-size: 14px; word-break: break-word; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.report-item-time { margin-top: 4px; font-size: 11px; }

.report-status {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.report-status.draft { background: var(--bg-hover); color: var(--text-muted); }
.report-status.sent  { background: rgba(22,163,74,.18); color: var(--success); }

.reports-editor {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 16px 20px;
  overflow: hidden;
  min-width: 0;
}
.report-editor-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
#reportTitle {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  outline: none;
}
#reportTitle:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.report-save-indicator {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  white-space: nowrap;
}

.report-table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  padding: 0 0 8px;
}
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 1000px;
}
.report-table thead th {
  background: #a7c8eb;
  color: #1a1f2e;
  font-weight: 700;
  text-align: left;
  padding: 10px 8px;
  border: 1px solid #d1d6df;
  position: sticky;
  top: 0;
  z-index: 1;
}
[data-theme="dark"] .report-table thead th { background: #2a3a5a; color: #e6e8ee; border-color: #3a4150; }
.report-table tbody td {
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  vertical-align: top;
}
.report-table td.col-sno {
  text-align: center;
  font-weight: 600;
  width: 50px;
  padding: 8px;
  color: var(--text-muted);
  background: var(--bg-soft);
}
.report-table td.col-x {
  width: 32px;
  padding: 4px;
  text-align: center;
  background: var(--bg-soft);
}
.report-table td input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
  min-height: 36px;
}
.report-table td input:focus {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 2px var(--primary);
}
.report-table .col-date input { width: 130px; }
.report-table .col-status input::placeholder { color: var(--text-muted); font-size: 12px; }

.row-del {
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
}
.row-del:hover { background: rgba(220,38,38,.1); color: var(--danger); }

.report-actions {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.report-email-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px;
  color: var(--text-soft);
}
.report-email-label input[type="email"] {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13px;
  outline: none;
  min-width: 240px;
}
.report-email-label input[type="email"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- LOGIN BACKGROUND ---------- */
.auth-shell {
  background-image: url("/assets/login-bg.png");
  background-repeat: no-repeat;
  background-position: center 80%;
  background-size: cover;
}
@media (max-width: 600px) {
  .auth-shell { background-position: center bottom; background-size: 90vw auto; }
}
[data-theme="dark"] .auth-shell {
  background-image: linear-gradient(rgba(15,17,21,0.6), rgba(15,17,21,0.6)),
                    url("/assets/login-bg.png");
  background-blend-mode: normal;
}


/* ---------- MENTION AUTOCOMPLETE DROPDOWN ---------- */
.mention-dropdown {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 260px;
  max-width: 340px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 1500;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.mention-item.selected,
.mention-item:hover { background: var(--bg-hover); }
.mention-item.selected { background: var(--primary-soft); }
.mention-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
img.mention-avatar { object-fit: cover; }
.mention-meta { min-width: 0; }
.mention-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mention-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ---------- DRAG-AND-DROP OVERLAY ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(79, 70, 229, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  pointer-events: none;  /* let drag events fall through to document */
  animation: dropOverlayFade .15s ease-out;
}
.drop-overlay[hidden] { display: none; }
.drop-overlay-inner {
  background: var(--bg-elev);
  color: var(--text);
  border: 3px dashed var(--primary);
  border-radius: 20px;
  padding: 40px 64px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 80%;
}
.drop-overlay svg {
  color: var(--primary);
  margin-bottom: 14px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.drop-overlay h3 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}
.drop-overlay p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
@keyframes dropOverlayFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}


/* ---------- CHAT TOAST (incoming message) ---------- */
.chat-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 12px 36px 12px 14px;
  min-width: 260px;
  max-width: 360px;
  cursor: pointer;
  animation: chatToastIn .25s ease-out;
}
.chat-toast.out { animation: chatToastOut .25s ease-in forwards; }
.chat-toast-head { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.chat-toast-body { color: var(--text-soft); word-break: break-word; }
.chat-toast-x {
  position: absolute;
  top: 6px; right: 8px;
  border: none; background: transparent;
  color: var(--text-muted);
  font-size: 18px; cursor: pointer;
  width: 22px; height: 22px;
  border-radius: 6px;
}
.chat-toast-x:hover { background: var(--bg-hover); color: var(--text); }
@keyframes chatToastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes chatToastOut {
  to { transform: translateX(20px); opacity: 0; }
}

/* ---------- IMAGE DOWNLOAD OVERLAY ---------- */
.attach-image-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
.attach-image-download {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff !important;
  border-radius: 8px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transform: scale(0.92);
  transition: opacity .15s, transform .15s, background .15s;
  text-decoration: none !important;
  line-height: 1;
}
.attach-image-wrap:hover .attach-image-download,
.attach-image-download:focus { opacity: 1; transform: scale(1); }
.attach-image-download:hover { background: rgba(0, 0, 0, 0.85); }
/* Always show on touch devices since there's no hover */
@media (hover: none) {
  .attach-image-download { opacity: 0.9; transform: scale(1); }
}

/* ---------- IMG CONV AVATAR ---------- */
img.conv-avatar { object-fit: cover; background: var(--bg-soft); }

/* ---------- NOTIFICATION BANNER ---------- */
.notif-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 10px 14px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  max-width: min(640px, calc(100vw - 24px));
}
.notif-banner.denied { border-left-color: var(--danger); }
.notif-banner-icon { font-size: 20px; flex-shrink: 0; }
.notif-banner-text { flex: 1; min-width: 0; line-height: 1.4; }
.notif-banner-btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
.notif-banner-btn:hover { background: var(--primary-hover); }
.notif-banner-x {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex-shrink: 0;
}
.notif-banner-x:hover { background: var(--bg-hover); color: var(--text); }
@media (max-width: 540px) {
  .notif-banner { font-size: 13px; padding: 8px 12px; }
}

/* ---------- CONV FLASH (post-notification highlight) ---------- */
.conv-item.conv-flash {
  animation: convFlash 1.6s ease-out;
}
@keyframes convFlash {
  0%   { background: var(--primary); }
  35%  { background: var(--primary-soft); }
  100% { background: transparent; }
}


/* ---------- PWA INSTALL BANNER ---------- */
.install-banner {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  max-width: min(560px, calc(100vw - 20px));
  animation: installBannerIn .25s ease-out;
}
.install-banner-icon { font-size: 22px; flex-shrink: 0; }
.install-banner-text { flex: 1; min-width: 0; line-height: 1.35; }
.install-banner-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
.install-banner-btn:hover { background: var(--primary-hover); }
.install-banner-x {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}
.install-banner-x:hover { background: var(--bg-hover); color: var(--text); }
@keyframes installBannerIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}
@media (max-width: 540px) {
  .install-banner { font-size: 13px; padding: 10px 12px; bottom: 8px; }
  .install-banner-btn { padding: 7px 12px; }
}

/* ---------- MOBILE BACK BUTTON ---------- */
.chat-head-back {
  display: none;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  flex-shrink: 0;
}
.chat-head-back:hover { background: var(--bg-hover); }
.chat-head-back:active { background: var(--bg-soft); }
@media (max-width: 900px) {
  .chat-head-back { display: inline-flex; }
  /* Also: on mobile the navrail can be a bit cramped — make sure the chat
     pane fills the screen when show-chat is active */
  .app-shell.show-chat .navrail { display: none; }
}

/* ---------- ONLINE DOT + READ TICKS ---------- */
.conv-avatar-wrap { position: relative; flex-shrink: 0; display: inline-block; }
.conv-online-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  background: #22c55e;
  border: 2px solid var(--bg-elev);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, .35);
}

.chat-head-sub.online {
  color: #22c55e;
  font-weight: 600;
}

.msg-ticks {
  display: inline-block;
  margin-left: 4px;
  font-size: 12px;
  letter-spacing: -1px;
  font-family: -apple-system, sans-serif;
  vertical-align: baseline;
}
.msg-ticks.sent { color: var(--text-muted); }
.msg-ticks.read { color: #4fc3f7; }
.msg-row.mine .msg-ticks.sent { color: rgba(255,255,255,0.7); }
.msg-row.mine .msg-ticks.read { color: #4fc3f7; }

/* ---------- MOBILE CHAT WIDTH POLISH ---------- */
@media (max-width: 720px) {
  /* Use the full screen — desktop pads 20/24px which wastes real estate on phones */
  .chat-messages {
    padding: 12px 10px 14px;
    gap: 8px;
  }
  /* Let bubbles use most of the screen width */
  .msg-row {
    max-width: 94%;
    gap: 8px;
  }
  /* Slightly smaller avatar gives the bubble more room */
  .msg-avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }
  /* Tighter bubble padding + smaller radius */
  .msg-bubble {
    padding: 8px 12px;
    border-radius: 12px;
  }
  /* Force long words and URLs to break instead of stretching the bubble awkwardly */
  .msg-body {
    font-size: 14.5px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .msg-body a {
    word-break: break-all;        /* URLs always wrap, never overflow */
    overflow-wrap: anywhere;
  }
  /* Compact chat header */
  .chat-head {
    padding: 10px 12px;
  }
  .chat-head-title { font-size: 15px; }
  .chat-head-sub   { font-size: 11px; margin-top: 1px; }
  /* The members-bar wrapping its chips creates 2-3 lines of meta clutter; tighten */
  .members-bar {
    padding: 6px 12px;
    gap: 6px;
    font-size: 11px;
  }
  /* Composer: full width, tighter padding */
  .chat-composer {
    padding: 8px 10px 10px;
  }
  .composer-row {
    gap: 6px;
  }
  /* Hover-only message actions don't work on touch — keep them visible but small */
  .msg-actions {
    opacity: 1;
    transform: none;
  }
  .msg-action {
    width: 22px;
    height: 22px;
  }
}

@media (max-width: 420px) {
  /* On very narrow phones (~400px) squeeze further */
  .chat-messages { padding: 10px 8px; }
  .msg-row { max-width: 96%; gap: 6px; }
  .msg-avatar { width: 28px; height: 28px; }
  .msg-bubble { padding: 7px 10px; }
}

/* ---------- MOBILE MSG ACTION 3-DOT MENU ---------- */
/* Desktop: 3-dot toggle is hidden, hover still reveals the toolbar */
.msg-action-toggle { display: none; }

@media (max-width: 720px) {
  /* Reset the always-visible state I added earlier */
  .msg-actions {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(4px) scale(0.95);
    transform-origin: bottom center;
    transition: opacity .12s ease, transform .12s ease;
    z-index: 50;
  }
  .msg-bubble-wrap { position: relative; }
  .msg-bubble-wrap.actions-open .msg-actions {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0) scale(1);
  }

  /* Show the 3-dot toggle on mobile */
  .msg-action-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 999px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    margin: 0 2px;
  }
  .msg-action-toggle:hover,
  .msg-bubble-wrap.actions-open .msg-action-toggle {
    background: var(--bg-hover);
    color: var(--text);
  }

  /* When the popover is open, give the toolbar a clearer popover look */
  .msg-bubble-wrap.actions-open .msg-actions {
    box-shadow: var(--shadow-lg);
  }
}


/* ============================================================
   MOBILE: WhatsApp-inspired UI overhaul (≤ 720px)
   ============================================================ */
@media (max-width: 720px) {
  /* Make room for the bottom nav so content isn't covered */
  .app-shell { padding-bottom: 62px; box-sizing: border-box; }

  /* Hide the left rail — bottom nav replaces it on mobile */
  .navrail { display: none !important; }

  /* Sidebar takes the full screen now that left rail is gone */
  .sidebar {
    width: 100% !important;
    border-right: none;
  }

  /* ----- Sidebar header: bigger title, WhatsApp-style top bar ----- */
  .sidebar-head {
    padding: 14px 16px 10px;
  }
  .sidebar-head .brand-image img { height: 28px; }

  /* ----- Search bar: big rounded pill ----- */
  .user-search-wrap input[type="search"] {
    padding: 12px 18px;
    border-radius: 24px;
    background: var(--bg-soft);
    font-size: 15px;
    border-color: transparent;
  }

  /* ----- Filter chips row ----- */
  .conv-filters {
    display: flex;
    gap: 8px;
    padding: 4px 14px 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .conv-filters::-webkit-scrollbar { display: none; }
  .conv-filter {
    flex-shrink: 0;
    background: var(--bg-soft);
    border: 1px solid transparent;
    color: var(--text);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .12s, color .12s;
  }
  .conv-filter:hover { background: var(--bg-hover); }
  .conv-filter.active {
    background: rgba(34,197,94,0.18);
    color: #22c55e;
    border-color: rgba(34,197,94,0.3);
  }
  .conv-filter-count {
    background: rgba(34,197,94,0.3);
    color: #22c55e;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
  }
  .conv-filter.active .conv-filter-count { background: rgba(34,197,94,0.45); }

  /* ----- Conv-list: filter via data-filter on container ----- */
  .conv-list[data-filter="unread"] .conv-item:not(.has-unread) { display: none; }
  .conv-list[data-filter="groups"] .conv-item:not([data-conv-type="group"]) { display: none; }

  /* ----- Conv items: WhatsApp-style — round avatar, big tap target ----- */
  .conv-list { padding: 0 8px 14px; }
  .conv-item {
    padding: 10px 10px;
    gap: 12px;
    border-radius: 12px;
    align-items: center;
  }
  .conv-avatar {
    width: 50px !important;
    height: 50px !important;
    border-radius: 50% !important;
    font-size: 18px !important;
  }
  img.conv-avatar { object-fit: cover; }
  .conv-avatar-wrap { display: block; }
  .conv-online-dot {
    width: 13px;
    height: 13px;
    bottom: 0;
    right: 0;
    border-width: 3px;
  }
  .conv-title { font-size: 15.5px; }
  .conv-preview { font-size: 13.5px; margin-top: 3px; }
  .conv-badge {
    background: #22c55e !important;
    color: #fff;
    font-size: 11.5px;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 22px;
    font-weight: 700;
  }
  .conv-item .conv-title { display: flex; align-items: center; gap: 4px; }
  .conv-item .conv-title-row { gap: 8px; }

  /* 3-dot menu button stays subtle */
  .conv-menu-btn {
    opacity: 0.4;
  }
  .conv-item:active .conv-menu-btn { opacity: 1; }

  /* ----- Message avatars: also round ----- */
  .msg-avatar {
    border-radius: 50% !important;
  }

  /* ----- Bottom navigation bar ----- */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-nav-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: color .15s;
  }
  .mobile-nav-btn svg { width: 24px; height: 24px; transition: transform .15s; }
  .mobile-nav-btn.active {
    color: #22c55e;
  }
  .mobile-nav-btn.active svg { transform: scale(1.05); }
  .mobile-nav-btn:active svg { transform: scale(0.95); }
  .mobile-nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 22px);
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
    line-height: 1.5;
  }

  /* When the bottom nav is active, the chat-pane needs to make room for it too */
  .chat-pane { padding-bottom: 0; }
  .chat-messages { padding-bottom: 14px; }

  /* When inside a conversation (show-chat), hide bottom nav so the composer
     has full focus */
  .app-shell.show-chat ~ .mobile-bottom-nav,
  body:has(.app-shell.show-chat) .mobile-bottom-nav {
    transform: translateY(100%);
    transition: transform .2s ease;
  }
}

/* ---------- MOBILE: WHATSAPP-STYLE MSG BUBBLE ---------- */
/* Default (desktop): hide the inline meta — meta line above bubble is shown */
.msg-inline-meta { display: none; }
.time-spacer { display: none; }

@media (max-width: 720px) {
  /* Hide the avatar per-message — alignment shows who sent it */
  .msg-row > .msg-avatar { display: none !important; }
  /* Hide the name/date meta line above the bubble */
  .msg-row > .msg-col > .msg-meta { display: none; }

  /* Tighter message rows */
  .msg-row {
    max-width: 82%;
    gap: 0;
    margin-bottom: 1px;
  }
  .chat-messages { gap: 3px; padding: 12px 8px 16px; }

  /* Bubble: relative for inline meta absolute positioning */
  .msg-bubble {
    padding: 6px 10px 5px 10px;
    border-radius: 10px;
    position: relative;
    min-width: 64px;
    box-shadow: 0 1px 1px rgba(0,0,0,.08);
    word-break: break-word;
  }
  .msg-row.mine .msg-bubble  { border-bottom-right-radius: 4px; }
  .msg-row:not(.mine) .msg-bubble { border-bottom-left-radius: 4px; }

  /* Body: text content; spacer + absolute meta together solve the overlap */
  .msg-body {
    font-size: 14.5px;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
    padding: 0;
    min-height: 0;
  }
  .msg-body > p:last-child { margin-bottom: 0; }

  /* Invisible width spacer at end of body — forces the text to leave room
     for the inline meta even on short single-line messages. */
  .time-spacer {
    display: inline-block;
    width: 58px;        /* enough room for "12:34 AM ✓✓" + a little margin */
    height: 1px;
    vertical-align: bottom;
  }

  /* The actual visible meta, pinned bottom-right */
  .msg-inline-meta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    position: absolute;
    right: 8px;
    bottom: 4px;
    font-size: 10.5px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    pointer-events: none;
  }
  .msg-row:not(.mine) .msg-inline-meta { color: var(--text-muted); }
  .msg-inline-meta .msg-ticks   { margin-left: 2px; font-size: 10.5px; }
  .msg-inline-meta .msg-edited  { margin-right: 2px; font-size: 10px; opacity: 0.7; }

  /* ----- IMAGE ATTACHMENTS — fit the bubble cleanly ----- */
  /* When the bubble contains an image attachment, drop the padding so the
     image stretches edge-to-edge inside the bubble's rounded corners. */
  .msg-bubble:has(.attach-image-wrap) {
    padding: 3px;
    min-width: 0;
  }
  .msg-attachments {
    margin-top: 0;
    width: 100%;
  }
  .attach-image-wrap {
    display: block;
    width: 100%;
  }
  .attach-image {
    max-width: 100% !important;
    max-height: 320px !important;
    width: auto;
    height: auto;
    display: block;
    border-radius: 8px;
    object-fit: cover;
  }
  /* When image-only (no text alongside), let the inline-meta float over the
     image at bottom-right with a tiny dark backdrop for readability */
  .msg-bubble:has(.attach-image-wrap) .msg-inline-meta {
    background: rgba(0, 0, 0, 0.45);
    padding: 2px 6px;
    border-radius: 8px;
    color: #fff;
  }
  /* Download button on image: smaller on mobile so it doesn't dominate */
  .attach-image-download { width: 28px; height: 28px; top: 6px; right: 6px; }

  /* Reply-quote tighter */
  .msg-quote { padding: 4px 8px; font-size: 12px; margin-bottom: 4px; }
  .msg-quote-name { font-size: 11px; }
  .msg-quote-body { font-size: 12px; }

  /* Action toggle (3-dot): keep small and unobtrusive */
  .msg-action-toggle {
    width: 24px; height: 24px;
    align-self: center;
    opacity: 0.4;
  }
  .msg-bubble-wrap { align-items: center; }
}

/* ---------- CHAT HEAD AVATAR / MENU (base — applies on all viewports) ---------- */
.chat-head-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
img.chat-head-avatar { object-fit: cover; }
.chat-head-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-head-menu {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-head-menu:hover { background: var(--bg-hover); }

/* ---------- MOBILE: CHAT HEAD WHATSAPP STYLE ---------- */
@media (max-width: 720px) {
  .chat-head {
    padding: 8px 6px 8px 2px;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    min-height: 56px;
  }
  .chat-head-back {
    display: inline-flex;
    width: 40px;
    height: 40px;
    margin: 0;
    border-radius: 50%;
  }
  .chat-head-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
  }
  img.chat-head-avatar { object-fit: cover; }
  .chat-head-info {
    flex: 1;
    min-width: 0;
    margin-left: 4px;
    overflow: hidden;
  }
  .chat-head-title {
    font-size: 15.5px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-head-sub {
    font-size: 11.5px;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-head-menu {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text);
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .chat-head-menu:hover,
  .chat-head-menu:active { background: var(--bg-hover); }
  .chat-head-group-btn { display: none !important; }
  .members-bar { display: none; }
}


/* ============================================================
   STATUS / UPDATES VIEW
   ============================================================ */
.updates-shell { display: flex; flex-direction: column; height: 100%; }
.updates-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.updates-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.updates-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.status-section-header {
  padding: 14px 20px 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background .12s;
}
.status-row:hover { background: var(--bg-hover); }
.status-row.add-row { padding: 14px 20px; }

.status-ring {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  padding: 3px;
  background: transparent;
  border: 2.5px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.status-ring.mine-add {
  border: 2px dashed var(--text-muted);
}
.status-ring.mine-active {
  border-color: #22c55e;
}
.status-ring.unviewed {
  border-color: #22c55e;
}
.status-ring.viewed {
  border-color: var(--text-muted);
  opacity: 0.7;
}

.status-avatar-img,
.status-avatar-letter {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  object-fit: cover;
}

.status-add-plus {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #22c55e;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  border: 2px solid var(--bg);
}

.status-info {
  flex: 1;
  min-width: 0;
}
.status-title {
  font-size: 15.5px;
  font-weight: 600;
  margin-bottom: 2px;
}
.status-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

.status-del-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.status-del-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- Add status modal ---------- */
#addStatusModal textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
#addStatusModal textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.status-color-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.status-color {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform .12s;
}
.status-color:hover { transform: scale(1.1); }
.status-color.selected {
  border-color: var(--text);
  transform: scale(1.1);
}
.status-preview {
  margin-top: 14px;
  padding: 24px;
  border-radius: 12px;
  color: white;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ---------- Fullscreen status viewer ---------- */
.status-viewer {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #000;
  display: flex;
  flex-direction: column;
  user-select: none;
}
.status-viewer-progress {
  display: flex;
  gap: 4px;
  padding: 10px 14px 0;
}
.status-progress-bar {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  overflow: hidden;
}
.status-progress-bar.done { background: rgba(255,255,255,0.9); }
.status-progress-bar span { display: block; height: 100%; background: white; width: 0; }
.status-progress-bar.active span { animation: statusProgress 5s linear forwards; }
@keyframes statusProgress { from { width: 0; } to { width: 100%; } }

.status-viewer-head {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  color: white;
  gap: 12px;
  z-index: 2;
}
.status-viewer-head strong { font-size: 16px; }
.status-viewer-time { font-size: 12px; opacity: 0.8; flex: 1; }
.status-viewer-close {
  border: none;
  background: transparent;
  color: white;
  font-size: 28px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  line-height: 1;
}
.status-viewer-close:hover { background: rgba(255,255,255,0.15); }

.status-viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 30px;
  position: relative;
}
.status-viewer-text {
  color: white;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
}

.status-viewer-nav-left,
.status-viewer-nav-right {
  position: absolute;
  top: 60px;
  bottom: 0;
  width: 35%;
  cursor: pointer;
  z-index: 3;
}
.status-viewer-nav-left { left: 0; }
.status-viewer-nav-right { right: 0; }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 720px) {
  .updates-head { padding: 12px 14px; }
  .updates-head h2 { font-size: 24px; }
  .status-row { padding: 9px 14px; gap: 12px; }
  .status-row.add-row { padding: 14px; }
  .status-section-header { padding: 12px 14px 6px; font-size: 14px; color: var(--text-muted); font-weight: 500; }
  .status-ring { width: 52px; height: 52px; }
  .status-avatar-img,
  .status-avatar-letter { font-size: 16px; }
}

/* ---------- STATUS IMAGE UPLOAD ---------- */
.status-img-area {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: background .12s, border-color .12s;
  position: relative;
  overflow: hidden;
  background: var(--bg-soft);
}
.status-img-area:hover { background: var(--bg-hover); border-color: var(--primary); }
.status-img-area.uploading::after {
  content: "Uploading...";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.status-img-area.has-image {
  padding: 0;
  border-style: solid;
  border-color: transparent;
}
.status-img-area.has-image img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
}
.status-img-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.status-img-remove:hover { background: rgba(0,0,0,0.9); }

.status-viewer-image {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
}
.status-viewer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
}
.status-viewer-text.overlay {
  position: absolute;
  bottom: 30px;
  left: 30px;
  right: 30px;
  background: rgba(0,0,0,0.6);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 16px;
}
/* Reminder edit button */
.reminder-edit { background: transparent; border: none; color: var(--text-muted); cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.reminder-edit:hover { background: var(--bg-hover); color: var(--primary); }

/* Reminder frequency + custom-dates picker */
.reminders-form-row { margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.reminders-form-row label { font-weight: 500; }
#rmFrequency {
  padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--bg-soft); color: var(--text);
  font-size: 14px; font-family: inherit;
}
.rm-custom-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.rm-date-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 999px; font-size: 12.5px;
}
.rm-date-chip-x {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.rm-date-chip-x:hover { color: var(--danger, #ef4444); }
.reminder-freq-tag {
  display: inline-block; padding: 1px 8px; margin-left: 8px;
  background: var(--primary-soft, rgba(79,70,229,0.15));
  color: var(--primary, #4f46e5);
  border-radius: 10px; font-size: 11px; text-transform: capitalize; font-weight: 600;
}
/* Forwarded tag (small italic muted, WhatsApp-style) */
.forwarded-tag { font-size: 12px; opacity: 0.7; margin-bottom: 4px; display: flex; align-items: center; gap: 4px; }
.forwarded-tag em { font-style: italic; font-weight: normal; }
