/* ---------- پایه ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
}

html { font-size: 16px; }

body {
  font-family: "Vazirmatn", Vazirmatn, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  padding-bottom: 76px;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- فونت ---------- */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Regular.ttf");
  font-weight: 400;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Bold.ttf");
  font-weight: 700;
}

/* ---------- هدر ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #1c1917;
  color: #fafaf9;
}
.topbar h1 { font-size: 1.05rem; font-weight: 700; }
.clock { font-size: 0.75rem; color: #a8a29e; font-variant-numeric: tabular-nums; }

/* ---------- ناوبری پایین ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  display: flex;
  background: #ffffff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.68rem;
  color: var(--muted);
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-ic { font-size: 1.25rem; line-height: 1; }
.nav-btn.active { color: var(--accent); font-weight: 700; }
.nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- نماها ---------- */
main { max-width: 720px; margin-inline: auto; padding: 14px; }
.view { display: none; }
.view.active { display: block; animation: fadein 0.18s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 20px 2px 10px;
}

/* ---------- کارت‌ها ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cards.two { grid-template-columns: 1fr 1fr; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.card.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 0.72rem; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card.stat.warn .stat-value { color: var(--warn); }

.card.action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  padding: 22px 14px;
}
.card.action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.action.in { background: var(--accent-soft); border-color: #99f6e4; color: #115e59; }
.card.action.out { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.action-icon { font-size: 1.2rem; }

/* ---------- لیست انبارها (داشبورد) ---------- */
#dash-warehouses { display: flex; flex-direction: column; gap: 10px; }
.wh-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.wh-row:active { background: #fafaf9; }
.wh-name { font-weight: 700; font-size: 0.95rem; }
.wh-meta { font-size: 0.72rem; color: var(--muted); }
.wh-qty { text-align: left; font-variant-numeric: tabular-nums; }
.wh-qty b { font-size: 1.15rem; }
.wh-qty span { display: block; font-size: 0.68rem; color: var(--muted); }

/* ---------- لیست کالا ---------- */
.toolbar {
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 8px;
  margin-bottom: 12px;
}
input, select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.prod-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.prod-info { flex: 1; min-width: 0; }
.prod-name { font-weight: 700; font-size: 0.92rem; }
.prod-meta { font-size: 0.72rem; color: var(--muted); }
.prod-qty { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prod-qty b { font-size: 1.2rem; }
.prod-qty span { font-size: 0.68rem; color: var(--muted); display: block; }
.prod-row.low { border-inline-start: 4px solid var(--warn); background: #fffbeb; }
.prod-row.zero { border-inline-start: 4px solid var(--danger); background: #fef2f2; }

.badge {
  font-size: 0.62rem;
  padding: 2px 8px;
  border-radius: 99px;
  margin-top: 3px;
  display: inline-block;
}
.badge.low { background: var(--warn-soft); color: var(--warn); }
.badge.zero { background: var(--danger-soft); color: var(--danger); }

.prod-actions { display: flex; flex-direction: column; gap: 6px; }
.mini-btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn.in { color: var(--accent); border-color: #99f6e4; background: #f0fdfa; }
.mini-btn.out { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.mini-btn.edit { color: var(--muted); }

/* ---------- تراکنش‌ها ---------- */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tx-sign {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.tx-in .tx-sign { background: var(--accent-soft); color: var(--accent); }
.tx-out .tx-sign { background: var(--danger-soft); color: var(--danger); }
.tx-body { flex: 1; min-width: 0; }
.tx-title { font-size: 0.85rem; font-weight: 700; }
.tx-sub { font-size: 0.7rem; color: var(--muted); }
.tx-qty { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.tx-in .tx-qty { color: var(--accent); }
.tx-out .tx-qty { color: var(--danger); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  bottom: 90px;
  inset-inline-end: 18px;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.4);
  cursor: pointer;
  z-index: 9;
}
.fab:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- مودال ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 { font-size: 1.05rem; }
.close {
  background: #f5f5f4;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.78rem; font-weight: 700; margin-bottom: 5px; }

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  margin-top: 6px;
}
.btn.danger { background: var(--danger); }
.btn.ghost { background: #f5f5f4; color: var(--text); margin-top: 8px; }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.hint { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }

/* ---------- خالی ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.85rem;
}

/* ---------- توست ---------- */
.toast {
  position: fixed;
  bottom: 100px;
  inset-inline: 0;
  margin-inline: auto;
  width: max-content;
  max-width: 90vw;
  background: #1c1917;
  color: #fafaf9;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 0.82rem;
  z-index: 99;
  animation: toastin 0.2s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- دسکتاپ ---------- */
@media (min-width: 720px) {
  .fab { bottom: 30px; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
  .toast { bottom: 40px; }
}

/* ---------- ورودی سه‌تایی کارتن/باکس/بسته ---------- */
.units-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.units-row label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--muted);
}

/* ================= صفحه ورود ================= */
.login-wrap {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(160deg, #1c1917 0%, #292524 60%, #1c1917 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-box {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-logo { font-size: 2.6rem; }
.login-box h2 { margin: 6px 0 2px; }
.login-sub { color: var(--muted); font-size: 0.85rem; margin: 2px 0 16px; }
.login-users { display: flex; flex-direction: column; gap: 8px; }
.login-user-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e7e5e4;
  border-radius: 12px;
  background: #fafaf9;
  font: inherit; font-weight: 700; font-size: 1rem;
  text-align: right;
  cursor: pointer;
}
.login-user-btn .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
  flex: none;
}
.login-user-btn .role-tag {
  margin-inline-start: auto;
  font-size: 0.68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 20px;
  background: #e7e5e4; color: #57534e;
}
.login-user-btn .role-tag.admin { background: var(--accent); color: #fff; }
.login-user-name { font-weight: 800; font-size: 1rem; margin: 4px 0 10px; }
.login-box input {
  width: 100%; margin-bottom: 10px;
  padding: 12px 14px;
  border: 1.5px solid #e7e5e4; border-radius: 12px;
  font: inherit; font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.3em;
}
.login-box input[type="text"] { letter-spacing: 0; text-align: right; }
.login-actions { display: flex; gap: 8px; margin-top: 4px; }
.login-actions .btn { flex: 1; }
.login-actions .btn.primary { background: var(--accent); color: #fff; border: none; padding: 12px; border-radius: 12px; font-weight: 700; font: inherit; }
.login-actions .btn.ghost { background: #f5f5f4; border: 1.5px solid #e7e5e4; border-radius: 12px; font: inherit; }

/* ================= چیپ کاربر در هدر ================= */
.userchip {
  margin-inline-start: auto;
  display: flex; align-items: center; gap: 6px;
  background: #292524; color: #fff;
  border: none; border-radius: 20px;
  padding: 4px 10px 4px 6px;
  font: inherit; font-size: 0.75rem; font-weight: 700;
  cursor: pointer;
}
.userchip .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700;
}
.clock { margin-inline-start: 8px; }

/* ================= کارت‌های جابجایی ================= */
.tr-card {
  background: #fff; border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-inline-start: 4px solid #d6d3d1;
}
.tr-card.sent    { border-inline-start-color: #f59e0b; }
.tr-card.done    { border-inline-start-color: #16a34a; }
.tr-card.losing  { border-inline-start-color: #dc2626; }
.tr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tr-badge {
  font-size: 0.68rem; font-weight: 700;
  padding: 3px 9px; border-radius: 20px;
}
.tr-badge.sent   { background: #fef3c7; color: #92400e; }
.tr-badge.done   { background: #dcfce7; color: #166534; }
.tr-badge.losing { background: #fee2e2; color: #991b1b; }
.tr-route { font-weight: 700; font-size: 0.95rem; }
.tr-body { font-size: 0.85rem; color: var(--muted); line-height: 1.9; }
.tr-body b { color: var(--text); }
.tr-loss {
  margin-top: 6px;
  background: #fef2f2; color: #b91c1c;
  font-weight: 700; font-size: 0.82rem;
  padding: 6px 10px; border-radius: 8px;
}
.tr-actions { display: flex; gap: 8px; margin-top: 10px; }
.tr-actions .btn { flex: 1; padding: 9px; border-radius: 10px; font: inherit; font-weight: 700; border: none; cursor: pointer; }
.btn-green { background: #16a34a; color: #fff; }
.btn-red   { background: #dc2626; color: #fff; }
.btn-ghost2 { background: #f5f5f4; color: var(--text); }

/* ================= کارت راهنما و وضعیت خطر ================= */
.hint-card {
  background: #eff6ff; color: #1e40af;
  border-radius: 12px; padding: 10px 14px;
  font-size: 0.8rem; line-height: 1.8; margin-bottom: 12px;
}
.card.stat.danger {
  width: 100%;
  background: #fef2f2;
}
.card.stat.danger .stat-value { color: #dc2626; }

/* ================= برچسب نام کاربر در تراکنش‌ها ================= */
.tx-user {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7rem; font-weight: 700;
  color: #6d28d9; background: #f3e8ff;
  padding: 2px 8px; border-radius: 20px;
  margin-inline-start: 6px;
}

/* ---- دسترسی‌ها و گزارش‌ها ---- */
.check-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 8px; cursor: pointer;
  font-weight: 600;
}
.check-row input { width: 20px; height: 20px; accent-color: var(--accent, #0e7490); }
.card.stat.in .stat-value { color: #16a34a; }

/* بازه دلخواه گزارش */
#rep-custom {
  display: flex; gap: 8px; margin-top: 8px;
}
#rep-custom input {
  flex: 1; min-width: 0; text-align: center;
  font-size: .85rem;
}

/* فرم‌های گروهی */
.group-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 0 12px 10px;
  font-size: .9rem;
}
.group-row {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}
#view-tx .cards.two { margin-bottom: 10px; }

/* دکمه اصلاح مدیر در تاریخچه */
.tx-menu {
  background: none; border: none; font-size: 1.1rem;
  color: #64748b; padding: 6px 4px; cursor: pointer;
  align-self: center; flex-shrink: 0;
}
.tx-menu:active { color: #0f172a; }

/* فاکتورهای خرید */
.purchase-card {
  background: #fff; border: 1px solid #e7e5e4; border-radius: 12px;
  padding: 12px; margin: 0 12px 10px; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.pc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.pc-user { font-weight: 700; font-size: 0.9rem; color: #0f172a; }
.pc-date { font-size: 0.75rem; color: #64748b; }
.pc-wh { font-size: 0.75rem; color: #64748b; margin-bottom: 2px; }
.pc-note { font-size: 0.78rem; color: #92400e; background: #fef3c7; border-radius: 8px; padding: 5px 8px; margin: 6px 0; }
.pi-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 2px; border-top: 1px dashed #e2e8f0; font-size: 0.88rem;
}
.pi-row b { color: #134e4a; }

/* کارت واحد جابجایی در تاریخچه */
.tx-transfer { border-right: 3px solid #8b5cf6; }
.tx-transfer .tx-sign { background: #f1ebfe; color: #8b5cf6; }
.tr-badge { display: inline-block; background: #f1ebfe; color: #8b5cf6; font-size: 0.62rem; padding: 1px 6px; border-radius: 8px; margin-inline-start: 6px; font-weight: 700; }

.pi-edit { background: none; border: none; color: #8b5cf6; font-size: 0.95rem; padding: 2px 6px; cursor: pointer; border-radius: 6px; }
.pi-edit:active { background: #f1ebfe; }

/* پاورقی فاکتورها: مرجوعی و حذف */
.inv-foot { display: flex; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed #e5e7eb; }
.inv-del, .inv-ret { background: none; border: none; font-family: inherit; font-size: 0.78rem; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.inv-del { color: #dc2626; }
.inv-ret { color: #8b5cf6; }
.inv-del:active, .inv-ret:active { filter: brightness(0.92); }

/* ===== انتخابگر کالا با جستجو ===== */
.picker { position: relative; }
.picker-input { width: 100%; }
.picker-list { position: absolute; top: calc(100% + 4px); right: 0; left: 0; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 8px 24px rgba(15,23,42,.18); z-index: 80; max-height: 240px; overflow-y: auto; }
.picker-item { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid #f1f5f9; }
.picker-item:last-child { border-bottom: none; }
.picker-item:hover, .picker-item:active { background: #f1f5f9; }
.picker-stock { font-size: .72rem; color: #64748b; white-space: nowrap; }
.picker-empty { padding: 10px 14px; color: #94a3b8; font-size: .85rem; }
.picker-all { background: #f8fafc; font-weight: 600; color: #0e7490; }
.picker-all:hover, .picker-all:active { background: #ecfeff !important; }
.drv-check { display: flex; align-items: center; gap: 8px; padding: 7px 2px; font-size: .95rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.drv-check:last-child { border-bottom: none; }
.drv-check.drv-all { color: #0e7490; }
.drv-check input { width: 18px; height: 18px; accent-color: #0e7490; }
.dmg-line { font-size: .72rem; color: #b45309; background: #fffbeb; border: 1px dashed #fcd34d; border-radius: 8px; padding: 3px 8px; margin: 4px 0; width: fit-content; }
.mini-btn.dmg { color: #b45309; border-color: #fde68a; background: #fffbeb; }
.tx-dmg .tx-sign { background: #fef3c7; color: #b45309; }
.tx-dmg .tx-qty { color: #b45309; }
.tr-badge.dmg { background: #fef3c7; color: #92400e; }
