/* حساب — ledger-paper design system
   lapis ink on cool paper; green/madder bookkeeping inks; totals get the accountant's double rule. */
:root {
  --paper: #f5f6f8;
  --surface: #ffffff;
  --ink: #1b2433;
  --ink-2: #4a5568;
  --ink-3: #7a8597;
  --rule: #d9dee6;
  --rule-soft: #eaedf2;
  --lapis: #1f3a8a;
  --lapis-2: #2c4fb8;
  --lapis-tint: #e8edfa;
  --income: #157f5b;
  --income-tint: #e4f3ed;
  --expense: #b4322e;
  --expense-tint: #f9e7e6;
  --gold: #a87a22;
  --gold-tint: #f7efdd;
  --r-sm: 6px;
  --r-md: 10px;
  --font: "Vazirmatn", "Vazir", Tahoma, "Segoe UI", system-ui, sans-serif;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper);
  line-height: 1.75; -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01";
}
a { color: var(--lapis); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 var(--s3); line-height: 1.4; font-weight: 800; }
h1 { font-size: 1.85rem; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; font-weight: 700; }
p { margin: 0 0 var(--s3); max-width: 70ch; }
code { background: var(--rule-soft); padding: 1px 6px; border-radius: 4px; direction: ltr; display: inline-block; }
.num, .amount { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: .87rem; }
.ltr { direction: ltr; text-align: left; }
:focus-visible { outline: 2px solid var(--lapis-2); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-weight: 600; font-size: .95rem; padding: 8px 18px; min-height: 40px;
  border-radius: var(--r-sm); border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none !important; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--lapis); border-color: var(--lapis); color: #fff; }
