/* ============================ Theme ============================ */
:root {
  --bg: #ffffff;
  --bg-side: #ffffff;
  --bg-panel: #e6ebee;
  --bg-hover: #f1f4f6;
  --bg-active: #3390ec;
  --bg-active-soft: #ebf3fc;
  --text: #1a1a1a;
  --text-muted: #8a939b;
  --border: #e7e9eb;
  --bubble-in: #ffffff;
  --bubble-out: #eeffde;
  --bubble-out-text: #1a1a1a;
  --header-bg: #ffffff;
  --accent: #3390ec;
  --shadow: 0 2px 12px rgba(16, 35, 47, 0.12);
  --badge: #3390ec;
}
[data-theme="dark"] {
  --bg: #0e1621;
  --bg-side: #17212b;
  --bg-panel: #0e1621;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bg-active-soft: #2b5278;
  --text: #ffffff;
  --text-muted: #7d8b99;
  --border: #101921;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --bubble-out-text: #ffffff;
  --header-bg: #17212b;
  --accent: #64a9e9;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --badge: #64a9e9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", Vazirmatn, Tahoma, system-ui, sans-serif;
  background: var(--bg-panel);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ============================ Auth ============================ */
.auth-screen {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3390ec, #64a9e9);
}
.auth-card {
  width: 360px; max-width: 92vw;
  background: var(--bg); border-radius: 16px;
  padding: 36px 28px; text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,.25);
}
.auth-logo { font-size: 56px; }
.auth-title { font-size: 26px; margin: 6px 0 18px; font-weight: 700; }
.auth-sub { color: var(--text-muted); margin-bottom: 16px; }
.auth-step { display: flex; flex-direction: column; gap: 12px; }
.auth-hint, .auth-error { font-size: 13px; margin-top: 10px; }
.auth-hint { color: var(--text-muted); }
.auth-error { color: #e0564f; min-height: 18px; }
.auth-error-detail {
  font-size: 11.5px; color: var(--text-muted); margin-top: 4px; font-family: ui-monospace, Menlo, Consolas, monospace;
  word-break: break-word; white-space: pre-wrap; opacity: .85;
}
.auth-error-detail:empty { display: none; }

.field {
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font-size: 15px; outline: none; transition: border-color .15s;
}
.field:focus { border-color: var(--accent); }
.code-field {
  text-align: center; font-size: 26px; letter-spacing: 10px; font-weight: 700;
  padding-inline: 10px;
}

.field-status { font-size: 12.5px; min-height: 16px; margin-top: -6px; text-align: start; }
.field-status.ok { color: #4bb34b; }
.field-status.bad { color: #e0564f; }
.field-status.checking { color: var(--text-muted); }

.btn { border: none; border-radius: 10px; padding: 12px 16px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--bg-hover); }
.danger { color: #e0564f !important; }

/* ============================ App layout ============================ */
.app { height: 100%; display: flex; position: relative; }

.sidebar {
  width: 380px; min-width: 300px;
  background: var(--bg-side); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-top {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}
.icon-btn {
  border: none; background: transparent; color: var(--text-muted);
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.search-wrap { flex: 1; }
.search-input {
  width: 100%; padding: 9px 14px; border-radius: 20px;
  border: none; background: var(--bg-hover); color: var(--text);
  font-size: 14px; outline: none;
}

.dialog-list, .search-results { flex: 1; overflow-y: auto; }

/* Dialog / list rows */
.dialog {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; cursor: pointer; position: relative;
}
.dialog:hover { background: var(--bg-hover); }
.dialog.active { background: var(--bg-active); }
.dialog.active .dialog-title,
.dialog.active .dialog-preview,
.dialog.active .dialog-time { color: #fff; }
.dialog.active .avatar { box-shadow: 0 0 0 2px #fff; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 17px; user-select: none;
  background: var(--accent);
}
.avatar-lg { width: 74px; height: 74px; font-size: 28px; }

.dialog-main { flex: 1; min-width: 0; }
.dialog-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dialog-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-title .badge-icon { font-size: 13px; opacity: .7; margin-inline-start: 4px; }
.dialog-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.dialog-preview { font-size: 13.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.dialog-unread {
  background: var(--badge); color: #fff; font-size: 12px; font-weight: 600;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.section-label { padding: 10px 14px 4px; font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ============================ Drawer ============================ */
.overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.35); z-index: 40;
}
.drawer {
  position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 300px; background: var(--bg-side); z-index: 50;
  transform: translateX(-105%); transition: transform .25s ease;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
[dir="rtl"] .drawer { transform: translateX(105%); }
.drawer.open { transform: translateX(0) !important; }
.drawer-head {
  padding: 20px 18px; background: linear-gradient(135deg, #3390ec, #2b6fb3); color: #fff;
}
.drawer-head .avatar { margin-bottom: 12px; box-shadow: 0 0 0 2px rgba(255,255,255,.4); }
.drawer-name { font-size: 17px; font-weight: 600; }
.drawer-phone { font-size: 13px; opacity: .85; margin-top: 2px; }
.drawer-menu { list-style: none; padding: 8px 0; flex: 1; overflow-y: auto; min-height: 0; }
.drawer-menu li {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px; font-size: 15px; cursor: pointer;
}
.drawer-menu li:hover { background: var(--bg-hover); }
.drawer-menu .mi { font-size: 19px; width: 22px; text-align: center; }
.drawer-foot { padding: 14px 20px; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ============================ Chat panel ============================ */
.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg-panel); position: relative; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 14px;
}
.chat-empty-badge {
  width: 90px; height: 90px; border-radius: 50%; background: rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: center; font-size: 40px;
}
[data-theme="dark"] .chat-empty-badge { background: rgba(255,255,255,.06); }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--header-bg); border-bottom: 1px solid var(--border);
  min-height: 58px;
}
.chat-header-info { display: flex; align-items: center; gap: 11px; cursor: pointer; flex: 1; }
.chat-header-info .avatar { width: 42px; height: 42px; font-size: 16px; }
.chat-title { font-weight: 600; font-size: 16px; }
.chat-status { font-size: 13px; color: var(--text-muted); }
.chat-status.online { color: var(--accent); }

.messages {
  flex: 1; overflow-y: auto; padding: 18px 8%;
  display: flex; flex-direction: column; gap: 3px;
  background-image: radial-gradient(circle at 20% 30%, rgba(51,144,236,.05), transparent 60%);
}
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }

.bubble {
  max-width: 72%; padding: 7px 11px 6px; border-radius: 12px;
  background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,.08);
  position: relative; word-wrap: break-word; overflow-wrap: break-word;
}
.msg-row.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.bubble-sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.bubble-text { font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: break-word; }
.bubble-time { font-size: 11px; color: var(--text-muted); text-align: end; margin-top: 2px; }
.msg-row.out .bubble-time { color: rgba(0,0,0,.4); }
[data-theme="dark"] .msg-row.out .bubble-time { color: rgba(255,255,255,.5); }

.service-msg { align-self: center; background: rgba(0,0,0,.15); color: #fff;
  font-size: 12.5px; padding: 4px 12px; border-radius: 12px; margin: 6px 0; }
[data-theme="dark"] .service-msg { background: rgba(0,0,0,.4); }

.typing-indicator { padding: 2px 8% 6px; font-size: 13px; color: var(--accent); min-height: 20px; }

/* Composer */
.composer { padding: 10px 8% 14px; background: var(--bg-panel); }
.composer-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-side); border-radius: 22px; padding: 6px 8px; box-shadow: var(--shadow);
}
.msg-input {
  flex: 1; border: none; background: transparent; color: var(--text);
  font-size: 15px; padding: 8px 10px; outline: none;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transform: scaleX(-1);
}
.send-btn:hover { filter: brightness(1.06); }
.composer-locked { text-align: center; color: var(--text-muted); padding: 14px; font-size: 14px; }

/* ============================ Modals ============================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 440px; max-width: 96vw; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 14px; padding: 22px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.modal-title { font-size: 19px; font-weight: 700; }
.modal-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-error { color: #e0564f; font-size: 13px; min-height: 16px; }

.picker-list { max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.picker-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; cursor: pointer;
}
.picker-item:hover { background: var(--bg-hover); }
.picker-item .avatar { width: 40px; height: 40px; font-size: 15px; }
.picker-item.selected { background: var(--bg-active-soft); }
.picker-name { font-weight: 600; font-size: 14.5px; }
.picker-sub { font-size: 12.5px; color: var(--text-muted); }
.picker-check { margin-inline-start: auto; color: var(--accent); font-size: 18px; }
.picker-role { margin-inline-start: auto; font-size: 12px; color: var(--text-muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-active-soft); color: var(--accent); border-radius: 14px;
  padding: 4px 10px; font-size: 13px; display: flex; align-items: center; gap: 5px;
}
.chip .x { cursor: pointer; font-weight: 700; }

.info-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.info-sub { color: var(--text-muted); font-size: 14px; }
.info-about { font-size: 14px; margin-top: 4px; }

/* ============================ Toast ============================ */
.toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 200;
  font-size: 14px; box-shadow: var(--shadow);
}

