/* ------------------------------------------------------------------
   سامانه حسابداری — سیستم طراحی
   فونت: Vazirmatn (SIL OFL 1.1) — محلی
   آیکون: Lucide (ISC) — اسپرایت SVG محلی
------------------------------------------------------------------- */

@import url("fonts.css");

:root {
  color-scheme: light;

  --font: "Vazirmatn VF", Vazirmatn, Tahoma, "Segoe UI", system-ui, sans-serif;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e5e9f2;
  --line-strong: #cbd5e1;

  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #8494ac;

  --brand: #1e4fd8;
  --brand-ink: #16389a;
  --brand-soft: #eaf0ff;

  --ok: #0f7a52;
  --ok-soft: #e6f6ef;
  --warn: #a45b06;
  --warn-soft: #fdf3e3;
  --danger: #b3261e;
  --danger-soft: #fdecea;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --sidebar: 15.5rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg);
}

body, input, select, textarea, button { font-family: var(--font); }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); }

/* ---------------------------------------------------------- آیکون */
.ico {
  display: inline-block;
  vertical-align: -.18em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------------------------------------------------------- چیدمان */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: none;
  background: #101828;
  color: #cdd5e1;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.1rem 1.15rem;
  color: #fff; font-weight: 700; font-size: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sidebar-brand .ico { color: #6f9bff; }
.sidebar nav { padding: .6rem .6rem 1.5rem; overflow-y: auto; }

.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .7rem; margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: #b9c3d3; font-size: .875rem;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; font-weight: 500; }
.nav-link.active .ico { color: #fff; }
.nav-link .ico { color: #8fa0ba; }
.nav-group {
  padding: 1rem .75rem .3rem;
  font-size: .68rem; font-weight: 600; letter-spacing: .06em;
  color: #64748b; text-transform: uppercase;
}

.main { display: flex; min-width: 0; flex: 1; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .85rem 1.5rem;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.0625rem; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--ink-2); }
.topbar-user { display: flex; align-items: center; gap: .35rem; }

.content { padding: 1.5rem; flex: 1; }
.page-intro {
  display: flex; gap: .6rem;
  border: 1px solid #cfe0ff; background: var(--brand-soft); color: #17306e;
  border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1.25rem; font-size: .875rem;
}
.page-intro .ico { color: var(--brand); margin-top: .2rem; }

/* ---------------------------------------------------------- کارت */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}
.card + .card { margin-top: 1rem; }
.grid-cards .card + .card, .grid-cards > .card { margin-top: 0; }
.card-title {
  display: flex; align-items: center; gap: .45rem;
  font-size: .95rem; font-weight: 600; margin-bottom: .9rem;
}
.card-title .ico { color: var(--ink-3); }

.stat { display: flex; flex-direction: column; gap: .1rem; }
.stat-label { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--ink-2); }
.stat-label .ico { color: var(--ink-3); }
.stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.stat-link { font-size: .78rem; display: inline-flex; align-items: center; gap: .25rem; margin-top: .35rem; }

.tile {
  display: flex; gap: .8rem; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; background: var(--surface);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.tile:hover { border-color: #b9ccff; box-shadow: var(--shadow); transform: translateY(-1px); }
.tile-icon {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none;
  border-radius: 10px; background: var(--brand-soft); color: var(--brand);
}
.tile strong { display: block; font-size: .925rem; color: var(--ink); }
.tile p { margin: .15rem 0 0; font-size: .78rem; color: var(--ink-2); line-height: 1.6; }

/* ---------------------------------------------------------- فرم */
label { display: block; font-size: .8rem; font-weight: 500; color: var(--ink-2); margin-bottom: .3rem; }

.field,
input[type=text], input[type=number], input[type=password], input[type=email], input[type=file], select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  background: #fff;
  font-size: .9rem;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.field:hover, select:hover, textarea:hover { border-color: #9fb3cd; }
.field:focus, select:focus, textarea:focus, input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(30, 79, 216, .14);
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238494ac' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left .65rem center;
  padding-left: 2rem;
  text-overflow: ellipsis;
}
textarea { min-height: 4.5rem; resize: vertical; }

.form-grid { display: grid; gap: .9rem 1rem; }
@media (min-width: 768px) { .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); } .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); } }

.hint { display: block; font-size: .72rem; color: var(--ink-3); margin-top: .25rem; }
.money-hint { display: block; font-size: .72rem; color: var(--brand-ink); margin-top: .25rem; }
.money-hint:empty, .select-note:empty { display: none; }
.errorlist { color: var(--danger); font-size: .78rem; list-style: none; padding: 0; margin: .3rem 0 0; }

/* ---------------------------------------------------------- دکمه */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .5rem 1rem; font-size: .875rem; font-weight: 500; font-family: inherit;
  cursor: pointer; white-space: nowrap; transition: background .12s, box-shadow .12s, border-color .12s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); color: #fff; }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover { background: #0b5f40; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1d16; color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: #9fb3cd; }
