/* app.css - ریسپانسیو، راست‌چین؛ موبایل: منوی همبرگری + میانبرهای پایین، دسکتاپ: منوی بالا */
@font-face { font-family: 'Vazirmatn'; src: url('fonts/Vazirmatn-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('fonts/Vazirmatn-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
:root {
  --bg: #f3f5f9; --card: #fff; --text: #1d2733; --muted: #6b7785; --line: #e2e7ee;
  --primary: #1f6feb; --primary-d: #1559c1; --pos: #12805c; --neg: #c0392b; --warn: #b7791f;
  --radius: 14px; --shadow: 0 1px 3px rgba(20, 30, 50, .08);
  --blue: #1f6feb; --green: #12805c; --orange: #e08a1e; --purple: #7c4dff; --gray: #6b7785;
}
:root[data-theme="dark"] {
  --bg: #11161c; --card: #19212a; --text: #e6ebf1; --muted: #93a0ae; --line: #2b3541; --primary: #4c8dff; --primary-d: #3a78e6;
  --pos: #3ecf9e; --neg: #ff7b6b; --warn: #e0b04a; --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161c; --card: #19212a; --text: #e6ebf1; --muted: #93a0ae; --line: #2b3541; --primary: #4c8dff; --primary-d: #3a78e6;
    --pos: #3ecf9e; --neg: #ff7b6b; --warn: #e0b04a; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif; line-height: 1.7; overflow-x: hidden; }
body.no-scroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 6px 0 12px; } h2 { margin-top: 0; } h3 { margin: 0 0 8px; font-size: 1.05rem; }
.ic { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 14px; }
.app-main { padding-top: 14px; padding-bottom: 28px; min-height: 66vh; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 14px 0 20px; border-top: 1px solid var(--line); }
body.has-nav .foot { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

/* ---- سربرگ ---- */
.app-header { position: sticky; top: 0; z-index: 30; background: var(--card); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.hdr { display: flex; align-items: center; gap: 10px; min-height: 54px; }
.hdr-title { flex: 1; min-width: 0; font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-title:hover { text-decoration: none; }
.hdr-links { display: none; }
.hdr-end { display: flex; align-items: center; gap: 12px; }
.hdr-end .hdr-user { display: none; font-size: .9rem; }
form.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.icon-btn { width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--bg); }
.icon-btn .ic { width: 1.4em; height: 1.4em; }

/* ---- نوار میانبر پایین (موبایل) ---- */
.app-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0, 0, 0, .08); }
.nav-item { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; font-size: .72rem; color: var(--muted); border-radius: 12px; text-decoration: none; white-space: nowrap; }
.nav-item .ic { width: 1.5em; height: 1.5em; }
.nav-item:hover { text-decoration: none; }
.nav-item.active { color: var(--primary); font-weight: 700; background: color-mix(in srgb, var(--primary) 10%, transparent); }
body.has-nav { padding-bottom: 0; }

/* ---- منوی کشویی ---- */
.drawer-bk { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); }
.drawer-bk[hidden] { display: none; }
.drawer { position: fixed; top: 0; bottom: 0; right: 0; z-index: 50; width: min(320px, 86vw); display: flex; flex-direction: column; background: var(--card); color: var(--text);
  box-shadow: -12px 0 40px rgba(0, 0, 0, .3); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); overflow-y: auto;
  transform: translateX(105%); visibility: hidden; transition: transform .22s ease, visibility .22s; }
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head strong { display: block; } .drawer-head small { color: var(--muted); }
.drawer-nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.drawer-nav hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; width: 100%; }
.drawer-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; background: transparent; border-radius: 12px; color: var(--text); font: inherit; text-align: right; cursor: pointer; text-decoration: none; }
.drawer-item:hover { background: var(--bg); text-decoration: none; }
.drawer-item.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 700; }
.drawer-item.danger { color: var(--neg); }
.drawer-item .ic { color: var(--muted); } .drawer-item.active .ic, .drawer-item.danger .ic { color: inherit; }

