/* کنسول اکانت واتساپ.
   همه‌چیز روی یک ایده بنا شده: این داشبوردِ آمار نیست، وضعیتِ یک بند
   است — یک گوشی که به یک مرورگر وصل است. سبز فقط جایی می‌آید که واقعاً
   وصل باشیم؛ اگر همه‌جا سبز باشد دیگر چیزی نمی‌گوید. */

/* فونت از داخل سورس، نه CDN. کپی‌شده از کنسول ایتا تا هر دو پروژه
   دقیقاً یک فونت داشته باشند. */
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --surface-2: #e6ebe9;
  --line: #d3dbd8;
  --text: #101a1d;
  --text-2: #55666b;

  /* سه‌گانه‌ی وضعیت — تنها جایی که رنگ معنا حمل می‌کند */
  --live: #0e8f45;  --live-soft: #dff2e6;
  --wait: #9a6b05;  --wait-soft: #fbf0d8;
  --down: #c0362b;  --down-soft: #fbe6e4;

  --accent: var(--live);
  --accent-ink: #ffffff;

  --shadow: 0 1px 2px rgba(16, 26, 29, .06);
  --shadow-2: 0 8px 24px rgba(16, 26, 29, .12);

  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  /* چگالی بالا (داشبورد اپراتوری): مقیاس ۴px */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --nav-w: 232px;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

/* تیره پیش‌فرضِ عملی است ولی روشن هم کامل ساخته شده — کنسول ممکن است
   کنار پنجره‌ی روشن باز بماند. مشکی مطلق نه: روی OLED لکه می‌اندازد. */
:root[data-theme="dark"] {
  --bg: #0b1013;
  --surface: #141b1f;
  --surface-2: #1c2529;
  --line: #2a353a;
  --text: #e8eeec;
  --text-2: #91a2a6;

  --live: #25d366;  --live-soft: #0d2c1b;
  --wait: #e0a22b;  --wait-soft: #322510;
  --down: #f16a5f;  --down-soft: #33191a;

  --accent-ink: #06140c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.65 Vazirmatn, system-ui, Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--live);
  outline-offset: 2px;
}

/* اعداد در جدول‌ها نباید موقع تغییر بپرند */
.num { font-variant-numeric: tabular-nums; }

/* جزیره‌ی چپ‌چین داخل صفحه‌ی راست‌چین: شماره، کد، لاگ */
.ltr {
  direction: ltr;
  text-align: right;
  unicode-bidi: isolate;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  clip: rect(0 0 0 0); overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---------------------------------------------------------- پوسته */

.shell {
  min-height: 100dvh;   /* نه 100vh — روی موبایل با نوار آدرس می‌پرد */
  display: flex;
  flex-direction: column;
}

.side { display: contents; }   /* موبایل: نوار بالا و پایین جدا می‌شوند */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  padding-top: max(var(--s3), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: var(--s2); }
.brand svg { width: 22px; height: 22px; color: var(--live); }
.brand b { font-weight: 700; font-size: 15px; }
.brand small { display: block; font-size: 11.5px; color: var(--text-2); }
.topbar .spacer { flex: 1; }

.icon-btn {
  width: 44px; height: 44px;         /* حداقل هدف لمسی */
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.main {
  flex: 1;
  width: 100%; max-width: 1080px;
  margin: 0 auto;
  padding: var(--s4);
  padding-bottom: 96px;              /* جا برای نوار پایین */
}

.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav button {
  min-height: 56px;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
  border: 0; background: transparent;
  color: var(--text-2); font: 500 11.5px/1 Vazirmatn, sans-serif;
  cursor: pointer; touch-action: manipulation;
  transition: color .18s var(--ease);
}
.nav button svg { width: 20px; height: 20px; }
.nav button[aria-current="page"] { color: var(--live); }

@media (min-width: 900px) {
  .shell { flex-direction: row-reverse; }
  .side {
    display: flex; flex-direction: column;
    position: fixed; inset-block: 0;
    /* در RTL، inline-start یعنی راست. با inline-end سایدبار به چپ
       می‌افتد — همان باگی که در نسخه‌ی اول بود. */
    inset-inline-start: 0;
    width: var(--nav-w);
    background: var(--surface);
    border-inline-end: 1px solid var(--line);
  }
  .topbar {
    position: static; border-bottom: 1px solid var(--line);
    backdrop-filter: none; background: transparent;
  }
  .nav {
    position: static; grid-template-columns: 1fr;
    background: transparent; border: 0; backdrop-filter: none;
    padding: var(--s2);
  }
  .nav button {
    flex-direction: row; justify-content: flex-start;
    gap: var(--s3); min-height: 44px;
    padding: 0 var(--s3); border-radius: var(--r-sm);
    font-size: 14px;
  }
  .nav button[aria-current="page"] { background: var(--live-soft); }
  .main { margin-inline-start: var(--nav-w); padding: var(--s5); padding-bottom: var(--s5); }
}

/* ------------------------------------------------- وضعیتِ بند */

/* قهرمان صفحه. --tone را جاوااسکریپت با data-tone عوض می‌کند و همه‌ی
   رنگ‌های داخلش از همان یکی می‌آید — پس هیچ‌وقت نیمی از بنر سبز و نیمی
   قرمز نمی‌شود. */
.state {
  --tone: var(--text-2);
  --tone-soft: var(--surface-2);
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s5) var(--s4);
  margin-bottom: var(--s4);
  background: var(--tone-soft);
  border: 1px solid color-mix(in srgb, var(--tone) 22%, transparent);
  border-radius: var(--r-lg);
  transition: background .4s var(--ease), border-color .4s var(--ease);
}
.state[data-tone="live"] { --tone: var(--live); --tone-soft: var(--live-soft); }
.state[data-tone="wait"] { --tone: var(--wait); --tone-soft: var(--wait-soft); }
.state[data-tone="down"] { --tone: var(--down); --tone-soft: var(--down-soft); }

.beacon {
  flex: 0 0 42px; height: 42px;
  display: grid; place-items: center; position: relative;
}
.beacon i {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--tone); display: block;
}
.beacon::after {
  content: ''; position: absolute;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--tone);
  opacity: 0;
}
.state[data-tone="live"] .beacon::after { animation: ping 2.4s var(--ease) infinite; }
.state[data-tone="wait"] .beacon::after { animation: ping 1.1s var(--ease) infinite; }

@keyframes ping {
  0%   { transform: scale(.35); opacity: .75; }
  70%  { transform: scale(3);   opacity: 0; }
  100% { opacity: 0; }
}

.state .headline { font: 700 19px/1.3 Vazirmatn, sans-serif; color: var(--tone); }
.state .detail { font-size: 13.5px; color: var(--text-2); margin-top: 2px; }
.state .detail b { color: var(--text); font-weight: 500; }

/* ------------------------------------------------------- کارت */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
  margin-bottom: var(--s4);
  box-shadow: var(--shadow);
}
.card > header {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s4);
}
.card > header h2 { flex: 1; margin: 0; font: 700 16px/1.3 Vazirmatn, sans-serif; }
.card > header .note { font-size: 12.5px; color: var(--text-2); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); margin: 0; }
.tile {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--s3);
}
.tile dt { font-size: 12.5px; color: var(--text-2); }
.tile dd { margin: 2px 0 0; font: 700 19px/1.2 Vazirmatn, sans-serif; font-variant-numeric: tabular-nums; }

@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

/* ------------------------------------------------------ دکمه‌ها */

.btn {
  min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  padding: 0 var(--s4);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--accent); color: var(--accent-ink);
  font: 500 14.5px/1 Vazirmatn, sans-serif;
  cursor: pointer; touch-action: manipulation;
  transition: filter .18s var(--ease), transform .1s var(--ease);
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }

.btn.ghost {
  background: transparent; color: var(--text);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: var(--down); color: #fff; }
.btn.slim { min-height: 34px; padding: 0 var(--s3); font-size: 13px; }
.btn.block { width: 100%; }

.row-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ------------------------------------------------------- فیلد */

.field { margin-bottom: var(--s3); }
.field label {
  display: block; margin-bottom: var(--s2);
  font: 500 13.5px/1 Vazirmatn, sans-serif; color: var(--text);
}
.input {
  width: 100%; height: 46px;
  padding: 0 var(--s3);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg); color: var(--text);
  font: 400 16px/1 Vazirmatn, sans-serif;   /* ۱۶px وگرنه iOS زوم می‌کند */
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.input:focus {
  outline: 0; border-color: var(--live);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 18%, transparent);
}
.help { margin: var(--s2) 0 0; font-size: 12.5px; color: var(--text-2); }

/* --------------------------------------------------- کارت QR */

/* اینجا تنها جایی است که جسارت خرج می‌شود: یک حلقه‌ی نازک دور کد که
   آرام خالی می‌شود. بدون آن، کد ناگهان عوض می‌شود و کاربر فکر می‌کند
   خراب شده. با آن، می‌بیند دارد تمام می‌شود. */
/* موبایل: کد بالا، مراحل زیرش. از ۷۰۰px به بالا کنار هم، چون کارت
   آن‌قدر پهن می‌شود که تک‌ستونی نصفش خالی می‌ماند. */
.qr-layout { display: grid; gap: var(--s4); }

@media (min-width: 700px) {
  .qr-layout {
    grid-template-columns: 268px minmax(0, 380px);
    align-items: center;
    gap: var(--s6);
    /* بدون این، کارت روی مانیتور پهن می‌شود و نیمه‌ی چپش خالی می‌ماند */
    max-width: 700px;
    margin-inline: auto;
  }
  .qr-wrap { margin: 0; }
}

.qr-wrap {
  position: relative;
  width: min(268px, 72vw); aspect-ratio: 1;
  margin: 0 auto;
  padding: var(--s3);
  background: #fff;                 /* QR همیشه روی سفید، حتی در تم تیره */
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.qr-wrap img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }

.qr-ring {
  position: absolute; inset: -7px;
  border-radius: calc(var(--r-lg) + 7px);
  pointer-events: none;
}
.qr-ring rect {
  fill: none; stroke: var(--wait); stroke-width: 2;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}

.qr-swap { transition: opacity .25s var(--ease); }
.qr-swap.out { opacity: .25; }

/* شماره‌گذاری فقط چون این واقعاً یک ترتیب است، نه تزئین */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s2) 0;
  font-size: 14px; color: var(--text-2);
  counter-increment: s;
}
.steps li::before {
  content: counter(s);
  flex: 0 0 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  font: 700 12.5px/1 Vazirmatn, sans-serif;
}

/* ----------------------------------------------- کد جفت‌شدن */

.pair-code {
  direction: ltr;
  text-align: center;
  font: 700 30px/1.2 ui-monospace, 'Cascadia Mono', Consolas, monospace;
  letter-spacing: .18em;
  padding: var(--s4);
  background: var(--surface-2);
  border-radius: var(--r-md);
  margin-bottom: var(--s3);
  user-select: all;                 /* یک‌بار کلیک، کل کد انتخاب */
}

/* ---------------------------------------------- لیست و چیپ */

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s2);
  border-radius: var(--r-md);
  transition: background .18s var(--ease);
}
.item:hover { background: var(--surface-2); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font: 500 12px/1.6 Vazirmatn, sans-serif;
  background: var(--surface-2); color: var(--text-2);
}
.chip.live { background: var(--live-soft); color: var(--live); }
.chip.wait { background: var(--wait-soft); color: var(--wait); }
.chip.down { background: var(--down-soft); color: var(--down); }

.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--text-2); }
.empty svg { width: 34px; height: 34px; opacity: .45; margin-bottom: var(--s2); }

.skel {
  height: 54px; border-radius: var(--r-md); margin-bottom: var(--s2);
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--surface-2) 55%, var(--surface)),
    var(--surface-2),
    color-mix(in srgb, var(--surface-2) 55%, var(--surface)));
  background-size: 240% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -240% 0; } }

/* ------------------------------------------------------ توست */

.toasts {
  position: fixed; z-index: 60;
  inset-inline: var(--s4);
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--s2);
  pointer-events: none;
}
.toast {
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  border-inline-start: 3px solid var(--text-2);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  font-size: 14px;
  animation: toast-in .22s var(--ease);
}
.toast.ok { border-inline-start-color: var(--live); }
.toast.err { border-inline-start-color: var(--down); }
.toast.out { animation: toast-out .18s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (min-width: 900px) {
  .toasts { inset-inline: auto var(--s5); width: 340px; bottom: var(--s5); }
}

/* ------------------------------------------------------- گیت */

.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: var(--s4);
  background: var(--bg);
}
.gate .box { width: 100%; max-width: 340px; }
.gate .brand { justify-content: center; margin-bottom: var(--s5); }
#gate-err { color: var(--down); font-size: 13px; margin: var(--s2) 0 0; }

/* -------------------------------------------- کارت نتیجه‌ی لوکاپ */

.pcard-head {
  display: flex; align-items: center; gap: var(--s4);
  margin-bottom: var(--s4);
}
.pcard-avatar {
  flex: 0 0 72px; width: 72px; height: 72px;
  border-radius: 50%; object-fit: cover;
  background: var(--surface-2);
  display: grid; place-items: center;
  font: 700 26px/1 Vazirmatn, sans-serif; color: var(--text-2);
  overflow: hidden;
}
.pcard-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pcard-id { min-width: 0; }
.pcard-name { font: 700 18px/1.3 Vazirmatn, sans-serif; }
.pcard-phone { font-size: 13.5px; color: var(--text-2); direction: ltr; text-align: right; }
.pcard-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* سطرهای فیلد: برچسب سمت راست، مقدار سمت چپِ همان سطر */
.pfields { display: flex; flex-direction: column; gap: 1px; }
.pfield {
  display: flex; gap: var(--s3); align-items: baseline;
  padding: var(--s3) var(--s2);
  border-top: 1px solid var(--line);
}
.pfield:first-child { border-top: 0; }
.pfield .k { flex: 0 0 88px; color: var(--text-2); font-size: 13.5px; }
.pfield .v { flex: 1; font-size: 14px; overflow-wrap: anywhere; }
.pfield .v.dim { color: var(--text-2); }

/* استوری‌ها */
.stories { display: flex; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s2); }
.story {
  position: relative; width: 84px;
  border-radius: var(--r-md); overflow: hidden;
  background: var(--surface-2);
  border: 2px solid var(--live);
}
.story.seen { border-color: var(--line); }
.story-thumb { width: 84px; height: 120px; object-fit: cover; display: block; background: var(--surface-2); }
.story-ph {
  display: grid; place-items: center;
  color: var(--text-2);
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
}
.story-ph svg { width: 26px; height: 26px; opacity: .6; }
.story-meta {
  position: absolute; inset-inline: 0; bottom: 0;
  padding: 3px 5px; font-size: 10.5px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  display: flex; justify-content: space-between;
}
.story-type {
  position: absolute; top: 4px; inset-inline-start: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff;
  display: grid; place-items: center;
}
.story-type svg { width: 11px; height: 11px; }
