/* Sepan web app. Persian, right-to-left, phone first (iPhone home-screen app), light and dark. */
:root {
  --bg: #ffffff; --bg2: #f1f3f6; --chat: #e8eef4; --fg: #111418; --fg2: #6b7480; --line: #e2e6eb;
  --accent: #1e88e5; --accent-fg: #ffffff; --mine: #d9f2c4; --theirs: #ffffff; --danger: #d93025; --ok: #2e9d4f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .12); --fs: 16px; --tick: #2a9bf0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17212b; --bg2: #0e1621; --chat: #0e1621; --fg: #e9edf1; --fg2: #8b98a5; --line: #233140;
    --accent: #3d9bf0; --mine: #2b5278; --theirs: #182533; --shadow: none; color-scheme: dark; --tick: #8fd0ff;
  }
}
:root[data-theme="dark"] {
  --bg: #17212b; --bg2: #0e1621; --chat: #0e1621; --fg: #e9edf1; --fg2: #8b98a5; --line: #233140;
  --accent: #3d9bf0; --mine: #2b5278; --theirs: #182533; --shadow: none; color-scheme: dark; --tick: #8fd0ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overscroll-behavior: none; }
body { font: var(--fs)/1.5 -apple-system, BlinkMacSystemFont, "Vazirmatn", "Segoe UI", Tahoma, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; background: var(--bg); position: relative; overflow: hidden; }
.splash { margin: auto; font-size: 32px; font-weight: 700; color: var(--accent); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); min-height: 56px; flex: none; }
.bar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .grow { flex: 1; min-width: 0; cursor: pointer; }
.bar .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .s { font-size: 13px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .s.on { color: var(--accent); }
.icon { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; font-size: 21px; display: inline-flex; align-items: center; justify-content: center; position: relative; flex: none; color: var(--accent); }
.icon:active { background: var(--bg2); }
.badge { position: absolute; top: 2px; left: 2px; background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 4px; }
.conn { font-size: 13px; color: var(--fg2); }

/* ---------- lists ---------- */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 14px; cursor: pointer; border: 0; background: none; width: 100%; text-align: right; }
.row:active { background: var(--bg2); }
.row .mid { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 9px; margin-bottom: -9px; }
.row .top { display: flex; gap: 8px; align-items: baseline; }
.row .name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--fg2); flex: none; }
.row .sub { display: flex; gap: 8px; align-items: center; }
.row .prev { flex: 1; min-width: 0; color: var(--fg2); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .prev.typing { color: var(--accent); }
.count { background: var(--accent); color: #fff; border-radius: 11px; font-size: 12px; min-width: 22px; height: 22px; line-height: 22px; text-align: center; padding: 0 6px; flex: none; }
.empty { text-align: center; color: var(--fg2); padding: 40px 24px; }
.section { padding: 14px 16px 6px; color: var(--accent); font-weight: 600; font-size: 14px; }
.hint { margin: 10px 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg2); font-size: 14px; color: var(--fg2); }
.hint b { color: var(--fg); }

/* ---------- avatars ---------- */
.av { width: 50px; height: 50px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 19px; background: #65aadd; position: relative; overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.sm { width: 40px; height: 40px; font-size: 16px; }
.av.lg { width: 112px; height: 112px; font-size: 42px; margin: 0 auto; }
.av-wrap { position: relative; flex: none; }
.dot { position: absolute; bottom: 1px; left: 1px; width: 13px; height: 13px; border-radius: 50%; background: #4cd964; border: 2px solid var(--bg); }

/* ---------- forms ---------- */
.form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--fg2); }
input[type=text], input[type=password], textarea, select { font-size: 16px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); outline: none; width: 100%; }
input:focus, textarea:focus { border-color: var(--accent); }
.ltr { direction: ltr; text-align: left; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: 16px; }
.btn:disabled { opacity: .55; }
.btn.flat { background: var(--bg2); color: var(--accent); }
.btn.danger { background: none; color: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }
.ok { color: var(--ok); font-size: 14px; }
.login { margin: auto; width: 100%; max-width: 380px; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); text-align: center; }
.login .logo { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 10px; display: block; }
.login h2 { margin: 6px 0 2px; }
.login p { color: var(--fg2); margin: 0 0 18px; font-size: 14px; }
.login .form { padding: 0; text-align: right; }
.login .form a { margin-top: 2px; }
.hint.apk { text-align: center; margin: 18px 0 0; }
.hint.apk .qr { display: block; width: 180px; height: 180px; margin: 10px auto; border-radius: 8px; background: #fff; }
.hint.apk .btn { display: inline-block; margin-top: 8px; text-decoration: none; }
.devcode { font: 700 34px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 4px; direction: ltr; text-align: center; margin: 10px 0 4px; user-select: all; -webkit-user-select: all; }
.keybox { max-width: 460px; margin: 0 auto; padding: 8px 0 calc(24px + env(safe-area-inset-bottom)); }
.keybox > p { padding: 12px 16px 0; margin: 0; }
.keybox h3 { margin: 4px 0 0; font-size: 17px; }
.keybox .form .hint { margin: 0; }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.setting .l { flex: 1; }
.setting .d { font-size: 13px; color: var(--fg2); }
.mono { font-family: ui-monospace, Menlo, monospace; direction: ltr; font-size: 13px; word-break: break-all; }
.center { text-align: center; }
.profile-head { text-align: center; padding: 20px 16px 8px; }
.profile-head h2 { margin: 10px 0 0; }
.profile-head .u { color: var(--fg2); direction: ltr; }
.actions { display: flex; gap: 10px; justify-content: center; padding: 10px 16px 16px; flex-wrap: wrap; }

/* ---------- chat ---------- */
.chat { background: var(--chat); }
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 8px 12px; display: flex; flex-direction: column; gap: 3px; overflow-anchor: none; }
.day { align-self: center; background: rgba(0, 0, 0, .18); color: #fff; font-size: 12.5px; border-radius: 10px; padding: 2px 10px; margin: 8px 0 4px; }
.m { display: flex; flex-direction: column; max-width: 82%; }
.m.me { align-self: flex-start; }
.m.them { align-self: flex-end; }
.bubble { padding: 6px 10px 4px; border-radius: 16px; background: var(--theirs); box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere; min-width: 64px; }
.m.me .bubble { background: var(--mine); border-bottom-right-radius: 5px; }
.m.them .bubble { border-bottom-left-radius: 5px; }
.bubble .who { font-size: 13px; font-weight: 700; margin-bottom: 1px; }
.bubble .txt { white-space: pre-wrap; unicode-bidi: plaintext; text-align: start; }
.bubble .meta { font-size: 11.5px; color: var(--fg2); text-align: left; direction: ltr; margin-top: 1px; display: flex; gap: 4px; justify-content: flex-start; align-items: center; }
.bubble.flash { animation: flash 1.2s; }
@keyframes flash { 0%, 60% { filter: brightness(.82); } }
.bubble.emoji { background: none !important; box-shadow: none; padding: 0; }
.bubble.emoji .txt { font-size: 52px; line-height: 1.15; animation: pop .45s ease-out; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.reply { border-right: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 4px; border-radius: 4px; background: rgba(30, 136, 229, .08); font-size: 13.5px; cursor: pointer; }
.reply .ru { color: var(--accent); font-weight: 600; }
.reply .rx { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--fg2); }
.img { display: block; max-width: 100%; border-radius: 10px; margin: 2px 0; background: rgba(0, 0, 0, .08); object-fit: cover; cursor: pointer; }
.img-ph { display: flex; align-items: center; justify-content: center; color: var(--fg2); font-size: 14px; border-radius: 10px; background: rgba(0, 0, 0, .08); margin: 2px 0; cursor: pointer; }
.file { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; }
.file .fi { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.file .fn { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; direction: ltr; text-align: right; }
.file .fs { font-size: 12.5px; color: var(--fg2); }
.bar-prog { height: 3px; background: rgba(0, 0, 0, .1); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.bar-prog i { display: block; height: 100%; background: var(--accent); width: 0; }
.fail { color: var(--danger); font-size: 13px; }
.fail button { border: 0; background: none; color: var(--accent); padding: 0 4px; font-size: 13px; }
.call-line { align-self: center; background: var(--bg); color: var(--fg2); font-size: 13px; border-radius: 12px; padding: 3px 12px; margin: 4px 0; box-shadow: var(--shadow); }
.pinbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--line); cursor: pointer; flex: none; }
.pinbar .pt { flex: 1; min-width: 0; border-right: 2px solid var(--accent); padding-right: 8px; font-size: 13.5px; }
.pinbar .pt b { color: var(--accent); font-weight: 600; display: block; font-size: 12.5px; }
.pinbar .pt span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jump { position: absolute; left: 14px; bottom: 76px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg); color: var(--fg2); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); font-size: 20px; }
.jump .badge { top: -6px; left: auto; right: -2px; background: var(--accent); }
.composer { flex: none; background: var(--bg); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.composer .line { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 42px; border-radius: 21px; padding: 9px 14px; line-height: 1.4; background: var(--bg2); border: 0; }
.composer .send { color: var(--accent); }
.replybar { display: flex; align-items: center; gap: 8px; padding: 2px 6px 6px; }
.replybar .reply { flex: 1; margin: 0; min-width: 0; }
.emojis { display: grid; grid-template-columns: repeat(8, 1fr); max-height: 230px; overflow-y: auto; padding: 4px; }
.emojis button { border: 0; background: none; font-size: 27px; padding: 5px 0; border-radius: 8px; }
.emojis button:active { background: var(--bg2); }
.emojis .cap { grid-column: 1 / -1; font-size: 12.5px; color: var(--fg2); padding: 4px 4px 0; }
.searchbar { display: flex; gap: 6px; padding: 6px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
mark { background: #ffe082; color: inherit; border-radius: 3px; }

/* ---------- sheets / overlays ---------- */
.veil { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); max-height: 80dvh; overflow-y: auto; }
.sheet button.it { display: block; width: 100%; text-align: right; border: 0; background: none; padding: 13px 20px; font-size: 16px; }
.sheet button.it:active { background: var(--bg2); }
.sheet button.it.danger { color: var(--danger); }
.sheet .st { padding: 8px 20px 10px; color: var(--fg2); font-size: 14px; }
.dialog { background: var(--bg); width: calc(100% - 32px); max-width: 420px; border-radius: 16px; padding: 18px; margin: auto; }
.dialog h3 { margin: 0 0 8px; }
.dialog p { margin: 0 0 14px; color: var(--fg2); font-size: 15px; }
.dialog .btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 30; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer .vbar { display: flex; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; }
.viewer .icon { color: #fff; }
.toast { position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 50%; transform: translateX(-50%); z-index: 40; background: rgba(30, 30, 30, .92); color: #fff; padding: 9px 16px; border-radius: 14px; font-size: 14.5px; max-width: calc(100% - 32px); box-shadow: 0 2px 10px rgba(0, 0, 0, .3); cursor: pointer; }

/* ---------- calls ---------- */
.call { position: fixed; inset: 0; z-index: 35; background: #10202f; color: #fff; display: flex; flex-direction: column; align-items: center; }
.call video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call video.local { position: absolute; top: calc(env(safe-area-inset-top) + 14px); left: 14px; width: 30%; max-width: 150px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; z-index: 2; background: #222; transform: scaleX(-1); }
.call video.local.back { transform: none; }
.call .info { position: relative; z-index: 2; text-align: center; margin-top: calc(env(safe-area-inset-top) + 70px); text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.call .info h2 { margin: 12px 0 4px; font-size: 26px; }
.call .info .av { margin: 0 auto; }
.call .ctrls { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 36px); display: flex; gap: 22px; z-index: 2; flex-wrap: wrap; justify-content: center; }
.call .cb { width: 64px; height: 64px; border-radius: 50%; border: 0; font-size: 26px; background: rgba(255, 255, 255, .2); color: #fff; }
.call .cb.on { background: #fff; color: #10202f; }
.call .cb.red { background: #e53935; }
.call .cb.green { background: #43a047; }
.setting select { width: auto; max-width: 55%; flex: none; }
/* forward / edit / selection (1.3) */
.bubble .fw { font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.m.sel .bubble { outline: 2px solid var(--accent); }
.m.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.selbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--bg2); }
.picklist { max-height: 45dvh; overflow-y: auto; margin: 8px 0; }
.pick { display: flex; align-items: center; gap: 10px; padding: 6px 2px; cursor: pointer; }
.pick.sw { border-top: 1px solid var(--bg2); padding-top: 10px; }
.pick small, .hist small { color: var(--fg2); font-size: 12px; display: block; }
.dialog input[type=text] { width: 100%; box-sizing: border-box; }
.hist { margin: 6px 0 12px; display: flex; flex-direction: column; gap: 8px; }
.hv { background: var(--bg2); border-radius: 10px; padding: 6px 10px; }
/* ticks, reactions, voice, recording, drafts (1.4) */
.tick { font-weight: 700; font-size: 12.5px; letter-spacing: -4px; padding-left: 4px; direction: ltr; }
.tick.sent { color: var(--fg2); }
.tick.delivered, .tick.seen { color: var(--tick); }
.row .top .tick { flex: none; font-size: 13px; }
.row .draft { color: var(--danger); }
.pinmark { font-size: 13px; flex: none; opacity: .7; }
.rxn { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 1px; }
.rchip { border: 0; border-radius: 13px; padding: 1px 8px; background: color-mix(in srgb, var(--accent) 14%, transparent); font-size: 15px; display: inline-flex; gap: 4px; align-items: center; }
.rchip span { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.rchip.mine { background: var(--accent); }
.rchip.mine span { color: #fff; }
.rbig { font-size: 22px; }
.rpick { display: flex; justify-content: space-around; padding: 4px 10px 10px; border-bottom: 1px solid var(--line); }
.rpick button { border: 0; background: none; font-size: 30px; border-radius: 50%; width: 46px; height: 46px; }
.rpick button.on { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.rpick button.more { font-size: 20px; color: var(--accent); }
.emojis.tall { max-height: 60dvh; }
.voice { display: flex; align-items: center; gap: 10px; padding: 4px 0; min-width: 210px; }
.vplay { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 17px; flex: none; }
.vw { flex: 1; min-width: 0; }
.wave { display: flex; align-items: center; gap: 2px; height: 28px; direction: ltr; cursor: pointer; }
.wave i { flex: 1; max-width: 4px; min-width: 2px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 38%, transparent); }
.wave i.on { background: var(--accent); }
.voice .fs { font-size: 12.5px; color: var(--fg2); }
.composer .mic { color: var(--accent); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.recbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.recbar .rdot { width: 12px; height: 12px; border-radius: 50%; background: #e53935; transition: transform .2s; flex: none; }
.recbar .rt { font-variant-numeric: tabular-nums; min-width: 44px; }
.recbar .hintx { color: var(--fg2); font-size: 14px; text-align: center; }
.recbar .grow { flex: 1; }
.pick .grow { flex: 1; }
.loc { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; min-width: 200px; }
.loc .fi { width: 44px; height: 44px; border-radius: 50%; background: #e53935; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.loc .fn { font-weight: 600; font-size: 14.5px; }
.loc .fs { font-size: 12.5px; color: var(--fg2); }
