:root {
  --ink: #15252a;
  --ink-2: #5b6b70;
  --paper: #f1f5f4;
  --panel: #ffffff;
  --line: #dde5e3;
  --accent: #0b7a75;
  --accent-ink: #ffffff;
  --accent-soft: #d6efec;
  --own: #cdeee9;
  --other: #ffffff;
  --danger: #c0392b;
  --badge: #e08a1e;
  --online: #2fb36b;
  --shadow: 0 1px 2px rgba(10, 40, 40, .12);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6efee;
    --ink-2: #92a5a6;
    --paper: #0d1719;
    --panel: #142226;
    --line: #223539;
    --accent: #21a79f;
    --accent-ink: #04201e;
    --accent-soft: #17403f;
    --own: #17504d;
    --other: #1b2f33;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; width: 100%; overflow: hidden; }
body {
  font-family: "Vazirmatn", "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.6;
  color: var(--ink); background: var(--paper);
  overscroll-behavior: none;
}
.hidden { display: none !important; }
button, input, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; fill: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- بوت --- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--accent); z-index: 50; }
.boot-logo { color: #fff; font-size: 48px; line-height: 1.3; font-family: "Cambria Math", "Segoe UI Symbol", "Noto Sans Math", "Apple Symbols", system-ui, sans-serif; text-align: center; }

/* --- احراز هویت --- */
.auth { display: flex; height: var(--app-h, 100dvh); overflow-y: auto; padding: calc(var(--sat) + 16px) 16px calc(var(--sab) + 16px); }
.auth-card { margin: auto; width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px 22px; }
.brand { margin: 0; font-size: 38px; font-weight: 800; color: var(--accent); line-height: 1.2; }
.brand-sub { margin: 2px 0 20px; color: var(--ink-2); }
.tabs { display: flex; gap: 4px; background: var(--paper); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; color: var(--ink-2); font-weight: 600; }
.tab.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.auth-form input { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 16px; }
.auth-form input:focus { border-color: var(--accent); outline: none; }
.hint { margin: 0; color: var(--ink-2); font-size: 13px; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; background: var(--line); color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .55; }
.link { border: 0; background: none; color: var(--accent); padding: 4px; font-size: 14px; }
.error { color: var(--danger); margin: 12px 0 0; font-size: 14px; }

/* --- چیدمان اصلی --- */
.main { position: relative; display: flex; height: var(--app-h, 100dvh); width: 100%; overflow: hidden; background: var(--paper); }
.sidebar { position: relative; display: flex; flex-direction: column; width: 100%; background: var(--panel); border-inline-end: 1px solid var(--line); min-height: 0; }
.chatview { position: absolute; inset: 0; background: var(--paper); transform: translateX(-100%); visibility: hidden; transition: transform .22s ease, visibility .22s; z-index: 5; }
.main.in-chat .chatview { transform: none; visibility: visible; }
@media (min-width: 820px) {
  .sidebar { width: 360px; flex: none; }
  .chatview { position: static; transform: none; visibility: visible; flex: 1; transition: none; }
  .btn-back, .back { display: none; }
}
@media (prefers-reduced-motion: reduce) { .chatview { transition: none; } }

.side-head { display: flex; align-items: center; gap: 10px; padding: calc(var(--sat) + 10px) 12px 8px; }
.side-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 800; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:hover { background: var(--paper); }
.icon-btn.light { color: #fff; width: auto; padding: 0 14px; }
.avatar-btn { padding: 0; width: 40px; height: 40px; }
.search-wrap { padding: 4px 12px 8px; }
.search-wrap input { width: 100%; padding: 9px 14px; border-radius: 22px; border: 0; background: var(--paper); color: var(--ink); }
.search-wrap input:focus { outline: 2px solid var(--accent); }
.net-banner { background: var(--badge); color: #fff; text-align: center; font-size: 13px; padding: 3px; }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; }
.chat-item:hover, .chat-item.active { background: var(--paper); }
.chat-item .mid { flex: 1; min-width: 0; }
.chat-item .row { display: flex; align-items: baseline; gap: 8px; }
.chat-item .name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--ink-2); flex: none; }
.chat-item .preview { flex: 1; color: var(--ink-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .preview.typing { color: var(--accent); }
.badge { background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; flex: none; }
.empty { text-align: center; color: var(--ink-2); padding: 40px 24px; }
.fab { position: absolute; inset-inline-start: 18px; bottom: calc(var(--sab) + 18px); width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.25); }

/* --- آواتار --- */
.avatar { position: relative; display: inline-grid; place-items: center; flex: none; border-radius: 50%; color: #fff; font-weight: 800; overflow: visible; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar .dot { position: absolute; inset-inline-end: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--online); border: 2px solid var(--panel); }

/* --- چت --- */
.no-chat { height: 100%; display: grid; place-items: center; color: var(--ink-2); }
.chat-pane { position: relative; display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: calc(var(--sat) + 6px) 8px 6px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-title-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: start; flex: 1; min-width: 0; padding: 2px 4px; border-radius: 10px; }
.chat-title-text { display: flex; flex-direction: column; min-width: 0; }
.chat-title-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.chat-title-text small { color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.chat-title-text small.live { color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day { align-self: center; background: var(--panel); color: var(--ink-2); font-size: 12px; padding: 2px 12px; border-radius: 12px; margin: 10px 0 4px; box-shadow: var(--shadow); }
.sys { align-self: center; color: var(--ink-2); font-size: 12.5px; padding: 3px 12px; margin: 4px 0; background: var(--accent-soft); border-radius: 12px; text-align: center; }
.msg { max-width: min(82%, 520px); padding: 6px 10px 4px; border-radius: 14px; background: var(--other); box-shadow: var(--shadow); word-break: break-word; position: relative; }
.msg.own { margin-left: auto; background: var(--own); border-bottom-right-radius: 4px; }
.msg.other { margin-right: auto; border-bottom-left-radius: 4px; }
.msg .who { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.msg .txt { white-space: pre-wrap; unicode-bidi: plaintext; }
.msg .meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-2); margin-top: 1px; }
.msg.deleted .txt { color: var(--ink-2); font-style: italic; }
.msg.failed { outline: 1px solid var(--danger); }
.msg.pending { opacity: .7; }
.msg.img { padding: 3px 3px 4px; }
.msg.img .meta { padding: 0 6px; }
.msg.img .who { padding: 3px 7px 0; }
.msg img.photo { display: block; width: 100%; max-width: 300px; max-height: 340px; min-width: 160px; object-fit: cover; border-radius: 11px; cursor: zoom-in; background: var(--line); }
.tick { font-size: 12px; letter-spacing: -3px; }
.tick.seen { color: var(--accent); }

.to-bottom { position: absolute; inset-inline-end: 14px; bottom: 76px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--ink-2); display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.to-bottom .badge { position: absolute; top: -8px; inset-inline-start: -6px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(var(--sab) + 8px); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 140px; border: 1px solid var(--line); background: var(--paper); border-radius: 20px; padding: 9px 14px; line-height: 1.5; font-size: 16px; color: var(--ink); unicode-bidi: plaintext; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.send { border: 0; width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }

/* --- پنجره --- */
.modal { position: fixed; inset: 0; background: rgba(5, 20, 20, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
@media (min-width: 820px) { .modal { align-items: center; } }
.sheet { width: 100%; max-width: 440px; max-height: 88dvh; background: var(--panel); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: var(--sab); }
@media (min-width: 820px) { .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; padding: 10px 16px 6px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 17px; }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.sheet-body input[type=text], .sheet-body input[type=password], .sheet-body input[type=search] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 16px; }
.sheet-body label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.user-row { display: flex; align-items: center; gap: 12px; padding: 6px 4px; border-radius: 10px; cursor: pointer; }
.user-row:hover { background: var(--paper); }
.user-row .u-name { flex: 1; min-width: 0; }
.user-row .u-name small { display: block; color: var(--ink-2); }
.user-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.section-title { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.profile-top { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0; }
.code-box { direction: ltr; text-align: center; font-family: ui-monospace, Consolas, monospace; font-size: 19px; letter-spacing: 1px; font-weight: 700; padding: 14px 8px; border-radius: 12px; background: var(--accent-soft); color: var(--ink); user-select: all; }
.warn { color: var(--ink-2); font-size: 13.5px; margin: 0; }
.action-list { display: flex; flex-direction: column; }
.action-list button { text-align: start; border: 0; background: none; padding: 12px 6px; border-radius: 10px; font-size: 16px; }
.action-list button:hover { background: var(--paper); }
.action-list .danger { color: var(--danger); }

/* --- نمایشگر تصویر --- */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 40; display: flex; align-items: center; justify-content: center; }
.viewer-bar { position: absolute; top: 0; inset-inline: 0; display: flex; justify-content: space-between; padding: calc(var(--sat) + 8px) 8px 8px; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 90px); transform: translateX(-50%); background: #223; color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 14px; z-index: 60; max-width: 90%; text-align: center; }
.avatar-btn.big { width: 96px; height: 96px; }

.vbadge { display: inline-flex; vertical-align: middle; margin-inline-start: 4px; }
.vbadge svg { width: 16px; height: 16px; fill: #1d9bf0; }
.chat-title-text strong .vbadge svg { width: 17px; height: 17px; }

/* --- تماس --- */
.call { position: fixed; inset: 0; z-index: 45; background: linear-gradient(180deg, #0b2a2c 0%, #07161a 100%); color: #fff; display: flex; flex-direction: column; align-items: center; overflow: hidden; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.call.has-video .call-remote { display: block; }
.call-local { position: absolute; top: calc(var(--sat) + 14px); inset-inline-end: 14px; width: 96px; height: 128px; object-fit: cover; border-radius: 14px; background: #123; box-shadow: 0 2px 12px rgba(0,0,0,.5); transform: scaleX(-1); z-index: 2; }
.call-info { position: relative; z-index: 1; margin-top: calc(var(--sat) + 18vh); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0 20px; }
.call-info h2 { margin: 10px 0 0; font-size: 26px; font-weight: 800; text-shadow: 0 1px 6px rgba(0,0,0,.4); }
.call-info p { margin: 0; font-size: 16px; opacity: .85; text-shadow: 0 1px 6px rgba(0,0,0,.4); }
.call.has-video .call-info { margin-top: calc(var(--sat) + 14px); align-self: flex-start; align-items: flex-start; text-align: start; }
.call.has-video .call-avatar { display: none; }
.call.has-video .call-info h2 { font-size: 18px; margin: 0; }
.call.has-video .call-info p { font-size: 14px; }
.call-controls { position: absolute; z-index: 3; bottom: calc(var(--sab) + 28px); inset-inline: 0; display: flex; justify-content: center; gap: 22px; padding: 0 16px; }
.call-btn { width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255,255,255,.18); color: #fff; backdrop-filter: blur(6px); }
.call-btn svg { width: 28px; height: 28px; }
.call-btn.off { background: #fff; color: #17252a; }
.call-btn.end { background: #e0483a; }
.call-btn.end svg { transform: rotate(135deg); }
.call-btn.accept { background: #2fb36b; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(47,179,107,.55); } 50% { box-shadow: 0 0 0 16px rgba(47,179,107,0); } }
@media (prefers-reduced-motion: reduce) { .call-btn.accept { animation: none; } }
