:root {
  /* رنگ‌های تم با جاوااسکریپت تنظیم می‌شوند؛ این‌ها مقادیر پیش‌فرض (یاسی) هستند */
  --h: 254; --s: 88%; --bh: 258; --ch: 258;
  --msg-size: 15px;
  --msg-font: 'Vazirmatn', Tahoma, sans-serif;
  color-scheme: light;
  --primary: hsl(var(--h) var(--s) 64%);
  --primary-strong: hsl(var(--h) var(--s) 54%);
  --primary-soft: hsl(var(--h) 100% 96%);
  --active-bg: hsl(var(--h) var(--s) 64%);
  --pill-out-mine-text: #ffffff;
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1d1730;
  --muted: #7d7690;
  --border: #ece8f5;
  --hover: hsl(var(--h) 40% 97%);
  --field-border: hsl(var(--h) 25% 88%);
  --search-bg: hsl(var(--h) 35% 96%);
  --in-bg: #ffffff;
  --out-bg: hsl(var(--bh) 100% 94%);
  --out-meta: hsl(var(--bh) 62% 55%);
  --in-meta: #a39cb6;
  --pill-in: hsl(var(--h) 100% 96%);
  --pill-in-text: hsl(var(--h) var(--s) 52%);
  --pill-out: hsl(var(--bh) 85% 87%);
  --pill-out-text: hsl(var(--bh) 55% 40%);
  --online: #3cc36e;
  --shadow: 0 1px 2px hsl(var(--h) 50% 30% / .14);
  --chat-bg: linear-gradient(150deg, hsl(var(--ch) 85% 93%) 0%, hsl(var(--ch) 75% 87%) 38%, hsl(var(--ch) 85% 95%) 68%, hsl(var(--ch) 70% 85%) 100%);
  --pattern: rgba(255, 255, 255, .45);
  --service-bg: hsl(var(--ch) 45% 40% / .42);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
  color-scheme: dark;
  --primary: hsl(var(--h) 100% 76%);
  --primary-strong: hsl(var(--h) 100% 82%);
  --primary-soft: hsl(var(--h) 30% 21%);
  --active-bg: hsl(var(--h) 50% 50%);
  --pill-out-mine-text: hsl(var(--bh) 60% 18%);
  --bg: hsl(var(--h) 22% 12%);
  --surface: hsl(var(--h) 22% 12%);
  --text: #f3f0fa;
  --muted: hsl(var(--h) 12% 62%);
  --border: hsl(var(--h) 25% 8%);
  --hover: hsl(var(--h) 22% 17%);
  --field-border: hsl(var(--h) 20% 27%);
  --search-bg: hsl(var(--h) 22% 17%);
  --in-bg: hsl(var(--h) 22% 17%);
  --out-bg: hsl(var(--bh) 45% 42%);
  --out-meta: hsl(var(--bh) 90% 88%);
  --in-meta: hsl(var(--h) 10% 58%);
  --pill-in: hsl(var(--h) 30% 26%);
  --pill-in-text: hsl(var(--h) 100% 85%);
  --pill-out: hsl(var(--bh) 45% 55%);
  --pill-out-text: #ffffff;
  --online: #4cd683;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --chat-bg: linear-gradient(150deg, hsl(var(--ch) 30% 8%) 0%, hsl(var(--ch) 35% 13%) 50%, hsl(var(--ch) 30% 7%) 100%);
  --pattern: hsl(var(--ch) 100% 80% / .05);
  --service-bg: hsl(var(--ch) 30% 25% / .85);
  }
}
:root[data-scheme="dark"] {
  color-scheme: dark;
  --primary: hsl(var(--h) 100% 76%);
  --primary-strong: hsl(var(--h) 100% 82%);
  --primary-soft: hsl(var(--h) 30% 21%);
  --active-bg: hsl(var(--h) 50% 50%);
  --pill-out-mine-text: hsl(var(--bh) 60% 18%);
  --bg: hsl(var(--h) 22% 12%);
  --surface: hsl(var(--h) 22% 12%);
  --text: #f3f0fa;
  --muted: hsl(var(--h) 12% 62%);
  --border: hsl(var(--h) 25% 8%);
  --hover: hsl(var(--h) 22% 17%);
  --field-border: hsl(var(--h) 20% 27%);
  --search-bg: hsl(var(--h) 22% 17%);
  --in-bg: hsl(var(--h) 22% 17%);
  --out-bg: hsl(var(--bh) 45% 42%);
  --out-meta: hsl(var(--bh) 90% 88%);
  --in-meta: hsl(var(--h) 10% 58%);
  --pill-in: hsl(var(--h) 30% 26%);
  --pill-in-text: hsl(var(--h) 100% 85%);
  --pill-out: hsl(var(--bh) 45% 55%);
  --pill-out-text: #ffffff;
  --online: #4cd683;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --chat-bg: linear-gradient(150deg, hsl(var(--ch) 30% 8%) 0%, hsl(var(--ch) 35% 13%) 50%, hsl(var(--ch) 30% 7%) 100%);
  --pattern: hsl(var(--ch) 100% 80% / .05);
  --service-bg: hsl(var(--ch) 30% 25% / .85);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.ltr { direction: ltr; text-align: left; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon-btn {
  width: 40px; height: 40px; border: none; background: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted); flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); }

