/* حسابگر دقیق — طراحی بر پایه دفتر حساب: خط‌کشی، حاشیه زعفرانی، جمع با دو خط | پالت مروارید: porcelain / deep teal / saffron */
@font-face { font-family: "Vazirmatn FD"; src: url(fonts/Vazirmatn-UI-FD-Regular.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn FD"; src: url(fonts/Vazirmatn-UI-FD-Bold.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Vazirmatn FD"; src: url(fonts/Vazirmatn-UI-FD-Black.woff2) format("woff2"); font-weight: 900; font-display: swap; }

:root {
  --paper: #ECF1F1; --surface: #FFFFFF; --ink: #0D4145; --ink-2: #3E5658; --ink-3: #6F8587;
  --rule: #D3DEDE; --rule-2: #BCCFCF; --margin: #C8890F; --accent: #17797E; --accent-2: #DDEBEB;
  --gold: #8A5D07; --gold-bg: #F7EBD2; --ok: #1E7A4F; --ok-bg: #E4F3EB; --bad: #B3261E; --bad-bg: #FBE9E7;
  --radius: 6px; --side: 232px;
  --f: "Vazirmatn FD", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--f); color: var(--ink); background: var(--paper); line-height: 1.7; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.35; margin: 0; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-2); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.neg { color: var(--bad); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--ink); color: #D9E9E9; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 0 24px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 0 18px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.logo b { font-weight: 900; font-size: 1.5rem; background: #ECF1F1; color: var(--ink); border-radius: 6px; padding: 0 9px; line-height: 1.5; box-shadow: inset -3px 0 0 var(--margin); }
