/* ───────── فونت ───────── */
@font-face {
  font-family: Vazirmatn;
  src: url(/fonts/Vazirmatn-Medium.ttf) format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url(/fonts/Vazirmatn-Bold.ttf) format("truetype");
  font-weight: 700;
  font-display: swap;
}

/* ───────── متغیرها ───────── */
:root {
  --brand: #2f6bff;
  --brand-2: #7b5cf0;
  --brand-soft: #eaf0ff;
  --bg: #f2f4f9;
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --text: #10141f;
  --muted: #6b7280;
  --line: #e6e9f2;
  --mine: linear-gradient(135deg, #2f6bff, #5a7dff);
  --theirs: #ffffff;
  --ok: #16a34a;
  --danger: #e5484d;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(16, 24, 64, .08);
}

[data-theme="dark"] {
  --brand: #4b82ff;
  --brand-2: #8b6cff;
  --brand-soft: #1b2440;
  --bg: #0d1017;
  --panel: #151a24;
  --panel-2: #1b2130;
  --text: #eef1f8;
  --muted: #8b93a7;
  --line: #232a38;
  --mine: linear-gradient(135deg, #2b5bd6, #4a63d8);
  --theirs: #1d2431;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, system-ui, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ───────── ورود ───────── */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(47, 107, 255, .18), transparent 60%),
    radial-gradient(700px 400px at 10% 110%, rgba(123, 92, 240, .16), transparent 60%),
    var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 44px; height: 44px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -.3px; }
.sub { color: var(--muted); font-size: 13px; margin: 10px 0 18px; }

.seg {
  display: flex;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.seg button {
  flex: 1;
  padding: 9px 0;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  transition: .18s;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); font-weight: 700; }

.field { display: block; margin-bottom: 13px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--panel-2);
  outline: none;
  transition: .16s;
}
.field input:focus { border-color: var(--brand); background: var(--panel); box-shadow: 0 0 0 4px var(--brand-soft); }

.primary {
  background: var(--brand);
  color: #fff;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 700;
  transition: .16s;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: scale(.98); }
.primary.big { width: 100%; padding: 13px; margin-top: 6px; }

.err {
  margin-top: 12px;
  background: rgba(229, 72, 77, .1);
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}

/* ───────── چیدمان اپ ───────── */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

/* ───────── ستون کنار ───────── */
.side {
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  gap: 8px;
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-txt { display: flex; flex-direction: column; min-width: 0; }
.me-txt b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-txt small { color: var(--muted); font-size: 11.5px; display: flex; align-items: center; gap: 5px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .16); }

.side-actions { display: flex; gap: 2px; }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex: 0 0 auto;
  user-select: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 36px; height: 36px; border-radius: 12px; font-size: 14px; }
.avatar.xs { width: 30px; height: 30px; border-radius: 10px; font-size: 12.5px; }
.avatar.big { width: 84px; height: 84px; border-radius: 26px; font-size: 30px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

.search {
  position: relative;
  margin: 4px 14px 10px;
}
.search input {
  width: 100%;
  padding: 10px 38px 10px 12px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--panel-2);
  outline: none;
}
.search input:focus { border-color: var(--brand); background: var(--panel); }
.search-ico { position: absolute; inset-inline-start: 11px; top: 10px; width: 18px; height: 18px; color: var(--muted); }

.convs { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.conv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 14px;
  cursor: pointer;
  transition: .13s;
  width: 100%;
  text-align: start;
}
.conv:hover { background: var(--panel-2); }
.conv.on { background: var(--brand-soft); }
.conv-txt { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.conv-top b { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-top time { font-size: 10.5px; color: var(--muted); flex: 0 0 auto; }
.conv-sub { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 2px; }
.conv-sub span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 auto;
}

.empty-hint { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 10px; }

/* ───────── گفتگو ───────── */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(47, 107, 255, .06), transparent 70%),
    var(--bg);
  position: relative;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 62px;
}
.chat-title { display: flex; flex-direction: column; min-width: 0; }
.chat-title b { font-size: 15px; }
.chat-title small { font-size: 11.5px; color: var(--muted); }
.back { display: none; }

.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

.day {
  align-self: center;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 20px;
  margin: 10px 0 8px;
  border: 1px solid var(--line);
}

.row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.row.mine { flex-direction: row-reverse; }
.row + .row { margin-top: 2px; }
.row.gap { margin-top: 10px; }

.bubble {
  max-width: min(560px, 76%);
  padding: 9px 13px;
  border-radius: 16px;
  background: var(--theirs);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 24, 64, .04);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.65;
  position: relative;
}
.row.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-color: transparent;
  border-end-end-radius: 6px;
}
.row:not(.mine) .bubble { border-end-start-radius: 6px; }

