/* حساب‌یار — مرجع طراحی: Apple Native (.ux-profile.md)
   رنگ‌بندی سرمه‌ای و طلایی: زمینه‌ی خنثی‌ی گرم، فهرست‌های گروهی بدون سایه، سرمه‌ای برای کنترل‌ها،
   و طلایی فقط روی خط‌های برگه‌ی T در خانه (یک جای پررنگ، بقیه آرام).
   مبلغ‌ها شخصیت اصلی صفحه‌اند. قرمز = بدهی/دیرکرد، سبز = دریافت/تسویه؛ هیچ‌جا تزئینی نیستند.
   سه نقطه‌ی شکست: باریک < 768، متوسط 768–1279، پهن ≥ 1280. */

@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-SemiBold.woff2) format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --vp-narrow: 375px; --vp-medium: 768px; --vp-wide: 1280px;

  /* سطح‌ها */
  --canvas: #F4F3EF;
  --surface: #FFFFFF;
  --sunken: #ECEBE5;
  --hover: #F8F7F3;
  --sep: rgba(28, 36, 56, 0.12);               /* جداکننده‌ی ردیف‌ها */
  --field: #8C95A4;                            /* لبه‌ی ورودی‌ها؛ ۳:۱ روی سفید */
  --overlay: 0 12px 32px rgba(28, 36, 56, 0.08);
  --edge: 1px solid rgba(28, 36, 56, 0.14);    /* لبه‌ی هر لایه‌ی شناور، پیش از سایه */

  /* متن */
  --ink: #1C2438;
  --ink-2: #454C5E;                            /* ۸٫۵:۱ روی سفید */
  --ink-3: #5D6372;                            /* ۶:۱ روی سفید، ۵٫۴:۱ روی زمینه */

  /* تأکید و معنا */
  --accent: #22335C;                           /* سرمه‌ای */
  --accent-press: #182648;
  --accent-soft: #E7EAF2;
  --hero: #1F2B47;                             /* زمینه‌ی برگه‌ی T */
  --hero-ink: #FFFFFF;
  --hero-muted: #C8CFDF;                       /* ۸٫۸:۱ روی سرمه‌ای */
  --gold: #C9A24A;                             /* فقط خط‌های برگه‌ی T و نشان */
  --ok: #16753A;   --ok-soft: #E7F4EC;
  --due: #B4232B;  --due-soft: #FBECEC;
  --warn: #7A5300; --warn-soft: #FFF4D6;

  /* فاصله و گوشه */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px; --s12: 48px;
  --radius: 10px;                              /* کنترل‌ها */
  --radius-lg: 14px;                           /* گروه‌ها و برگه‌ها */
  --hit: 44px;
  --row: 52px;
  --tabbar: 64px;

  /* حروف: ۱۲ / ۱۴ / ۱۶ / ۱۸ / ۲۲ / ۲۸ و مبلغ ۴۰ */
  --t-meta: 0.75rem; --t-sec: 0.875rem; --t-body: 1rem; --t-h3: 1.125rem; --t-h2: 1.375rem; --t-h1: 1.75rem; --t-money: 2.5rem;

  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; }