/* ---- کارت‌ها و پایه ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.narrow, .narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.grid .card { margin: 0; }
.stats { grid-template-columns: repeat(2, 1fr); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat.wide { grid-column: 1 / -1; }
.stat span { color: var(--muted); font-size: .85rem; } .stat b { font-size: 1.3rem; } .stat small { color: var(--muted); }
.pos-bg { border-top: 3px solid var(--pos); } .neg-bg { border-top: 3px solid var(--neg); }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); text-decoration: none; }
.tile:active { transform: scale(.98); } .tile:hover { text-decoration: none; border-color: var(--primary); }
.tile small { color: var(--muted); font-size: .78rem; }
.t-ic { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; margin-bottom: 6px; background: var(--primary); }
.t-ic.tone-blue { background: var(--blue); } .t-ic.tone-green { background: var(--green); } .t-ic.tone-orange { background: var(--orange); }
.t-ic.tone-purple { background: var(--purple); } .t-ic.tone-gray { background: var(--gray); }
.cols { display: grid; grid-template-columns: 1fr; gap: 14px; }
.cols .card { margin-bottom: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.head h1 { margin: 0; }
.big { font-size: 1.15rem; font-weight: 700; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
.actions .btn { text-align: center; }
.muted { color: var(--muted); } .pos { color: var(--pos); } .neg { color: var(--neg); } .zero { color: var(--muted); }
.mt { margin-top: 10px; }
.tag { border: 1px solid; border-radius: 6px; padding: 0 8px; font-size: .8rem; vertical-align: middle; }
.alert { background: color-mix(in srgb, var(--neg) 12%, var(--card)); border: 1px solid var(--neg); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.alert.ok { background: color-mix(in srgb, var(--pos) 12%, var(--card)); border-color: var(--pos); }
.alert:empty { display: none; }

/* ---- دکمه و فرم ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 10px 14px; min-height: 44px; border-radius: 12px; cursor: pointer; font: inherit; line-height: 1.3; text-decoration: none; }
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.sm { padding: 4px 10px; min-height: 34px; font-size: .88rem; border-radius: 10px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn[disabled] { opacity: .55; cursor: wait; }
.big-btn { padding: 12px 28px; font-size: 1.05rem; flex: 1 1 auto; }
label { display: block; margin: 10px 0 4px; font-size: .88rem; color: var(--muted); }
input, select, textarea { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; font-size: 16px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=file] { padding: 8px; min-height: 0; }
input.picked { border-color: var(--pos); background: color-mix(in srgb, var(--pos) 8%, var(--card)); }
.money-input, .qty-input, .date-input { direction: ltr; text-align: right; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 100%; min-width: 0; } .row > .grow, .grow { flex: 1 1 100%; }
.row > input, .row > select { flex: 1 1 100%; width: auto; }
.field { margin-bottom: 4px; min-width: 0; }
.inline { display: flex; gap: 8px; align-items: stretch; }
.inline > .grow { flex: 1; min-width: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 1 1 160px; width: auto; } .filters select { flex: 1 1 130px; width: auto; }
.radios { display: flex; gap: 12px; flex-wrap: wrap; }
.radio { display: flex; gap: 8px; align-items: center; margin: 0; color: var(--text); font-size: 1rem; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; flex: 1 1 140px; }
.scroll { overflow-x: auto; }
dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--text); width: min(92vw, 420px); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
details summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.new-item { color: var(--primary); }

/* ---- جدول‌ها ---- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 400; font-size: .85rem; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.void td { text-decoration: line-through; color: var(--muted); }
.tbl tr.overdue td { background: color-mix(in srgb, var(--neg) 12%, transparent); }
.tbl tr.soon td { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.tbl td.amt { white-space: nowrap; font-weight: 700; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- فرم فاکتور ---- */
.ac-wrap, .ac-holder { position: relative; }
.ac-box { position: absolute; z-index: 35; right: 0; left: 0; top: 100%; background: var(--card); border: 1px solid var(--primary); border-radius: 12px; max-height: 260px; overflow: auto; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.ac-item { padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--line); } .ac-item:last-child { border-bottom: 0; } .ac-item:hover { background: var(--bg); }
.tbl.lines td input, .tbl.lines td select { min-width: 90px; }
.tbl.lines td.n { color: var(--muted); width: 30px; }
.part { border: 1px dashed var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; }
.part-main { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; }
.part-main select { grid-column: 1; } .part-main input { grid-column: 2; min-width: 0; }
.cheque-box { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.cheque-box input { flex: 1 1 140px; width: auto; }
.cheque-box[hidden] { display: none; }
.totals { display: flex; flex-direction: column; gap: 6px; }
.totals > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.totals input { width: 160px; }
.totals .grand { font-size: 1.15rem; border-top: 1px solid var(--line); padding-top: 6px; }
img.receipt { max-width: 100%; max-height: 520px; border-radius: 12px; border: 1px solid var(--line); }
.item-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.item-row > .field:first-child { grid-column: 1 / -1; }
.item-row .btns { grid-column: 1 / -1; } .row-btns { display: flex; gap: 8px; } .row-btns .btn { flex: 1; }
.item-list .item-row { margin-bottom: 10px; }

/* ---- موبایل ---- */
@media (max-width: 767px) {
  .tbl.lines thead { display: none; }
  .tbl.lines, .tbl.lines tbody { display: block; width: 100%; }
  .tbl.lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
  .tbl.lines td { display: block; border: 0; padding: 0; min-width: 0; }
  .tbl.lines td[data-key=item] { grid-column: 1 / -1; }
  .tbl.lines td[data-label]::before { content: attr(data-label); display: block; font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
  .tbl.lines td.n { display: none; }
  .tbl.lines td.amt { grid-column: 1; align-self: center; }
  .tbl.lines td.amt::before { content: 'مبلغ: '; color: var(--muted); font-weight: 400; font-size: .85rem; }
  .tbl.lines td:last-child { grid-column: 2; justify-self: end; }
  .tbl.lines td input, .tbl.lines td select { min-width: 0; }
  .tbl.stack, .tbl.stack tbody { display: block; width: 100%; }
  .tbl.stack .thead-row { display: none; }
  .tbl.stack tr { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 8px; background: var(--card); }
  .tbl.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 5px 0; text-align: left; }
  .tbl.stack td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; flex: none; text-align: right; }
  .tbl.stack td:not([data-label])::before { display: none; }
  .tbl.stack td.acts { justify-content: flex-start; }
  .tbl.stack td.empty { display: none; }
  .card:has(> .stack), .card:has(> .scroll > .stack) { background: transparent; border: 0; padding: 0; box-shadow: none; }
  .totals input { width: 140px; }
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .card { padding: 12px; }
  .actions .btn.btn-primary:only-child, .actions .big-btn { grid-column: 1 / -1; }
  .item-row > .field:last-child { grid-column: 1 / -1; } .item-row > .field:last-child > .btn { width: 100%; }
}
@media (max-width: 400px) { .nav-item { font-size: .66rem; } h1 { font-size: 1.25rem; } .stat b { font-size: 1.1rem; } }

