@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ظاهر «دفتر حساب»: کاغذ گرم، جوهر تیره، سبز دفتری. پیش‌فرض روشن است. */
:root, :root[data-theme="light"] {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8d8;
  --text: #2a251d;
  --muted: #7a7062;
  --line: #e2d9c6;
  --line-strong: #cfc4ab;
  --primary: #0f6b57;
  --primary-text: #ffffff;
  --primary-soft: #dcebe4;
  --ok: #1f7a44;
  --ok-soft: #dfeedd;
  --warn: #946200;
  --warn-soft: #f6e8c4;
  --bad: #a8362b;
  --bad-soft: #f6ddd8;
  --radius: 10px;
  --nav-h: 62px;
  --font: "Vazirmatn", Tahoma, "Segoe UI", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #17150f; --surface: #1f1c14; --surface-2: #2a261b; --text: #ece5d4; --muted: #a39a85; --line: #342f22; --line-strong: #4a4332;
  --primary: #5fc9a8; --primary-text: #0b1a14; --primary-soft: #1b3a30;
  --ok: #7ad49a; --ok-soft: #1a3322; --warn: #e5b45a; --warn-soft: #3a2d10; --bad: #f0877a; --bad-soft: #3d1f1a;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #17150f; --surface: #1f1c14; --surface-2: #2a261b; --text: #ece5d4; --muted: #a39a85; --line: #342f22; --line-strong: #4a4332;
    --primary: #5fc9a8; --primary-text: #0b1a14; --primary-soft: #1b3a30;
    --ok: #7ad49a; --ok-soft: #1a3322; --warn: #e5b45a; --warn-soft: #3a2d10; --bad: #f0877a; --bad-soft: #3d1f1a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16.5px; line-height: 1.75; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.45; }
h1 { font-size: 1.3rem; font-weight: 800; }
h2 { font-size: 1.08rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.small { font-size: .85rem; }
.section-title { font-size: .85rem; font-weight: 700; color: var(--muted); margin: 6px 2px -4px; letter-spacing: 0; }

/* چارچوب */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar { background: var(--bg); padding: 14px 18px 10px; padding-top: calc(14px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.topbar .date { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.page { padding: 16px 16px 24px; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.nav { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line-strong);
  display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
.nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); font-size: .74rem; }
.nav a svg { width: 23px; height: 23px; }
.nav a.active { color: var(--primary); font-weight: 700; }
.nav a.active::before { content: ""; position: absolute; top: -1px; width: 28px; height: 3px; background: var(--primary); border-radius: 0 0 3px 3px; }
@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-inline-start: 214px; }
  .nav { inset-inline: auto; inset-inline-start: 0; top: 0; bottom: 0; width: 214px; height: auto; grid-template-columns: 1fr; align-content: start;
    border-top: 0; border-inline-end: 1px solid var(--line-strong); padding: 18px 10px; gap: 2px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 14px; border-radius: 8px; font-size: 1rem; }
  .nav a.active { background: var(--primary-soft); }
  .nav a.active::before { display: none; }
  .page { max-width: 960px; padding-top: 22px; }
  .topbar { padding-inline: 28px; }
}

/* اجزا */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card.tap { display: block; color: inherit; }
.card.tap:active, .item:active { background: var(--surface-2); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* خلاصه‌ی اعداد؛ مثل برگه‌های بالای دفتر */
.tile { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--line-strong); border-radius: 6px; padding: 10px 12px 8px; }
.tile .label { color: var(--muted); font-size: .82rem; }
.tile .value { font-size: 1.2rem; font-weight: 800; line-height: 1.5; }
.tile .hint { font-size: .78rem; color: var(--muted); }
.tile.bad { border-top-color: var(--bad); } .tile.bad .value { color: var(--bad); }
.tile.ok { border-top-color: var(--ok); } .tile.ok .value { color: var(--ok); }
.tile.main { border-top-color: var(--primary); }

.btn { appearance: none; border: 1px solid transparent; border-radius: 8px; min-height: 46px; padding: 0 18px; background: var(--primary); color: var(--primary-text);
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { filter: brightness(.93); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); font-weight: 600; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: .88rem; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: .88rem; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input { width: 100%; min-height: 46px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 12px; background: var(--surface); }
textarea.input { min-height: 84px; }
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.input.ltr { direction: ltr; text-align: right; }
.hint { font-size: .8rem; color: var(--muted); }
.err { color: var(--bad); font-size: .85rem; }

.badge { display: inline-flex; align-items: center; padding: 1px 9px; border-radius: 6px; font-size: .76rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* فهرست: یک برگه‌ی واحد با خط‌های جداکننده */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: inherit; background: transparent; border: 0; border-bottom: 1px solid var(--line); width: 100%; }
.item:last-child { border-bottom: 0; }
.item .name { font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 8px 0 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: end; }

.steps { display: flex; gap: 6px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--line-strong); }
.steps span.on { background: var(--primary); }
.sticky-actions { position: sticky; z-index: 5; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); display: flex; gap: 10px;
  margin-inline: -16px; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line-strong); }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
