@font-face {
  font-family: "Vazirmatn";
  src: url("vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d6f1ec;
  --bg: #eef1f0;
  --panel: #ffffff;
  --line: #e1e6e4;
  --ink: #17211f;
  --muted: #64716e;
  --bubble: #ffffff;
  --bubble-me: #d9f3ea;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(16, 32, 28, .08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #2bb3a3;
    --accent-ink: #06211d;
    --accent-soft: #14332f;
    --bg: #0e1513;
    --panel: #161f1d;
    --line: #26322f;
    --ink: #e7eeec;
    --muted: #93a19d;
    --bubble: #1c2725;
    --bubble-me: #14463e;
    --danger: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.7 "Vazirmatn", Tahoma, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: isolate; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

/* ---------- فرم‌ها ---------- */
input[type=text], input[type=password], input[type=search], input[type=number], input:not([type]), textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
input[dir=ltr] { text-align: right; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label > input, label > textarea { margin-top: 4px; color: var(--ink); font-size: 15px; }
.btn, .primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 10px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel);
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; font-weight: 500; }
button:disabled { opacity: .55; cursor: default; }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- صفحهٔ ورود و نصب ---------- */
.plain, .auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px 16px; }
.auth { min-height: 100dvh; }
.card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 18px; padding: 24px 20px; box-shadow: var(--shadow); }
.card.install { max-width: 460px; }
.card h1 { font-size: 20px; margin-bottom: 6px; }
.card h2 { font-size: 15px; margin: 18px 0 10px; }
.card .primary { width: 100%; margin-top: 4px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand img { width: 48px; height: 48px; border-radius: 12px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tabs button { padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected=true] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.checks { list-style: none; padding: 0; margin: 14px 0; font-size: 13px; }
.checks .ok { color: var(--accent); }
.checks .bad { color: var(--danger); }

/* ---------- چیدمان اصلی ---------- */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; max-width: 1400px; margin: 0 auto; background: var(--panel); }
.side { display: flex; flex-direction: column; min-width: 0; border-inline-end: 1px solid var(--line); background: var(--panel); min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }
.bar { display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); }
.bar h1 { font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--muted); }
.icon:hover { background: var(--bg); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.accent { background: var(--accent); color: var(--accent-ink); }
.search { padding: 8px 12px; }
.search input { border-radius: 999px; background: var(--bg); border-color: transparent; padding: 8px 14px; }
.offline { background: #8a5a00; color: #fff; text-align: center; font-size: 13px; padding: 4px 8px; }

.list { flex: 1; overflow-y: auto; padding: 4px 6px 12px; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 12px; text-align: start; }
.item:hover { background: var(--bg); }
.item.on { background: var(--accent-soft); }
.item .mid { flex: 1; min-width: 0; }
.item .top { display: flex; align-items: baseline; gap: 6px; }
.item .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .when { font-size: 12px; color: var(--muted); flex: none; }
.item .sub { display: flex; align-items: center; gap: 6px; }
.item .last { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty .primary { margin-top: 12px; }

.av { width: 46px; height: 46px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; position: relative; }
.av.sm { width: 38px; height: 38px; font-size: 15px; }
.av.lg { width: 88px; height: 88px; font-size: 34px; }
.av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avedit { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.av.on::after { content: ""; position: absolute; bottom: 1px; inset-inline-start: 1px; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--panel); }

/* ---------- گفتگو ---------- */
.pane-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); padding: 20px; text-align: center; }
.chat-title { flex: 1; min-width: 0; text-align: start; display: flex; align-items: center; gap: 10px; }
.chat-title .t { min-width: 0; }
.chat-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.chat-title small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }

.msgs { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 10px 8px; display: flex; flex-direction: column; gap: 3px; overflow-anchor: none; }
.day, .sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 999px; padding: 2px 12px; margin: 8px 0; box-shadow: var(--shadow); max-width: 90%; text-align: center; }
.more { align-self: center; font-size: 13px; color: var(--accent); padding: 6px 12px; }
.msg { display: flex; max-width: min(78%, 520px); align-self: flex-end; position: relative; }
.msg.me { align-self: flex-start; }
.msg.gap { margin-top: 8px; }
.bub { background: var(--bubble); border-radius: var(--radius); padding: 6px 10px 4px; box-shadow: var(--shadow); min-width: 64px; max-width: 100%; overflow: hidden; }
.msg.me .bub { background: var(--bubble-me); }
.msg.flash .bub { outline: 2px solid var(--accent); }
.who { font-size: 12.5px; font-weight: 700; line-height: 1.5; }
.txt { white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; text-align: start; }
.meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; font-size: 11px; color: var(--muted); line-height: 1.4; direction: ltr; }
.tick { font-size: 12px; letter-spacing: -3px; padding-inline-end: 3px; }
.tick.seen { color: var(--accent); }
.quote { display: block; width: 100%; text-align: start; border-inline-start: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 6px; padding: 2px 8px; margin: 2px 0 4px; font-size: 12.5px; }
.quote b { display: block; color: var(--accent); }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.pic { display: block; margin: 0 -6px 4px; border-radius: 10px; overflow: hidden; background: var(--line); max-width: 280px; }
.pic img { display: block; width: 100%; height: 100%; object-fit: cover; }
.msg.sticker .bub { background: none; box-shadow: none; padding: 0; }
.msg.sticker img { display: block; width: 132px; height: 132px; object-fit: contain; }
.msg.sticker .meta { background: var(--panel); border-radius: 999px; padding: 1px 8px; width: fit-content; margin-inline-start: auto; }
.file { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 4px 0; min-width: 190px; }
.file .ic { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.file .ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.file .fn { min-width: 0; }
.file .fn b { display: block; font-weight: 600; font-size: 14px; overflow-wrap: anywhere; unicode-bidi: plaintext; text-align: start; line-height: 1.5; }
.file .fn small { color: var(--muted); font-size: 12px; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 4px 0; direction: ltr; }
.voice button { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); flex: none; display: inline-flex; align-items: center; justify-content: center; }
.voice button svg { width: 18px; height: 18px; fill: currentColor; }
.voice .track { flex: 1; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--muted) 35%, transparent); overflow: hidden; cursor: pointer; }
.voice .track i { display: block; height: 100%; width: 0; background: var(--accent); }
.voice time { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; }
.pending { opacity: .7; }
.opts { position: absolute; top: 2px; inset-inline-start: -34px; width: 30px; height: 30px; opacity: 0; }
.msg.me .opts { inset-inline-start: auto; inset-inline-end: -34px; }
.msg:hover .opts, .opts:focus-visible { opacity: 1; }

