/* رسپی پاپاردله — فارسی، راست‌به‌چپ، اول موبایل. دکمه‌ها درشت برای کار با دست در آشپزخانه. */

@font-face { font-family: "Vazir"; src: url("../fonts/Vazir-Regular-FD.732f41451cb9.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazir"; src: url("../fonts/Vazir-Medium-FD.662b4bbae810.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazir"; src: url("../fonts/Vazir-Bold-FD.5d949700eb21.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --text: #2b2420;
  --muted: #7a6f66;
  --border: #e3dbd0;
  --brand: #7a2e1d;
  --brand-ink: #ffffff;
  --brand-soft: #f6e7e1;
  --ok: #2f6b3a;
  --ok-soft: #e4f1e6;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #a32020;
  --danger-soft: #fbe5e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(43, 36, 32, .06), 0 2px 8px rgba(43, 36, 32, .05);
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1715;
    --surface: #24201d;
    --surface-2: #2d2824;
    --text: #efe8e1;
    --muted: #a99d93;
    --border: #3a332e;
    --brand: #d8826a;
    --brand-ink: #1b1715;
    --brand-soft: #3a2620;
    --ok: #7fc58b;
    --ok-soft: #22352a;
    --warn: #e2b45a;
    --warn-soft: #3a3020;
    --danger: #ef8a8a;
    --danger-soft: #3d2222;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Vazir", Tahoma, sans-serif; font-size: 16px; line-height: 1.7;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.4; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.sprite { display: none; }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.lead { color: var(--muted); margin: 0 0 16px; }

/* ---------- قاب اصلی */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: 0 0 250px; background: var(--surface); border-inline-start: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 16px; }
.brand img { border-radius: 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a, .me-link {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 12px;
  border-radius: 10px; color: var(--text); text-decoration: none; font: inherit;
  background: none; border: 0; cursor: pointer; width: 100%; text-align: start;
}
.nav a:hover, .me-link:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav svg, .me-link svg { width: 22px; height: 22px; flex: 0 0 22px; }
.me { border-top: 1px solid var(--border); padding-top: 12px; }
.me-name { font-weight: 700; padding: 0 12px; }
.me-role { color: var(--muted); font-size: .85rem; padding: 0 12px 6px; }
.me form { margin: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 12px 20px; background: var(--bg);
  position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--border);
}
.page-title { font-size: 1.2rem; margin: 0; }
.content { padding: 20px; max-width: 1200px; width: 100%; }
.icon-btn {
  display: none; width: var(--tap); height: var(--tap); border: 0; border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer; align-items: center; justify-content: center;
}
.icon-btn svg { width: 24px; height: 24px; }
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 20; transform: translateX(100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 15; }
  .icon-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 8px 12px; }
}

/* ---------- اجزا */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap);
  padding: 0 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 0 10px; border-radius: 999px; font-size: .8rem;
  background: var(--surface-2); color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--danger-soft); color: var(--danger); }

.messages { margin-bottom: 16px; display: grid; gap: 8px; }
.msg { padding: 12px 16px; border-radius: 10px; background: var(--surface-2); }
.msg-success { background: var(--ok-soft); color: var(--ok); }
.msg-error { background: var(--danger-soft); color: var(--danger); }
.msg-warning { background: var(--warn-soft); color: var(--warn); }

/* ---------- فرم */
.form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 500; }
.field input[type=text], .field input[type=password], .field input[type=number], .field select, .field textarea,
.filters input, .filters select {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.field input:focus, .field select:focus, .filters input:focus, .filters select:focus {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field .error { color: var(--danger); }
.field .help, .help { color: var(--muted); font-size: .85rem; }
.field.checkbox { flex-direction: row; align-items: center; gap: 10px; }
.field.checkbox input, .perm input { width: 22px; height: 22px; accent-color: var(--brand); }
.static { min-height: var(--tap); display: flex; align-items: center; padding: 0 12px; background: var(--surface-2); border-radius: 10px; }
.narrow { max-width: 480px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }

.perms { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 8px 0 16px; }
.perms legend { font-weight: 700; padding: 0 8px; }
.perm-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 8px; }
.perm-group { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.perm { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.perms.locked .perm { opacity: .55; cursor: default; }

/* ---------- جدول (روی موبایل کارت می‌شود) */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: var(--surface-2); font-weight: 700; font-size: .9rem; }
.table tr:last-child td { border-bottom: 0; }
.row-muted td { color: var(--muted); }
@media (max-width: 700px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table td { border: 0; padding: 4px 16px; display: flex; gap: 8px; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); min-width: 90px; flex: 0 0 90px; }
}

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.field-actions { flex-direction: row !important; gap: 8px; }
.field-actions .btn, .btn { white-space: nowrap; }
.changes { margin: 0; padding-inline-start: 18px; }
.changes .old { color: var(--danger); text-decoration: line-through; }
.changes .new { color: var(--ok); }
.reason { color: var(--muted); font-size: .9rem; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; }

/* ---------- خانه */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 18px; min-height: 140px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
a.tile:hover { border-color: var(--brand); }
.tile-icon { width: 34px; height: 34px; color: var(--brand); }
.tile-title { font-weight: 700; font-size: 1.05rem; }
.tile-desc { color: var(--muted); font-size: .9rem; }
.tile-soon { opacity: .6; }
.tile .badge { position: absolute; top: 14px; inset-inline-end: 14px; }

/* ---------- صفحه ورود */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 24px;
}
.auth-brand { text-align: center; margin-bottom: 16px; }
.auth-brand img { border-radius: 14px; }
.auth-brand h1 { font-size: 1.3rem; margin: 8px 0 0; }
.error-page { text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--brand); }