.bubble .who { font-size: 11.5px; font-weight: 700; color: var(--brand); margin-bottom: 3px; }
.bubble .meta {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
}
.row.mine .bubble .meta { color: rgba(255, 255, 255, .78); }
.tick { font-size: 12px; letter-spacing: -2px; }
.tick.read { color: #7fe3a6; }

.bubble img.photo {
  display: block;
  max-width: 100%;
  max-height: 280px;
  width: auto;
  border-radius: 11px;
  cursor: zoom-in;
  margin: -2px 0 2px;
  background: var(--panel-2);
}
.bubble.media { padding: 5px; max-width: min(340px, 78%); }
.bubble.media .meta { padding: 0 6px; }

/* پخش‌کننده صدا */
.voice { display: flex; align-items: center; gap: 10px; min-width: 190px; padding: 2px 0; }
.vplay {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.row.mine .vplay { background: rgba(255, 255, 255, .22); }
.vplay svg { width: 17px; height: 17px; fill: currentColor; stroke: none; }
.vbars { display: flex; align-items: center; gap: 2.5px; height: 26px; flex: 1; }
.vbars i {
  width: 2.5px;
  border-radius: 2px;
  background: currentColor;
  opacity: .35;
  transition: opacity .12s;
}
.vbars i.p { opacity: 1; }
.vtime { font-size: 11.5px; opacity: .8; font-variant-numeric: tabular-nums; }

/* فایل */
.file-row { display: flex; align-items: center; gap: 10px; padding: 2px 0; min-width: 190px; }
.file-ico {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: rgba(47, 107, 255, .12);
  color: var(--brand);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.row.mine .file-ico { background: rgba(255, 255, 255, .2); color: #fff; }
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-info b { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.file-info small { font-size: 11px; opacity: .75; }

/* ───────── نوار نوشتن ───────── */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--line);
  background: var(--panel-2);
  border-radius: 16px;
  padding: 10px 14px;
  max-height: 132px;
  outline: none;
  line-height: 1.6;
  transition: .16s;
}
.composer textarea:focus { border-color: var(--brand); background: var(--panel); }
.icon-btn.send { background: var(--brand); color: #fff; }
.icon-btn.send:hover { background: var(--brand); filter: brightness(1.08); color: #fff; }
.icon-btn.mic.rec { background: var(--danger); color: #fff; }

.rec {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.rec .pulse {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.1s infinite;
}
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }
#recTime { font-variant-numeric: tabular-nums; font-weight: 700; }
.rec-hint { color: var(--muted); font-size: 12.5px; flex: 1; }
.ghost { color: var(--muted); padding: 9px 14px; border-radius: 11px; }
.ghost:hover { background: var(--panel-2); color: var(--text); }

/* ───────── سایر ───────── */
.jump {
  position: absolute;
  inset-inline-end: 20px;
  bottom: 88px;
  background: var(--panel);
  color: var(--brand);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.jump svg { width: 15px; height: 15px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, .92);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #10141f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

/* شیت انتخاب مخاطب */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, .5);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: 20px;
}
.sheet-card {
  background: var(--panel);
  border-radius: 20px;
  width: min(380px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-head b { font-size: 15px; }
.sheet-list { overflow-y: auto; padding: 8px; }

.typing { font-size: 11.5px; color: var(--brand); }

/* ───────── حساب من ───────── */
.me { cursor: pointer; border-radius: 14px; padding: 4px 6px; margin: -4px -6px; transition: .15s; }
.me:hover { background: var(--panel-2); }

.set-body { padding: 16px; overflow-y: auto; }
.set-avatar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.set-avatar .ghost {
  font-size: 13px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: 9px 14px;
}

.set-danger {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.set-danger b { font-size: 13.5px; color: var(--danger); }
.set-danger p { font-size: 12.5px; color: var(--muted); margin: 6px 0 12px; line-height: 1.7; }

.danger-btn {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  background: rgba(229, 72, 77, .1);
  color: var(--danger);
  font-weight: 700;
  border: 1.5px solid rgba(229, 72, 77, .25);
  transition: .15s;
}
.danger-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.danger-btn:disabled { opacity: .6; cursor: default; }

.warn {
  background: rgba(229, 72, 77, .08);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 12.5px;
  color: var(--danger);
  line-height: 1.7;
  margin: 0 0 14px;
}

/* ───────── موبایل ───────── */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed;
    inset: 0;
    z-index: 20;
    transition: transform .22s ease;
  }
  .side.hide { transform: translateX(100%); }
  .chat { grid-column: 1; }
  .back { display: grid; }
  .bubble { max-width: 84%; }
  .msgs { padding: 12px 10px 6px; }
}

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: rgba(120, 130, 150, .35); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }
