/* ─────────────────────────────────────────────────────────────
   بی‌مرز — لایه‌ی مشترک طراحی
   هم مینی‌اپ تلگرام و هم پنل وب از همین توکن‌ها تغذیه می‌کنند.

   سه حالت تم پشتیبانی می‌شود:
   ۱. :root            → پالت روشن، کامل
   ۲. prefers-color-scheme: dark  → وقتی کاربر انتخاب صریح نکرده
   ۳. [data-theme]     → انتخاب صریح کاربر، بر همه اولویت دارد
   ───────────────────────────────────────────────────────────── */

/* ───────────────────────── توکن‌ها: روشن ───────────────────────── */

:root {
  /* زمینه و سطح — خاکستری با گرایش سرد به سمت فیروزه، نه خاکستری خام */
  --bg:            #f1f4f5;
  --surface:       #ffffff;
  --surface-2:     #f7f9fa;
  --surface-sunk:  #e9eef0;

  /* مرکب */
  --ink:           #0f1619;
  --ink-2:         #35454b;
  --muted:         #61737a;
  --faint:         #8fa2a9;

  /* خطوط */
  --line:          #dde5e8;
  --line-strong:   #c3d0d4;

  /* اکسنت — فیروزه‌ی سیگنال */
  --accent:        #00838c;
  --accent-ink:    #ffffff;
  --accent-soft:   #d7f0f2;
  --accent-line:   #93d4d9;

  /* وضعیت — جدا از اکسنت، چون معنا دارند نه تزئین */
  --ok:            #157a4a;
  --ok-soft:       #d8f0e3;
  --warn:          #9a6410;
  --warn-soft:     #fbeed3;
  --danger:        #b3372a;
  --danger-soft:   #fadedb;

  /* عمق — کم و هدفمند */
  --shadow-sm: 0 1px 2px rgba(15, 22, 25, .06);
  --shadow-md: 0 4px 16px rgba(15, 22, 25, .08);
  --shadow-lg: 0 12px 40px rgba(15, 22, 25, .14);

  /* شکل */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* فاصله */
  --s1: 4px;  --s2: 8px;   --s3: 12px;  --s4: 16px;
  --s5: 24px; --s6: 32px;  --s7: 48px;

  /* تایپ */
  --font: "Vazirmatn", ui-sans-serif, "Segoe UI", Tahoma, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  color-scheme: light;
}

/* ─────────────── توکن‌ها: تیره (وقتی انتخاب صریح نشده) ─────────────── */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0b1113;
    --surface:       #121b1e;
    --surface-2:     #172226;
    --surface-sunk:  #0e1618;

    --ink:           #e6eef0;
    --ink-2:         #bccbd0;
    --muted:         #8298a0;
    --faint:         #5d7178;

    --line:          #222f34;
    --line-strong:   #33454b;

    --accent:        #26c2cc;
    --accent-ink:    #04211f;
    --accent-soft:   #0e3236;
    --accent-line:   #1b585f;

    --ok:            #45c98a;
    --ok-soft:       #10301f;
    --warn:          #e0a83d;
    --warn-soft:     #33260d;
    --danger:        #f2705f;
    --danger-soft:   #3a1512;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, .55);

    color-scheme: dark;
  }
}

/* ─────────────── توکن‌ها: تیره (انتخاب صریح کاربر) ─────────────── */

:root[data-theme="dark"] {
  --bg:            #0b1113;
  --surface:       #121b1e;
  --surface-2:     #172226;
  --surface-sunk:  #0e1618;

  --ink:           #e6eef0;
  --ink-2:         #bccbd0;
  --muted:         #8298a0;
  --faint:         #5d7178;

  --line:          #222f34;
  --line-strong:   #33454b;

  --accent:        #26c2cc;
  --accent-ink:    #04211f;
  --accent-soft:   #0e3236;
  --accent-line:   #1b585f;

  --ok:            #45c98a;
  --ok-soft:       #10301f;
  --warn:          #e0a83d;
  --warn-soft:     #33260d;
  --danger:        #f2705f;
  --danger-soft:   #3a1512;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

/* ───────────────────────── پایه ───────────────────────── */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  font-feature-settings: "ss01";
  -webkit-font-smoothing: antialiased;
}

/* اعداد در ستون‌ها باید هم‌عرض باشند */
.num, table, .stat-value, .money { font-variant-numeric: tabular-nums; }

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.4;
  text-wrap: balance;
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .92rem; }