/* ───────── ورود / ثبت‌نام ───────── */
.auth {
  position: fixed; inset: 0; overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 20px; background: var(--bg);
}
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.logo {
  display: block; width: 120px; height: 120px; margin: 0 auto 22px;
  filter: drop-shadow(0 10px 24px rgba(139, 108, 246, .35));
}
.brand { font-size: 32px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 8px; color: var(--primary-strong); }
.auth .sub { color: var(--muted); margin-bottom: 32px; line-height: 1.6; }
.auth .signup-only { display: none; }
.auth.signup .signup-only { display: block; }
.auth.signup .login-only { display: none; }

.field { position: relative; margin-bottom: 18px; text-align: right; }
.field input {
  width: 100%; height: 54px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--field-border); background: transparent; font-size: 16px;
  transition: border-color .15s;
}
.field input:hover { border-color: var(--primary); }
.field input:focus { outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.field label {
  position: absolute; right: 14px; top: 27px; transform: translateY(-50%);
  padding: 0 4px; color: var(--muted); background: var(--bg); pointer-events: none;
  transition: top .15s, font-size .15s, color .15s;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label { top: 0; font-size: 13px; }
.field input:focus + label { color: var(--primary); }
.field.error input { border-color: #e53935; box-shadow: inset 0 0 0 1px #e53935; }
.field.error label { color: #e53935; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 4px 0; }
.hint.good { color: var(--online); }
.hint.bad { color: #e53935; }
.form-error { min-height: 22px; color: #e53935; font-size: 14px; margin-bottom: 8px; }

.btn-primary {
  width: 100%; height: 54px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.switch { margin-top: 22px; color: var(--muted); }
.switch a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ───────── چیدمان اصلی ───────── */
.app { display: flex; height: 100%; height: 100dvh; }

.sidebar {
  width: 380px; min-width: 300px; max-width: 40%;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); position: relative;
}
.sidebar-header {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
}
.search-box {
  flex: 1; display: flex; align-items: center; gap: 8px; height: 42px;
  padding: 0 14px; border-radius: 22px; background: var(--search-bg); color: var(--muted);
  border: 2px solid transparent;
}
.search-box:focus-within { border-color: var(--primary); background: var(--surface); color: var(--primary); }
.search-box input { flex: 1; min-width: 0; border: none; background: none; outline: none; color: var(--text); }
.search-clear { border: none; background: none; font-size: 22px; line-height: 1; color: var(--muted); }

.menu {
  position: absolute; top: 56px; right: 10px; z-index: 30; width: 270px;
  background: var(--surface); border-radius: 12px; padding: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .18); animation: drop .15s ease-out;
}
@keyframes drop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.menu-profile {
  display: flex; gap: 12px; align-items: center; padding: 8px; width: 100%;
  border: none; background: none; border-radius: 10px; text-align: right;
}
.menu-profile:hover { background: var(--hover); }
.menu-profile .name { font-weight: 600; }
.menu-profile .sub { color: var(--muted); font-size: 13px; direction: ltr; text-align: right; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: right;
  border: none; background: none; padding: 10px 12px; border-radius: 8px; margin-top: 2px;
}
.menu-item svg { color: var(--muted); }
.menu-item.danger svg { color: inherit; }
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: #e53935; }

.list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.section-title { color: var(--muted); font-size: 14px; font-weight: 500; padding: 8px 10px; }
.list-empty { color: var(--muted); text-align: center; padding: 40px 20px; line-height: 1.9; }

.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border-radius: 12px; cursor: pointer; user-select: none;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active-bg); color: #fff; }
.chat-item.active .ci-preview, .chat-item.active .ci-time, .chat-item.active .you,
.chat-item.active .typing-text, .chat-item.active .tick { color: #fff !important; }
.chat-item.active .badge { background: #fff; color: var(--primary); }
.chat-item.active .avatar .dot { border-color: var(--active-bg); }
.ci-body { flex: 1; min-width: 0; }
.ci-top, .ci-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ci-bottom { margin-top: 3px; }
.ci-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--muted); flex-shrink: 0; display: flex; align-items: center; gap: 3px; }
.ci-time .tick { color: var(--online); }
.ci-preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-preview.username { direction: ltr; }
.ci-preview b { color: var(--primary); font-weight: 600; }
.you { color: var(--primary); }
.typing-text { color: var(--primary); }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center; flex-shrink: 0;
}

.avatar {
  --size: 54px;
  width: var(--size); height: var(--size); border-radius: 50%; flex-shrink: 0; position: relative;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: calc(var(--size) * .36);
  background-image: linear-gradient(rgba(255, 255, 255, .18), rgba(0, 0, 0, .06));
}
.avatar.sm { --size: 42px; }
.avatar.xl { --size: 120px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar .dot {
  position: absolute; bottom: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--surface);
}

/* ───────── صفحه گفتگو ───────── */
.chat {
  flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column;
  background: var(--chat-bg);
}
.chat::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(var(--pattern) 2px, transparent 2.5px),
    radial-gradient(var(--pattern) 1.5px, transparent 2px);
  background-size: 46px 46px, 46px 46px;
  background-position: 0 0, 23px 23px;
}
.empty-state {
  margin: auto; position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-title { font-size: 26px; font-weight: 800; color: #fff; text-shadow: 0 2px 10px rgba(80, 50, 170, .35); margin-bottom: 4px; }
.empty-state span, .no-messages {
  display: inline-block; background: var(--service-bg); color: #fff;
  padding: 6px 14px; border-radius: 16px; font-size: 14px; font-weight: 500;
}
.chat-view { position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px;
  padding-top: env(safe-area-inset-top); box-sizing: content-box;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.back-btn { display: none; }
.ch-peer {
  display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1;
  border: none; background: none; text-align: right; padding: 6px; margin: -6px; border-radius: 10px;
}
.ch-info { min-width: 0; display: flex; flex-direction: column; }
.ch-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; color: var(--muted); }
.status.online { color: var(--primary); }

.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px max(14px, calc((100% - 740px) / 2));
}
.no-messages { margin: auto; text-align: center; padding: 16px 24px; line-height: 1.8; }
.date-sep {
  align-self: center; position: sticky; top: 4px; z-index: 2;
  background: var(--service-bg); color: #fff; font-size: 13px; font-weight: 500;
  padding: 2px 10px; border-radius: 12px; margin: 10px 0 6px;
}

.msg { display: flex; align-items: flex-end; gap: 6px; }
.msg.out { justify-content: flex-start; }   /* در RTL یعنی سمت راست */
.msg.in  { justify-content: flex-end; }     /* در RTL یعنی سمت چپ */
.msg.in .msg-actions { order: -1; }
.msg.tail { margin-bottom: 6px; }
.msg.appear .bubble { animation: appear .2s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(8px) scale(.97); } }

.bubble {
  position: relative; max-width: min(480px, 80%); min-width: 70px;
  padding: 6px 10px 5px; border-radius: 14px; box-shadow: var(--shadow);
  background: var(--in-bg);
}
.msg.out .bubble { background: var(--out-bg); }
.msg.out.tail .bubble { border-bottom-right-radius: 4px; }
.msg.in.tail .bubble { border-bottom-left-radius: 4px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; font-family: var(--msg-font); font-size: var(--msg-size); }
.text a { color: var(--primary); }
.msg.out .text a { color: var(--out-meta); }
.meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 3px;
  direction: ltr; font-size: 11.5px; color: var(--in-meta); margin-top: 1px; user-select: none;
}
.msg.out .meta { color: var(--out-meta); }
.tick { font-size: 12px; letter-spacing: -4px; padding-right: 4px; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reactions:empty { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 9px 0 7px;
  border: none; border-radius: 14px; background: var(--pill-in); color: var(--pill-in-text);
  font-size: 13px; font-weight: 600; animation: pop .25s cubic-bezier(.3, 1.6, .5, 1);
}
.pill .pe { font-size: 16px; line-height: 1; }
.pill.mine { background: var(--primary); color: #fff; }
.msg.out .pill { background: var(--pill-out); color: var(--pill-out-text); }
.msg.out .pill.mine { background: var(--out-meta); color: var(--pill-out-mine-text); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }


@media (hover: none) {
  .msg-actions { display: none !important; }
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}


.composer {
  position: relative; display: flex; align-items: flex-end; gap: 8px; flex-shrink: 0;
  padding: 6px max(14px, calc((100% - 740px) / 2)) max(12px, env(safe-area-inset-bottom));
}

.send-btn {
  width: 50px; height: 50px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  box-shadow: var(--shadow); transition: transform .1s;
}
.send-btn svg { transform: scaleX(-1); }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .6; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); z-index: 60;
  background: rgba(0, 0, 0, .78); color: #fff; padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────── موبایل ───────── */
@media (max-width: 760px) {
  .sidebar { width: 100%; max-width: none; border: none; }
  .chat { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat { display: flex; }
  .back-btn { display: grid; }
  .chat-header { padding: 0 6px; }
  .bubble { max-width: 85%; }
}

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

/* ───────── پنل ویرایش پروفایل ───────── */
.panel {
  position: absolute; inset: 0; z-index: 25; background: var(--surface);
  display: flex; flex-direction: column; animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(-24px); opacity: 0; } }
.panel-header {
  display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 12px;
  padding-top: env(safe-area-inset-top); box-sizing: content-box; flex-shrink: 0;
}
.panel-header h2 { font-size: 19px; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 20px 28px; }
.avatar-edit {
  position: relative; width: 120px; height: 120px; margin: 8px auto 6px; border-radius: 50%; overflow: hidden;
}
.avatar-edit.busy { opacity: .5; pointer-events: none; }
.avatar-cam {
  position: absolute; inset: 0; display: grid; place-items: center; cursor: pointer;
  background: rgba(30, 15, 70, .35); transition: background .15s;
}
.avatar-cam:hover { background: rgba(30, 15, 70, .5); }
.avatar-cam svg { transition: transform .15s; }
.avatar-cam:hover svg { transform: scale(1.12); }
.link-btn {
  display: block; margin: 0 auto 18px; border: none; background: none;
  color: #e5484d; font-size: 14px; padding: 4px 8px;
}
#removeAvatar.hidden + .field { margin-top: 22px; }
.panel .field label { background: var(--surface); }
.counter {
  position: absolute; left: 14px; top: 27px; transform: translateY(-50%);
  font-size: 13px; color: var(--muted); pointer-events: none;
}
.field-note { color: var(--muted); font-size: 13px; line-height: 1.7; margin: -8px 4px 22px; }
#p-bio { padding-left: 44px; }

/* ───────── پروفایل کاربر مقابل ───────── */
.modal {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 10, 45, .45); animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative; width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 18px; overflow: hidden; box-shadow: 0 20px 60px rgba(40, 20, 100, .3);
  animation: pickerIn .18s ease-out;
}
.modal-close { position: absolute; top: 10px; left: 10px; z-index: 2; color: #fff; }
.modal-close:hover { background: rgba(255, 255, 255, .18); }
.profile-hero {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 20px 22px;
  background: linear-gradient(160deg, hsl(var(--h) 100% 82%), hsl(var(--h) var(--s) 62%)); color: #fff; text-align: center;
}
.profile-hero .avatar { box-shadow: 0 0 0 4px rgba(255, 255, 255, .45), 0 8px 24px rgba(40, 20, 110, .3); margin-bottom: 10px; }
.profile-hero .p-name { font-size: 21px; font-weight: 700; }
.profile-hero .p-status { font-size: 14px; opacity: .9; }
.info-rows { padding: 8px; }
.info-row {
  display: flex; gap: 16px; align-items: flex-start; width: 100%; padding: 10px 12px;
  border: none; background: none; border-radius: 10px; text-align: right;
}
button.info-row:hover { background: var(--hover); }
.info-row svg { color: var(--muted); flex-shrink: 0; margin-top: 2px; }
.info-row .val { line-height: 1.6; overflow-wrap: anywhere; }
.info-row .lbl { color: var(--muted); font-size: 13px; }
.profile-actions { padding: 0 16px 18px; }

.avatar-edit .avatar:not(:has(img)) { font-size: 0; }

/* ───────── دکمه‌های کنار پیام (دسکتاپ) ───────── */
.msg-actions { display: flex; flex-direction: column; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.act-btn {
  width: 30px; height: 30px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--service-bg); color: #fff; font-size: 16px; line-height: 1;
  display: grid; place-items: center;
}
.act-btn:hover { filter: brightness(1.15); }

/* ───────── نقل‌قول پاسخ ───────── */
.reply-quote {
  display: block; margin: 2px 0 5px; padding: 4px 10px 4px 8px; border-radius: 6px; cursor: pointer;
  border-right: 3px solid var(--primary); background: var(--primary-soft); max-width: 100%; overflow: hidden;
}
.msg.out .reply-quote { border-right-color: var(--out-meta); background: hsl(var(--bh) 70% 50% / .12); }
.rq-name { font-size: 13px; font-weight: 600; color: var(--primary-strong); }
.msg.out .rq-name { color: var(--out-meta); }
.rq-text {
  font-size: calc(var(--msg-size) - 1.5px); font-family: var(--msg-font);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85;
}
.msg.flash .bubble { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px hsl(var(--h) 90% 65% / .55); } }

.mention { color: var(--primary-strong); text-decoration: none; font-weight: 500; unicode-bidi: isolate; }
.msg.out .mention { color: var(--out-meta); }
.mention:hover { text-decoration: underline; }

/* ───────── عکس و فایل داخل پیام ───────── */
.bubble.has-media { padding: 4px; }
.bubble.has-media > .text, .bubble.has-media > .reactions, .bubble.has-media > .meta,
.bubble.has-media > .reply-quote { margin-right: 6px; margin-left: 6px; }
.bubble.has-media > .text { margin-top: 4px; }
.media { display: block; position: relative; border-radius: 11px; overflow: hidden; background: hsl(var(--h) 30% 85% / .4); }
.media img { display: block; width: 100%; height: auto; max-height: 460px; object-fit: cover; }
.meta.on-media {
  position: absolute; bottom: 6px; left: 6px; padding: 1px 7px; border-radius: 10px;
  background: rgba(0, 0, 0, .45); color: #fff !important; margin: 0;
}
.file {
  display: flex; align-items: center; gap: 12px; padding: 4px 2px 2px; color: inherit; text-decoration: none; min-width: 200px;
}
.file-icon {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--primary); color: #fff; transition: transform .15s;
}
.msg.out .file-icon { background: var(--out-meta); color: var(--out-bg); }
.file:hover .file-icon { transform: scale(1.06); }
.file-info { min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.file-size { font-size: 13px; color: var(--in-meta); }
.msg.out .file-size { color: var(--out-meta); }

/* ───────── نوار پاسخ و پیوست بالای کادر پیام ───────── */
.composer-main {
  flex: 1; min-width: 0; background: var(--in-bg); border-radius: 18px 18px 6px 18px; box-shadow: var(--shadow);
}
.input-row { display: flex; align-items: flex-end; padding: 6px 16px 6px 6px; }
.input-row textarea {
  flex: 1; border: none; outline: none; background: none; resize: none; padding: 6px 0;
  font-family: var(--msg-font); font-size: max(16px, var(--msg-size)); line-height: 1.45; max-height: 160px;
}
.attach-btn { width: 36px; height: 36px; }
.attach-btn:hover { color: var(--primary); }
.compose-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px 6px;
  border-bottom: 1px solid var(--border); animation: barIn .15s ease-out;
}
@keyframes barIn { from { opacity: 0; transform: translateY(6px); } }
.cb-icon { color: var(--primary); flex-shrink: 0; }
.cb-body {
  flex: 1; min-width: 0; border-right: 2px solid var(--primary); padding-right: 8px;
}
.cb-title { font-size: 14px; font-weight: 600; color: var(--primary-strong); }
.cb-text { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-close { width: 32px; height: 32px; font-size: 22px; }
.cb-thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--hover);
  display: grid; place-items: center; color: var(--primary);
}
.progress { height: 3px; border-radius: 2px; background: var(--hover); margin-top: 5px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .15s; }
.cb-text.error { color: #e5484d; }

.attach-menu {
  position: absolute; bottom: calc(100% - 4px); left: max(78px, calc((100% - 740px) / 2 + 64px)); z-index: 30;
  background: var(--surface); border-radius: 12px; padding: 6px; min-width: 160px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .18); animation: drop .15s ease-out;
}