.btn.primary:hover { background: var(--lapis-2); }
.btn.danger { color: var(--expense); border-color: #e7c3c1; }
.btn.danger:hover { background: var(--expense-tint); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--rule-soft); }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: .87rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.form { display: grid; gap: var(--s4); }
.form h3 { margin: var(--s3) 0 0; }
label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 8px 12px; min-height: 42px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--lapis-2); box-shadow: 0 0 0 3px var(--lapis-tint); }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--lapis); }
.check { display: flex; align-items: center; gap: var(--s2); font-weight: 500; }
.field-error input { border-color: var(--expense); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.alert { padding: var(--s3) var(--s4); border-radius: var(--r-sm); border-inline-start: 3px solid; margin-bottom: var(--s4); font-size: .93rem; }
.alert.error { background: var(--expense-tint); border-color: var(--expense); color: #7d1f1c; }
.alert.success { background: var(--income-tint); border-color: var(--income); color: #0d5a40; }
.alert.info { background: var(--lapis-tint); border-color: var(--lapis); color: var(--lapis); }
.alert.warn { background: var(--gold-tint); border-color: var(--gold); color: #6e4f14; }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 1px 10px; border-radius: 99px; background: var(--rule-soft); color: var(--ink-2); }
.badge.green { background: var(--income-tint); color: var(--income); }
.badge.red { background: var(--expense-tint); color: var(--expense); }
.badge.blue { background: var(--lapis-tint); color: var(--lapis); }
.badge.gold { background: var(--gold-tint); color: var(--gold); }

/* ---------- app shell (RTL: sidebar on the right) ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--rule); padding: var(--s5) var(--s4);
  display: flex; flex-direction: column; gap: var(--s5); position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: var(--s3); font-weight: 800; font-size: 1.3rem; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--lapis); color: #fff;
  display: grid; place-items: center; font-size: 1.1rem; font-weight: 800;
}
.org-switch select { font-weight: 600; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--s3); padding: 8px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; }
.nav a:hover { background: var(--rule-soft); color: var(--ink); }
.nav a.active { background: var(--lapis-tint); color: var(--lapis); font-weight: 700; }
.nav-group { font-size: .8rem; color: var(--ink-3); padding: var(--s3) 12px 2px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--rule-soft); padding-top: var(--s4); font-size: .88rem; }
.main { padding: var(--s6) var(--s6) var(--s7); min-width: 0; }
.main:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.topbar { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; align-content: start; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 270px; z-index: 40; transform: translateX(100%); transition: transform .2s; box-shadow: none; }
  .shell.nav-open .sidebar { transform: none; box-shadow: -8px 0 30px rgba(27,36,51,.18); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 30; }
  .main { padding: var(--s5) var(--s4) var(--s7); }
}

/* ---------- panels & ledger tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s5); margin-bottom: var(--s5); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.panel-head h2, .panel-head h3 { margin: 0; }
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--s5)); padding: 0 var(--s5); }
table.ledger { width: 100%; border-collapse: collapse; font-size: .93rem; }
.ledger th { text-align: start; font-weight: 600; color: var(--ink-3); font-size: .84rem; padding: 6px 10px; border-bottom: 1px solid var(--ink-3); white-space: nowrap; }
.ledger td { padding: 10px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.ledger tr:hover td { background: #fafbfc; }
.ledger .amount, .ledger th.amount { text-align: end; }
.ledger tfoot td { border-bottom: 3px double var(--ink); font-weight: 800; }
.amount.in { color: var(--income); }
.amount.out { color: var(--expense); }
.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--ink-3); }
.empty h3 { color: var(--ink); }

/* figures strip — a ruled ledger summary rather than stat cards */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); margin-bottom: var(--s5); background: var(--surface); }
.figure { padding: var(--s4) var(--s5); border-inline-start: 1px solid var(--rule-soft); }
.figure:first-child { border-inline-start: 0; }
.figure .label { font-size: .85rem; color: var(--ink-3); }
.figure .value { font-size: 1.55rem; font-weight: 800; font-feature-settings: "tnum"; }
.figure .value small { font-size: .8rem; font-weight: 500; color: var(--ink-3); margin-inline-start: 4px; }

.meter { height: 6px; background: var(--rule-soft); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--lapis); border-radius: 99px; }
.meter.full > span { background: var(--expense); }

/* ---------- plans ---------- */
.cycle-toggle { display: inline-flex; border: 1px solid var(--rule); border-radius: 99px; padding: 3px; background: var(--surface); }
.cycle-toggle button { font: inherit; font-weight: 600; border: 0; background: none; padding: 4px 16px; border-radius: 99px; cursor: pointer; color: var(--ink-2); }
.cycle-toggle button.on { background: var(--ink); color: #fff; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.plan { padding: var(--s5); border-inline-start: 1px solid var(--rule); display: flex; flex-direction: column; gap: var(--s3); position: relative; }
.plan:first-child { border-inline-start: 0; }
.plan.featured { background: linear-gradient(var(--lapis-tint), var(--surface) 40%); }
.plan.current { box-shadow: inset 0 3px 0 var(--income); }
.plan .price { font-size: 1.7rem; font-weight: 800; font-feature-settings: "tnum"; line-height: 1.3; }
.plan .price small { font-size: .85rem; font-weight: 500; color: var(--ink-3); }
.plan ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: .92rem; flex: 1; align-content: start; }
.plan li { padding-inline-start: 22px; position: relative; }
.plan li::before { content: ""; position: absolute; inset-inline-start: 2px; top: .7em; width: 10px; height: 2px; background: var(--income); }
.plan li.no { color: var(--ink-3); text-decoration: line-through; }
.plan li.no::before { background: var(--rule); }
@media (max-width: 720px) { .plan { border-inline-start: 0; border-top: 1px solid var(--rule); } .plan:first-child { border-top: 0; } }

/* ---------- auth & landing ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s6); }
.auth-card .brand { margin-bottom: var(--s5); }
.brand-title { font-size: 1.4rem; }
.auth-alt { text-align: center; margin-top: var(--s4); font-size: .92rem; color: var(--ink-3); }

.site-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s4) var(--s6); max-width: 1180px; margin: 0 auto; }
.site-head nav { display: flex; gap: var(--s2); align-items: center; }
.hero { max-width: 1180px; margin: 0 auto; padding: var(--s7) var(--s6); display: grid; grid-template-columns: 1fr 1.05fr; gap: var(--s7); align-items: center; }
.hero h1 { font-size: 2.6rem; line-height: 1.35; font-weight: 900; margin-bottom: var(--s4); }
.hero p { font-size: 1.1rem; color: var(--ink-2); }
.hero-cta { display: flex; gap: var(--s3); margin-top: var(--s5); flex-wrap: wrap; }
.ledger-sheet {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s5) var(--s5) var(--s4);
  box-shadow: 0 20px 50px -30px rgba(31,58,138,.35);
}
.ledger-sheet .sheet-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: var(--s3); }
.ledger-sheet .row { display: grid; grid-template-columns: 1fr auto; height: 44px; align-items: center; font-size: .95rem; border-bottom: 1px solid var(--rule-soft); }
.ledger-sheet .row .amount { font-weight: 700; }
.ledger-sheet .sheet-head { border-bottom: 1px solid var(--ink-3); padding-bottom: 6px; }
.ledger-sheet .total { border-top: 1px solid var(--ink); border-bottom: 3px double var(--ink); font-weight: 900; }
.section { max-width: 1180px; margin: 0 auto; padding: var(--s7) var(--s6); }
.section > h2 { font-size: 1.7rem; margin-bottom: var(--s2); }
.section > p { color: var(--ink-2); margin-bottom: var(--s5); }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s6); }
.features h3 { margin-bottom: var(--s2); }
.features p { color: var(--ink-2); font-size: .95rem; }
.site-foot { border-top: 1px solid var(--rule); padding: var(--s5) var(--s6); text-align: center; color: var(--ink-3); font-size: .88rem; }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding: var(--s5) var(--s4); gap: var(--s5); }
  .hero h1 { font-size: 1.9rem; }
  .features { grid-template-columns: 1fr; gap: var(--s4); }
  .section, .site-head { padding-left: var(--s4); padding-right: var(--s4); }
}

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(27,36,51,.42); display: grid; place-items: center; z-index: 60; padding: var(--s4); }
.modal { background: var(--surface); border-radius: var(--r-md); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: var(--s5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s4); }
.modal-head h3 { margin: 0; }
.modal-actions { display: flex; gap: var(--s2); justify-content: flex-start; margin-top: var(--s5); }
.toasts { position: fixed; bottom: var(--s5); left: var(--s5); display: grid; gap: var(--s2); z-index: 70; }
.toast { background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r-sm); font-size: .93rem; max-width: 360px; animation: toast-in .2s ease-out; }
.toast.error { background: var(--expense); }
.toast.success { background: var(--income); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.loading { padding: var(--s7); text-align: center; color: var(--ink-3); }
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--rule); margin-bottom: var(--s5); overflow-x: auto; }
.tabs a { padding: 8px 16px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tabs a.active { color: var(--lapis); border-color: var(--lapis); }
.row-actions { text-align: end; white-space: nowrap; }
.row-actions .btn + .btn { margin-inline-start: var(--s1); }
.inline-form { display: flex; gap: var(--s2); align-items: center; }
.inline-form input { max-width: 280px; }
.btn svg { width: 20px; height: 20px; stroke: currentColor; flex: none; }

/* ---------- books (Hesabyar port) ---------- */
.head-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.toolbar { margin-bottom: var(--s4); }
.toolbar input { max-width: 380px; }
.money-hint { font-size: .8rem; font-weight: 500; color: var(--lapis); min-height: 1.2em; }
.jdate { display: flex; gap: 6px; align-items: stretch; }
.jdate input:first-child { flex: 1; }
.jdate-pick { width: 44px !important; min-width: 44px; padding: 0 !important; color: transparent; cursor: pointer; flex: none; }
.jdate-pick::-webkit-datetime-edit { display: none; }
.jdate-pick::-webkit-calendar-picker-indicator { margin: 0 auto; cursor: pointer; }

.entry-layout { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: var(--s5); align-items: start; }
.type-grid { display: grid; gap: var(--s2); }
.type-card { font: inherit; text-align: start; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s3) var(--s4); cursor: pointer; display: grid; gap: 2px; color: var(--ink); }
.type-card strong { font-size: 1rem; }
.type-card span { font-size: .85rem; color: var(--ink-3); }
.type-card:hover { border-color: var(--ink-3); }
.type-card.selected { border-color: var(--lapis); box-shadow: inset 3px 0 0 var(--lapis); background: var(--lapis-tint); }
.posting-preview { background: var(--paper); border-radius: var(--r-sm); padding: var(--s3) var(--s4); font-size: .9rem; }
.posting-preview table { margin-top: 4px; }
.posting-preview td { padding: 4px 6px; border-bottom-color: var(--rule); }
@media (max-width: 900px) { .entry-layout { grid-template-columns: 1fr; } .type-grid { grid-template-columns: 1fr 1fr; } }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s4); }
.card-grid .panel { margin: 0; display: flex; flex-direction: column; gap: var(--s3); }
.contact-top { display: flex; gap: var(--s3); align-items: center; }
.contact-top h3 { margin: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--lapis-tint); color: var(--lapis); display: grid; place-items: center; font-weight: 800; flex: none; }
.balance-box { border-top: 1px solid var(--rule-soft); border-bottom: 3px double var(--rule); padding: var(--s2) 0; display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
.balance-box span { font-size: .85rem; color: var(--ink-3); }
.balance-box strong { font-size: 1.1rem; }
.balance-box.debtor strong { color: var(--income); }
.balance-box.creditor strong { color: var(--expense); }
.contact-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: auto; }
.product-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s2); }
.product-head h3 { margin: 0; }
.product-flags { display: flex; gap: 6px; flex-wrap: wrap; min-height: 0; }
.product-flags:empty { display: none; }
table.ledger.compact td { padding: 6px 0; }