/* ---- تبلت و دسکتاپ ---- */
@media (min-width: 768px) {
  .menu-btn { display: none; }
  .hdr-title { flex: none; max-width: 220px; margin-left: 10px; }
  .hdr-links { display: flex; gap: 2px; flex: 1; }
  .hdr-links a { padding: 7px 11px; border-radius: 10px; color: var(--text); font-size: .95rem; }
  .hdr-links a:hover { background: var(--bg); text-decoration: none; }
  .hdr-links a.on { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 700; }
  .hdr-end .hdr-user { display: inline; }
  .app-nav { position: static; max-width: 1072px; margin: 14px auto 0; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
  .nav-item { flex-direction: row; justify-content: center; gap: 8px; font-size: .95rem; padding: 10px; border: 1px solid transparent; }
  .nav-item:hover { border-color: var(--primary); }
  body.has-nav .foot { padding-bottom: 20px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } .stat.wide { grid-column: auto; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .cols { grid-template-columns: 1fr 1fr; }
  .actions { display: flex; flex-wrap: wrap; }
  .row > .field { flex: 0 1 190px; } .row > .grow, .grow { flex: 1 1 240px; }
  .row > input, .row > select { flex: 1 1 160px; }
  .part-main { grid-template-columns: 150px 1fr auto auto; }
  .totals { max-width: 460px; }
  .item-row { grid-template-columns: 2fr 1fr 1fr auto; } .item-row > .field:first-child, .item-row .btns { grid-column: auto; }
  dialog { margin: auto; }
}

@media print {
  .no-print, .app-header, .app-nav, .foot, .drawer, .drawer-bk { display: none !important; }
  body { background: #fff; color: #000; } .card { border: 0; padding: 0; box-shadow: none; }
  .tbl th, .tbl td { border-bottom: 1px solid #bbb; } a { color: #000; }
}