p { margin: 0; }
a { color: var(--accent); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

code, .mono, .ltr {
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}

/* برچسب‌های کوچک حروف‌بزرگ */
.eyebrow {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--faint);
  text-transform: uppercase;
}

/* ───────────────────────── سطح‌ها ───────────────────────── */

/* کارت: فقط جایی که واقعاً یک «شیء جدا» است */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
}
.card-flat { background: var(--surface); border-radius: var(--r-lg); padding: var(--s4); }
.sunk { background: var(--surface-sunk); border-radius: var(--r-md); }

/* ردیف‌های فهرست: بدون کارت، فقط با خط جداکننده */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.inline { display: flex; align-items: center; gap: var(--s2); }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.grow { flex: 1; min-width: 0; }

/* ───────────────────────── دکمه ───────────────────────── */

.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 11px 18px;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .06s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }

.btn-quiet {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--line-strong);
}
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-sm { padding: 7px 12px; font-size: .82rem; border-radius: var(--r-sm); }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: var(--s2); }
.btn-row > .btn { flex: 1; }

/* ───────────────────────── نشان وضعیت ───────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.pill-ok     { background: var(--ok-soft);     color: var(--ok); }
.pill-warn   { background: var(--warn-soft);   color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-mute   { background: var(--surface-sunk); color: var(--muted); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* نقطه‌ی وضعیت */
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-danger { background: var(--danger); }
.dot-mute { background: var(--faint); }

/* ───────────────────────── نوار مصرف ───────────────────────── */

.meter {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-sunk);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--ok);
  transition: width .45s cubic-bezier(.4, 0, .2, 1);
}
.meter.is-warn   > i { background: var(--warn); }
.meter.is-danger > i { background: var(--danger); }

.meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: .76rem;
  color: var(--muted);
  margin-top: 5px;
}

/* «آخرین مصرفِ تأییدشده» — عدد درست است ولی لحظه‌ای نیست. */
.meter-note {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 4px;
}
.meter-note.warn { color: var(--warn); }

/* ───────────────────────── فرم ───────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: .82rem; font-weight: 600; color: var(--ink-2); }

.input, .select, .textarea {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 10px 13px;
  font: inherit;
  font-size: .92rem;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder { color: var(--faint); }
.hint { font-size: .76rem; color: var(--muted); }
.error-text { font-size: .8rem; color: var(--danger); }

/* ───────────────────────── جدول ───────────────────────── */

.table-wrap { overflow-x: auto; }
table.data, table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  white-space: nowrap;
}
table.data th, table.table th {
  text-align: right;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--faint);
  padding: 0 var(--s3) var(--s2);
  border-bottom: 1px solid var(--line);
}
table.data td, table.table td {
  padding: var(--s3);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
}
table.data tbody tr:hover td, table.table tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr:last-child td, table.table tbody tr:last-child td { border-bottom: 0; }

/* ───────────────────────── حالت خالی ───────────────────────── */

.empty {
  text-align: center;
  padding: var(--s7) var(--s4);
  color: var(--muted);
}
.empty h3 { color: var(--ink-2); margin-bottom: 6px; }
.empty p { font-size: .88rem; margin-bottom: var(--s4); }

/* ───────────────────────── اسکلت بارگذاری ───────────────────────── */

.skeleton {
  background: linear-gradient(
    90deg, var(--surface-sunk) 25%, var(--surface-2) 50%, var(--surface-sunk) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ───────────────────────── توست ───────────────────────── */

.toast {
  position: fixed;
  inset-inline: var(--s4);
  bottom: var(--s5);
  max-width: 460px;
  margin-inline: auto;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: rise .22s cubic-bezier(.2, .8, .3, 1);
}
.toast.is-ok     { border-inline-start-color: var(--ok); }
.toast.is-danger { border-inline-start-color: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ───────────────────────── شیت پایین ───────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 150; }
.sheet-veil {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 14, .55);
  backdrop-filter: blur(2px);
  animation: fade .18s;
}
.sheet-panel {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--s2) var(--s4) var(--s6);
  max-height: 88vh;
  overflow-y: auto;
  animation: slide-up .26s cubic-bezier(.2, .8, .3, 1);
}
.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  margin: var(--s2) auto var(--s4);
}
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

/* ───────────────────────── احترام به کاهش حرکت ───────────────────────── */

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