body { margin: 0; background: var(--canvas); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
strong, b, th { font-weight: 600; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: var(--t-h1); letter-spacing: -0.01em; }
h2 { font-size: var(--t-h3); }
h3 { font-size: var(--t-body); }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
.muted { color: var(--ink-3); }
.small { font-size: var(--t-sec); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; flex-wrap: nowrap !important; }
.strike { text-decoration: line-through; }
.text-due { color: var(--due); }
.text-ok { color: var(--ok); }
.pad { padding: var(--s3) var(--s4); }
.gap-top { margin-top: var(--s6); }
.stack > * + * { margin-top: var(--s4); }
.stack-tight { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stack-tight.end { align-items: flex-end; }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.spread { justify-content: space-between; }
.narrow { max-width: 440px; }
.loading { padding: var(--s12); text-align: center; color: var(--ink-3); }

/* ---------- پوسته ---------- */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; width: 100%; }
nav.side {
  background: var(--canvas); border-inline-end: 1px solid var(--sep);
  padding: var(--s4) var(--s3); position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s1);
}
.brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s6); }
.brand > div { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 10px; background: var(--hero); color: var(--gold); font-weight: 600; font-size: 1.125rem;
}
nav.side a {
  display: flex; align-items: center; min-height: var(--hit);
  padding: 0 var(--s3); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-weight: 500;
}
nav.side a[aria-current=page] { background: var(--accent); color: #fff; }
@media (hover: hover) { nav.side a:not([aria-current=page]):hover { background: var(--sunken); } }
.who { margin-top: auto; padding: var(--s4) var(--s2) 0; border-top: 1px solid var(--sep); display: grid; gap: var(--s2); }
.biz-switch { width: 100%; }
.content { min-width: 0; display: flex; flex-direction: column; }
main { padding: var(--s8) var(--s8) var(--s12); max-width: var(--vp-wide); width: 100%; margin-inline: auto; outline: none; }
.topbar, .tabbar, .scrim { display: none; }

/* باریک: نوار پایین به‌جای ستون کناری؛ «بیشتر» همان منوی کامل را باز می‌کند */
@media (max-width: 767.98px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  nav.side {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: min(320px, 86vw); z-index: 30;
    background: var(--surface); transform: translateX(100%); transition: transform 200ms cubic-bezier(0, 0, 0.2, 1);
    border-inline-end: var(--edge); box-shadow: var(--overlay); padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  }
  body.nav-open nav.side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(28, 36, 56, 0.32); z-index: 20; }
  .topbar {
    display: flex; align-items: center; justify-content: center; position: sticky; top: 0; z-index: 10;
    background: rgba(244, 243, 239, 0.96); border-bottom: 1px solid var(--sep); padding: var(--s2) var(--s4); min-height: 48px;
  }
  .topbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--t-sec); }
  .topbar .menu-btn { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: 15;
    background: var(--surface); border-top: 1px solid var(--sep);
    padding-bottom: env(safe-area-inset-bottom); min-height: var(--tabbar);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tabbar);
    background: none; border: 0; color: var(--ink-3); font-size: var(--t-meta); font-weight: 500; text-decoration: none; cursor: pointer;
  }
  .tabbar .icon { width: 24px; height: 24px; }
  .tabbar a[aria-current=page] { color: var(--accent); }
  main { padding: var(--s6) var(--s4) calc(var(--tabbar) + var(--s8)); }
  #toasts { bottom: calc(var(--tabbar) + var(--s3)); }
}
@media (prefers-reduced-motion: reduce) { nav.side { transition: none; } }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s6); }
.pagehead > div > a.small { display: inline-block; margin-bottom: var(--s1); }
.banner { background: var(--accent-soft); color: var(--accent); padding: var(--s3) var(--s4); border-radius: var(--radius); margin-bottom: var(--s4); }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-radius: 0; margin: 0; padding-inline: var(--s8); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin: var(--s4) 0; }
.toolbar input[type=search] { max-width: 300px; }
.month-nav { display: flex; align-items: center; gap: var(--s1); }
.month-nav strong { min-width: 112px; text-align: center; }