.drop-overlay {
  position: absolute; inset: 10px; z-index: 40; border-radius: 16px; display: grid; place-items: center;
  border: 2px dashed var(--primary); background: hsl(var(--h) 100% 97% / .85); color: var(--primary-strong);
  font-size: 18px; font-weight: 600; pointer-events: none;
}

/* ───────── منوی پیام (کلیک راست / لمس طولانی) ───────── */
.ctx-menu {
  position: fixed; z-index: 50; background: var(--surface); border-radius: 14px; min-width: 210px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, .22); overflow: hidden; animation: pickerIn .16s ease-out;
}
@keyframes pickerIn { from { opacity: 0; transform: scale(.88); } }
.ctx-reactions { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.ctx-reactions button {
  width: 38px; height: 38px; border: none; background: none; border-radius: 50%;
  font-size: 23px; line-height: 1; transition: transform .12s;
}
.ctx-reactions button:hover { transform: scale(1.22); }
.ctx-reactions button.chosen { background: var(--hover); }
.ctx-items { padding: 4px; }
.ctx-items .menu-item { margin: 0; padding: 9px 12px; }

/* ───────── نمایش عکس در اندازه‌ی بزرگ ───────── */
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(8, 4, 20, .92);
  display: grid; place-items: center; animation: fade .15s ease-out;
}
.lightbox img { max-width: 94vw; max-height: 86vh; border-radius: 6px; object-fit: contain; }
.lb-bar { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; display: flex; gap: 6px; }
.lb-btn { color: #fff; }
.lb-btn:hover { background: rgba(255, 255, 255, .12); }

/* ───────── تنظیمات ───────── */
.settings-preview {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px 12px;
  border-radius: 16px; background: var(--chat-bg); margin-bottom: 22px; overflow: hidden;
}
.settings-preview .bubble { max-width: 85%; }
.set-title { font-size: 15px; font-weight: 600; color: var(--primary-strong); margin: 0 4px 10px; }
.range-row { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; padding: 0 4px; }
.range-row input { flex: 1; accent-color: var(--primary); }
.a-small { font-size: 12px; color: var(--muted); }
.a-big { font-size: 20px; color: var(--muted); }
.range-val {
  min-width: 34px; text-align: center; font-size: 13px; font-weight: 600; color: var(--primary-strong);
  background: var(--primary-soft); border-radius: 8px; padding: 2px 6px;
}
.option-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 24px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border: none; background: none; border-radius: 10px; text-align: right;
}
.option:hover { background: var(--hover); }
.option .radio {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--field-border); flex-shrink: 0;
  display: grid; place-items: center;
}
.option.selected .radio { border-color: var(--primary); }
.option.selected .radio::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.option .sample { margin-right: auto; color: var(--muted); font-size: 16px; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 24px; }
.swatch {
  border: 2px solid transparent; border-radius: 14px; padding: 4px; background: none;
  display: flex; flex-direction: column; gap: 6px; align-items: stretch;
}
.swatch.selected { border-color: var(--primary); }
.sw-preview {
  height: 64px; border-radius: 10px; position: relative; overflow: hidden;
  background: linear-gradient(150deg, hsl(var(--ch) 85% 90%), hsl(var(--ch) 70% 82%));
}
.sw-preview::before, .sw-preview::after { content: ""; position: absolute; height: 14px; border-radius: 7px; }
.sw-preview::before { top: 12px; left: 10px; width: 46%; background: #fff; }
.sw-preview::after { bottom: 12px; right: 10px; width: 52%; background: hsl(var(--bh) 100% 93%); box-shadow: inset 0 0 0 2px hsl(var(--h) 85% 64%); }
.sw-label { font-size: 13px; color: var(--muted); }
.swatch.selected .sw-label { color: var(--primary-strong); font-weight: 600; }
.segmented {
  display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--search-bg); margin-bottom: 12px;
}
.segmented button {
  flex: 1; border: none; background: none; padding: 9px 6px; border-radius: 9px; color: var(--muted); font-weight: 500;
}
.segmented button.selected { background: var(--surface); color: var(--primary-strong); box-shadow: var(--shadow); }