.btn-link { background: none; border: none; color: var(--brand); padding: 0; cursor: pointer; font-size: .82rem; }
.btn-link.danger { color: var(--danger); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(30, 79, 216, .25); }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* ---------------------------------------------------------- جدول */
.table-wrap { overflow-x: auto; margin-inline: -.25rem; padding-inline: .25rem; }
table.grid { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.grid th {
  background: var(--surface-2); text-align: right; padding: .6rem .7rem;
  font-weight: 600; font-size: .78rem; color: var(--ink-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid td { padding: .6rem .7rem; border-bottom: 1px solid #f1f4f9; vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: #fafbfe; }
table.grid tfoot th { background: transparent; border-top: 2px solid var(--line); border-bottom: none; color: var(--ink); font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; unicode-bidi: plaintext; }
table.grid th.num, table.grid td.num { text-align: right; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--ink-3); }
.empty .ico { display: block; margin: 0 auto .5rem; color: var(--line-strong); }

/* ---------------------------------------------------------- نشان‌ها و پیام‌ها */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  border-radius: 999px; padding: .1rem .6rem; font-size: .74rem; font-weight: 500; white-space: nowrap;
}
.badge.ok, .badge.final { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.cancelled { background: #eef1f6; color: var(--ink-2); }

.alert {
  display: flex; gap: .6rem; align-items: flex-start;
  border: 1px solid; border-radius: var(--radius); padding: .8rem 1rem; font-size: .875rem;
}
.alert .ico { margin-top: .18rem; flex: none; }
.alert-info { background: var(--brand-soft); border-color: #cfe0ff; color: #17306e; }
.alert-success { background: var(--ok-soft); border-color: #b9e5d1; color: #0b5238; }
.alert-warning { background: var(--warn-soft); border-color: #f2d9ac; color: #7a4405; }
.alert-error { background: var(--danger-soft); border-color: #f4c2be; color: #8f1d16; }

.total-note { font-size: .8rem; margin-inline-start: .4rem; font-weight: 500; }
.total-note.ok { color: var(--ok); }
.total-note.bad { color: var(--danger); }

.summary-bar {
  position: sticky; bottom: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--brand);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .9rem 1.15rem; margin-top: 1rem;
}
.summary-bar dl { display: grid; gap: .5rem 1.5rem; margin: 0 0 .75rem; }
@media (min-width: 768px) { .summary-bar dl { grid-template-columns: repeat(4, auto); justify-content: start; } }
.summary-bar dt { font-size: .76rem; color: var(--ink-2); }
.summary-bar dd { margin: 0; font-size: 1rem; font-weight: 700; }

/* ---------------------------------------------------------- تقویم شمسی */
.datepicker {
  position: absolute; z-index: 60; top: calc(100% + 4px); inset-inline-start: 0;
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: .6rem; width: 15.5rem; box-shadow: var(--shadow-lg);
}
.dp-head { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; font-weight: 600; margin-bottom: .45rem; }
.dp-head button { background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; width: 1.8rem; height: 1.8rem; cursor: pointer; color: var(--ink-2); display: grid; place-items: center; }
.dp-head button:hover { background: var(--brand-soft); color: var(--brand); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dp-wd { font-size: .68rem; color: var(--ink-3); padding: .25rem 0; font-weight: 500; }
.dp-day { font-size: .8rem; padding: .34rem 0; border-radius: 7px; border: none; background: none; cursor: pointer; color: var(--ink); font-family: inherit; }
.dp-day:hover { background: var(--brand-soft); color: var(--brand-ink); }
.dp-today { background: var(--brand); color: #fff; font-weight: 600; }
.dp-now { width: 100%; margin-top: .45rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: .35rem; font-size: .8rem; cursor: pointer; font-family: inherit; color: var(--ink-2); }
.dp-now:hover { background: var(--brand-soft); color: var(--brand); }

/* ---------------------------------------------------------- ریز اجزا */
.alloc-block { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .9rem; background: var(--surface-2); }
.alloc-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .7rem; }
.alloc-block table.grid th { background: #fff; }
.alloc-block input { max-width: 9rem; }

.meta-grid { display: grid; gap: .6rem 1.25rem; font-size: .875rem; }
@media (min-width: 640px) { .meta-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .meta-grid.cols-4 { grid-template-columns: repeat(4, 1fr); } .meta-grid.cols-5 { grid-template-columns: repeat(5, 1fr); } }
.meta-grid dt { font-size: .76rem; color: var(--ink-3); }
.meta-grid dd { margin: 0; font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.toolbar form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.toolbar .field { width: auto; min-width: 13rem; }
.search-box { position: relative; }
.search-box .ico { position: absolute; inset-inline-start: .6rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-box input { padding-inline-start: 2rem; }

.grid-cards { display: grid; gap: 1rem; }
@media (min-width: 640px) { .grid-cards.c2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) {
  .grid-cards.c3 { grid-template-columns: repeat(3, 1fr); }
  .grid-cards.c4 { grid-template-columns: repeat(4, 1fr); }
  .grid-cards > .span2 { grid-column: span 2; }
}

.help-step { border-inline-start: 3px solid var(--brand); padding-inline-start: 1rem; margin-bottom: 1.5rem; }
.sidebar-toggle { display: none; background: none; border: none; color: #fff; cursor: pointer; }
.topbar-toggle { display: none; }   /* فقط روی موبایل دیده می‌شود */

/* ---------------------------------------------------------- موبایل */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar-toggle { display: inline-grid; place-items: center; }
  .sidebar nav { display: none; }
  .sidebar nav.open { display: block; }
  .content { padding: 1rem; }
  .topbar { padding: .75rem 1rem; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; font-size: 12px; }
  .card { border: none; box-shadow: none; padding: 0; }

  @page { size: A4; margin: 12mm; }
  .portal-main, .print-page { padding: 0; margin: 0; max-width: none; }
  .sheet { border: none; box-shadow: none; padding: 0; margin: 0; max-width: none; }
  .sheet-items thead { display: table-header-group; }
  .sheet-items tr, .sheet-signatures, .sheet-footer { break-inside: avoid; }
  table.grid tbody tr:hover td { background: transparent; }
  .table-wrap { overflow: visible; }
}

/* ---------------------------------------------------------- نسخه چاپی فاکتور */
.print-page { background: #eef1f7; padding: 1.25rem; }
.print-bar { display: flex; flex-wrap: wrap; gap: .5rem; max-width: 48rem; margin: 0 auto 1rem; }

.sheet {
  max-width: 48rem; margin: 0 auto; padding: 1.75rem;
  background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.sheet > * + * { margin-top: 1.1rem; }

.sheet-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding-bottom: 1rem; border-bottom: 2px solid var(--ink);
}
.sheet-org h1 { font-size: 1.35rem; }
.sheet-org-name { margin: .25rem 0 .1rem; font-weight: 600; font-size: .95rem; }
.sheet-org p { margin: 0; }

.sheet-id { display: grid; gap: .25rem; margin: 0; font-size: .85rem; }
.sheet-id div { display: flex; gap: .5rem; }
.sheet-id dt { color: var(--ink-2); min-width: 6rem; }
.sheet-id dd { margin: 0; }

.sheet-qr { margin: 0; text-align: center; }
.sheet-qr img { width: 6rem; height: 6rem; display: block; }
.sheet-qr figcaption { margin-top: .2rem; max-width: 6rem; }

.sheet-stamp {
  align-self: center; padding: .35rem 1rem; font-weight: 700; font-size: 1rem;
  border: 2px dashed var(--line-strong); border-radius: var(--radius-sm); color: var(--ink-2);
  transform: rotate(-4deg);
}
.sheet-stamp.draft { border-color: #e0b877; color: var(--warn); }
.sheet-stamp.cancelled { border-color: #e9a6a1; color: var(--danger); }

.sheet-warning {
  margin: 0; padding: .5rem .8rem; font-size: .82rem;
  background: var(--warn-soft); border: 1px solid #f2d9ac; border-radius: var(--radius-sm); color: #7a4405;
}

.sheet-party h2, .sheet-payments h2 { font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .5rem; }
.sheet-party-grid {
  display: grid; gap: .5rem 1rem; font-size: .85rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .75rem .9rem; background: var(--surface-2);
}
@media (min-width: 640px) { .sheet-party-grid { grid-template-columns: repeat(3, 1fr); } .sheet-party-grid .wide { grid-column: 1 / -1; } }
.sheet-party-grid span { display: block; font-size: .72rem; color: var(--ink-3); }

.sheet-items th, .sheet-items td { border-bottom: 1px solid var(--line); }
.sheet-items tbody tr:last-child td { border-bottom: 1px solid var(--line); }

.sheet-footer { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; justify-content: space-between; }
.sheet-notes { flex: 1 1 16rem; min-width: 0; font-size: .85rem; }
.sheet-words { margin: 0; }
.sheet-note-text { margin: .5rem 0 0; color: var(--ink-2); }
.sheet-note-text span { color: var(--ink-3); }

.sheet-totals { flex: 0 1 19rem; margin: 0; font-size: .875rem; }
.sheet-totals div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; }
.sheet-totals dt { color: var(--ink-2); }
.sheet-totals dd { margin: 0; }
.sheet-totals .grand { border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); margin: .3rem 0; font-weight: 700; font-size: .95rem; }
.sheet-totals .grand dt { color: var(--ink); }
.sheet-totals .due { font-weight: 700; }

.sheet-signatures { display: flex; gap: 2rem; margin-top: 2.5rem; }
.sheet-signatures div { flex: 1; border-top: 1px dashed var(--line-strong); padding-top: .4rem; text-align: center; }
.sheet-signatures span { font-size: .78rem; color: var(--ink-2); }

/* ---------------------------------------------------------- بخش تاشو */
.collapse-card { padding: 0; }
.collapse-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .9rem 1.15rem; cursor: pointer; list-style: none; border-radius: var(--radius);
}
.collapse-head::-webkit-details-marker { display: none; }
.collapse-head:hover { background: var(--surface-2); }
.collapse-head:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(30, 79, 216, .25); }
.collapse-title { display: flex; align-items: center; gap: .45rem; font-size: .95rem; font-weight: 600; }
.collapse-title .ico { color: var(--ink-3); }
.collapse-hint { display: flex; align-items: center; gap: .6rem; }
.collapse-count { font-size: .76rem; color: var(--ink-3); }
.collapse-action {
  display: inline-flex; align-items: center; gap: .3rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: .3rem .7rem; font-size: .82rem; font-weight: 500; color: var(--ink); background: #fff;
}
.collapse-head:hover .collapse-action { border-color: #9fb3cd; color: var(--brand-ink); }
.collapse-action .ico { transition: transform .15s; }
.collapse-close { display: none; }
[open] > .collapse-head .collapse-open { display: none; }
[open] > .collapse-head .collapse-close { display: inline; }
[open] > .collapse-head .collapse-action .ico { transform: rotate(180deg); }
.collapse-body { padding: 0 1.15rem 1.15rem; }

/* ---------------------------------------------------------- کمکی‌ها */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.row-end { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }
.stack > * + * { margin-top: .9rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-2); }
.small { font-size: .8rem; }
.tiny { font-size: .72rem; color: var(--ink-3); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.center { text-align: center; }
.mt-1 { margin-top: .35rem; } .mt-2 { margin-top: .75rem; } .mt-3 { margin-top: 1.15rem; } .mt-4 { margin-top: 1.6rem; }
.mb-1 { margin-bottom: .35rem; } .mb-2 { margin-bottom: .75rem; } .mb-3 { margin-bottom: 1.15rem; } .mb-4 { margin-bottom: 1.6rem; }
.hidden { display: none; }
.list { margin: 0; padding-inline-start: 1.2rem; }
.list li + li { margin-top: .3rem; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li + li { margin-top: .35rem; }
details > summary { cursor: pointer; font-size: .84rem; color: var(--ink-2); user-select: none; }
details > summary:hover { color: var(--brand); }
details[open] > summary { margin-bottom: .6rem; }
.sheet { max-width: 44rem; }
.invoice-doc { max-width: 52rem; margin: 0 auto; }

/* ---------------------------------------------------------- پنل مشتری و شریک */
.portal-header { background: #101828; color: #e2e8f0; }
.portal-header a { color: #cbd5e1; display: inline-flex; align-items: center; gap: .35rem; font-size: .875rem; }
.portal-header a:hover { color: #fff; }
.portal-brand { font-weight: 700; font-size: 1rem; color: #fff !important; }
.portal-brand .ico { color: #6f9bff; }
.portal-header .btn-ghost { background: rgba(255,255,255,.08); color: #e2e8f0; border-color: rgba(255,255,255,.16); }
.portal-header .btn-ghost:hover { background: rgba(255,255,255,.16); color: #fff; }
.portal-wrap { max-width: 68rem; margin: 0 auto; padding: 0 1.25rem; }
.portal-header .portal-wrap { padding-block: .9rem; }
.portal-main { padding-block: 2rem; }
.auth-card { max-width: 24rem; margin: 3.5rem auto; }
.auth-card .card { padding: 1.75rem; }

/* ---------------------------------------------------------- دراپ‌داون با افزودن/به‌روزرسانی */
.select-group { display: block; }
.select-line { display: flex; align-items: stretch; gap: .35rem; }
.select-line select { flex: 1 1 auto; min-width: 0; }
.icon-btn {
  flex: none; width: 2.25rem; min-height: 2.25rem;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink-2);
  transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); border-color: #b9ccff; }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(30, 79, 216, .25); }
select.is-loading { opacity: .55; }
.select-note { display: block; font-size: .72rem; color: var(--ok); margin-top: .2rem; }
.select-note.bad { color: var(--danger); }

/* ---------------------------------------------------------- وضعیت ارسال فرم */
.btn.is-busy { opacity: .65; cursor: progress; }
.btn.is-busy::after {
  content: ""; width: .8rem; height: .8rem; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- صفحه‌بندی */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-top: 1rem; }
.pager .pages { display: flex; align-items: center; gap: .3rem; }
.pager a, .pager span.page-current, .pager span.page-link {
  display: inline-grid; place-items: center; min-width: 2.1rem; height: 2.1rem; padding: 0 .5rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: .82rem;
  color: var(--ink-2); background: #fff;
}
.pager a:hover { border-color: var(--brand); color: var(--brand); }
.pager span.page-current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .disabled { opacity: .4; pointer-events: none; }

/* ---------------------------------------------------------- پنجره افزودن رکورد */
.popup-body { background: var(--surface); }
.popup-body .content { padding: 1.25rem; }
.popup-done { display: grid; place-items: center; min-height: 60vh; text-align: center; gap: .6rem; }

/* ---------------------------------------------------------- دسترس‌پذیری */
.skip-link {
  position: absolute; inset-inline-start: -9999px; top: .5rem; z-index: 100;
  background: var(--brand); color: #fff; padding: .5rem 1rem; border-radius: var(--radius-sm);
}
.skip-link:focus { inset-inline-start: .5rem; color: #fff; }
a:focus-visible, button:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px;
}
.req { color: var(--danger); margin-inline-start: .15rem; }
.nav-overlay { display: none; }

/* ---------------------------------------------------------- موبایل: کشوی منو و جدول‌ها */
@media (max-width: 900px) {
  .sidebar { position: sticky; top: 0; z-index: 45; }
  /* در RTL کشو باید از سمت راست (لبه شروع) باز شود */
  .sidebar nav {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: min(17rem, 84vw);
    background: #101828; padding-top: 1rem; overflow-y: auto;
    transform: translateX(100%); transition: transform .22s ease, visibility .22s;
    display: block; visibility: hidden;
    box-shadow: -8px 0 24px rgba(0, 0, 0, .3);
  }
  .sidebar nav.open { transform: translateX(0); visibility: visible; }
  .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 44; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .nav-overlay.show { opacity: 1; pointer-events: auto; }
  .nav-link { padding: .7rem .8rem; font-size: .92rem; }

  /* لمس راحت‌تر */
  .btn { padding: .6rem 1rem; min-height: 2.6rem; }
  .icon-btn { width: 2.6rem; min-height: 2.6rem; }
  .btn-link { display: inline-flex; align-items: center; gap: .3rem; min-height: 2.6rem; padding: .3rem .2rem; }

  /* iOS با فونت کوچک‌تر از ۱۶px صفحه را زوم می‌کند */
  .field, input, select, textarea { font-size: 16px; }

  /* جدول‌های پهن: راهنمای اسکرول */
  .table-wrap { position: relative; -webkit-overflow-scrolling: touch; }
  .table-wrap::after {
    content: ""; position: sticky; inset-inline-end: 0; top: 0; float: left;
    width: 1.5rem; height: 100%; pointer-events: none;
    background: linear-gradient(to left, rgba(255,255,255,.95), rgba(255,255,255,0));
  }
  .scroll-hint { display: flex; }

  .summary-bar { padding: .8rem; }
  .summary-bar dl { grid-template-columns: 1fr 1fr; gap: .4rem .8rem; }
  .summary-bar dd { font-size: .92rem; }
  .alloc-block input { max-width: none; }
  .toolbar .field { min-width: 0; width: 100%; }
  .toolbar form { width: 100%; }
  .toolbar form .search-box { flex: 1 1 12rem; }
  .datepicker { width: min(15.5rem, 88vw); }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  .topbar h1 { font-size: 1rem; width: 100%; }
}

@media (min-width: 901px) { .scroll-hint { display: none; } }

@media (max-width: 520px) {
  /* دو ستونه ماندن، صفحه را نصف می‌کند و همه اعداد هم جا می‌شوند */
  .meta-grid { grid-template-columns: 1fr 1fr; gap: .55rem .8rem; }
  .grid-cards.c4 { grid-template-columns: 1fr 1fr; }
  .grid-cards.c4 .card { padding: .8rem .7rem; }
  .stat-value { font-size: 1.02rem; overflow-wrap: anywhere; }
  .stat-label { font-size: .74rem; }
  .stat-link { font-size: .72rem; }
  .summary-bar dl { grid-template-columns: 1fr; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .card { padding: 1rem; }
  .content { padding: .85rem; }
}

/* دراپ‌داون داخل جدول نباید بیش از حد فشرده شود */
td .select-line { min-width: 11rem; }
td .select-note { display: none; }

/* صفحه‌های خطا */
.error-page { display: grid; place-items: center; min-height: 70vh; text-align: center; padding: 2rem 1rem; }
.error-page .code { font-size: 3rem; font-weight: 700; color: var(--ink-3); line-height: 1; }
.error-page h1 { font-size: 1.25rem; margin: .75rem 0 .35rem; }

/* ---------------------------------------------------------- حذف آنی ردیف */
[data-row] input[type=checkbox][name$="-DELETE"] { display: none; }
.row-actions { white-space: nowrap; }
.icon-btn.danger { color: var(--danger); border-color: #f0c9c6; background: #fff; }
.icon-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.icon-btn:disabled { opacity: .5; cursor: wait; }

.toast {
  position: fixed; inset-block-end: 1.25rem; inset-inline-start: 50%;
  transform: translate(50%, 1rem);
  background: var(--ink); color: #fff; border-radius: var(--radius);
  padding: .6rem 1.1rem; font-size: .85rem; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 90;
}
.toast.show { opacity: 1; transform: translate(50%, 0); }
.toast.bad { background: var(--danger); }

/* ---------------------------------------------------------- ماشین‌حساب (مودال) */
.input-group { position: relative; display: block; }
.input-line { display: flex; align-items: stretch; gap: .35rem; }
.input-line > input { flex: 1 1 auto; min-width: 0; }

body.calc-open { overflow: hidden; }

.calc-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  animation: calc-fade .14s ease;
}
@keyframes calc-fade { from { opacity: 0; } to { opacity: 1; } }

.calc-panel {
  width: min(21rem, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1rem;
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .35);
  animation: calc-pop .16s ease;
}
@keyframes calc-pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

.calc-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  font-size: .82rem; color: var(--ink-2); margin-bottom: .6rem;
}
.calc-head b { color: var(--ink); }
.calc-close {
  background: none; border: none; color: var(--ink-3); cursor: pointer;
  display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--radius-sm);
}
.calc-close:hover { background: var(--danger-soft); color: var(--danger); }

.calc-screen {
  width: 100%; font-size: 1.15rem; padding: .6rem .75rem;
  font-variant-numeric: tabular-nums; text-align: left; direction: ltr;
}
.calc-result {
  margin: .6rem 0; padding: .55rem .7rem; border-radius: var(--radius-sm);
  background: var(--brand-soft); color: var(--brand-ink); min-height: 3rem;
}
.calc-value { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; direction: ltr; text-align: left; }
.calc-words { display: block; font-size: .72rem; color: var(--ink-2); line-height: 1.6; }

/* چیدمان چپ‌به‌راست، دقیقاً مثل ماشین‌حساب گوشی */
.calc-keys { direction: ltr; display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.calc-key {
  min-height: 3rem; font-size: 1.15rem; font-family: inherit; cursor: pointer;
  border: 1px solid var(--line); border-radius: .7rem;
  background: #fff; color: var(--ink);
  display: grid; place-items: center;
  transition: background .1s, transform .06s;
}
.calc-key:hover { background: var(--surface-2); }
.calc-key:active { transform: scale(.96); background: var(--brand-soft); }
.calc-key.calc-op { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; border-color: #cfe0ff; }
.calc-key.calc-op:hover { background: #dce7ff; }
.calc-key.calc-fn { background: var(--surface-2); color: var(--ink-2); font-size: 1rem; }
.calc-key:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(30, 79, 216, .3); }

.calc-actions { display: grid; grid-template-columns: 2fr 1fr; gap: .5rem; margin-top: .7rem; }
.calc-actions .btn { justify-content: center; min-height: 2.8rem; }

td .input-line { min-width: 10rem; }

.calc-panel.has-error .calc-result { background: var(--danger-soft); color: var(--danger); }
.calc-panel.has-error .calc-words { color: var(--danger); }

/* ================================================================
   موبایل: استفاده درست از فضا
   ================================================================ */
@media (max-width: 900px) {
  /* فقط یک نوار چسبان بالای صفحه بماند، نه سه ردیف */
  .sidebar { position: static; }
  .sidebar-brand { padding: .7rem 1rem; font-size: .95rem; }
  .sidebar-toggle { display: none; }
  .topbar-toggle {
    display: inline-grid; place-items: center; flex: none;
    width: 2.4rem; height: 2.4rem; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer;
  }
  .topbar { flex-wrap: nowrap; gap: .6rem; padding: .6rem .85rem; }
  .topbar h1 { width: auto; flex: 1 1 auto; font-size: .98rem; min-width: 0;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { display: none; }
  .nav-user { display: block; border-top: 1px solid rgba(255,255,255,.08); margin-top: .5rem; }

  /* جدول‌های ورود داده به‌جای اسکرول افقی، کارت می‌شوند */
  table.entry-grid, table.entry-grid tbody, table.entry-grid tr, table.entry-grid td { display: block; width: 100%; }
  table.entry-grid thead { display: none; }
  table.entry-grid { border-collapse: separate; }
  table.entry-grid tr {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: .75rem; margin-bottom: .7rem; background: var(--surface-2);
  }
  table.entry-grid tbody tr:hover td { background: transparent; }
  table.entry-grid td { border: none; padding: .3rem 0; }
  table.entry-grid td::before {
    content: attr(data-label); display: block;
    font-size: .75rem; font-weight: 500; color: var(--ink-2); margin-bottom: .25rem;
  }
  table.entry-grid td[data-label="جمع ردیف"] {
    display: flex; justify-content: space-between; align-items: baseline;
    border-top: 1px dashed var(--line); margin-top: .45rem; padding-top: .5rem; font-weight: 700;
  }
  table.entry-grid td[data-label="جمع ردیف"]::before { margin: 0; font-weight: 500; }
  /* حذف در گوشه کارت، تا یک ردیف کامل از ارتفاع صفحه نگیرد */
  table.entry-grid tr { position: relative; }
  table.entry-grid td[data-label="حذف"] {
    position: absolute; inset-inline-start: .5rem; top: .6rem; width: auto; padding: 0;
  }
  table.entry-grid td[data-label="حذف"]::before { display: none; }
  table.entry-grid td .input-line, table.entry-grid td .select-line { min-width: 0; }
  table.entry-grid td .money-hint { display: block; }
}

@media (max-width: 520px) {
  /* نوار جمع فشرده شود تا نصف صفحه را نگیرد */
  .summary-bar { padding: .7rem .8rem calc(.7rem + env(safe-area-inset-bottom, 0px)); }
  .summary-bar dl { grid-template-columns: 1fr 1fr; gap: .45rem .8rem; margin-bottom: .6rem; }
  .summary-bar dt { font-size: .72rem; margin: 0; }
  .summary-bar dd { font-size: .9rem; }
  .summary-bar .total-note { display: block; margin: .1rem 0 0; font-size: .72rem; }
  .summary-bar .btn { width: 100%; justify-content: center; }
  .summary-bar .row .tiny { display: none; }

  .card { padding: .9rem; }
  .card-title { margin-bottom: .7rem; }
  .form-grid { gap: .7rem; }
  .page-intro { padding: .7rem .8rem; font-size: .82rem; }
}
@media (max-width: 900px) {
  table.entry-grid td[colspan]::before { display: none; }
  table.entry-grid td[colspan] { text-align: center; color: var(--ink-3); }
}

/* نوار جمع روی موبایل: پیش‌فرض فشرده، با امکان باز شدن */
.summary-toggle { display: none; }
@media (max-width: 700px) {
  .summary-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: .4rem;
    width: 100%; margin-bottom: .5rem; padding: .35rem .5rem; cursor: pointer;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .78rem; color: var(--ink-2);
  }
  .summary-toggle .ico { transition: transform .18s; }
  .summary-bar.expanded .summary-toggle .ico { transform: rotate(180deg); }
  .summary-bar .sum-extra { display: none; }
  .summary-bar.expanded .sum-extra { display: block; }
}

@media (max-width: 420px) {
  .calc-panel { padding: .85rem; }
  .calc-key { min-height: 2.9rem; }
}

/* ------------------------------------------------------- صفحه لیست قیمت (نمایش)
   در DOM یک جدول واقعی است تا مرورگر هنگام چاپ سربرگش را بالای هر برگه A4 تکرار کند
   (فقط <thead> واقعی تکرار می‌شود، نه display:table-header-group روی div).
   اینجا همان جدول با CSS به شبکهٔ کارت تبدیل می‌شود. */
.pl-hero {
  background: linear-gradient(135deg, #12224a, #1e4fd8);
  color: #fff; border-radius: var(--radius); padding: 1.35rem;
  box-shadow: var(--shadow-lg);
}
.pl-hero-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .6rem 1.25rem; }
.pl-hero-main { flex: 1 1 18rem; min-width: 0; }
.pl-hero-side { display: flex; flex-direction: column; align-items: flex-end; text-align: end; margin-inline-start: auto; }
.pl-brand-name { font-weight: 700; font-size: .95rem; }
.pl-brand-line { font-size: .74rem; color: #b9c9ee; }

.pl-hero h1 { font-size: 1.3rem; margin: 0 0 .3rem; line-height: 1.6; overflow-wrap: anywhere; }
.pl-intro { margin: 0; color: #cfdcff; font-size: .85rem; max-width: 46rem; line-height: 1.9; }

.rate-strip { display: grid; gap: .6rem; margin-top: 1.1rem; }
@media (min-width: 560px) { .rate-strip { grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr)); } }
.rate-chip {
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--radius-sm); padding: .65rem .8rem;
  display: flex; align-items: center; gap: .65rem; min-width: 0;
}
.rate-chip .ico { color: #9dbaff; flex: none; }
.rate-chip > div { min-width: 0; }
.rate-chip .rate-value { font-size: 1.02rem; font-weight: 700; line-height: 1.45; }
.rate-chip .rate-label { font-size: .73rem; color: #b9c9ee; line-height: 1.7; }
.rate-chip.is-stale { border-color: rgba(255, 200, 120, .45); }
.rate-chip .rate-flag { font-size: .68rem; color: #ffd79a; }
.rate-chip .rate-missing { color: #ffc9c4; }

.pl-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin: 1.35rem 0 1rem; }
.pl-search { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; flex: 1 1 16rem; }
.pl-search .search-box { flex: 1 1 11rem; min-width: 0; }
.pl-search .search-box input { width: 100%; min-width: 0; }
.pl-count { font-size: .82rem; color: var(--ink-2); }

/* جدول → شبکهٔ کارت */
.pl-sheet { display: block; width: 100%; border-collapse: collapse; }
.pl-head { display: none; }                         /* سربرگ جدول فقط برای کاغذ است */
/* minmax(0,…) لازم است وگرنه عرض ذاتی عکس کف عرض ستون می‌شود و صفحه افقی سرریز می‌کند */
.pl-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 620px) { .pl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .pl-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.pl-card {
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: box-shadow .18s, transform .18s, border-color .18s;
}
.pl-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: #c3d3f5; }

.pl-thumb {
  display: grid; place-items: center; position: relative; aspect-ratio: 1 / 1;
  background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 0;
  width: 100%; min-width: 0; overflow: hidden;
}
/* contain یعنی عکس کامل دیده شود؛ نوار خالی رنگِ لبهٔ عکس را می‌گیرد
   (استایل درون‌خطی روی خود <img> از فیلد image_backdrop می‌آید). */
.pl-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; min-width: 0;
                background: var(--surface-2); }
.pl-thumb .ico { color: var(--line-strong); }
.pl-sku {
  position: absolute; inset-inline-end: .6rem; top: .6rem;
  background: rgba(15, 23, 42, .78); color: #fff;
  font-size: .7rem; padding: .18rem .5rem; border-radius: 999px; direction: ltr;
}

.pl-body { display: flex; flex-direction: column; gap: .5rem; flex: 1; min-width: 0; padding: .9rem 1rem 1rem; }
.pl-price, .pl-thumb, .pl-body { min-width: 0; }
.pl-cellbox { display: contents; }   /* فقط روی کاغذ به جعبهٔ بریده تبدیل می‌شود */
.pl-body h2 { font-size: 1rem; margin: 0; line-height: 1.7; overflow-wrap: anywhere; }
.pl-rowmeta { display: none; }
.pl-desc { font-size: .82rem; color: var(--ink-2); line-height: 1.9; margin: 0; overflow-wrap: anywhere; }

.pl-specs { display: grid; gap: .25rem; font-size: .78rem; margin: 0; }
.pl-specs div { display: flex; gap: .4rem; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: .22rem; }
.pl-specs dt { color: var(--ink-3); margin: 0; }
.pl-specs dd { margin: 0; color: var(--ink); font-weight: 500; text-align: end; overflow-wrap: anywhere; }

.pl-price {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .6rem;
  padding: .75rem 1rem .95rem; border-top: 1px solid var(--line); text-align: start;
}
.pl-toman { font-size: 1.15rem; font-weight: 700; color: var(--brand-ink); line-height: 1.6; flex: 1 1 auto; }
.pl-toman.is-missing { font-size: .85rem; font-weight: 500; color: var(--warn); }
.pl-foreign { font-size: .8rem; color: var(--ink-2); direction: ltr; unicode-bidi: isolate; }
.pl-unit { font-size: .74rem; color: var(--ink-3); flex: 1 1 100%; }
.pl-note { font-size: .74rem; color: var(--warn); flex: 1 1 100%; }

.pl-foot { margin-top: 2rem; font-size: .8rem; color: var(--ink-2); line-height: 2; text-align: center; }

/* موبایل: تصویر کوتاه‌تر تا کالای بیشتری در یک نگاه بیاید، دکمه‌های قابل لمس */
@media (max-width: 620px) {
  .pl-hero { padding: 1.1rem; border-radius: var(--radius-sm); }
  .pl-hero h1 { font-size: 1.15rem; }
  .pl-hero-side { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem;
                  margin-inline-start: 0; text-align: start; }
  .pl-toolbar { margin: 1rem 0 .85rem; }
  .pl-toolbar .row { width: 100%; justify-content: space-between; }
  .pl-search { flex: 1 1 100%; }
  .pl-toolbar .btn { min-height: 44px; }
  .pl-body { padding: .8rem .85rem .9rem; }
  .pl-price { padding: .7rem .85rem .85rem; }
}

/* ------------------------------------------------------- لیست قیمت روی کاغذ A4
   جدول به حالت طبیعی برمی‌گردد: <thead> بالای هر برگه تکرار می‌شود و هر ۱۰ کالا
   یک برگه است. ارتفاع‌ها میلی‌متری بسته شده تا ۱۰ ردیف مطمئن در A4 جا شود:
   ۲۹۷ − ۲۴ (حاشیه) = ۲۷۳mm فضا؛ سربرگ ≈ ۱۵mm + ۱۰×۲۲mm = ۲۳۵mm، پس پابرگ هم جا می‌شود. */
@media print {
  .pl-sku { display: none !important; }

  .pl-sheet { display: table; width: 100%; border-collapse: collapse; table-layout: fixed; }
  .pl-head { display: table-header-group; }
  .pl-grid { display: table-row-group; gap: 0; }

  /* سربرگ فشرده و تکرارشونده */
  /* th باید table-cell بماند وگرنه چیدمان جدول به‌هم می‌ریزد؛ فلکس روی لایه داخلی است. */
  .pl-head-row th { padding: 0 0 1.2mm; border-bottom: .7pt solid #333; text-align: start; font-weight: 400; }
  .pl-head-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: .8mm 4mm; }
  .pl-head-brand { font-size: 9pt; font-weight: 700; }
  .pl-head-brand .pl-brand-line { font-size: 7pt; color: #555; margin-inline-start: 1.5mm; }
  .pl-head-title { font-size: 11pt; font-weight: 700; }
  .pl-head-rates { font-size: 8pt; color: #333; }
  .pl-head-date { font-size: 7.5pt; color: #555; margin-inline-start: auto; }

  .pl-colhead th {
    font-size: 7.5pt; font-weight: 600; color: #444; text-align: start;
    padding: 1.2mm 2mm; border-bottom: .5pt solid #999; background: #f2f4f8;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .pl-colhead th:last-child { text-align: end; }

  /* هر کالا یک ردیف */
  .pl-card {
    display: table-row; break-inside: avoid; page-break-inside: avoid;
    box-shadow: none; border: none; border-radius: 0; transform: none; overflow: visible;
  }
  /* :not(:last-child) لازم است — با تکیه بر ترتیب قواعد، شکست روی ردیف آخر هم
     اجرا می‌شود و پابرگ را به یک برگهٔ اضافی می‌فرستد. */
  .pl-card:nth-child(10n):not(:last-child) { break-after: page; page-break-after: always; }
  .pl-card:last-child { break-after: auto; page-break-after: auto; }

  /* ارتفاع ردیف قطعی است: خانه ۲۲mm و جعبهٔ داخلی ۱۸٫۸mm با برش، پس هر برگه
     دقیقاً ۱۰ ردیف می‌گیرد هرچقدر هم متن کالا بلند باشد — و پابرگ هم در همان
     برگه جا می‌شود، پس ۱۰ کالا یک ورق کامل است نه یک‌و‌نیم ورق. */
  .pl-thumb, .pl-body, .pl-price {
    display: table-cell; vertical-align: top; height: 22mm;
    padding: 1.6mm; border-bottom: .5pt solid #d6dae2; background: none; border-radius: 0;
  }
  .pl-cellbox { display: block; height: 18.8mm; overflow: hidden; }
  .pl-card:nth-child(even) .pl-thumb,
  .pl-card:nth-child(even) .pl-body,
  .pl-card:nth-child(even) .pl-price {
    background: #fafbfd; -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .pl-thumb {
    width: 22mm; aspect-ratio: auto; text-align: center; border-inline-end: .5pt solid #eceef2;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  /* تصویر مربع و هم‌اندازه ارتفاع مفید ردیف */
  .pl-thumb .pl-cellbox { display: grid; place-items: center; }
  .pl-thumb img {
    width: 18.8mm; height: 18.8mm; object-fit: contain; border: .5pt solid #d6dae2;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .pl-thumb .ico { width: 7mm; height: 7mm; color: #c3c9d4; }

  .pl-body h2 {
    font-size: 9pt; margin: 0; line-height: 4.1mm;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .pl-rowmeta { display: block; font-size: 6.8pt; color: #666; line-height: 3.2mm; }
  .pl-desc {
    font-size: 7pt; color: #444; line-height: 3.4mm; margin: 0;
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
  }

  /* مشخصات به صورت فهرست درون‌خطی، برای استفاده بهتر از عرض کاغذ */
  .pl-specs {
    font-size: 7pt; line-height: 3.4mm; margin: 0;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .pl-specs div { display: inline; border: none; padding: 0; }
  .pl-specs div + div::before { content: " · "; color: #999; }
  .pl-specs dt, .pl-specs dd { display: inline; text-align: start; }
  .pl-specs dt { color: #777; }
  .pl-specs dt::after { content: ": "; }
  .pl-specs dd { font-weight: 600; margin: 0; }

  .pl-price { width: 33mm; text-align: end; border-inline-start: .5pt solid #eceef2; }
  .pl-toman { font-size: 10pt; font-weight: 700; color: #000; line-height: 4.6mm; }
  .pl-toman.is-missing { font-size: 7pt; font-weight: 400; color: #666; line-height: 3.2mm; }
  .pl-foreign { font-size: 8pt; color: #333; line-height: 3.8mm; }
  .pl-unit, .pl-note { font-size: 6.8pt; color: #666; line-height: 3.2mm; }

  .pl-foot { margin-top: 2mm; font-size: 7pt; color: #555; line-height: 1.7; break-inside: avoid; }
}

/* قیمت کالا به چند ارز، کنار مبلغ تومانی */
.pl-foreign { display: flex; flex-wrap: wrap; gap: .15rem .5rem; justify-content: flex-end; }
.pl-cur { white-space: nowrap; }
.pl-cur.is-base { font-weight: 600; color: var(--ink); }
@media print {
  .pl-foreign { display: block; }
  .pl-cur { display: block; }
  .pl-cur.is-base { color: #000; }
}

/* ================================================================
   ردیف‌های سند: هر کالا یک کارت دوخطی
   جدول پهن بود و اسکرول افقی می‌خواست. حالا همان <tr> یک شبکه می‌شود:
   خط اول کالا و تعداد و قیمت و جمع، خط دوم هزینه‌های اختصاصی ردیف.
   ساختار DOM دست نخورده تا افزودن/حذف ردیف و جمع زنده مثل قبل کار کند.
   ================================================================ */
.line-extras-title { display: block; font-size: .72rem; color: var(--ink-3); margin-bottom: .35rem; }
/* هر هزینه یک جفت «ارزی + تومانی» است و باید با هم بماند، نه تک‌افتاده */
.line-extras-grid { display: grid; gap: .5rem .9rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); align-items: end; }
.extra-pair { display: flex; flex-wrap: wrap; gap: .4rem .5rem; }
.extra-pair > div { flex: 1 1 9.5rem; min-width: 0; }   /* کنار هم اگر جا باشد، وگرنه زیر هم */
.line-extras-grid label { display: block; font-size: .72rem; color: var(--ink-2); margin-bottom: .2rem; }
.line-extras-grid input { width: 100%; }
table.entry-grid td.line-extras::before { display: none !important; }

@media (min-width: 901px) {
  table.entry-grid, table.entry-grid tbody { display: block; width: 100%; }
  table.entry-grid thead { display: none; }
  .table-wrap:has(table.entry-grid) { overflow-x: visible; }

  table.entry-grid tr[data-row] {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    align-items: end; gap: .55rem .8rem;
    padding: .8rem .9rem; padding-inline-start: 3rem; margin-bottom: .6rem;
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  }
  /* این قاعده برای جدول پهن قدیمی بود؛ اینجا ورودی را از ستونش پهن‌تر می‌کرد
     و روی خانه بغلی می‌افتاد. عرض را شبکه تعیین می‌کند. */
  table.entry-grid td .input-line, table.entry-grid td .select-line { min-width: 0; }
  table.entry-grid tr[data-row]:hover td { background: transparent; }
  table.entry-grid td { display: block; border: none; padding: 0; min-width: 0; }
  table.entry-grid td::before {
    content: attr(data-label); display: block;
    font-size: .72rem; color: var(--ink-2); margin-bottom: .2rem; white-space: nowrap;
  }
  table.entry-grid td .field, table.entry-grid td input, table.entry-grid td select { width: 100%; min-width: 0; }

  /* کالا پهن‌تر، جمع و حذف انتهای خط اول */
  table.entry-grid td[data-label="کالا"] { grid-column: span 2; }
  /* جمع ردیف ته خط اول می‌نشیند؛ اگر جا نبود خودش به خط بعد می‌افتد */
  table.entry-grid td[data-line-total] {
    text-align: end; font-weight: 700; font-size: 1rem;
    white-space: nowrap; padding-bottom: .5rem; min-width: 7rem;
  }
  table.entry-grid td.line-extras { order: 2; }
  /* دکمه حذف گوشه کارت می‌نشیند تا یک ستون کامل از خط اول آزاد شود */
  table.entry-grid td[data-label="حذف"] {
    position: absolute; inset-inline-start: .55rem; top: .7rem; width: auto;
  }
  table.entry-grid td[data-label="حذف"]::before { display: none; }

  /* خط دوم: سرتاسری زیر خط اول */
  table.entry-grid td.line-extras {
    grid-column: 1 / -1; margin-top: .2rem; padding-top: .6rem;
    border-top: 1px dashed var(--line-strong);
  }
}

/* موبایل: کارت‌ها فشرده‌تر و ورودی‌ها قابل لمس */
@media (max-width: 900px) {
  table.entry-grid tr { padding: .7rem .75rem; padding-inline-start: 3.5rem; }
  table.entry-grid td { padding: .25rem 0; }
  table.entry-grid td .field, table.entry-grid td input, table.entry-grid td select {
    width: 100%; min-height: 42px; font-size: 16px;   /* ۱۶px جلوی زوم خودکار iOS را می‌گیرد */
  }
  table.entry-grid td.line-extras {
    margin-top: .4rem; padding-top: .55rem; border-top: 1px dashed var(--line-strong);
  }
  .line-extras-grid { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .45rem .7rem; }
  .line-extras-grid input { min-height: 42px; font-size: 16px; }
  [data-add-row] { width: 100%; justify-content: center; min-height: 44px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
}

/* ================================================================
   بازبینی ظاهری فرم فاکتور
   ================================================================ */

/* [hidden] فقط یک display:none پیش‌فرض مرورگر است و قاعده‌های ما بر آن غلبه
   می‌کردند؛ برای همین ستون ارزی در حالت تومانی هم دیده می‌شد. */
table.entry-grid td[hidden],
table.entry-grid th[hidden],
.field-pair > [hidden],
[data-foreign-col][hidden] { display: none !important; }

/* هر هزینه با جفت ارزی‌اش یک واحد است و با هم می‌شکنند */
.field-pair { display: grid; gap: .55rem; align-content: start; }

/* سرتیتر داخل کارت، برای جدا کردن «سند» از «هزینه‌ها» */
.sub-title {
  margin: 1.25rem 0 .2rem; font-size: .84rem; font-weight: 600; color: var(--ink-2);
  padding-top: .85rem; border-top: 1px solid var(--line);
}
.sub-title:first-of-type { margin-top: 1rem; }

/* مقدارهای محاسبه‌شده باید «عدد خوانده‌شده» به نظر برسند، نه ورودی خالی */
table.entry-grid td[data-line-total],
.extra-total-value {
  font-variant-numeric: tabular-nums;
}
@media (min-width: 901px) {
  table.entry-grid td[data-line-total] {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: .3rem .6rem; align-self: end;
  }
  table.entry-grid td[data-line-total]::before { margin-bottom: .1rem; }
}

/* ---------------------------------------- خانه مبلغ و جعبه هزینه‌های جمع‌شونده */
.amount-field { display: grid; gap: .25rem; align-content: start; min-width: 0; }
.unit-tag {
  margin-inline-start: .35rem; font-size: .68rem; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: .05rem .4rem; color: var(--ink-2);
}
.amount-hint { font-size: .72rem; color: var(--brand-ink); font-variant-numeric: tabular-nums; }

.cost-box { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); margin-top: 1rem; }
.cost-box > summary {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .8rem; cursor: pointer; font-size: .84rem; font-weight: 600; color: var(--ink-2);
  list-style: none;
}
.cost-box > summary::-webkit-details-marker { display: none; }
.cost-box > summary::after {
  content: "＋"; font-weight: 400; color: var(--ink-3); order: 3; margin-inline-start: auto;
}
.cost-box[open] > summary::after { content: "－"; }
.cost-box > summary:hover { background: var(--surface); border-radius: var(--radius-sm); }
.cost-box > summary .ico { color: var(--ink-3); vertical-align: -2px; }
.cost-box-sum { font-weight: 500; font-size: .78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cost-box-sum b { color: var(--ink); }
.cost-box-sum b.grand { color: var(--brand-ink); }
.cost-box > *:not(summary) { padding: 0 .8rem .8rem; }
.cost-box.is-row { margin-top: .5rem; background: var(--surface); }

@media (min-width: 901px) {
  table.entry-grid td.line-extras { padding-top: .4rem; border-top: none; }
}

/* برچسب «قیمت واحد» ردیف هم باید واحد را بگوید؛ قاعده عمومی ::before بعداً می‌آید
   و بر آن غلبه می‌کند، پس اینجا با گزینشگر دقیق‌تر و در انتهای فایل نوشته شده است. */
table.entry-grid td[data-unit-cell][data-unit]::before {
  content: attr(data-label) " · " attr(data-unit);
}

/* ---------------------------------------- عرض ستون‌های ردیف سند
   auto-fit ستون خالی را جمع می‌کند، ولی خانه هزینه‌ها تمام‌عرض است و همه ستون‌ها را
   اشغال می‌کند؛ نتیجه‌اش ستون‌های باریک و نیمه خالیِ خط اول بود. حالا که ورودی ارزی و
   تومانی یکی شده‌اند تعداد ستون‌ها ثابت است و عرضشان را عمداً تعیین می‌کنیم. */
@media (min-width: 901px) {
  /* عرض «کالا» را خودِ الگوی ستون‌ها تعیین می‌کند، نه span */
  table.entry-grid tbody[data-row-key] tr[data-row] td[data-label="کالا"] { grid-column: auto; }

  table.entry-grid tbody[data-row-key="purchase-item"] tr[data-row] {
    grid-template-columns:
      minmax(0, 2.6fr)   /* کالا */
      minmax(0, 1fr)     /* تعداد */
      minmax(0, 1.6fr)   /* قیمت واحد + معادل تومانی */
      minmax(0, 1.3fr);  /* جمع ردیف */
  }
  table.entry-grid tbody[data-row-key="sale-item"] tr[data-row] {
    grid-template-columns:
      minmax(0, 2.4fr)   /* کالا */
      minmax(0, 1fr)     /* تعداد */
      minmax(0, 1.6fr)   /* قیمت واحد */
      minmax(0, .9fr)    /* تخفیف ردیف */
      minmax(0, 1.3fr);  /* جمع ردیف */
  }
  table.entry-grid tbody[data-row-key="purchase-contribution"] tr[data-row] {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.6fr);
  }
}

/* ---------------------------------------- خطاهای فرم داخل شبکه
   متن خطا (مخصوصاً بلند) عرض ستون را می‌کشید و کل ردیف را بازچینی می‌کرد.
   حالا در جریان عادی می‌ماند، می‌شکند، و روی اندازه ستون اثر نمی‌گذارد. */
.errorlist {
  list-style: none; margin: .2rem 0 0; padding: 0;
  font-size: .72rem; line-height: 1.6; color: var(--danger);
  overflow-wrap: anywhere; word-break: break-word;
}
.errorlist li { margin: 0; }
.amount-field, .amount-field > div,
table.entry-grid td, .line-extras-grid > * { min-width: 0; }
table.entry-grid td .errorlist, .amount-field .errorlist { max-width: 100%; }
/* خانه‌ای که خطا دارد با یک نوار قرمز کنار خودش دیده شود، نه با جابه‌جایی چیدمان */
.amount-field:has(.errorlist) > div input,
table.entry-grid td:has(.errorlist) input { border-color: var(--danger); }

/* ---------------------------------------- نمایش دوارزی مبلغ‌ها
   روی فاکتور ارزی، هر مبلغ هم به تومان و هم به ارز سند دیده می‌شود. */
.sum-foreign {
  display: block; font-size: .72rem; font-weight: 500; color: var(--ink-2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cost-box-sum .sum-foreign { display: inline; margin-inline-start: .4rem; color: var(--ink-3); }
.summary-bar .sum-foreign { color: #b9c9ee; }

/* معادل ارزی زیر هر مبلغ تومانی در صفحه سند */
.foreign-amount {
  display: block; font-size: .74rem; font-weight: 400; color: var(--ink-2);
  font-variant-numeric: tabular-nums; white-space: nowrap; margin-top: .1rem;
}
.meta-grid .foreign-amount { color: var(--brand-ink); }
@media print { .foreign-amount { color: #444; } }