/* ---------- سطح‌ها: گروه‌های درون‌رفته ---------- */
.panel { background: var(--surface); border-radius: var(--radius-lg); padding: var(--s4) var(--s6); min-width: 0; }
.panel.flush { padding: 0; overflow: hidden; }
.panel > h2 { margin-bottom: var(--s2); }
.panel.flush > h2 { margin: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s1); }
fieldset.panel { margin: 0; border: 0; }
fieldset.panel legend { font-weight: 600; padding: 0; float: inline-start; width: 100%; margin-bottom: var(--s3); }
fieldset.plain { border: 0; padding: 0; margin: 0; }
fieldset.plain legend { padding: 0; margin-bottom: var(--s1); font-size: var(--t-sec); color: var(--ink-2); }
.grid { display: grid; gap: var(--s6); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: start; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.grid-form { display: grid; gap: var(--s4) var(--s6); grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.grid-2-tight { display: grid; gap: var(--s3); grid-template-columns: 1fr 1fr; }
.grid-2-tight > * + * { margin-top: 0; }

.stat { display: block; background: var(--surface); border-radius: var(--radius-lg); padding: var(--s4) var(--s6); color: var(--ink-2); font-size: var(--t-sec); text-decoration: none; }
.stat b { display: block; font-size: var(--t-h2); color: var(--ink); line-height: 1.3; margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.stat.due b { color: var(--due); }
.stat.credit b, .stat.ok b { color: var(--ok); }

/* ---------- برگه‌ی T: خلاصه‌ی حساب در خانه ---------- */
.ledger { background: var(--hero); color: var(--hero-ink); border-radius: var(--radius-lg); padding: var(--s6) var(--s6) var(--s6); margin-bottom: var(--s6); }
.ledger a { color: inherit; text-decoration: none; }
.ledger a:focus-visible { outline-color: var(--gold); }
.ledger-top { display: block; padding-bottom: var(--s4); border-bottom: 2px solid var(--gold); text-align: center; }
.ledger-label { display: block; font-size: var(--t-sec); color: var(--hero-muted); }
.ledger-amount { display: block; font-size: var(--t-money); font-weight: 600; line-height: 1.2; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ledger-amount .unit { font-size: var(--t-body); font-weight: 500; color: var(--hero-muted); margin-inline-start: var(--s2); letter-spacing: 0; }
.ledger-cols { display: grid; grid-template-columns: 1fr 1fr; }
.ledger-col { display: block; padding: var(--s4) var(--s3) 0; text-align: center; min-height: var(--hit); }
.ledger-col + .ledger-col { border-inline-start: 2px solid var(--gold); }
.ledger-col b { display: block; font-size: var(--t-h2); line-height: 1.3; font-variant-numeric: tabular-nums; }
.ledger-col .ledger-label { margin-bottom: 2px; }
@media (max-width: 767.98px) {
  .ledger { padding: var(--s6) var(--s4) var(--s4); }
  .ledger-amount { font-size: 2.125rem; }
  .ledger-col b { font-size: var(--t-h3); }
}

/* میان‌برها */
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: var(--s2); margin-bottom: var(--s6); }
.quick-btn {
  display: flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 var(--s3);
  border: 0; border-radius: var(--radius); background: var(--surface);
  color: var(--accent); font-weight: 600; text-decoration: none; cursor: pointer;
}
.quick-btn:active { background: var(--sunken); }
.quick-btn.primary { background: var(--accent); color: #fff; }
.quick-btn.primary:active { background: var(--accent-press); }
@media (max-width: 767.98px) { .quick { grid-template-columns: 1fr 1fr; } .quick-btn.primary { grid-column: 1 / -1; } }

/* ---------- فهرست‌ها (جداکننده از لبه‌ی آغاز فاصله دارد) ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { position: relative; }
.list > li + li::before {
  content: ''; position: absolute; top: 0; inset-inline-start: var(--s6); inset-inline-end: 0; height: 1px; background: var(--sep);
}
.panel:not(.flush) .list > li + li::before { inset-inline-start: 0; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
  min-height: var(--row); padding: var(--s2) var(--s6); color: inherit; text-decoration: none;
}
a.list-row:active { background: var(--sunken); }
/* نشانه‌ی ردیف قابل کلیک: فلش رو به جلو (در راست‌به‌چپ، رو به چپ) */
a.list-row::after {
  content: ''; flex: none; width: 8px; height: 8px; margin-inline-start: calc(var(--s2) * -1);
  border-left: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg);
}
@media (hover: hover) { a.list-row:hover { background: var(--hover); } }
.panel:not(.flush) .list-row { padding-inline: 0; }
.list-row.total { font-weight: 600; background: var(--hover); }
.panel:not(.flush) .list-row.total { padding-inline: var(--s3); border-radius: var(--radius); }
.amt-due { color: var(--due); }
.amt-credit { color: var(--ok); }
.amt { white-space: nowrap; font-variant-numeric: tabular-nums; }
.amt-tag { font-size: var(--t-meta); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: var(--s3) var(--s3); text-align: start; border-bottom: 1px solid var(--sep); vertical-align: top; }
.table thead th { color: var(--ink-3); font-size: var(--t-meta); font-weight: 500; border-bottom-color: var(--sep); padding-block: var(--s2); }
.table td.num, .table th.num { text-align: end; }
.table tfoot th { text-align: end; font-weight: 500; color: var(--ink-2); border-bottom: 0; }
.table tfoot td { text-align: end; border-bottom: 0; }
.table tfoot tr.total th, .table tfoot tr.total td { font-weight: 600; color: var(--ink); font-size: var(--t-h3); border-top: 2px solid var(--ink); }
.table tfoot tr.due td { color: var(--due); font-weight: 600; }
.table tr.muted td { color: var(--ink-3); }

.tag { display: inline-block; font-size: var(--t-meta); padding: 0 var(--s2); border-radius: 6px; background: var(--sunken); color: var(--ink-2); line-height: 1.75; font-weight: 500; }
.tag-due, .tag-bounced { background: var(--due-soft); color: var(--due); }
.tag-cleared, .tag-job-ready { background: var(--ok-soft); color: var(--ok); }
.tag-in { background: var(--ok-soft); color: var(--ok); }
.tag-out, .tag-job-in_progress { background: var(--accent-soft); color: var(--accent); }

.empty-state { text-align: center; padding: var(--s12) var(--s4); color: var(--ink-2); display: grid; gap: var(--s4); justify-items: center; background: var(--surface); border-radius: var(--radius-lg); }

/* ---------- دکمه‌ها ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--hit); padding: 0 var(--s4); border-radius: var(--radius);
  border: 0; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 0.9375rem; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:active { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); filter: none; }
.btn-danger { background: var(--due); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); font-weight: 500; }
.btn-ghost.danger { color: var(--due); }
@media (hover: hover) {
  .btn:hover { filter: brightness(0.97); }
  .btn-primary:hover { background: var(--accent-press); filter: none; }
  .btn-ghost:hover { background: var(--accent-soft); filter: none; }
}
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--t-sec); }
.btn-block { width: 100%; min-height: 48px; }
.link { background: none; border: 0; padding: var(--s2) 0; min-height: var(--hit); color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
@media (pointer: coarse) { .btn-sm { min-height: var(--hit); } }

/* زبانه‌ها: کنترل بخش‌بندی‌شده */
.tabs {
  display: flex; gap: var(--s1); overflow-x: auto; scrollbar-width: none; margin-bottom: var(--s4);
  background: var(--sunken); border-radius: var(--radius); padding: var(--s1); width: fit-content; max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; background: none; border: 0; border-radius: 8px; padding: 0 var(--s4); min-height: 38px;
  color: var(--ink-2); cursor: pointer; white-space: nowrap; font-weight: 500; font-size: var(--t-sec);
}
.tabs button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px rgba(28, 36, 56, 0.10); }
.toolbar .tabs { margin: 0; }
@media (pointer: coarse) { .tabs button { min-height: var(--hit); } }

/* ---------- فرم‌ها ---------- */
.field { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.field .label { font-size: var(--t-sec); color: var(--ink-2); font-weight: 500; }
.hint { font-size: 0.8125rem; color: var(--ink-3); }
.hint.words { min-height: 1.2em; }
input[type=text], input[type=tel], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: var(--hit); padding: var(--s2) var(--s3); border: 1px solid var(--field);
  border-radius: var(--radius); background: var(--surface);
}
textarea { resize: vertical; }
/* جست‌وجو: ذره‌بین در لبه‌ی آغاز، تا بدون برچسب هم شناخته شود */
input[type=search] {
  padding-inline-start: 40px; background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27%235B6475%27 stroke-width=%272%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3E%3Ccircle cx=%2711%27 cy=%2711%27 r=%278%27/%3E%3Cpath d=%27m21 21-4.3-4.3%27/%3E%3C/svg%3E");
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--accent-soft); outline-offset: 0; }
input.num, input.date { text-align: start; }
input[dir=ltr] { text-align: left; }
.amount-wrap { position: relative; display: block; }
.amount-wrap input { padding-inline-end: 64px; font-variant-numeric: tabular-nums; font-size: var(--t-h3); font-weight: 500; }
.amount-wrap .suffix { position: absolute; inset-inline-end: var(--s3); top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: 0.8125rem; pointer-events: none; }
.check { display: inline-flex; align-items: center; gap: var(--s2); min-height: var(--hit); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.form-error { color: var(--due); background: var(--due-soft); padding: var(--s3) var(--s4); border-radius: var(--radius); font-size: 0.9375rem; }
details summary { cursor: pointer; color: var(--accent); min-height: var(--hit); display: flex; align-items: center; }
.row.nowrap > input { flex: 1; }

/* انتخاب طرف حساب */
.picker { position: relative; }
.popover {
  position: absolute; inset-inline: 0; top: calc(var(--hit) + 4px); z-index: 40; margin: 0; padding: var(--s1);
  list-style: none; background: var(--surface); border-radius: var(--radius);
  border: var(--edge); box-shadow: var(--overlay); max-height: 280px; overflow-y: auto;
}
.popover li { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s3); min-height: var(--hit); align-items: center; border-radius: 8px; cursor: pointer; }
.popover li:hover { background: var(--sunken); }
.picker > input + input { margin-top: var(--s2); }

/* ردیف‌های فاکتور */
.item-head, .item-row { display: grid; gap: var(--s2); align-items: start; grid-template-columns: minmax(0, 3fr) 80px minmax(0, 1.4fr) 96px minmax(90px, 1fr) 64px; }
.item-head { font-size: var(--t-meta); color: var(--ink-3); padding-bottom: var(--s1); }
.item-row { padding: var(--s3) 0; border-top: 1px solid var(--sep); }
.row-amount { display: block; text-align: end; padding-top: 10px; font-weight: 600; }
.totals { margin-top: var(--s6); margin-inline-start: auto; max-width: 380px; display: grid; gap: var(--s1); }
.tot-line { display: flex; justify-content: space-between; gap: var(--s4); }
.tot-line.grand { font-size: var(--t-h2); font-weight: 600; border-top: 2px solid var(--ink); padding-top: var(--s2); margin-top: var(--s1); }
@media (max-width: 767.98px) {
  .item-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; grid-template-areas: 'desc desc' 'qty price' 'kind amount' 'del del'; }
  .c-desc { grid-area: desc; } .c-qty { grid-area: qty; } .c-price { grid-area: price; }
  .c-kind { grid-area: kind; } .c-amount { grid-area: amount; } .c-del { grid-area: del; justify-self: start; }
  .totals { max-width: none; }
}