.logo span { font-weight: 700; }
.logo small { display: block; font-size: .75rem; color: #8FB5B6; font-weight: 400; }
.nav { padding: 10px 10px 0; }
.nav h4 { font-size: .76rem; font-weight: 700; color: #7FA6A8; margin: 16px 10px 4px; }
.nav a { display: flex; align-items: center; justify-content: space-between; color: #D9E9E9; padding: 5px 10px; border-radius: 5px; font-size: .94rem; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.on { background: #ECF1F1; color: var(--ink); font-weight: 700; }
.nav .pro-tag { font-size: .7rem; color: #E6B64E; border: 1px solid #E6B64E55; border-radius: 3px; padding: 0 5px; }
.nav a.on .pro-tag { color: var(--gold); border-color: var(--gold); }
.nav .badge { background: var(--margin); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75rem; }
.side-quota { padding: 14px 20px; font-size: .82rem; color: #A9CACB; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--rule); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.top .menu-btn { display: none; }
.top .biz { font-weight: 700; }
.top .fy { color: var(--ink-2); font-size: .86rem; border: 1px solid var(--rule); border-radius: 20px; padding: 0 12px; }
.top .grow { flex: 1; }
.plan { font-size: .82rem; border-radius: 20px; padding: 1px 12px; border: 1px solid var(--rule-2); color: var(--ink-2); }
.plan.pro { background: var(--gold-bg); border-color: #EAD3A2; color: var(--gold); font-weight: 700; }
.help-btn { width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--surface); font-weight: 900; cursor: pointer; line-height: 1; }
.help-btn[aria-expanded="true"] { background: var(--ink); color: #fff; }
.content { padding: 22px 24px 60px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 1.45rem; font-weight: 900; }
.page-head .sub { color: var(--ink-2); font-size: .9rem; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rule-2); background: var(--surface); padding: 6px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; font-size: .93rem; color: var(--ink); }
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #12494D; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: #E5B5B0; }
.btn.gold { background: var(--gold-bg); color: var(--gold); border-color: #EAD3A2; font-weight: 700; }
.btn.sm { padding: 1px 10px; font-size: .84rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: .88rem; color: var(--ink-2); }
label.f > span { font-weight: 700; color: var(--ink); font-size: .85rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  border: 1px solid var(--rule-2); background: var(--surface); border-radius: var(--radius); padding: 6px 10px; width: 100%; min-height: 36px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-2); }
.ltr { direction: ltr; text-align: left; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .92rem; }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.panel > h2 { font-size: 1.02rem; font-weight: 700; margin-bottom: 10px; }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

/* شاخص‌ها: ستون‌های مبلغ دفتر */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); margin-bottom: 16px; }
.figure { padding: 12px 18px; border-inline-start: 1px solid var(--rule); }
.figure:first-child { border-inline-start: 0; box-shadow: inset -3px 0 0 var(--margin); }
.figure .l { font-size: .84rem; color: var(--ink-2); }
.figure .v { font-size: 1.35rem; font-weight: 900; }
.figure .v small { font-size: .75rem; font-weight: 400; color: var(--ink-3); margin-inline-start: 4px; }

/* ---------- جدول دفتری ---------- */
.ledger-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
table.ledger { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.ledger th, table.ledger td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.ledger th:first-child, table.ledger td:first-child { border-right: 2px solid var(--margin); padding-right: 14px; }
table.ledger thead th { font-size: .82rem; color: var(--ink-2); font-weight: 700; border-bottom: 3px double var(--rule-2); background: #F6F9F9; white-space: nowrap; }
table.ledger tbody tr:hover { background: #F3F8F8; }
table.ledger td.num, table.ledger th.num { text-align: left; }
table.ledger tfoot td { font-weight: 900; border-bottom: 0; background: #F6F9F9; }
table.ledger tfoot td.num { box-shadow: inset 0 -4px 0 -1px #fff, inset 0 -5px 0 -1px var(--ink); border-bottom: 1px solid var(--ink); }
table.ledger tr.click { cursor: pointer; }
table.ledger tr.canceled td { color: var(--ink-3); text-decoration: line-through; }
table.ledger tr.focus td { background: var(--accent-2); }
table.ledger .empty { text-align: center; color: var(--ink-2); padding: 34px; }
.pill { display: inline-block; font-size: .78rem; padding: 0 9px; border-radius: 20px; border: 1px solid var(--rule-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: #B5DCC6; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: #EFC2BD; }
.pill.warn { background: var(--gold-bg); color: var(--gold); border-color: #EAD3A2; }
.pill.info { background: var(--accent-2); color: var(--accent); border-color: #B5D3D4; }

/* ---------- فرم فاکتور ---------- */
.inv-lines td { padding: 4px 6px !important; }
.inv-lines input, .inv-lines select { min-height: 32px !important; padding: 3px 8px !important; }
.inv-lines .c-qty { width: 90px; } .inv-lines .c-price { width: 150px; } .inv-lines .c-dis { width: 120px; } .inv-lines .c-vat { width: 70px; }
.inv-lines .del { color: var(--bad); border: 0; background: none; cursor: pointer; font-size: 1.2rem; }
.totals { margin-inline-start: auto; min-width: 280px; }
.totals div { display: flex; justify-content: space-between; gap: 20px; padding: 3px 0; border-bottom: 1px solid var(--rule); }
.totals div.grand { font-weight: 900; font-size: 1.1rem; border-bottom: 3px double var(--ink); }

/* combo */
.combo { position: relative; }
.combo-list { position: absolute; inset-inline: 0; top: 100%; z-index: 40; background: var(--surface); border: 1px solid var(--rule-2); border-radius: var(--radius); max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(27,42,74,.14); min-width: 280px; }
.combo-list button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: right; border: 0; background: none; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--rule); }
.combo-list button:hover, .combo-list button.hi { background: var(--accent-2); }
.combo-list .hint { padding: 8px 10px; color: var(--ink-2); font-size: .85rem; }

/* datepicker */
.dp { position: absolute; z-index: 95; background: var(--surface); border: 1px solid var(--rule-2); border-radius: var(--radius); box-shadow: 0 10px 28px rgba(27,42,74,.18); padding: 10px; width: 260px; }
.dp header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-weight: 700; }
.dp header button { border: 0; background: none; cursor: pointer; font-size: 1.2rem; padding: 0 8px; }
.dp .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: .85rem; }
.dp .days span { color: var(--ink-3); font-size: .75rem; }
.dp .days button { border: 0; background: none; border-radius: 4px; padding: 3px 0; cursor: pointer; }
.dp .days button:hover { background: var(--accent-2); }
.dp .days button.today { box-shadow: inset 0 0 0 1px var(--accent); }
.dp .days button.sel { background: var(--ink); color: #fff; }

/* ---------- Modal / drawer / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,30,50,.42); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 8px; width: min(620px, 100%); max-height: 92vh; overflow-y: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); border-top: 3px solid var(--ink); }
.modal.wide { width: min(980px, 100%); }
.modal h2 { font-size: 1.15rem; font-weight: 900; margin-bottom: 14px; }
.modal .foot { display: flex; gap: 8px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--rule); }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(420px, 94vw); background: var(--surface); z-index: 90; box-shadow: 8px 0 40px rgba(0,0,0,.18); padding: 22px 24px; overflow-y: auto; border-right: 3px solid var(--margin); transform: translateX(-105%); visibility: hidden; transition: transform .22s ease, visibility .22s; }
.drawer.open { transform: none; visibility: visible; }
.drawer h2 { font-size: 1.15rem; font-weight: 900; margin: 0 0 8px; padding-left: 30px; }
.drawer h3 { font-size: .98rem; margin: 16px 0 4px; }
.drawer p, .drawer li { font-size: .93rem; color: #1C5A5E; }
.drawer ol, .drawer ul { padding-inline-start: 20px; }
.drawer .x { position: absolute; top: 14px; left: 16px; border: 0; background: none; font-size: 1.5rem; cursor: pointer; line-height: 1; }
.toasts { position: fixed; bottom: 18px; left: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; }
.toast.err { background: var(--bad); }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

.note { background: var(--accent-2); border-inline-start: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: .92rem; margin-bottom: 14px; }
.note.warn { background: var(--gold-bg); border-color: var(--gold); }
.note.bad { background: var(--bad-bg); border-color: var(--bad); }
.quota { height: 6px; background: rgba(255,255,255,.15); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.quota i { display: block; height: 100%; background: #6FB9BC; }
.quota.full i { background: var(--margin); }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 160px; padding-top: 10px; border-bottom: 3px double var(--rule-2); }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars i { display: block; width: 100%; max-width: 46px; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars div:last-child i { background: var(--accent); }
.bars small { font-size: .72rem; color: var(--ink-2); }

/* tree */
.tree .lv1 td:nth-child(2) { font-weight: 900; }
.tree .lv2 td:nth-child(2) { font-weight: 700; padding-right: 30px; }
.tree .lv3 td:nth-child(2) { padding-right: 52px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .brand-side { background: var(--ink); color: #D9E9E9; padding: 56px 88px 56px 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 28px; position: relative; overflow: hidden;
  background-image: repeating-linear-gradient(to bottom, transparent 0 35px, rgba(255,255,255,.06) 35px 36px); }
.auth .brand-side::before { content: ""; position: absolute; top: 0; bottom: 0; right: 52px; width: 2px; background: var(--margin); opacity: .85; }
.auth .mark { font-size: 6rem; font-weight: 900; line-height: 1; color: #ECF1F1; }
.auth .mark span { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 12px; }
.auth .brand-side p { max-width: 38ch; color: #A9CACB; }
.auth .brand-side ul { list-style: none; padding: 0; margin: 0; columns: 2; font-size: .92rem; color: #C7DCDC; }
.auth .brand-side li { padding: 3px 0; break-inside: avoid; }
.auth .form-side { display: grid; place-items: center; padding: 32px; }
.auth form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; }
.auth form h1 { font-size: 1.5rem; font-weight: 900; }
.auth .switch { font-size: .92rem; color: var(--ink-2); margin: 0; }

/* ---------- چاپ فاکتور ---------- */
.print-page { background: #fff; max-width: 1060px; margin: 0 auto; padding: 24px; }
.print-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.pinv { border: 1.5px solid #000; font-size: .86rem; color: #000; }
.pinv h1 { text-align: center; font-size: 1.15rem; padding: 8px; border-bottom: 1.5px solid #000; }
.pinv .hd { display: flex; justify-content: space-between; border-bottom: 1.5px solid #000; }
.pinv .hd > div { padding: 6px 10px; }
.pinv .sec { background: #EDEDED; text-align: center; font-weight: 700; border-bottom: 1px solid #000; padding: 3px; }
.pinv .party { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 14px; padding: 6px 10px; border-bottom: 1.5px solid #000; }
.pinv table { width: 100%; border-collapse: collapse; }
.pinv th, .pinv td { border: 1px solid #000; padding: 4px 6px; text-align: center; }
.pinv th { background: #EDEDED; font-size: .78rem; }
.pinv td.num { text-align: left; }
.pinv .sign { display: grid; grid-template-columns: 1fr 1fr; min-height: 90px; }
.pinv .sign div { padding: 8px 10px; border-left: 1px solid #000; }
.pinv .sign div:last-child { border-left: 0; }
.pinv img.logo { max-height: 56px; }
@media print {
  body { background: #fff; }
  .side, .top, .print-bar, .toasts, .filters button, .page-head .actions, .drawer { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .print-page { padding: 0; }
  .ledger-wrap { border: 0; overflow: visible; }
  @page { size: A4 landscape; margin: 10mm; }
}

/* ---------- Admin / install ---------- */
body.install { display: grid; place-items: center; min-height: 100vh; }
.install-box { background: #fff; border: 1px solid var(--rule); border-top: 3px solid var(--ink); padding: 28px; border-radius: 8px; width: min(520px, 94vw); }
.install-box form { display: flex; flex-direction: column; gap: 10px; }
.install-box label { display: flex; flex-direction: column; gap: 4px; }
.install-box code { display: block; background: var(--paper); padding: 8px; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; right: 0; width: var(--side); z-index: 70; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.3); }
  .top .menu-btn { display: inline-flex; }
  .top .fy, .top .biz { display: none; }
  .content { padding: 16px 12px 60px; }
  .auth { grid-template-columns: 1fr; }
  .auth .brand-side { padding: 32px 76px 28px 28px; }
  .auth .brand-side::before { right: 40px; }
  .auth .mark { font-size: 3.6rem; }
  .auth .brand-side ul { display: none; }
}
