/* abbasabad-anbar */
@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;600;700&display=swap");

:root {
  --bg: #f4f4f0;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --in: #2d6a3e;
  --out: #b33;
  --transfer: #c65c00;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { margin: 0; min-height: 100%; font-family: "Vazirmatn", Tahoma, sans-serif; background: var(--bg); color: var(--text); direction: rtl; }
.page {
  max-width: 520px; margin: 0 auto;
  padding: 16px 16px 48px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  width: 100%;
}
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.top h1 { margin: 0; font-size: 1.5rem; font-weight: 700; }
.sub { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }
.sub.block { margin-bottom: 12px; }
.top-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.top-icon {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  font-size: 1rem; padding: 5px 10px; border-radius: 999px; cursor: pointer; line-height: 1;
  font-family: inherit;
}
.top-icon:hover { color: var(--text); border-color: #bbb; }
.btn-logout {
  font-family: inherit; font-size: 0.75rem; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid #e0e0dc; background: var(--card); color: var(--muted);
  cursor: pointer; line-height: 1.2;
}
.btn-logout:hover { border-color: #d4a5a5; color: var(--out); background: #fdf8f8; }
.corner-link {
  border: none; background: none; color: var(--muted); font-size: 1.1rem;
  padding: 4px 8px; cursor: pointer; line-height: 1;
}
.corner-link:hover { color: var(--text); }

/* پنل مدیریت — overlay از گوشه */
.admin-overlay {
  /* inset:0 جایگزین با top/right/bottom/left برای سازگاری با مرورگرهای قدیمی (تبلت‌های اندروید قدیمی) */
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 120;
  background: rgba(0,0,0,.35);
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 12px;
}
.admin-overlay[hidden] { display: none; }
.admin-sheet {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  /* min() جایگزین با width/max-width برای سازگاری با مرورگرهای قدیمی */
  width: 100%; max-width: 300px; max-height: 85vh; overflow-y: auto; padding: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.15);
}
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 0.9rem; }
.admin-row {
  display: block; width: 100%; text-align: right;
  padding: 10px 8px; margin-bottom: 4px;
  border: none; background: none; font: inherit; font-size: 0.85rem;
  color: var(--text); cursor: pointer; border-radius: 8px;
}
.admin-row:hover { background: #f0f0ec; }
.admin-row.danger-text { color: var(--out); font-size: 0.8rem; margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 14px; }
.stock-subtabs { display: flex; gap: 6px; margin-bottom: 12px; }
.stock-sub {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.stock-sub.active { background: var(--text); color: #fff; border-color: var(--text); }
.wh-block { margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.wh-block-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 2px solid var(--line); }
.total-line { font-size: 0.8rem; color: var(--in); font-weight: 600; margin-top: 2px; }
.status { font-size: 0.75rem; padding: 6px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.status.ok { color: var(--in); background: #eef6f0; border-color: #b8d4be; }
.status.bad { color: var(--out); background: #fdf0f0; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab { flex: 1; padding: 12px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font: inherit; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.panel { display: none; }
.panel.active { display: block; }

.step-label { font-size: 0.8rem; font-weight: 700; color: var(--muted); margin: 0 0 8px; }

/* انتخاب ورود/خروج — اول فرم */
.direction-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.direction-pick.dir-pick-3 { grid-template-columns: 1fr 1fr 1fr; }
.dir-btn {
  padding: 20px 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.dir-btn[data-dir="in"].selected { border-color: var(--in); background: #eef6f0; color: var(--in); }
.dir-btn[data-dir="out"].selected { border-color: var(--out); background: #fdf0f0; color: var(--out); }
.dir-btn[data-dir="transfer"].selected { border-color: var(--transfer); background: #fff4e8; color: var(--transfer); }
.dir-hint { margin: -12px 0 16px; font-weight: 600; font-size: 0.9rem; }

.card-form { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 20px; overflow: visible; width: 100%; max-width: 100%; }
.field { display: block; margin-bottom: 14px; width: 100%; max-width: 100%; min-width: 0; }
label.field { display: block; width: 100%; max-width: 100%; }
.field span { display: block; font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; max-width: 100%; min-width: 0;
  padding: 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px;
  -webkit-appearance: none; appearance: none;
}
.row { display: flex; gap: 10px; }
.row .field { flex: 1; }

/* چیدمان فیلدهای ورود — flex ستونی برای موبایل/WebView (grid روی بعضی گوشی‌ها نصف‌عرض می‌شود) */
.entry-grid {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}
.entry-grid > .field {
  display: block;
  flex: 0 0 auto;
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.entry-grid > .field input,
.entry-grid > .field .suggest-wrap {
  width: 100%;
  max-width: 100%;
}
/* ترتیب نمایش — ورود */
.entry-grid .fld-product-name { order: 1; }
.entry-grid .fld-product-specs { order: 2; }
.entry-grid .fld-amount { order: 3; }
.entry-grid .fld-unit { order: 4; }
.entry-grid .fld-warehouse { order: 5; }
.entry-grid .fld-coords { order: 6; }
/* ترتیب نمایش — خروج */
.entry-grid.out-order .fld-unit { order: 3; }
.entry-grid.out-order .fld-warehouse { order: 4; }
.entry-grid.out-order .fld-amount { order: 5; }
.entry-grid.out-order .fld-coords { order: 6; display: block !important; }

.in-out-block { display: contents; }
.in-out-block[hidden] { display: none !important; }

.transfer-panel { margin: 8px 0 20px; }
.transfer-col {
  background: #fafaf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  overflow: visible;
  width: 100%;
  margin-bottom: 4px;
}
.transfer-col .field { margin-bottom: 14px; }
.transfer-col .field:last-child { margin-bottom: 0; }
.transfer-col .field input { font-size: 16px; padding: 13px 12px; }
.transfer-col .suggest-wrap:focus-within { z-index: 300; }
.transfer-qty-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.transfer-qty-row .field { margin-bottom: 0; }
.transfer-hints { margin-top: 10px; }
.transfer-hints .max-hint,
.transfer-hints .hint { margin: 6px 0 0; }

.suggest-wrap { position: relative; z-index: 1; width: 100%; min-width: 0; }
.suggest-wrap:focus-within { z-index: 200; }
.suggest-box { display: none; position: absolute; top: 100%; right: 0; left: 0; z-index: 201; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.suggest-box.open { display: block; }
.suggest-item { display: block; width: 100%; text-align: right; padding: 10px 12px; border: none; background: none; font: inherit; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest-item:hover { background: #f0f0ec; }
.suggest-item strong { display: block; }
.item-spec { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.item-coords { font-size: 0.8rem; color: #2d6a3e; margin-top: 3px; }
.wh-coords-summary { font-size: 0.82rem; color: #2d6a3e; margin: 4px 0 8px; padding: 6px 10px; background: #eef6f0; border-radius: 8px; }
.suggest-item small { color: var(--muted); }

.hint { margin: 0 0 14px; padding: 10px 12px; background: #eef6f0; border-radius: 8px; font-weight: 600; font-size: 0.9rem; }
.wh-name-line { margin: 0 0 8px; font-size: 0.9rem; font-weight: 700; color: var(--text); }
.field input:read-only { background: #f5f5f2; color: var(--muted); }
.field input.picker {
  cursor: pointer; background-color: #fff; color: var(--text);
  caret-color: transparent;
  padding-inline-start: 12px;
  padding-inline-end: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
}
.field input.picker::placeholder { color: #9a9a94; }
.field input.picker[data-picked="1"] { background-color: #eef6f0; border-color: var(--in); }
.field input[data-picked="1"] { background-color: #eef6f0; border-color: var(--in); }
#amountInput.amount-over {
  background: #fdf0f0 !important;
  border-color: #e0a0a0 !important;
}
#amountInput.amount-needs-pair,
#unitInput.field-needs-pair {
  background: #fffaf0 !important;
  border-color: #e8d8a8 !important;
}
.btn.submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn { padding: 14px; border: none; border-radius: 12px; font: inherit; font-weight: 700; cursor: pointer; }
.btn.in { background: var(--in); color: #fff; }
.btn.out { background: var(--out); color: #fff; }
.btn.submit { width: 100%; font-size: 1.15rem; padding: 16px; background: var(--text); color: #fff; }
.btn.submit.is-out { background: var(--out); }
.btn.submit.is-transfer { background: var(--transfer); }
.btn.submit.is-in { background: var(--in); }
.btn.lite { background: var(--card); border: 1px solid var(--line); color: var(--text); padding: 10px 14px; font-size: 0.85rem; }
.btn.sm { font-size: 0.8rem; padding: 6px 10px; }

.h2 { font-size: 1rem; margin: 16px 0 10px; font-weight: 700; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.item.cancelled { opacity: 0.65; border-style: dashed; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-meta { font-size: 0.85rem; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.item-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; background: #eee; font-weight: 600; }
.tag.in { background: #eef6f0; color: var(--in); }
.tag.out { background: #fdf0f0; color: var(--out); }
.tag.transfer { background: #fff0e0; color: var(--transfer); }
.tag.del { background: #fee; color: var(--out); }
.tag.restore { background: #eef; color: #336; }
.empty { text-align: center; padding: 24px; color: var(--muted); }

/* لیست ساده ثبت — بدون دکمه عملیات */
.list-simple .item { padding: 10px 12px; }
.list-simple .item-meta { margin-top: 2px; }
.list.compact .item { padding: 8px 10px; font-size: 0.85rem; }

/* بخش اصلاح — جدا از صفحه ثبت */
.manage-panel { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.audit-details { margin-top: 20px; font-size: 0.85rem; color: var(--muted); }
.audit-details summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.audit-details[open] summary { margin-bottom: 8px; }

.sep { border: none; border-top: 1px dashed var(--line); margin: 20px 0; }
.sub-panel { margin-top: 10px; }
.danger-zone { margin-top: 16px; padding: 12px; border: 1px solid #e8b8b8; border-radius: 12px; background: #fffafa; }
.danger-zone summary { cursor: pointer; font-weight: 700; color: var(--out); }
.btn.danger { background: var(--out); color: #fff; font-size: 0.95rem; padding: 12px; }
.confirm-input { width: 100%; padding: 10px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 12px 20px; border-radius: 10px; display: none; z-index: 200; max-width: 90vw; text-align: center; }
.toast.show { display: block; }
.toast.err { background: var(--out); }

.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 150; padding: 16px; }
.modal.modal-page { align-items: stretch; justify-content: stretch; padding: 0; background: var(--bg); }
#editModal.modal-edit-dialog { z-index: 200; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: 16px; padding: 20px; max-width: 400px; width: 100%; }
.modal-box.modal-wide { max-width: 440px; }
.modal-box.modal-edit-dialog-box {
  max-width: 520px;
  width: 100%;
  max-height: min(88vh, 620px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.modal-box.modal-edit-dialog-box .edit-form-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: visible;
}
.modal-box.modal-edit-dialog-box .suggest-wrap:focus-within { z-index: 320; }
.modal-box.modal-edit-dialog-box .suggest-box { z-index: 321; }
.modal-box.modal-edit-sheet {
  max-width: none;
  width: 100%;
  min-height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.edit-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
}
.edit-modal-head h2 { margin: 0; font-size: 1.15rem; }
.edit-form-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  padding: 16px 20px;
  align-content: start;
}
.edit-form-grid .field { margin-bottom: 0; }
.edit-form-grid .field-span-2 { grid-column: 1 / -1; }
.edit-modal-foot {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
}
.edit-modal-foot .btn { flex: 1; }
.audit-row { cursor: pointer; }
.audit-row:hover { background: #f7f7f7; }
.audit-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.audit-detail-box { background: #f5f5f5; border-radius: 8px; padding: 10px; min-height: 80px; }
.audit-detail-box h3 { margin: 0 0 8px; font-size: 0.88rem; color: var(--muted); }
.audit-detail-line { margin: 5px 0; font-size: 0.85rem; line-height: 1.45; }
.audit-detail-line span { color: var(--muted); display: inline-block; min-width: 4.5em; }
.stock-loc-row { font-size: 0.85rem; color: var(--muted); margin: 4px 0 2px 8px; line-height: 1.45; }
.stock-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.stock-card-parent { margin-bottom: 10px; }
.stock-card-parent .item-head { margin-bottom: 0; }
.stock-parent-qty { font-weight: 700; white-space: nowrap; }
.stock-children {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  margin-right: 14px;
  padding-right: 10px;
  border-right: 2px solid #e8e8e4;
}
.stock-children-wh { margin-top: 8px; }
.stock-card-mid {
  padding: 10px 12px;
  background: #fafaf8;
  border-radius: 8px;
}
.stock-card-mid .stock-children {
  margin-right: 12px;
  padding-right: 8px;
  border-right-color: #d8d8d4;
}
.stock-card-child {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  background: #f3f3f0;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid #ebebe8;
}
.stock-child-label { flex: 1; line-height: 1.45; }
.stock-child-qty { font-weight: 600; color: var(--text); white-space: nowrap; }
.stock-click { cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; }
.stock-click:hover,
.stock-click:focus-visible {
  background: #f0f4ff;
  border-color: #c5d4f0;
  outline: none;
}
.wh-block-title.stock-click:hover { color: #1a5fb4; }
.stock-history-list { max-height: min(70vh, 520px); overflow-y: auto; margin-top: 10px; }
.item-cancelled { opacity: 0.55; }
.stock-mid-qty { font-weight: 700; white-space: nowrap; }
.item-head-compact { margin-bottom: 0; }
.item-meta-strong { font-weight: 600; color: var(--text); }
.stock-wh-item { padding: 6px 10px; }
.modal-box h2 { margin: 0 0 12px; font-size: 1.1rem; }
.modal-box p { margin: 0 0 16px; line-height: 1.6; white-space: pre-line; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

@media (max-width: 480px) {
  .direction-pick { grid-template-columns: 1fr; }
  .direction-pick.dir-pick-3 { grid-template-columns: 1fr; }
  .transfer-qty-row { grid-template-columns: 1fr; }
  .edit-form-grid { grid-template-columns: 1fr; }
  .edit-form-grid .field-span-2 { grid-column: auto; }
  .page { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .card-form { padding: 14px 12px; }
  .entry-grid { gap: 10px; }
  .field { margin-bottom: 10px; }
  .dir-btn { padding: 16px 10px; font-size: 0.95rem; }
  .item-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .item-head > span { align-self: flex-end; }
}

/* لاگین و کاربر */
.login-overlay {
  /* inset:0 جایگزین با top/right/bottom/left برای سازگاری با مرورگرهای قدیمی (تبلت‌های اندروید قدیمی) */
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-overlay[hidden] { display: none; }
.login-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  /* min() جایگزین با width/max-width برای سازگاری با مرورگرهای قدیمی */
  padding: 28px 24px; width: 100%; max-width: 380px;
}
.login-box h1 { margin: 0 0 4px; font-size: 1.6rem; text-align: center; }
.login-box .sub { text-align: center; margin-bottom: 20px; display: block; }
.max-hint { margin: -8px 0 12px; padding: 6px 10px; background: #eef6f0; border-radius: 8px; font-size: 0.8rem; color: var(--in); font-weight: 700; }
.opt-tag { font-weight: 400; color: #b0b0a8; }
.req-tag { font-weight: 600; color: #b33; }
#warehouseCoordsInput.field-needs-pair,
#sourceCoordsInput.field-needs-pair,
#destCoordsInput.field-needs-pair {
  background: #fffaf0 !important;
  border-color: #e8d8a8 !important;
}
.login-error { color: var(--out); font-size: 0.85rem; margin: 0 0 10px; text-align: center; font-weight: 600; }
.btn.full { width: 100%; margin-top: 8px; }
.user-pill { font-size: 0.75rem; padding: 6px 10px; border-radius: 999px; background: #eef6f0; color: var(--in); font-weight: 600; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-form { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.user-form select { width: 100%; padding: 10px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }
body:not(.is-admin) .admin-only { display: none !important; }

/* فیلد رمز با دکمه نمایش/پنهان */
.pwd-wrap .pwd-field { position: relative; display: flex; align-items: stretch; }
.pwd-wrap .pwd-field input { flex: 1; padding-left: 44px; }
.pwd-toggle {
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; font-size: 1.15rem; line-height: 1;
  padding: 8px 10px; cursor: pointer; color: var(--muted);
  font-family: inherit;
}
.pwd-toggle:hover { color: var(--text); }
.pwd-toggle.on { color: var(--in); }

#btnExportExcel { margin-bottom: 14px; }