/* ============================ Avatars with photos ============================ */
.avatar.has-img { background-size: cover !important; background-position: center; color: transparent; }
.avatar-picker { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar-editable { cursor: pointer; position: relative; font-size: 30px; }
.avatar-editable::after {
  content: '📷'; position: absolute; inset-block-end: -2px; inset-inline-end: -2px;
  background: var(--accent); color: #fff; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 13px; border: 2px solid var(--bg);
}

/* ============================ Composer icons ============================ */
.composer-icon {
  border: none; background: transparent; font-size: 22px; width: 40px; height: 40px;
  border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.composer-icon:hover { background: var(--bg-hover); }
.composer-icon.active { background: var(--bg-active-soft); }

/* ============================ Emoji / sticker panel ============================ */
.emoji-panel {
  background: var(--bg-side); border-radius: 14px; box-shadow: var(--shadow);
  padding: 8px; margin-bottom: 8px; display: flex; flex-direction: column;
}
.emoji-tabs { display: flex; gap: 6px; padding: 2px 2px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.emoji-tab { border: none; background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 600;
  padding: 6px 14px; border-radius: 16px; cursor: pointer; }
.emoji-tab.active { background: var(--bg-active-soft); color: var(--accent); }
.emoji-grid {
  max-height: 210px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px;
}
.emoji-cat { grid-column: 1 / -1; font-size: 12px; color: var(--text-muted); padding: 6px 4px 2px; }
.emoji-item {
  border: none; background: transparent; font-size: 23px; height: 40px; border-radius: 8px; cursor: pointer;
}
.emoji-item:hover { background: var(--bg-hover); }
.sticker-grid {
  max-height: 210px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 4px;
}
.sticker-item { border: none; background: transparent; font-size: 42px; height: 60px; border-radius: 10px; cursor: pointer; }
.sticker-item:hover { background: var(--bg-hover); transform: scale(1.08); }

/* ============================ Voice recording bar ============================ */
.rec-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-side); border-radius: 22px; padding: 8px 12px; box-shadow: var(--shadow);
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e0564f; animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { color: var(--text-muted); font-size: 13px; flex: 1; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ============================ Media in bubbles ============================ */
.bubble.has-media { padding: 4px 4px 6px; }
.bubble.has-media .bubble-text { padding: 2px 7px 0; }
.bubble.has-media .bubble-sender { padding: 3px 7px 0; }
.media-img {
  display: block; max-width: min(320px, 68vw); max-height: 360px; width: auto; height: auto;
  border-radius: 10px; cursor: pointer; object-fit: cover;
}
.media-video { display: block; max-width: min(340px, 72vw); border-radius: 10px; }
.bubble-meta { display: flex; align-items: center; gap: 3px; justify-content: flex-end; margin-top: 2px; }
.bubble.has-media .bubble-meta { padding-inline: 7px; }

/* Voice player */
.voice { display: flex; align-items: center; gap: 10px; padding: 4px 7px; min-width: 180px; }
.voice-play {
  width: 38px; height: 38px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.voice-body { flex: 1; }
.voice-bar { height: 4px; background: rgba(127,127,127,.35); border-radius: 2px; overflow: hidden; cursor: pointer; }
.voice-prog { height: 100%; width: 0; background: var(--accent); }
.voice-dur { font-size: 12px; color: var(--text-muted); margin-top: 3px; display: block; }
.msg-row.out .voice-dur { color: rgba(0,0,0,.45); }
[data-theme="dark"] .msg-row.out .voice-dur { color: rgba(255,255,255,.6); }

/* Audio (music) + file cards */
.file-card {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; text-decoration: none;
  color: inherit; min-width: 190px; max-width: 260px;
}
.file-icon {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0;
}
.file-info { min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--text-muted); }
.audio-el { width: 240px; max-width: 62vw; margin-top: 4px; }

/* ============================ Read ticks ============================ */
.ticks { display: inline-flex; color: var(--text-muted); flex-shrink: 0; }
.ticks svg { width: 16px; height: 12px; }
.ticks.read { color: #34b7f1; }
.msg-row.out .ticks:not(.read) { color: rgba(0,0,0,.4); }
[data-theme="dark"] .msg-row.out .ticks:not(.read) { color: rgba(255,255,255,.5); }
.dialog-tick { display: inline-flex; vertical-align: middle; margin-inline-end: 2px; color: var(--text-muted); }
.dialog-tick.read { color: #34b7f1; }
.dialog-tick svg { width: 15px; height: 11px; }

/* ============================ Lightbox ============================ */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lightbox-img { max-width: 94vw; max-height: 90vh; border-radius: 8px; }
.lightbox-close {
  position: absolute; inset-block-start: 18px; inset-inline-end: 22px;
  background: rgba(255,255,255,.15); color: #fff; border: none; width: 44px; height: 44px;
  border-radius: 50%; font-size: 20px; cursor: pointer;
}

/* ============================ Upload toast ============================ */
.upload-toast {
  position: fixed; inset-block-end: 24px; inset-inline-end: 24px; z-index: 200;
  background: var(--bg-side); color: var(--text); padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.spinner {
  width: 18px; height: 18px; border: 2.5px solid var(--bg-hover);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Responsive ============================ */
.mobile-only { display: none; }
@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat-panel { display: none; }
  .app:not(.chat-open) .drawer { transform: translateX(105%); } /* keep drawer usable */
  .drawer { width: 82%; }
  .mobile-only { display: flex; }
  .messages { padding-inline: 10px; }
  .composer { padding: 8px 10px 12px; }
  .bubble { max-width: 85%; }
  .media-img { max-width: 78vw; }
  .composer-icon { font-size: 20px; width: 36px; height: 36px; }
}

/* ============================ Phase 1: messaging UX ============================ */
/* messages wrapper (holds scroll-to-bottom button) */
.messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.messages-wrap .messages { flex: 1; }

/* date separator + unread divider */
.date-sep { align-self: center; margin: 8px 0; }
.date-sep span { background: rgba(0,0,0,.14); color: #fff; font-size: 12.5px; padding: 3px 12px; border-radius: 12px; }
[data-theme="dark"] .date-sep span { background: rgba(0,0,0,.4); }
.unread-divider { align-self: stretch; text-align: center; font-size: 12.5px; color: var(--accent);
  border-top: 1px solid var(--accent); margin: 6px 0; position: relative; opacity: .8; }
.unread-divider { background: linear-gradient(var(--bg-panel),var(--bg-panel)) ; }

/* reply block inside a bubble */
.reply-block { border-inline-start: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px;
  background: rgba(51,144,236,.08); border-radius: 4px; cursor: pointer; max-width: 100%; }
.reply-block.deleted { color: var(--text-muted); font-style: italic; cursor: default; }
.reply-name { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.reply-text { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.fwd-from { font-size: 12.5px; color: var(--accent); margin-bottom: 3px; }

/* text formatting */
.bubble-text .inline-code { background: rgba(0,0,0,.08); padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: .92em; }
[data-theme="dark"] .bubble-text .inline-code { background: rgba(255,255,255,.12); }
.bubble-text .code-block { background: rgba(0,0,0,.08); padding: 8px 10px; border-radius: 8px; font-family: monospace;
  font-size: .9em; white-space: pre-wrap; overflow-x: auto; margin: 3px 0; }
[data-theme="dark"] .bubble-text .code-block { background: rgba(0,0,0,.35); }
.msg-link { color: var(--accent); text-decoration: none; }
.msg-link:hover { text-decoration: underline; }
.edited { font-size: 11px; color: var(--text-muted); margin-inline-end: 4px; }
.msg-row.out .edited { color: rgba(0,0,0,.4); }
[data-theme="dark"] .msg-row.out .edited { color: rgba(255,255,255,.5); }

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { border: none; cursor: pointer; background: rgba(0,0,0,.06); border-radius: 12px;
  padding: 1px 8px; font-size: 13px; display: flex; align-items: center; gap: 3px; }
.reaction span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.reaction.mine { background: var(--accent); color: #fff; }
.reaction.mine span { color: #fff; }
[data-theme="dark"] .reaction { background: rgba(255,255,255,.1); }

/* message highlight (jump target) */
.msg-row.highlight .bubble { animation: hl 1.6s ease; }
@keyframes hl { 0%,40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }

/* floating context menu */
.ctx-menu { position: fixed; z-index: 250; background: var(--bg-side); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px; min-width: 180px; }
.ctx-reacts { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.ctx-react { border: none; background: transparent; font-size: 20px; cursor: pointer; border-radius: 8px; padding: 3px 4px; }
.ctx-react:hover { background: var(--bg-hover); transform: scale(1.2); }
.ctx-item { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent;
  color: var(--text); font-size: 14.5px; padding: 9px 12px; border-radius: 8px; cursor: pointer; text-align: start; }
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: #e0564f; }
.ctx-ic { width: 20px; text-align: center; }

/* reply / edit composer bar */
.reply-bar { display: flex; align-items: center; gap: 10px; background: var(--bg-side);
  border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
  border-inline-start: 3px solid var(--accent); }
.reply-bar.editing { border-inline-start-color: #eda86c; }
.reply-bar-icon { font-size: 18px; }
.reply-bar-body { flex: 1; min-width: 0; }
.reply-bar-name { font-size: 13px; font-weight: 600; color: var(--accent); }
.reply-bar-text { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* pinned message bar */
.pinned-bar { display: flex; align-items: center; gap: 10px; padding: 6px 16px;
  background: var(--header-bg); border-bottom: 1px solid var(--border); cursor: pointer; }
.pin-emoji { font-size: 15px; }
.pinned-body { flex: 1; min-width: 0; border-inline-start: 2px solid var(--accent); padding-inline-start: 8px; }
.pinned-title { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.pinned-text { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* scroll-to-bottom button */
.scroll-btn { position: absolute; inset-block-end: 14px; inset-inline-end: 14px; z-index: 5;
  width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--bg-side);
  box-shadow: var(--shadow); font-size: 22px; color: var(--text-muted); cursor: pointer; }
.scroll-btn:hover { color: var(--text); }
.scroll-badge { position: absolute; inset-block-start: -4px; inset-inline-end: -2px; background: var(--badge);
  color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center; }

/* dialog pin / mute indicators */
.mute-icon { font-size: 12px; opacity: .6; }
.pin-icon { font-size: 13px; opacity: .5; }
.dialog-unread.muted { background: var(--text-muted); }

/* ============================ Phase 2: groups & channels ============================ */
/* In-chat message search */
.chat-search {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--header-bg); border-bottom: 1px solid var(--border);
}
.chat-search .search-input { flex: 1; }
.chat-search-results {
  position: absolute; inset-inline: 0; top: 100%; z-index: 20;
  background: var(--bg-side); box-shadow: var(--shadow);
  max-height: 340px; overflow-y: auto; border-bottom: 1px solid var(--border);
}
.chat-search-item { padding: 9px 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.chat-search-item:hover { background: var(--bg-hover); }
.cs-name { font-size: 13px; font-weight: 600; color: var(--accent); display: flex; justify-content: space-between; gap: 8px; }
.cs-time { font-size: 11.5px; color: var(--text-muted); font-weight: 400; }
.cs-text { font-size: 13.5px; color: var(--text); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-text mark { background: rgba(51,144,236,.25); color: inherit; border-radius: 3px; padding: 0 1px; }

/* Admin controls panel (chat info) */
.info-admin { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border); padding: 12px 0; }
.info-admin-btns { display: flex; gap: 8px; }
.info-admin-btns .btn { flex: 1; }
.info-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 14px; padding: 4px 2px; cursor: pointer; }
.info-toggle input { width: 42px; height: 24px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background: var(--bg-hover); border-radius: 12px; position: relative; transition: background .2s; flex-shrink: 0; border: 1px solid var(--border); }
.info-toggle input::after { content: ''; position: absolute; inset-block: 2px; inset-inline-start: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.info-toggle input:checked { background: var(--accent); }
[dir="rtl"] .info-toggle input:checked::after { transform: translateX(-18px); }
[dir="ltr"] .info-toggle input:checked::after { transform: translateX(18px); }

/* Invite link */
.invite-link { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.invite-link .field { font-size: 13px; }
.invite-link-btns { display: flex; gap: 8px; }
.invite-link-btns .btn { flex: 1; }

/* Pending join requests */
.info-requests { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.req-actions { margin-inline-start: auto; display: flex; gap: 6px; }
.req-btn { width: 32px; height: 32px; border-radius: 50%; border: none; font-size: 15px; cursor: pointer; }
.req-btn.ok { background: #4bb34b; color: #fff; }
.req-btn.no { background: var(--bg-hover); color: #e0564f; }
.req-btn:hover { filter: brightness(1.06); }

/* Member row action button (promote/demote/kick) */
.member-menu-btn { margin-inline-start: auto; border: none; background: transparent; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer; flex-shrink: 0; }
.member-menu-btn:hover { background: var(--bg-hover); color: var(--text); }
.picker-item .picker-role + .member-menu-btn { margin-inline-start: 6px; }

/* @mention autocomplete */
.mention-box {
  background: var(--bg-side); border-radius: 12px; box-shadow: var(--shadow);
  margin-bottom: 8px; max-height: 240px; overflow-y: auto; overflow-x: hidden;
}
.mention-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.mention-item:hover { background: var(--bg-hover); }
.mention-item .avatar { width: 36px; height: 36px; font-size: 14px; }
.mention-name { font-size: 14px; font-weight: 600; }
.mention-user { font-size: 12.5px; color: var(--text-muted); }

/* ============================ Phase 3: media polish ============================ */
/* Attach menu */
.attach-menu { background: var(--bg-side); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
  margin-bottom: 8px; width: max-content; }
.attach-item { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent;
  color: var(--text); font-size: 14.5px; padding: 9px 16px 9px 12px; border-radius: 8px; cursor: pointer; text-align: start; }
.attach-item:hover { background: var(--bg-hover); }
.attach-item span { font-size: 18px; width: 22px; text-align: center; }

/* Drag & drop overlay */
.drop-overlay { position: absolute; inset: 0; z-index: 30; background: rgba(51,144,236,.12);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; }
.drop-inner { border: 2.5px dashed var(--accent); border-radius: 16px; padding: 40px 60px; text-align: center;
  color: var(--accent); font-size: 16px; font-weight: 600; background: var(--bg-side); }
.drop-icon { font-size: 44px; margin-bottom: 8px; }

/* Sticker messages (no bubble chrome) */
.bubble.is-sticker { background: transparent !important; box-shadow: none !important; padding: 0 !important; }
.bubble.is-sticker .bubble-meta { padding-inline: 4px; }
.sticker-emoji { font-size: 90px; line-height: 1; user-select: none; }
.sticker-img { max-width: 160px; max-height: 160px; }

/* Photo/video album grid */
.album { display: grid; gap: 3px; border-radius: 10px; overflow: hidden; max-width: min(360px, 74vw); }
.album-1 { grid-template-columns: 1fr; }
.album-2 { grid-template-columns: 1fr 1fr; }
.album-3 { grid-template-columns: 1fr 1fr; }
.album-3 .album-cell:first-child { grid-column: 1 / -1; }
.album-4 { grid-template-columns: 1fr 1fr; }
.album-cell { position: relative; aspect-ratio: 1 / 1; cursor: pointer; overflow: hidden; background: rgba(127,127,127,.12); }
.album-media { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-play { position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,.5); color: #fff; border-radius: 50%; font-size: 18px; pointer-events: none; }
.album-more { position: absolute; inset: 0; background: rgba(0,0,0,.5); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 26px; font-weight: 600; }

/* Voice waveform + playback speed */
.voice-foot { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.voice-speed { border: none; background: rgba(127,127,127,.18); color: var(--text-muted); font-size: 11px;
  font-weight: 600; border-radius: 9px; padding: 1px 7px; cursor: pointer; }
.msg-row.out .voice-speed { background: rgba(0,0,0,.12); }
.waveform { position: relative; display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; }
.wf-bar { flex: 1; min-width: 2px; background: currentColor; opacity: .95; border-radius: 2px; }
.voice.has-wave { color: var(--accent); }
.msg-row.out .voice.has-wave { color: var(--bubble-out-text); }
/* Overlay dims the still-unplayed portion of the waveform (shrinks as it plays). */
.wf-mask { position: absolute; inset-block: -2px; inset-inline-end: 0; width: 100%; background: var(--bubble-in);
  opacity: .6; pointer-events: none; }
.msg-row.out .wf-mask { background: var(--bubble-out); }
.voice.has-wave .voice-dur { color: var(--text-muted); }

/* Open Graph link preview card */
.link-preview { display: flex; gap: 10px; margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  background: rgba(51,144,236,.08); border-inline-start: 3px solid var(--accent); text-decoration: none; color: inherit; max-width: 320px; }
.link-preview:hover { background: rgba(51,144,236,.14); }
.lp-img { width: 56px; height: 56px; border-radius: 6px; background-size: cover; background-position: center; flex-shrink: 0; }
.lp-body { min-width: 0; }
.lp-site { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.lp-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-desc { font-size: 12.5px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Poll bubble */
.poll { min-width: 240px; max-width: 320px; }
.poll-q { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.poll-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.poll-opts { display: flex; flex-direction: column; gap: 8px; }
.poll-opt { border: none; background: transparent; text-align: start; cursor: pointer; padding: 2px 0; width: 100%; color: inherit; }
.poll-opt-top { display: flex; align-items: center; gap: 6px; font-size: 13.5px; margin-bottom: 3px; }
.poll-check { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent);
  font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.poll-opt.mine .poll-check { background: var(--accent); color: #fff; }
.poll-opt-text { flex: 1; }
.poll-pct { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.poll-bar { display: block; height: 5px; background: rgba(127,127,127,.2); border-radius: 3px; overflow: hidden; }
.poll-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.poll-total { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* Poll create modal */
.poll-options { display: flex; flex-direction: column; gap: 8px; }
.poll-opt-row { display: flex; align-items: center; gap: 8px; }
.poll-opt-row .field { flex: 1; }
.poll-opt-del { border: none; background: transparent; color: var(--text-muted); font-size: 15px; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; }
.poll-opt-del:hover { background: var(--bg-hover); color: #e0564f; }

/* ============================ Phase 4/5: presence, notifications, privacy ============================ */
/* Online dot on avatars */
.avatar { position: relative; }
.avatar.online::after {
  content: ''; position: absolute; inset-block-end: 1px; inset-inline-end: 1px;
  width: 12px; height: 12px; border-radius: 50%; background: #4bb34b; border: 2px solid var(--bg-side);
}
.chat-header .avatar.online::after { border-color: var(--header-bg); }
.modal .avatar.online::after, #user-avatar.online::after { border-color: var(--bg); }

/* "typing…" in the chat list */
.dialog-preview.typing { color: var(--accent); font-style: italic; }
.dialog.active .dialog-preview.typing { color: #d6e9ff; }

/* User profile modal */
.user-fields { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.user-field { display: flex; justify-content: space-between; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.uf-label { color: var(--text-muted); font-size: 13.5px; }
.uf-val { font-size: 14.5px; font-weight: 500; text-align: end; word-break: break-word; }

/* Privacy & security modal */
.priv-section { padding: 10px 0; border-bottom: 1px solid var(--border); }
.priv-section:last-of-type { border-bottom: none; }
.priv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.priv-head .btn { padding: 4px 10px; font-size: 13px; }
.priv-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; padding: 6px 2px; }
.priv-select {
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 14px; padding: 6px 10px; cursor: pointer; outline: none;
}
.priv-select:focus { border-color: var(--accent); }

/* Active sessions */
.sessions-list { display: flex; flex-direction: column; gap: 2px; }
.session-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.session-row:last-child { border-bottom: none; }
.session-info { flex: 1; min-width: 0; }
.session-dev { font-size: 14px; font-weight: 500; }
.session-current { color: #4bb34b; font-size: 12px; font-weight: 600; }
.session-time { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Wallpaper picker */
.wallpaper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.wp-cell {
  height: 92px; border-radius: 12px; border: 2px solid transparent; cursor: pointer; position: relative;
  overflow: hidden; display: flex; align-items: flex-end; justify-content: center; background-size: cover;
}
.wp-cell.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.wp-label { width: 100%; text-align: center; font-size: 12px; color: #333; background: rgba(255,255,255,.75);
  padding: 3px 0; backdrop-filter: blur(2px); }