.inv-meta { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s8); margin-bottom: var(--s6); }
.inv-meta > div { display: flex; flex-direction: column; }
.note { margin-top: var(--s3); color: var(--ink-2); white-space: pre-line; max-width: 75ch; }
.empty-state p, .banner, .hint { max-width: 75ch; }
.balance-box { display: flex; flex-direction: column; align-items: flex-end; padding: var(--s2) var(--s4); border-radius: var(--radius); background: var(--surface); }
.balance-box strong { font-size: var(--t-h3); }
.balance-box.due { background: var(--due-soft); color: var(--due); }
.balance-box.credit { background: var(--ok-soft); color: var(--ok); }

/* کارت‌های کار */
.cards { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.card { background: var(--surface); border-radius: var(--radius-lg); padding: var(--s4) var(--s6); display: flex; flex-direction: column; gap: var(--s2); }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-actions { margin-top: auto; padding-top: var(--s2); }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* نمودار */
.chart svg { display: block; width: 100%; height: auto; }
.chart .bar { fill: var(--accent); }
.chart .axis { stroke: var(--sep); }

/* ---------- پنجره‌ها: در گوشی، برگه‌ای که از پایین بالا می‌آید ---------- */
dialog {
  border: 0; border-radius: var(--radius-lg); padding: var(--s6); width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow-y: auto; border: var(--edge); box-shadow: var(--overlay); color: var(--ink); background: var(--surface);
}
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(28, 36, 56, 0.36); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
.dlg-head h3 { font-size: var(--t-h3); }
.dlg-actions { padding-top: var(--s2); }
@media (max-width: 767.98px) {
  dialog {
    width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0;
    padding: var(--s6) var(--s4) calc(var(--s6) + env(safe-area-inset-bottom));
  }
  dialog[open] { animation: sheet-up 300ms cubic-bezier(0, 0, 0.2, 1); }
  dialog { border-inline: 0; border-bottom: 0; }
  dialog::before { content: ''; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--sep); margin: -8px auto var(--s3); }
  .dlg-actions .btn { flex: 1; }
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog[open] { animation: none; } }

