/* =====================================================================
   بهینه‌سازی موبایل و اندروید برای پنل مدیریت
   ===================================================================== */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }

@media (max-width: 860px) {
  html { font-size: 100%; }
  body { overflow-x: hidden; }
  .shell { min-height: 100dvh; }
  .sidebar { width: min(82vw, 300px); height: 100dvh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 60; }
  .scrim { z-index: 55; }
  .nav-link { min-height: 46px; }

  .topbar { padding: 8px 10px; gap: 8px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .topbar h2 { font-size: 1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn, .menu-btn { min-width: 42px; min-height: 42px; padding: 0 10px; justify-content: center; }
  #backToLibrary { padding: 0; width: 42px; }
  #backToLibrary .btn-text { display: none; }
  .content { padding: 12px 10px calc(24px + env(safe-area-inset-bottom)); }
  .card { padding: 14px; border-radius: 14px; }
  .table-card { padding: 0; }

  input[type=text], input[type=password], input[type=number], input[type=search], input[type=email], textarea, select { font-size: 16px; min-height: 46px; }
  textarea { min-height: 90px; }
  .btn { min-height: 42px; }
  .btn.sm { min-height: 40px; padding-inline: 12px; }
  .form-actions .btn { flex: 1 1 100%; justify-content: center; }

  .toolbar { gap: 8px; }
  .toolbar > * { flex: 1 1 100%; min-width: 0; }
  .toolbar select { width: 100%; }
  .toolbar .btn { justify-content: center; }

  /* کارت‌های آمار: دو ستون */
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.two { grid-template-columns: 1fr; }
  .stat { flex-direction: column; align-items: flex-start; gap: 8px; }
  .stat .ico { width: 42px; height: 42px; border-radius: 12px; }
  .stat .ico .ic { width: 22px; height: 22px; }
  .stat .num { font-size: 1.35rem; }
  .bar-row { grid-template-columns: 80px 1fr 28px; }
  .day-chart { gap: 2px; }
  .day-col { font-size: .6rem; }

  /* جدول ← کارت */
  .table-scroll { overflow: visible; }
  table.data, table.data tbody, table.data thead { display: block; min-width: 0 !important; width: 100%; }
  table.data thead tr { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; background: var(--color-surface-2); }
  table.data thead th { display: inline-flex; align-items: center; width: auto !important; padding: 7px 12px; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-surface); min-height: 36px; }
  table.data thead th.th-empty { display: none; }
  table.data thead th:has(input) { padding: 7px 10px; }
  table.data tbody tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 14px; border-top: 1px solid var(--color-border); }
  table.data td { display: block; border: 0; padding: 0; min-width: 0; flex: 1 1 auto; }
  table.data td[colspan] { flex: 1 1 100%; }
  table.data td[data-label]:not([data-label=""])::before { content: attr(data-label) ": "; color: var(--color-muted); font-size: .75rem; }
  table.data td.cell-lead { flex: 1 1 100%; font-weight: 600; font-size: 1rem; }
  table.data td.cell-lead::before, table.data td:has(.cell-title)::before { display: none; }
  table.data td:has(input[type=checkbox]) { flex: 0 0 auto; }
  table.data td:has(.cell-title) { flex: 1 1 calc(100% - 44px); }
  table.data td:has(.row-actions) { flex: 1 1 100%; }
  table.data td:has(.row-actions)::before { display: none; }
  table.data input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--color-primary); }
  .row-actions { flex-wrap: wrap; gap: 8px; width: 100%; }
  .row-actions .btn { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .pager { padding: 12px 8px; }
  .pager .btn { min-width: 40px; }

  .tree-row { padding: 9px 8px; flex-wrap: wrap; }
  .tree-row .acts { opacity: 1; flex-wrap: wrap; }
  .checks { grid-template-columns: 1fr; }
  .check { min-height: 46px; }
  .dropzone { padding: 24px 12px; }

  /* پنجره‌ی گفتگو ← کشوی پایین */
  .modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
  .modal { width: 100% !important; max-width: none !important; max-height: 92dvh; overflow-y: auto; border-radius: 20px 20px 0 0 !important; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .toast-stack { inset-inline: 10px; max-width: none; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .bulk-bar { width: 100%; bottom: calc(8px + env(safe-area-inset-bottom)); justify-content: center; }
}

@media (max-width: 420px) {
  .login-box { padding: 24px 18px; }
}