.modal.wide { max-width: 860px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.official-box { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); background: var(--paper); border-radius: var(--r-sm); padding: var(--s3) var(--s4); flex-wrap: wrap; }
.official-box > div:first-child { display: grid; }
fieldset.lines { border: 1px solid var(--rule); border-radius: var(--r-md); padding: var(--s3) var(--s4) var(--s4); margin: 0; display: grid; gap: var(--s3); }
fieldset.lines legend { font-weight: 700; padding: 0 6px; }
.item-row, .cheque-row { display: grid; gap: var(--s2); align-items: end; }
.item-row { grid-template-columns: 2.2fr .8fr 1.2fr auto; }
.cheque-row { grid-template-columns: 1fr 1fr 1.3fr 1fr auto; }
.item-row + .item-row, .cheque-row + .cheque-row { border-top: 1px dashed var(--rule); padding-top: var(--s2); }
@media (max-width: 720px) { .item-row, .cheque-row, .choice-grid { grid-template-columns: 1fr 1fr; } }
.invoice-total { border-top: 1px solid var(--ink); padding-top: var(--s2); display: grid; gap: 4px; }
.invoice-total > div { display: flex; justify-content: space-between; gap: var(--s3); }
.invoice-total .grand { border-bottom: 3px double var(--ink); padding-bottom: 4px; font-size: 1.15rem; font-weight: 800; }
.invoice-total.invalid { color: var(--expense); }
.info-strip { background: var(--lapis-tint); color: var(--lapis); padding: var(--s2) var(--s4); border-radius: var(--r-sm); margin-bottom: var(--s3); }