#toasts { position: fixed; bottom: var(--s6); inset-inline: var(--s4); display: grid; justify-items: center; gap: var(--s2); z-index: 100; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: var(--s3) var(--s6); border-radius: var(--radius); max-width: 520px; }
.toast-error { background: var(--due); }
.toast-ok { background: var(--ok); }

/* ---------- ورود ---------- */
.auth { min-height: 100vh; display: grid; place-content: center; gap: var(--s6); padding: var(--s6) var(--s4); }
.auth-brand { text-align: center; display: grid; justify-items: center; gap: var(--s2); }
.auth-brand .logo { width: 60px; height: 60px; font-size: 1.875rem; border-radius: 16px; }
.auth-card { width: min(420px, calc(100vw - 32px)); background: var(--surface); border-radius: var(--radius-lg); padding: var(--s6); }
.auth-card .tabs { width: 100%; margin: 0 0 var(--s6); }
.auth-card .tabs button { flex: 1; }

/* پنل پیامک */
.provider-pick { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.provider-card {
  display: flex; flex-direction: column; gap: var(--s1); padding: var(--s3) var(--s4); min-height: 64px;
  border: 2px solid transparent; border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); text-decoration: none;
}
.provider-card.selected { border-color: var(--accent); }
.pattern-row { display: grid; gap: var(--s2); grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); align-items: start; }
.pattern-row details summary { min-height: 32px; margin-top: 26px; }
.template { white-space: pre-wrap; background: var(--sunken); border-radius: var(--radius); padding: var(--s2) var(--s3); margin: var(--s2) 0; font: inherit; font-size: var(--t-sec); }
.test-row { display: grid; gap: var(--s3); grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; align-items: end; padding-top: var(--s4); border-top: 1px solid var(--sep); }
.banner-ok { background: var(--ok-soft); color: var(--ok); }
.banner-error { background: var(--due-soft); color: var(--due); }
.sms-result .banner { margin: 0; }
@media (max-width: 767.98px) {
  .pattern-row, .test-row { grid-template-columns: 1fr; }
  .pattern-row details summary { margin-top: 0; }
}

/* باریک: اگر دکمه‌های یک ردیف جا نشوند، به سطر بعد می‌روند (به‌جای بریده شدن) */
@media (max-width: 767.98px) {
  .list-row:not(a) { flex-wrap: wrap; }
  .list-row:not(a) > :first-child { flex: 1 1 auto; }
  .list-row > .row.nowrap { flex-wrap: wrap !important; justify-content: flex-end; }
}