.down { position: absolute; bottom: 84px; inset-inline-end: 14px; background: var(--panel); box-shadow: 0 2px 8px rgba(0,0,0,.2); z-index: 2; }
.down .badge { position: absolute; top: -8px; inset-inline-start: -4px; }

/* ---------- نوار نوشتن ---------- */
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.replybar { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px; }
.replybar .quote { flex: 1; min-width: 0; margin: 0; }
.row { display: flex; align-items: flex-end; gap: 4px; }
.row textarea { flex: 1; min-width: 0; resize: none; border-radius: 20px; background: var(--bg); border-color: transparent; padding: 9px 14px; max-height: 140px; line-height: 1.6; unicode-bidi: plaintext; }
.rec { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 6px; }
.rec .dot { width: 12px; height: 12px; border-radius: 50%; background: #e11d48; animation: pulse 1s infinite; }
.rec .timer { flex: 1; font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .rec .dot { animation: none; } }
.stickers { max-height: 230px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px; padding: 8px 4px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.stickers button { aspect-ratio: 1; border-radius: 10px; padding: 4px; }
.stickers button:hover { background: var(--bg); }
.stickers img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ---------- پنجره‌ها ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(8, 16, 14, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: var(--panel); border-radius: 18px; width: 100%; max-width: 440px; max-height: min(88dvh, 720px); display: flex; flex-direction: column; overflow: hidden; }
.dialog.wide { max-width: 560px; }
.dialog header { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; padding-inline: 16px 8px; border-bottom: 1px solid var(--line); }
.dialog header h2 { flex: 1; font-size: 16px; }
.dialog .body { padding: 14px 16px 18px; overflow-y: auto; }
.dialog h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
.dialog h3:first-child { margin-top: 0; }
.pick { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 4px; border-radius: 10px; text-align: start; }
.pick:hover { background: var(--bg); }
.pick .mid { flex: 1; min-width: 0; }
.pick .mid b { display: block; font-weight: 600; line-height: 1.5; }
.pick .mid small { color: var(--muted); font-size: 12px; }
.pick input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.rowline { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rowline:last-child { border-bottom: 0; }
.rowline .grow { flex: 1; min-width: 120px; }
.rowline small { color: var(--muted); display: block; font-size: 12px; }
.code { font: 600 16px/1.6 ui-monospace, Consolas, monospace; letter-spacing: 2px; direction: ltr; unicode-bidi: isolate; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline label { flex: 1; min-width: 110px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.sheet { display: flex; flex-direction: column; padding: 6px; }
.sheet button { padding: 12px 14px; text-align: start; border-radius: 10px; }
.sheet button:hover { background: var(--bg); }
.sheet .danger { color: var(--danger); }
.stk-admin { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.stk-admin div { position: relative; aspect-ratio: 1; background: var(--bg); border-radius: 10px; padding: 4px; }
.stk-admin img { width: 100%; height: 100%; object-fit: contain; }
.stk-admin button { position: absolute; top: -6px; inset-inline-start: -6px; width: 24px; height: 24px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 14px; line-height: 1; }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .tools { position: absolute; top: max(10px, env(safe-area-inset-top)); inset-inline: 10px; display: flex; justify-content: space-between; }
.viewer .icon { color: #fff; background: rgba(255, 255, 255, .15); }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 40; background: #1c2523; color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); }
.drop .msgs { outline: 3px dashed var(--accent); outline-offset: -8px; }

/* ---------- موبایل ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .pane { display: none; }
  .app.open .pane { display: flex; }
  .app.open .side { display: none; }
  .back { display: inline-flex; }
  .msg { max-width: 86%; }
  .opts { display: none; }
  .modal { align-items: flex-end; padding: 0; }
  .dialog { max-width: none; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
