:root {
  --p: #a77fe0;          /* بنفش روشن */
  --p-dark: #7a4fc2;
  --p-soft: #efe6fc;
  --bg: #f7f2ff;
  --card: #ffffff;
  --text: #2a1f3d;
  --muted: #6e6382;
  --line: #e4d9f5;
  --green: #22a652;
  --red: #e0413f;
  --mine: #e5d6fb;
  --radius: 18px;
  font-size: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1526; --card: #271f36; --text: #f3ecff; --muted: #b9add0;
    --line: #3a2f4f; --p-soft: #33284a; --mine: #4a3670;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: Vazirmatn, "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 1rem; line-height: 1.6; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
#app { min-height: 100%; display: flex; flex-direction: column; }

.splash { margin: auto; text-align: center; padding-top: 30vh; color: var(--muted); }
.splash img { width: 110px; border-radius: 26px; }

/* ---------- نوار بالا */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .5rem;
  padding: calc(.5rem + env(safe-area-inset-top)) .75rem .5rem;
  background: var(--p); color: #fff; box-shadow: 0 2px 8px rgba(80, 40, 140, .2);
}
.bar h1 { font-size: 1.25rem; margin: 0; flex: 1; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.bar h1 img { width: 40px; height: 40px; border-radius: 10px; }
.bar .title { flex: 1; min-width: 0; line-height: 1.3; }
.bar .title b { display: block; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title small { opacity: .9; font-size: .75rem; }
.barbtn {
  min-width: 56px; height: 56px; border-radius: 16px; background: rgba(255,255,255,.22);
  color: #fff; font-size: 1.6rem; display: flex; align-items: center; justify-content: center;
  flex-direction: column; line-height: 1; padding: 0 .4rem;
}
.barbtn small { font-size: .6rem; margin-top: 3px; }
.barbtn:active { background: rgba(255,255,255,.4); }
.back { font-size: 2rem; padding: 0 .5rem; min-width: 52px; }

/* ---------- صفحه‌ی اصلی */
.page { padding: .75rem .75rem 2rem; max-width: 720px; width: 100%; margin: 0 auto; }
.section-title { color: var(--muted); font-size: .85rem; margin: 1rem .3rem .4rem; font-weight: bold; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: .8rem; width: 100%; text-align: left;
  padding: .75rem .9rem; min-height: 84px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--p-soft); }
.item .info { flex: 1; min-width: 0; }
.item .name { font-weight: bold; font-size: 1.1rem; display: block; }
.item .preview { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.item .side { display: flex; flex-direction: column; align-items: center; gap: .3rem; font-size: .7rem; color: var(--muted); }
.badge { background: var(--green); color: #fff; border-radius: 99px; min-width: 32px; height: 32px; padding: 0 .5rem; font-size: .85rem; display: flex; align-items: center; justify-content: center; font-weight: bold; }
.oncall { color: var(--green); font-weight: bold; }

.avatar {
  width: 60px; height: 60px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: bold; font-size: 1.5rem; background: var(--p) center/cover no-repeat;
}
.avatar.small { width: 44px; height: 44px; font-size: 1.1rem; }
.avatar.big { width: 120px; height: 120px; font-size: 3rem; }

.banner {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  background: #fff4d6; color: #5a4300; border: 2px solid #f1d27a; border-radius: var(--radius);
  padding: .8rem 1rem; margin-bottom: .6rem; font-size: .95rem;
}
.banner .ico { font-size: 1.8rem; }
.banner.call { background: #dff7e7; border-color: #7fd39b; color: #11502a; }
.banner .x { margin-inline-start: auto; font-size: 1.2rem; padding: .3rem .6rem; }

/* ---------- گفتگو */
.chat { display: flex; flex-direction: column; height: 100dvh; height: 100vh; }
@supports (height: 100dvh) { .chat { height: 100dvh; } }
.msgs { flex: 1; overflow-y: auto; padding: .8rem .6rem; display: flex; flex-direction: column; gap: .35rem; }
.day { align-self: center; background: var(--p-soft); color: var(--muted); border-radius: 99px; padding: .1rem .9rem; font-size: .75rem; margin: .6rem 0; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.tick { color: #8f8a99; font-weight: bold; letter-spacing: -.35em; margin-inline-start: .25em; padding-inline-end: .35em; }
.tick.read { color: #18c94a; }
.item .name, .item .preview, .bar .title b, .urow .info b { unicode-bidi: plaintext; text-align: left; }
.bubble {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .55rem .8rem; white-space: pre-wrap; word-break: break-word; font-size: 1.05rem;
}
.mine .bubble { background: var(--mine); border-color: transparent; }
.msg .who { font-size: .75rem; font-weight: bold; color: var(--p-dark); margin: 0 .5rem .1rem; }
.msg .time { font-size: .65rem; color: var(--muted); margin: .1rem .5rem 0; }
.bubble img, .bubble video { display: block; border-radius: 12px; max-height: 60vh; width: 100%; object-fit: cover; background: #000; }
.bubble.media { padding: .3rem; }
.sysmsg { align-self: center; background: var(--p-soft); border-radius: 99px; padding: .3rem 1rem; font-size: .85rem; color: var(--muted); }
.more { align-self: center; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: .4rem 1.2rem; font-size: .85rem; }
.pending { opacity: .75; }

.aplayer { display: flex; align-items: center; gap: .6rem; min-width: 220px; }
.aplayer .play { width: 54px; height: 54px; border-radius: 50%; background: var(--p); color: #fff; font-size: 1.4rem; flex: none; }
.aplayer .track { flex: 1; height: 8px; background: var(--line); border-radius: 9px; overflow: hidden; }
.aplayer .fill { height: 100%; width: 0; background: var(--p-dark); }
.aplayer .dur { font-size: .8rem; color: var(--muted); min-width: 2.5rem; text-align: center; }

.composer { background: var(--card); border-top: 1px solid var(--line); padding: .5rem .6rem calc(.5rem + env(safe-area-inset-bottom)); }
.row { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 2px solid var(--line); background: var(--bg); border-radius: 16px;
  padding: .6rem .8rem; min-height: 56px; max-height: 140px; font-size: 1.05rem; outline: none;
}
.composer textarea:focus { border-color: var(--p); }
.send { background: var(--p-dark); color: #fff; border-radius: 16px; height: 56px; padding: 0 1rem; font-weight: bold; }
.tools { display: flex; gap: .5rem; margin-top: .5rem; }
.tool {
  flex: 1; height: 60px; border-radius: 16px; background: var(--p-soft); font-size: 1rem; font-weight: bold;
  display: flex; align-items: center; justify-content: center; gap: .4rem; color: var(--p-dark);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tool { color: #e3d2ff; } }
.tool span { font-size: 1.5rem; }
.tool:active, .send:active { filter: brightness(.9); }
.recording { display: flex; align-items: center; gap: .6rem; }
.recording .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
.recording .rtime { flex: 1; font-size: 1.2rem; font-weight: bold; }
.btn-red, .btn-green, .btn {
  height: 60px; padding: 0 1.2rem; border-radius: 16px; font-weight: bold; color: #fff; font-size: 1rem;
}
.btn-red { background: var(--red); }
.btn-green { background: var(--green); }
.btn { background: var(--p-dark); }
.btn.ghost { background: var(--p-soft); color: var(--p-dark); }
.btn.full { width: 100%; margin-top: .6rem; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- تماس */
.callscreen {
  position: fixed; inset: 0; z-index: 50; background: linear-gradient(160deg, #3b2363, #1d1230);
  color: #fff; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
}
.callhead { text-align: center; padding: 1rem; }
.callhead .cname { font-size: 1.5rem; font-weight: bold; }
.callhead .cstatus { opacity: .85; }
.tiles { flex: 1; display: grid; gap: 6px; padding: 6px; grid-template-columns: 1fr; grid-auto-rows: 1fr; min-height: 0; }
.tiles.n2 { grid-template-columns: 1fr; }
.tiles.n3, .tiles.n4 { grid-template-columns: 1fr 1fr; }
.tiles.n5, .tiles.n6, .tiles.n7, .tiles.n8, .tiles.nmany { grid-template-columns: 1fr 1fr 1fr; }
.tile { position: relative; background: #2c1d47; border-radius: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile.audio video { position: absolute; width: 1px; height: 1px; opacity: 0; }
.tile .tname { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,.5); padding: .1rem .7rem; border-radius: 99px; font-size: .85rem; }
.tile .avatar { width: 96px; height: 96px; font-size: 2.4rem; }
.localv { position: absolute; width: 28vw; max-width: 160px; aspect-ratio: 3/4; object-fit: cover; right: 12px; top: calc(90px + env(safe-area-inset-top)); border-radius: 14px; border: 2px solid rgba(255,255,255,.6); background: #000; z-index: 2; transform: scaleX(-1); }
.localv.back { transform: none; }
.callactions { display: flex; justify-content: center; gap: 1rem; padding: 1rem 1rem calc(1.2rem + env(safe-area-inset-bottom)); flex-wrap: wrap; }
.cbtn { display: flex; flex-direction: column; align-items: center; gap: .3rem; color: #fff; font-size: .8rem; }
.cbtn .circle { width: 72px; height: 72px; border-radius: 50%; background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.cbtn.off .circle { background: #fff; color: #333; }
.cbtn.hang .circle { background: var(--red); width: 84px; height: 84px; }
.cbtn.answer .circle { background: var(--green); width: 96px; height: 96px; font-size: 2.6rem; animation: pulse 1.2s infinite; }
.cbtn.decline .circle { background: var(--red); width: 96px; height: 96px; font-size: 2.6rem; }
.incoming { justify-content: space-between; text-align: center; }
.incoming .who { padding-top: 12vh; }
.incoming .who .avatar { margin: 0 auto 1rem; animation: pulse 1.6s infinite; }
.incoming .who .cname { font-size: 1.8rem; font-weight: bold; }
.incoming .callactions { gap: 3.5rem; padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
.incoming .cbtn { font-size: 1.1rem; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,.45); } 50% { box-shadow: 0 0 0 18px rgba(255,255,255,0); } }

/* ---------- عکس تمام‌صفحه و پنجره‌ها */
.viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; }
.viewer .close { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px; width: 64px; height: 64px; border-radius: 50%; background: rgba(255,255,255,.25); color: #fff; font-size: 1.8rem; }
.modal-bg { position: fixed; inset: 0; z-index: 55; background: rgba(20,10,40,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 .6rem; font-size: 1.2rem; }
.modal ol { padding-inline-start: 1.4rem; }
.modal li { margin-bottom: .6rem; }

/* ---------- تنظیمات و مدیریت */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; }
.card h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.me { display: flex; flex-direction: column; align-items: center; gap: .6rem; text-align: center; }
.me b { font-size: 1.3rem; }
.field { width: 100%; height: 60px; border: 2px solid var(--line); border-radius: 14px; padding: 0 1rem; background: var(--bg); font-size: 1.05rem; outline: none; }
.field:focus { border-color: var(--p); }
.sizes { display: flex; gap: .5rem; }
.sizes button { flex: 1; height: 60px; border-radius: 14px; background: var(--p-soft); font-weight: bold; }
.sizes button.on { background: var(--p-dark); color: #fff; }
.urow { display: flex; align-items: center; gap: .6rem; padding: .7rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.urow:last-child { border-bottom: 0; }
.urow .info { flex: 1; min-width: 140px; }
.urow .code { color: var(--muted); font-size: .8rem; direction: ltr; unicode-bidi: plaintext; }
.urow .acts { display: flex; gap: .4rem; flex-wrap: wrap; width: 100%; }
.sbtn { height: 46px; padding: 0 .8rem; border-radius: 12px; background: var(--p-soft); font-size: .8rem; font-weight: bold; }
.sbtn.danger { color: var(--red); }
.check { display: flex; align-items: center; gap: .8rem; padding: .6rem 0; font-size: 1.05rem; }
.check input { width: 28px; height: 28px; accent-color: var(--p-dark); }

#toast {
  position: fixed; bottom: calc(150px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #2a1f3d; color: #fff; padding: .7rem 1.3rem; border-radius: 99px; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 90vw; text-align: center; font-size: .95rem;
}
#toast.show { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.login { margin: auto; width: 100%; max-width: 420px; padding: 2rem 1.2rem; text-align: center; }
.login img { width: 140px; border-radius: 32px; box-shadow: 0 8px 24px rgba(120, 70, 200, .3); }
.login h1 { font-size: 1.5rem; margin: 1rem 0 .3rem; }
.login p { color: var(--muted); }
.login { padding-top: 1rem; }
.login img { width: 110px; }
.codebox { display: flex; justify-content: center; gap: 8px; margin: 1rem 0; }
.codebox span {
  width: 46px; height: 60px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 1.7rem; font-weight: bold;
}
.codebox span.on { border-color: var(--p-dark); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  height: 68px; border-radius: 18px; background: var(--card); border: 2px solid var(--line);
  font-size: 1.8rem; font-weight: bold;
}
.keypad button:active { background: var(--p-soft); }
.keypad .kdel { font-size: 1.5rem; color: var(--red); }
.keypad .kgo { background: var(--p-dark); color: #fff; border-color: var(--p-dark); font-size: 1.1rem; }

/* فیلترشکن */
.hint { font-size: .85rem; color: #6f6880; margin: .5rem 0 0; }
a.btn { display: block; text-align: center; text-decoration: none; box-sizing: border-box; }
.meter { height: 18px; background: #eee6f8; border-radius: 9px; overflow: hidden; margin: .6rem 0 1rem; }
.meter i { display: block; height: 100%; width: 0; background: #18c94a; transition: width .08s; }
a.msglink { color: inherit; text-decoration: underline; word-break: break-all; }
a.msglink.btn { color: #fff; text-decoration: none; display: block; margin-top: .5rem; }
