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

:root {
  --green: #1f7a3f;
  --green-dark: #165c2f;
  --green-soft: #e4f2e8;
  --bg: #f3f7f4;
  --card: #ffffff;
  --text: #17261c;
  --muted: #62756a;
  --line: #d9e4dc;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 50, 30, .06), 0 4px 14px rgba(20, 50, 30, .06);
  --nav-w: 250px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Vazirmatn FD", Tahoma, sans-serif; font-size: 15px; line-height: 1.7;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.4; }
h1 { font-size: 1.35rem; } h3 { font-size: 1.05rem; }
a { color: var(--green-dark); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { letter-spacing: .02em; }
input.num, .num { direction: ltr; unicode-bidi: plaintext; }
input.num { text-align: right; }
.nowrap { white-space: nowrap; }
.code { color: var(--green-dark); }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ───── فرم‌ها ───── */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=tel], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .75rem; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; font-size: 16px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: var(--green); }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-label { font-weight: 500; font-size: .9rem; }
.hint { color: var(--muted); font-size: .8rem; }
.hint.words { color: var(--green-dark); min-height: 1.2em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.grid2 .full, .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: .6rem .8rem; margin-top: .8rem; }
.inline { display: flex; gap: .5rem; align-items: center; }
.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.check input, .check-only input { width: 20px; height: 20px; accent-color: var(--green); }
.check-only { display: inline-flex; padding: .2rem; }

