@font-face { font-family: 'VazirFD'; src: url('../fonts/Vazirmatn-FD-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'VazirFD'; src: url('../fonts/Vazirmatn-FD-Medium.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'VazirFD'; src: url('../fonts/Vazirmatn-FD-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8f9fc; --border: #e3e7ef; --text: #1d2433; --muted: #6b7489;
  --primary: #2952cc; --primary-weak: #e8eefc; --primary-text: #fff;
  --ok: #17803d; --ok-weak: #e4f5ea; --warn: #b45f06; --warn-weak: #fdf0e1; --err: #c62828; --err-weak: #fdeaea;
  --purple: #6a3fc1; --purple-weak: #efe8fb; --gray-weak: #eef0f4;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141b; --surface: #1a1e27; --surface-2: #20252f; --border: #2c3240; --text: #e6e9f0; --muted: #98a1b3;
    --primary: #6d8cff; --primary-weak: #233056; --primary-text: #0d1220;
    --ok: #4cc27a; --ok-weak: #173323; --warn: #f0a24b; --warn-weak: #3a2a14; --err: #f26b6b; --err-weak: #3c1c1c;
    --purple: #b393f5; --purple-weak: #2e2547; --gray-weak: #262b36;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: 'VazirFD', Tahoma, sans-serif; font-size: 15px; line-height: 1.7; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ltr { direction: ltr; unicode-bidi: embed; text-align: left; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.right { text-align: left; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .mt-s { margin-top: .5rem; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--border); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; display: flex; align-items: center; gap: .5rem; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; font-size: 1rem; }
.nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 9px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-weak); color: var(--primary); font-weight: 500; }
.nav .sep { height: 1px; background: var(--border); margin: .75rem .5rem; }
.nav svg, .bottom-nav svg { width: 20px; height: 20px; flex-shrink: 0; }
.main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 2rem; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.mobile-head { display: none; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  body { font-size: 15px; }
  .sidebar { display: none; }
  .main { padding: .75rem 1rem calc(var(--nav-h) + 1.5rem); }
  .mobile-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .mobile-head .brand { padding: 0; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; right: 0; left: 0; height: var(--nav-h); background: var(--surface); border-top: 1px solid var(--border); z-index: 40; padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); font-size: .72rem; gap: 2px; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a.plus span.circle { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(41,82,204,.35); }
  .shell.menu-open .sidebar { display: block; position: fixed; inset: 0 0 0 auto; z-index: 50; width: 78vw; max-width: 300px; box-shadow: -8px 0 24px rgba(0,0,0,.2); }
  .backdrop { display: none; }
  .shell.menu-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 45; }
  h1 { font-size: 1.2rem; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: .9rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
@media (max-width: 860px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span3 { grid-column: 1 / -1; } }
@media (max-width: 560px) { .g2, .g3 { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; } }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 960px) { .cols { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.25rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: .75rem; font-weight: 400; color: var(--muted); }
.stat.accent { border-color: var(--primary); }
a.stat:hover { text-decoration: none; border-color: var(--primary); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dd { margin-bottom: .5rem; } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 500; }
.field label .req { color: var(--err); }
.field .hint { font-size: .78rem; color: var(--muted); min-height: 1em; }
.field .hint.bad { color: var(--err); } .field .hint.good { color: var(--ok); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: .55rem .7rem; width: 100%; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-weak); border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--primary); }
input.amount, input.ltr-in { direction: ltr; text-align: left; }
input[type=file] { padding: .45rem; }
.check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
@media (max-width: 560px) {
  .form-actions.sticky { position: sticky; bottom: calc(var(--nav-h) + 6px); background: var(--bg); padding: .5rem 0; z-index: 5; }
  .form-actions .btn { flex: 1; }
}
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.segmented label { padding: .4rem .9rem; border-radius: 8px; cursor: pointer; font-size: .9rem; }
.segmented input { display: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }
.words { font-size: .8rem; color: var(--ok); min-height: 1.2em; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 500; font-size: .92rem; padding: .5rem 1rem; min-height: 40px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--err); border-color: var(--err-weak); }
.btn.danger:hover { background: var(--err-weak); }
.btn.sm { padding: .25rem .6rem; min-height: 32px; font-size: .82rem; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { background: none; border: 0; padding: .4rem; cursor: pointer; color: var(--text); display: inline-grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; }
form.inline { display: inline; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: right; font-weight: 500; color: var(--muted); font-size: .8rem; padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
table.t td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); }
@media (max-width: 720px) {
  table.t.responsive thead { display: none; }
  table.t.responsive, table.t.responsive tbody, table.t.responsive tr, table.t.responsive td { display: block; width: 100%; }
  table.t.responsive tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: .6rem; padding: .35rem .25rem; background: var(--surface); }
  table.t.responsive td { border: 0; padding: .25rem .6rem; display: flex; justify-content: space-between; gap: 1rem; text-align: left; }
  table.t.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: right; flex-shrink: 0; }
  table.t.responsive td[data-label=""]::before { content: none; }
  table.t.responsive tfoot { display: block; } table.t.responsive tfoot tr { display: block; }
}

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 500; white-space: nowrap; }
.badge.gray { background: var(--gray-weak); color: var(--muted); }
.badge.blue { background: var(--primary-weak); color: var(--primary); }
.badge.purple { background: var(--purple-weak); color: var(--purple); }
.badge.orange { background: var(--warn-weak); color: var(--warn); }
.badge.green { background: var(--ok-weak); color: var(--ok); }
.badge.red { background: var(--err-weak); color: var(--err); }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-weak); color: var(--ok); }
.flash.err { background: var(--err-weak); color: var(--err); }
.flash.warn { background: var(--warn-weak); color: var(--warn); }
.errors { background: var(--err-weak); color: var(--err); border-radius: 10px; padding: .6rem 1rem; margin-bottom: 1rem; }
.errors ul { margin: .25rem 0 0; padding-right: 1.2rem; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip { padding: .25rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .82rem; }
.chip.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.chip:hover { text-decoration: none; }

details.filters > summary { cursor: pointer; list-style: none; }
details.filters > summary::-webkit-details-marker { display: none; }

/* progress */
.progress { height: 8px; background: var(--gray-weak); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

/* timeline / stepper */
.stepper { display: flex; margin-bottom: 1rem; overflow-x: auto; padding-bottom: .25rem; }
.step { flex: 1; min-width: 92px; text-align: center; font-size: .78rem; color: var(--muted); position: relative; padding-top: 30px; }
.step::before { content: ''; position: absolute; top: 10px; left: 50%; width: 100%; height: 3px; background: var(--border); z-index: 0; }
.step:first-child::before { display: none; }
.step .dot { position: absolute; top: 0; right: calc(50% - 12px); width: 24px; height: 24px; border-radius: 50%; background: var(--surface); border: 3px solid var(--border); z-index: 1; display: grid; place-items: center; font-size: .7rem; }
.step.done { color: var(--text); }
.step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done::before { background: var(--ok); }
.step .d { display: block; font-size: .72rem; color: var(--muted); }
@media (max-width: 560px) { .step { min-width: 0; font-size: .7rem; padding-inline: 2px; } .step .d { font-size: .65rem; } }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 1.4rem .9rem 0; border-right: 2px solid var(--border); margin-right: .45rem; }
.timeline li::before { content: ''; position: absolute; right: -7px; top: .45rem; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.timeline li.payment::before, .timeline li.settled::before { background: var(--ok); }
.timeline li.cancelled::before { background: var(--err); }
.timeline li:last-child { border-color: transparent; }
.timeline .when { font-size: .78rem; color: var(--muted); }

/* items editor */
.items .item { border: 1px solid var(--border); border-radius: 10px; padding: .75rem; margin-bottom: .6rem; background: var(--surface-2); position: relative; }
.items .item .rm { position: absolute; left: .4rem; top: .4rem; }
.items .item .no { font-weight: 700; color: var(--muted); font-size: .8rem; margin-bottom: .25rem; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; background: var(--primary-weak); border-radius: 10px; padding: .75rem 1rem; }
.totals b { display: block; font-size: 1.05rem; }

/* autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; top: 100%; right: 0; left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 20; max-height: 300px; overflow-y: auto; margin-top: 4px; }
.ac-list div { padding: .55rem .8rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-list div:last-child { border-bottom: 0; }
.ac-list div:hover, .ac-list div.on { background: var(--primary-weak); }
.party-picked { display: flex; justify-content: space-between; align-items: center; gap: .5rem; background: var(--ok-weak); color: var(--ok); padding: .5rem .8rem; border-radius: 10px; margin-bottom: .75rem; }

/* jalali datepicker */
.jdp { position: absolute; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: .6rem; width: 280px; user-select: none; }
.jdp .hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; font-weight: 600; }
.jdp .hd button { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--text); padding: .1rem .5rem; border-radius: 6px; }
.jdp .hd button:hover { background: var(--surface-2); }
.jdp .wk, .jdp .days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; }
.jdp .wk span { font-size: .72rem; color: var(--muted); }
.jdp .days button { border: 0; background: none; padding: .35rem 0; border-radius: 7px; cursor: pointer; font: inherit; font-size: .85rem; color: var(--text); }
.jdp .days button:hover { background: var(--primary-weak); }
.jdp .days button.today { outline: 1px solid var(--primary); }
.jdp .days button.sel { background: var(--primary); color: var(--primary-text); }
.jdp .ft { display: flex; justify-content: space-between; margin-top: .4rem; }
.jdp .ft button { font: inherit; font-size: .8rem; background: none; border: 0; color: var(--primary); cursor: pointer; }

/* email box */
.mailbox { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; line-height: 2; }
.copy-row { display: flex; gap: .5rem; align-items: center; }
.copy-row input { flex: 1; }

/* auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: 100%; max-width: 380px; padding: 1.5rem; }
.auth .brand { justify-content: center; font-size: 1.15rem; }

.thumb { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--border); display: block; }
.files { display: flex; flex-direction: column; gap: .4rem; }
.file-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem .6rem; background: var(--surface-2); border-radius: 8px; font-size: .88rem; }
.file-row a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem; background: var(--surface); color: var(--text); width: min(480px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

@media print {
  .sidebar, .bottom-nav, .mobile-head, .no-print, .topbar .actions, details.filters { display: none !important; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
}
