/* ===== سامانه استخراج حواله — استایل اصلی ===== */

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

:root {
  --primary: #1e3a5f;
  --primary-dark: #16293f;
  --primary-light: #2f5580;
  --accent: #f97316;
  --accent-dark: #c2570d;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #d8e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 35, 60, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 35, 60, 0.18);
}

* { box-sizing: border-box; }

/* استایل‌های display در این فایل بر خاصیت hidden غلبه می‌کنند و مرورگر
   دیگر عنصر مخفی را پنهان نمی‌کند؛ این قاعده جلوی آن را می‌گیرد. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Vazirmatn", "IRANSans", Tahoma, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== نوار بالا ===== */
.topbar {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { color: #fff; display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 22px; }
.nav { display: flex; gap: 6px; flex: 1; }
.nav a {
  color: #dbe6f2;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.nav a:hover { background: rgba(255, 255, 255, 0.12); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; font-weight: 500; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.userbox .username { color: #cbd5e1; }

/* ===== ناوبری پایین صفحه (فقط موبایل) ===== */
.mobile-nav { display: none; }

/* ===== ساختار صفحه ===== */
.page { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-title { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

/* ===== دکمه‌ها ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  background: #eef2f7;
  color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: #e2e8f0; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-success { background: var(--ok-text); color: #fff; }
.btn-success:hover { background: #14532d; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-ghost { background: rgba(255, 255, 255, 0.14); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.24); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== فرم ===== */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(47, 85, 128, 0.15);
}
textarea { resize: vertical; line-height: 1.9; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-bottom: 10px; }
label.check input { width: auto; }

/* ===== هشدارها ===== */
.alert { padding: 11px 15px; border-radius: 9px; font-size: 13.5px; margin-bottom: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid #fcd34d; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid #86efac; }

/* ===== ورود ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-title { margin: 0 0 6px; font-size: 20px; text-align: center; color: var(--primary); }
.error-card { max-width: 480px; margin: 60px auto; text-align: center; }
.error-code { font-size: 44px; font-weight: 700; color: var(--primary); }
.error-message { margin: 10px 0 22px; color: var(--muted); }

/* ===== داشبورد ===== */
.mode-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.mode-tab {
  flex: 1;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  transition: all 0.15s;
}
.mode-tab:hover { border-color: var(--primary-light); }
.mode-tab.active { border-color: var(--accent); background: #fff7ed; color: var(--accent-dark); }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: #fafcff;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: #fff7ed; }
.dropzone .dz-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.preview-wrap { margin-top: 16px; text-align: center; }
.preview-wrap img { max-width: 260px; max-height: 220px; border-radius: 10px; border: 1px solid var(--border); }
.file-meta { font-size: 13px; color: var(--muted); margin-top: 8px; }
.text-input { min-height: 190px; line-height: 2.1; }
.pick-row { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.pick-btn { flex: 1; min-width: 200px; padding: 16px 14px; font-size: 15px; font-weight: 500; }
.pick-btn .pick-icon { font-size: 22px; }
.pick-btn span + span { margin-inline-start: 4px; }

.hint-box {
  background: var(--warn-bg); color: var(--warn-text);
  padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px;
}

/* ===== پردازش دسته‌ای ===== */
.batch-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.batch-toolbar .spacer { flex: 1; }
.batch-queue {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 320px; overflow-y: auto;
}
.batch-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 9px; background: #f8fafc;
}
.batch-item.status-processing { border-color: var(--primary-light); background: #eff6ff; }
.batch-item.status-done { border-color: #86efac; background: var(--ok-bg); }
.batch-item.status-error { border-color: #fca5a5; background: #fee2e2; }
.batch-pos {
  flex: 0 0 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 12.5px;
  display: inline-flex; align-items: center; justify-content: center;
}
.batch-thumb {
  width: 44px; height: 44px; object-fit: cover;
  border-radius: 7px; border: 1px solid var(--border); flex-shrink: 0;
}
.batch-thumb-empty {
  display: inline-flex; align-items: center; justify-content: center;
  background: #e2e8f0; font-size: 20px;
}
.batch-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.batch-name {
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.batch-sub { font-size: 12px; color: var(--muted); }
.batch-remove {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  border: none; background: #fee2e2; color: var(--danger);
  font-size: 16px; cursor: pointer; line-height: 1; font-family: inherit;
}
.batch-remove:hover { background: #fecaca; }

.progress-wrap {
  position: relative; height: 26px; background: #e2e8f0;
  border-radius: 20px; overflow: hidden; margin: 12px 0;
}
.progress-bar {
  height: 100%; width: 0; background: var(--primary);
  border-radius: 20px; transition: width 0.3s;
}
.progress-wrap > span {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 500;
}

.batch-summary { display: flex; gap: 14px; margin-bottom: 12px; font-size: 14px; }
.batch-sum-ok { color: var(--ok-text); font-weight: 500; }
.batch-sum-err { color: var(--danger); font-weight: 500; }

.batch-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 16px; overflow: hidden; background: #fff;
  box-shadow: var(--shadow);
}
.batch-card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: #f8fafc; border-bottom: 1px solid var(--border);
}
.batch-card-head .batch-name { font-size: 14px; }
.batch-card-head .btn { margin-inline-start: auto; flex-shrink: 0; }
.batch-card .table-scroll { border-radius: 0; }

/* ===== اسکلت بارگذاری ===== */
.skeleton {
  background: linear-gradient(90deg, #e8edf3 25%, #f2f5f9 37%, #e8edf3 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.3s ease-in-out infinite;
  border-radius: 7px;
  height: 15px;
  margin-bottom: 9px;
}
.skeleton-line-lg { height: 26px; }
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.spinner {
  width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff; border-radius: 50%; display: inline-block;
  animation: spin 0.8s linear infinite; vertical-align: -4px;
}
.spinner-dark { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== صفحه نتیجه ===== */
.result-layout { display: grid; grid-template-columns: 400px 1fr; gap: 20px; align-items: start; }
.preview-pane { position: sticky; top: 84px; }
.preview-pane .preview-stage {
  height: 460px; overflow: hidden; border-radius: 10px;
  background: #e2e8f0; display: flex; align-items: center; justify-content: center;
  user-select: none; touch-action: pan-y;
}
/* وقتی کاربر تصویر را بزرگ کرد، جابه‌جایی تصویر اولویت دارد و اسکرول صفحه متوقف می‌شود */
.preview-pane .preview-stage.zoomed { cursor: grab; touch-action: none; }
.preview-pane .preview-stage.dragging { cursor: grabbing; }
.preview-pane .preview-stage img { max-width: none; transform-origin: center; }
.preview-text {
  max-height: 460px; overflow: auto; background: #f8fafc;
  border: 1px solid var(--border); border-radius: 10px; padding: 14px;
  white-space: pre-wrap; line-height: 2;
}
.preview-tools { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.preview-hint { margin: 8px 0 0; }

/* نمایش ساده تصویر در موبایل: بدون ترنسفورم، فقط متناسب با عرض کارت */
.preview-stage.is-simple {
  height: auto; min-height: 140px; max-height: 56vh;
  padding: 8px; background: #f8fafc;
}
.preview-stage.is-simple img {
  display: block; margin: 0 auto;
  max-width: 100%; max-height: calc(56vh - 16px);
  width: auto; height: auto; object-fit: contain;
  border-radius: 8px;
}

/* لاملایت‌باکس تمام‌صفحه — فقط موبایل */
.lightbox { display: none; }
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.94);
  align-items: center; justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox-close {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px));
  inset-inline-end: 12px;
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18); color: #fff; border: none;
  font-size: 26px; line-height: 1; cursor: pointer; font-family: inherit;
}

.table-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.table-toolbar .spacer { flex: 1; }
.save-state { font-size: 12.5px; color: var(--muted); }
.save-state.saved { color: var(--ok-text); }

.table-scroll { overflow-x: auto; border-radius: 10px; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th, table.data-table td {
  border: 1px solid var(--border); padding: 6px 8px; text-align: right; vertical-align: middle;
}
table.data-table thead th { background: var(--primary); color: #fff; font-weight: 500; font-size: 13.5px; white-space: nowrap; }
table.data-table tbody tr:nth-child(even) { background: #fafbfd; }
table.data-table tbody tr.low-score { background: var(--warn-bg) !important; }
table.data-table tbody tr.high-score { background: var(--ok-bg); }
table.data-table td.cell-row { background: #f1f5f9; text-align: center; color: var(--muted); font-weight: 500; }
table.data-table td input, table.data-table td select {
  padding: 6px 8px; font-size: 13.5px; border-radius: 6px; min-width: 70px;
}
table.data-table td.cell-name { min-width: 220px; }
table.data-table td.cell-name button {
  width: 100%; text-align: right; background: transparent; border: 1px dashed transparent;
  padding: 5px 7px; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 13.5px;
  color: var(--text); display: flex; align-items: center; gap: 6px; justify-content: space-between;
}
table.data-table td.cell-name button:hover { border-color: var(--primary-light); background: #fff; }
tr.low-score td.cell-name button { color: var(--warn-text); font-weight: 500; }
.score-badge {
  font-size: 11px; padding: 1px 7px; border-radius: 20px;
  background: #e2e8f0; color: #475569; flex-shrink: 0;
}
.score-badge.good { background: var(--ok-text); color: #fff; }
.score-badge.warn { background: #d97706; color: #fff; }
.del-row {
  background: #fee2e2; color: var(--danger); border: none; border-radius: 6px;
  min-width: 30px; height: 30px; padding: 0 7px; cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font-family: inherit;
}
.del-row:hover { background: #fecaca; }
.del-row .del-text { display: none; }
.action-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border);
}

/* ===== مودال ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px; max-height: 82vh; display: flex; flex-direction: column;
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.product-result {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 8px; cursor: pointer;
  background: #fff; width: 100%; text-align: right; font-family: inherit; font-size: 14px;
}
.product-result:hover { border-color: var(--accent); background: #fff7ed; }
.product-result.current { border-color: var(--ok-text); background: var(--ok-bg); }
.product-code {
  background: var(--primary); color: #fff; border-radius: 6px;
  padding: 2px 9px; font-size: 12.5px; flex-shrink: 0; font-family: Consolas, monospace;
}
.product-name { flex: 1; }
.product-score { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.empty-state { text-align: center; padding: 26px 10px; color: var(--muted); font-size: 13.5px; }

/* ===== تاریخچه ===== */
.history-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.history-toolbar .field { margin-bottom: 0; }
.range-btn.active { background: var(--primary); color: #fff; }
.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.history-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: transform 0.12s, box-shadow 0.12s;
}
.history-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.history-thumb {
  height: 140px; background: #f1f5f9; display: flex; align-items: center;
  justify-content: center; overflow: hidden; border-bottom: 1px solid var(--border);
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-thumb .thumb-text {
  padding: 12px; font-size: 12.5px; color: var(--muted); text-align: center;
  white-space: pre-wrap; max-height: 116px; overflow: hidden; width: 100%;
}
.history-body { padding: 13px 15px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.history-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.badge { padding: 1px 9px; border-radius: 20px; font-size: 11.5px; }
.badge-draft { background: var(--warn-bg); color: var(--warn-text); }
.badge-completed { background: var(--ok-bg); color: var(--ok-text); }
.badge-image { background: #dbeafe; color: #1e40af; }
.badge-text { background: #ede9fe; color: #5b21b6; }

/* ===== تنظیمات ===== */
.settings-section { margin-bottom: 26px; }
.settings-section h3 { margin: 0 0 4px; font-size: 16px; }
.column-list { display: flex; flex-direction: column; gap: 8px; }
.column-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 9px;
}
.column-item.dragging { opacity: 0.45; border-style: dashed; }
.column-item.drop-target { border-color: var(--accent); background: #fff7ed; }
.column-handle { cursor: grab; color: var(--muted); font-size: 17px; user-select: none; }
.column-item input[type="text"] { padding: 6px 9px; font-size: 13.5px; }
.column-item .col-key { flex: 1; }
.column-item .col-label { flex: 1; }
.lock-badge { font-size: 11.5px; color: var(--muted); background: #e2e8f0; padding: 2px 9px; border-radius: 20px; }
.code-editor {
  font-family: Consolas, "Courier New", monospace; font-size: 13px;
  direction: ltr; text-align: left; min-height: 260px; line-height: 1.75;
}
.preview-json {
  background: #0f172a; color: #e2e8f0; border-radius: 9px; padding: 14px;
  font-family: Consolas, "Courier New", monospace; font-size: 12.5px;
  direction: ltr; text-align: left; overflow: auto; max-height: 340px;
  white-space: pre; line-height: 1.7;
}
.excel-preview { overflow-x: auto; margin-top: 12px; }
.excel-preview table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.excel-preview th, .excel-preview td { border: 1px solid var(--border); padding: 5px 8px; white-space: nowrap; }
.excel-preview th { background: #f1f5f9; font-weight: 500; }
.excel-preview .col-code { background: #dcfce7; }
.excel-preview .col-name { background: #dbeafe; }

/* ===== ادمین ===== */
.table-responsive { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.users-table th, .users-table td { border: 1px solid var(--border); padding: 9px 11px; text-align: right; }
.users-table thead th { background: var(--primary); color: #fff; font-weight: 500; }
.users-table tbody tr:nth-child(even) { background: #fafbfd; }
.users-table tr.disabled td { opacity: 0.55; }
.users-table .role-select { width: auto; min-width: 110px; padding: 6px 10px; }
.password-box {
  background: #0f172a; color: #a5f3fc; padding: 13px 15px; border-radius: 9px;
  font-family: Consolas, monospace; font-size: 15px; direction: ltr; text-align: center;
  user-select: all; margin: 12px 0;
}

/* ===== توست ===== */
.toast-root { position: fixed; bottom: 22px; left: 22px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--primary); color: #fff; padding: 12px 18px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px;
  animation: toast-in 0.2s ease-out;
}
.toast.ok { background: var(--ok-text); }
.toast.err { background: var(--danger); }
.toast.warn { background: #b45309; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== موبایل ===== */
@media (max-width: 768px) {
  /* فونت پایه و ورودی‌ها ۱۶ پیکسل می‌شود تا iOS با فوکوس روی ورودی
     صفحه را خودکار زوم نکند. */
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 16px; }
  input[type="text"], input[type="password"], input[type="number"],
  input[type="date"], input[type="search"], select, textarea {
    font-size: 16px; padding: 11px 12px;
  }

  /* تصویر بالای صفحه و جدول پایین آن، بدون تب */
  .grid-2, .result-layout { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
  .preview-pane .preview-stage:not(.is-simple) { height: min(420px, 48vh); }
  .preview-text { max-height: 42vh; }
  .lightbox { display: flex; }

  /* نوار بالا سبک و تک‌ردیف می‌شود؛ ناوبری به پایین صفحه منتقل شده است. */
  .nav { display: none; }
  .topbar-inner { height: 56px; padding: 0 12px; gap: 8px; }
  .brand { flex: 1; min-width: 0; }
  .brand-text {
    font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .userbox { flex-shrink: 0; }
  .userbox .username { display: none; }

  /* ناوبری پایین صفحه */
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 90;
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(15, 35, 60, 0.12);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-nav a {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-height: 58px; padding: 7px 2px 8px;
    color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.3;
    text-align: center; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav a:active { background: #f1f5f9; }
  .mobile-nav a .nav-ico { font-size: 20px; line-height: 1.2; }
  .mobile-nav a.active { color: var(--accent-dark); }
  .mobile-nav a.active .nav-ico { transform: translateY(-1px); }

  /* فضای کافی زیر محتوا برای نوار ثابت پایین صفحه */
  body.has-mobile-nav { padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .page { padding: 14px 12px 20px; }
  .card { padding: 16px 14px; }

  .hide-mobile { display: none !important; }

  /* دکمه‌ها تمام‌عرض و قابل لمس */
  .action-bar { gap: 8px; }
  .action-bar .btn { flex: 1 1 100%; padding: 13px 14px; font-size: 15px; }
  .btn-row .btn { flex: 1 1 auto; }
  .pick-row { flex-direction: column; }
  .pick-btn { min-width: 0; width: 100%; }

  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 88vh; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; padding: 12px 14px; }
  .product-result { flex-wrap: wrap; }
  .product-name { flex: 1 1 100%; order: 3; }

  .toast-root { left: 10px; right: 10px; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  .toast { max-width: none; }

  .history-list { grid-template-columns: 1fr; }
  .history-toolbar .field { flex: 1 1 130px; }
  .code-editor, .preview-json { font-size: 12px; }

  /* پردازش دسته‌ای */
  .batch-card-head { flex-wrap: wrap; }
  .batch-card-head .btn { flex: 1 1 100%; }
  .batch-queue { max-height: 260px; }

  /* تنظیمات: ستون‌ها و ورودی‌ها روی عرض کم به دو خط می‌شوند */
  .column-item { flex-wrap: wrap; row-gap: 8px; }
  .column-item .col-key, .column-item .col-label { flex: 1 1 100%; }
  .column-item .column-handle { flex: 0 0 auto; }
  .btn-row > input[type="text"] { flex: 1 1 100% !important; }
  .btn-row > .btn { flex: 1 1 100%; }

  .table-toolbar .btn { flex: 1 1 auto; }
  .table-toolbar .spacer { display: none; }
  .save-state { flex: 1 1 100%; }
}

/* جدول نتیجه روی گوشی به‌جای اسکرول افقی، کارت‌به‌کارت نمایش داده می‌شود. */
@media (max-width: 640px) {
  .table-scroll { overflow-x: visible; }
  table.data-table { display: block; width: 100%; }
  table.data-table thead { display: none; }
  table.data-table tbody { display: block; }
  table.data-table tr {
    display: block; background: #fff;
    border: 1px solid var(--border); border-radius: 11px;
    margin-bottom: 12px; padding: 4px 12px;
  }
  table.data-table tbody tr:last-child { margin-bottom: 0; }
  table.data-table tbody tr.low-score { border-inline-start: 4px solid #d97706; }
  table.data-table tbody tr.high-score { border-inline-start: 4px solid var(--ok-text); }
  table.data-table td {
    display: flex; align-items: center; gap: 10px;
    border: none; border-bottom: 1px solid var(--border);
    padding: 8px 0; text-align: right;
  }
  table.data-table td:last-child { border-bottom: none; }
  /* سلول حذف برچسب ندارد؛ دکمهٔ خودش عنوان دارد */
  table.data-table td:last-child::before { content: none; }
  table.data-table td::before {
    content: attr(data-label);
    flex: 0 0 78px; font-size: 12.5px; color: var(--muted);
  }
  table.data-table td.cell-row,
  table.data-table td.cell-name { min-width: 0; background: transparent; }
  table.data-table td input { flex: 1; min-width: 0; }
  table.data-table td.cell-name button { width: 100%; font-size: 15px; }
  table.data-table td .del-row { margin-inline-start: auto; }
  .del-row { width: auto; height: 38px; padding: 0 14px; }
  .del-row .del-text { display: inline; }
}