.datefield { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.datefield select { width: auto; min-width: 64px; flex: 1 1 64px; padding-inline: .45rem; }
.datefield select:nth-child(2) { flex: 2 1 100px; }
.datefield select:nth-child(3) { flex: 1.4 1 86px; }
.moneyfield input { font-size: 18px; font-weight: 500; }

.picker { position: relative; }
.picker.invalid input { border-color: var(--danger); }
.picker-menu { position: absolute; z-index: 20; inset-inline: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.picker-item { padding: .6rem .8rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-item:last-child { border-bottom: 0; }
.picker-item.active, .picker-item:hover { background: var(--green-soft); }
.picker-empty { padding: .8rem; color: var(--muted); }

.items-box { display: flex; flex-direction: column; gap: .5rem; margin: .3rem 0 .5rem; }
.item-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: .5rem; align-items: center; }

/* ───── دکمه‌ها ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 42px; padding: .4rem 1rem;
  border: 1px solid var(--line); background: #fff; border-radius: 10px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--green-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { min-height: 34px; padding: .15rem .7rem; font-size: .88rem; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { color: var(--danger); border-color: #f0c9c6; }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 1.1rem; color: inherit; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* ───── قالب ───── */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .6rem; padding: .5rem 1rem; padding-top: calc(.5rem + env(safe-area-inset-top));
  background: var(--green); color: #fff; min-height: 58px;
}
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); }
.brand-title { display: flex; flex-direction: column; line-height: 1.3; flex: 1; min-width: 0; }
.brand-title b { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-title small { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-foot { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: .5rem; }
.exit-top { flex: none; }
.topbar .btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); color: #fff; }
.topbar .btn:hover { background: rgba(255,255,255,.25); }
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: fixed; z-index: 40; top: 0; bottom: 0; inset-inline-start: 0; width: var(--nav-w); max-width: 85vw; background: #fff; padding: 1rem .7rem;
  padding-top: calc(1rem + env(safe-area-inset-top)); transform: translateX(100%); transition: transform .2s; box-shadow: var(--shadow); overflow: auto;
}
body.nav-open .sidebar { transform: none; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
body.nav-open .scrim { display: block; }
.nav-link { display: flex; align-items: center; gap: .7rem; padding: .7rem .8rem; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--green-soft); }
.nav-link.active { background: var(--green); color: #fff; }
.nav-ico { width: 1.5rem; text-align: center; }
.main { flex: 1; min-width: 0; padding: 1rem; padding-bottom: 3rem; }
.page { max-width: 1200px; margin: 0 auto; }
@media (min-width: 900px) {
  .menu-btn { display: none; }
  .sidebar { position: sticky; top: 58px; height: calc(100vh - 58px); transform: none; box-shadow: none; border-inline-end: 1px solid var(--line); flex: none; padding-top: 1rem; }
  body.nav-open .scrim { display: none; }
  .main { padding: 1.5rem 2rem 3rem; }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card.narrow, .narrow { max-width: 720px; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.toolbar .search { flex: 1 1 240px; width: auto; }
.toolbar select { width: auto; }
.card > .search { margin-top: .8rem; }
.summary { display: flex; gap: 1.2rem; flex-wrap: wrap; padding: .6rem .9rem; background: var(--green-soft); border-radius: 10px; margin-bottom: .8rem; color: var(--green-dark); }
.day-label { font-weight: 700; font-size: 1.1rem; margin: .2rem 0 .5rem; }
.rangebar { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1.2rem; }
.range-col { display: flex; flex-direction: column; gap: .3rem; }
.presets { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.section-title { margin: 1.5rem 0 .7rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; background: #fff; border-radius: var(--radius); }
.chip { display: inline-block; font-size: .78rem; background: var(--green-soft); color: var(--green-dark); border-radius: 99px; padding: .05rem .6rem; }
.chip.alt { background: #eef1ff; color: #3a4aa8; }

/* ───── داشبورد ───── */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; margin-top: 1rem; }
.stat { display: block; background: #fff; border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); color: inherit; text-decoration: none; border-inline-start: 4px solid var(--green); }
a.stat:hover { background: var(--green-soft); }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--green-dark); line-height: 1.2; }
.stat-label { font-weight: 500; }
.stat-sub { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; }
.quick { display: flex; align-items: center; gap: .6rem; background: #fff; padding: .9rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: var(--text); font-weight: 500; }
.quick:hover { background: var(--green-soft); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.report-card { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.report-card p { margin: 0; flex: 1; }

/* ───── جدول ───── */
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: #edf4ef; font-weight: 700; text-align: start; padding: .6rem .8rem; font-size: .88rem; white-space: nowrap; position: sticky; top: 0; }
.table td { padding: .55rem .8rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: #f8fbf9; }
.table .idx { color: var(--muted); width: 2.5rem; }
.table .notes { max-width: 260px; color: var(--muted); }
.table tfoot td { font-weight: 700; background: #f3f7f4; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.more { padding: .8rem; text-align: center; }
.muted { }
.badge { display: inline-block; padding: .05rem .65rem; border-radius: 99px; font-size: .82rem; font-weight: 500; background: #eceff1; color: #455a64; white-space: nowrap; }
.badge.s1 { background: #dff3e5; color: #17612f; }
.badge.s2 { background: #fff1d6; color: #8a5a00; }
.badge.s3 { background: #fde2e0; color: #9c2a22; }
.badge.admin { background: #e5e8ff; color: #2e3a9c; }

@media (max-width: 760px) {
  .table-wrap { background: transparent; box-shadow: none; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tbody tr { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: .7rem; padding: .4rem .2rem; }
  .table td { border: 0; display: flex; justify-content: space-between; gap: 1rem; padding: .3rem .9rem; text-align: end; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; flex: none; text-align: start; }
  .table td.idx { display: none; }
  .table td.notes { max-width: none; }
  .table td.actions-col { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .6rem; }
  .table td.actions-col::before { display: none; }
  .table td.actions-col .row-actions { width: 100%; }
  .table td.actions-col .btn { flex: 1; }
  .table tfoot { display: block; }
  .grid2 { grid-template-columns: 1fr; }
  .rangebar { grid-template-columns: 1fr; }
}

/* ───── پنجره ───── */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 30, 18, .5); display: flex; align-items: flex-start; justify-content: center; padding: 3vh .6rem; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.25); margin: auto 0; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1rem .7rem .5rem; padding-inline: 1.1rem .5rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: 1rem 1.1rem 1.2rem; }
.confirm-msg { margin: 0 0 .5rem; font-size: 1.02rem; }
.receipt-canvas { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; display: block; }

.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: .35rem .6rem; text-align: center; border-bottom: 1px solid var(--line); }
.perm-table th:first-child, .perm-table td:first-child { text-align: start; white-space: nowrap; }
.perm-box > * { margin-bottom: .6rem; }
.perm-box .table-wrap { box-shadow: none; border: 1px solid var(--line); }

.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; border-bottom: 2px solid var(--line); }
.tab { background: none; border: 0; padding: .6rem 1rem; cursor: pointer; font-weight: 500; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--green-dark); border-bottom-color: var(--green); }

/* ───── ورود ───── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, #e4f2e8, #f3f7f4 60%); }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 1.6rem; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: .8rem; }
.auth-card h1 { text-align: center; }
.auth-card p { margin: 0; text-align: center; }
.auth-logo { width: 72px; height: 72px; border-radius: 18px; align-self: center; }

/* ───── اعلان ───── */
#toasts { position: fixed; z-index: 200; bottom: 1rem; inset-inline: 1rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; }
.toast { background: #17261c; color: #fff; padding: .65rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 100%; }
.toast.err { background: var(--danger); }
.next-code { font-weight: 700; color: var(--green-dark); }

/* ───── چاپ ───── */
#printArea { display: none; }
@page { size: A5 landscape; margin: 0; }
@media print {
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing { background: #fff; }
  body.printing #printArea { display: block; }
  body.printing #printArea img { width: 100%; height: auto; display: block; }
}
@media (min-width: 900px) { .exit-top { display: none; } }