table.journal tr.entry-first td { border-top: 1px solid var(--ink-3); }
table.journal td.credit-side { padding-inline-start: 32px; }

.settings-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--s5); align-items: start; }
.settings-cols .panel { margin: 0; }
@media (max-width: 900px) { .settings-cols { grid-template-columns: 1fr; } }
.logo-box { border: 1px dashed var(--rule); border-radius: var(--r-md); min-height: 110px; display: grid; place-items: center; margin-bottom: var(--s3); padding: var(--s3); }
.logo-box img { max-height: 90px; max-width: 100%; }
.danger-zone { border-color: #e7c3c1; }
.danger-zone h3 { color: var(--expense); }

.onboarding { border-color: var(--lapis); background: linear-gradient(var(--lapis-tint), var(--surface) 70%); }
.onboarding-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.verdict { font-weight: 700; margin: 0 0 var(--s3); }
.verdict.good { color: var(--income); }
.verdict.bad { color: var(--expense); }
.value.amount.in { color: var(--income); }
.value.amount.out { color: var(--expense); }
.figure .value.amount { font-size: 1.3rem; }
.figures.subtle { border-top-color: var(--rule); border-bottom: 1px solid var(--rule); }
.mini-chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: var(--s2); border-bottom: 1px solid var(--ink-3); }
.mini-chart .bar { flex: 1; background: var(--lapis); border-radius: 3px 3px 0 0; min-width: 6px; opacity: .85; }
.mini-chart .bar:hover { opacity: 1; background: var(--lapis-2); }
.chart-labels { display: flex; justify-content: space-between; margin-top: 4px; }
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.alert-list li { display: flex; gap: var(--s3); align-items: flex-start; }
.alert-list li > div { display: grid; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 8px; flex: none; }
.dot.warn { background: var(--gold); }
.dot.info { background: var(--lapis); }