.sticky-actions .btn { flex: 1; }
.seg { display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line-strong); }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: transparent; }
.check:last-child { border-bottom: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.center { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 22px 20px; }
.login .brand { text-align: center; color: var(--muted); font-size: .9rem; }
.toast { position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + 16px); z-index: 50; padding: 12px 16px; border-radius: 8px; color: #fff; background: #3a342a; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.22); }
.toast.error { background: var(--bad); } .toast.ok { background: var(--ok); }
@media (min-width: 900px) { .toast { inset-inline: auto; inset-inline-start: 238px; bottom: 24px; min-width: 280px; } }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 6px; text-align: start; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.spacer { height: 4px; }
details.card > summary { cursor: pointer; font-weight: 600; }

/* چاپ: فقط برگه. اندازه‌ی کاغذ از خود صفحه (کلاس‌های sheet-a4 / sheet-a5) می‌آید */
.sheet { background: #fff; color: #000; border: 1px solid var(--line-strong); border-radius: 6px; padding: 14px; font-size: 12.5px; line-height: 1.8; }
.sheet h1 { font-size: 1.15rem; } .sheet h2 { font-size: 1rem; margin-top: 8px; border-bottom: 1px solid #000; }
.sheet table { width: 100%; border-collapse: collapse; margin: 4px 0; }
.sheet th, .sheet td { border: 1px solid #000; padding: 2px 6px; text-align: start; }
.sheet .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .sign { height: 70px; border: 1px solid #000; padding: 4px; }
.sheet .num { direction: ltr; }
.sheet + .sheet { margin-top: 12px; }
@media print {
  .nav, .topbar, .no-print, .toast, .sticky-actions { display: none !important; }
  html, body { background: #fff !important; }
  .shell { padding: 0 !important; }
  .page { max-width: none !important; padding: 0 !important; gap: 0 !important; }
  .sheet { border: 0; border-radius: 0; padding: 0; font-size: 11pt; page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
}

/* انتخاب سریع تاریخ و پیشنهاد کالا */
.chip { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.suggest { position: absolute; inset-inline: 0; top: 100%; z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-top: 2px; max-height: 260px; overflow: auto; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.suggest-item { display: block; width: 100%; text-align: start; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 11px 12px; font: inherit; color: var(--text); cursor: pointer; }
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover, .suggest-item:focus { background: var(--primary-soft); }
select.input { appearance: auto; }
/* صورت‌حساب خط‌به‌خط (شبیه دفتر حساب) */
.ledger { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ledger td { padding: 7px 4px; vertical-align: top; }
.ledger .amt { text-align: end; white-space: nowrap; }
.ledger tr.rule td { border-bottom: 1.5px solid var(--text); }
.ledger tr.sub td { font-weight: 700; }
.ledger tr.info td { color: var(--muted); font-size: .9rem; }
.ledger .det { display: block; color: var(--muted); font-size: .8rem; }
.ledger .neg { color: var(--bad); }
.ledger .date { color: var(--muted); font-size: .78rem; white-space: nowrap; }

/* ستون چرخان تاریخ (مثل ساعت گوشی) */
.wheel { height: 120px; overflow-y: scroll; scroll-snap-type: y mandatory; padding-block: 40px; -webkit-overflow-scrolling: touch; scrollbar-width: none; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.wheel::-webkit-scrollbar { display: none; }
.wheel-item { height: 40px; line-height: 40px; text-align: center; scroll-snap-align: center; color: var(--muted); font-size: .92rem; cursor: pointer; white-space: nowrap; }
.wheel-item.on { color: var(--text); font-weight: 800; font-size: 1rem; }
.wheel-mid { position: absolute; inset-inline: 0; top: 60px; height: 40px; border-block: 2px solid var(--primary); pointer-events: none; opacity: .55; }
/* جدول مدت‌ها: مربع‌های دوتایی یا سه‌تایی */
.terms-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .terms-grid { grid-template-columns: repeat(3, 1fr); } }
.term-tile { text-align: center; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 6px; font: inherit; color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.term-tile.on { background: var(--primary-soft); border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.term-tile .m { font-weight: 800; }
.term-tile .pay { font-size: 1.05rem; font-weight: 800; }