@media (max-width: 700px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { min-height: 120px; padding: 14px; }
  .tile .badge { position: static; align-self: flex-start; margin-top: 4px; }
}

/* ---------- اقلام */
.crumb { color: var(--muted); text-decoration: none; font-weight: 500; }
.crumb:hover { color: var(--brand); }
.toolbar-note { align-self: center; margin-inline-start: auto; }
.field-wide { grid-column: span 2; }
@media (max-width: 700px) { .field-wide { grid-column: auto; } }
.filters input[type=search] {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.cards { gap: 16px; align-items: start; }
.cards .card { margin-bottom: 0; }
.chips { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.chip form { margin: 0; display: inline; }
.chip-x {
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--muted);
  font-size: 1.2rem; cursor: pointer; line-height: 1;
}
.chip-x:hover { background: var(--danger-soft); color: var(--danger); }
.plain { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.plain li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
form.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 160px; margin-bottom: 0; display: flex; flex-direction: column; gap: 4px; }
.inline-form .field input {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.row-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.row-form input {
  min-height: 40px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; flex: 1 1 180px;
}
.row-form input.num { flex: 0 0 90px; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 16px; }
.danger-zone p { margin: 4px 0 0; }
textarea { resize: vertical; }

/* ---------- رسپی */
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.row-warn td { background: var(--warn-soft); }
.row-error td { background: var(--danger-soft); }
.issues { margin: 6px 0 0; padding-inline-start: 20px; }
.draft-box { border-color: var(--warn); }
.draft-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.draft-head h2 { margin: 0; }
.submit-form { margin: 8px 0; }
.prewrap { white-space: pre-wrap; }
.diff { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.diff li { padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
.diff-added { background: var(--ok-soft) !important; }
.diff-removed { background: var(--danger-soft) !important; }
.diff .old { color: var(--danger); text-decoration: line-through; }
.diff .new { color: var(--ok); font-weight: 700; }
.table tfoot th { background: var(--surface-2); text-align: start; }
.center { text-align: center !important; }
.pad { padding: 12px; }
.edit-lines td { padding: 6px; vertical-align: middle; }
.edit-lines input[type=text], .edit-lines select {
  min-height: 44px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
.edit-lines input[name$=quantity], .edit-lines input[name$=quantity_double] { width: 90px; }
.edit-lines input[name$=unit] { width: 90px; }
.edit-lines input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }
.edit-lines .error { color: var(--danger); display: block; }
.edit-lines:not(.has-double) .col-double { display: none; }
.move { white-space: nowrap; }
.icon-sm {
  width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: .7rem;
}
.sticky-actions {
  position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border); z-index: 4;
}
@media (max-width: 700px) {
  .edit-lines td { padding: 4px 12px; }
  .edit-lines td.move { justify-content: flex-start; }
  .edit-lines input[name$=quantity], .edit-lines input[name$=quantity_double], .edit-lines input[name$=unit] { width: 100%; }
}
@media (max-width: 700px) { .sticky-actions { position: static; } }

/* ---------- فرم تولید */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.3rem; font-weight: 700; }
.stat-value small { font-size: .8rem; font-weight: 400; color: var(--muted); }
.stat-warn { background: var(--warn-soft); }
.pct { font-size: 1rem; color: var(--brand); }
.danger-zone .field { flex: 1 1 260px; display: flex; flex-direction: column; gap: 4px; margin: 0; }
.danger-zone input[type=text] {
  min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
a.stat-link { color: var(--text); text-decoration: none; border: 1px solid transparent; }
a.stat-link:hover { border-color: var(--brand); }
.filters .field.checkbox { flex-direction: row; align-items: center; min-height: var(--tap); }
.kg-hint { display: block; color: var(--brand); font-weight: 700; min-height: 1.2em; }
.edit-lines tfoot th, .edit-lines tfoot td { background: var(--surface-2); padding: 10px 12px; }

/* حذف ردیف با سطل آشغال؛ تیک DELETE پنهان می‌ماند و با دکمه زده می‌شود */
.row-delete input[type=checkbox] { display: none; }
.icon-del {
  width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--danger); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-del:hover, .icon-del:focus-visible { background: var(--danger); color: #fff; border-color: var(--danger); }
.icon-del svg { width: 20px; height: 20px; }
tr.line-row[hidden] { display: none !important; }
.add-reason { display: flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); margin-top: 4px; }
.add-reason[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- وزن دوخانه‌ای: کیلو | گرم (در RTL کیلو سمت راست) */
.wfield { display: flex; gap: 6px; min-width: 0; }
.wpart { position: relative; flex: 1 1 0; min-width: 0; display: block; margin: 0; }
.wpart input {
  width: 100%; min-height: var(--tap); padding: 8px 10px; padding-inline-end: 40px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  font: inherit; font-size: 1.05rem; text-align: center;
}
.wpart input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.wpart .wunit {
  position: absolute; inset-inline-end: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .8rem; pointer-events: none;
}
.has-error .wpart input, .row-error .wpart input { border-color: var(--danger); }
.weights { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 16px; }
.row-form .wfield { width: 220px; }

/* ورودی‌ها: حالت کیلو/گرم یا واحد دیگر */
.c-amount { min-width: 230px; }
.amt-qty { display: flex; align-items: center; gap: 8px; }
.amt-qty input { flex: 1; min-width: 0; }
.amt-unit { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.amt-caption { display: block; color: var(--muted); font-size: .8rem; margin: 6px 0 4px; }
.mode-weight .amt-qty, .mode-weight .amt-caption { display: none; }
.edit-lines select[name$=unit] { min-width: 110px; }
.loss-amount { display: flex; align-items: center; gap: 8px; }
.loss-amount .wfield { flex: 2 1 0; }
.loss-amount .pct { flex: 0 0 84px; }
.loss-or { color: var(--muted); font-size: .85rem; }
[data-target][hidden] { display: none; }

/* موبایل: هر ردیف یک کارت؛ کالا و سطل آشغال بالا، مقدار تمام‌عرض */
@media (max-width: 700px) {
  .line-cards tbody tr.line-row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; gap: 10px;
    width: auto; padding: 12px; margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow);
  }
  .line-cards tbody tr.line-row.row-error { border-color: var(--danger); }
  .line-cards tbody td { display: block; width: auto; padding: 0; border: 0; min-width: 0; }
  .line-cards td[data-label]::before {
    display: block; min-width: 0; flex: none; margin-bottom: 4px; font-size: .8rem;
  }
  .line-cards .c-item { grid-column: 1 / 3; grid-row: 1; }
  .line-cards .row-delete { grid-column: 3; grid-row: 1; align-self: end; text-align: center; }
  .line-cards .c-plan { grid-column: 1 / -1; font-size: .9rem; }
  .line-cards .c-unit { grid-column: 1 / 3; }
  .line-cards .c-amount, .line-cards .c-note { grid-column: 1 / -1; min-width: 0; }
  .line-cards input[type=text], .line-cards select { width: 100%; min-height: var(--tap); font-size: 16px; }
  .line-cards .icon-del { width: 44px; height: var(--tap); }
  .line-cards tfoot, .line-cards tfoot tr { display: block; }
  .line-cards tfoot tr { display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
    padding: 12px; border-radius: var(--radius); background: var(--surface-2); }
  .line-cards tfoot th, .line-cards tfoot td { display: inline; width: auto; padding: 0; background: none; }
  .line-cards tfoot td::before { content: none; }
  .loss-amount { flex-wrap: wrap; }
  .loss-amount .wfield { flex: 1 1 100%; }
  .loss-amount .loss-or { flex: 0 0 auto; }
  .loss-amount .pct { flex: 1 1 0; }
  .weights { grid-template-columns: 1fr; }
  .row-form .wfield { width: 100%; }
}
@media (max-width: 700px) { .stats { grid-template-columns: 1fr 1fr; } .stat-value { font-size: 1rem; } }