/* ───────── تیک آبی ───────── */
.vtick { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -3px; margin-inline-start: 3px; }
.ci-name, .ch-name, .au-name { display: flex; align-items: center; min-width: 0; }
.ci-name .uname, .ch-name .uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-hero .vtick { width: 20px; height: 20px; vertical-align: -4px; }

/* ───────── «در حال نوشتن» با سه نقطه‌ی متحرک ───────── */
.dots { display: inline-flex; gap: 2px; margin-inline-start: 3px; vertical-align: middle; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dotb 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dotb { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* ───────── کشیدن برای پاسخ ───────── */
.bubble { transition: transform .22s cubic-bezier(.2, .9, .3, 1.2); }
.bubble.swiping { transition: none; }
.swipe-reply {
  position: absolute; top: 50%; right: -44px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: var(--service-bg);
  opacity: 0; transform: translateY(-50%) scale(.4); transition: background .15s; pointer-events: none;
}
.swipe-reply.ready { background: var(--primary); }

/* ───────── فرم ورود: رمز ───────── */
.pw-toggle {
  position: absolute; left: 8px; top: 27px; transform: translateY(-50%); width: 38px; height: 38px;
  border: none; background: none; border-radius: 50%; color: var(--muted); display: grid; place-items: center;
}
.pw-toggle.on { color: var(--primary); }
.field:has(.pw-toggle) input { padding-left: 48px; }
.pw-rules { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 18px; }
.pw-rules li {
  font-size: 12.5px; padding: 3px 10px; border-radius: 12px; background: var(--search-bg); color: var(--muted);
  transition: background .15s, color .15s;
}
.pw-rules li::before { content: "○ "; }
.pw-rules li.ok { background: hsl(140 60% 92%); color: #1e8e4a; }
.pw-rules li.ok::before { content: "✓ "; }

/* ───────── منو ───────── */
.menu-count {
  margin-right: auto; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary-strong);
}
.menu-count:empty { display: none; }

/* ───────── دستگاه‌ها ───────── */
.device-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.device { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 12px; }
.device:hover { background: var(--hover); }
.device-icon {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-strong);
}
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 600; }
.device-meta { font-size: 13px; color: var(--muted); }
.online-txt { color: var(--primary-strong); font-weight: 500; }
.device-out {
  border: 1px solid #e5484d55; background: none; color: #e5484d; border-radius: 9px; padding: 5px 12px; font-size: 13px;
}
.device-out:hover { background: #e5484d14; }
.danger-btn {
  width: 100%; height: 46px; border-radius: 10px; border: 1px solid #e5484d; background: none; color: #e5484d;
  font-weight: 600; margin-bottom: 6px;
}
.danger-btn:hover { background: #e5484d12; }

/* ───────── پنل مدیریت ───────── */
.admin {
  position: fixed; inset: 0; z-index: 75; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 10, 45, .45); animation: fade .15s ease-out;
}
.admin-inner {
  width: min(1040px, 100%); height: min(92vh, 920px); background: var(--surface); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(40, 20, 100, .3);
}
.admin-head { display: flex; align-items: center; gap: 16px; padding: 12px 16px 12px 20px; border-bottom: 1px solid var(--border); }
.admin-head h2 { font-size: 20px; font-weight: 700; }
.admin-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--search-bg); margin-right: auto; }
.admin-tabs button { border: none; background: none; padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.admin-tabs button.selected { background: var(--surface); color: var(--primary-strong); box-shadow: var(--shadow); }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 16px 20px; }
.stat { background: var(--primary-soft); border-radius: 12px; padding: 12px 14px; }
.stat-n { font-size: 22px; font-weight: 700; color: var(--primary-strong); }
.stat-l { font-size: 13px; color: var(--muted); margin-top: 2px; }
.admin-tab { flex: 1; min-height: 0; overflow-y: auto; padding: 0 20px 20px; }
.admin-search { margin: 0 0 10px; height: 40px; }
.au-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; }
.au-row:hover { background: var(--hover); }
.au-row.banned { opacity: .6; }
.au-open { border: none; background: none; padding: 0; border-radius: 50%; }
.au-main { flex: 1; min-width: 0; }
.au-name { gap: 6px; font-weight: 600; }
.au-sub { font-size: 13px; color: var(--muted); }
.chip { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--primary-soft); color: var(--primary-strong); }
.chip.red { background: #e5484d1c; color: #e5484d; }
.au-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 430px; }
.au-btn {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--field-border); background: var(--surface);
  border-radius: 9px; padding: 5px 10px; font-size: 13px;
}
.au-btn:hover { border-color: var(--primary); color: var(--primary-strong); }
.au-btn .vtick { margin: 0; width: 15px; height: 15px; }
.au-btn.on { background: #3b9cf514; border-color: #3b9cf5; }
.au-btn.red { color: #e5484d; border-color: #e5484d66; }
.ev { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.ev-icon {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 700;
  background: var(--primary-soft); color: var(--primary-strong);
}
.ev-icon.signup { background: hsl(140 60% 92%); color: #1e8e4a; }
.ev-body { flex: 1; min-width: 0; }
.ev-body > div:first-child { display: flex; align-items: center; gap: 4px; font-weight: 600; }
.ev-user { font-weight: 400; color: var(--muted); font-size: 13px; }
.ev-what { font-size: 13px; color: var(--muted); }
.ev-time { font-size: 12.5px; color: var(--muted); flex-shrink: 0; }

@media (max-width: 760px) {
  .admin { padding: 0; }
  .admin-inner { height: 100%; border-radius: 0; }
  .admin-head { flex-wrap: wrap; padding-top: max(12px, env(safe-area-inset-top)); }
  .admin-tabs { order: 3; margin: 0; width: 100%; }
  .admin-tabs button { flex: 1; }
  .admin-head .icon-btn { margin-right: auto; }
  .admin-inner { overflow-y: auto; }
  .admin-head { position: sticky; top: 0; z-index: 2; background: var(--surface); }
  .admin-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 12px 14px; }
  .stat { padding: 8px 12px; }
  .stat-n { font-size: 18px; }
  .admin-tab { flex: none; overflow: visible; min-height: auto; padding: 0 14px 20px; }
  .au-row { flex-wrap: wrap; }
  .au-actions { width: 100%; justify-content: flex-start; max-width: none; padding-right: 54px; }
}
