:root {
  --brand: #0f766e; --brand-dark: #115e59; --on-brand: #fff;
  --bg: #f4f2ee; --chat-bg: #ebe7e0; --card: #fff; --fg: #1c1c1e; --muted: #6b6b70; --line: #e2ded6;
  --mine: #d7f5c9; --theirs: #fff; --tick: #8a8f98; --tick-read: #1d9bf0; --danger: #c62828; --ok: #2e7d32;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #14897f; --brand-dark: #0d5f58; --bg: #111416; --chat-bg: #0c1013; --card: #1d2226; --fg: #e9ecee; --muted: #9aa3a9;
    --line: #2a3136; --mine: #1f5b46; --theirs: #22292e; --tick: #9aa3a9; --tick-read: #53bdeb; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.5 Vazirmatn, "Segoe UI", Roboto, Tahoma, system-ui, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
#root { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }

/* top bar */
.bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: var(--on-brand); min-height: 58px; flex: none;
}
.bar h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .sub { font-size: 12.5px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .title { flex: 1; min-width: 0; }
.ibtn {
  width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; color: inherit;
  display: grid; place-items: center; flex: none;
}
.ibtn:active { background: rgba(255,255,255,.18); }
.ibtn svg { width: 24px; height: 24px; }
[dir=rtl] .flip svg { transform: scaleX(-1); }

/* avatars */
.av {
  border-radius: 50%; display: grid; place-items: center; flex: none; overflow: hidden;
  color: #fff; font-weight: 700; letter-spacing: .3px; object-fit: cover;
}

/* login */
.center { flex: 1; overflow: auto; padding: 24px 16px; }
.hint { color: var(--muted); text-align: center; margin: 4px 0 18px; }
.users { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.ucard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.ucard:active { transform: scale(.97); }
.ucard .n { font-size: 14px; text-align: center; overflow-wrap: anywhere; }
.pin { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.dots { display: flex; gap: 16px; direction: ltr; margin: 6px 0; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); }
.dots i.on { background: var(--brand); }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; direction: ltr; }
.pad button {
  height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 26px;
}
.pad button:active { background: var(--line); }
.pad .blank { visibility: hidden; }
.err { color: var(--danger); min-height: 1.5em; text-align: center; }
.link { background: none; border: 0; color: var(--brand); padding: 8px; }
.langbtn { position: absolute; top: max(10px, env(safe-area-inset-top)); inset-inline-end: 10px; }

/* rooms */
.list { flex: 1; overflow: auto; background: var(--card); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; width: 100%;
  background: none; border: 0; border-bottom: 1px solid var(--line); text-align: start;
}
.row:active { background: var(--bg); }
.row .mid { flex: 1; min-width: 0; }
.row .top { display: flex; gap: 8px; align-items: baseline; }
.row .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { font-size: 12px; color: var(--muted); flex: none; }
.row .time.new { color: var(--brand); font-weight: 600; }
.row .prev { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.row .prev span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  background: var(--brand); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 7px;
  font-size: 12.5px; display: grid; place-items: center; font-weight: 700; flex: none;
}
.empty { color: var(--muted); text-align: center; padding: 48px 20px; }

/* chat */
.chat {
  flex: 1; overflow-y: auto; padding: 10px 10px 6px; background: var(--chat-bg);
  display: flex; flex-direction: column; gap: 3px;
}
.day { align-self: center; background: var(--card); color: var(--muted); font-size: 12.5px; padding: 3px 12px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg {
  max-width: 80%; padding: 6px 10px 4px; border-radius: 12px; position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; overflow-wrap: anywhere;
}
/* own messages always on the right, others on the left, in both languages */
.msg.mine { background: var(--mine); margin-left: auto; margin-right: 0; border-top-right-radius: 4px; }
.msg.theirs { background: var(--theirs); margin-right: auto; margin-left: 0; border-top-left-radius: 4px; }
.msg.cont { border-radius: 12px; margin-top: -1px; }
.msg .who { font-size: 12.5px; font-weight: 700; margin-bottom: 1px; }
.msg .body { white-space: pre-wrap; }
.msg .meta { display: flex; gap: 4px; justify-content: flex-end; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 1px; direction: ltr; }
.msg .tick { width: 16px; height: 11px; color: var(--tick); }
.msg .tick.read { color: var(--tick-read); }
.msg.failed { outline: 1px solid var(--danger); }
.sys { align-self: center; background: #fff7d6; color: #5c4a00; font-size: 13.5px; padding: 4px 12px; border-radius: 10px; margin: 4px 0; text-align: center; }
@media (prefers-color-scheme: dark) { .sys { background: #3a3218; color: #f3e3a2; } }
.more { align-self: center; margin: 6px 0; }

.composer {
  display: flex; gap: 8px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--chat-bg); flex: none; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 22px; padding: 10px 16px; background: var(--card);
  max-height: 140px; min-height: 44px; outline: none; line-height: 1.4;
}
.send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.send svg { width: 22px; height: 22px; }
[dir=rtl] .send svg { transform: scaleX(-1); }

/* sheets, menus, banners */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet {
  background: var(--card); width: 100%; max-width: 760px; border-radius: 18px 18px 0 0; padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  max-height: 90dvh; overflow: auto;
}
.sheet h2 { font-size: 17px; margin: 4px 0 12px; }
.sheet .item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 6px; border: 0; background: none; text-align: start; border-radius: 10px; }
.sheet .item:active { background: var(--bg); }
.sheet .item svg { width: 22px; height: 22px; color: var(--brand); flex: none; }
.sheet .item.danger, .sheet .item.danger svg { color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); direction: ltr; text-align: center; letter-spacing: 6px; }
.btn { border: 0; background: var(--brand); color: #fff; border-radius: 10px; padding: 10px 18px; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.profile { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.profile .n { font-weight: 700; font-size: 18px; }
.muted { color: var(--muted); font-size: 13.5px; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }

.ring {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; max-width: 740px; margin: 0 auto; z-index: 30;
  background: var(--card); border-radius: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 12px; display: flex; gap: 12px; align-items: center;
  animation: drop .25s ease-out;
}
.ring .mid { flex: 1; min-width: 0; }
.ring .accept { width: 48px; height: 48px; border-radius: 50%; border: 0; background: #22a447; color: #fff; display: grid; place-items: center; animation: pulse 1.2s infinite; }
.ring .decline { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--bg); display: grid; place-items: center; }
.ring svg { width: 22px; height: 22px; }
@keyframes drop { from { transform: translateY(-30px); opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(34,164,71,.15); } }

#toast {
  position: fixed; bottom: calc(80px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 40;
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw; text-align: center;
}
.offline { background: #fff3cd; color: #6d5200; text-align: center; font-size: 13px; padding: 3px; flex: none; }
@media (prefers-color-scheme: dark) { .offline { background: #3d3311; color: #f6e3a1; } }

/* ---------- calls ---------- */
.row .live { color: #22a447; display: inline-grid; }
.row .live svg { width: 16px; height: 16px; }
.row .prev.missed span:first-child, .sys.missed { color: var(--danger); }
.sys svg { width: 15px; height: 15px; vertical-align: -3px; margin-inline-end: 5px; }
.callbar {
  display: flex; align-items: center; gap: 10px; border: 0; width: 100%; flex: none;
  background: #1f9d4c; color: #fff; padding: 8px 14px; font-size: 14.5px; text-align: start;
}
.callbar svg { width: 20px; height: 20px; flex: none; }
.callbar span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.callbar .join { background: #fff; color: #1f9d4c; border-radius: 16px; padding: 2px 14px; font-weight: 600; }
.callbar .cl { font-variant-numeric: tabular-nums; }

.call {
  position: fixed; inset: 0; z-index: 50; background: #0b1114; color: #fff;
  display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
}
.call[hidden] { display: none; }
.ctop { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.ctitle { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: center; }
.ctitle b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cstat { font-size: 13px; opacity: .8; font-variant-numeric: tabular-nums; }
.clock { width: 40px; display: grid; place-items: center; opacity: .8; }
.clock svg { width: 18px; height: 18px; }
.stage { flex: 1; min-height: 0; position: relative; display: flex; }
.grid { flex: 1; min-height: 0; display: grid; gap: 6px; padding: 6px 0; }
.strip { position: absolute; z-index: 2; display: flex; gap: 6px; max-width: calc(100% - 20px); overflow-x: auto; touch-action: none; }
.strip:empty { display: none; }
.strip.c-br { right: 10px; bottom: 16px; flex-direction: row-reverse; }
.strip.c-bl { left: 10px; bottom: 16px; }
.strip.c-tr { right: 10px; top: 16px; flex-direction: row-reverse; }
.strip.c-tl { left: 10px; top: 16px; }
.tile.small { flex: none; width: 96px; height: 136px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.5); }
@media (orientation: landscape) { .tile.small { width: 136px; height: 96px; } }
.tile.small .tname { font-size: 11px; bottom: 4px; inset-inline-start: 4px; padding: 1px 6px; }
.tile.small .ph .av { width: 48px !important; height: 48px !important; font-size: 17px !important; }
.grid.scroll { overflow-y: auto; grid-auto-rows: minmax(160px, 1fr); }
.tile { position: relative; border-radius: 14px; overflow: hidden; background: #1c272c; min-height: 0; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.mirror video { transform: scaleX(-1); }
.tile .ph { position: absolute; inset: 0; display: none; place-items: center; }
.tile.off video { opacity: 0; }
.tile.off .ph { display: grid; }
.tile .tname {
  position: absolute; inset-inline-start: 8px; bottom: 8px; display: flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,.45); padding: 2px 9px; border-radius: 10px; font-size: 13px; max-width: calc(100% - 16px);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.tile .moff { display: none; color: #ff8a80; }
.tile .moff svg { width: 15px; height: 15px; display: block; }
.tile.muted .moff { display: inline; }
.cnote { text-align: center; font-size: 13.5px; background: rgba(255,193,7,.18); color: #ffe08a; border-radius: 10px; padding: 5px 10px; margin: 0 8px 6px; }
.cnote[hidden] { display: none; }
.cbar { display: flex; justify-content: center; gap: 14px; padding-top: 6px; flex-wrap: wrap; }
.cbtn {
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14); color: #fff;
  display: grid; place-items: center;
}
.cbtn[hidden] { display: none; }
.cbtn svg { width: 27px; height: 27px; }
.cbtn.on { background: #fff; color: #0b1114; }
.cbtn.end { background: #e53935; }
.cbtn.ghost { width: 44px; height: 44px; background: transparent; }

/* ---------- login: username and password ---------- */
.login { max-width: 340px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.lf { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lf span { font-size: 13px; color: var(--muted); }
.lf input {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: var(--card); width: 100%;
  outline: none; font-size: 16px;
}
.lf input:focus { border-color: var(--brand); }
.btn.wide { width: 100%; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .6; }

/* ---------- requests ---------- */
.tag { font-size: 11.5px; background: var(--brand); color: #fff; border-radius: 8px; padding: 0 7px; flex: none; }
.note { background: var(--card); color: var(--muted); text-align: center; font-size: 13px; padding: 4px 10px; border-bottom: 1px solid var(--line); flex: none; }
.askbox { background: var(--card); padding: 14px 16px max(14px, env(safe-area-inset-bottom)); text-align: center; flex: none; border-top: 1px solid var(--line); }
.askbox p { margin: 0 0 12px; }
.askbox .row2 { display: flex; gap: 10px; justify-content: center; }
.askbox .btn { min-width: 120px; }
.profile .code { font-weight: 700; letter-spacing: 2px; color: var(--fg); }
.sheet form .field input { font-size: 20px; }
